| Version: 3.2.8

Public Member Functions | List of all members
wxPrintPreview Class Reference
Class List by Category » Printing Framework

`#include <wx/print.h>`

Inheritance diagram for wxPrintPreview:
[legend]

## Detailed Description

Objects of this class manage the print preview process.

The object is passed a wxPrintout object, and the wxPrintPreview object itself is passed to a wxPreviewFrame object. Previewing is started by initializing and showing the preview frame. Unlike wxPrinter::Print(), flow of control returns to the application immediately after the frame is shown.

Note
  The preview shown is only exact on Windows. On other platforms, the wxDC used for preview is different from what is used for printing and the results may be significantly different, depending on how is the output created. In particular, printing code relying on wxDC::GetTextExtent() heavily (for example, wxHtmlEasyPrinting and other wxHTML classes do) is affected. It is recommended to use native preview functionality on platforms that offer it (macOS, GTK+).

##

Library: wxCore
Category: Printing Framework

See also
  Printing Framework Overview, wxPrinterDC, wxPrintDialog, wxPrintout, wxPrinter, wxPreviewCanvas, wxPreviewControlBar, wxPreviewFrame

## Public Member Functions
| wxPrintPreview (wxPrintout *printout, wxPrintout *printoutForPrinting=NULL, wxPrintDialogData *data=NULL)
| Constructor. More...
| wxPrintPreview (wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data)
| ~wxPrintPreview ()
| Destructor. More...
virtual wxPreviewCanvas * | GetCanvas () const
| Gets the preview window used for displaying the print preview image. More...
virtual int | GetCurrentPage () const
| Gets the page currently being previewed. More...
virtual wxFrame * | GetFrame () const
| Gets the frame used for displaying the print preview canvas and control bar. More...
virtual int | GetMaxPage () const
| Returns the maximum page number. More...
virtual int | GetMinPage () const
| Returns the minimum page number. More...
virtual wxPrintout * | GetPrintout () const
| Gets the preview printout object associated with the wxPrintPreview object. More...
virtual wxPrintout * | GetPrintoutForPrinting () const
| Gets the printout object to be used for printing from within the preview interface, or NULL if none exists. More...
virtual int | GetZoom () const
| Gets the current percentage zoom level of the preview canvas. More...
virtual bool | IsOk () const
| Returns true if the wxPrintPreview is valid, false otherwise. More...
virtual bool | PaintPage (wxPreviewCanvas *canvas, wxDC &dc)
| This refreshes the preview window with the preview image. More...
virtual bool | Print (bool prompt)
| Invokes the print process using the second wxPrintout object supplied in the wxPrintPreview constructor. More...
virtual bool | RenderPage (int pageNum)
| Renders a page into a wxMemoryDC. More...
virtual void | SetCanvas (wxPreviewCanvas *window)
| Sets the window to be used for displaying the print preview image. More...
virtual bool | SetCurrentPage (int pageNum)
| Sets the current page to be previewed. More...
virtual void | SetFrame (wxFrame *frame)
| Sets the frame to be used for displaying the print preview canvas and control bar. More...
virtual void | SetPrintout (wxPrintout *printout)
| Associates a printout object with the wxPrintPreview object. More...
virtual void | SetZoom (int percent)
| Sets the percentage preview zoom, and refreshes the preview canvas accordingly. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
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). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
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. More...

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

## Constructor & Destructor Documentation

## ◆ wxPrintPreview() [1/2]

wxPrintPreview::wxPrintPreview | ( | wxPrintout * | printout,
|  | wxPrintout * | printoutForPrinting = `NULL`,
|  | wxPrintDialogData * | data = `NULL`
| ) |  |

Constructor.

Pass a printout object, an optional printout object to be used for actual printing, and the address of an optional block of printer data, which will be copied to the print preview object's print data.

If printoutForPrinting is non-NULL, a "Print..." button will be placed on the preview frame so that the user can print directly from the preview interface.

Remarks
  Do not explicitly delete the printout objects once this constructor has been called, since they will be deleted in the wxPrintPreview destructor. The same does not apply to the data argument.

Use IsOk() to check whether the wxPrintPreview object was created correctly.

