]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tprint.tex
allow customizing the string values returned by wxGridCellBoolEditor::GetValue()...
[wxWidgets.git] / docs / latex / wx / tprint.tex
CommitLineData
a660d684
KB
1\section{Printing overview}\label{printingoverview}
2
7bcb11d3
JS
3Classes: \helpref{wxPrintout}{wxprintout},
4\helpref{wxPrinter}{wxprinter},
5\helpref{wxPrintPreview}{wxprintpreview},
6\helpref{wxPrinterDC}{wxprinterdc},
f415cab9 7\helpref{wxPostScriptDC}{wxpostscriptdc},
7bcb11d3
JS
8\helpref{wxPrintDialog}{wxprintdialog},
9\helpref{wxPrintData}{wxprintdata},
10\helpref{wxPrintDialogData}{wxprintdialogdata},
11\helpref{wxPageSetupDialog}{wxpagesetupdialog},
12\helpref{wxPageSetupDialogData}{wxpagesetupdialogdata}
a660d684 13
f415cab9
JS
14The printing framework relies on the application to provide classes whose member
15functions can respond to particular requests, such as `print this page' or `does
16this page exist in the document?'. This method allows wxWidgets to take over the
17housekeeping duties of turning preview pages, calling the print dialog box,
18creating the printer device context, and so on: the application can concentrate
a660d684 19on the rendering of the information onto a device context.
a660d684 20
f415cab9
JS
21In most cases, the only class you will need to derive from is
22\helpref{wxPrintout}{wxprintout}; all others will be used as-is.
23
24A brief description of each class's role and how they work together follows.
25
26\subsection{\helpref{wxPrintout}{wxprintout}}
a660d684 27
f415cab9
JS
28A document's printing ability is represented in an application by a derived
29wxPrintout class. This class prints a page on request, and can be passed to the
30Print function of a wxPrinter object to actually print the document, or can be
31passed to a wxPrintPreview object to initiate previewing. The following code
32(from the printing sample) shows how easy it is to initiate printing, previewing
33and the print setup dialog, once the wxPrintout functionality has been defined.
34Notice the use of MyPrintout for both printing and previewing. All the preview
35user interface functionality is taken care of by wxWidgets. For more details on how
36MyPrintout is defined, please look at the printout sample code.
a660d684
KB
37
38\begin{verbatim}
39 case WXPRINT_PRINT:
40 {
41 wxPrinter printer;
42 MyPrintout printout("My printout");
cc81d32f 43 printer.Print(this, &printout, true);
a660d684
KB
44 break;
45 }
46 case WXPRINT_PREVIEW:
47 {
48 // Pass two printout objects: for preview, and possible printing.
49 wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout);
dbd94b75 50 wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
a660d684
KB
51 frame->Centre(wxBOTH);
52 frame->Initialize();
cc81d32f 53 frame->Show(true);
a660d684
KB
54 break;
55 }
a660d684
KB
56\end{verbatim}
57
f415cab9
JS
58Class \helpref{wxPrintout}{wxprintout} assembles the printed page and (using
59your subclass's overrides) writes requested pages to a \helpref{wxDC}{wxdc} that
60is passed to it. This wxDC could be a \helpref{wxMemoryDC}{wxmemorydc} (for
61displaying the preview image on-screen), a \helpref{wxPrinterDC}{wxprinterdc}
62(for printing under MSW and Mac), or a \helpref{wxPostScriptDC}{wxpostscriptdc}
63(for printing under GTK or generating PostScript output).
64
65The \helpref{document/view framework}{docviewoverview} creates a default
66wxPrintout object for every view, calling wxView::OnDraw to achieve a
67prepackaged print/preview facility.
68
69If your window classes have a Draw(wxDC *dc) routine to do screen rendering,
70your wxPrintout subclass will typically call those routines to create portions
71of the image on your printout. Your wxPrintout subclass can also make its own
72calls to its wxDC to draw headers, footers, page numbers, etc.
73
74The scaling of the drawn image typically differs from the screen to the preview
75and printed images. This class provides a set of routines named
76FitThisSizeToXXX(), MapScreenSizeToXXX(), and GetLogicalXXXRect, which can be
77used to set the user scale and origin of the wxPrintout's DC so that your class
78can easily map your image to the printout withough getting into the details of
79screen and printer PPI and scaling. See the printing sample for examples of how
80these routines are used.
81
82\subsection{\helpref{wxPrinter}{wxprinter}}
83
84Class wxPrinter encapsulates the platform-dependent print function with a common
85interface. In most cases, you will not need to derive a class from wxPrinter;
86simply create a wxPrinter object in your Print function as in the example above.
87
88\subsection{\helpref{wxPrintPreview}{wxprintpreview}}
89
90Class wxPrintPreview manages the print preview process. Among other things, it
91constructs the wxDCs that get passed to your wxPrintout subclass for printing
92and manages the display of multiple pages, a zoomable preview image, and so
93forth. In most cases you will use this class as-is, but you can create your own
94subclass, for example, to change the layout or contents of the preview window.
95
96
97\subsection{\helpref{wxPrinterDC}{wxprinterdc}}
98
99Class wxPrinterDC is the wxDC that represents the actual printed page under MSW
100and Mac. During printing, an object of this class will be passed to your derived
101wxPrintout object to draw upon. The size of the wxPrinterDC will depend on the
102paper orientation and the resolution of the printer.
103
104There are two important rectangles in printing: the \em{page rectangle} defines
105the printable area seen by the application, and under MSW and Mac, it is the
106printable area specified by the printer. (For PostScript printing, the page
107rectangle is the entire page.) The inherited function
108\helpref{wxDC::GetSize}{wxdcgetsize} returns the page size in device pixels. The
109point (0,0) on the wxPrinterDC represents the top left corner of the page
110rectangle; that is, the page rect is given by wxRect(0, 0, w, h), where (w,h)
111are the values returned by GetSize.
112
113The \em{paper rectangle}, on the other hand, represents the entire paper area
114including the non-printable border. Thus, the coordinates of the top left corner
115of the paper rectangle will have small negative values, while the width and
116height will be somewhat larger than that of the page rectangle. The
117wxPrinterDC-specific function
118\helpref{wxPrinterDC::GetPaperRect}{wxprinterdcgetpaperrect} returns the paper
119rectangle of the given wxPrinterDC.
120
121\subsection{\helpref{wxPostScriptDC}{wxpostscriptdc}}
122
123Class wxPostScriptDC is the wxDC that represents the actual printed page under
124GTK and other PostScript printing. During printing, an object of this class will
125be passed to your derived wxPrintout object to draw upon. The size of the
126wxPostScriptDC will depend upon the \helpref{wxPrintData}{wxprintdata} used to
127construct it.
128
129Unlike a wxPrinterDC, there is no distinction between the page rectangle and the
130paper rectangle in a wxPostScriptDC; both rectangles are taken to represent the
131entire sheet of paper.
132
133\subsection{\helpref{wxPrintDialog}{wxprintdialog}}
134
135Class wxPrintDialog puts up the standard print dialog, which allows you to
136select the page range for printing (as well as many other print settings, which
137may vary from platform to platform). You provide an object of type
138\helpref{wxPrintDialogData}{wxprintdialogdata} to the wxPrintDialog at
139construction, which is used to populate the dialog.
140
141\subsection{\helpref{wxPrintData}{wxprintdata}}
142
143Class wxPrintData is a subset of wxPrintDialogData that is used (internally) to
144initialize a wxPrinterDC or wxPostScriptDC. (In fact, a wxPrintData is a data
145member of a wxPrintDialogData and a wxPageSetupDialogData). Essentially,
146wxPrintData contains those bits of information from the two dialogs necessary to
147configure the wxPrinterDC or wxPostScriptDC (e.g., size, orientation, etc.). You
148might wish to create a global instance of this object to provide call-to-call
149persistence to your application's print settings.
150
151\subsection{\helpref{wxPrintDialogData}{wxprintdialogdata}}
152
153Class wxPrintDialogData contains the settings entered by the user in the print
154dialog. It contains such things as page range, number of copies, and so forth.
155In most cases, you won't need to access this information; the framework takes
156care of asking your wxPrintout derived object for the pages requested by the
157user.
158
159\subsection{\helpref{wxPageSetupDialog}{wxpagesetupdialog}}
160
161Class wxPageSetupDialog puts up the standard page setup dialog, which allows you
162to specify the orientation, paper size, and related settings. You provide it
163with a wxPageSetupDialogData object at intialization, which is used to populate
164the dialog; when the dialog is dismissed, this object contains the settings
165chosen by the user, including orientation and/or page margins.
166
167Note that on Macintosh, the native page setup dialog does not contain entries
168that allow you to change the page margins. You can use the Mac-specific class
169wxMacPageMarginsDialog (which, like wxPageSetupDialog, takes a
170wxPageSetupDialogData object in its constructor) to provide this capability; see
171the printing sample for an example.
172
173\subsection{\helpref{wxPageSetupDialogData}{wxpagesetupdialogdata}}
174
175Class wxPageSetupDialogData contains settings affecting the page size (paper
176size), orientation, margins, and so forth. Note that not all platforms populate
177all fields; for example, the MSW page setup dialog lets you set the page margins
178while the Mac setup dialog does not.
179
180You will typically create a global instance of each of a wxPrintData and
181wxPageSetupDialogData at program initiation, which will contain the default
182settings provided by the system. Each time the user calls up either the
183wxPrintDialog or the wxPageSetupDialog, you pass these data structures to
184initialize the dialog values and to be updated by the dialog. The framework then
185queries these data structures to get information like the printed page range
186(from the wxPrintDialogData) or the paper size and/or page orientation (from the
187wxPageSetupDialogData).
188
189
190
c436b310
RR
191\section{Printing under Unix (GTK+)}\label{unixprinting}
192
193Printing under Unix has always been a cause of problems as Unix
194does not provide a standard way to display text and graphics
195on screen and print it to a printer using the same application
196programming interface - instead, displaying on screen is done
197via the X11 library while printing has to be done with using
198PostScript commands. This was particularly difficult to handle
199for the case of fonts with the result that only a selected
200number of application could offer WYSIWYG under Unix. Equally,
201wxWidgets offered its own printing implementation using PostScript
202which never really matched the screen display.
203
204Starting with version 2.8.X, the GNOME project provides printing
205support through the libgnomeprint and libgnomeprintui libraries
206by which especially the font problem is mostly solved. Beginning
207with version 2.5.4, the GTK+ port of wxWidgets can make use of
208these libraries if wxWidgets is configured accordingly and if the
209libraries are present. You need to configure wxWidgets with the
210{\it configure --with-gnomeprint} switch and you application will
211then search for the GNOME print libraries at runtime. If they
212are found, printing will be done through these, otherwise the
213application will fall back to the old PostScript printing code.
214Note that the application will not require the GNOME print libraries
215to be installed in order to run (there will be no dependency on
216these libraries).
217
218It is expected that the printing code that is currently implemented
219in the GNOME print libraries will be moved into GTK+ later.
dceb1c09 220