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