]>
git.saurik.com Git - wxWidgets.git/blob - interface/print.h
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
);
55 The buttons parameter may be a combination of the following, using the bitwise
61 Create a print button.
66 Create a next page button.
71 Create a previous page button.
76 Create a zoom control.
81 Equivalent to a combination of wxPREVIEW_PREVIOUS, wxPREVIEW_NEXT and
84 wxPreviewControlBar(wxPrintPreview
* preview
, long buttons
,
86 const wxPoint
& pos
= wxDefaultPosition
,
87 const wxSize
& size
= wxDefaultSize
,
89 const wxString
& name
= "panel");
94 @class wxPreviewCanvas
97 A preview canvas is the default canvas used by the print preview
98 system to display the preview.
104 wxPreviewFrame, wxPreviewControlBar, wxPrintPreview
106 class wxPreviewCanvas
: public wxScrolledWindow
112 wxPreviewCanvas(wxPrintPreview
* preview
, wxWindow
* parent
,
113 const wxPoint
& pos
= wxDefaultPosition
,
114 const wxSize
& size
= wxDefaultSize
,
116 const wxString
& name
= "canvas");
124 Calls wxPrintPreview::PaintPage to refresh the canvas.
126 void OnPaint(wxPaintEvent
& event
);
131 @class wxPreviewFrame
134 This class provides the default method of managing the print preview interface.
135 Member functions may be overridden to replace functionality, or the
136 class may be used without derivation.
142 wxPreviewCanvas, wxPreviewControlBar, wxPrintPreview
144 class wxPreviewFrame
: public wxFrame
148 Constructor. Pass a print preview object plus other normal frame arguments.
149 The print preview object will be destroyed by the frame when it closes.
151 wxPreviewFrame(wxPrintPreview
* preview
, wxWindow
* parent
,
152 const wxString
& title
,
153 const wxPoint
& pos
= wxDefaultPosition
,
154 const wxSize
& size size
= wxDefaultSize
,
155 long style
= wxDEFAULT_FRAME_STYLE
,
156 const wxString
& name
= "frame");
164 Creates a wxPreviewCanvas. Override this function to allow
165 a user-defined preview canvas object to be created.
170 Creates a wxPreviewControlBar. Override this function to allow
171 a user-defined preview control bar object to be created.
173 void CreateControlBar();
176 Creates the preview canvas and control bar, and calls
177 wxWindow::MakeModal(@true) to disable other top-level windows
180 This function should be called by the application prior to
186 Enables the other frames in the application, and deletes the print preview
187 object, implicitly deleting any printout objects associated with the print
190 void OnCloseWindow(wxCloseEvent
& event
);
195 @class wxPrintPreview
198 Objects of this class manage the print preview process. The object is passed
199 a wxPrintout object, and the wxPrintPreview object itself is passed to
200 a wxPreviewFrame object. Previewing is started by initializing and showing
201 the preview frame. Unlike wxPrinter::Print, flow of control returns to the
203 immediately after the frame is shown.
209 @ref overview_printingoverview "Printing framework overview", wxPrinterDC,
210 wxPrintDialog, wxPrintout, wxPrinter, wxPreviewCanvas, wxPreviewControlBar, wxPreviewFrame.
212 class wxPrintPreview
: public wxObject
216 Constructor. Pass a printout object, an optional printout object to be
217 used for actual printing, and the address of an optional
218 block of printer data, which will be copied to the print preview object's
221 If @e printoutForPrinting is non-@NULL, a @b Print... button will be placed on
223 preview frame so that the user can print directly from the preview interface.
225 Do not explicitly delete the printout objects once this destructor has been
226 called, since they will be deleted in the wxPrintPreview constructor.
227 The same does not apply to the @e data argument.
229 Test the Ok member to check whether the wxPrintPreview object was created
231 Ok could return @false if there was a problem initializing the printer device
233 (current printer not set, for example).
235 wxPrintPreview(wxPrintout
* printout
,
236 wxPrintout
* printoutForPrinting
,
237 wxPrintData
* data
=@NULL
);
240 Destructor. Deletes both print preview objects, so do not destroy these objects
246 Gets the preview window used for displaying the print preview image.
248 wxPreviewCanvas
* GetCanvas();
251 Gets the page currently being previewed.
253 int GetCurrentPage();
256 Gets the frame used for displaying the print preview canvas
259 wxFrame
* GetFrame();
262 Returns the maximum page number.
267 Returns the minimum page number.
272 Gets the preview printout object associated with the wxPrintPreview object.
274 wxPrintout
* GetPrintout();
277 Gets the printout object to be used for printing from within the preview
279 or @NULL if none exists.
281 wxPrintout
* GetPrintoutForPrinting();
284 Returns @true if the wxPrintPreview is valid, @false otherwise. It could return
285 @false if there was a
286 problem initializing the printer device context (current printer not set, for
289 #define bool Ok() /* implementation is private */
292 This refreshes the preview window with the preview image.
293 It must be called from the preview window's OnPaint member.
295 The implementation simply blits the preview bitmap onto
296 the canvas, creating a new preview bitmap if none exists.
298 bool PaintPage(wxPreviewCanvas
* canvas
, wxDC dc
);
301 Invokes the print process using the second wxPrintout object
302 supplied in the wxPrintPreview constructor.
303 Will normally be called by the @b Print... panel item on the
304 preview frame's control bar.
306 Returns @false in case of error -- call
307 wxPrinter::GetLastError to get detailed
308 information about the kind of the error.
310 bool Print(bool prompt
);
313 Renders a page into a wxMemoryDC. Used internally by wxPrintPreview.
315 bool RenderPage(int pageNum
);
318 Sets the window to be used for displaying the print preview image.
320 void SetCanvas(wxPreviewCanvas
* window
);
323 Sets the current page to be previewed.
325 void SetCurrentPage(int pageNum
);
328 Sets the frame to be used for displaying the print preview canvas
331 void SetFrame(wxFrame
* frame
);
334 Associates a printout object with the wxPrintPreview object.
336 void SetPrintout(wxPrintout
* printout
);
339 Sets the percentage preview zoom, and refreshes the preview canvas
342 void SetZoom(int percent
);
350 This class represents the Windows or PostScript printer, and is the vehicle
352 which printing may be launched by an application. Printing can also
353 be achieved through using of lower functions and classes, but
354 this and associated classes provide a more convenient and general
361 @ref overview_printingoverview "Printing framework overview", wxPrinterDC,
362 wxPrintDialog, wxPrintout, wxPrintPreview.
364 class wxPrinter
: public wxObject
368 Constructor. Pass an optional pointer to a block of print
369 dialog data, which will be copied to the printer object's local data.
371 @sa wxPrintDialogData, wxPrintData
373 wxPrinter(wxPrintDialogData
* data
= @NULL
);
376 Creates the default printing abort window, with a cancel button.
378 void CreateAbortWindow(wxWindow
* parent
, wxPrintout
* printout
);
381 Returns @true if the user has aborted the print job.
386 Return last error. Valid after calling Print(),
388 wxPrintPreview::Print. These functions
389 set last error to @b wxPRINTER_NO_ERROR if no error happened.
391 Returned value is one of the following:
394 @b wxPRINTER_NO_ERROR
399 @b wxPRINTER_CANCELLED
402 The user cancelled printing.
407 There was an error during printing.
409 static wxPrinterError
GetLastError();
412 Returns the @ref overview_wxprintdata "print data" associated with the printer
415 wxPrintDialogData
GetPrintDialogData();
418 Starts the printing process. Provide a parent window, a user-defined wxPrintout
419 object which controls
420 the printing of a document, and whether the print dialog should be invoked
423 Print could return @false if there was a problem initializing the printer device
425 (current printer not set, for example) or the user cancelled printing. Call
426 GetLastError() to get detailed
427 information about the kind of the error.
429 bool Print(wxWindow
* parent
, wxPrintout
* printout
,
433 Invokes the print dialog. If successful (the user did not press Cancel
434 and no error occurred), a suitable device context will be returned
435 (otherwise @NULL is returned -- call
436 GetLastError() to get detailed
437 information about the kind of the error).
439 The application must delete this device context to avoid a memory leak.
441 wxDC
* PrintDialog(wxWindow
* parent
);
444 Default error-reporting function.
446 void ReportError(wxWindow
* parent
, wxPrintout
* printout
,
447 const wxString
& message
);
450 Invokes the print setup dialog. Note that the setup dialog is obsolete from
451 Windows 95, though retained for backward compatibility.
453 bool Setup(wxWindow
* parent
);
461 This class encapsulates the functionality of printing out an application
462 document. A new class must be derived and members overridden to respond to calls
463 such as OnPrintPage and HasPage and to render the print image onto an associated
464 wxDC. Instances of this class are passed to wxPrinter::Print or
465 to a wxPrintPreview object to initiate printing or previewing.
467 Your derived wxPrintout is responsible for drawing both the preview image and
468 the printed page. If your windows' drawing routines accept an arbitrary DC as an
469 argument, you can re-use those routines within your wxPrintout subclass to draw
470 the printout image. You may also add additional drawing elements within your
471 wxPrintout subclass, like headers, footers, and/or page numbers. However, the
472 image on the printed page will often differ from the image drawn on the screen,
473 as will the print preview image -- not just in the presence of headers and
474 footers, but typically in scale. A high-resolution printer presents a much
475 larger drawing surface (i.e., a higher-resolution DC); a zoomed-out preview
476 image presents a much smaller drawing surface (lower-resolution DC). By using
477 the routines FitThisSizeToXXX() and/or MapScreenSizeToXXX() within your
478 wxPrintout subclass to set the user scale and origin of the associated DC, you
479 can easily use a single drawing routine to draw on your application's windows,
480 to create the print preview image, and to create the printed paper image, and
481 achieve a common appearance to the preview image and the printed page.
487 @ref overview_printingoverview "Printing framework overview", wxPrinterDC,
488 wxPrintDialog, wxPageSetupDialog, wxPrinter, wxPrintPreview
490 class wxPrintout
: public wxObject
494 Constructor. Pass an optional title argument - the current filename would be a
495 good idea. This will appear in the printing list
498 wxPrintout(const wxString
& title
= "Printout");
506 Set the user scale and device origin of the wxDC associated with this wxPrintout
507 so that the given image size fits entirely within the page rectangle and the
508 origin is at the top left corner of the page rectangle. On MSW and Mac, the page
509 rectangle is the printable area of the page. On other platforms and PostScript
510 printing, the page rectangle is the entire paper. Use this if you want your
511 printed image as large as possible, but with the caveat that on some platforms,
512 portions of the image might be cut off at the edges.
514 void FitThisSizeToPage(const wxSize
& imageSize
);
517 Set the user scale and device origin of the wxDC associated with this wxPrintout
518 so that the given image size fits entirely within the page margins set in the
519 given wxPageSetupDialogData object. This function provides the greatest
520 consistency across all platforms because it does not depend on having access to
521 the printable area of the paper. Note that on Mac, the native wxPageSetupDialog
522 does not let you set the page margins; you'll have to provide your own
524 or you can use the Mac-only class wxMacPageMarginsDialog.
526 void FitThisSizeToPageMargins(const wxSize
& imageSize
,
527 const wxPageSetupDialogData
& pageSetupData
);
530 Set the user scale and device origin of the wxDC associated with this wxPrintout
531 so that the given image size fits entirely within the paper and the origin is at
532 the top left corner of the paper. Note that with most printers, the region
533 around the edges of the paper are not printable so that the edges of the image
534 could be cut off. Use this if you're managing your own page margins.
536 void FitThisSizeToPaper(const wxSize
& imageSize
);
539 Returns the device context associated with the printout (given to the printout
541 printing or previewing). This will be a wxPrinterDC if printing under Windows
543 a wxPostScriptDC if printing on other platforms, and a wxMemoryDC if previewing.
545 #define wxDC * GetDC() /* implementation is private */
548 Return the rectangle corresponding to the page margins specified by the given
549 wxPageSetupDialogData object in the associated wxDC's logical coordinates for
551 current user scale and device origin. The page margins are specified
552 with respect to the edges of the paper on all platforms.
554 wxRect
GetLogicalPageMarginsRect(const wxPageSetupDialogData
& pageSetupData
);
557 Return the rectangle corresponding to the page in the associated wxDC's
558 logical coordinates for the current user scale and device origin.
559 On MSW and Mac, this will be the printable area of the paper. On other platforms
560 and PostScript printing, this will be the full paper rectangle.
562 wxRect
GetLogicalPageRect();
565 Return the rectangle corresponding to the paper in the associated wxDC's
566 logical coordinates for the current user scale and device origin.
568 wxRect
GetLogicalPaperRect();
571 Returns the number of pixels per logical inch of the printer device context.
572 Dividing the printer PPI by the screen PPI can give a suitable scaling factor
573 for drawing text onto the printer. Remember to multiply this by a scaling factor
574 to take the preview DC size into account. Or you can just use the
575 FitThisSizeToXXX() and MapScreenSizeToXXX routines below, which do most of the
576 scaling calculations for you.
578 void GetPPIPrinter(int * w
, int * h
);
581 Returns the number of pixels per logical inch of the screen device context.
582 Dividing the printer PPI by the screen PPI can give a suitable scaling factor
583 for drawing text onto the printer. If you are doing your own scaling, remember
584 to multiply this by a scaling factor to take the preview DC size into account.
586 void GetPPIScreen(int * w
, int * h
);
589 Called by the framework to obtain information from the application about minimum
590 and maximum page values that the user can select, and the required page range to
591 be printed. By default this returns 1, 32000 for the page minimum and maximum
592 values, and 1, 1 for the required page range.
594 If @e minPage is zero, the page number controls in the print dialog will be
597 void GetPageInfo(int * minPage
, int * maxPage
, int * pageFrom
,
601 Returns the size of the printer page in millimetres.
603 void GetPageSizeMM(int * w
, int * h
);
606 Returns the size of the printer page in pixels, called the page rectangle.
607 The page rectangle has a top left corner at (0,0) and a bottom right corner at
608 (w,h). These values may not be the same as the values returned from
609 wxDC::GetSize; if the printout is being used for
610 previewing, a memory device context is used, which uses a bitmap size reflecting
611 the current preview zoom. The application must take this discrepancy into
612 account if previewing is to be supported.
614 void GetPageSizePixels(int * w
, int * h
);
617 Returns the rectangle that corresponds to the entire paper in pixels, called the
618 paper rectangle. This distinction between paper rectangle and page
619 rectangle reflects the fact that most printers cannot print all the way to the
620 edge of the paper. The page rectangle is a rectangle whose top left corner is at
621 (0,0) and whose width and height are given by
622 wxDC::GetPageSizePixels. On MSW and Mac,
623 the page rectangle gives the printable area of the paper, while the paper
624 rectangle represents the entire paper, including non-printable borders. Thus,
625 the rectangle returned by GetPaperRectPixels will have a top left corner whose
626 coordinates are small negative numbers and the bottom right corner will have
627 values somewhat larger than the width and height given by
628 wxDC::GetPageSizePixels. On other
629 platforms and for PostScript printing, the paper is treated as if its entire
630 area were printable, so this function will return the same rectangle as the page
633 wxRect
GetPaperRectPixels();
636 Returns the title of the printout
641 Should be overridden to return @true if the document has this page, or @false
642 if not. Returning @false signifies the end of the document. By default,
643 HasPage behaves as if the document has only one page.
645 bool HasPage(int pageNum
);
648 Returns @true if the printout is currently being used for previewing.
653 Set the user scale and device origin of the wxDC associated with this wxPrintout
654 so that one screen pixel maps to one device pixel on the DC. That is, the user
655 scale is set to (1,1) and the device origin is set to (0,0). Use this if you
656 want to do your own scaling prior to calling wxDC drawing calls, for example, if
657 your underlying model is floating-point and you want to achieve maximum drawing
658 precision on high-resolution printers. (Note that while the underlying drawing
659 model of Mac OS X is floating-point, wxWidgets's drawing model scales from
661 coordinates.) You can use the GetLogicalXXXRect() routines below to obtain the
662 paper rectangle, page rectangle, or page margins rectangle to perform your own
665 void MapScreenSizeToDevice();
668 This sets the user scale of the wxDC assocated with this wxPrintout to the same
669 scale as MapScreenSizeToPaper() but sets
670 the logical origin to the top left corner of the page rectangle.
672 void MapScreenSizeToPage();
675 This sets the user scale of the wxDC assocated with this wxPrintout to the same
677 MapScreenSizeToPageMargins() but
678 sets the logical origin to the top left corner of the page margins specified by
679 the given wxPageSetupDialogData object.
681 void MapScreenSizeToPageMargins(const wxPageSetupDialogData
& pageSetupData
);
684 Set the user scale and device origin of the wxDC associated with this wxPrintout
685 so that the printed page matches the screen size as closely as possible
686 and the logical origin is in the top left corner of the paper rectangle.
688 a 100-pixel object on screen should appear at the same size on the printed
690 will, of course, be larger or smaller in the preview image, depending on the
692 factor.) Use this if you want WYSIWYG behavior, e.g., in a text editor.
694 void MapScreenSizeToPaper();
697 Shift the device origin by an amount specified in logical coordinates.
699 void OffsetLogicalOrigin(wxCoord xoff
, wxCoord yoff
);
702 Called by the framework at the start of document printing. Return @false from
703 this function cancels the print job. OnBeginDocument is called once for every
706 The base OnBeginDocument() @e must be called (and the return value
707 checked) from within the overridden function, since it calls wxDC::StartDoc.
709 bool OnBeginDocument(int startPage
, int endPage
);
712 Called by the framework at the start of printing. OnBeginPrinting is called
714 print job (regardless of how many copies are being printed).
716 void OnBeginPrinting();
719 Called by the framework at the end of document printing. OnEndDocument
720 is called once for every copy printed.
722 The base OnEndDocument() @e must be called
723 from within the overridden function, since it calls wxDC::EndDoc.
725 void OnEndDocument();
728 Called by the framework at the end of printing. OnEndPrinting
729 is called once for every print job (regardless of how many copies are being
732 void OnEndPrinting();
735 Called once by the framework before any other demands are made of the
736 wxPrintout object. This gives the object an opportunity to calculate the
737 number of pages in the document, for example.
739 void OnPreparePrinting();
742 Called by the framework when a page should be printed. Returning @false cancels
743 the print job. The application can use GetDC() to obtain a device
746 bool OnPrintPage(int pageNum
);
749 Set the device origin of the associated wxDC so that the current logical point
750 becomes the new logical origin.
752 void SetLogicalOrigin(wxCoord x
, wxCoord y
);