Printing Dialogs
You use wxPageSetupDialog and wxPrintDialog in applications that print documents. If you use the printing framework (including wxPrintout, wxPrinter, and other classes), you won't need to invoke these dialogs explicitly in your code. For more on printing, refer to Chapter 5, "Drawing and Printing."
wxPageSetupDialog
wxPageSetupDialog contains controls for paper size such as A4 and letter, orientation (landscape or portrait), and controls for setting left, top, right, and bottom margin sizes in millimeters. The user can also set printer-specific options by invoking a further dialog from this one.Figure 8-27 shows the wxPageSetupDialog dialog under Windows.
Figure 8-27. wxPageSetupDialog under Windows

Figure 8-28. wxPageSetupDialog under GTK+ without GNOME printing

Figure 8-29. wxPageSetupDialog under GTK+ with GNOME printing
[View full size image]

Figure 8-30. wxPageSetupDialog under Mac OS X

wxPageSetupData Functions
wxPageSetupDialogData has the following functions.Ok returns true if the print data associated with the object is valid. This can return false on Windows if the current printer is not set, for example. On all other platforms, it returns true.SetMarginTopLeft takes a wxPoint object and sets the left and top margins in millimeters. Call GetMarginTopLeft to retrieve this value.SetMarginBottomRight takes a wxPoint object and sets the bottom and right margins in millimeters. Call GetMarginBottomRight to retrieve this value.SetPaperId sets the paper identifier to select the current paper size, instead of using SetPaperSize. See the documentation for this function for the symbols that are available. GetPaperId retrieves the paper identifier.SetPaperSize takes a wxSize object and sets the paper size in millimeters. Use GetPaperSize to retrieve the current paper size.EnableMargins enables or disables the margin controls (Windows only). Call GetEnableMargins to test the value of this setting.EnableOrientation enables or disables the orientation control (Windows only). Call GetEnableOrientation to test the value of this setting.EnablePaper enables or disables the paper size control (Windows only). Call GetEnablePaper to test the value of this setting.EnablePrinter enables or disables the Printer button, which invokes a print setup dialog. Call GetEnablePrinter to test the value of this setting.
wxPageSetupDialog Example
Here's an example of using wxPageSetupDialog:
#include "wx/printdlg.h"
void MyFrame::OnPageSetup(wxCommandEvent& event)
{
wxPageSetupDialog pageSetupDialog(this, & m_pageSetupData);
if (pageSetupDialog.ShowModal() == wxID_OK)
m_pageSetupData = pageSetupDialog.GetPageSetupData();
}
wxPrintDialog
This class represents the print and print setup standard dialogs. You may obtain a wxPrinterDC device context from a successfully dismissed print dialog.Figure 8-31 shows wxPrintDialog under Windows.
Figure 8-31. wxPrintDialog under Windows

Figure 8-32. wxPrintDialog under GTK+ without GNOME printing

Figure 8-33. wxPrintDialog under GTK+ with GNOME printing

Figure 8-34. wxPrintDialog under Mac OS X

wxPrintDialogData Functions
These are the functions you can use with wxPrintDialogData.EnableHelp enables or disables the Help button. Use GetEnableHelp to return the value of this setting.EnablePageNumbers enables or disables the page number controls, and GetEnablePageNumbers returns the value of this setting.EnablePrintToFile enables or disables the Print to File check box. Use GetEnablePrintToFile to return the value of this setting.EnableSelection enables or disables the Selection radio button that lets the user specify that the current selection should be printed. Use GetEnableSelection to return the value of this setting.SetCollate sets the Collate check box to be TRue or false. Use GetCollate to return the value of this setting.SetFromPage and SetToPage set the page range to print. Use GetFromPage and GetToPage to return this range.SetMinPage and SetMaxPage set the minimum and maximum page numbers that can be printed. Use GetMinPage and GetMaxPage to return these values.SetNoCopies sets the default number of copies that will be printed. Use GetNoCopies to return the value of this setting.SetPrintToFile sets the Print to File check box to TRue or false. Use GetPrintToFile to return the value of this setting.SetSelection sets the Selection radio button. Use GetSelection to return the value of this setting.SetSetupDialog determines whether the print setup dialog is shown (TRue) or the normal print dialog is shown (false). Use GetSetupDialog to return the value of this setting.SetPrintData sets the internal wxPrintData object. GetPrintData returns a reference to the internal wxPrintData object.
wxPrintDialog Example
The following example shows wxPrintDialog being used to return a suitable printer device context:
However, usually you can avoid invoking the print dialog directly. Instead, use the higher-level printing framework (refer to Chapter 5). The print dialog will be shown as a side effect of calling wxPrinter::Print.
#include "wx/printdlg.h"
void MyFrame::OnPrint(wxCommandEvent& event)
{
wxPrintDialogData dialogData;
dialogData.SetFromPage(0);
dialogData.SetToPage(10);
wxPrintDialog printDialog(this, & m_dialogData);
if (printDialog.ShowModal() == wxID_OK)
{
// After calling GetPrintDC(), the application
// owns the DC
wxDC* dc = printDialog.GetPrintDC();
// Draw on the device context
...
// Destroy it
delete dc;
}
}