use wxFAIL_MSG, not wxMessageBox for programming errors
[wxWidgets.git] / src / common / prntbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: prntbase.cpp
3 // Purpose: Printing framework base class implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "prntbase.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #include "wx/defs.h"
24
25 #if wxUSE_PRINTING_ARCHITECTURE
26
27 #ifndef WX_PRECOMP
28 #include "wx/utils.h"
29 #include "wx/dc.h"
30 #include "wx/app.h"
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"
38 #include "wx/intl.h"
39 #endif
40
41 #include "wx/prntbase.h"
42 #include "wx/dcprint.h"
43 #include "wx/printdlg.h"
44 #include "wx/module.h"
45
46 #include <stdlib.h>
47 #include <string.h>
48
49 #ifdef __WXMSW__
50 #include "wx/msw/private.h"
51 #include <commdlg.h>
52
53 #ifndef __WIN32__
54 #include <print.h>
55 #endif
56 #endif // __WXMSW__
57
58 IMPLEMENT_CLASS(wxPrinterBase, wxObject)
59 IMPLEMENT_ABSTRACT_CLASS(wxPrintout, wxObject)
60 IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow)
61 IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow)
62 IMPLEMENT_CLASS(wxPreviewFrame, wxFrame)
63 IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject)
64
65 BEGIN_EVENT_TABLE(wxPrintAbortDialog, wxDialog)
66 EVT_BUTTON(wxID_CANCEL, wxPrintAbortDialog::OnCancel)
67 END_EVENT_TABLE()
68
69 BEGIN_EVENT_TABLE(wxPreviewCanvas, wxScrolledWindow)
70 EVT_PAINT(wxPreviewCanvas::OnPaint)
71 EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged)
72 END_EVENT_TABLE()
73
74 /*
75 * Printer
76 */
77
78 wxPrinterBase::wxPrinterBase(wxPrintDialogData *data)
79 {
80 m_currentPrintout = (wxPrintout *) NULL;
81 sm_abortWindow = (wxWindow *) NULL;
82 sm_abortIt = FALSE;
83 if (data)
84 m_printDialogData = (*data);
85 }
86
87 wxWindow *wxPrinterBase::sm_abortWindow = (wxWindow *) NULL;
88 bool wxPrinterBase::sm_abortIt = FALSE;
89
90 wxPrinterBase::~wxPrinterBase()
91 {
92 }
93
94 void wxPrintAbortDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
95 {
96 wxPrinterBase::sm_abortIt = TRUE;
97 wxPrinterBase::sm_abortWindow->Show(FALSE);
98 wxPrinterBase::sm_abortWindow->Close(TRUE);
99 wxPrinterBase::sm_abortWindow = (wxWindow *) NULL;
100 }
101
102 wxWindow *wxPrinterBase::CreateAbortWindow(wxWindow *parent, wxPrintout *WXUNUSED(printout))
103 {
104 wxPrintAbortDialog *dialog = new wxPrintAbortDialog(parent, _("Printing"), wxPoint(0, 0), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE);
105 (void) new wxStaticText(dialog, -1, _("Please wait..."), wxPoint(5, 5));
106
107 wxButton *button = new wxButton(dialog, wxID_CANCEL, _("Cancel"), wxPoint(5, 30));
108
109 dialog->Fit();
110 button->Centre(wxHORIZONTAL);
111
112 dialog->Centre();
113 return dialog;
114 }
115
116 void wxPrinterBase::ReportError(wxWindow *parent, wxPrintout *WXUNUSED(printout), char *message)
117 {
118 wxMessageBox(message, _("Printing Error"), wxOK, parent);
119 }
120
121 /*
122 * Printout class
123 */
124
125 wxPrintout::wxPrintout(const wxString& title)
126 {
127 m_printoutTitle = title ;
128 m_printoutDC = (wxDC *) NULL;
129 m_pageWidthMM = 0;
130 m_pageHeightMM = 0;
131 m_pageWidthPixels = 0;
132 m_pageHeightPixels = 0;
133 m_PPIScreenX = 0;
134 m_PPIScreenY = 0;
135 m_PPIPrinterX = 0;
136 m_PPIPrinterY = 0;
137 m_isPreview = FALSE;
138 }
139
140 wxPrintout::~wxPrintout()
141 {
142 }
143
144 bool wxPrintout::OnBeginDocument(int WXUNUSED(startPage), int WXUNUSED(endPage))
145 {
146 return GetDC()->StartDoc(_("Printing"));
147 }
148
149 void wxPrintout::OnEndDocument()
150 {
151 GetDC()->EndDoc();
152 }
153
154 void wxPrintout::OnBeginPrinting()
155 {
156 }
157
158 void wxPrintout::OnEndPrinting()
159 {
160 }
161
162 bool wxPrintout::HasPage(int page)
163 {
164 return (page == 1);
165 }
166
167 void wxPrintout::GetPageInfo(int *minPage, int *maxPage, int *fromPage, int *toPage)
168 {
169 *minPage = 1;
170 *maxPage = 32000;
171 *fromPage = 1;
172 *toPage = 1;
173 }
174
175 /*
176 * Preview canvas
177 */
178
179 wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent,
180 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
181 wxScrolledWindow(parent, -1, pos, size, style, name)
182 {
183 m_printPreview = preview;
184 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
185
186 SetScrollbars(15, 18, 100, 100);
187 }
188
189 wxPreviewCanvas::~wxPreviewCanvas()
190 {
191 }
192
193 void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
194 {
195 wxPaintDC dc(this);
196 PrepareDC( dc );
197
198 /*
199 #ifdef __WXGTK__
200 if (!GetUpdateRegion().IsEmpty())
201 dc.SetClippingRegion( GetUpdateRegion() );
202 #endif
203 */
204
205 if (m_printPreview)
206 {
207 m_printPreview->PaintPage(this, dc);
208 }
209 }
210
211 // Responds to colour changes, and passes event on to children.
212 void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event)
213 {
214 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
215 Refresh();
216
217 // Propagate the event to the non-top-level children
218 wxWindow::OnSysColourChanged(event);
219 }
220
221 /*
222 * Preview control bar
223 */
224
225 BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel)
226 EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnWindowClose)
227 EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrint)
228 EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPreviousButton)
229 EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNextButton)
230 EVT_CHAR(wxPreviewControlBar::OnChar)
231 EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom)
232 EVT_PAINT(wxPreviewControlBar::OnPaint)
233 END_EVENT_TABLE()
234
235 wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons,
236 wxWindow *parent, const wxPoint& pos, const wxSize& size,
237 long style, const wxString& name):
238 wxPanel(parent, -1, pos, size, style, name)
239 {
240 m_printPreview = preview;
241 m_closeButton = (wxButton *) NULL;
242 m_nextPageButton = (wxButton *) NULL;
243 m_previousPageButton = (wxButton *) NULL;
244 m_printButton = (wxButton *) NULL;
245 m_zoomControl = (wxChoice *) NULL;
246 m_buttonFlags = buttons;
247 }
248
249 wxPreviewControlBar::~wxPreviewControlBar()
250 {
251 }
252
253 void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event))
254 {
255 wxPaintDC dc(this);
256
257 int w, h;
258 GetSize(&w, &h);
259 dc.SetPen(*wxBLACK_PEN);
260 dc.SetBrush(*wxTRANSPARENT_BRUSH);
261 dc.DrawLine( 0, h-1, w, h-1 );
262 }
263
264 void wxPreviewControlBar::OnWindowClose(wxCommandEvent& WXUNUSED(event))
265 {
266 wxPreviewFrame *frame = (wxPreviewFrame *)GetParent();
267 frame->Close(TRUE);
268 }
269
270 void wxPreviewControlBar::OnPrint(wxCommandEvent& WXUNUSED(event))
271 {
272 wxPrintPreviewBase *preview = GetPrintPreview();
273 preview->Print(TRUE);
274 }
275
276 void wxPreviewControlBar::OnChar(wxKeyEvent &event)
277 {
278 switch(event.KeyCode())
279 {
280 case WXK_NEXT:
281 OnNext(); break;
282 case WXK_PRIOR:
283 OnPrevious(); break;
284 default:
285 event.Skip();
286 }
287 }
288
289 void wxPreviewControlBar::OnNext(void)
290 {
291 wxPrintPreviewBase *preview = GetPrintPreview();
292 if (preview)
293 {
294 int currentPage = preview->GetCurrentPage();
295 if ((preview->GetMaxPage() > 0) &&
296 (currentPage < preview->GetMaxPage()) &&
297 preview->GetPrintout()->HasPage(currentPage + 1))
298 {
299 preview->SetCurrentPage(currentPage + 1);
300 }
301 }
302 }
303
304 void wxPreviewControlBar::OnPrevious(void)
305 {
306 wxPrintPreviewBase *preview = GetPrintPreview();
307 if (preview)
308 {
309 int currentPage = preview->GetCurrentPage();
310 if ((preview->GetMinPage() > 0) &&
311 (currentPage > preview->GetMinPage()) &&
312 preview->GetPrintout()->HasPage(currentPage - 1))
313 {
314 preview->SetCurrentPage(currentPage - 1);
315 }
316 }
317 }
318
319 void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event))
320 {
321 int zoom = GetZoomControl();
322 if (GetPrintPreview())
323 GetPrintPreview()->SetZoom(zoom);
324 }
325
326 void wxPreviewControlBar::CreateButtons()
327 {
328 SetSize(0, 0, 400, 40);
329
330 /*
331 #ifdef __WXMSW__
332 int fontSize = 9;
333 #else
334 int fontSize = 10;
335 #endif
336
337 wxFont buttonFont(fontSize, wxSWISS, wxNORMAL, wxBOLD);
338 SetFont(buttonFont);
339 */
340
341 int buttonWidth = 65;
342 #ifdef __WXGTK__
343 int buttonHeight = -1;
344 #else
345 int buttonHeight = 24;
346 #endif
347
348 int x = 5;
349 int y = 5;
350
351 #ifdef __WXMOTIF__
352 int gap = 15;
353 #else
354 int gap = 5;
355 #endif
356
357 m_closeButton = new wxButton(this, wxID_PREVIEW_CLOSE, _("Close"),
358 wxPoint(x, y), wxSize(buttonWidth, buttonHeight));
359
360 x += gap + buttonWidth;
361
362 if (m_buttonFlags & wxPREVIEW_PRINT)
363 {
364 m_printButton = new wxButton(this, wxID_PREVIEW_PRINT, _("Print..."), wxPoint(x, y),
365 wxSize(buttonWidth, buttonHeight));
366 x += gap + buttonWidth;
367 }
368
369 if (m_buttonFlags & wxPREVIEW_PREVIOUS)
370 {
371 m_previousPageButton = new wxButton(this, wxID_PREVIEW_PREVIOUS, wxT("<<"), wxPoint(x, y),
372 wxSize(buttonWidth, buttonHeight));
373 x += gap + buttonWidth;
374 }
375
376 if (m_buttonFlags & wxPREVIEW_NEXT)
377 {
378 m_nextPageButton = new wxButton(this, wxID_PREVIEW_NEXT, wxT(">>"),
379 wxPoint(x, y), wxSize(buttonWidth, buttonHeight));
380 x += gap + buttonWidth;
381 }
382
383 if (m_buttonFlags & wxPREVIEW_ZOOM)
384 {
385 static const char *choices[] =
386 {
387 "10%", "15%", "20%", "25%", "30%", "35%", "40%", "45%", "50%", "55%",
388 "60%", "65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%", "110%",
389 "120%", "150%", "200%"
390 };
391
392 int n = WXSIZEOF(choices);
393
394 wxString* strings = new wxString[n];
395 int i;
396 for (i = 0; i < n; i++ )
397 strings[i] = choices[i];
398
399 m_zoomControl = new wxChoice(this, wxID_PREVIEW_ZOOM,
400 wxPoint(x, y),
401 wxSize(100, -1),
402 n,
403 strings
404 );
405 delete[] strings;
406
407 SetZoomControl(m_printPreview->GetZoom());
408 }
409
410 // m_closeButton->SetDefault();
411 }
412
413 void wxPreviewControlBar::SetZoomControl(int zoom)
414 {
415 char buf[20];
416 sprintf(buf, "%d%%", zoom);
417 // Someone is calling methods that do no exist in wxChoice!! So I'll just comment out for VA for now
418 if (m_zoomControl)
419 m_zoomControl->SetStringSelection(buf);
420 }
421
422 int wxPreviewControlBar::GetZoomControl()
423 {
424 wxChar buf[20];
425 if (m_zoomControl && (m_zoomControl->GetStringSelection() != wxT("")))
426 {
427 wxStrcpy(buf, m_zoomControl->GetStringSelection());
428 buf[wxStrlen(buf) - 1] = 0;
429 return (int)wxAtoi(buf);
430 }
431 else return 0;
432 }
433
434
435 /*
436 * Preview frame
437 */
438
439 BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame)
440 EVT_CLOSE(wxPreviewFrame::OnCloseWindow)
441 END_EVENT_TABLE()
442
443 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxFrame *parent, const wxString& title,
444 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
445 wxFrame(parent, -1, title, pos, size, style, name)
446 {
447 m_printPreview = preview;
448 m_controlBar = NULL;
449 m_previewCanvas = NULL;
450 }
451
452 wxPreviewFrame::~wxPreviewFrame()
453 {
454 }
455
456 void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
457 {
458 MakeModal(FALSE);
459
460 // Need to delete the printout and the print preview
461 wxPrintout *printout = m_printPreview->GetPrintout();
462 if (printout)
463 {
464 delete printout;
465 m_printPreview->SetPrintout(NULL);
466 m_printPreview->SetCanvas(NULL);
467 m_printPreview->SetFrame(NULL);
468 }
469 delete m_printPreview;
470
471 Destroy();
472 }
473
474 void wxPreviewFrame::Initialize()
475 {
476 CreateStatusBar();
477
478 CreateCanvas();
479 CreateControlBar();
480
481 m_printPreview->SetCanvas(m_previewCanvas);
482 m_printPreview->SetFrame(this);
483
484 // Set layout constraints here
485
486 // Control bar constraints
487 wxLayoutConstraints *c1 = new wxLayoutConstraints;
488 // int w, h;
489 // m_controlBar->GetSize(&w, &h);
490 int h;
491 #if (defined(__WXMSW__) || defined(__WXGTK__))
492 h = 40;
493 #else
494 h = 60;
495 #endif
496
497 c1->left.SameAs (this, wxLeft);
498 c1->top.SameAs (this, wxTop);
499 c1->right.SameAs (this, wxRight);
500 c1->height.Absolute (h);
501
502 m_controlBar->SetConstraints(c1);
503
504 // Canvas constraints
505 wxLayoutConstraints *c2 = new wxLayoutConstraints;
506
507 c2->left.SameAs (this, wxLeft);
508 c2->top.Below (m_controlBar);
509 c2->right.SameAs (this, wxRight);
510 c2->bottom.SameAs (this, wxBottom);
511
512 m_previewCanvas->SetConstraints(c2);
513
514 SetAutoLayout(TRUE);
515
516 MakeModal(TRUE);
517
518 Layout();
519 }
520
521 void wxPreviewFrame::CreateCanvas()
522 {
523 m_previewCanvas = new wxPreviewCanvas(m_printPreview, this);
524 }
525
526 void wxPreviewFrame::CreateControlBar()
527 {
528 long buttons = wxPREVIEW_DEFAULT;
529 if (m_printPreview->GetPrintoutForPrinting())
530 buttons |= wxPREVIEW_PRINT;
531
532 m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0, 0), wxSize(400, 40));
533 m_controlBar->CreateButtons();
534 }
535
536 /*
537 * Print preview
538 */
539
540 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
541 wxPrintout *printoutForPrinting,
542 wxPrintData *data)
543 {
544 if (data)
545 m_printDialogData = (*data);
546
547 Init(printout, printoutForPrinting);
548 }
549
550 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
551 wxPrintout *printoutForPrinting,
552 wxPrintDialogData *data)
553 {
554 if (data)
555 m_printDialogData = (*data);
556
557 Init(printout, printoutForPrinting);
558 }
559
560 void wxPrintPreviewBase::Init(wxPrintout *printout,
561 wxPrintout *printoutForPrinting)
562 {
563 m_isOk = TRUE;
564 m_previewPrintout = printout;
565 if (m_previewPrintout)
566 m_previewPrintout->SetIsPreview(TRUE);
567
568 m_printPrintout = printoutForPrinting;
569
570 m_previewCanvas = NULL;
571 m_previewFrame = NULL;
572 m_previewBitmap = NULL;
573 m_currentPage = 1;
574 m_currentZoom = 70;
575 m_topMargin = 40;
576 m_leftMargin = 40;
577 m_pageWidth = 0;
578 m_pageHeight = 0;
579 m_printingPrepared = FALSE;
580
581 // Too soon! Moved to RenderPage.
582 // printout->OnPreparePrinting();
583
584 // Get some parameters from the printout, if defined
585 int selFrom, selTo;
586 printout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo);
587 }
588
589 wxPrintPreviewBase::~wxPrintPreviewBase()
590 {
591 if (m_previewPrintout)
592 delete m_previewPrintout;
593 if (m_previewBitmap)
594 delete m_previewBitmap;
595 if (m_printPrintout)
596 delete m_printPrintout;
597 }
598
599 bool wxPrintPreviewBase::SetCurrentPage(int pageNum)
600 {
601 if (m_currentPage == pageNum)
602 return TRUE;
603
604 m_currentPage = pageNum;
605 if (m_previewBitmap)
606 {
607 delete m_previewBitmap;
608 m_previewBitmap = NULL;
609 }
610
611 if (m_previewCanvas)
612 {
613 RenderPage(pageNum);
614 m_previewCanvas->Refresh();
615 }
616 return TRUE;
617 }
618
619 bool wxPrintPreviewBase::PaintPage(wxWindow *canvas, wxDC& dc)
620 {
621 DrawBlankPage(canvas, dc);
622
623 if (!m_previewBitmap)
624 RenderPage(m_currentPage);
625
626 if (!m_previewBitmap)
627 return FALSE;
628
629 if (!canvas)
630 return FALSE;
631
632 int canvasWidth, canvasHeight;
633 canvas->GetSize(&canvasWidth, &canvasHeight);
634
635 double zoomScale = ((float)m_currentZoom/(float)100);
636 double actualWidth = (zoomScale*m_pageWidth*m_previewScale);
637 // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale);
638
639 int x = (int) ((canvasWidth - actualWidth)/2.0);
640 if (x < m_leftMargin)
641 x = m_leftMargin;
642 int y = m_topMargin;
643
644 wxMemoryDC temp_dc;
645 temp_dc.SelectObject(*m_previewBitmap);
646
647 dc.Blit(x, y, m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0);
648
649 temp_dc.SelectObject(wxNullBitmap);
650
651 return TRUE;
652 }
653
654 bool wxPrintPreviewBase::RenderPage(int pageNum)
655 {
656 int canvasWidth, canvasHeight;
657
658 if (!m_previewCanvas)
659 {
660 wxFAIL_MSG(_T("wxPrintPreviewBase::RenderPage: must use "
661 "wxPrintPreviewBase::SetCanvas to let me "
662 "know about the canvas!"));
663
664 return FALSE;
665 }
666 m_previewCanvas->GetSize(&canvasWidth, &canvasHeight);
667
668 double zoomScale = (m_currentZoom/100.0);
669 int actualWidth = (int)(zoomScale*m_pageWidth*m_previewScale);
670 int actualHeight = (int)(zoomScale*m_pageHeight*m_previewScale);
671
672 int x = (int)((canvasWidth - actualWidth)/2.0);
673 if (x < m_leftMargin)
674 x = m_leftMargin;
675 // int y = m_topMargin;
676
677
678 if (!m_previewBitmap)
679 {
680 m_previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight);
681 if (!m_previewBitmap || !m_previewBitmap->Ok())
682 {
683 if (m_previewBitmap)
684 delete m_previewBitmap;
685 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK);
686 return FALSE;
687 }
688 }
689
690 wxMemoryDC memoryDC;
691 memoryDC.SelectObject(*m_previewBitmap);
692
693 memoryDC.Clear();
694
695 m_previewPrintout->SetDC(&memoryDC);
696 m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
697
698 // Need to delay OnPreparePrinting until here, so we have enough information.
699 if (!m_printingPrepared)
700 {
701 m_previewPrintout->OnPreparePrinting();
702 m_printingPrepared = TRUE;
703 }
704
705 m_previewPrintout->OnBeginPrinting();
706
707 if (!m_previewPrintout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
708 {
709 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK);
710
711 memoryDC.SelectObject(wxNullBitmap);
712
713 delete m_previewBitmap;
714 return FALSE;
715 }
716
717 m_previewPrintout->OnPrintPage(pageNum);
718 m_previewPrintout->OnEndDocument();
719 m_previewPrintout->OnEndPrinting();
720
721 m_previewPrintout->SetDC(NULL);
722
723 memoryDC.SelectObject(wxNullBitmap);
724
725 wxChar buf[200];
726 if (m_maxPage != 0)
727 wxSprintf(buf, _("Page %d of %d"), pageNum, m_maxPage);
728 else
729 wxSprintf(buf, _("Page %d"), pageNum);
730
731 if (m_previewFrame)
732 m_previewFrame->SetStatusText(buf);
733
734 return TRUE;
735 }
736
737
738 bool wxPrintPreviewBase::DrawBlankPage(wxWindow *canvas, wxDC& dc)
739 {
740 int canvasWidth, canvasHeight;
741 canvas->GetSize(&canvasWidth, &canvasHeight);
742
743 float zoomScale = (float)((float)m_currentZoom/(float)100);
744 float actualWidth = zoomScale*m_pageWidth*m_previewScale;
745 float actualHeight = zoomScale*m_pageHeight*m_previewScale;
746
747 float x = (float)((canvasWidth - actualWidth)/2.0);
748 if (x < m_leftMargin)
749 x = (float)m_leftMargin;
750 float y = (float)m_topMargin;
751
752 // Draw shadow, allowing for 1-pixel border AROUND the actual page
753 int shadowOffset = 4;
754 dc.SetPen(*wxBLACK_PEN);
755 dc.SetBrush(*wxBLACK_BRUSH);
756 /*
757 dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2));
758 */
759 dc.DrawRectangle((int)(x + shadowOffset), (int)(y + actualHeight+1), (int)(actualWidth), shadowOffset);
760 dc.DrawRectangle((int)(x + actualWidth), (int)(y + shadowOffset), shadowOffset, (int)(actualHeight));
761
762 // Draw blank page allowing for 1-pixel border AROUND the actual page
763 dc.SetPen(*wxBLACK_PEN);
764 dc.SetBrush(*wxWHITE_BRUSH);
765
766 /*
767 wxRegion update_region = canvas->GetUpdateRegion();
768 wxRect r = update_region.GetBox();
769
770 printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height );
771 */
772
773 dc.DrawRectangle((int)(x-2), (int)(y-1), (int)(actualWidth+3), (int)(actualHeight+2));
774
775 return TRUE;
776 }
777
778 void wxPrintPreviewBase::SetZoom(int percent)
779 {
780 if (m_currentZoom == percent)
781 return;
782
783 m_currentZoom = percent;
784 if (m_previewBitmap)
785 {
786 delete m_previewBitmap;
787 m_previewBitmap = NULL;
788 }
789
790 if (m_previewCanvas)
791 {
792 RenderPage(m_currentPage);
793 ((wxScrolledWindow *) m_previewCanvas)->Scroll(0, 0);
794 m_previewCanvas->Clear();
795 m_previewCanvas->Refresh();
796 }
797 }
798
799 #endif // wxUSE_PRINTING_ARCHITECTURE