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