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