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