]>
git.saurik.com Git - wxWidgets.git/blob - interface/print.h
5ad64366d1b41d7904114dbabaf046767f841b0e
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxPreviewControlBar class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxPreviewControlBar
13 This is the default implementation of the preview control bar, a panel
14 with buttons and a zoom control. You can derive a new class from this and
15 override some or all member functions to change the behaviour and appearance;
16 or you can leave it as it is.
22 wxPreviewFrame, wxPreviewCanvas, wxPrintPreview
24 class wxPreviewControlBar
: public wxPanel
30 ~wxPreviewControlBar();
33 Creates buttons, according to value of the button style flags.
38 Gets the print preview object associated with the control bar.
40 wxPrintPreview
* GetPrintPreview();
43 Gets the current zoom setting in percent.
48 Sets the zoom control.
50 void SetZoomControl(int percent
);
54 The buttons parameter may be a combination of the following, using the bitwise
59 Create a print button.
63 Create a next page button.
67 Create a previous page button.
71 Create a zoom control.
75 Equivalent to a combination of wxPREVIEW_PREVIOUS, wxPREVIEW_NEXT and
78 wxPreviewControlBar(wxPrintPreview
* preview
, long buttons
,
80 const wxPoint
& pos
= wxDefaultPosition
,
81 const wxSize
& size
= wxDefaultSize
,
83 const wxString
& name
= "panel");
88 @class wxPreviewCanvas
91 A preview canvas is the default canvas used by the print preview
92 system to display the preview.
98 wxPreviewFrame, wxPreviewControlBar, wxPrintPreview
100 class wxPreviewCanvas
: public wxScrolledWindow
106 wxPreviewCanvas(wxPrintPreview
* preview
, wxWindow
* parent
,
107 const wxPoint
& pos
= wxDefaultPosition
,
108 const wxSize
& size
= wxDefaultSize
,
110 const wxString
& name
= "canvas");
118 Calls wxPrintPreview::PaintPage to refresh the canvas.
120 void OnPaint(wxPaintEvent
& event
);
125 @class wxPreviewFrame
128 This class provides the default method of managing the print preview interface.
129 Member functions may be overridden to replace functionality, or the
130 class may be used without derivation.
136 wxPreviewCanvas, wxPreviewControlBar, wxPrintPreview
138 class wxPreviewFrame
: public wxFrame
142 Constructor. Pass a print preview object plus other normal frame arguments.
143 The print preview object will be destroyed by the frame when it closes.
145 wxPreviewFrame(wxPrintPreview
* preview
, wxWindow
* parent
,
146 const wxString
& title
,
147 const wxPoint
& pos
= wxDefaultPosition
,
148 const wxSize
& size size
= wxDefaultSize
,
149 long style
= wxDEFAULT_FRAME_STYLE
,
150 const wxString
& name
= "frame");
158 Creates a wxPreviewCanvas. Override this function to allow
159 a user-defined preview canvas object to be created.
164 Creates a wxPreviewControlBar. Override this function to allow
165 a user-defined preview control bar object to be created.
167 void CreateControlBar();
170 Creates the preview canvas and control bar, and calls
171 wxWindow::MakeModal(@true) to disable other top-level windows
173 This function should be called by the application prior to
179 Enables the other frames in the application, and deletes the print preview
180 object, implicitly deleting any printout objects associated with the print
183 void OnCloseWindow(wxCloseEvent
& event
);
188 @class wxPrintPreview
191 Objects of this class manage the print preview process. The object is passed
192 a wxPrintout object, and the wxPrintPreview object itself is passed to
193 a wxPreviewFrame object. Previewing is started by initializing and showing
194 the preview frame. Unlike wxPrinter::Print, flow of control returns to the
196 immediately after the frame is shown.
202 @ref overview_printingoverview "Printing framework overview", wxPrinterDC,
203 wxPrintDialog, wxPrintout, wxPrinter, wxPreviewCanvas, wxPreviewControlBar, wxPreviewFrame.
205 class wxPrintPreview
: public wxObject
209 Constructor. Pass a printout object, an optional printout object to be
210 used for actual printing, and the address of an optional
211 block of printer data, which will be copied to the print preview object's
213 If @a printoutForPrinting is non-@NULL, a @b Print... button will be placed on
215 preview frame so that the user can print directly from the preview interface.
216 Do not explicitly delete the printout objects once this destructor has been
217 called, since they will be deleted in the wxPrintPreview constructor.
218 The same does not apply to the @a data argument.
219 Test the Ok member to check whether the wxPrintPreview object was created
221 Ok could return @false if there was a problem initializing the printer device
223 (current printer not set, for example).
225 wxPrintPreview(wxPrintout
* printout
,
226 wxPrintout
* printoutForPrinting
,
227 wxPrintData
* data
= NULL
);
230 Destructor. Deletes both print preview objects, so do not destroy these objects
236 Gets the preview window used for displaying the print preview image.
238 wxPreviewCanvas
* GetCanvas();
241 Gets the page currently being previewed.
243 int GetCurrentPage();
246 Gets the frame used for displaying the print preview canvas
252 Returns the maximum page number.
257 Returns the minimum page number.
262 Gets the preview printout object associated with the wxPrintPreview object.
264 wxPrintout
* GetPrintout();
267 Gets the printout object to be used for printing from within the preview
269 or @NULL if none exists.
271 wxPrintout
* GetPrintoutForPrinting();
274 Returns @true if the wxPrintPreview is valid, @false otherwise. It could return
275 @false if there was a
276 problem initializing the printer device context (current printer not set, for
282 This refreshes the preview window with the preview image.
283 It must be called from the preview window's OnPaint member.
284 The implementation simply blits the preview bitmap onto
285 the canvas, creating a new preview bitmap if none exists.
287 bool PaintPage(wxPreviewCanvas
* canvas
, wxDC dc
);
290 Invokes the print process using the second wxPrintout object
291 supplied in the wxPrintPreview constructor.
292 Will normally be called by the @b Print... panel item on the
293 preview frame's control bar.
294 Returns @false in case of error -- call
295 wxPrinter::GetLastError to get detailed
296 information about the kind of the error.
298 bool Print(bool prompt
);
301 Renders a page into a wxMemoryDC. Used internally by wxPrintPreview.
303 bool RenderPage(int pageNum
);
306 Sets the window to be used for displaying the print preview image.
308 void SetCanvas(wxPreviewCanvas
* window
);
311 Sets the current page to be previewed.
313 void SetCurrentPage(int pageNum
);
316 Sets the frame to be used for displaying the print preview canvas
319 void SetFrame(wxFrame
* frame
);
322 Associates a printout object with the wxPrintPreview object.
324 void SetPrintout(wxPrintout
* printout
);
327 Sets the percentage preview zoom, and refreshes the preview canvas
330 void SetZoom(int percent
);
338 This class represents the Windows or PostScript printer, and is the vehicle
340 which printing may be launched by an application. Printing can also
341 be achieved through using of lower functions and classes, but
342 this and associated classes provide a more convenient and general
349 @ref overview_printingoverview "Printing framework overview", wxPrinterDC,
350 wxPrintDialog, wxPrintout, wxPrintPreview.
352 class wxPrinter
: public wxObject
356 Constructor. Pass an optional pointer to a block of print
357 dialog data, which will be copied to the printer object's local data.
359 @see wxPrintDialogData, wxPrintData
361 wxPrinter(wxPrintDialogData
* data
= NULL
);
364 Creates the default printing abort window, with a cancel button.
366 void CreateAbortWindow(wxWindow
* parent
, wxPrintout
* printout
);
369 Returns @true if the user has aborted the print job.
374 Return last error. Valid after calling Print(),
376 wxPrintPreview::Print. These functions
377 set last error to @b wxPRINTER_NO_ERROR if no error happened.
378 Returned value is one of the following:
380 @b wxPRINTER_NO_ERROR
384 @b wxPRINTER_CANCELLED
386 The user cancelled printing.
390 There was an error during printing.
392 static wxPrinterError
GetLastError();
395 Returns the @ref overview_wxprintdata "print data" associated with the printer
398 wxPrintDialogData
GetPrintDialogData();
401 Starts the printing process. Provide a parent window, a user-defined wxPrintout
402 object which controls
403 the printing of a document, and whether the print dialog should be invoked
405 Print could return @false if there was a problem initializing the printer device
407 (current printer not set, for example) or the user cancelled printing. Call
408 GetLastError() to get detailed
409 information about the kind of the error.
411 bool Print(wxWindow
* parent
, wxPrintout
* printout
,
415 Invokes the print dialog. If successful (the user did not press Cancel
416 and no error occurred), a suitable device context will be returned
417 (otherwise @NULL is returned -- call
418 GetLastError() to get detailed
419 information about the kind of the error).
420 The application must delete this device context to avoid a memory leak.
422 wxDC
* PrintDialog(wxWindow
* parent
);
425 Default error-reporting function.
427 void ReportError(wxWindow
* parent
, wxPrintout
* printout
,
428 const wxString
& message
);
431 Invokes the print setup dialog. Note that the setup dialog is obsolete from
432 Windows 95, though retained for backward compatibility.
434 bool Setup(wxWindow
* parent
);
442 This class encapsulates the functionality of printing out an application
443 document. A new class must be derived and members overridden to respond to calls
444 such as OnPrintPage and HasPage and to render the print image onto an associated
445 wxDC. Instances of this class are passed to wxPrinter::Print or
446 to a wxPrintPreview object to initiate printing or previewing.
448 Your derived wxPrintout is responsible for drawing both the preview image and
449 the printed page. If your windows' drawing routines accept an arbitrary DC as an
450 argument, you can re-use those routines within your wxPrintout subclass to draw
451 the printout image. You may also add additional drawing elements within your
452 wxPrintout subclass, like headers, footers, and/or page numbers. However, the
453 image on the printed page will often differ from the image drawn on the screen,
454 as will the print preview image -- not just in the presence of headers and
455 footers, but typically in scale. A high-resolution printer presents a much
456 larger drawing surface (i.e., a higher-resolution DC); a zoomed-out preview
457 image presents a much smaller drawing surface (lower-resolution DC). By using
458 the routines FitThisSizeToXXX() and/or MapScreenSizeToXXX() within your
459 wxPrintout subclass to set the user scale and origin of the associated DC, you
460 can easily use a single drawing routine to draw on your application's windows,
461 to create the print preview image, and to create the printed paper image, and
462 achieve a common appearance to the preview image and the printed page.
468 @ref overview_printingoverview "Printing framework overview", wxPrinterDC,
469 wxPrintDialog, wxPageSetupDialog, wxPrinter, wxPrintPreview
471 class wxPrintout
: public wxObject
475 Constructor. Pass an optional title argument - the current filename would be a
476 good idea. This will appear in the printing list
479 wxPrintout(const wxString
& title
= "Printout");
487 Set the user scale and device origin of the wxDC associated with this wxPrintout
488 so that the given image size fits entirely within the page rectangle and the
489 origin is at the top left corner of the page rectangle. On MSW and Mac, the page
490 rectangle is the printable area of the page. On other platforms and PostScript
491 printing, the page rectangle is the entire paper. Use this if you want your
492 printed image as large as possible, but with the caveat that on some platforms,
493 portions of the image might be cut off at the edges.
495 void FitThisSizeToPage(const wxSize
& imageSize
);
498 Set the user scale and device origin of the wxDC associated with this wxPrintout
499 so that the given image size fits entirely within the page margins set in the
500 given wxPageSetupDialogData object. This function provides the greatest
501 consistency across all platforms because it does not depend on having access to
502 the printable area of the paper. Note that on Mac, the native wxPageSetupDialog
503 does not let you set the page margins; you'll have to provide your own
505 or you can use the Mac-only class wxMacPageMarginsDialog.
507 void FitThisSizeToPageMargins(const wxSize
& imageSize
,
508 const wxPageSetupDialogData
& pageSetupData
);
511 Set the user scale and device origin of the wxDC associated with this wxPrintout
512 so that the given image size fits entirely within the paper and the origin is at
513 the top left corner of the paper. Note that with most printers, the region
514 around the edges of the paper are not printable so that the edges of the image
515 could be cut off. Use this if you're managing your own page margins.
517 void FitThisSizeToPaper(const wxSize
& imageSize
);
520 Returns the device context associated with the printout (given to the printout
522 printing or previewing). This will be a wxPrinterDC if printing under Windows
524 a wxPostScriptDC if printing on other platforms, and a wxMemoryDC if previewing.
529 Return the rectangle corresponding to the page margins specified by the given
530 wxPageSetupDialogData object in the associated wxDC's logical coordinates for
532 current user scale and device origin. The page margins are specified
533 with respect to the edges of the paper on all platforms.
535 wxRect
GetLogicalPageMarginsRect(const wxPageSetupDialogData
& pageSetupData
);
538 Return the rectangle corresponding to the page in the associated wxDC's
539 logical coordinates for the current user scale and device origin.
540 On MSW and Mac, this will be the printable area of the paper. On other platforms
541 and PostScript printing, this will be the full paper rectangle.
543 wxRect
GetLogicalPageRect();
546 Return the rectangle corresponding to the paper in the associated wxDC's
547 logical coordinates for the current user scale and device origin.
549 wxRect
GetLogicalPaperRect();
552 Returns the number of pixels per logical inch of the printer device context.
553 Dividing the printer PPI by the screen PPI can give a suitable scaling factor
554 for drawing text onto the printer. Remember to multiply this by a scaling factor
555 to take the preview DC size into account. Or you can just use the
556 FitThisSizeToXXX() and MapScreenSizeToXXX routines below, which do most of the
557 scaling calculations for you.
559 void GetPPIPrinter(int* w
, int* h
);
562 Returns the number of pixels per logical inch of the screen device context.
563 Dividing the printer PPI by the screen PPI can give a suitable scaling factor
564 for drawing text onto the printer. If you are doing your own scaling, remember
565 to multiply this by a scaling factor to take the preview DC size into account.
567 void GetPPIScreen(int* w
, int* h
);
570 Called by the framework to obtain information from the application about minimum
571 and maximum page values that the user can select, and the required page range to
572 be printed. By default this returns 1, 32000 for the page minimum and maximum
573 values, and 1, 1 for the required page range.
574 If @a minPage is zero, the page number controls in the print dialog will be
577 void GetPageInfo(int* minPage
, int* maxPage
, int* pageFrom
,
581 Returns the size of the printer page in millimetres.
583 void GetPageSizeMM(int* w
, int* h
);
586 Returns the size of the printer page in pixels, called the page rectangle.
587 The page rectangle has a top left corner at (0,0) and a bottom right corner at
588 (w,h). These values may not be the same as the values returned from
589 wxDC::GetSize; if the printout is being used for
590 previewing, a memory device context is used, which uses a bitmap size reflecting
591 the current preview zoom. The application must take this discrepancy into
592 account if previewing is to be supported.
594 void GetPageSizePixels(int* w
, int* h
);
597 Returns the rectangle that corresponds to the entire paper in pixels, called the
598 paper rectangle. This distinction between paper rectangle and page
599 rectangle reflects the fact that most printers cannot print all the way to the
600 edge of the paper. The page rectangle is a rectangle whose top left corner is at
601 (0,0) and whose width and height are given by
602 wxDC::GetPageSizePixels. On MSW and Mac,
603 the page rectangle gives the printable area of the paper, while the paper
604 rectangle represents the entire paper, including non-printable borders. Thus,
605 the rectangle returned by GetPaperRectPixels will have a top left corner whose
606 coordinates are small negative numbers and the bottom right corner will have
607 values somewhat larger than the width and height given by
608 wxDC::GetPageSizePixels. On other
609 platforms and for PostScript printing, the paper is treated as if its entire
610 area were printable, so this function will return the same rectangle as the page
613 wxRect
GetPaperRectPixels();
616 Returns the title of the printout
621 Should be overridden to return @true if the document has this page, or @false
622 if not. Returning @false signifies the end of the document. By default,
623 HasPage behaves as if the document has only one page.
625 bool HasPage(int pageNum
);
628 Returns @true if the printout is currently being used for previewing.
633 Set the user scale and device origin of the wxDC associated with this wxPrintout
634 so that one screen pixel maps to one device pixel on the DC. That is, the user
635 scale is set to (1,1) and the device origin is set to (0,0). Use this if you
636 want to do your own scaling prior to calling wxDC drawing calls, for example, if
637 your underlying model is floating-point and you want to achieve maximum drawing
638 precision on high-resolution printers. (Note that while the underlying drawing
639 model of Mac OS X is floating-point, wxWidgets's drawing model scales from
641 coordinates.) You can use the GetLogicalXXXRect() routines below to obtain the
642 paper rectangle, page rectangle, or page margins rectangle to perform your own
645 void MapScreenSizeToDevice();
648 This sets the user scale of the wxDC assocated with this wxPrintout to the same
649 scale as MapScreenSizeToPaper() but sets
650 the logical origin to the top left corner of the page rectangle.
652 void MapScreenSizeToPage();
655 This sets the user scale of the wxDC assocated with this wxPrintout to the same
657 MapScreenSizeToPageMargins() but
658 sets the logical origin to the top left corner of the page margins specified by
659 the given wxPageSetupDialogData object.
661 void MapScreenSizeToPageMargins(const wxPageSetupDialogData
& pageSetupData
);
664 Set the user scale and device origin of the wxDC associated with this wxPrintout
665 so that the printed page matches the screen size as closely as possible
666 and the logical origin is in the top left corner of the paper rectangle.
668 a 100-pixel object on screen should appear at the same size on the printed
670 will, of course, be larger or smaller in the preview image, depending on the
672 factor.) Use this if you want WYSIWYG behavior, e.g., in a text editor.
674 void MapScreenSizeToPaper();
677 Shift the device origin by an amount specified in logical coordinates.
679 void OffsetLogicalOrigin(wxCoord xoff
, wxCoord yoff
);
682 Called by the framework at the start of document printing. Return @false from
683 this function cancels the print job. OnBeginDocument is called once for every
685 The base OnBeginDocument() @e must be called (and the return value
686 checked) from within the overridden function, since it calls wxDC::StartDoc.
688 bool OnBeginDocument(int startPage
, int endPage
);
691 Called by the framework at the start of printing. OnBeginPrinting is called
693 print job (regardless of how many copies are being printed).
695 void OnBeginPrinting();
698 Called by the framework at the end of document printing. OnEndDocument
699 is called once for every copy printed.
700 The base OnEndDocument() @e must be called
701 from within the overridden function, since it calls wxDC::EndDoc.
703 void OnEndDocument();
706 Called by the framework at the end of printing. OnEndPrinting
707 is called once for every print job (regardless of how many copies are being
710 void OnEndPrinting();
713 Called once by the framework before any other demands are made of the
714 wxPrintout object. This gives the object an opportunity to calculate the
715 number of pages in the document, for example.
717 void OnPreparePrinting();
720 Called by the framework when a page should be printed. Returning @false cancels
721 the print job. The application can use GetDC() to obtain a device
724 bool OnPrintPage(int pageNum
);
727 Set the device origin of the associated wxDC so that the current logical point
728 becomes the new logical origin.
730 void SetLogicalOrigin(wxCoord x
, wxCoord y
);