1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Printing framework base class implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 // VZ: the current code doesn't refresh properly without
188 // wxFULL_REPAINT_ON_RESIZE, this must be fixed as otherwise we have
189 // really horrible flicker when resizing the preview frame, but without
190 // this style it simply doesn't work correctly at all...
191 wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase
*preview
, wxWindow
*parent
,
192 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
193 wxScrolledWindow(parent
, -1, pos
, size
, style
| wxFULL_REPAINT_ON_RESIZE
, name
)
195 m_printPreview
= preview
;
197 // The app workspace colour is always white, but we should have
198 // a contrast with the page.
199 wxSystemColour colourIndex
= wxSYS_COLOUR_3DDKSHADOW
;
201 wxSystemColour colourIndex
= wxSYS_COLOUR_APPWORKSPACE
;
203 SetBackgroundColour(wxSystemSettings::GetColour(colourIndex
));
205 SetScrollbars(10, 10, 100, 100);
208 wxPreviewCanvas::~wxPreviewCanvas()
212 void wxPreviewCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
))
219 if (!GetUpdateRegion().IsEmpty())
220 dc.SetClippingRegion( GetUpdateRegion() );
226 m_printPreview
->PaintPage(this, dc
);
230 // Responds to colour changes, and passes event on to children.
231 void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent
& event
)
234 // The app workspace colour is always white, but we should have
235 // a contrast with the page.
236 wxSystemColour colourIndex
= wxSYS_COLOUR_3DDKSHADOW
;
238 wxSystemColour colourIndex
= wxSYS_COLOUR_APPWORKSPACE
;
240 SetBackgroundColour(wxSystemSettings::GetColour(colourIndex
));
243 // Propagate the event to the non-top-level children
244 wxWindow::OnSysColourChanged(event
);
247 void wxPreviewCanvas::OnChar(wxKeyEvent
&event
)
249 wxPreviewControlBar
* controlBar
= ((wxPreviewFrame
*) GetParent())->GetControlBar();
250 if (event
.GetKeyCode() == WXK_ESCAPE
)
252 ((wxPreviewFrame
*) GetParent())->Close(TRUE
);
255 else if (event
.GetKeyCode() == WXK_TAB
)
257 controlBar
->OnGoto();
260 else if (event
.GetKeyCode() == WXK_RETURN
)
262 controlBar
->OnPrint();
266 if (!event
.ControlDown())
272 switch(event
.GetKeyCode())
275 controlBar
->OnNext(); break;
277 controlBar
->OnPrevious(); break;
279 controlBar
->OnFirst(); break;
281 controlBar
->OnLast(); break;
288 * Preview control bar
291 BEGIN_EVENT_TABLE(wxPreviewControlBar
, wxPanel
)
292 EVT_BUTTON(wxID_PREVIEW_CLOSE
, wxPreviewControlBar::OnWindowClose
)
293 EVT_BUTTON(wxID_PREVIEW_PRINT
, wxPreviewControlBar::OnPrintButton
)
294 EVT_BUTTON(wxID_PREVIEW_PREVIOUS
, wxPreviewControlBar::OnPreviousButton
)
295 EVT_BUTTON(wxID_PREVIEW_NEXT
, wxPreviewControlBar::OnNextButton
)
296 EVT_BUTTON(wxID_PREVIEW_FIRST
, wxPreviewControlBar::OnFirstButton
)
297 EVT_BUTTON(wxID_PREVIEW_LAST
, wxPreviewControlBar::OnLastButton
)
298 EVT_BUTTON(wxID_PREVIEW_GOTO
, wxPreviewControlBar::OnGotoButton
)
299 EVT_CHOICE(wxID_PREVIEW_ZOOM
, wxPreviewControlBar::OnZoom
)
300 EVT_PAINT(wxPreviewControlBar::OnPaint
)
303 wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase
*preview
, long buttons
,
304 wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
305 long style
, const wxString
& name
):
306 wxPanel(parent
, -1, pos
, size
, style
, name
)
308 m_printPreview
= preview
;
309 m_closeButton
= (wxButton
*) NULL
;
310 m_nextPageButton
= (wxButton
*) NULL
;
311 m_previousPageButton
= (wxButton
*) NULL
;
312 m_printButton
= (wxButton
*) NULL
;
313 m_zoomControl
= (wxChoice
*) NULL
;
314 m_buttonFlags
= buttons
;
317 wxPreviewControlBar::~wxPreviewControlBar()
321 void wxPreviewControlBar::OnPaint(wxPaintEvent
& WXUNUSED(event
))
327 dc
.SetPen(*wxBLACK_PEN
);
328 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
329 dc
.DrawLine( 0, h
-1, w
, h
-1 );
332 void wxPreviewControlBar::OnWindowClose(wxCommandEvent
& WXUNUSED(event
))
334 wxPreviewFrame
*frame
= (wxPreviewFrame
*)GetParent();
338 void wxPreviewControlBar::OnPrint(void)
340 wxPrintPreviewBase
*preview
= GetPrintPreview();
341 preview
->Print(TRUE
);
344 void wxPreviewControlBar::OnNext(void)
346 wxPrintPreviewBase
*preview
= GetPrintPreview();
349 int currentPage
= preview
->GetCurrentPage();
350 if ((preview
->GetMaxPage() > 0) &&
351 (currentPage
< preview
->GetMaxPage()) &&
352 preview
->GetPrintout()->HasPage(currentPage
+ 1))
354 preview
->SetCurrentPage(currentPage
+ 1);
359 void wxPreviewControlBar::OnPrevious(void)
361 wxPrintPreviewBase
*preview
= GetPrintPreview();
364 int currentPage
= preview
->GetCurrentPage();
365 if ((preview
->GetMinPage() > 0) &&
366 (currentPage
> preview
->GetMinPage()) &&
367 preview
->GetPrintout()->HasPage(currentPage
- 1))
369 preview
->SetCurrentPage(currentPage
- 1);
374 void wxPreviewControlBar::OnFirst(void)
376 wxPrintPreviewBase
*preview
= GetPrintPreview();
379 int currentPage
= preview
->GetMinPage();
380 if (preview
->GetPrintout()->HasPage(currentPage
))
382 preview
->SetCurrentPage(currentPage
);
387 void wxPreviewControlBar::OnLast(void)
389 wxPrintPreviewBase
*preview
= GetPrintPreview();
392 int currentPage
= preview
->GetMaxPage();
393 if (preview
->GetPrintout()->HasPage(currentPage
))
395 preview
->SetCurrentPage(currentPage
);
400 void wxPreviewControlBar::OnGoto(void)
402 wxPrintPreviewBase
*preview
= GetPrintPreview();
407 if (preview
->GetMinPage() > 0)
412 strPrompt
.Printf( _("Enter a page number between %d and %d:"),
413 preview
->GetMinPage(), preview
->GetMaxPage());
414 strPage
.Printf( wxT("%d"), preview
->GetCurrentPage() );
417 wxGetTextFromUser( strPrompt
, _("Goto Page"), strPage
, GetParent());
419 if ( strPage
.ToLong( ¤tPage
) )
420 if (preview
->GetPrintout()->HasPage(currentPage
))
422 preview
->SetCurrentPage(currentPage
);
428 void wxPreviewControlBar::OnZoom(wxCommandEvent
& WXUNUSED(event
))
430 int zoom
= GetZoomControl();
431 if (GetPrintPreview())
432 GetPrintPreview()->SetZoom(zoom
);
435 void wxPreviewControlBar::CreateButtons()
437 SetSize(0, 0, 400, 40);
439 wxBoxSizer
*item0
= new wxBoxSizer( wxHORIZONTAL
);
441 int smallButtonWidth
= 45;
443 m_closeButton
= new wxButton( this, wxID_PREVIEW_CLOSE
, _("&Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
444 item0
->Add( m_closeButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
446 if (m_buttonFlags
& wxPREVIEW_PRINT
)
448 m_printButton
= new wxButton( this, wxID_PREVIEW_PRINT
, _("&Print..."), wxDefaultPosition
, wxDefaultSize
, 0 );
449 item0
->Add( m_printButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
452 if (m_buttonFlags
& wxPREVIEW_FIRST
)
454 m_firstPageButton
= new wxButton( this, wxID_PREVIEW_FIRST
, _("|<<"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
455 item0
->Add( m_firstPageButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
458 if (m_buttonFlags
& wxPREVIEW_PREVIOUS
)
460 m_previousPageButton
= new wxButton( this, wxID_PREVIEW_PREVIOUS
, _("<<"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
461 item0
->Add( m_previousPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
464 if (m_buttonFlags
& wxPREVIEW_NEXT
)
466 m_nextPageButton
= new wxButton( this, wxID_PREVIEW_NEXT
, _(">>"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
467 item0
->Add( m_nextPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
470 if (m_buttonFlags
& wxPREVIEW_LAST
)
472 m_lastPageButton
= new wxButton( this, wxID_PREVIEW_LAST
, _(">>|"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
473 item0
->Add( m_lastPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
476 if (m_buttonFlags
& wxPREVIEW_GOTO
)
478 m_gotoPageButton
= new wxButton( this, wxID_PREVIEW_GOTO
, _("&Goto..."), wxDefaultPosition
, wxDefaultSize
, 0 );
479 item0
->Add( m_gotoPageButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
482 if (m_buttonFlags
& wxPREVIEW_ZOOM
)
486 wxT("10%"), wxT("15%"), wxT("20%"), wxT("25%"), wxT("30%"), wxT("35%"), wxT("40%"), wxT("45%"), wxT("50%"), wxT("55%"),
487 wxT("60%"), wxT("65%"), wxT("70%"), wxT("75%"), wxT("80%"), wxT("85%"), wxT("90%"), wxT("95%"), wxT("100%"), wxT("110%"),
488 wxT("120%"), wxT("150%"), wxT("200%")
490 int n
= WXSIZEOF(choices
);
492 m_zoomControl
= new wxChoice( this, wxID_PREVIEW_ZOOM
, wxDefaultPosition
, wxSize(70,-1), n
, choices
, 0 );
493 item0
->Add( m_zoomControl
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
494 SetZoomControl(m_printPreview
->GetZoom());
501 void wxPreviewControlBar::SetZoomControl(int zoom
)
505 int n
, count
= m_zoomControl
->GetCount();
507 for (n
=0; n
<count
; n
++)
509 if (m_zoomControl
->GetString(n
).BeforeFirst(wxT('%')).ToLong(&val
) &&
512 m_zoomControl
->SetSelection(n
);
517 m_zoomControl
->SetSelection(count
-1);
521 int wxPreviewControlBar::GetZoomControl()
523 if (m_zoomControl
&& (m_zoomControl
->GetStringSelection() != wxEmptyString
))
526 if (m_zoomControl
->GetStringSelection().BeforeFirst(wxT('%')).ToLong(&val
))
538 BEGIN_EVENT_TABLE(wxPreviewFrame
, wxFrame
)
539 EVT_CLOSE(wxPreviewFrame::OnCloseWindow
)
542 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase
*preview
, wxWindow
*parent
, const wxString
& title
,
543 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
544 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
546 m_printPreview
= preview
;
548 m_previewCanvas
= NULL
;
550 // Give the application icon
552 wxFrame
* topFrame
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
554 SetIcon(topFrame
->GetIcon());
558 wxPreviewFrame::~wxPreviewFrame()
562 void wxPreviewFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
564 // MakeModal doesn't work on wxMac, especially when there
565 // are multiple top-level windows.
570 // Need to delete the printout and the print preview
571 wxPrintout
*printout
= m_printPreview
->GetPrintout();
575 m_printPreview
->SetPrintout(NULL
);
576 m_printPreview
->SetCanvas(NULL
);
577 m_printPreview
->SetFrame(NULL
);
579 delete m_printPreview
;
584 void wxPreviewFrame::Initialize()
592 m_printPreview
->SetCanvas(m_previewCanvas
);
593 m_printPreview
->SetFrame(this);
595 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
597 item0
->Add( m_controlBar
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
598 item0
->Add( m_previewCanvas
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
600 SetAutoLayout( TRUE
);
603 // MakeModal doesn't work on wxMac, especially when there
604 // are multiple top-level windows.
611 m_printPreview
->AdjustScrollbars(m_previewCanvas
);
612 m_previewCanvas
->SetFocus();
613 m_controlBar
->SetFocus();
616 void wxPreviewFrame::CreateCanvas()
618 m_previewCanvas
= new wxPreviewCanvas(m_printPreview
, this);
621 void wxPreviewFrame::CreateControlBar()
623 long buttons
= wxPREVIEW_DEFAULT
;
624 if (m_printPreview
->GetPrintoutForPrinting())
625 buttons
|= wxPREVIEW_PRINT
;
627 m_controlBar
= new wxPreviewControlBar(m_printPreview
, buttons
, this, wxPoint(0, 0), wxSize(400, 40));
628 m_controlBar
->CreateButtons();
635 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout
*printout
,
636 wxPrintout
*printoutForPrinting
,
640 m_printDialogData
= (*data
);
642 Init(printout
, printoutForPrinting
);
645 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout
*printout
,
646 wxPrintout
*printoutForPrinting
,
647 wxPrintDialogData
*data
)
650 m_printDialogData
= (*data
);
652 Init(printout
, printoutForPrinting
);
655 void wxPrintPreviewBase::Init(wxPrintout
*printout
,
656 wxPrintout
*printoutForPrinting
)
659 m_previewPrintout
= printout
;
660 if (m_previewPrintout
)
661 m_previewPrintout
->SetIsPreview(TRUE
);
663 m_printPrintout
= printoutForPrinting
;
665 m_previewCanvas
= NULL
;
666 m_previewFrame
= NULL
;
667 m_previewBitmap
= NULL
;
674 m_printingPrepared
= FALSE
;
679 wxPrintPreviewBase::~wxPrintPreviewBase()
681 if (m_previewPrintout
)
682 delete m_previewPrintout
;
684 delete m_previewBitmap
;
686 delete m_printPrintout
;
689 bool wxPrintPreviewBase::SetCurrentPage(int pageNum
)
691 if (m_currentPage
== pageNum
)
694 m_currentPage
= pageNum
;
697 delete m_previewBitmap
;
698 m_previewBitmap
= NULL
;
703 AdjustScrollbars(m_previewCanvas
);
705 if (!RenderPage(pageNum
))
707 m_previewCanvas
->Refresh();
708 m_previewCanvas
->SetFocus();
713 bool wxPrintPreviewBase::PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
)
715 DrawBlankPage(canvas
, dc
);
717 if (!m_previewBitmap
)
718 if (!RenderPage(m_currentPage
))
721 if (!m_previewBitmap
)
727 int canvasWidth
, canvasHeight
;
728 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
730 double zoomScale
= ((float)m_currentZoom
/(float)100);
731 double actualWidth
= (zoomScale
*m_pageWidth
*m_previewScale
);
732 // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale);
734 int x
= (int) ((canvasWidth
- actualWidth
)/2.0);
735 if (x
< m_leftMargin
)
740 temp_dc
.SelectObject(*m_previewBitmap
);
742 dc
.Blit(x
, y
, m_previewBitmap
->GetWidth(), m_previewBitmap
->GetHeight(), &temp_dc
, 0, 0);
744 temp_dc
.SelectObject(wxNullBitmap
);
749 // Adjusts the scrollbars for the current scale
750 void wxPrintPreviewBase::AdjustScrollbars(wxPreviewCanvas
*canvas
)
755 int canvasWidth
, canvasHeight
;
756 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
758 double zoomScale
= ((float)m_currentZoom
/(float)100);
759 double actualWidth
= (zoomScale
*m_pageWidth
*m_previewScale
);
760 double actualHeight
= (zoomScale
*m_pageHeight
*m_previewScale
);
762 // Set the scrollbars appropriately
763 int totalWidth
= (int)(actualWidth
+ 2*m_leftMargin
);
764 int totalHeight
= (int)(actualHeight
+ 2*m_topMargin
);
765 int scrollUnitsX
= totalWidth
/10;
766 int scrollUnitsY
= totalHeight
/10;
767 wxSize virtualSize
= canvas
->GetVirtualSize();
768 if (virtualSize
.GetWidth() != totalWidth
|| virtualSize
.GetHeight() != totalHeight
)
769 canvas
->SetScrollbars(10, 10, scrollUnitsX
, scrollUnitsY
, 0, 0, TRUE
);
772 bool wxPrintPreviewBase::RenderPage(int pageNum
)
776 int canvasWidth
, canvasHeight
;
778 if (!m_previewCanvas
)
780 wxFAIL_MSG(_T("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"));
784 m_previewCanvas
->GetSize(&canvasWidth
, &canvasHeight
);
786 double zoomScale
= (m_currentZoom
/100.0);
787 int actualWidth
= (int)(zoomScale
*m_pageWidth
*m_previewScale
);
788 int actualHeight
= (int)(zoomScale
*m_pageHeight
*m_previewScale
);
790 if (!m_previewBitmap
)
792 m_previewBitmap
= new wxBitmap((int)actualWidth
, (int)actualHeight
);
793 if (!m_previewBitmap
|| !m_previewBitmap
->Ok())
795 if (m_previewBitmap
) {
796 delete m_previewBitmap
;
797 m_previewBitmap
= NULL
;
799 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK
);
805 memoryDC
.SelectObject(*m_previewBitmap
);
809 m_previewPrintout
->SetDC(&memoryDC
);
810 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
812 // Need to delay OnPreparePrinting until here, so we have enough information.
813 if (!m_printingPrepared
)
815 m_previewPrintout
->OnPreparePrinting();
817 m_previewPrintout
->GetPageInfo(&m_minPage
, &m_maxPage
, &selFrom
, &selTo
);
818 m_printingPrepared
= TRUE
;
821 m_previewPrintout
->OnBeginPrinting();
823 if (!m_previewPrintout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
825 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK
);
827 memoryDC
.SelectObject(wxNullBitmap
);
829 delete m_previewBitmap
;
830 m_previewBitmap
= NULL
;
834 m_previewPrintout
->OnPrintPage(pageNum
);
835 m_previewPrintout
->OnEndDocument();
836 m_previewPrintout
->OnEndPrinting();
838 m_previewPrintout
->SetDC(NULL
);
840 memoryDC
.SelectObject(wxNullBitmap
);
845 status
= wxString::Format(_("Page %d of %d"), pageNum
, m_maxPage
);
847 status
= wxString::Format(_("Page %d"), pageNum
);
850 m_previewFrame
->SetStatusText(status
);
857 bool wxPrintPreviewBase::DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
)
859 int canvasWidth
, canvasHeight
;
860 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
862 float zoomScale
= (float)((float)m_currentZoom
/(float)100);
863 float actualWidth
= zoomScale
*m_pageWidth
*m_previewScale
;
864 float actualHeight
= zoomScale
*m_pageHeight
*m_previewScale
;
866 float x
= (float)((canvasWidth
- actualWidth
)/2.0);
867 if (x
< m_leftMargin
)
868 x
= (float)m_leftMargin
;
869 float y
= (float)m_topMargin
;
871 // Draw shadow, allowing for 1-pixel border AROUND the actual page
872 int shadowOffset
= 4;
873 dc
.SetPen(*wxBLACK_PEN
);
874 dc
.SetBrush(*wxBLACK_BRUSH
);
876 dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2));
878 dc
.DrawRectangle((int)(x
+ shadowOffset
), (int)(y
+ actualHeight
+1), (int)(actualWidth
), shadowOffset
);
879 dc
.DrawRectangle((int)(x
+ actualWidth
), (int)(y
+ shadowOffset
), shadowOffset
, (int)(actualHeight
));
881 // Draw blank page allowing for 1-pixel border AROUND the actual page
882 dc
.SetPen(*wxBLACK_PEN
);
883 dc
.SetBrush(*wxWHITE_BRUSH
);
886 wxRegion update_region = canvas->GetUpdateRegion();
887 wxRect r = update_region.GetBox();
889 printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height );
892 dc
.DrawRectangle((int)(x
-2), (int)(y
-1), (int)(actualWidth
+3), (int)(actualHeight
+2));
897 void wxPrintPreviewBase::SetZoom(int percent
)
899 if (m_currentZoom
== percent
)
902 m_currentZoom
= percent
;
905 delete m_previewBitmap
;
906 m_previewBitmap
= NULL
;
911 AdjustScrollbars(m_previewCanvas
);
912 RenderPage(m_currentPage
);
913 ((wxScrolledWindow
*) m_previewCanvas
)->Scroll(0, 0);
914 m_previewCanvas
->ClearBackground();
915 m_previewCanvas
->Refresh();
916 m_previewCanvas
->SetFocus();
920 #endif // wxUSE_PRINTING_ARCHITECTURE