| Version: 3.0.2

- Main Page
- Related Pages
- Categories
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
wxPrintout Class Referenceabstract
Printing Framework

`#include <wx/print.h>`

Inheritance diagram for wxPrintout:
[legend]

## Detailed Description

This class encapsulates the functionality of printing out an application document.

A new class must be derived and members overridden to respond to calls such as OnPrintPage() and HasPage() and to render the print image onto an associated wxDC. Instances of this class are passed to wxPrinter::Print() or to a wxPrintPreview object to initiate printing or previewing.

Your derived wxPrintout is responsible for drawing both the preview image and the printed page. If your windows' drawing routines accept an arbitrary DC as an argument, you can re-use those routines within your wxPrintout subclass to draw the printout image. You may also add additional drawing elements within your wxPrintout subclass, like headers, footers, and/or page numbers. However, the image on the printed page will often differ from the image drawn on the screen, as will the print preview image – not just in the presence of headers and footers, but typically in scale. A high-resolution printer presents a much larger drawing surface (i.e., a higher-resolution DC); a zoomed-out preview image presents a much smaller drawing surface (lower-resolution DC). By using the routines FitThisSizeToXXX() and/or MapScreenSizeToXXX() within your wxPrintout subclass to set the user scale and origin of the associated DC, you can easily use a single drawing routine to draw on your application's windows, to create the print preview image, and to create the printed paper image, and achieve a common appearance to the preview image and the printed page.

##

Library: wxCore
Category: Printing Framework

See Also
  Printing Framework Overview, wxPrinterDC, wxPrintDialog, wxPageSetupDialog, wxPrinter, wxPrintPreview

## Public Member Functions
| wxPrintout (const wxString &title="Printout")
| Constructor.
virtual | ~wxPrintout ()
| Destructor.
void | FitThisSizeToPage (const wxSize &imageSize)
| Set the user scale and device origin of the wxDC associated with this wxPrintout so that the given image size fits entirely within the page rectangle and the origin is at the top left corner of the page rectangle.
void | FitThisSizeToPageMargins (const wxSize &imageSize, const wxPageSetupDialogData &pageSetupData)
| Set the user scale and device origin of the wxDC associated with this wxPrintout so that the given image size fits entirely within the page margins set in the given wxPageSetupDialogData object.
void | FitThisSizeToPaper (const wxSize &imageSize)
| Set the user scale and device origin of the wxDC associated with this wxPrintout so that the given image size fits entirely within the paper and the origin is at the top left corner of the paper.
wxDC * | GetDC () const
| Returns the device context associated with the printout (given to the printout at start of printing or previewing).
wxRect | GetLogicalPageMarginsRect (const wxPageSetupDialogData &pageSetupData) const
| Return the rectangle corresponding to the page margins specified by the given wxPageSetupDialogData object in the associated wxDC's logical coordinates for the current user scale and device origin.
wxRect | GetLogicalPageRect () const
| Return the rectangle corresponding to the page in the associated wxDC 's logical coordinates for the current user scale and device origin.
wxRect | GetLogicalPaperRect () const
| Return the rectangle corresponding to the paper in the associated wxDC 's logical coordinates for the current user scale and device origin.
void | GetPPIPrinter (int *w, int *h) const
| Returns the number of pixels per logical inch of the printer device context.
void | GetPPIScreen (int *w, int *h) const
| Returns the number of pixels per logical inch of the screen device context.
virtual void | GetPageInfo (int *minPage, int *maxPage, int *pageFrom, int *pageTo)
| Called by the framework to obtain information from the application about minimum and maximum page values that the user can select, and the required page range to be printed.
void | GetPageSizeMM (int *w, int *h) const
| Returns the size of the printer page in millimetres.
void | GetPageSizePixels (int *w, int *h) const
| Returns the size of the printer page in pixels, called the page rectangle.
wxRect | GetPaperRectPixels () const
| Returns the rectangle that corresponds to the entire paper in pixels, called the paper rectangle.
virtual wxString | GetTitle () const
| Returns the title of the printout.
virtual bool | HasPage (int pageNum)
| Should be overridden to return true if the document has this page, or false if not.
virtual bool | IsPreview () const
| Returns true if the printout is currently being used for previewing.
wxPrintPreview * | GetPreview () const
| Returns the associated preview object if any.
void | MapScreenSizeToDevice ()
| Set the user scale and device origin of the wxDC associated with this wxPrintout so that one screen pixel maps to one device pixel on the DC.
void | MapScreenSizeToPage ()
| This sets the user scale of the wxDC associated with this wxPrintout to the same scale as MapScreenSizeToPaper() but sets the logical origin to the top left corner of the page rectangle.
void | MapScreenSizeToPageMargins (const wxPageSetupDialogData &pageSetupData)
| This sets the user scale of the wxDC associated with this wxPrintout to the same scale as MapScreenSizeToPageMargins() but sets the logical origin to the top left corner of the page margins specified by the given wxPageSetupDialogData object.
void | MapScreenSizeToPaper ()
| Set the user scale and device origin of the wxDC associated with this wxPrintout so that the printed page matches the screen size as closely as possible and the logical origin is in the top left corner of the paper rectangle.
void | OffsetLogicalOrigin (wxCoord xoff, wxCoord yoff)
| Shift the device origin by an amount specified in logical coordinates.
virtual bool | OnBeginDocument (int startPage, int endPage)
| Called by the framework at the start of document printing.
virtual void | OnBeginPrinting ()
| Called by the framework at the start of printing.
virtual void | OnEndDocument ()
| Called by the framework at the end of document printing.
virtual void | OnEndPrinting ()
| Called by the framework at the end of printing.
virtual void | OnPreparePrinting ()
| Called once by the framework before any other demands are made of the wxPrintout object.
virtual bool | OnPrintPage (int pageNum)=0
| Called by the framework when a page should be printed.
void | SetLogicalOrigin (wxCoord x, wxCoord y)
| Set the device origin of the associated wxDC so that the current logical point becomes the new logical origin.
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data.
| wxObject (const wxObject &other)
| Copy ctor.
virtual | ~wxObject ()
| Destructor.
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar).
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class.
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj.
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone.
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer.
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data.
void | UnShare ()
| This is the same of AllocExclusive() but this method is public.
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `WXDEBUG` is defined.
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `WXDEBUG` is defined.

