home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / Printer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  7.4 KB  |  248 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Printer.h
  3.  
  4.     Contains:    Printing utility for OpenDoc, with QuickDraw & GX support.
  5.  
  6.     Owned by:    Jens Alfke (with help from Steve Smith & Thomas Weisbach)
  7.  
  8.     Copyright:    © 1995-96 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      2/2/96    JA        Filled in header comments
  13.          <1>      2/2/96    JA        first checked in
  14.  
  15.     To Do:
  16. */
  17.  
  18.  
  19. #ifndef _PRINTER_
  20. #define _PRINTER_
  21.  
  22. #ifndef _ODTYPES_
  23. #include <ODTypes.h>
  24. #endif
  25.  
  26.  
  27. //=================================================================================
  28. // Resource ID declarations:
  29. //
  30. //         Used by the DisplayError method. Clients don't need to use these resource
  31. //        IDs, but they need to be aware of them so they can provide the appropriate
  32. //        resources (or renumber the IDs if they prefer to use different numbering.)
  33. //
  34. //        Standard resources matching these descriptions are in Printer.r.
  35. //=================================================================================
  36.  
  37. enum
  38. {
  39.     rPrintErrorsID = 32000,                // 'STR#' resource of printing error messages
  40.     
  41.     rMenuStrID = 32001,                    // 'STR#' resource of "Undo" / "Redo" strings
  42.          kPMUndoStrIndex = 1,                // Index of "Undo" string in rMenuStrID
  43.          kPMRedoStrIndex,                    // Index of "Redo" string in rMenuStrID
  44.          
  45.     rPrintErrorDialog = 32000            // 'ALRT' of printing-error alert
  46. };
  47.  
  48.  
  49. //=================================================================================
  50. // CPrinter
  51. //=================================================================================
  52.  
  53.  
  54. struct Environment;
  55. class ODFacet;
  56. class ODFrame;
  57. class ODSession;
  58. class ODShape;
  59. class ODStorageUnit;
  60.  
  61.  
  62. class CPrinter {
  63.  
  64.     public:
  65.     
  66.         // -- Factory method & destructor --
  67.         static CPrinter*    New( Environment*, ODStorageUnit* );
  68.         
  69.         virtual ~CPrinter();
  70.         
  71.         // -- Storage --
  72.                 void        Externalize( Environment*, ODStorageUnit* =kODNULL );
  73.     
  74.         // -- Getters --
  75.         virtual ODGraphicsSystem    GetGraphicsSystem( )                                =0;
  76.                 ODPlatformPrintJob    GetPlatformPrintJob( Environment* );
  77.         virtual ODRect                GetPageRect( Environment* )                            =0;
  78.     
  79.         // -- Printing --
  80.                 ODBoolean    PageSetup( Environment* );
  81.                 void        PrintDocument( Environment*, ODFrame* initiator, ODShape* area =kODNULL );
  82.     
  83.     protected:
  84.         // -- Private stuff --
  85.         CPrinter();
  86.     
  87.         virtual void        Initialize( Environment*, ODStorageUnit *su );
  88.         
  89.         virtual void        OpenPrinting( );
  90.         virtual void        ClosePrinting( );
  91.         inline    ODBoolean    IsPrintingOpen( )                                {return fPrintingOpen;}
  92.  
  93.         virtual ODValueType    GetValueType( )                                                =0;
  94.         virtual ODValueType    GetSecondaryValueType( )                        {return kODNULL;}
  95.         virtual ODPlatformPrintJob    BasicGetPlatformPrintJob( )                            =0;
  96.         virtual ODPlatformPrintJob    ReadJobFromHandle( ODValueType valueType, ODHandle)    =0;
  97.         virtual ODPlatformPrintJob    CreateNewJob()                                        =0;
  98.         virtual ODHandle    CopyJobToHandle( )                                            =0;
  99.         
  100.         virtual    void        SetupPrintingEnv( Environment*, ODFrame* initiator, ODShape *area );
  101.         virtual void        CleanupPrintingEnv( Environment*, ODFrame* initiator );
  102.         virtual ODPlatformCanvas CreatePrintingPlatformCanvas( Environment*, ODGraphicsSystem,
  103.                                             ODFrame *initiator, ODShape *area )             =0;
  104.         virtual ODULong        CountPages( Environment*, ODShape* area );
  105.  
  106.         virtual void        PrintPage( Environment*, ODUShort page, ODShape *area );
  107.         virtual void        SetPage( Environment*, ODUShort pageNum, ODShape* area );
  108.         
  109.         virtual void        OpenPage( Environment*, ODUShort page )                        =0;
  110.         virtual void        ClosePage( Environment* )                                    =0;
  111.         
  112.         virtual ODBoolean    RunPageSetupDialog( Environment *ev )                        =0;
  113.         virtual ODBoolean    RunPrintDialog( Environment *ev )                            =0;
  114.         virtual void        DoPrint( Environment*, ODShape* area )                        =0;
  115.         
  116.         virtual void        DisplayError( Environment*, ODSShort error );
  117.         
  118.         ODSession*            fSession;
  119.         ODStorageUnit*        fSU;
  120.         ODFacet*            fPrintFacet;
  121.         ODBoolean            fDirty;
  122.         ODSShort            fPrintingOpen;
  123.         
  124.         friend class CWithPrintingOpen;
  125. };
  126.  
  127.  
  128. //=================================================================================
  129. // Private stuff
  130. //=================================================================================
  131.  
  132. #ifdef _PRINTER_PRIVATE_
  133.  
  134. #ifndef __PRINTING__
  135. #include <Printing.h>        /* For THPrint and TPrPort */
  136. #endif
  137.  
  138. #ifndef __GXPRINTING__
  139. #include <GXPrinting.h>
  140. #endif
  141.  
  142. #ifndef __GXENVIRONMENT__
  143. #include <GXEnvironment.h>
  144. #endif
  145.  
  146. class ODWindowState;
  147.  
  148. //-----------------------------------------------
  149.  
  150. class CQDPrinter : public CPrinter {
  151.  
  152.     public:
  153.         CQDPrinter();
  154.         virtual ~CQDPrinter();
  155.             
  156.     protected:
  157.         virtual void        OpenPrinting( );
  158.         virtual void        ClosePrinting( );
  159.         virtual ODGraphicsSystem    GetGraphicsSystem( )            {return kODQuickDraw;}
  160.         virtual ODValueType    GetValueType( )                            {return kODTypeQuickDrawPageSetup;}
  161.         virtual ODPlatformPrintJob    BasicGetPlatformPrintJob( )        {return (ODPlatformPrintJob)fJob;}
  162.         virtual ODPlatformPrintJob    ReadJobFromHandle( ODValueType valueType, ODHandle );
  163.         virtual ODPlatformPrintJob    CreateNewJob();
  164.         virtual ODHandle    CopyJobToHandle( );
  165.         virtual ODPlatformCanvas CreatePrintingPlatformCanvas( Environment*, ODGraphicsSystem,
  166.                                             ODFrame *initiator, ODShape *area );
  167.         virtual ODRect        GetPageRect( Environment* );
  168.         virtual void        CleanupPrintingEnv( Environment*, ODFrame* initiator );
  169.         virtual void        OpenPage( Environment*, ODUShort page );
  170.         virtual void        ClosePage( Environment* );
  171.         virtual ODBoolean    RunPageSetupDialog( Environment *ev );
  172.         virtual ODBoolean    RunPrintDialog( Environment *ev );
  173.         virtual void        DoPrint( Environment*, ODShape* area );
  174.     
  175.     private:
  176.         THPrint        fJob;
  177.         TPrPort*    fPort;
  178.         Ptr            fIOBuffer;
  179.         ODBoolean    fPageOpen;
  180. };
  181.  
  182. //-----------------------------------------------
  183.  
  184. class CGXPrinter : public CPrinter {
  185.  
  186.     public:
  187.         CGXPrinter();
  188.         virtual ~CGXPrinter();
  189.  
  190.     protected:
  191.         virtual void        Initialize( Environment*, ODStorageUnit *su );
  192.         virtual ODGraphicsSystem    GetGraphicsSystem( )            {return kODQuickDrawGX;}
  193.         virtual ODValueType    GetValueType( )                            {return kODTypeGXPageSetup;}
  194.         virtual ODValueType    GetSecondaryValueType( )                {return kODTypeQuickDrawPageSetup;}
  195.         virtual ODPlatformPrintJob    BasicGetPlatformPrintJob( )        {return (ODPlatformPrintJob)fJob;}
  196.         virtual ODPlatformPrintJob    ReadJobFromHandle( ODValueType valueType, ODHandle );
  197.         virtual ODPlatformPrintJob    CreateNewJob();
  198.         virtual ODHandle    CopyJobToHandle( );
  199.         virtual ODPlatformCanvas CreatePrintingPlatformCanvas( Environment*, ODGraphicsSystem,
  200.                                             ODFrame *initiator, ODShape *area );
  201.         virtual ODRect        GetPageRect( Environment* );
  202.         virtual void        CleanupPrintingEnv( Environment*, ODFrame* initiator );
  203.         virtual void        OpenPage( Environment*, ODUShort page );
  204.         virtual void        ClosePage( Environment* );
  205.         virtual ODBoolean    RunPageSetupDialog( Environment *ev );
  206.         virtual ODBoolean    RunPrintDialog( Environment *ev );
  207.         virtual void        DoPrint( Environment*, ODShape* area );
  208.         
  209.                 void        EnableMenus( Environment*, ODBoolean enable );
  210.         
  211.         static    OSErr        PrintAShape( gxShape currentShape, long refCon );
  212.  
  213.     private:
  214.         gxJob            fJob;
  215.         gxViewPort        fViewPort;
  216.         GrafPtr            fQDPort;
  217.         gxEditMenuRecord fEditMenuRec;
  218.         gxShapeSpoolUPP    fPrintAShapeProcPtr;
  219.         ODBoolean        fJobStarted;
  220.         ODBoolean        fPageOpen;
  221. };
  222.  
  223. class CWithPrintingOpen :Destructo
  224. {
  225.     public:
  226.         CWithPrintingOpen( CPrinter* );
  227.         ~CWithPrintingOpen( );
  228.     private:
  229.         CPrinter *fPrinter;
  230. };
  231.  
  232. class CWithDialogState :Destructo
  233. {
  234.     public:
  235.         CWithDialogState( Environment *ev, ODSession *session );
  236.         ~CWithDialogState( );
  237.     private:
  238.         Environment *fEv;
  239.         ODWindowState *fWindowState;
  240.         GrafPtr fPort;
  241. };
  242.  
  243. void BusyCursor( );
  244.  
  245. #endif /*_PRINTER_PRIVATE_*/
  246.  
  247. #endif /*_PRINTER_*/
  248.