## ◆ wxPrintPreview() [2/2]

wxPrintPreview::wxPrintPreview | ( | wxPrintout * | printout,
|  | wxPrintout * | printoutForPrinting,
|  | wxPrintData * | data
| ) |  |

## ◆ ~wxPrintPreview()

wxPrintPreview::~wxPrintPreview | ( |  | ) |

Destructor.

Deletes both print preview objects, so do not destroy these objects in your application.

## Member Function Documentation

## ◆ GetCanvas()

virtual wxPreviewCanvas* wxPrintPreview::GetCanvas | ( |  | ) | const
| virtual

Gets the preview window used for displaying the print preview image.

## ◆ GetCurrentPage()

virtual int wxPrintPreview::GetCurrentPage | ( |  | ) | const
| virtual

Gets the page currently being previewed.

## ◆ GetFrame()

virtual wxFrame* wxPrintPreview::GetFrame | ( |  | ) | const
| virtual

Gets the frame used for displaying the print preview canvas and control bar.

## ◆ GetMaxPage()

virtual int wxPrintPreview::GetMaxPage | ( |  | ) | const
| virtual

Returns the maximum page number.

## ◆ GetMinPage()

virtual int wxPrintPreview::GetMinPage | ( |  | ) | const
| virtual

Returns the minimum page number.

## ◆ GetPrintout()

virtual wxPrintout* wxPrintPreview::GetPrintout | ( |  | ) | const
| virtual

Gets the preview printout object associated with the wxPrintPreview object.

## ◆ GetPrintoutForPrinting()

virtual wxPrintout* wxPrintPreview::GetPrintoutForPrinting | ( |  | ) | const
| virtual

Gets the printout object to be used for printing from within the preview interface, or NULL if none exists.

## ◆ GetZoom()

virtual int wxPrintPreview::GetZoom | ( |  | ) | const
| virtual

Gets the current percentage zoom level of the preview canvas.

See also
  SetZoom()

## ◆ IsOk()

virtual bool wxPrintPreview::IsOk | ( |  | ) | const
| virtual

Returns true if the wxPrintPreview is valid, false otherwise.

It could return false if there was a problem initializing the printer device context (current printer not set, for example).

## ◆ PaintPage()

virtual bool wxPrintPreview::PaintPage | ( | wxPreviewCanvas * | canvas,
|  | wxDC & | dc
| ) |  |
| virtual

This refreshes the preview window with the preview image.

It must be called from the preview window's OnPaint member.

The implementation simply blits the preview bitmap onto the canvas, creating a new preview bitmap if none exists.

## ◆ Print()

virtual bool wxPrintPreview::Print | ( | bool | prompt | ) |
| virtual

Invokes the print process using the second wxPrintout object supplied in the wxPrintPreview constructor.

Will normally be called by the Print... panel item on the preview frame's control bar.

Returns false in case of error – call wxPrinter::GetLastError() to get detailed information about the kind of the error.

## ◆ RenderPage()

virtual bool wxPrintPreview::RenderPage | ( | int | pageNum | ) |
| virtual

Renders a page into a wxMemoryDC.

Used internally by wxPrintPreview.

## ◆ SetCanvas()

virtual void wxPrintPreview::SetCanvas | ( | wxPreviewCanvas * | window | ) |
| virtual

Sets the window to be used for displaying the print preview image.

## ◆ SetCurrentPage()

virtual bool wxPrintPreview::SetCurrentPage | ( | int | pageNum | ) |
| virtual

Sets the current page to be previewed.

## ◆ SetFrame()

virtual void wxPrintPreview::SetFrame | ( | wxFrame * | frame | ) |
| virtual

Sets the frame to be used for displaying the print preview canvas and control bar.

## ◆ SetPrintout()

virtual void wxPrintPreview::SetPrintout | ( | wxPrintout * | printout | ) |
| virtual

Associates a printout object with the wxPrintPreview object.

## ◆ SetZoom()

virtual void wxPrintPreview::SetZoom | ( | int | percent | ) |
| virtual

Sets the percentage preview zoom, and refreshes the preview canvas accordingly.

See also
  GetZoom()