#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"
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 );
}
#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));
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)
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.
m_closeButton = NULL;
m_zoomControl = NULL;
m_currentPageText = NULL;
+ m_maxPageText = NULL;
m_buttonFlags = buttons;
}
void wxPreviewControlBar::CreateButtons()
{
- SetSize(0, 0, 400, 40);
-
SizerWithButtons sizer(this);
// Print button group (a single button).
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)
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)
m_controlBar = NULL;
m_previewCanvas = NULL;
m_windowDisabler = NULL;
+ m_modalityKind = wxPreviewFrame_NonModal;
// Give the application icon
#ifdef __WXMSW__
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)
{
}
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();
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();
if (m_printPreview->GetPrintoutForPrinting())
buttons |= wxPREVIEW_PRINT;
- m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0,0), wxSize(400, 40));
+ m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this);
m_controlBar->CreateButtons();
}
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;
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();
{
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);
bool wxPrintPreview::IsOk() const
{
- return m_pimpl->Ok();
+ return m_pimpl->IsOk();
}
void wxPrintPreview::SetOk(bool ok)