X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e562dfb1a0dbabd0a93d50495de52e827efc59a9..2e14066008229145e2da7b9f05a478ce38631f83:/src/common/prntbase.cpp diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index be09647180..4aebfb1b51 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -32,6 +32,7 @@ #include "wx/layout.h" #include "wx/choice.h" #include "wx/button.h" + #include "wx/bmpbuttn.h" #include "wx/settings.h" #include "wx/dcmemory.h" #include "wx/dcclient.h" @@ -380,6 +381,19 @@ bool wxPrinter::Setup(wxWindow *parent) bool wxPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) { + if ( !prompt && m_printDialogData.GetToPage() == 0 ) + { + // If the dialog is not shown, set the pages range to print everything + // by default (as otherwise we wouldn't print anything at all which is + // certainly not a reasonable default behaviour). + int minPage, maxPage, selFrom, selTo; + printout->GetPageInfo(&minPage, &maxPage, &selFrom, &selTo); + + wxPrintDialogData& pdd = m_pimpl->GetPrintDialogData(); + pdd.SetFromPage(minPage); + pdd.SetToPage(maxPage); + } + return m_pimpl->Print( parent, printout, prompt ); } @@ -985,38 +999,90 @@ void wxPreviewCanvas::OnMouseWheel(wxMouseEvent& event) #endif // wxUSE_MOUSEWHEEL +namespace +{ + +// This is by the controls in the print preview as the maximal (and hence +// longest) page number we may have to display. +enum { MAX_PAGE_NUMBER = 99999 }; + +} // anonymous namespace + +// ---------------------------------------------------------------------------- +// wxPrintPageMaxCtrl +// ---------------------------------------------------------------------------- + +// A simple static control showing the maximal number of pages. +class wxPrintPageMaxCtrl : public wxStaticText +{ +public: + wxPrintPageMaxCtrl(wxWindow *parent) + : wxStaticText( + parent, + wxID_ANY, + wxString(), + wxDefaultPosition, + wxSize + ( + parent->GetTextExtent(MaxAsString(MAX_PAGE_NUMBER)).x, + wxDefaultCoord + ), + wxST_NO_AUTORESIZE | wxALIGN_CENTRE + ) + { + } + + // Set the maximal page to display once we really know what it is. + void SetMaxPage(int maxPage) + { + SetLabel(MaxAsString(maxPage)); + } + +private: + static wxString MaxAsString(int maxPage) + { + return wxString::Format("/ %d", maxPage); + } + + wxDECLARE_NO_COPY_CLASS(wxPrintPageMaxCtrl); +}; + // ---------------------------------------------------------------------------- // wxPrintPageTextCtrl // ---------------------------------------------------------------------------- -// This text control contains the page number in the interval specified during -// its construction. Invalid pages are not accepted and the control contents is -// validated when it loses focus. Conversely, if the user changes the page to -// another valid one or presses Enter, OnGotoPage() method of the preview object -// will be called. +// This text control contains the page number in the specified interval. +// +// Invalid pages are not accepted and the control contents is validated when it +// loses focus. Conversely, if the user changes the page to another valid one +// or presses Enter, OnGotoPage() method of the preview object will be called. class wxPrintPageTextCtrl : public wxTextCtrl { public: - wxPrintPageTextCtrl(wxPreviewControlBar *preview, int minPage, int maxPage) + wxPrintPageTextCtrl(wxPreviewControlBar *preview) : wxTextCtrl(preview, wxID_PREVIEW_GOTO, - PageAsString(minPage), + wxString(), wxDefaultPosition, - // We use hardcoded 99999 for the width instead of fitting - // it to the values we can show because the control looks - // uncomfortably narrow if the real page number is just - // one or two digits. - wxSize(preview->GetTextExtent("99999").x, wxDefaultCoord), + // We use hardcoded maximal page number for the width + // instead of fitting it to the values we can show because + // the control looks uncomfortably narrow if the real page + // number is just one or two digits. + wxSize + ( + preview->GetTextExtent(PageAsString(MAX_PAGE_NUMBER)).x, + wxDefaultCoord + ), wxTE_PROCESS_ENTER #if wxUSE_VALIDATORS , wxTextValidator(wxFILTER_DIGITS) #endif // wxUSE_VALIDATORS ), - m_preview(preview), - m_minPage(minPage), - m_maxPage(maxPage) + m_preview(preview) { - m_page = minPage; + m_minPage = + m_maxPage = + m_page = 1; Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler(wxPrintPageTextCtrl::OnKillFocus)); @@ -1024,6 +1090,17 @@ public: wxCommandEventHandler(wxPrintPageTextCtrl::OnTextEnter)); } + // Update the pages range, must be called after OnPreparePrinting() as + // these values are not known before. + void SetPageInfo(int minPage, int maxPage) + { + m_minPage = minPage; + m_maxPage = maxPage; + + // Show the first page by default. + SetPageNumber(minPage); + } + // Helpers to conveniently set or get the current page number. Return value // is 0 if the current controls contents is invalid. void SetPageNumber(int page) @@ -1094,8 +1171,8 @@ private: wxPreviewControlBar * const m_preview; - const int m_minPage, - m_maxPage; + int m_minPage, + m_maxPage; // This is the last valid page value that we had, we revert to it if an // invalid page is entered. @@ -1141,6 +1218,7 @@ wxPanel(parent, wxID_ANY, pos, size, style, name) m_closeButton = NULL; m_zoomControl = NULL; m_currentPageText = NULL; + m_maxPageText = NULL; m_buttonFlags = buttons; } @@ -1422,18 +1500,11 @@ void wxPreviewControlBar::CreateButtons() if (m_buttonFlags & wxPREVIEW_GOTO) { - int minPage, maxPage, pageFrom, pageTo; - m_printPreview->GetPrintout()->GetPageInfo(&minPage, &maxPage, - &pageFrom, &pageTo); - - m_currentPageText = new wxPrintPageTextCtrl(this, minPage, maxPage); + m_currentPageText = new wxPrintPageTextCtrl(this); sizer.Add(m_currentPageText); - wxStaticText * - maxPageText = new wxStaticText(this, wxID_ANY, - wxString::Format("/ %d", maxPage)); - - sizer.Add(maxPageText); + m_maxPageText = new wxPrintPageMaxCtrl(this); + sizer.Add(m_maxPageText); } if (m_buttonFlags & wxPREVIEW_NEXT) @@ -1475,6 +1546,15 @@ void wxPreviewControlBar::CreateButtons() sizer.AddAtEnd(m_closeButton); } +void wxPreviewControlBar::SetPageInfo(int minPage, int maxPage) +{ + if ( m_currentPageText ) + m_currentPageText->SetPageInfo(minPage, maxPage); + + if ( m_maxPageText ) + m_maxPageText->SetMaxPage(maxPage); +} + void wxPreviewControlBar::SetZoomControl(int zoom) { if (m_zoomControl) @@ -1539,6 +1619,7 @@ wxFrame(parent, wxID_ANY, title, pos, size, style, name) m_controlBar = NULL; m_previewCanvas = NULL; m_windowDisabler = NULL; + m_modalityKind = wxPreviewFrame_NonModal; // Give the application icon #ifdef __WXMSW__ @@ -1550,14 +1631,6 @@ wxFrame(parent, wxID_ANY, title, pos, size, style, name) wxPreviewFrame::~wxPreviewFrame() { -} - -void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) -{ - if (m_windowDisabler) - delete m_windowDisabler; - - // Need to delete the printout and the print preview wxPrintout *printout = m_printPreview->GetPrintout(); if (printout) { @@ -1568,12 +1641,33 @@ void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) } m_previewCanvas->SetPreview(NULL); - wxDELETE(m_printPreview); + delete m_printPreview; +} + +void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) +{ + // Reenable any windows we disabled by undoing whatever we did in our + // Initialize(). + switch ( m_modalityKind ) + { + case wxPreviewFrame_AppModal: + delete m_windowDisabler; + m_windowDisabler = NULL; + break; + + case wxPreviewFrame_WindowModal: + if ( GetParent() ) + GetParent()->Enable(); + break; + + case wxPreviewFrame_NonModal: + break; + } Destroy(); } -void wxPreviewFrame::Initialize() +void wxPreviewFrame::InitializeWithModality(wxPreviewFrameModalityKind kind) { #if wxUSE_STATUSBAR CreateStatusBar(); @@ -1592,7 +1686,25 @@ void wxPreviewFrame::Initialize() SetAutoLayout( true ); SetSizer( item0 ); - m_windowDisabler = new wxWindowDisabler(this); + m_modalityKind = kind; + switch ( m_modalityKind ) + { + case wxPreviewFrame_AppModal: + // Disable everything. + m_windowDisabler = new wxWindowDisabler( this ); + break; + + case wxPreviewFrame_WindowModal: + // Disable our parent if we have one. + if ( GetParent() ) + GetParent()->Disable(); + break; + + case wxPreviewFrame_NonModal: + // Nothing to do, we don't need to disable any windows. + break; + } + Layout(); @@ -1658,8 +1770,8 @@ void wxPrintPreviewBase::Init(wxPrintout *printout, m_previewFailed = false; m_currentPage = 1; m_currentZoom = 70; - m_topMargin = 40; - m_leftMargin = 40; + m_topMargin = + m_leftMargin = 2*wxSizerFlags::GetDefaultBorder(); m_pageWidth = 0; m_pageHeight = 0; m_printingPrepared = false; @@ -1815,13 +1927,23 @@ bool wxPrintPreviewBase::RenderPageIntoDC(wxDC& dc, int pageNum) m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); // Need to delay OnPreparePrinting() until here, so we have enough - // information. + // information and a wxDC. if (!m_printingPrepared) { + m_printingPrepared = true; + m_previewPrintout->OnPreparePrinting(); int selFrom, selTo; m_previewPrintout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo); - m_printingPrepared = true; + + // Update the wxPreviewControlBar page range display. + if ( m_previewFrame ) + { + wxPreviewControlBar * const + controlBar = ((wxPreviewFrame*)m_previewFrame)->GetControlBar(); + if ( controlBar ) + controlBar->SetPageInfo(m_minPage, m_maxPage); + } } m_previewPrintout->OnBeginPrinting(); @@ -1867,7 +1989,7 @@ bool wxPrintPreviewBase::RenderPage(int pageNum) { m_previewBitmap = new wxBitmap(pageRect.width, pageRect.height); - if (!m_previewBitmap || !m_previewBitmap->Ok()) + if (!m_previewBitmap || !m_previewBitmap->IsOk()) { InvalidatePreviewBitmap(); wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK); @@ -2088,7 +2210,7 @@ int wxPrintPreview::GetMinPage() const bool wxPrintPreview::IsOk() const { - return m_pimpl->Ok(); + return m_pimpl->IsOk(); } void wxPrintPreview::SetOk(bool ok)