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