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_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged
) 
  80 wxPrinterBase::wxPrinterBase(wxPrintDialogData 
*data
) 
  82     m_currentPrintout 
= (wxPrintout 
*) NULL
; 
  83     sm_abortWindow 
= (wxWindow 
*) NULL
; 
  86         m_printDialogData 
= (*data
); 
  87     sm_lastError 
= wxPRINTER_NO_ERROR
; 
  90 wxWindow 
*wxPrinterBase::sm_abortWindow 
= (wxWindow 
*) NULL
; 
  91 bool wxPrinterBase::sm_abortIt 
= FALSE
; 
  92 wxPrinterError 
wxPrinterBase::sm_lastError 
= wxPRINTER_NO_ERROR
; 
  94 wxPrinterBase::~wxPrinterBase() 
  98 void wxPrintAbortDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
)) 
 100     wxPrinterBase::sm_abortIt 
= TRUE
; 
 101     wxPrinterBase::sm_abortWindow
->Show(FALSE
); 
 102     wxPrinterBase::sm_abortWindow
->Close(TRUE
); 
 103     wxPrinterBase::sm_abortWindow 
= (wxWindow 
*) NULL
; 
 106 wxWindow 
*wxPrinterBase::CreateAbortWindow(wxWindow 
*parent
, wxPrintout 
* printout
) 
 108     wxPrintAbortDialog 
*dialog 
= new wxPrintAbortDialog(parent
, _("Printing ") , wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
); 
 110     wxBoxSizer 
*button_sizer 
= new wxBoxSizer( wxVERTICAL 
); 
 111     button_sizer
->Add( new wxStaticText(dialog
, -1, _("Please wait while printing\n") + printout
->GetTitle() ), 0, wxALL
, 10 ); 
 112     button_sizer
->Add( new wxButton( dialog
, wxID_CANCEL
, wxT("Cancel") ), 0, wxALL 
| wxALIGN_CENTER
, 10 ); 
 114     dialog
->SetAutoLayout( TRUE 
); 
 115     dialog
->SetSizer( button_sizer 
); 
 117     button_sizer
->Fit(dialog
); 
 118     button_sizer
->SetSizeHints (dialog
) ; 
 123 void wxPrinterBase::ReportError(wxWindow 
*parent
, wxPrintout 
*WXUNUSED(printout
), const wxString
& message
) 
 125     wxMessageBox(message
, _("Printing Error"), wxOK
, parent
); 
 132 wxPrintout::wxPrintout(const wxString
& title
) 
 134     m_printoutTitle 
= title 
; 
 135     m_printoutDC 
= (wxDC 
*) NULL
; 
 138     m_pageWidthPixels 
= 0; 
 139     m_pageHeightPixels 
= 0; 
 147 wxPrintout::~wxPrintout() 
 151 bool wxPrintout::OnBeginDocument(int WXUNUSED(startPage
), int WXUNUSED(endPage
)) 
 153     return GetDC()->StartDoc(_("Printing ") + m_printoutTitle
); 
 156 void wxPrintout::OnEndDocument() 
 161 void wxPrintout::OnBeginPrinting() 
 165 void wxPrintout::OnEndPrinting() 
 169 bool wxPrintout::HasPage(int page
) 
 174 void wxPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *fromPage
, int *toPage
) 
 186 wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase 
*preview
, wxWindow 
*parent
, 
 187                                  const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
): 
 188 wxScrolledWindow(parent
, -1, pos
, size
, style
, name
) 
 190     m_printPreview 
= preview
; 
 192     // The app workspace colour is always white, but we should have 
 193     // a contrast with the page. 
 194     wxSystemColour colourIndex 
= wxSYS_COLOUR_3DDKSHADOW
; 
 196     wxSystemColour colourIndex 
= wxSYS_COLOUR_APPWORKSPACE
; 
 198     SetBackgroundColour(wxSystemSettings::GetColour(colourIndex
)); 
 200     SetScrollbars(15, 18, 100, 100); 
 203 wxPreviewCanvas::~wxPreviewCanvas() 
 207 void wxPreviewCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
)) 
 214     if (!GetUpdateRegion().IsEmpty()) 
 215         dc.SetClippingRegion( GetUpdateRegion() ); 
 221         m_printPreview
