home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sibylft1.zip / DOC.DAT / DOC / SPCC / PRINTERS.PAS < prev    next >
Pascal/Delphi Source File  |  1997-04-07  |  6KB  |  156 lines

  1.  
  2. {************************************************}
  3. {                                                }
  4. { Speed-Pascal 2.0 Printer Support Unit          }
  5. {                                                }
  6. { Copyright (c) 1996-1997 Joerg Pleumann         }
  7. {                                                }
  8. { Please mail all bugs and suggestions to:       }
  9. {                                                }
  10. { Internet: pleumann @ uni-duisburg.de           }
  11. { FidoNet:  Joerg Pleumann @ 2:2448/136.6        }
  12. {                                                }
  13. {************************************************}
  14.  
  15. unit Printers;
  16.  
  17. interface
  18.  
  19. {$r Printers.srf}
  20.  
  21. uses
  22.   OS2Def, PmSpl, SysUtils, Classes, Forms;
  23.  
  24. type
  25.   EPrinter = class(Exception);
  26.     { Raised in case of printer errors. }
  27.  
  28.   TPrinterOrientation = (poPortrait, poLandscape);
  29.     { Used for Orientation property. }
  30.  
  31.   TPrinterState = (psNoHandle, psHandleIC, psHandleDC);
  32.     { Internal. }
  33.  
  34.   TQueueInfo = array[0..1023] of PRQINFO3;
  35.   PQueueInfo = ^TQueueInfo;
  36.     { Internal. }
  37.  
  38.   TDeviceInfo = array[0..1023] of PRDINFO3;
  39.   PDeviceInfo = ^TDeviceInfo;
  40.     { Internal. }
  41.  
  42.   TPrinter = class
  43.   private
  44.     FQueues: PQueueInfo;       // Pointer to queue info buffer
  45.     FQueueCount: LongInt;      // Number of queues available
  46.     FQueueIndex: LongInt;      // Currently selected queue
  47.     FQueueSize:  LongInt;      // Size of queue info buffer
  48.  
  49.     FDevices: PDeviceInfo;     // Pointer to device info buffer
  50.     FDeviceCount: LongInt;     // Number of devices available
  51.     FDeviceIndex: LongInt;     // Currently selected device
  52.     FDeviceSize:  LongInt;     // Size of device info buffer
  53.  
  54.     FDeviceName: cstring[32];  // Name of currently selected device
  55.     FDeviceData: DEVOPENSTRUC; // Data needed to open device contect
  56.  
  57.     FPrintToFile: Boolean;     // Print to file instead of printer?
  58.     FFileName: AnsiString;     // Name of output file
  59.  
  60.     FPrinters: TStrings;       // Printer names visible to end user
  61.  
  62.     FHandle: HDC;              // Printer device context
  63.     FCanvas: TCanvas;          // Printer canvas
  64.  
  65.     FState: TPrinterState;     // Current state of printer object
  66.  
  67.     FTitle: AnsiString;        // Document title
  68.     FCopies: LongInt;          // Number of copies to be printed
  69.     FAborted: Boolean;         // True when last job was aborted
  70.     FPageNumber: LongInt;      // Number of current page
  71.  
  72.     procedure Error(ID: Word);
  73.     procedure FmtError(ID: Word; Args: array of const);
  74.     function GetOrientation: TPrinterOrientation;
  75.     function GetPageHeight: LongInt;
  76.     function GetPageWidth: LongInt;
  77.     procedure GetPrinterInfo;
  78.     function GetPrinting: Boolean;
  79.     procedure SetFileName(Value: AnsiString);
  80.     procedure SetPrinterIndex(Value: LongInt);
  81.     procedure SetPrinterState(Value: TPrinterState);
  82.     procedure SetPrintToFile(Value: Boolean);
  83.  
  84.   public
  85.     constructor Create;
  86.       { Create printer object. One printer object
  87.         is automatically created and stored in the
  88.         Printer variable. No need to create more
  89.         printer objects. }
  90.     destructor Destroy; override;
  91.       { Destroy printer object. The instance stored
  92.         in the Printer variable is automatically
  93.         destroyed in the unit's finalization code. }
  94.  
  95.     procedure Abort;
  96.       { Abort current document. Only available inside
  97.         document. }
  98.     procedure BeginDoc;
  99.       { Begin new document. Only available when last
  100.         job has either been completed or aborted. }
  101.     procedure EndDoc;
  102.       { End document. Only available inside document. }
  103.     procedure NewPage;
  104.       { Start a new, blank page. Only available inside
  105.         document. }
  106.     procedure OptionsDlg;
  107.       { Display job properties dialog for currently
  108.         selected printer. Allow the user to change
  109.         job properties. Only available while not in
  110.         document. }
  111.  
  112.     property Aborted: Boolean read FAborted;
  113.       { True if last job has been aborted. }
  114.     property Canvas: TCanvas read FCanvas;
  115.       { Printer canvas. Only available inside
  116.         document. }
  117.     property Copies: LongInt read FCopies write FCopies;
  118.       { Number of copies to be printed of next
  119.         document. Must be set before BeginDoc,
  120.         otherwise ignored. }
  121.     property FileName: AnsiString read FFileName write SetFileName;
  122.       { Destination when printing to a file. }
  123.     property Handle: HDC read FHandle;
  124.       { Printer device context. }
  125.     property Orientation: TPrinterOrientation read GetOrientation;
  126.       { Page orientation. }
  127.     property PageHeight: LongInt read GetPageHeight;
  128.       { Page height in pixels. }
  129.     property PageNumber: LongInt read FPageNumber;
  130.       { Current page number. }
  131.     property PageWidth: LongInt read GetPageWidth;
  132.       { Page width in pixels. }
  133.     property PrinterIndex: LongInt read FQueueIndex write SetPrinterIndex;
  134.       { Currently selected printer. Change only while not
  135.         in document. Set PrinterIndex to -1 for system
  136.         default printer. }
  137.     property Printers: TStrings read FPrinters;
  138.       { Names of printers (aka queues) available. If
  139.         Printers.Count is 0, the system doesn't have
  140.         any printers installed. }
  141.     property Printing: Boolean read GetPrinting;
  142.       { True when inside document. }
  143.     property PrintToFile: Boolean read FPrintToFile write SetPrintToFile;
  144.       { When True, output is sent to file specified
  145.         in the FileName property. }
  146.     property Title: AnsiString read FTitle write FTitle;
  147.       { Title of next document. Must be set before
  148.         BeginDoc, otherwise ignored. }
  149.   end;
  150.  
  151. var
  152.   Printer: TPrinter;
  153.  
  154. implementation
  155.  
  156.