Store page setup data in wxDocManager.

Printing of documents from wxDocManager always used default page setup data,
allow the user to configure it now.

Add wxDocManager::m_pageSetupDialogData and add a handler for wxID_PRINT_SETUP
command to it.

Closes #11394.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64439 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2010-05-30 20:05:39 +00:00
parent 65052c6fa7
commit b99017ce20
3 changed files with 31 additions and 9 deletions

View File

@ -629,6 +629,7 @@ All:
- wxImage handlers can now support multiple extensions (Ivan Krestinin).
- Added wxFileName::StripExtension() (troelsk).
- Added wxLOCALE_DATE/TIME_FMT support to wxLocale::GetInfo().
- Store page setup data directly in wxDocManager (troelsk).
All (Unix):

View File

@ -371,8 +371,11 @@ public:
void OnFileRevert(wxCommandEvent& event);
void OnFileSave(wxCommandEvent& event);
void OnFileSaveAs(wxCommandEvent& event);
#if wxUSE_PRINTING_ARCHITECTURE
void OnPrint(wxCommandEvent& event);
void OnPreview(wxCommandEvent& event);
void OnPageSetup(wxCommandEvent& event);
#endif // wxUSE_PRINTING_ARCHITECTURE
void OnUndo(wxCommandEvent& event);
void OnRedo(wxCommandEvent& event);
@ -479,6 +482,7 @@ public:
wxDEPRECATED( size_t GetNoHistoryFiles() const );
#endif // WXWIN_COMPATIBILITY_2_6
protected:
#if wxUSE_PRINTING_ARCHITECTURE
virtual wxPreviewFrame* CreatePreviewFrame(wxPrintPreviewBase* preview,
@ -507,6 +511,10 @@ protected:
wxString m_lastDirectory;
static wxDocManager* sm_docManager;
#if wxUSE_PRINTING_ARCHITECTURE
wxPageSetupDialogData m_pageSetupDialogData;
#endif // wxUSE_PRINTING_ARCHITECTURE
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxDocManager)
wxDECLARE_NO_COPY_CLASS(wxDocManager);

View File

@ -897,10 +897,12 @@ BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler)
#if wxUSE_PRINTING_ARCHITECTURE
EVT_MENU(wxID_PRINT, wxDocManager::OnPrint)
EVT_MENU(wxID_PREVIEW, wxDocManager::OnPreview)
EVT_MENU(wxID_PRINT_SETUP, wxDocManager::OnPageSetup)
EVT_UPDATE_UI(wxID_PRINT, wxDocManager::OnUpdateDisableIfNoDoc)
EVT_UPDATE_UI(wxID_PREVIEW, wxDocManager::OnUpdateDisableIfNoDoc)
#endif
EVT_UPDATE_UI(wxID_PRINT_SETUP, wxDocManager::OnUpdateDisableIfNoDoc)
#endif // wxUSE_PRINTING_ARCHITECTURE
END_EVENT_TABLE()
wxDocManager* wxDocManager::sm_docManager = NULL;
@ -1080,9 +1082,10 @@ void wxDocManager::OnFileSaveAs(wxCommandEvent& WXUNUSED(event))
doc->SaveAs();
}
#if wxUSE_PRINTING_ARCHITECTURE
void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_PRINTING_ARCHITECTURE
wxView *view = GetActiveView();
if (!view)
return;
@ -1090,26 +1093,32 @@ void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event))
wxPrintout *printout = view->OnCreatePrintout();
if (printout)
{
wxPrinter printer;
wxPrintDialogData printDialogData(m_pageSetupDialogData.GetPrintData());
wxPrinter printer(&printDialogData);
printer.Print(view->GetFrame(), printout, true);
delete printout;
}
#endif // wxUSE_PRINTING_ARCHITECTURE
}
#if wxUSE_PRINTING_ARCHITECTURE
void wxDocManager::OnPageSetup(wxCommandEvent& WXUNUSED(event))
{
wxPageSetupDialog dlg(wxTheApp->GetTopWindow(), &m_pageSetupDialogData);
if ( dlg.ShowModal() == wxID_OK )
{
m_pageSetupDialogData = dlg.GetPageSetupData();
}
}
wxPreviewFrame* wxDocManager::CreatePreviewFrame(wxPrintPreviewBase* preview,
wxWindow *parent,
const wxString& title)
{
return new wxPreviewFrame(preview, parent, title);
}
#endif // wxUSE_PRINTING_ARCHITECTURE
void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_PRINTING_ARCHITECTURE
wxBusyCursor busy;
wxView *view = GetActiveView();
if (!view)
@ -1118,9 +1127,13 @@ void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
wxPrintout *printout = view->OnCreatePrintout();
if (printout)
{
wxPrintDialogData printDialogData(m_pageSetupDialogData.GetPrintData());
// Pass two printout objects: for preview, and possible printing.
wxPrintPreviewBase *
preview = new wxPrintPreview(printout, view->OnCreatePrintout());
preview = new wxPrintPreview(printout,
view->OnCreatePrintout(),
&printDialogData);
if ( !preview->Ok() )
{
delete preview;
@ -1137,8 +1150,8 @@ void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
frame->Initialize();
frame->Show(true);
}
#endif // wxUSE_PRINTING_ARCHITECTURE
}
#endif // wxUSE_PRINTING_ARCHITECTURE
void wxDocManager::OnUndo(wxCommandEvent& event)
{