->PaintPage(this, dc
); 
 225 // Responds to colour changes, and passes event on to children. 
 226 void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent
& event
) 
 229     // The app workspace colour is always white, but we should have 
 230     // a contrast with the page. 
 231     wxSystemColour colourIndex 
= wxSYS_COLOUR_3DDKSHADOW
; 
 233     wxSystemColour colourIndex 
= wxSYS_COLOUR_APPWORKSPACE
; 
 235     SetBackgroundColour(wxSystemSettings::GetColour(colourIndex
)); 
 238     // Propagate the event to the non-top-level children 
 239     wxWindow::OnSysColourChanged(event
); 
 243 * Preview control bar 
 246 BEGIN_EVENT_TABLE(wxPreviewControlBar
, wxPanel
) 
 247     EVT_BUTTON(wxID_PREVIEW_CLOSE
,    wxPreviewControlBar::OnWindowClose
) 
 248     EVT_BUTTON(wxID_PREVIEW_PRINT
,    wxPreviewControlBar::OnPrint
) 
 249     EVT_BUTTON(wxID_PREVIEW_PREVIOUS
, wxPreviewControlBar::OnPreviousButton
) 
 250     EVT_BUTTON(wxID_PREVIEW_NEXT
,     wxPreviewControlBar::OnNextButton
) 
 251     EVT_BUTTON(wxID_PREVIEW_FIRST
,    wxPreviewControlBar::OnFirstButton
) 
 252     EVT_BUTTON(wxID_PREVIEW_LAST
,     wxPreviewControlBar::OnLastButton
) 
 253     EVT_BUTTON(wxID_PREVIEW_GOTO
,     wxPreviewControlBar::OnGotoButton
) 
 254     EVT_CHAR(wxPreviewControlBar::OnChar
) 
 255     EVT_CHOICE(wxID_PREVIEW_ZOOM
,     wxPreviewControlBar::OnZoom
) 
 256     EVT_PAINT(wxPreviewControlBar::OnPaint
) 
 259 wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase 
*preview
, long buttons
, 
 260                                          wxWindow 
*parent
, const wxPoint
& pos
, const wxSize
& size
, 
 261                                          long style
, const wxString
& name
): 
 262 wxPanel(parent
, -1, pos
, size
, style
, name
) 
 264     m_printPreview 
= preview
; 
 265     m_closeButton 
= (wxButton 
*) NULL
; 
 266     m_nextPageButton 
= (wxButton 
*) NULL
; 
 267     m_previousPageButton 
= (wxButton 
*) NULL
; 
 268     m_printButton 
= (wxButton 
*) NULL
; 
 269     m_zoomControl 
= (wxChoice 
*) NULL
; 
 270     m_buttonFlags 
= buttons
; 
 273 wxPreviewControlBar::~wxPreviewControlBar() 
 277 void wxPreviewControlBar::OnPaint(wxPaintEvent
& WXUNUSED(event
)) 
 283     dc
.SetPen(*wxBLACK_PEN
); 
 284     dc
.SetBrush(*wxTRANSPARENT_BRUSH
); 
 285     dc
.DrawLine( 0, h
-1, w
, h
-1 ); 
 288 void wxPreviewControlBar::OnWindowClose(wxCommandEvent
& WXUNUSED(event
)) 
 290     wxPreviewFrame 
*frame 
= (wxPreviewFrame 
*)GetParent(); 
 294 void wxPreviewControlBar::OnPrint(wxCommandEvent
& WXUNUSED(event
)) 
 296     wxPrintPreviewBase 
*preview 
= GetPrintPreview(); 
 297     preview
->Print(TRUE
); 
 300 void wxPreviewControlBar::OnChar(wxKeyEvent 
&event
) 
 302    switch(event
.GetKeyCode()) 
 319 void wxPreviewControlBar::OnNext(void) 
 321     wxPrintPreviewBase 
*preview 
= GetPrintPreview(); 
 324         int currentPage 
= preview
->GetCurrentPage(); 
 325         if ((preview
->GetMaxPage() > 0) && 
 326             (currentPage 
< preview
->GetMaxPage()) && 
 327             preview
->GetPrintout()->HasPage(currentPage 
+ 1)) 
 329             preview
