]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: print.h | |
e54c96f1 | 3 | // Purpose: interface of wxPreviewControlBar |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
9 | /** | |
10 | @class wxPreviewControlBar | |
7c913512 | 11 | |
23324ae1 | 12 | This is the default implementation of the preview control bar, a panel |
b1b95a65 FM |
13 | with buttons and a zoom control. |
14 | ||
15 | You can derive a new class from this and override some or all member functions | |
16 | to change the behaviour and appearance; or you can leave it as it is. | |
7c913512 | 17 | |
23324ae1 FM |
18 | @library{wxbase} |
19 | @category{printing} | |
7c913512 | 20 | |
e54c96f1 | 21 | @see wxPreviewFrame, wxPreviewCanvas, wxPrintPreview |
23324ae1 FM |
22 | */ |
23 | class wxPreviewControlBar : public wxPanel | |
24 | { | |
25 | public: | |
b1b95a65 FM |
26 | |
27 | /** | |
28 | Constructor. | |
29 | ||
30 | The @a buttons parameter may be a combination of the following, using the bitwise | |
31 | 'or' operator: | |
32 | ||
09a728e1 FM |
33 | @beginFlagTable |
34 | @flag{wxPREVIEW_PRINT} | |
b1b95a65 | 35 | Create a print button. |
09a728e1 | 36 | @flag{wxPREVIEW_NEXT} |
b1b95a65 | 37 | Create a next page button. |
09a728e1 | 38 | @flag{wxPREVIEW_PREVIOUS} |
b1b95a65 | 39 | Create a previous page button. |
09a728e1 | 40 | @flag{wxPREVIEW_ZOOM} |
b1b95a65 | 41 | Create a zoom control. |
09a728e1 | 42 | @flag{wxPREVIEW_DEFAULT} |
b1b95a65 FM |
43 | Equivalent to a combination of @c wxPREVIEW_PREVIOUS, @c wxPREVIEW_NEXT |
44 | and @c wxPREVIEW_ZOOM. | |
09a728e1 | 45 | @endFlagTable |
b1b95a65 FM |
46 | */ |
47 | wxPreviewControlBar(wxPrintPreview* preview, | |
48 | long buttons, | |
49 | wxWindow* parent, | |
50 | const wxPoint& pos = wxDefaultPosition, | |
51 | const wxSize& size = wxDefaultSize, | |
52 | long style = 0, | |
53 | const wxString& name = "panel"); | |
54 | ||
23324ae1 FM |
55 | /** |
56 | Destructor. | |
57 | */ | |
adaaa686 | 58 | virtual ~wxPreviewControlBar(); |
23324ae1 FM |
59 | |
60 | /** | |
61 | Creates buttons, according to value of the button style flags. | |
4a31b0c3 FM |
62 | |
63 | @todo which flags?? | |
23324ae1 | 64 | */ |
adaaa686 | 65 | virtual void CreateButtons(); |
23324ae1 FM |
66 | |
67 | /** | |
68 | Gets the print preview object associated with the control bar. | |
69 | */ | |
adaaa686 | 70 | virtual wxPrintPreviewBase* GetPrintPreview() const; |
23324ae1 FM |
71 | |
72 | /** | |
73 | Gets the current zoom setting in percent. | |
74 | */ | |
adaaa686 | 75 | virtual int GetZoomControl(); |
23324ae1 FM |
76 | |
77 | /** | |
78 | Sets the zoom control. | |
79 | */ | |
adaaa686 | 80 | virtual void SetZoomControl(int percent); |
23324ae1 | 81 | |
23324ae1 FM |
82 | }; |
83 | ||
84 | ||
e54c96f1 | 85 | |
23324ae1 FM |
86 | /** |
87 | @class wxPreviewCanvas | |
7c913512 | 88 | |
23324ae1 FM |
89 | A preview canvas is the default canvas used by the print preview |
90 | system to display the preview. | |
7c913512 | 91 | |
23324ae1 FM |
92 | @library{wxbase} |
93 | @category{printing} | |
7c913512 | 94 | |
e54c96f1 | 95 | @see wxPreviewFrame, wxPreviewControlBar, wxPrintPreview |
23324ae1 FM |
96 | */ |
97 | class wxPreviewCanvas : public wxScrolledWindow | |
98 | { | |
99 | public: | |
100 | /** | |
101 | Constructor. | |
102 | */ | |
103 | wxPreviewCanvas(wxPrintPreview* preview, wxWindow* parent, | |
104 | const wxPoint& pos = wxDefaultPosition, | |
105 | const wxSize& size = wxDefaultSize, | |
106 | long style = 0, | |
107 | const wxString& name = "canvas"); | |
108 | ||
109 | /** | |
110 | Destructor. | |
111 | */ | |
adaaa686 | 112 | virtual ~wxPreviewCanvas(); |
23324ae1 FM |
113 | |
114 | /** | |
b1b95a65 | 115 | Calls wxPrintPreview::PaintPage() to refresh the canvas. |
23324ae1 FM |
116 | */ |
117 | void OnPaint(wxPaintEvent& event); | |
118 | }; | |
119 | ||
6aacfc73 VZ |
120 | /** |
121 | Preview frame modality kind. | |
23324ae1 | 122 | |
6aacfc73 VZ |
123 | The elements of this enum can be used with wxPreviewFrame::Initialize() to |
124 | indicate how should the preview frame be shown. | |
125 | ||
126 | @since 2.9.2 | |
127 | */ | |
128 | enum wxPreviewFrameModalityKind | |
129 | { | |
130 | /** | |
131 | Disable all the other top level windows while the preview frame is shown. | |
132 | ||
133 | This is the default behaviour. | |
134 | */ | |
135 | wxPreviewFrame_AppModal, | |
136 | ||
137 | /** | |
138 | Disable only the parent window while the preview frame is shown. | |
139 | */ | |
140 | wxPreviewFrame_WindowModal, | |
141 | ||
142 | /** | |
143 | Show the preview frame non-modally and don't disable any other windows. | |
144 | */ | |
145 | wxPreviewFrame_NonModal | |
146 | }; | |
e54c96f1 | 147 | |
23324ae1 FM |
148 | /** |
149 | @class wxPreviewFrame | |
7c913512 | 150 | |
23324ae1 FM |
151 | This class provides the default method of managing the print preview interface. |
152 | Member functions may be overridden to replace functionality, or the | |
153 | class may be used without derivation. | |
7c913512 | 154 | |
23324ae1 FM |
155 | @library{wxbase} |
156 | @category{printing} | |
7c913512 | 157 | |
e54c96f1 | 158 | @see wxPreviewCanvas, wxPreviewControlBar, wxPrintPreview |
23324ae1 FM |
159 | */ |
160 | class wxPreviewFrame : public wxFrame | |
161 | { | |
162 | public: | |
163 | /** | |
b1b95a65 FM |
164 | Constructor. |
165 | ||
166 | Pass a print preview object plus other normal frame arguments. | |
23324ae1 FM |
167 | The print preview object will be destroyed by the frame when it closes. |
168 | */ | |
8067ee11 FM |
169 | wxPreviewFrame(wxPrintPreviewBase* preview, wxWindow* parent, |
170 | const wxString& title = "Print Preview", | |
23324ae1 | 171 | const wxPoint& pos = wxDefaultPosition, |
8067ee11 | 172 | const wxSize& size = wxDefaultSize, |
23324ae1 | 173 | long style = wxDEFAULT_FRAME_STYLE, |
408776d0 | 174 | const wxString& name = wxFrameNameStr); |
23324ae1 FM |
175 | |
176 | /** | |
177 | Destructor. | |
178 | */ | |
adaaa686 | 179 | virtual ~wxPreviewFrame(); |
23324ae1 FM |
180 | |
181 | /** | |
b1b95a65 FM |
182 | Creates a wxPreviewCanvas. |
183 | ||
184 | Override this function to allow a user-defined preview canvas object | |
185 | to be created. | |
23324ae1 | 186 | */ |
adaaa686 | 187 | virtual void CreateCanvas(); |
23324ae1 FM |
188 | |
189 | /** | |
b1b95a65 FM |
190 | Creates a wxPreviewControlBar. |
191 | ||
192 | Override this function to allow a user-defined preview control bar object | |
193 | to be created. | |
23324ae1 | 194 | */ |
adaaa686 | 195 | virtual void CreateControlBar(); |
23324ae1 FM |
196 | |
197 | /** | |
6aacfc73 VZ |
198 | Creates the preview canvas and control bar. |
199 | ||
200 | By default also disables the other existing top level windows to | |
201 | prepare for showing the preview frame modally. Since wxWidgets 2.9.2 | |
202 | this can be changed by specifying either wxPreviewFrame_WindowModal -- | |
203 | to disable just the parent window -- or wxPreviewFrame_NonModal -- to | |
204 | not disable any windows at all -- as @a kind parameter. | |
205 | ||
206 | This function must be called by the application prior to showing the frame. | |
b1b95a65 | 207 | |
6aacfc73 VZ |
208 | @param kind |
209 | The modality kind of preview frame. @since 2.9.2 | |
23324ae1 | 210 | */ |
6aacfc73 VZ |
211 | virtual void Initialize(wxPreviewFrameModalityKind kind |
212 | = wxPreviewFrame_AppModal); | |
23324ae1 FM |
213 | |
214 | /** | |
6aacfc73 | 215 | Enables any disabled frames in the application, and deletes the print preview |
23324ae1 FM |
216 | object, implicitly deleting any printout objects associated with the print |
217 | preview object. | |
218 | */ | |
219 | void OnCloseWindow(wxCloseEvent& event); | |
220 | }; | |
221 | ||
222 | ||
e54c96f1 | 223 | |
23324ae1 FM |
224 | /** |
225 | @class wxPrintPreview | |
7c913512 | 226 | |
23324ae1 FM |
227 | Objects of this class manage the print preview process. The object is passed |
228 | a wxPrintout object, and the wxPrintPreview object itself is passed to | |
229 | a wxPreviewFrame object. Previewing is started by initializing and showing | |
b1b95a65 FM |
230 | the preview frame. Unlike wxPrinter::Print(), flow of control returns to the |
231 | application immediately after the frame is shown. | |
7c913512 | 232 | |
82824b73 VS |
233 | @note |
234 | The preview shown is only exact on Windows. On other platforms, the wxDC | |
235 | used for preview is different from what is used for printing and the | |
236 | results may be significantly different, depending on how is the output | |
237 | created. In particular, printing code relying on wxDC::GetTextExtent() | |
238 | heavily (for example, wxHtmlEasyPrinting and other wxHTML classes do) is | |
239 | affected. It is recommended to use native preview functionality on | |
240 | platforms that offer it (OS X, GTK+). | |
241 | ||
23324ae1 FM |
242 | @library{wxbase} |
243 | @category{printing} | |
7c913512 | 244 | |
4a31b0c3 FM |
245 | @see @ref overview_printing, wxPrinterDC, wxPrintDialog, wxPrintout, wxPrinter, |
246 | wxPreviewCanvas, wxPreviewControlBar, wxPreviewFrame | |
23324ae1 FM |
247 | */ |
248 | class wxPrintPreview : public wxObject | |
249 | { | |
250 | public: | |
251 | /** | |
b1b95a65 FM |
252 | Constructor. |
253 | ||
254 | Pass a printout object, an optional printout object to be used for actual | |
255 | printing, and the address of an optional block of printer data, which will | |
256 | be copied to the print preview object's print data. | |
257 | ||
4a31b0c3 | 258 | If @a printoutForPrinting is non-@NULL, a @b "Print..." button will be placed on |
b1b95a65 FM |
259 | the preview frame so that the user can print directly from the preview interface. |
260 | ||
261 | @remarks | |
23324ae1 FM |
262 | Do not explicitly delete the printout objects once this destructor has been |
263 | called, since they will be deleted in the wxPrintPreview constructor. | |
4cc4bfaf | 264 | The same does not apply to the @a data argument. |
b1b95a65 | 265 | |
4a31b0c3 | 266 | Use IsOk() to check whether the wxPrintPreview object was created correctly. |
23324ae1 FM |
267 | */ |
268 | wxPrintPreview(wxPrintout* printout, | |
11e3af6e FM |
269 | wxPrintout* printoutForPrinting = NULL, |
270 | wxPrintDialogData* data = NULL); | |
23324ae1 FM |
271 | |
272 | /** | |
b1b95a65 FM |
273 | Destructor. |
274 | ||
275 | Deletes both print preview objects, so do not destroy these objects | |
23324ae1 FM |
276 | in your application. |
277 | */ | |
278 | ~wxPrinter(); | |
279 | ||
280 | /** | |
281 | Gets the preview window used for displaying the print preview image. | |
282 | */ | |
adaaa686 | 283 | virtual wxPreviewCanvas* GetCanvas() const; |
23324ae1 FM |
284 | |
285 | /** | |
286 | Gets the page currently being previewed. | |
287 | */ | |
adaaa686 | 288 | virtual int GetCurrentPage() const; |
23324ae1 FM |
289 | |
290 | /** | |
291 | Gets the frame used for displaying the print preview canvas | |
292 | and control bar. | |
293 | */ | |
adaaa686 | 294 | virtual wxFrame* GetFrame() const; |
23324ae1 FM |
295 | |
296 | /** | |
297 | Returns the maximum page number. | |
298 | */ | |
adaaa686 | 299 | virtual int GetMaxPage() const; |
23324ae1 FM |
300 | |
301 | /** | |
302 | Returns the minimum page number. | |
303 | */ | |
adaaa686 | 304 | virtual int GetMinPage() const; |
23324ae1 FM |
305 | |
306 | /** | |
307 | Gets the preview printout object associated with the wxPrintPreview object. | |
308 | */ | |
adaaa686 | 309 | virtual wxPrintout* GetPrintout() const; |
23324ae1 FM |
310 | |
311 | /** | |
312 | Gets the printout object to be used for printing from within the preview | |
313 | interface, | |
314 | or @NULL if none exists. | |
315 | */ | |
adaaa686 | 316 | virtual wxPrintout* GetPrintoutForPrinting() const; |
23324ae1 FM |
317 | |
318 | /** | |
b1b95a65 FM |
319 | Returns @true if the wxPrintPreview is valid, @false otherwise. |
320 | ||
321 | It could return @false if there was a problem initializing the printer | |
322 | device context (current printer not set, for example). | |
23324ae1 | 323 | */ |
adaaa686 | 324 | virtual bool IsOk() const; |
23324ae1 FM |
325 | |
326 | /** | |
327 | This refreshes the preview window with the preview image. | |
328 | It must be called from the preview window's OnPaint member. | |
b1b95a65 | 329 | |
23324ae1 FM |
330 | The implementation simply blits the preview bitmap onto |
331 | the canvas, creating a new preview bitmap if none exists. | |
332 | */ | |
43c48e1e | 333 | virtual bool PaintPage(wxPreviewCanvas* canvas, wxDC& dc); |
23324ae1 FM |
334 | |
335 | /** | |
336 | Invokes the print process using the second wxPrintout object | |
337 | supplied in the wxPrintPreview constructor. | |
338 | Will normally be called by the @b Print... panel item on the | |
339 | preview frame's control bar. | |
b1b95a65 FM |
340 | |
341 | Returns @false in case of error -- call wxPrinter::GetLastError() | |
342 | to get detailed information about the kind of the error. | |
23324ae1 | 343 | */ |
adaaa686 | 344 | virtual bool Print(bool prompt); |
23324ae1 FM |
345 | |
346 | /** | |
347 | Renders a page into a wxMemoryDC. Used internally by wxPrintPreview. | |
348 | */ | |
adaaa686 | 349 | virtual bool RenderPage(int pageNum); |
23324ae1 FM |
350 | |
351 | /** | |
352 | Sets the window to be used for displaying the print preview image. | |
353 | */ | |
adaaa686 | 354 | virtual void SetCanvas(wxPreviewCanvas* window); |
23324ae1 FM |
355 | |
356 | /** | |
357 | Sets the current page to be previewed. | |
358 | */ | |
43c48e1e | 359 | virtual bool SetCurrentPage(int pageNum); |
23324ae1 FM |
360 | |
361 | /** | |
362 | Sets the frame to be used for displaying the print preview canvas | |
363 | and control bar. | |
364 | */ | |
adaaa686 | 365 | virtual void SetFrame(wxFrame* frame); |
23324ae1 FM |
366 | |
367 | /** | |
368 | Associates a printout object with the wxPrintPreview object. | |
369 | */ | |
adaaa686 | 370 | virtual void SetPrintout(wxPrintout* printout); |
23324ae1 FM |
371 | |
372 | /** | |
4a31b0c3 | 373 | Sets the percentage preview zoom, and refreshes the preview canvas accordingly. |
23324ae1 | 374 | */ |
adaaa686 | 375 | virtual void SetZoom(int percent); |
23324ae1 FM |
376 | }; |
377 | ||
378 | ||
e54c96f1 | 379 | |
23324ae1 FM |
380 | /** |
381 | @class wxPrinter | |
7c913512 | 382 | |
23324ae1 | 383 | This class represents the Windows or PostScript printer, and is the vehicle |
b1b95a65 | 384 | through which printing may be launched by an application. |
4a31b0c3 | 385 | |
b1b95a65 FM |
386 | Printing can also be achieved through using of lower functions and classes, |
387 | but this and associated classes provide a more convenient and general method | |
388 | of printing. | |
7c913512 | 389 | |
23324ae1 FM |
390 | @library{wxbase} |
391 | @category{printing} | |
7c913512 | 392 | |
4a31b0c3 | 393 | @see @ref overview_printing, wxPrinterDC, wxPrintDialog, wxPrintout, wxPrintPreview |
23324ae1 FM |
394 | */ |
395 | class wxPrinter : public wxObject | |
396 | { | |
397 | public: | |
398 | /** | |
b1b95a65 FM |
399 | Constructor. |
400 | ||
401 | Pass an optional pointer to a block of print dialog data, which will be | |
402 | copied to the printer object's local data. | |
3c4f71cc | 403 | |
4cc4bfaf | 404 | @see wxPrintDialogData, wxPrintData |
23324ae1 | 405 | */ |
4cc4bfaf | 406 | wxPrinter(wxPrintDialogData* data = NULL); |
23324ae1 FM |
407 | |
408 | /** | |
409 | Creates the default printing abort window, with a cancel button. | |
410 | */ | |
43c48e1e | 411 | virtual wxWindow* CreateAbortWindow(wxWindow* parent, wxPrintout* printout); |
23324ae1 FM |
412 | |
413 | /** | |
414 | Returns @true if the user has aborted the print job. | |
415 | */ | |
adaaa686 | 416 | bool GetAbort() const; |
23324ae1 FM |
417 | |
418 | /** | |
b1b95a65 FM |
419 | Return last error. Valid after calling Print(), PrintDialog() or |
420 | wxPrintPreview::Print(). | |
4a31b0c3 FM |
421 | |
422 | These functions set last error to @c wxPRINTER_NO_ERROR if no error happened. | |
3c4f71cc | 423 | |
b1b95a65 | 424 | Returned value is one of the following: |
3c4f71cc | 425 | |
b1b95a65 | 426 | @beginTable |
4a31b0c3 FM |
427 | @row2col{wxPRINTER_NO_ERROR, No error happened.} |
428 | @row2col{wxPRINTER_CANCELLED, The user cancelled printing.} | |
429 | @row2col{wxPRINTER_ERROR, There was an error during printing.} | |
b1b95a65 | 430 | @endTable |
23324ae1 FM |
431 | */ |
432 | static wxPrinterError GetLastError(); | |
433 | ||
434 | /** | |
b1b95a65 FM |
435 | Returns the @ref overview_printing_printdata "print data" associated with |
436 | the printer object. | |
23324ae1 | 437 | */ |
adaaa686 | 438 | virtual wxPrintDialogData& GetPrintDialogData() const; |
23324ae1 FM |
439 | |
440 | /** | |
441 | Starts the printing process. Provide a parent window, a user-defined wxPrintout | |
b1b95a65 FM |
442 | object which controls the printing of a document, and whether the print dialog |
443 | should be invoked first. | |
444 | ||
445 | Print() could return @false if there was a problem initializing the printer device | |
446 | context (current printer not set, for example) or the user cancelled printing. | |
447 | Call GetLastError() to get detailed information about the kind of the error. | |
23324ae1 | 448 | */ |
fadc2df6 FM |
449 | virtual bool Print(wxWindow* parent, wxPrintout* printout, |
450 | bool prompt = true); | |
23324ae1 FM |
451 | |
452 | /** | |
b1b95a65 FM |
453 | Invokes the print dialog. |
454 | ||
455 | If successful (the user did not press Cancel and no error occurred), | |
4a31b0c3 FM |
456 | a suitable device context will be returned; otherwise @NULL is returned; |
457 | call GetLastError() to get detailed information about the kind of the error. | |
b1b95a65 FM |
458 | |
459 | @remarks | |
23324ae1 FM |
460 | The application must delete this device context to avoid a memory leak. |
461 | */ | |
adaaa686 | 462 | virtual wxDC* PrintDialog(wxWindow* parent); |
23324ae1 FM |
463 | |
464 | /** | |
465 | Default error-reporting function. | |
466 | */ | |
fadc2df6 FM |
467 | virtual void ReportError(wxWindow* parent, wxPrintout* printout, |
468 | const wxString& message); | |
23324ae1 FM |
469 | |
470 | /** | |
b1b95a65 FM |
471 | Invokes the print setup dialog. |
472 | ||
473 | @remarks | |
474 | The setup dialog is obsolete from Windows 95, though retained | |
475 | for backward compatibility. | |
23324ae1 | 476 | */ |
adaaa686 | 477 | virtual bool Setup(wxWindow* parent); |
23324ae1 FM |
478 | }; |
479 | ||
480 | ||
e54c96f1 | 481 | |
23324ae1 FM |
482 | /** |
483 | @class wxPrintout | |
7c913512 | 484 | |
b1b95a65 FM |
485 | This class encapsulates the functionality of printing out an application document. |
486 | ||
487 | A new class must be derived and members overridden to respond to calls such as | |
488 | OnPrintPage() and HasPage() and to render the print image onto an associated wxDC. | |
489 | Instances of this class are passed to wxPrinter::Print() or | |
23324ae1 | 490 | to a wxPrintPreview object to initiate printing or previewing. |
7c913512 | 491 | |
23324ae1 FM |
492 | Your derived wxPrintout is responsible for drawing both the preview image and |
493 | the printed page. If your windows' drawing routines accept an arbitrary DC as an | |
494 | argument, you can re-use those routines within your wxPrintout subclass to draw | |
495 | the printout image. You may also add additional drawing elements within your | |
496 | wxPrintout subclass, like headers, footers, and/or page numbers. However, the | |
497 | image on the printed page will often differ from the image drawn on the screen, | |
498 | as will the print preview image -- not just in the presence of headers and | |
499 | footers, but typically in scale. A high-resolution printer presents a much | |
500 | larger drawing surface (i.e., a higher-resolution DC); a zoomed-out preview | |
501 | image presents a much smaller drawing surface (lower-resolution DC). By using | |
502 | the routines FitThisSizeToXXX() and/or MapScreenSizeToXXX() within your | |
503 | wxPrintout subclass to set the user scale and origin of the associated DC, you | |
504 | can easily use a single drawing routine to draw on your application's windows, | |
505 | to create the print preview image, and to create the printed paper image, and | |
506 | achieve a common appearance to the preview image and the printed page. | |
7c913512 | 507 | |
23324ae1 FM |
508 | @library{wxbase} |
509 | @category{printing} | |
7c913512 | 510 | |
4a31b0c3 FM |
511 | @see @ref overview_printing, wxPrinterDC, wxPrintDialog, wxPageSetupDialog, |
512 | wxPrinter, wxPrintPreview | |
23324ae1 FM |
513 | */ |
514 | class wxPrintout : public wxObject | |
515 | { | |
516 | public: | |
517 | /** | |
b1b95a65 FM |
518 | Constructor. |
519 | ||
520 | Pass an optional title argument - the current filename would be a | |
521 | good idea. This will appear in the printing list (at least in MSW) | |
23324ae1 FM |
522 | */ |
523 | wxPrintout(const wxString& title = "Printout"); | |
524 | ||
525 | /** | |
526 | Destructor. | |
527 | */ | |
adaaa686 | 528 | virtual ~wxPrintout(); |
23324ae1 FM |
529 | |
530 | /** | |
531 | Set the user scale and device origin of the wxDC associated with this wxPrintout | |
532 | so that the given image size fits entirely within the page rectangle and the | |
b1b95a65 FM |
533 | origin is at the top left corner of the page rectangle. |
534 | ||
535 | On MSW and Mac, the page rectangle is the printable area of the page. | |
536 | On other platforms and PostScript printing, the page rectangle is the entire paper. | |
537 | ||
538 | Use this if you want your printed image as large as possible, but with the caveat | |
539 | that on some platforms, portions of the image might be cut off at the edges. | |
23324ae1 FM |
540 | */ |
541 | void FitThisSizeToPage(const wxSize& imageSize); | |
542 | ||
543 | /** | |
544 | Set the user scale and device origin of the wxDC associated with this wxPrintout | |
545 | so that the given image size fits entirely within the page margins set in the | |
b1b95a65 FM |
546 | given wxPageSetupDialogData object. |
547 | ||
548 | This function provides the greatest consistency across all platforms because it | |
549 | does not depend on having access to the printable area of the paper. | |
550 | ||
551 | @remarks | |
552 | On Mac, the native wxPageSetupDialog does not let you set the page margins; | |
553 | you'll have to provide your own mechanism, or you can use the Mac-only class | |
554 | wxMacPageMarginsDialog. | |
23324ae1 FM |
555 | */ |
556 | void FitThisSizeToPageMargins(const wxSize& imageSize, | |
557 | const wxPageSetupDialogData& pageSetupData); | |
558 | ||
559 | /** | |
560 | Set the user scale and device origin of the wxDC associated with this wxPrintout | |
561 | so that the given image size fits entirely within the paper and the origin is at | |
b1b95a65 FM |
562 | the top left corner of the paper. |
563 | ||
564 | Use this if you're managing your own page margins. | |
565 | ||
566 | @note | |
567 | With most printers, the region around the edges of the paper are not | |
568 | printable so that the edges of the image could be cut off. | |
569 | ||
23324ae1 FM |
570 | */ |
571 | void FitThisSizeToPaper(const wxSize& imageSize); | |
572 | ||
573 | /** | |
574 | Returns the device context associated with the printout (given to the printout | |
b1b95a65 FM |
575 | at start of printing or previewing). |
576 | ||
577 | The application can use GetDC() to obtain a device context to draw on. | |
578 | ||
579 | This will be a wxPrinterDC if printing under Windows or Mac, a wxPostScriptDC | |
580 | if printing on other platforms, and a wxMemoryDC if previewing. | |
23324ae1 | 581 | */ |
adaaa686 | 582 | wxDC* GetDC() const; |
23324ae1 FM |
583 | |
584 | /** | |
585 | Return the rectangle corresponding to the page margins specified by the given | |
586 | wxPageSetupDialogData object in the associated wxDC's logical coordinates for | |
b1b95a65 FM |
587 | the current user scale and device origin. |
588 | ||
589 | The page margins are specified with respect to the edges of the paper on all | |
590 | platforms. | |
23324ae1 | 591 | */ |
adaaa686 | 592 | wxRect GetLogicalPageMarginsRect(const wxPageSetupDialogData& pageSetupData) const; |
23324ae1 FM |
593 | |
594 | /** | |
b1b95a65 | 595 | Return the rectangle corresponding to the page in the associated wxDC 's |
7c913512 | 596 | logical coordinates for the current user scale and device origin. |
b1b95a65 FM |
597 | |
598 | On MSW and Mac, this will be the printable area of the paper. | |
599 | On other platforms and PostScript printing, this will be the full paper | |
600 | rectangle. | |
23324ae1 | 601 | */ |
adaaa686 | 602 | wxRect GetLogicalPageRect() const; |
23324ae1 FM |
603 | |
604 | /** | |
b1b95a65 | 605 | Return the rectangle corresponding to the paper in the associated wxDC 's |
23324ae1 FM |
606 | logical coordinates for the current user scale and device origin. |
607 | */ | |
adaaa686 | 608 | wxRect GetLogicalPaperRect() const; |
23324ae1 FM |
609 | |
610 | /** | |
611 | Returns the number of pixels per logical inch of the printer device context. | |
b1b95a65 | 612 | |
23324ae1 | 613 | Dividing the printer PPI by the screen PPI can give a suitable scaling factor |
b1b95a65 FM |
614 | for drawing text onto the printer. |
615 | ||
616 | Remember to multiply this by a scaling factor to take the preview DC size into | |
617 | account. | |
618 | Or you can just use the FitThisSizeToXXX() and MapScreenSizeToXXX routines below, | |
619 | which do most of the scaling calculations for you. | |
620 | ||
621 | @beginWxPythonOnly | |
622 | This method returns the output-only parameters as a tuple. | |
623 | @endWxPythonOnly | |
1058f652 MB |
624 | |
625 | @beginWxPerlOnly | |
626 | In wxPerl this method takes no arguments and returns a | |
627 | 2-element list (w, h). | |
628 | @endWxPerlOnly | |
23324ae1 | 629 | */ |
adaaa686 | 630 | void GetPPIPrinter(int* w, int* h) const; |
23324ae1 FM |
631 | |
632 | /** | |
633 | Returns the number of pixels per logical inch of the screen device context. | |
b1b95a65 | 634 | |
23324ae1 | 635 | Dividing the printer PPI by the screen PPI can give a suitable scaling factor |
b1b95a65 FM |
636 | for drawing text onto the printer. |
637 | ||
638 | If you are doing your own scaling, remember to multiply this by a scaling | |
639 | factor to take the preview DC size into account. | |
640 | ||
641 | @beginWxPythonOnly | |
642 | This method returns the output-only parameters as a tuple. | |
643 | @endWxPythonOnly | |
1058f652 MB |
644 | |
645 | @beginWxPerlOnly | |
646 | In wxPerl this method takes no arguments and returns a | |
647 | 2-element list (w, h). | |
648 | @endWxPerlOnly | |
23324ae1 | 649 | */ |
adaaa686 | 650 | void GetPPIScreen(int* w, int* h) const; |
23324ae1 FM |
651 | |
652 | /** | |
653 | Called by the framework to obtain information from the application about minimum | |
654 | and maximum page values that the user can select, and the required page range to | |
b1b95a65 FM |
655 | be printed. |
656 | ||
657 | By default this returns (1, 32000) for the page minimum and maximum values, and | |
658 | (1, 1) for the required page range. | |
659 | ||
3877c17e VZ |
660 | @a minPage must be greater than zero and @a maxPage must be greater |
661 | than @a minPage. | |
b1b95a65 FM |
662 | |
663 | @beginWxPythonOnly | |
664 | When this method is implemented in a derived Python class, it should be designed | |
665 | to take no parameters (other than the self reference) and to return a tuple of | |
666 | four integers. | |
667 | @endWxPythonOnly | |
23324ae1 | 668 | */ |
fadc2df6 FM |
669 | virtual void GetPageInfo(int* minPage, int* maxPage, int* pageFrom, |
670 | int* pageTo); | |
23324ae1 FM |
671 | |
672 | /** | |
673 | Returns the size of the printer page in millimetres. | |
b1b95a65 FM |
674 | |
675 | @beginWxPythonOnly | |
676 | This method returns the output-only parameters as a tuple. | |
677 | @endWxPythonOnly | |
1058f652 MB |
678 | |
679 | @beginWxPerlOnly | |
680 | In wxPerl this method takes no arguments and returns a | |
681 | 2-element list (w, h). | |
682 | @endWxPerlOnly | |
23324ae1 | 683 | */ |
adaaa686 | 684 | void GetPageSizeMM(int* w, int* h) const; |
23324ae1 FM |
685 | |
686 | /** | |
687 | Returns the size of the printer page in pixels, called the page rectangle. | |
b1b95a65 | 688 | |
23324ae1 FM |
689 | The page rectangle has a top left corner at (0,0) and a bottom right corner at |
690 | (w,h). These values may not be the same as the values returned from | |
b1b95a65 | 691 | wxDC::GetSize(); if the printout is being used for |
23324ae1 FM |
692 | previewing, a memory device context is used, which uses a bitmap size reflecting |
693 | the current preview zoom. The application must take this discrepancy into | |
694 | account if previewing is to be supported. | |
b1b95a65 FM |
695 | |
696 | @beginWxPythonOnly | |
697 | This method returns the output-only parameters as a tuple. | |
698 | @endWxPythonOnly | |
1058f652 MB |
699 | |
700 | @beginWxPerlOnly | |
701 | In wxPerl this method takes no arguments and returns a | |
702 | 2-element list (w, h). | |
703 | @endWxPerlOnly | |
23324ae1 | 704 | */ |
adaaa686 | 705 | void GetPageSizePixels(int* w, int* h) const; |
23324ae1 FM |
706 | |
707 | /** | |
708 | Returns the rectangle that corresponds to the entire paper in pixels, called the | |
b1b95a65 FM |
709 | paper rectangle. |
710 | ||
711 | This distinction between paper rectangle and page rectangle reflects the fact that | |
712 | most printers cannot print all the way to the edge of the paper. | |
713 | The page rectangle is a rectangle whose top left corner is at (0,0) and whose width | |
714 | and height are given by wxDC::GetPageSizePixels(). | |
715 | ||
716 | On MSW and Mac, the page rectangle gives the printable area of the paper, while the | |
717 | paper rectangle represents the entire paper, including non-printable borders. | |
718 | Thus, the rectangle returned by wxDC::GetPaperRectPixels() will have a top left corner | |
719 | whose coordinates are small negative numbers and the bottom right corner will have | |
720 | values somewhat larger than the width and height given by wxDC::GetPageSizePixels(). | |
721 | ||
722 | On other platforms and for PostScript printing, the paper is treated as if its entire | |
23324ae1 FM |
723 | area were printable, so this function will return the same rectangle as the page |
724 | rectangle. | |
725 | */ | |
adaaa686 | 726 | wxRect GetPaperRectPixels() const; |
23324ae1 FM |
727 | |
728 | /** | |
4a31b0c3 FM |
729 | Returns the title of the printout. |
730 | ||
731 | @todo the python note here was wrong | |
23324ae1 | 732 | */ |
adaaa686 | 733 | virtual wxString GetTitle() const; |
23324ae1 FM |
734 | |
735 | /** | |
736 | Should be overridden to return @true if the document has this page, or @false | |
b1b95a65 FM |
737 | if not. |
738 | ||
739 | Returning @false signifies the end of the document. By default, | |
23324ae1 FM |
740 | HasPage behaves as if the document has only one page. |
741 | */ | |
adaaa686 | 742 | virtual bool HasPage(int pageNum); |
23324ae1 FM |
743 | |
744 | /** | |
745 | Returns @true if the printout is currently being used for previewing. | |
1bd122dd VZ |
746 | |
747 | @see GetPreview() | |
23324ae1 | 748 | */ |
adaaa686 | 749 | virtual bool IsPreview() const; |
23324ae1 | 750 | |
1bd122dd VZ |
751 | /** |
752 | Returns the associated preview object if any. | |
753 | ||
754 | If this printout object is used for previewing, returns the associated | |
755 | wxPrintPreview. Otherwise returns @NULL. | |
756 | ||
757 | The returned pointer is not owned by the printout and must not be | |
758 | deleted. | |
759 | ||
760 | @see IsPreview() | |
761 | ||
762 | @since 2.9.1. | |
763 | */ | |
764 | wxPrintPreview *GetPreview() const; | |
765 | ||
23324ae1 FM |
766 | /** |
767 | Set the user scale and device origin of the wxDC associated with this wxPrintout | |
b1b95a65 FM |
768 | so that one screen pixel maps to one device pixel on the DC. |
769 | That is, the user scale is set to (1,1) and the device origin is set to (0,0). | |
770 | ||
771 | Use this if you want to do your own scaling prior to calling wxDC drawing calls, | |
772 | for example, if your underlying model is floating-point and you want to achieve | |
773 | maximum drawing precision on high-resolution printers. | |
774 | ||
775 | You can use the GetLogicalXXXRect() routines below to obtain the paper rectangle, | |
776 | page rectangle, or page margins rectangle to perform your own scaling. | |
777 | ||
778 | @note | |
779 | While the underlying drawing model of Mac OS X is floating-point, | |
780 | wxWidgets's drawing model scales from integer coordinates. | |
23324ae1 FM |
781 | */ |
782 | void MapScreenSizeToDevice(); | |
783 | ||
784 | /** | |
d13b34d3 | 785 | This sets the user scale of the wxDC associated with this wxPrintout to the same |
b1b95a65 FM |
786 | scale as MapScreenSizeToPaper() but sets the logical origin to the top left corner |
787 | of the page rectangle. | |
23324ae1 FM |
788 | */ |
789 | void MapScreenSizeToPage(); | |
790 | ||
791 | /** | |
d13b34d3 | 792 | This sets the user scale of the wxDC associated with this wxPrintout to the same |
b1b95a65 FM |
793 | scale as MapScreenSizeToPageMargins() but sets the logical origin to the top left |
794 | corner of the page margins specified by the given wxPageSetupDialogData object. | |
23324ae1 FM |
795 | */ |
796 | void MapScreenSizeToPageMargins(const wxPageSetupDialogData& pageSetupData); | |
797 | ||
798 | /** | |
799 | Set the user scale and device origin of the wxDC associated with this wxPrintout | |
800 | so that the printed page matches the screen size as closely as possible | |
801 | and the logical origin is in the top left corner of the paper rectangle. | |
4a31b0c3 FM |
802 | |
803 | That is, a 100-pixel object on screen should appear at the same size on the | |
804 | printed page. | |
b1b95a65 FM |
805 | (It will, of course, be larger or smaller in the preview image, depending on the |
806 | zoom factor.) | |
807 | ||
4c51a665 | 808 | Use this if you want WYSIWYG behaviour, e.g., in a text editor. |
23324ae1 FM |
809 | */ |
810 | void MapScreenSizeToPaper(); | |
811 | ||
812 | /** | |
813 | Shift the device origin by an amount specified in logical coordinates. | |
814 | */ | |
815 | void OffsetLogicalOrigin(wxCoord xoff, wxCoord yoff); | |
816 | ||
817 | /** | |
818 | Called by the framework at the start of document printing. Return @false from | |
b1b95a65 FM |
819 | this function cancels the print job. |
820 | ||
821 | OnBeginDocument() is called once for every copy printed. | |
822 | ||
823 | @remarks | |
824 | The base OnBeginDocument() must be called (and the return value | |
825 | checked) from within the overridden function, since it calls wxDC::StartDoc(). | |
826 | ||
827 | @beginWxPythonOnly | |
828 | If this method is overridden in a Python class then the base class version can | |
829 | be called by using the method <tt>base_OnBeginDocument(startPage, endPage)</tt>. | |
830 | @endWxPythonOnly | |
23324ae1 | 831 | */ |
adaaa686 | 832 | virtual bool OnBeginDocument(int startPage, int endPage); |
23324ae1 FM |
833 | |
834 | /** | |
b1b95a65 FM |
835 | Called by the framework at the start of printing. |
836 | ||
837 | OnBeginPrinting() is called once for every print job | |
838 | (regardless of how many copies are being printed). | |
23324ae1 | 839 | */ |
adaaa686 | 840 | virtual void OnBeginPrinting(); |
23324ae1 FM |
841 | |
842 | /** | |
b1b95a65 FM |
843 | Called by the framework at the end of document printing. |
844 | ||
845 | OnEndDocument() is called once for every copy printed. | |
846 | ||
847 | @remarks | |
848 | The base OnEndDocument() must be called from within the overridden function, | |
849 | since it calls wxDC::EndDoc(). | |
23324ae1 | 850 | */ |
adaaa686 | 851 | virtual void OnEndDocument(); |
23324ae1 FM |
852 | |
853 | /** | |
b1b95a65 FM |
854 | Called by the framework at the end of printing. |
855 | ||
856 | OnEndPrinting is called once for every print job | |
857 | (regardless of how many copies are being printed). | |
23324ae1 | 858 | */ |
adaaa686 | 859 | virtual void OnEndPrinting(); |
23324ae1 FM |
860 | |
861 | /** | |
862 | Called once by the framework before any other demands are made of the | |
b1b95a65 FM |
863 | wxPrintout object. |
864 | ||
865 | This gives the object an opportunity to calculate the number of pages | |
866 | in the document, for example. | |
23324ae1 | 867 | */ |
adaaa686 | 868 | virtual void OnPreparePrinting(); |
23324ae1 FM |
869 | |
870 | /** | |
871 | Called by the framework when a page should be printed. Returning @false cancels | |
b1b95a65 | 872 | the print job. |
23324ae1 | 873 | */ |
da1ed74c | 874 | virtual bool OnPrintPage(int pageNum) = 0; |
23324ae1 FM |
875 | |
876 | /** | |
877 | Set the device origin of the associated wxDC so that the current logical point | |
878 | becomes the new logical origin. | |
879 | */ | |
880 | void SetLogicalOrigin(wxCoord x, wxCoord y); | |
881 | }; | |
e54c96f1 | 882 |