From b99017ce201dc312c75354a74810cc07ca49ea17 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 May 2010 20:05:39 +0000 Subject: [PATCH] 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 --- docs/changes.txt | 1 + include/wx/docview.h | 8 ++++++++ src/common/docview.cpp | 31 ++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 357c9534d8..80cd2d646f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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): diff --git a/include/wx/docview.h b/include/wx/docview.h index ee7067b09d..0c92952467 100644 --- a/include/wx/docview.h +++ b/include/wx/docview.h @@ -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); diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 03d455b528..fa23123c8d 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -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) { -- 2.45.2