->SetCurrentPage(currentPage 
+ 1); 
 334 void wxPreviewControlBar::OnPrevious(void) 
 336     wxPrintPreviewBase 
*preview 
= GetPrintPreview(); 
 339         int currentPage 
= preview
->GetCurrentPage(); 
 340         if ((preview
->GetMinPage() > 0) && 
 341             (currentPage 
> preview
->GetMinPage()) && 
 342             preview
->GetPrintout()->HasPage(currentPage 
- 1)) 
 344             preview
->SetCurrentPage(currentPage 
- 1); 
 349 void wxPreviewControlBar::OnFirst(void) 
 351     wxPrintPreviewBase 
*preview 
= GetPrintPreview(); 
 354         int currentPage 
= preview
->GetMinPage(); 
 355         if (preview
->GetPrintout()->HasPage(currentPage
)) 
 357             preview
->SetCurrentPage(currentPage
); 
 362 void wxPreviewControlBar::OnLast(void) 
 364     wxPrintPreviewBase 
*preview 
= GetPrintPreview(); 
 367         int currentPage 
= preview
->GetMaxPage(); 
 368         if (preview
->GetPrintout()->HasPage(currentPage
)) 
 370             preview
->SetCurrentPage(currentPage
); 
 375 void wxPreviewControlBar::OnGoto(void) 
 377     wxPrintPreviewBase 
*preview 
= GetPrintPreview(); 
 382         if (preview
->GetMinPage() > 0) 
 387             strPrompt
.Printf( wxT("%d...%d"), 
 388                 preview
->GetMinPage(), preview
->GetMaxPage()); 
 389             strPage
.Printf( wxT("%d"), preview
->GetCurrentPage() ); 
 392                 wxGetTextFromUser( strPrompt
, _("Goto Page"), strPage
); 
 394             if ( strPage
.ToLong( ¤tPage 
) ) 
 395                 if (preview
->GetPrintout()->HasPage(currentPage
)) 
 397                     preview
->SetCurrentPage(currentPage
); 
 403 void wxPreviewControlBar::OnZoom(wxCommandEvent
& WXUNUSED(event
)) 
 405     int zoom 
= GetZoomControl(); 
 406     if (GetPrintPreview()) 
 407         GetPrintPreview()->SetZoom(zoom
); 
 410 void wxPreviewControlBar::CreateButtons() 
 412     SetSize(0, 0, 400, 40); 
 414     wxBoxSizer 
*item0 
= new wxBoxSizer( wxHORIZONTAL 
); 
 416     int smallButtonWidth 
= 45; 
 418     m_closeButton 
= new wxButton( this, wxID_PREVIEW_CLOSE
, _("&Close"), wxDefaultPosition
, wxDefaultSize
, 0 ); 
 419     item0
->Add( m_closeButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 ); 
 421     if (m_buttonFlags 
& wxPREVIEW_PRINT
) 
 423         m_printButton 
= new wxButton( this, wxID_PREVIEW_PRINT
, _("&Print..."), wxDefaultPosition
, wxDefaultSize
, 0 ); 
 424         item0
->Add( m_printButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 ); 
 427     if (m_buttonFlags 
& wxPREVIEW_FIRST
) 
 429         m_firstPageButton 
