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