]> git.saurik.com Git - wxWidgets.git/blob - src/common/prntbase.cpp
More key event work. Added SetDetectableAutoRepeat.
[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 static const char *choices[] =
370 {
371 "10%", "15%", "20%", "25%", "30%", "35%", "40%", "45%", "50%", "55%",
372 "60%", "65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%", "110%",
373 "120%", "150%", "200%"
374 };
375
376 if (m_buttonFlags & wxPREVIEW_ZOOM)
377 {
378 m_zoomControl = new wxChoice(this, wxID_PREVIEW_ZOOM,
379 wxPoint(x, y), wxSize(100, -1));
380 SetZoomControl(m_printPreview->GetZoom());
381 }
382
383 // Yes, this look stupid, but this is because gcc gives up otherwise.
384 int n = WXSIZEOF(choices);
385 for ( int i = 0; i < n; i++ )
386 m_zoomControl->Append(choices[i]);
387
388 // m_closeButton->SetDefault();
389 }
390
391 void wxPreviewControlBar::SetZoomControl(int zoom)
392 {
393 char buf[20];
394 sprintf(buf, "%d%%", zoom);
395 if (m_zoomControl)
396 m_zoomControl->SetStringSelection(buf);
397 }
398
399 int wxPreviewControlBar::GetZoomControl()
400 {
401 wxChar buf[20];
402 if (m_zoomControl && (m_zoomControl->GetStringSelection() != _T("")))
403 {
404 wxStrcpy(buf, m_zoomControl->GetStringSelection());
405 buf[wxStrlen(buf) - 1] = 0;
406 return (int)wxAtoi(buf);
407 }
408 else return 0;
409 }
410
411
412 /*
413 * Preview frame
414 */
415
416 BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame)
417 EVT_CLOSE(wxPreviewFrame::OnCloseWindow)
418 END_EVENT_TABLE()
419
420 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxFrame *parent, const wxString& title,
421 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
422 wxFrame(parent, -1, title, pos, size, style, name)
423 {
424 m_printPreview = preview;
425 m_controlBar = NULL;
426 m_previewCanvas = NULL;
427 }
428
429 wxPreviewFrame::~wxPreviewFrame()
430 {
431 }
432
433 void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
434 {
435 MakeModal(FALSE);
436
437 // Need to delete the printout and the print preview
438 wxPrintout *printout = m_printPreview->GetPrintout();
439 if (printout)
440 {
441 delete printout;
442 m_printPreview->SetPrintout(NULL);
443 m_printPreview->SetCanvas(NULL);
444 m_printPreview->SetFrame(NULL);
445 }
446 delete m_printPreview;
447
448 Destroy();
449 }
450
451 void wxPreviewFrame::Initialize()
452 {
453 CreateStatusBar();
454
455 CreateCanvas();
456 CreateControlBar();
457
458 m_printPreview->SetCanvas(m_previewCanvas);
459 m_printPreview->SetFrame(this);
460
461 // Set layout constraints here
462
463 // Control bar constraints
464 wxLayoutConstraints *c1 = new wxLayoutConstraints;
465 // int w, h;
466 // m_controlBar->GetSize(&w, &h);
467 int h;
468 #if (defined(__WXMSW__) || defined(__WXGTK__))
469 h = 40;
470 #else
471 h = 60;
472 #endif
473
474 c1->left.SameAs (this, wxLeft);
475 c1->top.SameAs (this, wxTop);
476 c1->right.SameAs (this, wxRight);
477 c1->height.Absolute (h);
478
479 m_controlBar->SetConstraints(c1);
480
481 // Canvas constraints
482 wxLayoutConstraints *c2 = new wxLayoutConstraints;
483
484 c2->left.SameAs (this, wxLeft);
485 c2->top.Below (m_controlBar);
486 c2->right.SameAs (this, wxRight);
487 c2->bottom.SameAs (this, wxBottom);
488
489 m_previewCanvas->SetConstraints(c2);
490
491 SetAutoLayout(TRUE);
492
493 MakeModal(TRUE);
494
495 Layout();
496 }
497
498 void wxPreviewFrame::CreateCanvas()
499 {
500 m_previewCanvas = new wxPreviewCanvas(m_printPreview, this);
501 }
502
503 void wxPreviewFrame::CreateControlBar()
504 {
505 long buttons = wxPREVIEW_DEFAULT;
506 if (m_printPreview->GetPrintoutForPrinting())
507 buttons |= wxPREVIEW_PRINT;
508
509 m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0, 0), wxSize(400, 40));
510 m_controlBar->CreateButtons();
511 }
512
513 /*
514 * Print preview
515 */
516
517 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
518 wxPrintout *printoutForPrinting,
519 wxPrintData *data)
520 {
521 if (data)
522 m_printDialogData = (*data);
523
524 Init(printout, printoutForPrinting);
525 }
526
527 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
528 wxPrintout *printoutForPrinting,
529 wxPrintDialogData *data)
530 {
531 if (data)
532 m_printDialogData = (*data);
533
534 Init(printout, printoutForPrinting);
535 }
536
537 void wxPrintPreviewBase::Init(wxPrintout *printout,
538 wxPrintout *printoutForPrinting)
539 {
540 m_isOk = TRUE;
541 m_previewPrintout = printout;
542 if (m_previewPrintout)
543 m_previewPrintout->SetIsPreview(TRUE);
544
545 m_printPrintout = printoutForPrinting;
546
547 m_previewCanvas = NULL;
548 m_previewFrame = NULL;
549 m_previewBitmap = NULL;
550 m_currentPage = 1;
551 m_currentZoom = 30;
552 m_topMargin = 40;
553 m_leftMargin = 40;
554 m_pageWidth = 0;
555 m_pageHeight = 0;
556
557 printout->OnPreparePrinting();
558
559 // Get some parameters from the printout, if defined
560 int selFrom, selTo;
561 printout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo);
562 }
563
564 wxPrintPreviewBase::~wxPrintPreviewBase()
565 {
566 if (m_previewPrintout)
567 delete m_previewPrintout;
568 if (m_previewBitmap)
569 delete m_previewBitmap;
570 if (m_printPrintout)
571 delete m_printPrintout;
572 }
573
574 bool wxPrintPreviewBase::SetCurrentPage(int pageNum)
575 {
576 if (m_currentPage == pageNum)
577 return TRUE;
578
579 m_currentPage = pageNum;
580 if (m_previewBitmap)
581 {
582 delete m_previewBitmap;
583 m_previewBitmap = NULL;
584 }
585
586 if (m_previewCanvas)
587 {
588 RenderPage(pageNum);
589 m_previewCanvas->Refresh();
590 }
591 return TRUE;
592 }
593
594 bool wxPrintPreviewBase::PaintPage(wxWindow *canvas, wxDC& dc)
595 {
596 DrawBlankPage(canvas, dc);
597
598 if (!m_previewBitmap)
599 RenderPage(m_currentPage);
600
601 if (!m_previewBitmap)
602 return FALSE;
603
604 if (!canvas)
605 return FALSE;
606
607 int canvasWidth, canvasHeight;
608 canvas->GetSize(&canvasWidth, &canvasHeight);
609
610 double zoomScale = ((float)m_currentZoom/(float)100);
611 double actualWidth = (zoomScale*m_pageWidth*m_previewScale);
612 // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale);
613
614 int x = (int) ((canvasWidth - actualWidth)/2.0);
615 if (x < m_leftMargin)
616 x = m_leftMargin;
617 int y = m_topMargin;
618
619 wxMemoryDC temp_dc;
620 temp_dc.SelectObject(*m_previewBitmap);
621
622 dc.Blit(x, y, m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0);
623
624 temp_dc.SelectObject(wxNullBitmap);
625
626 return TRUE;
627 }
628
629 bool wxPrintPreviewBase::RenderPage(int pageNum)
630 {
631 int canvasWidth, canvasHeight;
632
633 if (!m_previewCanvas)
634 {
635 wxMessageBox(_("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"),
636 _("Print Preview Failure"), wxOK);
637 return FALSE;
638 }
639 m_previewCanvas->GetSize(&canvasWidth, &canvasHeight);
640
641 double zoomScale = (m_currentZoom/100.0);
642 int actualWidth = (int)(zoomScale*m_pageWidth*m_previewScale);
643 int actualHeight = (int)(zoomScale*m_pageHeight*m_previewScale);
644
645 int x = (int)((canvasWidth - actualWidth)/2.0);
646 if (x < m_leftMargin)
647 x = m_leftMargin;
648 // int y = m_topMargin;
649
650
651 if (!m_previewBitmap)
652 {
653 m_previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight);
654 if (!m_previewBitmap || !m_previewBitmap->Ok())
655 {
656 if (m_previewBitmap)
657 delete m_previewBitmap;
658 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK);
659 return FALSE;
660 }
661 }
662
663 wxMemoryDC memoryDC;
664 memoryDC.SelectObject(*m_previewBitmap);
665
666 memoryDC.Clear();
667
668 m_previewPrintout->SetDC(&memoryDC);
669 m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
670
671 m_previewPrintout->OnBeginPrinting();
672
673 if (!m_previewPrintout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
674 {
675 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK);
676
677 memoryDC.SelectObject(wxNullBitmap);
678
679 delete m_previewBitmap;
680 return FALSE;
681 }
682
683 m_previewPrintout->OnPrintPage(pageNum);
684 m_previewPrintout->OnEndDocument();
685 m_previewPrintout->OnEndPrinting();
686
687 m_previewPrintout->SetDC(NULL);
688
689 memoryDC.SelectObject(wxNullBitmap);
690
691 wxChar buf[200];
692 if (m_maxPage != 0)
693 wxSprintf(buf, _("Page %d of %d"), pageNum, m_maxPage);
694 else
695 wxSprintf(buf, _("Page %d"), pageNum);
696
697 if (m_previewFrame)
698 m_previewFrame->SetStatusText(buf);
699
700 return TRUE;
701 }
702
703
704 bool wxPrintPreviewBase::DrawBlankPage(wxWindow *canvas, wxDC& dc)
705 {
706 int canvasWidth, canvasHeight;
707 canvas->GetSize(&canvasWidth, &canvasHeight);
708
709 float zoomScale = (float)((float)m_currentZoom/(float)100);
710 float actualWidth = zoomScale*m_pageWidth*m_previewScale;
711 float actualHeight = zoomScale*m_pageHeight*m_previewScale;
712
713 float x = (float)((canvasWidth - actualWidth)/2.0);
714 if (x < m_leftMargin)
715 x = (float)m_leftMargin;
716 float y = (float)m_topMargin;
717
718 // Draw shadow, allowing for 1-pixel border AROUND the actual page
719 int shadowOffset = 4;
720 dc.SetPen(*wxBLACK_PEN);
721 dc.SetBrush(*wxBLACK_BRUSH);
722 /*
723 dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2));
724 */
725 dc.DrawRectangle((int)(x + shadowOffset), (int)(y + actualHeight+1), (int)(actualWidth), shadowOffset);
726 dc.DrawRectangle((int)(x + actualWidth), (int)(y + shadowOffset), shadowOffset, (int)(actualHeight));
727
728 // Draw blank page allowing for 1-pixel border AROUND the actual page
729 dc.SetPen(*wxBLACK_PEN);
730 dc.SetBrush(*wxWHITE_BRUSH);
731
732 /*
733 wxRegion update_region = canvas->GetUpdateRegion();
734 wxRect r = update_region.GetBox();
735
736 printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height );
737 */
738
739 dc.DrawRectangle((int)(x-2), (int)(y-1), (int)(actualWidth+3), (int)(actualHeight+2));
740
741 return TRUE;
742 }
743
744 void wxPrintPreviewBase::SetZoom(int percent)
745 {
746 if (m_currentZoom == percent)
747 return;
748
749 m_currentZoom = percent;
750 if (m_previewBitmap)
751 {
752 delete m_previewBitmap;
753 m_previewBitmap = NULL;
754 }
755
756
757 if (m_previewCanvas)
758 {
759 RenderPage(m_currentPage);
760 m_previewCanvas->Clear();
761 m_previewCanvas->Refresh();
762 }
763 }
764