home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / blx21.zip / OWLPRT.ARJ / PRTCPP.ARJ / PRINTER.H < prev    next >
C/C++ Source or Header  |  1992-02-19  |  5KB  |  167 lines

  1. /* printer.h */
  2.  
  3. #ifndef __PRINTER_H
  4. #define __PRINTER_H
  5.  
  6. // OWL headers
  7. #include <owl.h>
  8. #include <objstrm.h>
  9. #include <owldefs.h>
  10. #include <tcollect.h>
  11.  
  12. // Windows header
  13. #include <drivinit.h>
  14.  
  15. // Standard header
  16. #include <string.h>
  17.  
  18. #define PS_OK 0
  19. #define PS_INVALIDDEVICE -1  // Device parameters (to set device) invalid
  20. #define PS_UNASSOCIATED -2   // Object not associated with a printer
  21.  
  22. // TPrintout banding flags
  23.  
  24. #define PF_GRAPHICS 0x01     // Current band only accepts graphics
  25. #define PF_TEXT 0x02         // Current band only accepts text
  26. #define PF_BOTH 0x03         // Current band accepts both text and graphics
  27.  
  28. /*
  29. TPrintout represents the physical printed document which is to
  30. sent to a printer to be printed. TPrintout does the rendering of
  31. the document onto the printer. For every document, or document
  32. type, a corresponding TPrintout class should be created.
  33. */
  34.  
  35. _CLASSDEF(TPrintout)
  36. class TPrintout: public TStreamable
  37. {
  38. protected:
  39.   Pchar Title;
  40.   BOOL Banding;
  41.   BOOL ForceAllBands;
  42. public:
  43.   TPrintout(Pchar ATitle);
  44.   virtual ~TPrintout();
  45.   virtual void PrintPage(HDC DC, WORD Page, POINT Size, LPRECT Rect, WORD Flags) = 0;
  46.   virtual BOOL IsNextPage();
  47.  
  48.   // The following are pure virtual functions in TStreamable
  49.   // and so must be redefined here to make this an instance class.
  50.   // These should be redefined if you actually want your TPrintout
  51.   // class to be streamable.
  52. private:
  53.   virtual const Pchar streamableName() const
  54.   {
  55.     return "TPrintout";
  56.   }
  57. protected:
  58.   virtual Pvoid read(Ripstream)
  59.   {
  60.     return this;
  61.   }
  62.   virtual void write(Ropstream)
  63.   {}
  64.  
  65.   friend class _CLASSTYPE TPrinter;
  66. };
  67.  
  68. /*
  69. TPrinter represent the physical printer device.  To print a
  70. TPrintout, send the TPrintout to the TPrinter's Print function.
  71. */
  72.  
  73. // DeviceMode functions have no template in windows.h or drivinit.h.
  74. typedef WORD (FAR PASCAL *PTDeviceModeFcn)(HWND, HANDLE, LPSTR, LPSTR);
  75.  
  76. _CLASSDEF(TPrinter)
  77. class TPrinter: public TStreamable
  78. {
  79. protected:
  80.   Pchar Device, Driver, Port;    // Printer device description
  81.   int Status;                    // Device status, error is != PS_OK
  82.   int Error;                     // < 0 if error occurred during print
  83.   HANDLE DeviceModule;           // Handle to printer driver module
  84.   PTDeviceModeFcn DeviceMode;    // Function pointer to DevMode
  85.   LPFNDEVMODE ExtDeviceMode;     // Function pointer to ExtDevMode
  86.   PDEVMODE DevSettings;          // Local copy of printer settings
  87.   int DevSettingSize;            // Size of the printer settings
  88.   void GetDefaultPrinter();
  89.  
  90. public:
  91.   TPrinter();
  92.   virtual ~TPrinter();
  93.   void ClearDevice();
  94.   void Configure(PTWindowsObject Window);
  95.   virtual HDC GetDC();
  96.   virtual void ReportError(PTPrintout Printout);
  97.   void SetDevice(Pchar ADevice, Pchar ADriver, Pchar APort);
  98.   void Setup(PTWindowsObject Parent);
  99.   BOOL Print(PTWindowsObject ParentWin, PTPrintout Printout);
  100. private:
  101.   // Private member used by Print
  102.   void CalcBandingFlags();
  103.  
  104.   // The following are pure virtual functions in TStreamable
  105.   // and so must be redefined here to make this an instance class.
  106. private:
  107.   virtual const Pchar streamableName() const
  108.   {
  109.     return "TPrinter";
  110.   }
  111. protected:
  112.   virtual Pvoid read(Ripstream)
  113.   {
  114.     return this;
  115.   }
  116.   virtual void write(Ropstream)
  117.   {}
  118.  
  119.   friend class _CLASSTYPE TPrinterSetupDlg;
  120. };
  121.  
  122. /*
  123. TPrinterSetupDlg is a dialog to modify which printer a TPrinter
  124. object is attached to. It displays all the active printers
  125. in the system allowing the user to select the desired printer.
  126. The dialog also allows the user to call up the printer's
  127. "setup" dialog for further configuration of the printer.
  128. */
  129.  
  130. #define ID_COMBO 100
  131. #define ID_SETUP 101
  132.  
  133. _CLASSDEF(TPrinterSetupDlg)
  134. class TPrinterSetupDlg: public TDialog
  135. {
  136. protected:
  137.   PTPrinter Printer;
  138. public:
  139.   TPrinterSetupDlg(PTWindowsObject AParent, LPSTR TemplateName, PTPrinter APrinter);
  140.   virtual ~TPrinterSetupDlg();
  141.   virtual void TransferData(WORD TransferFlag);
  142.   virtual void IDSetup(RTMessage)
  143.     = [ID_FIRST + ID_SETUP];
  144.   virtual void Cancel(RTMessage)
  145.     = [ID_FIRST + IDCANCEL];
  146. private:
  147.   Pchar OldDevice, OldDriver, OldPort;
  148.   PTNSCollection DeviceCollection;
  149. };
  150.  
  151. #define ID_TITLE 101
  152. #define ID_DEVICE 102
  153. #define ID_PORT 103
  154.  
  155. _CLASSDEF(TPrinterAbortDlg)
  156. class TPrinterAbortDlg: public TDialog
  157. {
  158. public:
  159.   TPrinterAbortDlg(PTWindowsObject AParent, Pchar Template,
  160.     Pchar Title, Pchar Device, Pchar Port);
  161.   virtual void SetupWindow();
  162.   virtual void WMCommand(RTMessage)
  163.     = [WM_FIRST + WM_COMMAND];
  164. };
  165.  
  166. #endif
  167.