]> git.saurik.com Git - wxWidgets.git/blob - src/common/prntbase.cpp
docopydocs is not needed for this script.
[wxWidgets.git] / src / common / prntbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_PRINTING_ARCHITECTURE
20
21 #ifndef WX_PRECOMP
22 #include "wx/utils.h"
23 #include "wx/dc.h"
24 #include "wx/app.h"
25 #include "wx/msgdlg.h"
26 #include "wx/layout.h"
27 #include "wx/choice.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/dcmemory.h"
31 #include "wx/stattext.h"
32 #include "wx/intl.h"
33 #include "wx/textdlg.h"
34 #include "wx/sizer.h"
35 #endif // !WX_PRECOMP
36
37 #include "wx/prntbase.h"
38 #include "wx/dcprint.h"
39 #include "wx/printdlg.h"
40 #include "wx/print.h"
41 #include "wx/module.h"
42
43 #include <stdlib.h>
44 #include <string.h>
45
46 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
47 #include "wx/msw/printdlg.h"
48 #elif defined(__WXMAC__)
49 #include "wx/mac/printdlg.h"
50 #include "wx/mac/private/print.h"
51 #else
52 #include "wx/generic/prntdlgg.h"
53 #endif
54
55 #ifdef __WXMSW__
56 #include "wx/msw/wrapcdlg.h"
57 #ifndef __WIN32__
58 #include <print.h>
59 #endif
60 #endif // __WXMSW__
61
62 //----------------------------------------------------------------------------
63 // wxPrintFactory
64 //----------------------------------------------------------------------------
65
66 wxPrintFactory *wxPrintFactory::m_factory = NULL;
67
68 void wxPrintFactory::SetPrintFactory( wxPrintFactory *factory )
69 {
70 if (wxPrintFactory::m_factory)
71 delete wxPrintFactory::m_factory;
72
73 wxPrintFactory::m_factory = factory;
74 }
75
76 wxPrintFactory *wxPrintFactory::GetFactory()
77 {
78 if (!wxPrintFactory::m_factory)
79 wxPrintFactory::m_factory = new wxNativePrintFactory;
80
81 return wxPrintFactory::m_factory;
82 }
83
84 //----------------------------------------------------------------------------
85 // wxNativePrintFactory
86 //----------------------------------------------------------------------------
87
88 wxPrinterBase *wxNativePrintFactory::CreatePrinter( wxPrintDialogData *data )
89 {
90 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
91 return new wxWindowsPrinter( data );
92 #elif defined(__WXMAC__)
93 return new wxMacPrinter( data );
94 #elif defined(__WXPM__)
95 return new wxOS2Printer( data );
96 #else
97 return new wxPostScriptPrinter( data );
98 #endif
99 }
100
101 wxPrintPreviewBase *wxNativePrintFactory::CreatePrintPreview( wxPrintout *preview,
102 wxPrintout *printout, wxPrintDialogData *data )
103 {
104 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
105 return new wxWindowsPrintPreview( preview, printout, data );
106 #elif defined(__WXMAC__)
107 return new wxMacPrintPreview( preview, printout, data );
108 #elif defined(__WXPM__)
109 return new wxOS2PrintPreview( preview, printout, data );
110 #else
111 return new wxPostScriptPrintPreview( preview, printout, data );
112 #endif
113 }
114
115 wxPrintPreviewBase *wxNativePrintFactory::CreatePrintPreview( wxPrintout *preview,
116 wxPrintout *printout, wxPrintData *data )
117 {
118 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
119 return new wxWindowsPrintPreview( preview, printout, data );
120 #elif defined(__WXMAC__)
121 return new wxMacPrintPreview( preview, printout, data );
122 #elif defined(__WXPM__)
123 return new wxOS2PrintPreview( preview, printout, data );
124 #else
125 return new wxPostScriptPrintPreview( preview, printout, data );
126 #endif
127 }
128
129 wxPrintDialogBase *wxNativePrintFactory::CreatePrintDialog( wxWindow *parent,
130 wxPrintDialogData *data )
131 {
132 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
133 return new wxWindowsPrintDialog( parent, data );
134 #elif defined(__WXMAC__)
135 return new wxMacPrintDialog( parent, data );
136 #else
137 return new wxGenericPrintDialog( parent, data );
138 #endif
139 }
140
141 wxPrintDialogBase *wxNativePrintFactory::CreatePrintDialog( wxWindow *parent,
142 wxPrintData *data )
143 {
144 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
145 return new wxWindowsPrintDialog( parent, data );
146 #elif defined(__WXMAC__)
147 return new wxMacPrintDialog( parent, data );
148 #else
149 return new wxGenericPrintDialog( parent, data );
150 #endif
151 }
152
153 wxPageSetupDialogBase *wxNativePrintFactory::CreatePageSetupDialog( wxWindow *parent,
154 wxPageSetupDialogData *data )
155 {
156 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
157 return new wxWindowsPageSetupDialog( parent, data );
158 #elif defined(__WXMAC__)
159 return new wxMacPageSetupDialog( parent, data );
160 #else
161 return new wxGenericPageSetupDialog( parent, data );
162 #endif
163 }
164
165 bool wxNativePrintFactory::HasPrintSetupDialog()
166 {
167 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
168 return false;
169 #elif defined(__WXMAC__)
170 return false;
171 #else
172 // Only here do we need to provide the print setup
173 // dialog ourselves, the other platforms either have
174 // none, don't make it accessible or let you configure
175 // the printer from the wxPrintDialog anyway.
176 return true;
177 #endif
178
179 }
180
181 wxDialog *wxNativePrintFactory::CreatePrintSetupDialog( wxWindow *parent,
182 wxPrintData *data )
183 {
184 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
185 wxUnusedVar(parent);
186 wxUnusedVar(data);
187 return NULL;
188 #elif defined(__WXMAC__)
189 wxUnusedVar(parent);
190 wxUnusedVar(data);
191 return NULL;
192 #else
193 // Only here do we need to provide the print setup
194 // dialog ourselves, the other platforms either have
195 // none, don't make it accessible or let you configure
196 // the printer from the wxPrintDialog anyway.
197 return new wxGenericPrintSetupDialog( parent, data );
198 #endif
199 }
200
201 bool wxNativePrintFactory::HasOwnPrintToFile()
202 {
203 // Only relevant for PostScript and here the
204 // setup dialog provides no "print to file"
205 // option. In the GNOME setup dialog, the
206 // setup dialog has its own print to file.
207 return false;
208 }
209
210 bool wxNativePrintFactory::HasPrinterLine()
211 {
212 // Only relevant for PostScript for now
213 return true;
214 }
215
216 wxString wxNativePrintFactory::CreatePrinterLine()
217 {
218 // Only relevant for PostScript for now
219
220 // We should query "lpstat -d" here
221 return _("Generic PostScript");
222 }
223
224 bool wxNativePrintFactory::HasStatusLine()
225 {
226 // Only relevant for PostScript for now
227 return true;
228 }
229
230 wxString wxNativePrintFactory::CreateStatusLine()
231 {
232 // Only relevant for PostScript for now
233
234 // We should query "lpstat -r" or "lpstat -p" here
235 return _("Ready");
236 }
237
238 wxPrintNativeDataBase *wxNativePrintFactory::CreatePrintNativeData()
239 {
240 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
241 return new wxWindowsPrintNativeData;
242 #elif defined(__WXMAC__)
243 return new wxMacCarbonPrintData;
244 #else
245 return new wxPostScriptPrintNativeData;
246 #endif
247 }
248
249 //----------------------------------------------------------------------------
250 // wxPrintNativeDataBase
251 //----------------------------------------------------------------------------
252
253 IMPLEMENT_ABSTRACT_CLASS(wxPrintNativeDataBase, wxObject)
254
255 wxPrintNativeDataBase::wxPrintNativeDataBase()
256 {
257 m_ref = 1;
258 }
259
260 //----------------------------------------------------------------------------
261 // wxPrintFactoryModule
262 //----------------------------------------------------------------------------
263
264 class wxPrintFactoryModule: public wxModule
265 {
266 public:
267 wxPrintFactoryModule() {}
268 bool OnInit() { return true; }
269 void OnExit() { wxPrintFactory::SetPrintFactory( NULL ); }
270
271 private:
272 DECLARE_DYNAMIC_CLASS(wxPrintFactoryModule)
273 };
274
275 IMPLEMENT_DYNAMIC_CLASS(wxPrintFactoryModule, wxModule)
276
277 //----------------------------------------------------------------------------
278 // wxPrinterBase
279 //----------------------------------------------------------------------------
280
281 IMPLEMENT_CLASS(wxPrinterBase, wxObject)
282
283 wxPrinterBase::wxPrinterBase(wxPrintDialogData *data)
284 {
285 m_currentPrintout = (wxPrintout *) NULL;
286 sm_abortWindow = (wxWindow *) NULL;
287 sm_abortIt = false;
288 if (data)
289 m_printDialogData = (*data);
290 sm_lastError = wxPRINTER_NO_ERROR;
291 }
292
293 wxWindow *wxPrinterBase::sm_abortWindow = (wxWindow *) NULL;
294 bool wxPrinterBase::sm_abortIt = false;
295 wxPrinterError wxPrinterBase::sm_lastError = wxPRINTER_NO_ERROR;
296
297 wxPrinterBase::~wxPrinterBase()
298 {
299 }
300
301 wxWindow *wxPrinterBase::CreateAbortWindow(wxWindow *parent, wxPrintout * printout)
302 {
303 wxPrintAbortDialog *dialog = new wxPrintAbortDialog(parent, _("Printing ") , wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE);
304
305 wxBoxSizer *button_sizer = new wxBoxSizer( wxVERTICAL );
306 button_sizer->Add( new wxStaticText(dialog, wxID_ANY, _("Please wait while printing\n") + printout->GetTitle() ), 0, wxALL, 10 );
307 button_sizer->Add( new wxButton( dialog, wxID_CANCEL, wxT("Cancel") ), 0, wxALL | wxALIGN_CENTER, 10 );
308
309 dialog->SetAutoLayout( true );
310 dialog->SetSizer( button_sizer );
311
312 button_sizer->Fit(dialog);
313 button_sizer->SetSizeHints (dialog) ;
314
315 return dialog;
316 }
317
318 void wxPrinterBase::ReportError(wxWindow *parent, wxPrintout *WXUNUSED(printout), const wxString& message)
319 {
320 wxMessageBox(message, _("Printing Error"), wxOK, parent);
321 }
322
323 wxPrintDialogData& wxPrinterBase::GetPrintDialogData() const
324 {
325 return (wxPrintDialogData&) m_printDialogData;
326 }
327
328 //----------------------------------------------------------------------------
329 // wxPrinter
330 //----------------------------------------------------------------------------
331
332 IMPLEMENT_CLASS(wxPrinter, wxPrinterBase)
333
334 wxPrinter::wxPrinter(wxPrintDialogData *data)
335 {
336 m_pimpl = wxPrintFactory::GetFactory()->CreatePrinter( data );
337 }
338
339 wxPrinter::~wxPrinter()
340 {
341 delete m_pimpl;
342 }
343
344 wxWindow *wxPrinter::CreateAbortWindow(wxWindow *parent, wxPrintout *printout)
345 {
346 return m_pimpl->CreateAbortWindow( parent, printout );
347 }
348
349 void wxPrinter::ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message)
350 {
351 m_pimpl->ReportError( parent, printout, message );
352 }
353
354 bool wxPrinter::Setup(wxWindow *parent)
355 {
356 return m_pimpl->Setup( parent );
357 }
358
359 bool wxPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
360 {
361 return m_pimpl->Print( parent, printout, prompt );
362 }
363
364 wxDC* wxPrinter::PrintDialog(wxWindow *parent)
365 {
366 return m_pimpl->PrintDialog( parent );
367 }
368
369 wxPrintDialogData& wxPrinter::GetPrintDialogData() const
370 {
371 return m_pimpl->GetPrintDialogData();
372 }
373
374 // ---------------------------------------------------------------------------
375 // wxPrintDialogBase: the dialog for printing.
376 // ---------------------------------------------------------------------------
377
378 IMPLEMENT_ABSTRACT_CLASS(wxPrintDialogBase, wxDialog)
379
380 wxPrintDialogBase::wxPrintDialogBase(wxWindow *parent,
381 wxWindowID id,
382 const wxString &title,
383 const wxPoint &pos,
384 const wxSize &size,
385 long style)
386 : wxDialog( parent, id, title.empty() ? wxString(_("Print")) : title,
387 pos, size, style )
388 {
389 }
390
391 // ---------------------------------------------------------------------------
392 // wxPrintDialog: the dialog for printing
393 // ---------------------------------------------------------------------------
394
395 IMPLEMENT_CLASS(wxPrintDialog, wxObject)
396
397 wxPrintDialog::wxPrintDialog(wxWindow *parent, wxPrintDialogData* data)
398 {
399 m_pimpl = wxPrintFactory::GetFactory()->CreatePrintDialog( parent, data );
400 }
401
402 wxPrintDialog::wxPrintDialog(wxWindow *parent, wxPrintData* data)
403 {
404 m_pimpl = wxPrintFactory::GetFactory()->CreatePrintDialog( parent, data );
405 }
406
407 wxPrintDialog::~wxPrintDialog()
408 {
409 delete m_pimpl;
410 }
411
412 int wxPrintDialog::ShowModal()
413 {
414 return m_pimpl->ShowModal();
415 }
416
417 wxPrintDialogData& wxPrintDialog::GetPrintDialogData()
418 {
419 return m_pimpl->GetPrintDialogData();
420 }
421
422 wxPrintData& wxPrintDialog::GetPrintData()
423 {
424 return m_pimpl->GetPrintData();
425 }
426
427 wxDC *wxPrintDialog::GetPrintDC()
428 {
429 return m_pimpl->GetPrintDC();
430 }
431
432 // ---------------------------------------------------------------------------
433 // wxPageSetupDialogBase: the page setup dialog
434 // ---------------------------------------------------------------------------
435
436 IMPLEMENT_ABSTRACT_CLASS(wxPageSetupDialogBase, wxDialog)
437
438 wxPageSetupDialogBase::wxPageSetupDialogBase(wxWindow *parent,
439 wxWindowID id,
440 const wxString &title,
441 const wxPoint &pos,
442 const wxSize &size,
443 long style)
444 : wxDialog( parent, id, title.empty() ? wxString(_("Page setup")) : title,
445 pos, size, style )
446 {
447 }
448
449 // ---------------------------------------------------------------------------
450 // wxPageSetupDialog: the page setup dialog
451 // ---------------------------------------------------------------------------
452
453 IMPLEMENT_CLASS(wxPageSetupDialog, wxObject)
454
455 wxPageSetupDialog::wxPageSetupDialog(wxWindow *parent, wxPageSetupDialogData *data )
456 {
457 m_pimpl = wxPrintFactory::GetFactory()->CreatePageSetupDialog( parent, data );
458 }
459
460 wxPageSetupDialog::~wxPageSetupDialog()
461 {
462 delete m_pimpl;
463 }
464
465 int wxPageSetupDialog::ShowModal()
466 {
467 return m_pimpl->ShowModal();
468 }
469
470 wxPageSetupDialogData& wxPageSetupDialog::GetPageSetupDialogData()
471 {
472 return m_pimpl->GetPageSetupDialogData();
473 }
474
475 // old name
476 wxPageSetupDialogData& wxPageSetupDialog::GetPageSetupData()
477 {
478 return m_pimpl->GetPageSetupDialogData();
479 }
480
481 //----------------------------------------------------------------------------
482 // wxPrintAbortDialog
483 //----------------------------------------------------------------------------
484
485 BEGIN_EVENT_TABLE(wxPrintAbortDialog, wxDialog)
486 EVT_BUTTON(wxID_CANCEL, wxPrintAbortDialog::OnCancel)
487 END_EVENT_TABLE()
488
489 void wxPrintAbortDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
490 {
491 wxPrinterBase::sm_abortIt = true;
492 wxPrinterBase::sm_abortWindow->Show(false);
493 wxPrinterBase::sm_abortWindow->Close(true);
494 wxPrinterBase::sm_abortWindow = (wxWindow *) NULL;
495 }
496
497 //----------------------------------------------------------------------------
498 // wxPrintout
499 //----------------------------------------------------------------------------
500
501 IMPLEMENT_ABSTRACT_CLASS(wxPrintout, wxObject)
502
503 wxPrintout::wxPrintout(const wxString& title)
504 {
505 m_printoutTitle = title ;
506 m_printoutDC = (wxDC *) NULL;
507 m_pageWidthMM = 0;
508 m_pageHeightMM = 0;
509 m_pageWidthPixels = 0;
510 m_pageHeightPixels = 0;
511 m_PPIScreenX = 0;
512 m_PPIScreenY = 0;
513 m_PPIPrinterX = 0;
514 m_PPIPrinterY = 0;
515 m_isPreview = false;
516 }
517
518 wxPrintout::~wxPrintout()
519 {
520 }
521
522 bool wxPrintout::OnBeginDocument(int WXUNUSED(startPage), int WXUNUSED(endPage))
523 {
524 return GetDC()->StartDoc(_("Printing ") + m_printoutTitle);
525 }
526
527 void wxPrintout::OnEndDocument()
528 {
529 GetDC()->EndDoc();
530 }
531
532 void wxPrintout::OnBeginPrinting()
533 {
534 }
535
536 void wxPrintout::OnEndPrinting()
537 {
538 }
539
540 bool wxPrintout::HasPage(int page)
541 {
542 return (page == 1);
543 }
544
545 void wxPrintout::GetPageInfo(int *minPage, int *maxPage, int *fromPage, int *toPage)
546 {
547 *minPage = 1;
548 *maxPage = 32000;
549 *fromPage = 1;
550 *toPage = 1;
551 }
552
553 //----------------------------------------------------------------------------
554 // wxPreviewCanvas
555 //----------------------------------------------------------------------------
556
557 IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow)
558
559 BEGIN_EVENT_TABLE(wxPreviewCanvas, wxScrolledWindow)
560 EVT_PAINT(wxPreviewCanvas::OnPaint)
561 EVT_CHAR(wxPreviewCanvas::OnChar)
562 EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged)
563 #if wxUSE_MOUSEWHEEL
564 EVT_MOUSEWHEEL(wxPreviewCanvas::OnMouseWheel)
565 #endif
566 END_EVENT_TABLE()
567
568 // VZ: the current code doesn't refresh properly without
569 // wxFULL_REPAINT_ON_RESIZE, this must be fixed as otherwise we have
570 // really horrible flicker when resizing the preview frame, but without
571 // this style it simply doesn't work correctly at all...
572 wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent,
573 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
574 wxScrolledWindow(parent, wxID_ANY, pos, size, style | wxFULL_REPAINT_ON_RESIZE, name)
575 {
576 m_printPreview = preview;
577 #ifdef __WXMAC__
578 // The app workspace colour is always white, but we should have
579 // a contrast with the page.
580 wxSystemColour colourIndex = wxSYS_COLOUR_3DDKSHADOW;
581 #else
582 wxSystemColour colourIndex = wxSYS_COLOUR_APPWORKSPACE;
583 #endif
584 SetBackgroundColour(wxSystemSettings::GetColour(colourIndex));
585
586 SetScrollbars(10, 10, 100, 100);
587 }
588
589 wxPreviewCanvas::~wxPreviewCanvas()
590 {
591 }
592
593 void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
594 {
595 wxPaintDC dc(this);
596 PrepareDC( dc );
597
598 /*
599 #ifdef __WXGTK__
600 if (!GetUpdateRegion().IsEmpty())
601 dc.SetClippingRegion( GetUpdateRegion() );
602 #endif
603 */
604
605 if (m_printPreview)
606 {
607 m_printPreview->PaintPage(this, dc);
608 }
609 }
610
611 // Responds to colour changes, and passes event on to children.
612 void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event)
613 {
614 #ifdef __WXMAC__
615 // The app workspace colour is always white, but we should have
616 // a contrast with the page.
617 wxSystemColour colourIndex = wxSYS_COLOUR_3DDKSHADOW;
618 #else
619 wxSystemColour colourIndex = wxSYS_COLOUR_APPWORKSPACE;
620 #endif
621 SetBackgroundColour(wxSystemSettings::GetColour(colourIndex));
622 Refresh();
623
624 // Propagate the event to the non-top-level children
625 wxWindow::OnSysColourChanged(event);
626 }
627
628 void wxPreviewCanvas::OnChar(wxKeyEvent &event)
629 {
630 wxPreviewControlBar* controlBar = ((wxPreviewFrame*) GetParent())->GetControlBar();
631 if (event.GetKeyCode() == WXK_ESCAPE)
632 {
633 ((wxPreviewFrame*) GetParent())->Close(true);
634 return;
635 }
636 else if (event.GetKeyCode() == WXK_TAB)
637 {
638 controlBar->OnGoto();
639 return;
640 }
641 else if (event.GetKeyCode() == WXK_RETURN)
642 {
643 controlBar->OnPrint();
644 return;
645 }
646
647 if (!event.ControlDown())
648 {
649 event.Skip();
650 return;
651 }
652
653 switch(event.GetKeyCode())
654 {
655 case WXK_PAGEDOWN:
656 controlBar->OnNext(); break;
657 case WXK_PAGEUP:
658 controlBar->OnPrevious(); break;
659 case WXK_HOME:
660 controlBar->OnFirst(); break;
661 case WXK_END:
662 controlBar->OnLast(); break;
663 default:
664 event.Skip();
665 }
666 }
667
668 #if wxUSE_MOUSEWHEEL
669
670 void wxPreviewCanvas::OnMouseWheel(wxMouseEvent& event)
671 {
672 wxPreviewControlBar *
673 controlBar = wxStaticCast(GetParent(), wxPreviewFrame)->GetControlBar();
674
675 if ( controlBar )
676 {
677 if ( event.ControlDown() && event.GetWheelRotation() != 0 )
678 {
679 int currentZoom = controlBar->GetZoomControl();
680
681 int delta;
682 if ( currentZoom < 100 )
683 delta = 5;
684 else if ( currentZoom <= 120 )
685 delta = 10;
686 else
687 delta = 50;
688
689 if ( event.GetWheelRotation() > 0 )
690 delta = -delta;
691
692 int newZoom = currentZoom + delta;
693 if ( newZoom < 10 )
694 newZoom = 10;
695 if ( newZoom > 200 )
696 newZoom = 200;
697 if ( newZoom != currentZoom )
698 {
699 controlBar->SetZoomControl(newZoom);
700 m_printPreview->SetZoom(newZoom);
701 Refresh();
702 }
703 return;
704 }
705 }
706
707 event.Skip();
708 }
709
710 #endif // wxUSE_MOUSEWHEEL
711
712 //----------------------------------------------------------------------------
713 // wxPreviewControlBar
714 //----------------------------------------------------------------------------
715
716 IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow)
717
718 BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel)
719 EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnWindowClose)
720 EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrintButton)
721 EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPreviousButton)
722 EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNextButton)
723 EVT_BUTTON(wxID_PREVIEW_FIRST, wxPreviewControlBar::OnFirstButton)
724 EVT_BUTTON(wxID_PREVIEW_LAST, wxPreviewControlBar::OnLastButton)
725 EVT_BUTTON(wxID_PREVIEW_GOTO, wxPreviewControlBar::OnGotoButton)
726 EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom)
727 EVT_PAINT(wxPreviewControlBar::OnPaint)
728 END_EVENT_TABLE()
729
730 wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons,
731 wxWindow *parent, const wxPoint& pos, const wxSize& size,
732 long style, const wxString& name):
733 wxPanel(parent, wxID_ANY, pos, size, style, name)
734 {
735 m_printPreview = preview;
736 m_closeButton = (wxButton *) NULL;
737 m_nextPageButton = (wxButton *) NULL;
738 m_previousPageButton = (wxButton *) NULL;
739 m_printButton = (wxButton *) NULL;
740 m_zoomControl = (wxChoice *) NULL;
741 m_buttonFlags = buttons;
742 }
743
744 wxPreviewControlBar::~wxPreviewControlBar()
745 {
746 }
747
748 void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event))
749 {
750 wxPaintDC dc(this);
751
752 int w, h;
753 GetSize(&w, &h);
754 dc.SetPen(*wxBLACK_PEN);
755 dc.SetBrush(*wxTRANSPARENT_BRUSH);
756 dc.DrawLine( 0, h-1, w, h-1 );
757 }
758
759 void wxPreviewControlBar::OnWindowClose(wxCommandEvent& WXUNUSED(event))
760 {
761 wxPreviewFrame *frame = (wxPreviewFrame *)GetParent();
762 frame->Close(true);
763 }
764
765 void wxPreviewControlBar::OnPrint(void)
766 {
767 wxPrintPreviewBase *preview = GetPrintPreview();
768 preview->Print(true);
769 }
770
771 void wxPreviewControlBar::OnNext(void)
772 {
773 wxPrintPreviewBase *preview = GetPrintPreview();
774 if (preview)
775 {
776 int currentPage = preview->GetCurrentPage();
777 if ((preview->GetMaxPage() > 0) &&
778 (currentPage < preview->GetMaxPage()) &&
779 preview->GetPrintout()->HasPage(currentPage + 1))
780 {
781 preview->SetCurrentPage(currentPage + 1);
782 }
783 }
784 }
785
786 void wxPreviewControlBar::OnPrevious(void)
787 {
788 wxPrintPreviewBase *preview = GetPrintPreview();
789 if (preview)
790 {
791 int currentPage = preview->GetCurrentPage();
792 if ((preview->GetMinPage() > 0) &&
793 (currentPage > preview->GetMinPage()) &&
794 preview->GetPrintout()->HasPage(currentPage - 1))
795 {
796 preview->SetCurrentPage(currentPage - 1);
797 }
798 }
799 }
800
801 void wxPreviewControlBar::OnFirst(void)
802 {
803 wxPrintPreviewBase *preview = GetPrintPreview();
804 if (preview)
805 {
806 int currentPage = preview->GetMinPage();
807 if (preview->GetPrintout()->HasPage(currentPage))
808 {
809 preview->SetCurrentPage(currentPage);
810 }
811 }
812 }
813
814 void wxPreviewControlBar::OnLast(void)
815 {
816 wxPrintPreviewBase *preview = GetPrintPreview();
817 if (preview)
818 {
819 int currentPage = preview->GetMaxPage();
820 if (preview->GetPrintout()->HasPage(currentPage))
821 {
822 preview->SetCurrentPage(currentPage);
823 }
824 }
825 }
826
827 void wxPreviewControlBar::OnGoto(void)
828 {
829 wxPrintPreviewBase *preview = GetPrintPreview();
830 if (preview)
831 {
832 long currentPage;
833
834 if (preview->GetMinPage() > 0)
835 {
836 wxString strPrompt;
837 wxString strPage;
838
839 strPrompt.Printf( _("Enter a page number between %d and %d:"),
840 preview->GetMinPage(), preview->GetMaxPage());
841 strPage.Printf( wxT("%d"), preview->GetCurrentPage() );
842
843 strPage =
844 wxGetTextFromUser( strPrompt, _("Goto Page"), strPage, GetParent());
845
846 if ( strPage.ToLong( &currentPage ) )
847 if (preview->GetPrintout()->HasPage(currentPage))
848 {
849 preview->SetCurrentPage(currentPage);
850 }
851 }
852 }
853 }
854
855 void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event))
856 {
857 int zoom = GetZoomControl();
858 if (GetPrintPreview())
859 GetPrintPreview()->SetZoom(zoom);
860 }
861
862 void wxPreviewControlBar::CreateButtons()
863 {
864 SetSize(0, 0, 400, 40);
865
866 wxBoxSizer *item0 = new wxBoxSizer( wxHORIZONTAL );
867
868 m_closeButton = new wxButton( this, wxID_PREVIEW_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
869 item0->Add( m_closeButton, 0, wxALIGN_CENTRE|wxALL, 5 );
870
871 if (m_buttonFlags & wxPREVIEW_PRINT)
872 {
873 m_printButton = new wxButton( this, wxID_PREVIEW_PRINT, _("&Print..."), wxDefaultPosition, wxDefaultSize, 0 );
874 item0->Add( m_printButton, 0, wxALIGN_CENTRE|wxALL, 5 );
875 }
876
877 if (m_buttonFlags & wxPREVIEW_FIRST)
878 {
879 m_firstPageButton = new wxButton( this, wxID_PREVIEW_FIRST, _("|<<"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
880 item0->Add( m_firstPageButton, 0, wxALIGN_CENTRE|wxALL, 5 );
881 }
882
883 if (m_buttonFlags & wxPREVIEW_PREVIOUS)
884 {
885 m_previousPageButton = new wxButton( this, wxID_PREVIEW_PREVIOUS, _("<<"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
886 item0->Add( m_previousPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 );
887 }
888
889 if (m_buttonFlags & wxPREVIEW_NEXT)
890 {
891 m_nextPageButton = new wxButton( this, wxID_PREVIEW_NEXT, _(">>"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
892 item0->Add( m_nextPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 );
893 }
894
895 if (m_buttonFlags & wxPREVIEW_LAST)
896 {
897 m_lastPageButton = new wxButton( this, wxID_PREVIEW_LAST, _(">>|"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
898 item0->Add( m_lastPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 );
899 }
900
901 if (m_buttonFlags & wxPREVIEW_GOTO)
902 {
903 m_gotoPageButton = new wxButton( this, wxID_PREVIEW_GOTO, _("&Goto..."), wxDefaultPosition, wxDefaultSize, 0 );
904 item0->Add( m_gotoPageButton, 0, wxALIGN_CENTRE|wxALL, 5 );
905 }
906
907 if (m_buttonFlags & wxPREVIEW_ZOOM)
908 {
909 wxString choices[] =
910 {
911 wxT("10%"), wxT("15%"), wxT("20%"), wxT("25%"), wxT("30%"), wxT("35%"), wxT("40%"), wxT("45%"), wxT("50%"), wxT("55%"),
912 wxT("60%"), wxT("65%"), wxT("70%"), wxT("75%"), wxT("80%"), wxT("85%"), wxT("90%"), wxT("95%"), wxT("100%"), wxT("110%"),
913 wxT("120%"), wxT("150%"), wxT("200%")
914 };
915 int n = WXSIZEOF(choices);
916
917 m_zoomControl = new wxChoice( this, wxID_PREVIEW_ZOOM, wxDefaultPosition, wxSize(70,wxDefaultCoord), n, choices, 0 );
918 item0->Add( m_zoomControl, 0, wxALIGN_CENTRE|wxALL, 5 );
919 SetZoomControl(m_printPreview->GetZoom());
920 }
921
922 SetSizer(item0);
923 item0->Fit(this);
924 }
925
926 void wxPreviewControlBar::SetZoomControl(int zoom)
927 {
928 if (m_zoomControl)
929 {
930 int n, count = m_zoomControl->GetCount();
931 long val;
932 for (n=0; n<count; n++)
933 {
934 if (m_zoomControl->GetString(n).BeforeFirst(wxT('%')).ToLong(&val) &&
935 (val >= long(zoom)))
936 {
937 m_zoomControl->SetSelection(n);
938 return;
939 }
940 }
941
942 m_zoomControl->SetSelection(count-1);
943 }
944 }
945
946 int wxPreviewControlBar::GetZoomControl()
947 {
948 if (m_zoomControl && (m_zoomControl->GetStringSelection() != wxEmptyString))
949 {
950 long val;
951 if (m_zoomControl->GetStringSelection().BeforeFirst(wxT('%')).ToLong(&val))
952 return int(val);
953 }
954
955 return 0;
956 }
957
958
959 /*
960 * Preview frame
961 */
962
963 IMPLEMENT_CLASS(wxPreviewFrame, wxFrame)
964
965 BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame)
966 EVT_CLOSE(wxPreviewFrame::OnCloseWindow)
967 END_EVENT_TABLE()
968
969 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxWindow *parent, const wxString& title,
970 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
971 wxFrame(parent, wxID_ANY, title, pos, size, style, name)
972 {
973 m_printPreview = preview;
974 m_controlBar = NULL;
975 m_previewCanvas = NULL;
976 m_windowDisabler = NULL;
977
978 // Give the application icon
979 #ifdef __WXMSW__
980 wxFrame* topFrame = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame);
981 if (topFrame)
982 SetIcon(topFrame->GetIcon());
983 #endif
984 }
985
986 wxPreviewFrame::~wxPreviewFrame()
987 {
988 }
989
990 void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
991 {
992 if (m_windowDisabler)
993 delete m_windowDisabler;
994
995 // Need to delete the printout and the print preview
996 wxPrintout *printout = m_printPreview->GetPrintout();
997 if (printout)
998 {
999 delete printout;
1000 m_printPreview->SetPrintout(NULL);
1001 m_printPreview->SetCanvas(NULL);
1002 m_printPreview->SetFrame(NULL);
1003 }
1004 delete m_printPreview;
1005
1006 Destroy();
1007 }
1008
1009 void wxPreviewFrame::Initialize()
1010 {
1011 #if wxUSE_STATUSBAR
1012 CreateStatusBar();
1013 #endif
1014 CreateCanvas();
1015 CreateControlBar();
1016
1017 m_printPreview->SetCanvas(m_previewCanvas);
1018 m_printPreview->SetFrame(this);
1019
1020 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
1021
1022 item0->Add( m_controlBar, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );
1023 item0->Add( m_previewCanvas, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );
1024
1025 SetAutoLayout( true );
1026 SetSizer( item0 );
1027
1028 m_windowDisabler = new wxWindowDisabler(this);
1029
1030 Layout();
1031
1032 m_printPreview->AdjustScrollbars(m_previewCanvas);
1033 m_previewCanvas->SetFocus();
1034 m_controlBar->SetFocus();
1035 }
1036
1037 void wxPreviewFrame::CreateCanvas()
1038 {
1039 m_previewCanvas = new wxPreviewCanvas(m_printPreview, this);
1040 }
1041
1042 void wxPreviewFrame::CreateControlBar()
1043 {
1044 long buttons = wxPREVIEW_DEFAULT;
1045 if (m_printPreview->GetPrintoutForPrinting())
1046 buttons |= wxPREVIEW_PRINT;
1047
1048 m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0,0), wxSize(400, 40));
1049 m_controlBar->CreateButtons();
1050 }
1051
1052 /*
1053 * Print preview
1054 */
1055
1056 IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject)
1057
1058 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
1059 wxPrintout *printoutForPrinting,
1060 wxPrintData *data)
1061 {
1062 if (data)
1063 m_printDialogData = (*data);
1064
1065 Init(printout, printoutForPrinting);
1066 }
1067
1068 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
1069 wxPrintout *printoutForPrinting,
1070 wxPrintDialogData *data)
1071 {
1072 if (data)
1073 m_printDialogData = (*data);
1074
1075 Init(printout, printoutForPrinting);
1076 }
1077
1078 void wxPrintPreviewBase::Init(wxPrintout *printout,
1079 wxPrintout *printoutForPrinting)
1080 {
1081 m_isOk = true;
1082 m_previewPrintout = printout;
1083 if (m_previewPrintout)
1084 m_previewPrintout->SetIsPreview(true);
1085
1086 m_printPrintout = printoutForPrinting;
1087
1088 m_previewCanvas = NULL;
1089 m_previewFrame = NULL;
1090 m_previewBitmap = NULL;
1091 m_currentPage = 1;
1092 m_currentZoom = 70;
1093 m_topMargin = 40;
1094 m_leftMargin = 40;
1095 m_pageWidth = 0;
1096 m_pageHeight = 0;
1097 m_printingPrepared = false;
1098 m_minPage = 1;
1099 m_maxPage = 1;
1100 }
1101
1102 wxPrintPreviewBase::~wxPrintPreviewBase()
1103 {
1104 if (m_previewPrintout)
1105 delete m_previewPrintout;
1106 if (m_previewBitmap)
1107 delete m_previewBitmap;
1108 if (m_printPrintout)
1109 delete m_printPrintout;
1110 }
1111
1112 bool wxPrintPreviewBase::SetCurrentPage(int pageNum)
1113 {
1114 if (m_currentPage == pageNum)
1115 return true;
1116
1117 m_currentPage = pageNum;
1118 if (m_previewBitmap)
1119 {
1120 delete m_previewBitmap;
1121 m_previewBitmap = NULL;
1122 }
1123
1124 if (m_previewCanvas)
1125 {
1126 AdjustScrollbars(m_previewCanvas);
1127
1128 if (!RenderPage(pageNum))
1129 return false;
1130 m_previewCanvas->Refresh();
1131 m_previewCanvas->SetFocus();
1132 }
1133 return true;
1134 }
1135
1136 int wxPrintPreviewBase::GetCurrentPage() const
1137 { return m_currentPage; }
1138 void wxPrintPreviewBase::SetPrintout(wxPrintout *printout)
1139 { m_previewPrintout = printout; }
1140 wxPrintout *wxPrintPreviewBase::GetPrintout() const
1141 { return m_previewPrintout; }
1142 wxPrintout *wxPrintPreviewBase::GetPrintoutForPrinting() const
1143 { return m_printPrintout; }
1144 void wxPrintPreviewBase::SetFrame(wxFrame *frame)
1145 { m_previewFrame = frame; }
1146 void wxPrintPreviewBase::SetCanvas(wxPreviewCanvas *canvas)
1147 { m_previewCanvas = canvas; }
1148 wxFrame *wxPrintPreviewBase::GetFrame() const
1149 { return m_previewFrame; }
1150 wxPreviewCanvas *wxPrintPreviewBase::GetCanvas() const
1151 { return m_previewCanvas; }
1152
1153 bool wxPrintPreviewBase::PaintPage(wxPreviewCanvas *canvas, wxDC& dc)
1154 {
1155 DrawBlankPage(canvas, dc);
1156
1157 if (!m_previewBitmap)
1158 if (!RenderPage(m_currentPage))
1159 return false;
1160
1161 if (!m_previewBitmap)
1162 return false;
1163
1164 if (!canvas)
1165 return false;
1166
1167 int canvasWidth, canvasHeight;
1168 canvas->GetSize(&canvasWidth, &canvasHeight);
1169
1170 double zoomScale = ((float)m_currentZoom/(float)100);
1171 double actualWidth = (zoomScale*m_pageWidth*m_previewScale);
1172 // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale);
1173
1174 int x = (int) ((canvasWidth - actualWidth)/2.0);
1175 if (x < m_leftMargin)
1176 x = m_leftMargin;
1177 int y = m_topMargin;
1178
1179 wxMemoryDC temp_dc;
1180 temp_dc.SelectObject(*m_previewBitmap);
1181
1182 dc.Blit(x, y, m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0);
1183
1184 temp_dc.SelectObject(wxNullBitmap);
1185
1186 return true;
1187 }
1188
1189 // Adjusts the scrollbars for the current scale
1190 void wxPrintPreviewBase::AdjustScrollbars(wxPreviewCanvas *canvas)
1191 {
1192 if (!canvas)
1193 return ;
1194
1195 int canvasWidth, canvasHeight;
1196 canvas->GetSize(&canvasWidth, &canvasHeight);
1197
1198 double zoomScale = ((float)m_currentZoom/(float)100);
1199 double actualWidth = (zoomScale*m_pageWidth*m_previewScale);
1200 double actualHeight = (zoomScale*m_pageHeight*m_previewScale);
1201
1202 // Set the scrollbars appropriately
1203 int totalWidth = (int)(actualWidth + 2*m_leftMargin);
1204 int totalHeight = (int)(actualHeight + 2*m_topMargin);
1205 int scrollUnitsX = totalWidth/10;
1206 int scrollUnitsY = totalHeight/10;
1207 wxSize virtualSize = canvas->GetVirtualSize();
1208 if (virtualSize.GetWidth() != totalWidth || virtualSize.GetHeight() != totalHeight)
1209 canvas->SetScrollbars(10, 10, scrollUnitsX, scrollUnitsY, 0, 0, true);
1210 }
1211
1212 bool wxPrintPreviewBase::RenderPage(int pageNum)
1213 {
1214 wxBusyCursor busy;
1215
1216 int canvasWidth, canvasHeight;
1217
1218 if (!m_previewCanvas)
1219 {
1220 wxFAIL_MSG(_T("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"));
1221
1222 return false;
1223 }
1224 m_previewCanvas->GetSize(&canvasWidth, &canvasHeight);
1225
1226 double zoomScale = (m_currentZoom/100.0);
1227 int actualWidth = (int)(zoomScale*m_pageWidth*m_previewScale);
1228 int actualHeight = (int)(zoomScale*m_pageHeight*m_previewScale);
1229
1230 if (!m_previewBitmap)
1231 {
1232 m_previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight);
1233 if (!m_previewBitmap || !m_previewBitmap->Ok())
1234 {
1235 if (m_previewBitmap) {
1236 delete m_previewBitmap;
1237 m_previewBitmap = NULL;
1238 }
1239 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK);
1240 return false;
1241 }
1242 }
1243
1244 wxMemoryDC memoryDC;
1245 memoryDC.SelectObject(*m_previewBitmap);
1246
1247 memoryDC.Clear();
1248
1249 m_previewPrintout->SetDC(&memoryDC);
1250 m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
1251
1252 // Need to delay OnPreparePrinting until here, so we have enough information.
1253 if (!m_printingPrepared)
1254 {
1255 m_previewPrintout->OnPreparePrinting();
1256 int selFrom, selTo;
1257 m_previewPrintout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo);
1258 m_printingPrepared = true;
1259 }
1260
1261 m_previewPrintout->OnBeginPrinting();
1262
1263 if (!m_previewPrintout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
1264 {
1265 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK);
1266
1267 memoryDC.SelectObject(wxNullBitmap);
1268
1269 delete m_previewBitmap;
1270 m_previewBitmap = NULL;
1271 return false;
1272 }
1273
1274 m_previewPrintout->OnPrintPage(pageNum);
1275 m_previewPrintout->OnEndDocument();
1276 m_previewPrintout->OnEndPrinting();
1277
1278 m_previewPrintout->SetDC(NULL);
1279
1280 memoryDC.SelectObject(wxNullBitmap);
1281
1282 #if wxUSE_STATUSBAR
1283 wxString status;
1284 if (m_maxPage != 0)
1285 status = wxString::Format(_("Page %d of %d"), pageNum, m_maxPage);
1286 else
1287 status = wxString::Format(_("Page %d"), pageNum);
1288
1289 if (m_previewFrame)
1290 m_previewFrame->SetStatusText(status);
1291 #endif
1292
1293 return true;
1294 }
1295
1296
1297 bool wxPrintPreviewBase::DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc)
1298 {
1299 int canvasWidth, canvasHeight;
1300 canvas->GetSize(&canvasWidth, &canvasHeight);
1301
1302 float zoomScale = (float)((float)m_currentZoom/(float)100);
1303 float actualWidth = zoomScale*m_pageWidth*m_previewScale;
1304 float actualHeight = zoomScale*m_pageHeight*m_previewScale;
1305
1306 float x = (float)((canvasWidth - actualWidth)/2.0);
1307 if (x < m_leftMargin)
1308 x = (float)m_leftMargin;
1309 float y = (float)m_topMargin;
1310
1311 // Draw shadow, allowing for 1-pixel border AROUND the actual page
1312 int shadowOffset = 4;
1313 dc.SetPen(*wxBLACK_PEN);
1314 dc.SetBrush(*wxBLACK_BRUSH);
1315 /*
1316 dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2));
1317 */
1318 dc.DrawRectangle((int)(x + shadowOffset), (int)(y + actualHeight+1), (int)(actualWidth), shadowOffset);
1319 dc.DrawRectangle((int)(x + actualWidth), (int)(y + shadowOffset), shadowOffset, (int)(actualHeight));
1320
1321 // Draw blank page allowing for 1-pixel border AROUND the actual page
1322 dc.SetPen(*wxBLACK_PEN);
1323 dc.SetBrush(*wxWHITE_BRUSH);
1324
1325 /*
1326 wxRegion update_region = canvas->GetUpdateRegion();
1327 wxRect r = update_region.GetBox();
1328
1329 printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height );
1330 */
1331
1332 dc.DrawRectangle((int)(x-2), (int)(y-1), (int)(actualWidth+3), (int)(actualHeight+2));
1333
1334 return true;
1335 }
1336
1337 void wxPrintPreviewBase::SetZoom(int percent)
1338 {
1339 if (m_currentZoom == percent)
1340 return;
1341
1342 m_currentZoom = percent;
1343 if (m_previewBitmap)
1344 {
1345 delete m_previewBitmap;
1346 m_previewBitmap = NULL;
1347 }
1348
1349 if (m_previewCanvas)
1350 {
1351 AdjustScrollbars(m_previewCanvas);
1352 RenderPage(m_currentPage);
1353 ((wxScrolledWindow *) m_previewCanvas)->Scroll(0, 0);
1354 m_previewCanvas->ClearBackground();
1355 m_previewCanvas->Refresh();
1356 m_previewCanvas->SetFocus();
1357 }
1358 }
1359
1360 wxPrintDialogData& wxPrintPreviewBase::GetPrintDialogData()
1361 {
1362 return m_printDialogData;
1363 }
1364
1365 int wxPrintPreviewBase::GetZoom() const
1366 { return m_currentZoom; }
1367 int wxPrintPreviewBase::GetMaxPage() const
1368 { return m_maxPage; }
1369 int wxPrintPreviewBase::GetMinPage() const
1370 { return m_minPage; }
1371 bool wxPrintPreviewBase::Ok() const
1372 { return m_isOk; }
1373 void wxPrintPreviewBase::SetOk(bool ok)
1374 { m_isOk = ok; }
1375 //----------------------------------------------------------------------------
1376 // wxPrintPreview
1377 //----------------------------------------------------------------------------
1378
1379 IMPLEMENT_CLASS(wxPrintPreview, wxPrintPreviewBase)
1380
1381 wxPrintPreview::wxPrintPreview(wxPrintout *printout,
1382 wxPrintout *printoutForPrinting,
1383 wxPrintDialogData *data) :
1384 wxPrintPreviewBase( printout, printoutForPrinting, data )
1385 {
1386 m_pimpl = wxPrintFactory::GetFactory()->
1387 CreatePrintPreview( printout, printoutForPrinting, data );
1388 }
1389
1390 wxPrintPreview::wxPrintPreview(wxPrintout *printout,
1391 wxPrintout *printoutForPrinting,
1392 wxPrintData *data ) :
1393 wxPrintPreviewBase( printout, printoutForPrinting, data )
1394 {
1395 m_pimpl = wxPrintFactory::GetFactory()->
1396 CreatePrintPreview( printout, printoutForPrinting, data );
1397 }
1398
1399 wxPrintPreview::~wxPrintPreview()
1400 {
1401 delete m_pimpl;
1402
1403 // don't delete twice
1404 m_printPrintout = NULL;
1405 m_previewPrintout = NULL;
1406 m_previewBitmap = NULL;
1407 }
1408
1409 bool wxPrintPreview::SetCurrentPage(int pageNum)
1410 {
1411 return m_pimpl->SetCurrentPage( pageNum );
1412 }
1413
1414 int wxPrintPreview::GetCurrentPage() const
1415 {
1416 return m_pimpl->GetCurrentPage();
1417 }
1418
1419 void wxPrintPreview::SetPrintout(wxPrintout *printout)
1420 {
1421 m_pimpl->SetPrintout( printout );
1422 }
1423
1424 wxPrintout *wxPrintPreview::GetPrintout() const
1425 {
1426 return m_pimpl->GetPrintout();
1427 }
1428
1429 wxPrintout *wxPrintPreview::GetPrintoutForPrinting() const
1430 {
1431 return m_pimpl->GetPrintoutForPrinting();
1432 }
1433
1434 void wxPrintPreview::SetFrame(wxFrame *frame)
1435 {
1436 m_pimpl->SetFrame( frame );
1437 }
1438
1439 void wxPrintPreview::SetCanvas(wxPreviewCanvas *canvas)
1440 {
1441 m_pimpl->SetCanvas( canvas );
1442 }
1443
1444 wxFrame *wxPrintPreview::GetFrame() const
1445 {
1446 return m_pimpl->GetFrame();
1447 }
1448
1449 wxPreviewCanvas *wxPrintPreview::GetCanvas() const
1450 {
1451 return m_pimpl->GetCanvas();
1452 }
1453
1454 bool wxPrintPreview::PaintPage(wxPreviewCanvas *canvas, wxDC& dc)
1455 {
1456 return m_pimpl->PaintPage( canvas, dc );
1457 }
1458
1459 bool wxPrintPreview::DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc)
1460 {
1461 return m_pimpl->DrawBlankPage( canvas, dc );
1462 }
1463
1464 void wxPrintPreview::AdjustScrollbars(wxPreviewCanvas *canvas)
1465 {
1466 m_pimpl->AdjustScrollbars( canvas );
1467 }
1468
1469 bool wxPrintPreview::RenderPage(int pageNum)
1470 {
1471 return m_pimpl->RenderPage( pageNum );
1472 }
1473
1474 void wxPrintPreview::SetZoom(int percent)
1475 {
1476 m_pimpl->SetZoom( percent );
1477 }
1478
1479 wxPrintDialogData& wxPrintPreview::GetPrintDialogData()
1480 {
1481 return m_pimpl->GetPrintDialogData();
1482 }
1483
1484 int wxPrintPreview::GetMaxPage() const
1485 {
1486 return m_pimpl->GetMaxPage();
1487 }
1488
1489 int wxPrintPreview::GetMinPage() const
1490 {
1491 return m_pimpl->GetMinPage();
1492 }
1493
1494 bool wxPrintPreview::Ok() const
1495 {
1496 return m_pimpl->Ok();
1497 }
1498
1499 void wxPrintPreview::SetOk(bool ok)
1500 {
1501 m_pimpl->SetOk( ok );
1502 }
1503
1504 bool wxPrintPreview::Print(bool interactive)
1505 {
1506 return m_pimpl->Print( interactive );
1507 }
1508
1509 void wxPrintPreview::DetermineScaling()
1510 {
1511 m_pimpl->DetermineScaling();
1512 }
1513
1514 #endif // wxUSE_PRINTING_ARCHITECTURE