]> git.saurik.com Git - wxWidgets.git/blob - src/common/prntbase.cpp
Changed the order in which events are checked, so that LOST events are
[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 if (m_printPreview)
199 {
200 m_printPreview->PaintPage(this, dc);
201 }
202 }
203
204 // Responds to colour changes, and passes event on to children.
205 void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event)
206 {
207 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
208 Refresh();
209
210 // Propagate the event to the non-top-level children
211 wxWindow::OnSysColourChanged(event);
212 }
213
214 /*
215 * Preview control bar
216 */
217
218 BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel)
219 EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnWindowClose)
220 EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrint)
221 EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPreviousButton)
222 EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNextButton)
223 EVT_CHAR(wxPreviewControlBar::OnChar)
224 EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom)
225 EVT_PAINT(wxPreviewControlBar::OnPaint)
226 END_EVENT_TABLE()
227
228 wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons,
229 wxWindow *parent, const wxPoint& pos, const wxSize& size,
230 long style, const wxString& name):
231 wxPanel(parent, -1, pos, size, style, name)
232 {
233 m_printPreview = preview;
234 m_closeButton = (wxButton *) NULL;
235 m_nextPageButton = (wxButton *) NULL;
236 m_previousPageButton = (wxButton *) NULL;
237 m_printButton = (wxButton *) NULL;
238 m_zoomControl = (wxChoice *) NULL;
239 m_buttonFlags = buttons;
240 }
241
242 wxPreviewControlBar::~wxPreviewControlBar()
243 {
244 }
245
246 void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event))
247 {
248 wxPaintDC dc(this);
249
250 int w, h;
251 GetSize(&w, &h);
252 dc.SetPen(*wxBLACK_PEN);
253 dc.SetBrush(*wxTRANSPARENT_BRUSH);
254 dc.DrawLine( 0, h-1, w, h-1 );
255 }
256
257 void wxPreviewControlBar::OnWindowClose(wxCommandEvent& WXUNUSED(event))
258 {
259 wxPreviewFrame *frame = (wxPreviewFrame *)GetParent();
260 frame->Close(TRUE);
261 }
262
263 void wxPreviewControlBar::OnPrint(wxCommandEvent& WXUNUSED(event))
264 {
265 wxPrintPreviewBase *preview = GetPrintPreview();
266 preview->Print(TRUE);
267 }
268
269 void wxPreviewControlBar::OnChar(wxKeyEvent &event)
270 {
271 switch(event.KeyCode())
272 {
273 case WXK_NEXT:
274 OnNext(); break;
275 case WXK_PRIOR:
276 OnPrevious(); break;
277 default:
278 event.Skip();
279 }
280 }
281
282 void wxPreviewControlBar::OnNext(void)
283 {
284 wxPrintPreviewBase *preview = GetPrintPreview();
285 if (preview)
286 {
287 int currentPage = preview->GetCurrentPage();
288 if ((preview->GetMaxPage() > 0) &&
289 (currentPage < preview->GetMaxPage()) &&
290 preview->GetPrintout()->HasPage(currentPage + 1))
291 {
292 preview->SetCurrentPage(currentPage + 1);
293 }
294 }
295 }
296
297 void wxPreviewControlBar::OnPrevious(void)
298 {
299 wxPrintPreviewBase *preview = GetPrintPreview();
300 if (preview)
301 {
302 int currentPage = preview->GetCurrentPage();
303 if ((preview->GetMinPage() > 0) &&
304 (currentPage > preview->GetMinPage()) &&
305 preview->GetPrintout()->HasPage(currentPage - 1))
306 {
307 preview->SetCurrentPage(currentPage - 1);
308 }
309 }
310 }
311
312 void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event))
313 {
314 int zoom = GetZoomControl();
315 if (GetPrintPreview())
316 GetPrintPreview()->SetZoom(zoom);
317 }
318
319 void wxPreviewControlBar::CreateButtons()
320 {
321 SetSize(0, 0, 400, 40);
322
323 /*
324 #ifdef __WXMSW__
325 int fontSize = 9;
326 #else
327 int fontSize = 10;
328 #endif
329
330 wxFont buttonFont(fontSize, wxSWISS, wxNORMAL, wxBOLD);
331 SetFont(buttonFont);
332 */
333
334 int buttonWidth = 65;
335 #ifdef __WXGTK__
336 int buttonHeight = -1;
337 #else
338 int buttonHeight = 24;
339 #endif
340
341 int x = 5;
342 int y = 5;
343
344 #ifdef __WXMOTIF__
345 int gap = 15;
346 #else
347 int gap = 5;
348 #endif
349
350 m_closeButton = new wxButton(this, wxID_PREVIEW_CLOSE, _("Close"),
351 wxPoint(x, y), wxSize(buttonWidth, buttonHeight));
352
353 x += gap + buttonWidth;
354
355 if (m_buttonFlags & wxPREVIEW_PRINT)
356 {
357 m_printButton = new wxButton(this, wxID_PREVIEW_PRINT, _("Print..."), wxPoint(x, y),
358 wxSize(buttonWidth, buttonHeight));
359 x += gap + buttonWidth;
360 }
361
362 if (m_buttonFlags & wxPREVIEW_PREVIOUS)
363 {
364 m_previousPageButton = new wxButton(this, wxID_PREVIEW_PREVIOUS, wxT("<<"), wxPoint(x, y),
365 wxSize(buttonWidth, buttonHeight));
366 x += gap + buttonWidth;
367 }
368
369 if (m_buttonFlags & wxPREVIEW_NEXT)
370 {
371 m_nextPageButton = new wxButton(this, wxID_PREVIEW_NEXT, wxT(">>"),
372 wxPoint(x, y), wxSize(buttonWidth, buttonHeight));
373 x += gap + buttonWidth;
374 }
375
376 if (m_buttonFlags & wxPREVIEW_ZOOM)
377 {
378 static const char *choices[] =
379 {
380 "10%", "15%", "20%", "25%", "30%", "35%", "40%", "45%", "50%", "55%",
381 "60%", "65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%", "110%",
382 "120%", "150%", "200%"
383 };
384
385 int n = WXSIZEOF(choices);
386
387 wxString* strings = new wxString[n];
388 int i;
389 for (i = 0; i < n; i++ )
390 strings[i] = choices[i];
391
392 m_zoomControl = new wxChoice(this, wxID_PREVIEW_ZOOM,
393 wxPoint(x, y),
394 wxSize(100, -1),
395 n,
396 strings
397 );
398 delete[] strings;
399
400 SetZoomControl(m_printPreview->GetZoom());
401 }
402
403 // m_closeButton->SetDefault();
404 }
405
406 void wxPreviewControlBar::SetZoomControl(int zoom)
407 {
408 char buf[20];
409 sprintf(buf, "%d%%", zoom);
410 // Someone is calling methods that do no exist in wxChoice!! So I'll just comment out for VA for now
411 if (m_zoomControl)
412 m_zoomControl->SetStringSelection(buf);
413 }
414
415 int wxPreviewControlBar::GetZoomControl()
416 {
417 wxChar buf[20];
418 if (m_zoomControl && (m_zoomControl->GetStringSelection() != wxT("")))
419 {
420 wxStrcpy(buf, m_zoomControl->GetStringSelection());
421 buf[wxStrlen(buf) - 1] = 0;
422 return (int)wxAtoi(buf);
423 }
424 else return 0;
425 }
426
427
428 /*
429 * Preview frame
430 */
431
432 BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame)
433 EVT_CLOSE(wxPreviewFrame::OnCloseWindow)
434 END_EVENT_TABLE()
435
436 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxFrame *parent, const wxString& title,
437 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
438 wxFrame(parent, -1, title, pos, size, style, name)
439 {
440 m_printPreview = preview;
441 m_controlBar = NULL;
442 m_previewCanvas = NULL;
443 }
444
445 wxPreviewFrame::~wxPreviewFrame()
446 {
447 }
448
449 void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
450 {
451 MakeModal(FALSE);
452
453 // Need to delete the printout and the print preview
454 wxPrintout *printout = m_printPreview->GetPrintout();
455 if (printout)
456 {
457 delete printout;
458 m_printPreview->SetPrintout(NULL);
459 m_printPreview->SetCanvas(NULL);
460 m_printPreview->SetFrame(NULL);
461 }
462 delete m_printPreview;
463
464 Destroy();
465 }
466
467 void wxPreviewFrame::Initialize()
468 {
469 CreateStatusBar();
470
471 CreateCanvas();
472 CreateControlBar();
473
474 m_printPreview->SetCanvas(m_previewCanvas);
475 m_printPreview->SetFrame(this);
476
477 // Set layout constraints here
478
479 // Control bar constraints
480 wxLayoutConstraints *c1 = new wxLayoutConstraints;
481 // int w, h;
482 // m_controlBar->GetSize(&w, &h);
483 int h;
484 #if (defined(__WXMSW__) || defined(__WXGTK__))
485 h = 40;
486 #else
487 h = 60;
488 #endif
489
490 c1->left.SameAs (this, wxLeft);
491 c1->top.SameAs (this, wxTop);
492 c1->right.SameAs (this, wxRight);
493 c1->height.Absolute (h);
494
495 m_controlBar->SetConstraints(c1);
496
497 // Canvas constraints
498 wxLayoutConstraints *c2 = new wxLayoutConstraints;
499
500 c2->left.SameAs (this, wxLeft);
501 c2->top.Below (m_controlBar);
502 c2->right.SameAs (this, wxRight);
503 c2->bottom.SameAs (this, wxBottom);
504
505 m_previewCanvas->SetConstraints(c2);
506
507 SetAutoLayout(TRUE);
508
509 MakeModal(TRUE);
510
511 Layout();
512 }
513
514 void wxPreviewFrame::CreateCanvas()
515 {
516 m_previewCanvas = new wxPreviewCanvas(m_printPreview, this);
517 }
518
519 void wxPreviewFrame::CreateControlBar()
520 {
521 long buttons = wxPREVIEW_DEFAULT;
522 if (m_printPreview->GetPrintoutForPrinting())
523 buttons |= wxPREVIEW_PRINT;
524
525 m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0, 0), wxSize(400, 40));
526 m_controlBar->CreateButtons();
527 }
528
529 /*
530 * Print preview
531 */
532
533 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
534 wxPrintout *printoutForPrinting,
535 wxPrintData *data)
536 {
537 if (data)
538 m_printDialogData = (*data);
539
540 Init(printout, printoutForPrinting);
541 }
542
543 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
544 wxPrintout *printoutForPrinting,
545 wxPrintDialogData *data)
546 {
547 if (data)
548 m_printDialogData = (*data);
549
550 Init(printout, printoutForPrinting);
551 }
552
553 void wxPrintPreviewBase::Init(wxPrintout *printout,
554 wxPrintout *printoutForPrinting)
555 {
556 m_isOk = TRUE;
557 m_previewPrintout = printout;
558 if (m_previewPrintout)
559 m_previewPrintout->SetIsPreview(TRUE);
560
561 m_printPrintout = printoutForPrinting;
562
563 m_previewCanvas = NULL;
564 m_previewFrame = NULL;
565 m_previewBitmap = NULL;
566 m_currentPage = 1;
567 m_currentZoom = 70;
568 m_topMargin = 40;
569 m_leftMargin = 40;
570 m_pageWidth = 0;
571 m_pageHeight = 0;
572 m_printingPrepared = FALSE;
573
574 // Too soon! Moved to RenderPage.
575 // printout->OnPreparePrinting();
576
577 // Get some parameters from the printout, if defined
578 int selFrom, selTo;
579 printout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo);
580 }
581
582 wxPrintPreviewBase::~wxPrintPreviewBase()
583 {
584 if (m_previewPrintout)
585 delete m_previewPrintout;
586 if (m_previewBitmap)
587 delete m_previewBitmap;
588 if (m_printPrintout)
589 delete m_printPrintout;
590 }
591
592 bool wxPrintPreviewBase::SetCurrentPage(int pageNum)
593 {
594 if (m_currentPage == pageNum)
595 return TRUE;
596
597 m_currentPage = pageNum;
598 if (m_previewBitmap)
599 {
600 delete m_previewBitmap;
601 m_previewBitmap = NULL;
602 }
603
604 if (m_previewCanvas)
605 {
606 RenderPage(pageNum);
607 m_previewCanvas->Refresh();
608 }
609 return TRUE;
610 }
611
612 bool wxPrintPreviewBase::PaintPage(wxWindow *canvas, wxDC& dc)
613 {
614 DrawBlankPage(canvas, dc);
615
616 if (!m_previewBitmap)
617 RenderPage(m_currentPage);
618
619 if (!m_previewBitmap)
620 return FALSE;
621
622 if (!canvas)
623 return FALSE;
624
625 int canvasWidth, canvasHeight;
626 canvas->GetSize(&canvasWidth, &canvasHeight);
627
628 double zoomScale = ((float)m_currentZoom/(float)100);
629 double actualWidth = (zoomScale*m_pageWidth*m_previewScale);
630 // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale);
631
632 int x = (int) ((canvasWidth - actualWidth)/2.0);
633 if (x < m_leftMargin)
634 x = m_leftMargin;
635 int y = m_topMargin;
636
637 wxMemoryDC temp_dc;
638 temp_dc.SelectObject(*m_previewBitmap);
639
640 dc.Blit(x, y, m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0);
641
642 temp_dc.SelectObject(wxNullBitmap);
643
644 return TRUE;
645 }
646
647 bool wxPrintPreviewBase::RenderPage(int pageNum)
648 {
649 int canvasWidth, canvasHeight;
650
651 if (!m_previewCanvas)
652 {
653 wxMessageBox(_("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"),
654 _("Print Preview Failure"), wxOK);
655 return FALSE;
656 }
657 m_previewCanvas->GetSize(&canvasWidth, &canvasHeight);
658
659 double zoomScale = (m_currentZoom/100.0);
660 int actualWidth = (int)(zoomScale*m_pageWidth*m_previewScale);
661 int actualHeight = (int)(zoomScale*m_pageHeight*m_previewScale);
662
663 int x = (int)((canvasWidth - actualWidth)/2.0);
664 if (x < m_leftMargin)
665 x = m_leftMargin;
666 // int y = m_topMargin;
667
668
669 if (!m_previewBitmap)
670 {
671 m_previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight);
672 if (!m_previewBitmap || !m_previewBitmap->Ok())
673 {
674 if (m_previewBitmap)
675 delete m_previewBitmap;
676 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK);
677 return FALSE;
678 }
679 }
680
681 wxMemoryDC memoryDC;
682 memoryDC.SelectObject(*m_previewBitmap);
683
684 memoryDC.Clear();
685
686 m_previewPrintout->SetDC(&memoryDC);
687 m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
688
689 // Need to delay OnPreparePrinting until here, so we have enough information.
690 if (!m_printingPrepared)
691 {
692 m_previewPrintout->OnPreparePrinting();
693 m_printingPrepared = TRUE;
694 }
695
696 m_previewPrintout->OnBeginPrinting();
697
698 if (!m_previewPrintout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
699 {
700 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK);
701
702 memoryDC.SelectObject(wxNullBitmap);
703
704 delete m_previewBitmap;
705 return FALSE;
706 }
707
708 m_previewPrintout->OnPrintPage(pageNum);
709 m_previewPrintout->OnEndDocument();
710 m_previewPrintout->OnEndPrinting();
711
712 m_previewPrintout->SetDC(NULL);
713
714 memoryDC.SelectObject(wxNullBitmap);
715
716 wxChar buf[200];
717 if (m_maxPage != 0)
718 wxSprintf(buf, _("Page %d of %d"), pageNum, m_maxPage);
719 else
720 wxSprintf(buf, _("Page %d"), pageNum);
721
722 if (m_previewFrame)
723 m_previewFrame->SetStatusText(buf);
724
725 return TRUE;
726 }
727
728
729 bool wxPrintPreviewBase::DrawBlankPage(wxWindow *canvas, wxDC& dc)
730 {
731 int canvasWidth, canvasHeight;
732 canvas->GetSize(&canvasWidth, &canvasHeight);
733
734 float zoomScale = (float)((float)m_currentZoom/(float)100);
735 float actualWidth = zoomScale*m_pageWidth*m_previewScale;
736 float actualHeight = zoomScale*m_pageHeight*m_previewScale;
737
738 float x = (float)((canvasWidth - actualWidth)/2.0);
739 if (x < m_leftMargin)
740 x = (float)m_leftMargin;
741 float y = (float)m_topMargin;
742
743 // Draw shadow, allowing for 1-pixel border AROUND the actual page
744 int shadowOffset = 4;
745 dc.SetPen(*wxBLACK_PEN);
746 dc.SetBrush(*wxBLACK_BRUSH);
747 /*
748 dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2));
749 */
750 dc.DrawRectangle((int)(x + shadowOffset), (int)(y + actualHeight+1), (int)(actualWidth), shadowOffset);
751 dc.DrawRectangle((int)(x + actualWidth), (int)(y + shadowOffset), shadowOffset, (int)(actualHeight));
752
753 // Draw blank page allowing for 1-pixel border AROUND the actual page
754 dc.SetPen(*wxBLACK_PEN);
755 dc.SetBrush(*wxWHITE_BRUSH);
756
757 /*
758 wxRegion update_region = canvas->GetUpdateRegion();
759 wxRect r = update_region.GetBox();
760
761 printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height );
762 */
763
764 dc.DrawRectangle((int)(x-2), (int)(y-1), (int)(actualWidth+3), (int)(actualHeight+2));
765
766 return TRUE;
767 }
768
769 void wxPrintPreviewBase::SetZoom(int percent)
770 {
771 if (m_currentZoom == percent)
772 return;
773
774 m_currentZoom = percent;
775 if (m_previewBitmap)
776 {
777 delete m_previewBitmap;
778 m_previewBitmap = NULL;
779 }
780
781 if (m_previewCanvas)
782 {
783 RenderPage(m_currentPage);
784 ((wxScrolledWindow *) m_previewCanvas)->Scroll(0, 0);
785 m_previewCanvas->Clear();
786 m_previewCanvas->Refresh();
787 }
788 }
789
790 #endif // wxUSE_PRINTING_ARCHITECTURE