home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-Developer.iso / NextLibrary / Frameworks / AppKit.framework / Versions / B / Headers / NSPrintOperation.h < prev    next >
Text File  |  1996-10-17  |  7KB  |  176 lines

  1. /*
  2.     NSPrintOperation.h
  3.     Application Kit
  4.     Copyright (c) 1994-1996, NeXT Software, Inc.
  5.     All rights reserved.
  6. */
  7.  
  8. /*
  9. NSPrintOperation controls the generation of PostScript code.  It is used to generate both Encapsulated PostScript output and PostScript print jobs.  It uses a specified View instance to produce the PostScript -- it doesn't do any PostScript generation itself.  Also, most parameters for PostScript generation are specified to the object through a PrintInfo object.  This object controls the user interface (the Print panel), the printing DPS context, and state for the particular operation, like job page order, the output stream, a copy of the PrintInfo, etc.
  10.  
  11. The object does keep a private instance of PrintInfo during the operation.  This should contain the settings that need to be preserved to duplicate the operation.  It may be copied at the end of the operation to be used in a subsequent operation.  So Print panel values like the starting and ending pages should be stored in the operation's PrintInfo, but the current page number should not -- it won't be reset during a subsequent operation.
  12.  
  13. If the current NSDPSContext's purpose is NSCopying or NSPrinting, there will be a current NSPrintOperation instance.  Drawing code should first check to see whether printing or copying is going on, and then it can assume there is an NSPrintOperation that can be consulted if needed.
  14.  
  15. The standard implementation for the print: method is very simple.  This code uses the global PrintInfo:
  16.  
  17. - print:sender {
  18.     [[NSPrintOperation printOperationWithView:self] runOperation];
  19.     return self;
  20. }
  21.  
  22. A document might have a documentPrint: method like:
  23.  
  24. - documentPrint:sender {
  25.     [[NSPrintOperation printOperationWithView:[self documentView] printInfo:[self printInfo]] runOperation];
  26.     return self;
  27. }
  28.  
  29. An application can produce a print job without the Print panel using code like this.  Note that the PrintInfo object would need to contain any non-default settings that would normally be collected from the Print panel -- for instance, one might use a copy of the PrintInfo from a previous print job.
  30.  
  31. - (void)printWithNoPanel {
  32.     NSPrintOperation *op;
  33.     
  34.     op = [NSPrintOperation printOperationWithView:[self myView] printInfo:[self previousPrintInfo]];
  35.     [op setShowPanels:NO];
  36.     [op runOperation];
  37. }
  38.  
  39.  
  40. */
  41.  
  42. #import <Foundation/NSObject.h>
  43. #import <Foundation/NSGeometry.h>
  44. #import <AppKit/AppKitDefines.h>
  45.  
  46. @class NSDPSContext;
  47. @class NSPrintPanel;
  48. @class NSView;
  49. @class NSPrintInfo;
  50. @class NSMutableData;
  51.  
  52. typedef enum _NSPrintingPageOrder {
  53.     NSDescendingPageOrder        = (-1),
  54.     NSSpecialPageOrder            = 0, // Tells spooler to not rearrange
  55.     NSAscendingPageOrder        = 1,
  56.     NSUnknownPageOrder            = 2  // No page order written out
  57. } NSPrintingPageOrder;
  58.  
  59.  
  60. /***** Exceptions *****/
  61. APPKIT_EXTERN NSString *NSPrintOperationExistsException;
  62.  
  63.  
  64. @interface NSPrintOperation : NSObject
  65. {
  66. @private
  67.     NSView *view;
  68.     NSPrintInfo *printInfo;
  69.     BOOL isEPS;
  70.     BOOL showPanels;
  71.     NSRect epsBounds;
  72.     NSMutableData *epsStream;
  73.     NSDPSContext *context;
  74.     NSPrintingPageOrder pageOrder;
  75.     NSPrintPanel *printPanel;
  76.     id _accessoryView;
  77.     NSMutableData *printStream;
  78.     int replyPort;
  79.     BOOL releaseData;
  80.     void *jobVars;
  81. #ifdef WIN32
  82.     id cancelPanel;
  83.     id  printServer; 
  84. #endif WIN32
  85. }
  86.  
  87. /* The following methods create an NSPrintOperation instance and make it the current print operation for the thread.  They raise an exception if there is already a current print operation.  These are the recommended methods for creating an NSPrintOperation instance.
  88. */
  89. + (NSPrintOperation *)printOperationWithView:(NSView *)aView;        // Use the global PrintInfo.
  90. + (NSPrintOperation *)printOperationWithView:(NSView *)aView printInfo:(NSPrintInfo *)aPrintInfo;
  91.  
  92. + (NSPrintOperation *)EPSOperationWithView:(NSView *)aView insideRect:(NSRect)rect toData:(NSMutableData *)data;
  93. + (NSPrintOperation *)EPSOperationWithView:(NSView *)aView insideRect:(NSRect)rect toData:(NSMutableData *)data printInfo:(NSPrintInfo *)aPrintInfo;
  94. + (NSPrintOperation *)EPSOperationWithView:(NSView *)aView insideRect:(NSRect)rect toPath:(NSString *)path printInfo:(NSPrintInfo *)aPrintInfo;
  95.  
  96. /* Set/get the current print operation for this thread.  If this is nil, there is no current operation.
  97. */
  98. + (NSPrintOperation *)currentOperation;
  99. + (void)setCurrentOperation:(NSPrintOperation *)operation;
  100.  
  101.  
  102. /* Designated initializer.  If called directly, returns a print job operation.  The specified PrintInfo object is copied -- that instance is *not* used in the operation.
  103. */
  104. - (id)initWithView:(NSView *)aView printInfo:(NSPrintInfo *)aPrintInfo;
  105.  
  106. /* Initializer for an EPS operation.
  107. */
  108. - (id)initEPSOperationWithView:(NSView *)aView insideRect:(NSRect)rect toData:(NSMutableData *)data printInfo:(NSPrintInfo *)aPrintInfo;
  109.  
  110. /* Returns whether the operation is doing EPS generation ("copying") or building a print job ("printing").
  111. */
  112. - (BOOL)isEPSOperation;
  113.  
  114. /* Do the print operation.  Returns YES if the operation completed successfully, NO if there was an error or the user cancelled the operation.  This can only be called once.  Create a new NSPrintOperation instance for each operation.  When this method completes, the object is removed from being the current operation if it is the current operation.
  115. */
  116. - (BOOL)runOperation;
  117.  
  118. /* Control whether panels are shown during the operation (doesn't necessarily include alerts).
  119. */
  120. - (void)setShowPanels:(BOOL)flag;
  121. - (BOOL)showPanels;
  122.  
  123. #ifndef STRICT_OPENSTEP
  124. /* Allow developers to supply their own Print panel if they like.
  125. */
  126. - (void)setPrintPanel:(NSPrintPanel *)panel;
  127. - (NSPrintPanel *)printPanel;
  128. #endif STRICT_OPENSTEP
  129.  
  130. /* Allow developers to supply an accessory view
  131. */
  132. - (void)setAccessoryView:(NSView *)aView;
  133. - (NSView *)accessoryView;
  134.  
  135. /* Set/get the current PrintInfo object for the operation.  Setting the PrintInfo object should be done very carefully.  The safest approach is to copy all the settings from the new object into current object, rather than replacing the object.
  136. */
  137. - (void)setPrintInfo:(NSPrintInfo *)aPrintInfo;
  138. - (NSPrintInfo *)printInfo;
  139.  
  140. /* The view being printed.
  141. */
  142. - (NSView *)view;
  143.  
  144. /* The current page number.
  145. */
  146. - (int)currentPage;
  147.  
  148. /* Set/get the page order that will be used to generate the pages in this job.  This is the physical page order of the pages.  It depends on the stacking order of the printer, the capability of the app to reverse page order, etc.
  149. */
  150. - (void)setPageOrder:(NSPrintingPageOrder)order;
  151. - (NSPrintingPageOrder)pageOrder;
  152.  
  153. /* The DPS context for the output of this operation.
  154. */
  155. - (NSDPSContext *)context;
  156.  
  157. /* Create the DPS context using the current PrintInfo settings, stream, etc.  Should not be called directly.  This is called before any output is generated by the operation.
  158. */
  159. - (NSDPSContext *)createContext;
  160.  
  161. /* Destroy the DPS context.  This is called at the end of the operation.  Should not be called directly.
  162. */
  163. - (void)destroyContext;
  164.  
  165. /* This spools the job, calls the Preview app, etc. -- whatever needs to be done to complete the operation.  Return YES is operation was completely successful, NO otherwise.  It is called after the job has been completely generated.  Should not be called directly.
  166. */
  167. - (BOOL)deliverResult;
  168.  
  169. /* Clean up an operation after it has been completed.  The object removes itself from being the current operation if it is the current operation.  
  170. */
  171. - (void)cleanUpOperation;
  172.  
  173.  
  174. @end
  175.  
  176.