= new wxButton( this, wxID_PREVIEW_FIRST
, _("|<<"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 ); 
 430         item0
->Add( m_firstPageButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 ); 
 433     if (m_buttonFlags 
& wxPREVIEW_PREVIOUS
) 
 435         m_previousPageButton 
= new wxButton( this, wxID_PREVIEW_PREVIOUS
, _("<<"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 ); 
 436         item0
->Add( m_previousPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 ); 
 439     if (m_buttonFlags 
& wxPREVIEW_NEXT
) 
 441         m_nextPageButton 
= new wxButton( this, wxID_PREVIEW_NEXT
, _(">>"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 ); 
 442         item0
->Add( m_nextPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 ); 
 445     if (m_buttonFlags 
& wxPREVIEW_LAST
) 
 447         m_lastPageButton 
= new wxButton( this, wxID_PREVIEW_LAST
, _(">>|"), wxDefaultPosition
, wxSize(smallButtonWidth
,-1), 0 ); 
 448         item0
->Add( m_lastPageButton
, 0, wxALIGN_CENTRE
|wxRIGHT
|wxTOP
|wxBOTTOM
, 5 ); 
 451     if (m_buttonFlags 
& wxPREVIEW_GOTO
) 
 453         m_gotoPageButton 
= new wxButton( this, wxID_PREVIEW_GOTO
, _("&Goto..."), wxDefaultPosition
, wxDefaultSize
, 0 ); 
 454         item0
->Add( m_gotoPageButton
, 0, wxALIGN_CENTRE
|wxALL
, 5 ); 
 457     if (m_buttonFlags 
& wxPREVIEW_ZOOM
) 
 461             wxT("10%"), wxT("15%"), wxT("20%"), wxT("25%"), wxT("30%"), wxT("35%"), wxT("40%"), wxT("45%"), wxT("50%"), wxT("55%"), 
 462                 wxT("60%"), wxT("65%"), wxT("70%"), wxT("75%"), wxT("80%"), wxT("85%"), wxT("90%"), wxT("95%"), wxT("100%"), wxT("110%"), 
 463                 wxT("120%"), wxT("150%"), wxT("200%") 
 465         int n 
= WXSIZEOF(choices
); 
 467         m_zoomControl 
= new wxChoice( this, wxID_PREVIEW_ZOOM
, wxDefaultPosition
, wxSize(70,-1), n
, choices
, 0 ); 
 468         item0
->Add( m_zoomControl
, 0, wxALIGN_CENTRE
|wxALL
, 5 ); 
 469         SetZoomControl(m_printPreview
->GetZoom()); 
 476 void wxPreviewControlBar::SetZoomControl(int zoom
) 
 479     wxSprintf( buf
, wxT("%d%%"), zoom 
); 
 482         m_zoomControl
->SetStringSelection(buf
); 
 485 int wxPreviewControlBar::GetZoomControl() 
 488     if (m_zoomControl 
&& (m_zoomControl
->GetStringSelection() != wxT(""))) 
 490         wxStrcpy(buf
, m_zoomControl
->GetStringSelection()); 
 491         buf
[wxStrlen(buf
) - 1] = 0; 
 492         return (int)wxAtoi(buf
); 
 502 BEGIN_EVENT_TABLE(wxPreviewFrame
, wxFrame
) 
 503     EVT_CLOSE(wxPreviewFrame::OnCloseWindow
) 
 506 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase 
*preview
, wxWindow 
*parent
, const wxString
& title
, 
 507                                const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
): 
 508 wxFrame(parent
, -1, title
, pos
, size
, style
, name
) 
 510     m_printPreview 
= preview
; 
 512     m_previewCanvas 
= NULL
; 
 514     // Give the application icon 
 516     wxFrame
* topFrame 
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
); 
 518         SetIcon(topFrame
->GetIcon()); 
 522 wxPreviewFrame::~wxPreviewFrame() 
 526 void wxPreviewFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
)) 
 528     // MakeModal doesn't work on wxMac, especially when there 
 529     // are multiple top-level windows. 
 534     // Need to delete the printout and the print preview 
 535     wxPrintout 
*printout 
= m_printPreview
->GetPrintout(); 
 539         m_printPreview
->SetPrintout(NULL
); 
 540         m_printPreview
->SetCanvas(NULL
); 
 541         m_printPreview
->SetFrame(NULL
); 
 543     delete m_printPreview
; 
 548 void wxPreviewFrame::Initialize() 
 556     m_printPreview
->SetCanvas(m_previewCanvas
); 
 557     m_printPreview
->SetFrame(this); 
 559     wxBoxSizer 
*item0 
= new wxBoxSizer( wxVERTICAL 
); 
 561     item0
->Add( m_controlBar
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 ); 
 562     item0
->Add( m_previewCanvas
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 ); 
 564     SetAutoLayout( TRUE 
); 
 567     // MakeModal doesn't work on wxMac, especially when there 
 568     // are multiple top-level windows. 
 576 void wxPreviewFrame::CreateCanvas() 
 578     m_previewCanvas 
= new wxPreviewCanvas(m_printPreview
, this); 
 581 void wxPreviewFrame::CreateControlBar() 
 583     long buttons 
