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 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 wxPreviewControlBar
* controlBar
= ((wxPreviewFrame
*) GetParent())->GetControlBar();
246 if (event
.GetKeyCode() == WXK_ESCAPE
)
248 ((wxPreviewFrame
*) GetParent())->Close(TRUE
);
251 else if (event
.GetKeyCode() == WXK_TAB
)
253 controlBar
->OnGoto();
256 else if (event
.GetKeyCode() == WXK_RETURN
)
258 controlBar
->OnPrint();
262 if (!event
.ControlDown())
268 switch(event
.GetKeyCode())
271 controlBar
->OnNext(); break;
273 controlBar
->OnPrevious(); break;
275 controlBar
->OnFirst(); break;
277 controlBar
->OnLast(); break;
284 * Preview control bar
287 BEGIN_EVENT_TABLE(wxPreviewControlBar
, wxPanel
)
288 EVT_BUTTON(wxID_PREVIEW_CLOSE
, wxPreviewControlBar::OnWindowClose
)
289 EVT_BUTTON(wxID_PREVIEW_PRINT
, wxPreviewControlBar::OnPrintButton
)
290 EVT_BUTTON(wxID_PREVIEW_PREVIOUS
, wxPreviewControlBar::OnPreviousButton
)
291 EVT_BUTTON(wxID_PREVIEW_NEXT
, wxPreviewControlBar::OnNextButton
)
292 EVT_BUTTON(wxID_PREVIEW_FIRST
, wxPreviewControlBar::OnFirstButton
)
293 EVT_BUTTON(wxID_PREVIEW_LAST
, wxPreviewControlBar::OnLastButton
)
294 EVT_BUTTON(wxID_PREVIEW_GOTO
, wxPreviewControlBar::OnGotoButton
)
295 EVT_CHOICE(wxID_PREVIEW_ZOOM
, wxPreviewControlBar::OnZoom
)
296 EVT_PAINT(wxPreviewControlBar::OnPaint
)
299 wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase
*preview
, long buttons
,
300 wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
301 long style
, const wxString
& name
):
302 wxPanel(parent
, -1, pos
, size
, style
, name
)
304 m_printPreview
= preview
;
305 m_closeButton
= (wxButton
*) NULL
;
306 m_nextPageButton
= (wxButton
*) NULL
;
307 m_previousPageButton
= (wxButton
*) NULL
;
308 m_printButton
= (wxButton
*) NULL
;
309 m_zoomControl
= (wxChoice
*) NULL
;
310 m_buttonFlags
= buttons
;
313 wxPreviewControlBar::~wxPreviewControlBar()
317 void wxPreviewControlBar::OnPaint(wxPaintEvent
& WXUNUSED(event
))
323 dc
.SetPen(*wxBLACK_PEN
);
324 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
325 dc
.DrawLine( 0, h
-1, w
, h
-1 );
328 void wxPreviewControlBar::OnWindowClose(wxCommandEvent
& WXUNUSED(event
))
330 wxPreviewFrame
*frame
= (wxPreviewFrame
*)GetParent();
334 void wxPreviewControlBar::OnPrint(void)
336 wxPrintPreviewBase
*preview
= GetPrintPreview();
337 preview
->Print(TRUE
);
340 void wxPreviewControlBar::OnNext(void)
342 wxPrintPreviewBase
*preview
= GetPrintPreview();
345 int currentPage
= preview
->GetCurrentPage();
346 if ((preview
->GetMaxPage() > 0) &&
347 (currentPage
< preview
->GetMaxPage()) &&
348 preview
->GetPrintout()->HasPage(currentPage
+ 1))
350 preview
->SetCurrentPage(currentPage
+ 1);
355 void wxPreviewControlBar::OnPrevious(void)
357 wxPrintPreviewBase
*preview
= GetPrintPreview();
360 int currentPage
= preview
->GetCurrentPage();
361 if ((preview
->GetMinPage() > 0) &&
362 (currentPage
> preview
->GetMinPage()) &&
363 preview
->GetPrintout()->HasPage(currentPage
- 1))
365 preview
->SetCurrentPage(currentPage
- 1);
370 void wxPreviewControlBar::OnFirst(void)
372 wxPrintPreviewBase
*preview
= GetPrintPreview();
375 int currentPage
= preview
->GetMinPage();
376 if (preview
->GetPrintout()->HasPage(currentPage
))
378 preview
->SetCurrentPage(currentPage
);
383 void wxPreviewControlBar::OnLast(void)
385 wxPrintPreviewBase
*preview
= GetPrintPreview();
388 int currentPage
= preview
->GetMaxPage();
389 if (preview
->GetPrintout()->HasPage(currentPage
))
391 preview
->SetCurrentPage(currentPage
);
396 void wxPreviewControlBar::OnGoto(void)
398 wxPrintPreviewBase
*preview
= GetPrintPreview();
403 if (preview
->GetMinPage() > 0)
408 strPrompt
.Printf( _("Enter a page number between %d and %d:"),
409 preview
->GetMinPage(), preview
->GetMaxPage());
410 strPage
.Printf( wxT("%d"), preview
->GetCurrentPage() );
413 wxGetTextFromUser( strPrompt
, _("Goto Page"), strPage
, GetParent());
415 if ( strPage
.ToLong( ¤tPage
) )
416 if (preview
->GetPrintout()->HasPage(currentPage
))
418 preview
->SetCurrentPage(currentPage
);
424 void wxPreviewControlBar::OnZoom(wxCommandEvent
& WXUNUSED(event
))
426 int zoom
= GetZoomControl();
427 if (GetPrintPreview())
428 GetPrintPreview()->SetZoom(zoom
);
431 void wxPreviewControlBar::CreateButtons()
433 SetSize(0, 0, 400, 40);
435 wxBoxSizer
*item0
= new wxBoxSizer( wxHORIZONTAL
);
437 int smallButtonWidth
= 45;
439 m_closeButton
= new wxButton( this, wxID_PREVIEW_CLOSE
, _("&Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
440 item0
->Add( m_closeButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
442 if (m_buttonFlags
& wxPREVIEW_PRINT
)
444 m_printButton
= new wxButton( this, wxID_PREVIEW_PRINT
, _("&Print..."), wxDefaultPosition
, wxDefaultSize
, 0 );
445 item0
->Add( m_printButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
448 if (m_buttonFlags
& wxPREVIEW_FIRST
)
450 m_firstPageButton
= new wxButton( this, wxID_PREVIEW_FIRST
, _("|<<"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
451 item0
->Add( m_firstPageButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
454 if (m_buttonFlags
& wxPREVIEW_PREVIOUS
)
456 m_previousPageButton
= new wxButton( this, wxID_PREVIEW_PREVIOUS
, _("<<"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
457 item0
->Add( m_previousPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
460 if (m_buttonFlags
& wxPREVIEW_NEXT
)
462 m_nextPageButton
= new wxButton( this, wxID_PREVIEW_NEXT
, _(">>"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
463 item0
->Add( m_nextPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
466 if (m_buttonFlags
& wxPREVIEW_LAST
)
468 m_lastPageButton
= new wxButton( this, wxID_PREVIEW_LAST
, _(">>|"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 );
469 item0
->Add( m_lastPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 );
472 if (m_buttonFlags
& wxPREVIEW_GOTO
)
474 m_gotoPageButton
= new wxButton( this, wxID_PREVIEW_GOTO
, _("&Goto..."), wxDefaultPosition
, wxDefaultSize
, 0 );
475 item0
->Add( m_gotoPageButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
478 if (m_buttonFlags
& wxPREVIEW_ZOOM
)
482 wxT("10%"), wxT("15%"), wxT("20%"), wxT("25%"), wxT("30%"), wxT("35%"), wxT("40%"), wxT("45%"), wxT("50%"), wxT("55%"),
483 wxT("60%"), wxT("65%"), wxT("70%"), wxT("75%"), wxT("80%"), wxT("85%"), wxT("90%"), wxT("95%"), wxT("100%"), wxT("110%"),
484 wxT("120%"), wxT("150%"), wxT("200%")
486 int n
= WXSIZEOF(choices
);
488 m_zoomControl
= new wxChoice( this, wxID_PREVIEW_ZOOM
, wxDefaultPosition
, wxSize(70,-1), n
, choices
, 0 );
489 item0
->Add( m_zoomControl
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
490 SetZoomControl(m_printPreview
->GetZoom());
497 void wxPreviewControlBar::SetZoomControl(int zoom
)
500 wxSprintf( buf
, wxT("%d%%"), zoom
);
503 m_zoomControl
->SetStringSelection(buf
);
506 int wxPreviewControlBar::GetZoomControl()
509 if (m_zoomControl
&& (m_zoomControl
->GetStringSelection() != wxT("")))
511 wxStrcpy(buf
, m_zoomControl
->GetStringSelection());
512 buf
[wxStrlen(buf
) - 1] = 0;
513 return (int)wxAtoi(buf
);
523 BEGIN_EVENT_TABLE(wxPreviewFrame
, wxFrame
)
524 EVT_CLOSE(wxPreviewFrame::OnCloseWindow
)
527 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase
*preview
, wxWindow
*parent
, const wxString
& title
,
528 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
529 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
531 m_printPreview
= preview
;
533 m_previewCanvas
= NULL
;
535 // Give the application icon
537 wxFrame
* topFrame
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
539 SetIcon(topFrame
->GetIcon());
543 wxPreviewFrame::~wxPreviewFrame()
547 void wxPreviewFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
549 // MakeModal doesn't work on wxMac, especially when there
550 // are multiple top-level windows.
555 // Need to delete the printout and the print preview
556 wxPrintout
*printout
= m_printPreview
->GetPrintout();
560 m_printPreview
->SetPrintout(NULL
);
561 m_printPreview
->SetCanvas(NULL
);
562 m_printPreview
->SetFrame(NULL
);
564 delete m_printPreview
;
569 void wxPreviewFrame::Initialize()
577 m_printPreview
->SetCanvas(m_previewCanvas
);
578 m_printPreview
->SetFrame(this);
580 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
582 item0
->Add( m_controlBar
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
583 item0
->Add( m_previewCanvas
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
585 SetAutoLayout( TRUE
);
588 // MakeModal doesn't work on wxMac, especially when there
589 // are multiple top-level windows.
596 m_printPreview
->AdjustScrollbars(m_previewCanvas
);
597 m_previewCanvas
->SetFocus();
598 m_controlBar
->SetFocus();
601 void wxPreviewFrame::CreateCanvas()
603 m_previewCanvas
= new wxPreviewCanvas(m_printPreview
, this);
606 void wxPreviewFrame::CreateControlBar()
608 long buttons
= wxPREVIEW_DEFAULT
;
609 if (m_printPreview
->GetPrintoutForPrinting())
610 buttons
|= wxPREVIEW_PRINT
;
612 m_controlBar
= new wxPreviewControlBar(m_printPreview
, buttons
, this, wxPoint(0, 0), wxSize(400, 40));
613 m_controlBar
->CreateButtons();
620 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout
*printout
,
621 wxPrintout
*printoutForPrinting
,
625 m_printDialogData
= (*data
);
627 Init(printout
, printoutForPrinting
);
630 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout
*printout
,
631 wxPrintout
*printoutForPrinting
,
632 wxPrintDialogData
*data
)
635 m_printDialogData
= (*data
);
637 Init(printout
, printoutForPrinting
);
640 void wxPrintPreviewBase::Init(wxPrintout
*printout
,
641 wxPrintout
*printoutForPrinting
)
644 m_previewPrintout
= printout
;
645 if (m_previewPrintout
)
646 m_previewPrintout
->SetIsPreview(TRUE
);
648 m_printPrintout
= printoutForPrinting
;
650 m_previewCanvas
= NULL
;
651 m_previewFrame
= NULL
;
652 m_previewBitmap
= NULL
;
659 m_printingPrepared
= FALSE
;
664 wxPrintPreviewBase::~wxPrintPreviewBase()
666 if (m_previewPrintout
)
667 delete m_previewPrintout
;
669 delete m_previewBitmap
;
671 delete m_printPrintout
;
674 bool wxPrintPreviewBase::SetCurrentPage(int pageNum
)
676 if (m_currentPage
== pageNum
)
679 m_currentPage
= pageNum
;
682 delete m_previewBitmap
;
683 m_previewBitmap
= NULL
;
688 AdjustScrollbars(m_previewCanvas
);
690 if (!RenderPage(pageNum
))
692 m_previewCanvas
->Refresh();
693 m_previewCanvas
->SetFocus();
698 bool wxPrintPreviewBase::PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
)
700 DrawBlankPage(canvas
, dc
);
702 if (!m_previewBitmap
)
703 if (!RenderPage(m_currentPage
))
706 if (!m_previewBitmap
)
712 int canvasWidth
, canvasHeight
;
713 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
715 double zoomScale
= ((float)m_currentZoom
/(float)100);
716 double actualWidth
= (zoomScale
*m_pageWidth
*m_previewScale
);
717 // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale);
719 int x
= (int) ((canvasWidth
- actualWidth
)/2.0);
720 if (x
< m_leftMargin
)
725 temp_dc
.SelectObject(*m_previewBitmap
);
727 dc
.Blit(x
, y
, m_previewBitmap
->GetWidth(), m_previewBitmap
->GetHeight(), &temp_dc
, 0, 0);
729 temp_dc
.SelectObject(wxNullBitmap
);
734 // Adjusts the scrollbars for the current scale
735 void wxPrintPreviewBase::AdjustScrollbars(wxPreviewCanvas
*canvas
)
740 int canvasWidth
, canvasHeight
;
741 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
743 double zoomScale
= ((float)m_currentZoom
/(float)100);
744 double actualWidth
= (zoomScale
*m_pageWidth
*m_previewScale
);
745 double actualHeight
= (zoomScale
*m_pageHeight
*m_previewScale
);
747 // Set the scrollbars appropriately
748 int totalWidth
= (int)(actualWidth
+ 2*m_leftMargin
);
749 int totalHeight
= (int)(actualHeight
+ 2*m_topMargin
);
750 int scrollUnitsX
= totalWidth
/10;
751 int scrollUnitsY
= totalHeight
/10;
752 wxSize virtualSize
= canvas
->GetVirtualSize();
753 if (virtualSize
.GetWidth() != totalWidth
|| virtualSize
.GetHeight() != totalHeight
)
754 canvas
->SetScrollbars(10, 10, scrollUnitsX
, scrollUnitsY
, 0, 0, TRUE
);
757 bool wxPrintPreviewBase::RenderPage(int pageNum
)
761 int canvasWidth
, canvasHeight
;
763 if (!m_previewCanvas
)
765 wxFAIL_MSG(_T("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"));
769 m_previewCanvas
->GetSize(&canvasWidth
, &canvasHeight
);
771 double zoomScale
= (m_currentZoom
/100.0);
772 int actualWidth
= (int)(zoomScale
*m_pageWidth
*m_previewScale
);
773 int actualHeight
= (int)(zoomScale
*m_pageHeight
*m_previewScale
);
775 if (!m_previewBitmap
)
777 m_previewBitmap
= new wxBitmap((int)actualWidth
, (int)actualHeight
);
778 if (!m_previewBitmap
|| !m_previewBitmap
->Ok())
780 if (m_previewBitmap
) {
781 delete m_previewBitmap
;
782 m_previewBitmap
= NULL
;
784 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK
);
790 memoryDC
.SelectObject(*m_previewBitmap
);
794 m_previewPrintout
->SetDC(&memoryDC
);
795 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
797 // Need to delay OnPreparePrinting until here, so we have enough information.
798 if (!m_printingPrepared
)
800 m_previewPrintout
->OnPreparePrinting();
802 m_previewPrintout
->GetPageInfo(&m_minPage
, &m_maxPage
, &selFrom
, &selTo
);
803 m_printingPrepared
= TRUE
;
806 m_previewPrintout
->OnBeginPrinting();
808 if (!m_previewPrintout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
810 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK
);
812 memoryDC
.SelectObject(wxNullBitmap
);
814 delete m_previewBitmap
;
815 m_previewBitmap
= NULL
;
819 m_previewPrintout
->OnPrintPage(pageNum
);
820 m_previewPrintout
->OnEndDocument();
821 m_previewPrintout
->OnEndPrinting();
823 m_previewPrintout
->SetDC(NULL
);
825 memoryDC
.SelectObject(wxNullBitmap
);
830 status
= wxString::Format(_("Page %d of %d"), pageNum
, m_maxPage
);
832 status
= wxString::Format(_("Page %d"), pageNum
);
835 m_previewFrame
->SetStatusText(status
);
842 bool wxPrintPreviewBase::DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
)
844 int canvasWidth
, canvasHeight
;
845 canvas
->GetSize(&canvasWidth
, &canvasHeight
);
847 float zoomScale
= (float)((float)m_currentZoom
/(float)100);
848 float actualWidth
= zoomScale
*m_pageWidth
*m_previewScale
;
849 float actualHeight
= zoomScale
*m_pageHeight
*m_previewScale
;
851 float x
= (float)((canvasWidth
- actualWidth
)/2.0);
852 if (x
< m_leftMargin
)
853 x
= (float)m_leftMargin
;
854 float y
= (float)m_topMargin
;
856 // Draw shadow, allowing for 1-pixel border AROUND the actual page
857 int shadowOffset
= 4;
858 dc
.SetPen(*wxBLACK_PEN
);
859 dc
.SetBrush(*wxBLACK_BRUSH
);
861 dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2));
863 dc
.DrawRectangle((int)(x
+ shadowOffset
), (int)(y
+ actualHeight
+1), (int)(actualWidth
), shadowOffset
);
864 dc
.DrawRectangle((int)(x
+ actualWidth
), (int)(y
+ shadowOffset
), shadowOffset
, (int)(actualHeight
));
866 // Draw blank page allowing for 1-pixel border AROUND the actual page
867 dc
.SetPen(*wxBLACK_PEN
);
868 dc
.SetBrush(*wxWHITE_BRUSH
);
871 wxRegion update_region = canvas->GetUpdateRegion();
872 wxRect r = update_region.GetBox();
874 printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height );
877 dc
.DrawRectangle((int)(x
-2), (int)(y
-1), (int)(actualWidth
+3), (int)(actualHeight
+2));
882 void wxPrintPreviewBase::SetZoom(int percent
)
884 if (m_currentZoom
== percent
)
887 m_currentZoom
= percent
;
890 delete m_previewBitmap
;
891 m_previewBitmap
= NULL
;
896 AdjustScrollbars(m_previewCanvas
);
897 RenderPage(m_currentPage
);
898 ((wxScrolledWindow
*) m_previewCanvas
)->Scroll(0, 0);
899 m_previewCanvas
->ClearBackground();
900 m_previewCanvas
->Refresh();
901 m_previewCanvas
->SetFocus();
905 #endif // wxUSE_PRINTING_ARCHITECTURE