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