1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Printing framework base class implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "prntbase.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #if wxUSE_PRINTING_ARCHITECTURE
31 #include "wx/msgdlg.h"
32 #include "wx/layout.h"
33 #include "wx/choice.h"
34 #include "wx/button.h"
35 #include "wx/settings.h"
36 #include "wx/dcmemory.h"
37 #include "wx/stattext.h"
39 #include "wx/textdlg.h"
43 #include "wx/prntbase.h"
44 #include "wx/dcprint.h"
45 #include "wx/printdlg.h"
46 #include "wx/module.h"
52 #include "wx/msw/private.h"
60 IMPLEMENT_CLASS(wxPrinterBase
, wxObject
)
61 IMPLEMENT_ABSTRACT_CLASS(wxPrintout
, wxObject
)
62 IMPLEMENT_CLASS(wxPreviewCanvas
, wxWindow
)
63 IMPLEMENT_CLASS(wxPreviewControlBar
, wxWindow
)
64 IMPLEMENT_CLASS(wxPreviewFrame
, wxFrame
)
65 IMPLEMENT_CLASS(wxPrintPreviewBase
, wxObject
)
67 BEGIN_EVENT_TABLE(wxPrintAbortDialog
, wxDialog
)
68 EVT_BUTTON(wxID_CANCEL
, wxPrintAbortDialog::OnCancel
)
71 BEGIN_EVENT_TABLE(wxPreviewCanvas
, wxScrolledWindow
)
72 EVT_PAINT(wxPreviewCanvas::OnPaint
)
73 EVT_CHAR(wxPreviewCanvas::OnChar
)
74 EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged
)
81 wxPrinterBase::wxPrinterBase(wxPrintDialogData
*data
)
83 m_currentPrintout
= (wxPrintout
*) NULL
;
84 sm_abortWindow
= (wxWindow
*) NULL
;
87 m_printDialogData
= (*data
);
88 sm_lastError
= wxPRINTER_NO_ERROR
;
91 wxWindow
*wxPrinterBase::sm_abortWindow
= (wxWindow
*) NULL
;
92 bool wxPrinterBase::sm_abortIt
= FALSE
;
93 wxPrinterError
wxPrinterBase::sm_lastError
= wxPRINTER_NO_ERROR
;
95 wxPrinterBase::~wxPrinterBase()
99 void wxPrintAbortDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
101 wxPrinterBase::sm_abortIt
= TRUE
;
102 wxPrinterBase::sm_abortWindow
->Show(FALSE
);
103 wxPrinterBase::sm_abortWindow
->Close(TRUE
);
104 wxPrinterBase::sm_abortWindow
= (wxWindow
*) NULL
;
107 wxWindow
*wxPrinterBase::CreateAbortWindow(wxWindow
*parent
, wxPrintout
* printout
)
109 wxPrintAbortDialog
*dialog
= new wxPrintAbortDialog(parent
, _("Printing ") , wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
);
111 wxBoxSizer
*button_sizer
= new wxBoxSizer( wxVERTICAL
);
112 button_sizer
->Add( new wxStaticText(dialog
, -1, _("Please wait while printing\n") + printout
->GetTitle() ), 0, wxALL
, 10 );
113 button_sizer
->Add( new wxButton( dialog
, wxID_CANCEL
, wxT("Cancel") ), 0, wxALL
| wxALIGN_CENTER
, 10 );
115 dialog
->SetAutoLayout( TRUE
);
116 dialog
->SetSizer( button_sizer
);
118 button_sizer
->Fit(dialog
);
119 button_sizer
->SetSizeHints (dialog
) ;
124 void wxPrinterBase::ReportError(wxWindow
*parent
, wxPrintout
*WXUNUSED(printout
), const wxString
& message
)
126 wxMessageBox(message
, _("Printing Error"), wxOK
, parent
);
133 wxPrintout::wxPrintout(const wxString
& title
)
135 m_printoutTitle
= title
;
136 m_printoutDC
= (wxDC
*) NULL
;
139 m_pageWidthPixels
= 0;
140 m_pageHeightPixels
= 0;
148 wxPrintout::~wxPrintout()
152 bool wxPrintout::OnBeginDocument(int WXUNUSED(startPage
), int WXUNUSED(endPage
))
154 return GetDC()->StartDoc(_("Printing ") + m_printoutTitle
);
157 void wxPrintout::OnEndDocument()
162 void wxPrintout::OnBeginPrinting()
166 void wxPrintout::OnEndPrinting()
170 bool wxPrintout::HasPage(int page
)
175 void wxPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *fromPage
, int *toPage
)
187 wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase
*preview
, wxWindow
*parent
,
188 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
189 wxScrolledWindow(parent
, -1, pos
, size
, style
, name
)
191 m_printPreview
= preview
;
193 // The app workspace colour is always white, but we should have
194 // a contrast with the page.
195 wxSystemColour colourIndex
= wxSYS_COLOUR_3DDKSHADOW
;
197 wxSystemColour colourIndex
= wxSYS_COLOUR_APPWORKSPACE
;
199 SetBackgroundColour(wxSystemSettings::GetColour(colourIndex
));
201 SetScrollbars(10, 10, 100, 100);
204 wxPreviewCanvas::~wxPreviewCanvas()
208 void wxPreviewCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
215 if (!GetUpdateRegion().IsEmpty())
216 dc.SetClippingRegion( GetUpdateRegion() );
222 m_printPreview
->PaintPage(this, dc
);
226 // Responds to colour changes, and passes event on to children.
227 void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent
& event
)
230 // The app workspace colour is always white, but we should have
231 // a contrast with the page.
232 wxSystemColour colourIndex
= wxSYS_COLOUR_3DDKSHADOW
;
234 wxSystemColour colourIndex
= wxSYS_COLOUR_APPWORKSPACE
;
236 SetBackgroundColour(wxSystemSettings::GetColour(colourIndex
));
239 // Propagate the event to the non-top-level children
240 wxWindow::OnSysColourChanged(event
);
243 void wxPreviewCanvas::OnChar(wxKeyEvent
&event
)
245 if (event
.GetKeyCode() == WXK_ESCAPE
)
247 ((wxPreviewFrame
*) GetParent())->Close(TRUE
);
251 if (!event
.ControlDown())
257 wxPreviewControlBar
* controlBar
= ((wxPreviewFrame
*) GetParent())->GetControlBar();
258 switch(event
.GetKeyCode())
261 controlBar
->OnNext(); break;
263 controlBar
->OnPrevious(); break;
265 controlBar
->OnFirst(); break;
267 controlBar
->OnLast(); break;
269 controlBar
->OnGoto(); break;
276 * Preview control bar
279 BEGIN_EVENT_TABLE(wxPreviewControlBar
, wxPanel
)
280 EVT_BUTTON(wxID_PREVIEW_CLOSE
, wxPreviewControlBar::OnWindowClose
)
281 EVT_BUTTON(wxID_PREVIEW_PRINT
, wxPreviewControlBar::OnPrint
)
282 EVT_BUTTON(wxID_PREVIEW_PREVIOUS
, wxPreviewControlBar::OnPreviousButton
)
283 EVT_BUTTON(wxID_PREVIEW_NEXT
, wxPreviewControlBar::OnNextButton
)
284 EVT_BUTTON(wxID_PREVIEW_FIRST
, wxPreviewControlBar::OnFirstButton
)
285 EVT_BUTTON(wxID_PREVIEW_LAST
, wxPreviewControlBar::OnLastButton
)
286 EVT_BUTTON(wxID_PREVIEW_GOTO
, wxPreviewControlBar::OnGotoButton
)
287 EVT_CHOICE(wxID_PREVIEW_ZOOM
, wxPreviewControlBar::OnZoom
)
288 EVT_PAINT(wxPreviewControlBar::OnPaint
)
291 wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase
*preview
, long buttons
,
292 wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
293 long style
, const wxString
& name
):
294 wxPanel(parent
, -1, pos
, size
, style
, name
)
296 m_printPreview
= preview
;
297 m_closeButton
= (wxButton
*) NULL
;
298 m_nextPageButton
= (wxButton
*) NULL
;
299 m_previousPageButton
= (wxButton
*) NULL
;
300 m_printButton
= (wxButton
*) NULL
;
301 m_zoomControl
= (wxChoice
*) NULL
;
302 m_buttonFlags
= buttons
;
305 wxPreviewControlBar::~wxPreviewControlBar()
309 void wxPreviewControlBar::OnPaint(wxPaintEvent
& WXUNUSED(event
))
315 dc
.SetPen(*wxBLACK_PEN
);
316 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
317 dc
.DrawLine( 0, h
-1, w
, h
-1 );
320 void wxPreviewControlBar::OnWindowClose(wxCommandEvent
& WXUNUSED(event
))
322 wxPreviewFrame
*frame
= (wxPreviewFrame
*)GetParent();
326 void wxPreviewControlBar::OnPrint(wxCommandEvent
& WXUNUSED(event
))
328 wxPrintPreviewBase
*preview
= GetPrintPreview();
329 preview
->Print(TRUE
);
332 void wxPreviewControlBar::OnNext(void)
334 wxPrintPreviewBase
*preview
= GetPrintPreview();
337 int currentPage
= preview
->GetCurrentPage();
338 if ((preview
->GetMaxPage() > 0) &&
339 (currentPage
< preview
->GetMaxPage()) &&
340 preview
->GetPrintout()->HasPage(currentPage
+ 1))
342 preview
->SetCurrentPage(currentPage
+ 1);
347 void wxPreviewControlBar::OnPrevious(void)
349 wxPrintPreviewBase
*preview
= GetPrintPreview();
352 int currentPage
= preview
->GetCurrentPage();
353 if ((preview
->GetMinPage() > 0) &&
354 (currentPage
> preview
->GetMinPage()) &&
355 preview
->GetPrintout()->HasPage(currentPage
- 1))
357 preview
->SetCurrentPage(currentPage
- 1);
362 void wxPreviewControlBar::OnFirst(void)
364 wxPrintPreviewBase
*preview
= GetPrintPreview();
367 int currentPage
= preview
->GetMinPage();
368 if (preview
->GetPrintout()->HasPage(currentPage
))
370 preview
->SetCurrentPage(currentPage
);
375 void wxPreviewControlBar::OnLast(void)
377 wxPrintPreviewBase
*preview
= GetPrintPreview();
380 int currentPage
= preview
->GetMaxPage();
381 if (preview
->GetPrintout()->HasPage(currentPage
))
383 preview
->SetCurrentPage(currentPage
);
388 void wxPreviewControlBar::OnGoto(void)
390 wxPrintPreviewBase
*preview
= GetPrintPreview();
395 if (preview
->GetMinPage() > 0)
400 strPrompt
.Printf( _("Enter a page number between %d and %d:"),
401 preview
->GetMinPage(), preview
->GetMaxPage());
402 strPage
.Printf( wxT("%d"), preview
->GetCurrentPage() );
405 wxGetTextFromUser( strPrompt
, _("Goto Page"), strPage
, GetParent());
407 if ( strPage
.ToLong( ¤tPage
) )
408 if (preview
->GetPrintout()->HasPage(currentPage
))
410 preview
->SetCurrentPage(currentPage
);
416 void wxPreviewControlBar::OnZoom(wxCommandEvent
& WXUNUSED(event
))
418 int zoom
= GetZoomControl();
419 if (GetPrintPreview())
420 GetPrintPreview()->SetZoom(zoom
);
423 void wxPreviewControlBar::CreateButtons()
425 SetSize(0, 0, 400, 40);
427 wxBoxSizer
*item0
= new wxBoxSizer( wxHORIZONTAL
);
429 int smallButtonWidth
= 45;
431 m_closeButton
= new wxButton( this, wxID_PREVIEW_CLOSE
, _("&Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
432 item0
->Add( m_closeButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
434 if (m_buttonFlags
& wxPREVIEW_PRINT
)
436 m_printButton
= new wxButton( this, wxID_PREVIEW_PRINT
, _("&Print..."), wxDefaultPosition
, wxDefaultSize
, 0 );
437 item0
->Add( m_printButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
440 if (m_buttonFlags
& wxPREVIEW_FIRST
)
442 m_firstPageButton
= new wxButton( this, wxID_PREVIEW_FIRST
, _("|<<"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
443 item0
->Add( m_firstPageButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
446 if (m_buttonFlags
& wxPREVIEW_PREVIOUS
)
448 m_previousPageButton
= new wxButton( this, wxID_PREVIEW_PREVIOUS
, _("<<"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
449 item0
->Add( m_previousPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
452 if (m_buttonFlags
& wxPREVIEW_NEXT
)
454 m_nextPageButton
= new wxButton( this, wxID_PREVIEW_NEXT
, _(">>"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
455 item0
->Add( m_nextPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
458 if (m_buttonFlags
& wxPREVIEW_LAST
)
460 m_lastPageButton
= new wxButton( this, wxID_PREVIEW_LAST
, _(">>|"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
461 item0
->Add( m_lastPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
464 if (m_buttonFlags
& wxPREVIEW_GOTO
)
466 m_gotoPageButton
= new wxButton( this, wxID_PREVIEW_GOTO
, _("&Goto..."), wxDefaultPosition
, wxDefaultSize
, 0 );
467 item0
->Add( m_gotoPageButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
470 if (m_buttonFlags
& wxPREVIEW_ZOOM
)
474 wxT("10%"), wxT("15%"), wxT("20%"), wxT("25%"), wxT("30%"), wxT("35%"), wxT("40%"), wxT("45%"), wxT("50%"), wxT("55%"),
475 wxT("60%"), wxT("65%"), wxT("70%"), wxT("75%"), wxT("80%"), wxT("85%"), wxT("90%"), wxT("95%"), wxT("100%"), wxT("110%"),
476 wxT("120%"), wxT("150%"), wxT("200%")
478 int n
= WXSIZEOF(choices
);
480 m_zoomControl
= new wxChoice( this, wxID_PREVIEW_ZOOM
, wxDefaultPosition
, wxSize(70,-1), n
, choices
, 0 );
481 item0
->Add( m_zoomControl
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
482 SetZoomControl(m_printPreview
->GetZoom());
489 void wxPreviewControlBar::SetZoomControl(int zoom
)
492 wxSprintf( buf
, wxT("%d%%"), zoom
);
495 m_zoomControl
->SetStringSelection(buf
);
498 int wxPreviewControlBar::GetZoomControl()
501 if (m_zoomControl
&& (m_zoomControl
->GetStringSelection() != wxT("")))
503 wxStrcpy(buf
, m_zoomControl
->GetStringSelection());
504 buf
[wxStrlen(buf
) - 1] = 0;
505 return (int)wxAtoi(buf
);
515 BEGIN_EVENT_TABLE(wxPreviewFrame
, wxFrame
)
516 EVT_CLOSE(wxPreviewFrame::OnCloseWindow
)
519 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase
*preview
, wxWindow
*parent
, const wxString
& title
,
520 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
521 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
523 m_printPreview
= preview
;
525 m_previewCanvas
= NULL
;
527 // Give the application icon
529 wxFrame
* topFrame
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
531 SetIcon(topFrame
->GetIcon());
535 wxPreviewFrame::~wxPreviewFrame()
539 void wxPreviewFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
541 // MakeModal doesn't work on wxMac, especially when there
542 // are multiple top-level windows.
547 // Need to delete the printout and the print preview
548 wxPrintout
*printout
= m_printPreview
->GetPrintout();
552 m_printPreview
->SetPrintout(NULL
);
553 m_printPreview
->SetCanvas(NULL
);
554 m_printPreview
->SetFrame(NULL
);
556 delete m_printPreview
;
561 void wxPreviewFrame::Initialize()
569 m_printPreview
->SetCanvas(m_previewCanvas
);
570 m_printPreview
->SetFrame(this);
572 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
574 item0
->Add( m_controlBar
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
575 item0
->Add( m_previewCanvas
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
577 SetAutoLayout( TRUE
);
580 // MakeModal doesn't work on wxMac, especially when there
581 // are multiple top-level windows.
588 m_printPreview
->AdjustScrollbars(m_previewCanvas
);
589 m_previewCanvas
->SetFocus();
590 m_controlBar
->SetFocus();
593 void wxPreviewFrame::CreateCanvas()
595 m_previewCanvas
= new wxPreviewCanvas(m_printPreview
, this);
598 void wxPreviewFrame::CreateControlBar()
600 long buttons
= wxPREVIEW_DEFAULT
;
601 if (m_printPreview
->GetPrintoutForPrinting())
602 buttons
|= wxPREVIEW_PRINT
;
604 m_controlBar
= new wxPreviewControlBar(m_printPreview
, buttons
, this, wxPoint(0, 0), wxSize(400, 40));
605 m_controlBar
->CreateButtons();
612 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout
*printout
,
613 wxPrintout
*printoutForPrinting
,
617 m_printDialogData
= (*data
);
619 Init(printout
, printoutForPrinting
);
622 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout
*printout
,
623 wxPrintout
*printoutForPrinting
,
624 wxPrintDialogData
*data
)
627 m_printDialogData
= (*data
);
629 Init(printout
, printoutForPrinting
);
632 void wxPrintPreviewBase::Init(wxPrintout
*printout
,
633 wxPrintout
*printoutForPrinting
)
636 m_previewPrintout
= printout
;
637 if (m_previewPrintout
)
638 m_previewPrintout
->SetIsPreview(TRUE
);
640 m_printPrintout
= printoutForPrinting
;
642 m_previewCanvas
= NULL
;
643 m_previewFrame
= NULL
;
644 m_previewBitmap
= NULL
;
651 m_printingPrepared
= FALSE
;
656 wxPrintPreviewBase::~wxPrintPreviewBase()
658 if (m_previewPrintout
)
659 delete m_previewPrintout
;
661 delete m_previewBitmap
;
663 delete m_printPrintout
;
666 bool wxPrintPreviewBase::SetCurrentPage(int pageNum
)
668 if (m_currentPage
== pageNum
)
671 m_currentPage
= pageNum
;
674 delete m_previewBitmap
;
675 m_previewBitmap
= NULL
;
680 AdjustScrollbars(m_previewCanvas
);
682 if (!RenderPage(pageNum
))
684 m_previewCanvas
->Refresh();
685 m_previewCanvas
->SetFocus();
690 bool wxPrintPreviewBase::PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
)
692 DrawBlankPage(canvas
, dc
);
694 if (!m_previewBitmap
)
695 if (!RenderPage(m_currentPage
))
698 if (!m_previewBitmap
)
704 int canvasWidth
, canvasHeight
;
705 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
707 double zoomScale
= ((float)m_currentZoom
/(float)100);
708 double actualWidth
= (zoomScale
*m_pageWidth
*m_previewScale
);
709 // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale);
711 int x
= (int) ((canvasWidth
- actualWidth
)/2.0);
712 if (x
< m_leftMargin
)
717 temp_dc
.SelectObject(*m_previewBitmap
);
719 dc
.Blit(x
, y
, m_previewBitmap
->GetWidth(), m_previewBitmap
->GetHeight(), &temp_dc
, 0, 0);
721 temp_dc
.SelectObject(wxNullBitmap
);
726 // Adjusts the scrollbars for the current scale
727 void wxPrintPreviewBase::AdjustScrollbars(wxPreviewCanvas
*canvas
)
732 int canvasWidth
, canvasHeight
;
733 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
735 double zoomScale
= ((float)m_currentZoom
/(float)100);
736 double actualWidth
= (zoomScale
*m_pageWidth
*m_previewScale
);
737 double actualHeight
= (zoomScale
*m_pageHeight
*m_previewScale
);
739 // Set the scrollbars appropriately
740 int totalWidth
= actualWidth
+ 2*m_leftMargin
;
741 int totalHeight
= actualHeight
+ 2*m_topMargin
;
742 int scrollUnitsX
= totalWidth
/10;
743 int scrollUnitsY
= totalHeight
/10;
744 wxSize virtualSize
= canvas
->GetVirtualSize();
745 if (virtualSize
.GetWidth() != totalWidth
|| virtualSize
.GetHeight() != totalHeight
)
746 canvas
->SetScrollbars(10, 10, scrollUnitsX
, scrollUnitsY
, 0, 0, TRUE
);
749 bool wxPrintPreviewBase::RenderPage(int pageNum
)
753 int canvasWidth
, canvasHeight
;
755 if (!m_previewCanvas
)
757 wxFAIL_MSG(_T("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"));
761 m_previewCanvas
->GetSize(&canvasWidth
, &canvasHeight
);
763 double zoomScale
= (m_currentZoom
/100.0);
764 int actualWidth
= (int)(zoomScale
*m_pageWidth
*m_previewScale
);
765 int actualHeight
= (int)(zoomScale
*m_pageHeight
*m_previewScale
);
767 int x
= (int)((canvasWidth
- actualWidth
)/2.0);
768 if (x
< m_leftMargin
)
770 // int y = m_topMargin;
773 if (!m_previewBitmap
)
775 m_previewBitmap
= new wxBitmap((int)actualWidth
, (int)actualHeight
);
776 if (!m_previewBitmap
|| !m_previewBitmap
->Ok())
778 if (m_previewBitmap
) {
779 delete m_previewBitmap
;
780 m_previewBitmap
= NULL
;
782 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK
);
788 memoryDC
.SelectObject(*m_previewBitmap
);
792 m_previewPrintout
->SetDC(&memoryDC
);
793 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
795 // Need to delay OnPreparePrinting until here, so we have enough information.
796 if (!m_printingPrepared
)
798 m_previewPrintout
->OnPreparePrinting();
800 m_previewPrintout
->GetPageInfo(&m_minPage
, &m_maxPage
, &selFrom
, &selTo
);
801 m_printingPrepared
= TRUE
;
804 m_previewPrintout
->OnBeginPrinting();
806 if (!m_previewPrintout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
808 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK
);
810 memoryDC
.SelectObject(wxNullBitmap
);
812 delete m_previewBitmap
;
813 m_previewBitmap
= NULL
;
817 m_previewPrintout
->OnPrintPage(pageNum
);
818 m_previewPrintout
->OnEndDocument();
819 m_previewPrintout
->OnEndPrinting();
821 m_previewPrintout
->SetDC(NULL
);
823 memoryDC
.SelectObject(wxNullBitmap
);
828 status
= wxString::Format(_("Page %d of %d"), pageNum
, m_maxPage
);
830 status
= wxString::Format(_("Page %d"), pageNum
);
833 m_previewFrame
->SetStatusText(status
);
840 bool wxPrintPreviewBase::DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
)
842 int canvasWidth
, canvasHeight
;
843 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
845 float zoomScale
= (float)((float)m_currentZoom
/(float)100);
846 float actualWidth
= zoomScale
*m_pageWidth
*m_previewScale
;
847 float actualHeight
= zoomScale
*m_pageHeight
*m_previewScale
;
849 float x
= (float)((canvasWidth
- actualWidth
)/2.0);
850 if (x
< m_leftMargin
)
851 x
= (float)m_leftMargin
;
852 float y
= (float)m_topMargin
;
854 // Draw shadow, allowing for 1-pixel border AROUND the actual page
855 int shadowOffset
= 4;
856 dc
.SetPen(*wxBLACK_PEN
);
857 dc
.SetBrush(*wxBLACK_BRUSH
);
859 dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2));
861 dc
.DrawRectangle((int)(x
+ shadowOffset
), (int)(y
+ actualHeight
+1), (int)(actualWidth
), shadowOffset
);
862 dc
.DrawRectangle((int)(x
+ actualWidth
), (int)(y
+ shadowOffset
), shadowOffset
, (int)(actualHeight
));
864 // Draw blank page allowing for 1-pixel border AROUND the actual page
865 dc
.SetPen(*wxBLACK_PEN
);
866 dc
.SetBrush(*wxWHITE_BRUSH
);
869 wxRegion update_region = canvas->GetUpdateRegion();
870 wxRect r = update_region.GetBox();
872 printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height );
875 dc
.DrawRectangle((int)(x
-2), (int)(y
-1), (int)(actualWidth
+3), (int)(actualHeight
+2));
880 void wxPrintPreviewBase::SetZoom(int percent
)
882 if (m_currentZoom
== percent
)
885 m_currentZoom
= percent
;
888 delete m_previewBitmap
;
889 m_previewBitmap
= NULL
;
894 AdjustScrollbars(m_previewCanvas
);
895 RenderPage(m_currentPage
);
896 ((wxScrolledWindow
*) m_previewCanvas
)->Scroll(0, 0);
897 m_previewCanvas
->Clear();
898 m_previewCanvas
->Refresh();
899 m_previewCanvas
->SetFocus();
903 #endif // wxUSE_PRINTING_ARCHITECTURE