printing.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: printing.h
  3. // Purpose: topic overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_printing Printing Framework Overview
  9. @tableofcontents
  10. The printing framework relies on the application to provide classes whose
  11. member functions can respond to particular requests, such as 'print this page'
  12. or 'does this page exist in the document?'. This method allows wxWidgets to
  13. take over the housekeeping duties of turning preview pages, calling the print
  14. dialog box, creating the printer device context, and so on: the application can
  15. concentrate on the rendering of the information onto a device context.
  16. In most cases, the only class you will need to derive from is wxPrintout; all
  17. others will be used as-is.
  18. A brief description of each class's role and how they work together follows.
  19. For the special case of printing under Unix, where various different printing
  20. backends have to be offered, please have a look at @ref overview_unixprinting.
  21. @see @ref group_class_printing
  22. @section overview_printing_printout wxPrintout
  23. A document's printing ability is represented in an application by a derived
  24. wxPrintout class. This class prints a page on request, and can be passed to the
  25. Print function of a wxPrinter object to actually print the document, or can be
  26. passed to a wxPrintPreview object to initiate previewing. The following code
  27. (from the printing sample) shows how easy it is to initiate printing,
  28. previewing and the print setup dialog, once the wxPrintout functionality has
  29. been defined. Notice the use of MyPrintout for both printing and previewing.
  30. All the preview user interface functionality is taken care of by wxWidgets. For
  31. more details on how MyPrintout is defined, please look at the printout sample
  32. code.
  33. @code
  34. case WXPRINT_PRINT:
  35. {
  36. wxPrinter printer;
  37. MyPrintout printout("My printout");
  38. printer.Print(this, &printout, true);
  39. break;
  40. }
  41. case WXPRINT_PREVIEW:
  42. {
  43. // Pass two printout objects: for preview, and possible printing.
  44. wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout);
  45. wxPreviewFrame *frame = new wxPreviewFrame(preview, this,
  46. "Demo Print Preview",
  47. wxPoint(100, 100),
  48. wxSize(600, 650));
  49. frame->Centre(wxBOTH);
  50. frame->Initialize();
  51. frame->Show(true);
  52. break;
  53. }
  54. @endcode
  55. wxPrintout assembles the printed page and (using your subclass's overrides)
  56. writes requested pages to a wxDC that is passed to it. This wxDC could be a
  57. wxMemoryDC (for displaying the preview image on-screen), a wxPrinterDC (for
  58. printing under MSW and Mac), or a wxPostScriptDC (for printing under GTK or
  59. generating PostScript output).
  60. The @ref overview_docview "document/view framework" creates a default
  61. wxPrintout object for every view, calling wxView::OnDraw() to achieve a
  62. prepackaged print/preview facility.
  63. If your window classes have a Draw(wxDC *dc) routine to do screen rendering,
  64. your wxPrintout subclass will typically call those routines to create portions
  65. of the image on your printout. Your wxPrintout subclass can also make its own
  66. calls to its wxDC to draw headers, footers, page numbers, etc.
  67. The scaling of the drawn image typically differs from the screen to the preview
  68. and printed images. This class provides a set of routines named
  69. FitThisSizeToXXX(), MapScreenSizeToXXX(), and GetLogicalXXXRect, which can be
  70. used to set the user scale and origin of the wxPrintout's DC so that your class
  71. can easily map your image to the printout withough getting into the details of
  72. screen and printer PPI and scaling. See the printing sample for examples of how
  73. these routines are used.
  74. @section overview_printing_printer wxPrinter
  75. Class wxPrinter encapsulates the platform-dependent print function with a common
  76. interface. In most cases, you will not need to derive a class from wxPrinter;
  77. simply create a wxPrinter object in your Print function as in the example above.
  78. @section overview_printing_printpreview wxPrintPreview
  79. Class wxPrintPreview manages the print preview process. Among other things, it
  80. constructs the wxDCs that get passed to your wxPrintout subclass for printing
  81. and manages the display of multiple pages, a zoomable preview image, and so
  82. forth. In most cases you will use this class as-is, but you can create your own
  83. subclass, for example, to change the layout or contents of the preview window.
  84. @section overview_printing_printerdc wxPrinterDC
  85. Class wxPrinterDC is the wxDC that represents the actual printed page under MSW
  86. and Mac. During printing, an object of this class will be passed to your derived
  87. wxPrintout object to draw upon. The size of the wxPrinterDC will depend on the
  88. paper orientation and the resolution of the printer.
  89. There are two important rectangles in printing: the <em>page rectangle</em>
  90. defines the printable area seen by the application, and under MSW and Mac, it
  91. is the printable area specified by the printer. (For PostScript printing, the
  92. page rectangle is the entire page.) The inherited function
  93. wxDC::GetSize() returns the page size in device pixels. The
  94. point (0,0) on the wxPrinterDC represents the top left corner of the page
  95. rectangle; that is, the page rect is given by wxRect(0, 0, w, h), where (w,h)
  96. are the values returned by GetSize.
  97. The <em>paper rectangle</em>, on the other hand, represents the entire paper
  98. area including the non-printable border. Thus, the coordinates of the top left
  99. corner of the paper rectangle will have small negative values, while the width
  100. and height will be somewhat larger than that of the page rectangle. The
  101. wxPrinterDC-specific function wxPrinterDC::GetPaperRect() returns the paper
  102. rectangle of the given wxPrinterDC.
  103. @section overview_printing_postscriptdc wxPostScriptDC
  104. Class wxPostScriptDC is the wxDC that represents the actual printed page under
  105. GTK and other PostScript printing. During printing, an object of this class
  106. will be passed to your derived wxPrintout object to draw upon. The size of the
  107. wxPostScriptDC will depend upon the wxPrintData used to construct it.
  108. Unlike a wxPrinterDC, there is no distinction between the page rectangle and
  109. the paper rectangle in a wxPostScriptDC; both rectangles are taken to represent
  110. the entire sheet of paper.
  111. @section overview_printing_printdialog wxPrintDialog
  112. Class wxPrintDialog puts up the standard print dialog, which allows you to
  113. select the page range for printing (as well as many other print settings, which
  114. may vary from platform to platform). You provide an object of type
  115. wxPrintDialogData to the wxPrintDialog at construction, which is used to
  116. populate the dialog.
  117. @section overview_printing_printdata wxPrintData
  118. Class wxPrintData is a subset of wxPrintDialogData that is used (internally) to
  119. initialize a wxPrinterDC or wxPostScriptDC. (In fact, a wxPrintData is a data
  120. member of a wxPrintDialogData and a wxPageSetupDialogData). Essentially,
  121. wxPrintData contains those bits of information from the two dialogs necessary
  122. to configure the wxPrinterDC or wxPostScriptDC (e.g., size, orientation, etc.).
  123. You might wish to create a global instance of this object to provide
  124. call-to-call persistence to your application's print settings.
  125. @section overview_printing_printdialogdata wxPrintDialogData
  126. Class wxPrintDialogData contains the settings entered by the user in the print
  127. dialog. It contains such things as page range, number of copies, and so forth.
  128. In most cases, you won't need to access this information; the framework takes
  129. care of asking your wxPrintout derived object for the pages requested by the
  130. user.
  131. @section overview_printing_pagesetupdialog wxPageSetupDialog
  132. Class wxPageSetupDialog puts up the standard page setup dialog, which allows
  133. you to specify the orientation, paper size, and related settings. You provide
  134. it with a wxPageSetupDialogData object at intialization, which is used to
  135. populate the dialog; when the dialog is dismissed, this object contains the
  136. settings chosen by the user, including orientation and/or page margins.
  137. Note that on Macintosh, the native page setup dialog does not contain entries
  138. that allow you to change the page margins. You can use the Mac-specific class
  139. wxMacPageMarginsDialog (which, like wxPageSetupDialog, takes a
  140. wxPageSetupDialogData object in its constructor) to provide this capability;
  141. see the printing sample for an example.
  142. @section overview_printing_pagesetupdialogdata wxPageSetupDialogData
  143. Class wxPageSetupDialogData contains settings affecting the page size (paper
  144. size), orientation, margins, and so forth. Note that not all platforms populate
  145. all fields; for example, the MSW page setup dialog lets you set the page
  146. margins while the Mac setup dialog does not.
  147. You will typically create a global instance of each of a wxPrintData and
  148. wxPageSetupDialogData at program initiation, which will contain the default
  149. settings provided by the system. Each time the user calls up either the
  150. wxPrintDialog or the wxPageSetupDialog, you pass these data structures to
  151. initialize the dialog values and to be updated by the dialog. The framework
  152. then queries these data structures to get information like the printed page
  153. range (from the wxPrintDialogData) or the paper size and/or page orientation
  154. (from the wxPageSetupDialogData).
  155. */