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