= wxPREVIEW_DEFAULT
; 
 584     if (m_printPreview
->GetPrintoutForPrinting()) 
 585         buttons 
|= wxPREVIEW_PRINT
; 
 587     m_controlBar 
= new wxPreviewControlBar(m_printPreview
, buttons
, this, wxPoint(0, 0), wxSize(400, 40)); 
 588     m_controlBar
->CreateButtons(); 
 595 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout 
*printout
, 
 596                                        wxPrintout 
*printoutForPrinting
, 
 600         m_printDialogData 
= (*data
); 
 602     Init(printout
, printoutForPrinting
); 
 605 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout 
*printout
, 
 606                                        wxPrintout 
*printoutForPrinting
, 
 607                                        wxPrintDialogData 
*data
) 
 610         m_printDialogData 
= (*data
); 
 612     Init(printout
, printoutForPrinting
); 
 615 void wxPrintPreviewBase::Init(wxPrintout 
*printout
, 
 616                               wxPrintout 
*printoutForPrinting
) 
 619     m_previewPrintout 
= printout
; 
 620     if (m_previewPrintout
) 
 621         m_previewPrintout
->SetIsPreview(TRUE
); 
 623     m_printPrintout 
= printoutForPrinting
; 
 625     m_previewCanvas 
= NULL
; 
 626     m_previewFrame 
= NULL
; 
 627     m_previewBitmap 
= NULL
; 
 634     m_printingPrepared 
= FALSE
; 
 636     // Too soon! Moved to RenderPage. 
 637     // printout->OnPreparePrinting(); 
 639     // Get some parameters from the printout, if defined 
 641     printout
->GetPageInfo(&m_minPage
, &m_maxPage
, &selFrom
, &selTo
); 
 644 wxPrintPreviewBase::~wxPrintPreviewBase() 
 646     if (m_previewPrintout
) 
 647         delete m_previewPrintout
; 
 649         delete m_previewBitmap
; 
 651         delete m_printPrintout
; 
 654 bool wxPrintPreviewBase::SetCurrentPage(int pageNum
) 
 656     if (m_currentPage 
== pageNum
) 
 659     m_currentPage 
= pageNum
; 
 662         delete m_previewBitmap
; 
 663         m_previewBitmap 
= NULL
; 
 668         if (!RenderPage(pageNum
)) 
 670         m_previewCanvas
->Refresh(); 
 675 bool wxPrintPreviewBase::PaintPage(wxWindow 
*canvas
, wxDC
& dc
) 
 677     DrawBlankPage(canvas
, dc
); 
 679     if (!m_previewBitmap
) 
 680         if (!RenderPage(m_currentPage
)) 
 683     if (!m_previewBitmap
) 
 689     int canvasWidth
, canvasHeight
; 
 690     canvas
->GetSize(&canvasWidth
, &canvasHeight
); 
 692     double zoomScale 
= ((float)m_currentZoom
/(float)100); 
 693     double actualWidth 
= (zoomScale
*m_pageWidth
*m_previewScale
); 
 694     //  float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale); 
 696     int x 
= (int) ((canvasWidth 
- actualWidth
)/2.0); 
 697     if (x 
< m_leftMargin
) 
 702     temp_dc
.SelectObject(*m_previewBitmap
); 
 704     dc
.Blit(x
, y
, m_previewBitmap
->GetWidth(), m_previewBitmap
->GetHeight(), &temp_dc
, 0, 0); 
 706     temp_dc
.SelectObject(wxNullBitmap
); 
 711 bool wxPrintPreviewBase::RenderPage(int pageNum
) 
 715     int canvasWidth
, canvasHeight
; 
 717     if (!m_previewCanvas
) 
 719         wxFAIL_MSG(_T("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!")); 
 723     m_previewCanvas
->GetSize(&canvasWidth
, &canvasHeight
); 
 725     double zoomScale 
= (m_currentZoom
/100.0); 
 726     int actualWidth 
= (int)(zoomScale
*m_pageWidth
*m_previewScale
); 
 727     int actualHeight 
= (int)(zoomScale
*m_pageHeight
*m_previewScale
); 
 729     int x 
= (int)((canvasWidth 
- actualWidth
)/2.0); 
 730     if (x 
< m_leftMargin
) 
 732     //  int y = m_topMargin; 
 735     if (!m_previewBitmap
) 
 737         m_previewBitmap 
