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