## Additional Inherited Members
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object.
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it.
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data.
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data.

## Constructor & Destructor Documentation

wxPrintout::wxPrintout | ( | const wxString & | title = `"Printout"` | ) |

Constructor.

Pass an optional title argument - the current filename would be a good idea. This will appear in the printing list (at least in MSW)

virtual wxPrintout::~wxPrintout | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

void wxPrintout::FitThisSizeToPage | ( | const wxSize & | imageSize | ) |

Set the user scale and device origin of the wxDC associated with this wxPrintout so that the given image size fits entirely within the page rectangle and the origin is at the top left corner of the page rectangle.

On MSW and Mac, the page rectangle is the printable area of the page. On other platforms and PostScript printing, the page rectangle is the entire paper.

Use this if you want your printed image as large as possible, but with the caveat that on some platforms, portions of the image might be cut off at the edges.

void wxPrintout::FitThisSizeToPageMargins | ( | const wxSize & | imageSize,
|  | const wxPageSetupDialogData & | pageSetupData
| ) |  |

Set the user scale and device origin of the wxDC associated with this wxPrintout so that the given image size fits entirely within the page margins set in the given wxPageSetupDialogData object.

This function provides the greatest consistency across all platforms because it does not depend on having access to the printable area of the paper.

Remarks
  On Mac, the native wxPageSetupDialog does not let you set the page margins; you'll have to provide your own mechanism, or you can use the Mac-only class wxMacPageMarginsDialog.

void wxPrintout::FitThisSizeToPaper | ( | const wxSize & | imageSize | ) |

Set the user scale and device origin of the wxDC associated with this wxPrintout so that the given image size fits entirely within the paper and the origin is at the top left corner of the paper.

Use this if you're managing your own page margins.

Note
  With most printers, the region around the edges of the paper are not printable so that the edges of the image could be cut off.

wxDC* wxPrintout::GetDC | ( |  | ) | const

Returns the device context associated with the printout (given to the printout at start of printing or previewing).

The application can use GetDC() to obtain a device context to draw on.

This will be a wxPrinterDC if printing under Windows or Mac, a wxPostScriptDC if printing on other platforms, and a wxMemoryDC if previewing.