= new wxBitmap((int)actualWidth
, (int)actualHeight
); 
 738         if (!m_previewBitmap 
|| !m_previewBitmap
->Ok()) 
 740             if (m_previewBitmap
) { 
 741                 delete m_previewBitmap
; 
 742                 m_previewBitmap 
= NULL
; 
 744             wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK
); 
 750     memoryDC
.SelectObject(*m_previewBitmap
); 
 754     m_previewPrintout
->SetDC(&memoryDC
); 
 755     m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
); 
 757     // Need to delay OnPreparePrinting until here, so we have enough information. 
 758     if (!m_printingPrepared
) 
 760         m_previewPrintout
->OnPreparePrinting(); 
 761         m_printingPrepared 
= TRUE
; 
 764     m_previewPrintout
->OnBeginPrinting(); 
 766     if (!m_previewPrintout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage())) 
 768         wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK
); 
 770         memoryDC
.SelectObject(wxNullBitmap
); 
 772         delete m_previewBitmap
; 
 773         m_previewBitmap 
= NULL
; 
 777     m_previewPrintout
->OnPrintPage(pageNum
); 
 778     m_previewPrintout
->OnEndDocument(); 
 779     m_previewPrintout
->OnEndPrinting(); 
 781     m_previewPrintout
->SetDC(NULL
); 
 783     memoryDC
.SelectObject(wxNullBitmap
); 
 788                 status 
= wxString::Format(_("Page %d of %d"), pageNum
, m_maxPage
); 
 790                 status 
= wxString::Format(_("Page %d"), pageNum
); 
 793         m_previewFrame
->SetStatusText(status
); 
 800 bool wxPrintPreviewBase::DrawBlankPage(wxWindow 
*canvas
, wxDC
& dc
) 
 802     int canvasWidth
, canvasHeight
; 
 803     canvas
->GetSize(&canvasWidth
, &canvasHeight
); 
 805     float zoomScale 
= (float)((float)m_currentZoom
/(float)100); 
 806     float actualWidth 
= zoomScale
*m_pageWidth
*m_previewScale
; 
 807     float actualHeight 
= zoomScale
*m_pageHeight
*m_previewScale
; 
 809     float x 
= (float)((canvasWidth 
- actualWidth
)/2.0); 
 810     if (x 
< m_leftMargin
) 
 811         x 
= (float)m_leftMargin
; 
 812     float y 
= (float)m_topMargin
; 
 814     // Draw shadow, allowing for 1-pixel border AROUND the actual page 
 815     int shadowOffset 
= 4; 
 816     dc
.SetPen(*wxBLACK_PEN
); 
 817     dc
.SetBrush(*wxBLACK_BRUSH
); 
 819     dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2)); 
 821     dc
.DrawRectangle((int)(x 
+ shadowOffset
), (int)(y 
+ actualHeight
+1), (int)(actualWidth
), shadowOffset
); 
 822     dc
.DrawRectangle((int)(x 
+ actualWidth
), (int)(y 
+ shadowOffset
), shadowOffset
, (int)(actualHeight
)); 
 824     // Draw blank page allowing for 1-pixel border AROUND the actual page 
 825     dc
.SetPen(*wxBLACK_PEN
); 
 826     dc
.SetBrush(*wxWHITE_BRUSH
); 
 829     wxRegion update_region = canvas->GetUpdateRegion(); 
 830     wxRect r = update_region.GetBox(); 
 832       printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height ); 
 835     dc
.DrawRectangle((int)(x
-2), (int)(y
-1), (int)(actualWidth
+3), (int)(actualHeight
+2)); 
 840 void wxPrintPreviewBase::SetZoom(int percent
) 
 842     if (m_currentZoom 
== percent
) 
 845     m_currentZoom 
= percent
; 
 848         delete m_previewBitmap
; 
 849         m_previewBitmap 
= NULL
; 
 854         RenderPage(m_currentPage
); 
 855         ((wxScrolledWindow 
*) m_previewCanvas
)->Scroll(0, 0); 
 856         m_previewCanvas
->Clear(); 
 857         m_previewCanvas
->Refresh(); 
 861 #endif // wxUSE_PRINTING_ARCHITECTURE