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