wxRect wxPrintout::GetLogicalPageMarginsRect | ( | const wxPageSetupDialogData & | pageSetupData | ) | const

Return the rectangle corresponding to the page margins specified by the given wxPageSetupDialogData object in the associated wxDC's logical coordinates for the current user scale and device origin.

The page margins are specified with respect to the edges of the paper on all platforms.

wxRect wxPrintout::GetLogicalPageRect | ( |  | ) | const

Return the rectangle corresponding to the page in the associated wxDC 's logical coordinates for the current user scale and device origin.

On MSW and Mac, this will be the printable area of the paper. On other platforms and PostScript printing, this will be the full paper rectangle.

wxRect wxPrintout::GetLogicalPaperRect | ( |  | ) | const

Return the rectangle corresponding to the paper in the associated wxDC 's logical coordinates for the current user scale and device origin.

virtual void wxPrintout::GetPageInfo | ( | int * | minPage,
|  | int * | maxPage,
|  | int * | pageFrom,
|  | int * | pageTo
| ) |  |
| virtual

Called by the framework to obtain information from the application about minimum and maximum page values that the user can select, and the required page range to be printed.

By default this returns (1, 32000) for the page minimum and maximum values, and (1, 1) for the required page range.

minPage must be greater than zero and maxPage must be greater than minPage.

Reimplemented in wxRichTextPrintout.

void wxPrintout::GetPageSizeMM | ( | int * | w,
|  | int * | h
| ) |  | const

Returns the size of the printer page in millimetres.

wxPerl Note: In wxPerl this method takes no arguments and returns a 2-element list (w, h).

void wxPrintout::GetPageSizePixels | ( | int * | w,
|  | int * | h
| ) |  | const

Returns the size of the printer page in pixels, called the page rectangle.

The page rectangle has a top left corner at (0,0) and a bottom right corner at (w,h). These values may not be the same as the values returned from wxDC::GetSize(); if the printout is being used for previewing, a memory device context is used, which uses a bitmap size reflecting the current preview zoom. The application must take this discrepancy into account if previewing is to be supported.

wxRect wxPrintout::GetPaperRectPixels | ( |  | ) | const

Returns the rectangle that corresponds to the entire paper in pixels, called the paper rectangle.

This distinction between paper rectangle and page rectangle reflects the fact that most printers cannot print all the way to the edge of the paper. The page rectangle is a rectangle whose top left corner is at (0,0) and whose width and height are given by wxDC::GetPageSizePixels().

On MSW and Mac, the page rectangle gives the printable area of the paper, while the paper rectangle represents the entire paper, including non-printable borders. Thus, the rectangle returned by wxDC::GetPaperRectPixels() will have a top left corner whose coordinates are small negative numbers and the bottom right corner will have values somewhat larger than the width and height given by wxDC::GetPageSizePixels().

On other platforms and for PostScript printing, the paper is treated as if its entire area were printable, so this function will return the same rectangle as the page rectangle.

void wxPrintout::GetPPIPrinter | ( | int * | w,
|  | int * | h
| ) |  | const

Returns the number of pixels per logical inch of the printer device context.

Dividing the printer PPI by the screen PPI can give a suitable scaling factor for drawing text onto the printer.

Remember to multiply this by a scaling factor to take the preview DC size into account. Or you can just use the FitThisSizeToXXX() and MapScreenSizeToXXX routines below, which do most of the scaling calculations for you.

wxPerl Note: In wxPerl this method takes no arguments and returns a 2-element list (w, h).

void wxPrintout::GetPPIScreen | ( | int * | w,
|  | int * | h
| ) |  | const

Returns the number of pixels per logical inch of the screen device context.

Dividing the printer PPI by the screen PPI can give a suitable scaling factor for drawing text onto the printer.

If you are doing your own scaling, remember to multiply this by a scaling factor to take the preview DC size into account.

wxPerl Note: In wxPerl this method takes no arguments and returns a 2-element list (w, h).

wxPrintPreview* wxPrintout::GetPreview | ( |  | ) | const

Returns the associated preview object if any.

If this printout object is used for previewing, returns the associated wxPrintPreview. Otherwise returns NULL.

The returned pointer is not owned by the printout and must not be deleted.

See Also
  IsPreview()

Since
  2.9.1.

virtual wxString wxPrintout::GetTitle | ( |  | ) | const
| virtual

Returns the title of the printout.

Todo:
  the python note here was wrong

virtual bool wxPrintout::HasPage | ( | int | pageNum | ) |
| virtual

Should be overridden to return true if the document has this page, or false if not.

Returning false signifies the end of the document. By default, HasPage behaves as if the document has only one page.

Reimplemented in wxRichTextPrintout.

virtual bool wxPrintout::IsPreview | ( |  | ) | const
| virtual

Returns true if the printout is currently being used for previewing.

See Also
  GetPreview()

void wxPrintout::MapScreenSizeToDevice | ( |  | ) |

Set the user scale and device origin of the wxDC associated with this wxPrintout so that one screen pixel maps to one device pixel on the DC.

That is, the user scale is set to (1,1) and the device origin is set to (0,0).

Use this if you want to do your own scaling prior to calling wxDC drawing calls, for example, if your underlying model is floating-point and you want to achieve maximum drawing precision on high-resolution printers.

You can use the GetLogicalXXXRect() routines below to obtain the paper rectangle, page rectangle, or page margins rectangle to perform your own scaling.

Note
  While the underlying drawing model of Mac OS X is floating-point, wxWidgets's drawing model scales from integer coordinates.

void wxPrintout::MapScreenSizeToPage | ( |  | ) |

This sets the user scale of the wxDC associated with this wxPrintout to the same scale as MapScreenSizeToPaper() but sets the logical origin to the top left corner of the page rectangle.

void wxPrintout::MapScreenSizeToPageMargins | ( | const wxPageSetupDialogData & | pageSetupData | ) |

This sets the user scale of the wxDC associated with this wxPrintout to the same scale as MapScreenSizeToPageMargins() but sets the logical origin to the top left corner of the page margins specified by the given wxPageSetupDialogData object.

void wxPrintout::MapScreenSizeToPaper | ( |  | ) |

Set the user scale and device origin of the wxDC associated with this wxPrintout so that the printed page matches the screen size as closely as possible and the logical origin is in the top left corner of the paper rectangle.

That is, a 100-pixel object on screen should appear at the same size on the printed page. (It will, of course, be larger or smaller in the preview image, depending on the zoom factor.)

Use this if you want WYSIWYG behaviour, e.g., in a text editor.

void wxPrintout::OffsetLogicalOrigin | ( | wxCoord | xoff,
|  | wxCoord | yoff
| ) |  |

Shift the device origin by an amount specified in logical coordinates.

virtual bool wxPrintout::OnBeginDocument | ( | int | startPage,
|  | int | endPage
| ) |  |
| virtual

Called by the framework at the start of document printing.

Return false from this function cancels the print job.

OnBeginDocument() is called once for every copy printed.

Remarks
  The base OnBeginDocument() must be called (and the return value checked) from within the overridden function, since it calls wxDC::StartDoc().

virtual void wxPrintout::OnBeginPrinting | ( |  | ) |
| virtual

Called by the framework at the start of printing.

OnBeginPrinting() is called once for every print job (regardless of how many copies are being printed).

virtual void wxPrintout::OnEndDocument | ( |  | ) |
| virtual

Called by the framework at the end of document printing.

OnEndDocument() is called once for every copy printed.

Remarks
  The base OnEndDocument() must be called from within the overridden function, since it calls wxDC::EndDoc().

virtual void wxPrintout::OnEndPrinting | ( |  | ) |
| virtual

Called by the framework at the end of printing.

OnEndPrinting is called once for every print job (regardless of how many copies are being printed).

virtual void wxPrintout::OnPreparePrinting | ( |  | ) |
| virtual

Called once by the framework before any other demands are made of the wxPrintout object.

This gives the object an opportunity to calculate the number of pages in the document, for example.

Reimplemented in wxRichTextPrintout.

virtual bool wxPrintout::OnPrintPage | ( | int | pageNum | ) |
| pure virtual

Called by the framework when a page should be printed.

Returning false cancels the print job.

Implemented in wxRichTextPrintout.

void wxPrintout::SetLogicalOrigin | ( | wxCoord | x,
|  | wxCoord | y
| ) |  |

Set the device origin of the associated wxDC so that the current logical point becomes the new logical origin.