]> git.saurik.com Git - wxWidgets.git/blame - src/common/prntbase.cpp
fix ANSI mode build
[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 56#elif defined(__WXMAC__)
c933e267
SC
57#include "wx/osx/printdlg.h"
58#include "wx/osx/private/print.h"
59#include "wx/osx/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)
b88bf073 811 EVT_IDLE(wxPreviewCanvas::OnIdle)
e81e3883 812 EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged)
fb6efdf2
VZ
813#if wxUSE_MOUSEWHEEL
814 EVT_MOUSEWHEEL(wxPreviewCanvas::OnMouseWheel)
815#endif
e81e3883 816END_EVENT_TABLE()
7bcb11d3 817
e9cafd42
VZ
818// VZ: the current code doesn't refresh properly without
819// wxFULL_REPAINT_ON_RESIZE, this must be fixed as otherwise we have
820// really horrible flicker when resizing the preview frame, but without
821// this style it simply doesn't work correctly at all...
c801d85f 822wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent,
7bcb11d3 823 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
7e548f6b 824wxScrolledWindow(parent, wxID_ANY, pos, size, style | wxFULL_REPAINT_ON_RESIZE, name)
c801d85f 825{
7bcb11d3 826 m_printPreview = preview;
46b24ef9
JS
827#ifdef __WXMAC__
828 // The app workspace colour is always white, but we should have
829 // a contrast with the page.
ca5020c2 830 wxSystemColour colourIndex = wxSYS_COLOUR_3DDKSHADOW;
92b799e0
JS
831#elif defined(__WXGTK__)
832 wxSystemColour colourIndex = wxSYS_COLOUR_BTNFACE;
46b24ef9
JS
833#else
834 wxSystemColour colourIndex = wxSYS_COLOUR_APPWORKSPACE;
e71fd398 835#endif
46b24ef9 836 SetBackgroundColour(wxSystemSettings::GetColour(colourIndex));
8826f46f 837
d2b354f9 838 SetScrollbars(10, 10, 100, 100);
c801d85f
KB
839}
840
34da0970 841wxPreviewCanvas::~wxPreviewCanvas()
c801d85f
KB
842{
843}
844
845void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
846{
7bcb11d3
JS
847 wxPaintDC dc(this);
848 PrepareDC( dc );
8826f46f 849
a56fcaaf 850/*
809934d2
RR
851#ifdef __WXGTK__
852 if (!GetUpdateRegion().IsEmpty())
853 dc.SetClippingRegion( GetUpdateRegion() );
854#endif
a56fcaaf 855*/
809934d2 856
7bcb11d3
JS
857 if (m_printPreview)
858 {
859 m_printPreview->PaintPage(this, dc);
860 }
c801d85f
KB
861}
862
b88bf073
VS
863void wxPreviewCanvas::OnIdle(wxIdleEvent& event)
864{
865 if ( m_printPreview )
866 {
867 if ( m_printPreview->UpdatePageRendering() )
868 Refresh();
869 }
870 event.Skip();
871}
872
c801d85f
KB
873// Responds to colour changes, and passes event on to children.
874void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event)
875{
46b24ef9
JS
876#ifdef __WXMAC__
877 // The app workspace colour is always white, but we should have
878 // a contrast with the page.
ca5020c2 879 wxSystemColour colourIndex = wxSYS_COLOUR_3DDKSHADOW;
92b799e0
JS
880#elif defined(__WXGTK__)
881 wxSystemColour colourIndex = wxSYS_COLOUR_BTNFACE;
46b24ef9
JS
882#else
883 wxSystemColour colourIndex = wxSYS_COLOUR_APPWORKSPACE;
e71fd398 884#endif
46b24ef9 885 SetBackgroundColour(wxSystemSettings::GetColour(colourIndex));
7bcb11d3 886 Refresh();
8826f46f 887
7bcb11d3
JS
888 // Propagate the event to the non-top-level children
889 wxWindow::OnSysColourChanged(event);
c801d85f
KB
890}
891
d2b354f9
JS
892void wxPreviewCanvas::OnChar(wxKeyEvent &event)
893{
b38b0d22 894 wxPreviewControlBar* controlBar = ((wxPreviewFrame*) GetParent())->GetControlBar();
043c6705 895 switch (event.GetKeyCode())
d2b354f9 896 {
043c6705
VZ
897 case WXK_TAB:
898 controlBar->OnGoto();
899 return;
900 case WXK_RETURN:
901 controlBar->OnPrint();
902 return;
b38b0d22
JS
903 }
904
d2b354f9
JS
905 if (!event.ControlDown())
906 {
907 event.Skip();
908 return;
909 }
e71fd398 910
b38b0d22
JS
911 switch(event.GetKeyCode())
912 {
faa94f3e 913 case WXK_PAGEDOWN:
b38b0d22 914 controlBar->OnNext(); break;
faa94f3e 915 case WXK_PAGEUP:
b38b0d22
JS
916 controlBar->OnPrevious(); break;
917 case WXK_HOME:
918 controlBar->OnFirst(); break;
919 case WXK_END:
920 controlBar->OnLast(); break;
921 default:
922 event.Skip();
923 }
d2b354f9
JS
924}
925
fb6efdf2
VZ
926#if wxUSE_MOUSEWHEEL
927
928void wxPreviewCanvas::OnMouseWheel(wxMouseEvent& event)
929{
930 wxPreviewControlBar *
931 controlBar = wxStaticCast(GetParent(), wxPreviewFrame)->GetControlBar();
932
933 if ( controlBar )
934 {
935 if ( event.ControlDown() && event.GetWheelRotation() != 0 )
936 {
937 int currentZoom = controlBar->GetZoomControl();
938
939 int delta;
940 if ( currentZoom < 100 )
941 delta = 5;
942 else if ( currentZoom <= 120 )
943 delta = 10;
944 else
945 delta = 50;
946
947 if ( event.GetWheelRotation() > 0 )
948 delta = -delta;
949
950 int newZoom = currentZoom + delta;
951 if ( newZoom < 10 )
952 newZoom = 10;
953 if ( newZoom > 200 )
954 newZoom = 200;
955 if ( newZoom != currentZoom )
956 {
957 controlBar->SetZoomControl(newZoom);
958 m_printPreview->SetZoom(newZoom);
959 Refresh();
960 }
961 return;
962 }
963 }
964
965 event.Skip();
966}
967
968#endif // wxUSE_MOUSEWHEEL
969
e81e3883
RR
970//----------------------------------------------------------------------------
971// wxPreviewControlBar
972//----------------------------------------------------------------------------
973
974IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow)
c801d85f
KB
975
976BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel)
8826f46f 977 EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnWindowClose)
90b6b974 978 EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrintButton)
0f90ec93
KB
979 EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPreviousButton)
980 EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNextButton)
bf89b538
JS
981 EVT_BUTTON(wxID_PREVIEW_FIRST, wxPreviewControlBar::OnFirstButton)
982 EVT_BUTTON(wxID_PREVIEW_LAST, wxPreviewControlBar::OnLastButton)
983 EVT_BUTTON(wxID_PREVIEW_GOTO, wxPreviewControlBar::OnGotoButton)
8826f46f
VZ
984 EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom)
985 EVT_PAINT(wxPreviewControlBar::OnPaint)
c801d85f 986END_EVENT_TABLE()
7bcb11d3 987
c801d85f 988wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons,
7bcb11d3
JS
989 wxWindow *parent, const wxPoint& pos, const wxSize& size,
990 long style, const wxString& name):
7e548f6b 991wxPanel(parent, wxID_ANY, pos, size, style, name)
c801d85f 992{
7bcb11d3
JS
993 m_printPreview = preview;
994 m_closeButton = (wxButton *) NULL;
995 m_nextPageButton = (wxButton *) NULL;
996 m_previousPageButton = (wxButton *) NULL;
997 m_printButton = (wxButton *) NULL;
998 m_zoomControl = (wxChoice *) NULL;
999 m_buttonFlags = buttons;
c801d85f
KB
1000}
1001
34da0970 1002wxPreviewControlBar::~wxPreviewControlBar()
c801d85f
KB
1003{
1004}
1005
1006void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event))
1007{
7bcb11d3 1008 wxPaintDC dc(this);
8826f46f 1009
7bcb11d3
JS
1010 int w, h;
1011 GetSize(&w, &h);
1012 dc.SetPen(*wxBLACK_PEN);
1013 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1014 dc.DrawLine( 0, h-1, w, h-1 );
c801d85f
KB
1015}
1016
c330a2cf 1017void wxPreviewControlBar::OnWindowClose(wxCommandEvent& WXUNUSED(event))
c801d85f 1018{
7bcb11d3 1019 wxPreviewFrame *frame = (wxPreviewFrame *)GetParent();
7e548f6b 1020 frame->Close(true);
c801d85f
KB
1021}
1022
b38b0d22 1023void wxPreviewControlBar::OnPrint(void)
c801d85f 1024{
7bcb11d3 1025 wxPrintPreviewBase *preview = GetPrintPreview();
7e548f6b 1026 preview->Print(true);
c801d85f
KB
1027}
1028
0f90ec93 1029void wxPreviewControlBar::OnNext(void)
c801d85f 1030{
7bcb11d3
JS
1031 wxPrintPreviewBase *preview = GetPrintPreview();
1032 if (preview)
c801d85f 1033 {
7bcb11d3
JS
1034 int currentPage = preview->GetCurrentPage();
1035 if ((preview->GetMaxPage() > 0) &&
1036 (currentPage < preview->GetMaxPage()) &&
1037 preview->GetPrintout()->HasPage(currentPage + 1))
1038 {
1039 preview->SetCurrentPage(currentPage + 1);
1040 }
c801d85f 1041 }
c801d85f
KB
1042}
1043
0f90ec93 1044void wxPreviewControlBar::OnPrevious(void)
c801d85f 1045{
7bcb11d3
JS
1046 wxPrintPreviewBase *preview = GetPrintPreview();
1047 if (preview)
c801d85f 1048 {
7bcb11d3
JS
1049 int currentPage = preview->GetCurrentPage();
1050 if ((preview->GetMinPage() > 0) &&
1051 (currentPage > preview->GetMinPage()) &&
1052 preview->GetPrintout()->HasPage(currentPage - 1))
1053 {
1054 preview->SetCurrentPage(currentPage - 1);
1055 }
c801d85f 1056 }
c801d85f
KB
1057}
1058
bf89b538
JS
1059void wxPreviewControlBar::OnFirst(void)
1060{
1061 wxPrintPreviewBase *preview = GetPrintPreview();
1062 if (preview)
1063 {
1064 int currentPage = preview->GetMinPage();
1065 if (preview->GetPrintout()->HasPage(currentPage))
1066 {
1067 preview->SetCurrentPage(currentPage);
1068 }
1069 }
1070}
1071
1072void wxPreviewControlBar::OnLast(void)
1073{
1074 wxPrintPreviewBase *preview = GetPrintPreview();
1075 if (preview)
1076 {
1077 int currentPage = preview->GetMaxPage();
1078 if (preview->GetPrintout()->HasPage(currentPage))
1079 {
1080 preview->SetCurrentPage(currentPage);
1081 }
1082 }
1083}
1084
1085void wxPreviewControlBar::OnGoto(void)
1086{
1087 wxPrintPreviewBase *preview = GetPrintPreview();
1088 if (preview)
1089 {
1090 long currentPage;
1091
1092 if (preview->GetMinPage() > 0)
1093 {
1094 wxString strPrompt;
1095 wxString strPage;
1096
d2b354f9 1097 strPrompt.Printf( _("Enter a page number between %d and %d:"),
bf89b538 1098 preview->GetMinPage(), preview->GetMaxPage());
7e99eddf 1099 strPage.Printf( wxT("%d"), preview->GetCurrentPage() );
bf89b538
JS
1100
1101 strPage =
d2b354f9 1102 wxGetTextFromUser( strPrompt, _("Goto Page"), strPage, GetParent());
bf89b538
JS
1103
1104 if ( strPage.ToLong( &currentPage ) )
1105 if (preview->GetPrintout()->HasPage(currentPage))
1106 {
1107 preview->SetCurrentPage(currentPage);
1108 }
1109 }
1110 }
1111}
1112
c801d85f
KB
1113void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event))
1114{
7bcb11d3
JS
1115 int zoom = GetZoomControl();
1116 if (GetPrintPreview())
1117 GetPrintPreview()->SetZoom(zoom);
c801d85f
KB
1118}
1119
34da0970 1120void wxPreviewControlBar::CreateButtons()
c801d85f 1121{
7bcb11d3 1122 SetSize(0, 0, 400, 40);
8826f46f 1123
9dff8515 1124 wxBoxSizer *item0 = new wxBoxSizer( wxHORIZONTAL );
e71fd398 1125
9dff8515
JS
1126 m_closeButton = new wxButton( this, wxID_PREVIEW_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
1127 item0->Add( m_closeButton, 0, wxALIGN_CENTRE|wxALL, 5 );
e71fd398 1128
7bcb11d3
JS
1129 if (m_buttonFlags & wxPREVIEW_PRINT)
1130 {
9dff8515
JS
1131 m_printButton = new wxButton( this, wxID_PREVIEW_PRINT, _("&Print..."), wxDefaultPosition, wxDefaultSize, 0 );
1132 item0->Add( m_printButton, 0, wxALIGN_CENTRE|wxALL, 5 );
7bcb11d3 1133 }
e71fd398 1134
892a76f7
JS
1135 // Exact-fit buttons are too tiny on wxUniversal
1136 int navButtonStyle;
1137 wxSize navButtonSize;
1138#ifdef __WXUNIVERSAL__
1139 navButtonStyle = 0;
2981fc83 1140 navButtonSize = wxSize(40, m_closeButton->GetSize().y);
892a76f7
JS
1141#else
1142 navButtonStyle = wxBU_EXACTFIT;
1143 navButtonSize = wxDefaultSize;
1144#endif
1145
bf89b538
JS
1146 if (m_buttonFlags & wxPREVIEW_FIRST)
1147 {
892a76f7 1148 m_firstPageButton = new wxButton( this, wxID_PREVIEW_FIRST, _("|<<"), wxDefaultPosition, navButtonSize, navButtonStyle );
9dff8515 1149 item0->Add( m_firstPageButton, 0, wxALIGN_CENTRE|wxALL, 5 );
bf89b538 1150 }
e71fd398 1151
7bcb11d3
JS
1152 if (m_buttonFlags & wxPREVIEW_PREVIOUS)
1153 {
892a76f7 1154 m_previousPageButton = new wxButton( this, wxID_PREVIEW_PREVIOUS, _("<<"), wxDefaultPosition, navButtonSize, navButtonStyle );
9dff8515 1155 item0->Add( m_previousPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 );
7bcb11d3 1156 }
e71fd398 1157
7bcb11d3
JS
1158 if (m_buttonFlags & wxPREVIEW_NEXT)
1159 {
892a76f7 1160 m_nextPageButton = new wxButton( this, wxID_PREVIEW_NEXT, _(">>"), wxDefaultPosition, navButtonSize, navButtonStyle );
9dff8515 1161 item0->Add( m_nextPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 );
bf89b538 1162 }
e71fd398 1163
bf89b538
JS
1164 if (m_buttonFlags & wxPREVIEW_LAST)
1165 {
892a76f7 1166 m_lastPageButton = new wxButton( this, wxID_PREVIEW_LAST, _(">>|"), wxDefaultPosition, navButtonSize, navButtonStyle );
9dff8515 1167 item0->Add( m_lastPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 );
bf89b538 1168 }
e71fd398 1169
bf89b538
JS
1170 if (m_buttonFlags & wxPREVIEW_GOTO)
1171 {
9dff8515
JS
1172 m_gotoPageButton = new wxButton( this, wxID_PREVIEW_GOTO, _("&Goto..."), wxDefaultPosition, wxDefaultSize, 0 );
1173 item0->Add( m_gotoPageButton, 0, wxALIGN_CENTRE|wxALL, 5 );
7bcb11d3 1174 }
e71fd398 1175
7bcb11d3
JS
1176 if (m_buttonFlags & wxPREVIEW_ZOOM)
1177 {
e71fd398 1178 wxString choices[] =
c25ccf85 1179 {
2b5f62a0 1180 wxT("10%"), wxT("15%"), wxT("20%"), wxT("25%"), wxT("30%"), wxT("35%"), wxT("40%"), wxT("45%"), wxT("50%"), wxT("55%"),
9dff8515
JS
1181 wxT("60%"), wxT("65%"), wxT("70%"), wxT("75%"), wxT("80%"), wxT("85%"), wxT("90%"), wxT("95%"), wxT("100%"), wxT("110%"),
1182 wxT("120%"), wxT("150%"), wxT("200%")
c25ccf85 1183 };
c25ccf85 1184 int n = WXSIZEOF(choices);
e71fd398 1185
7e548f6b 1186 m_zoomControl = new wxChoice( this, wxID_PREVIEW_ZOOM, wxDefaultPosition, wxSize(70,wxDefaultCoord), n, choices, 0 );
9dff8515 1187 item0->Add( m_zoomControl, 0, wxALIGN_CENTRE|wxALL, 5 );
7bcb11d3
JS
1188 SetZoomControl(m_printPreview->GetZoom());
1189 }
8826f46f 1190
9dff8515
JS
1191 SetSizer(item0);
1192 item0->Fit(this);
c801d85f
KB
1193}
1194
1195void wxPreviewControlBar::SetZoomControl(int zoom)
1196{
7bcb11d3 1197 if (m_zoomControl)
963907fa
RR
1198 {
1199 int n, count = m_zoomControl->GetCount();
1200 long val;
1201 for (n=0; n<count; n++)
1202 {
1203 if (m_zoomControl->GetString(n).BeforeFirst(wxT('%')).ToLong(&val) &&
1204 (val >= long(zoom)))
1205 {
1206 m_zoomControl->SetSelection(n);
1207 return;
1208 }
1209 }
7e548f6b 1210
963907fa
RR
1211 m_zoomControl->SetSelection(count-1);
1212 }
c801d85f
KB
1213}
1214
34da0970 1215int wxPreviewControlBar::GetZoomControl()
c801d85f 1216{
963907fa 1217 if (m_zoomControl && (m_zoomControl->GetStringSelection() != wxEmptyString))
7bcb11d3 1218 {
963907fa
RR
1219 long val;
1220 if (m_zoomControl->GetStringSelection().BeforeFirst(wxT('%')).ToLong(&val))
1221 return int(val);
7bcb11d3 1222 }
7e548f6b 1223
963907fa 1224 return 0;
c801d85f
KB
1225}
1226
1227
1228/*
7bcb11d3
JS
1229* Preview frame
1230*/
c801d85f 1231
e81e3883
RR
1232IMPLEMENT_CLASS(wxPreviewFrame, wxFrame)
1233
e3065973 1234BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame)
043c6705 1235 EVT_CHAR_HOOK(wxPreviewFrame::OnChar)
0f90ec93 1236 EVT_CLOSE(wxPreviewFrame::OnCloseWindow)
e3065973
JS
1237END_EVENT_TABLE()
1238
043c6705
VZ
1239void wxPreviewFrame::OnChar(wxKeyEvent &event)
1240{
1241 if ( event.GetKeyCode() == WXK_ESCAPE )
1242 {
1243 Close(true);
1244 }
1245 else
1246 {
1247 event.Skip();
1248 }
1249}
1250
a5ae8241 1251wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxWindow *parent, const wxString& title,
7bcb11d3 1252 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
7e548f6b 1253wxFrame(parent, wxID_ANY, title, pos, size, style, name)
c801d85f 1254{
7bcb11d3
JS
1255 m_printPreview = preview;
1256 m_controlBar = NULL;
1257 m_previewCanvas = NULL;
7c995553 1258 m_windowDisabler = NULL;
46b24ef9 1259
a5ae8241 1260 // Give the application icon
46b24ef9
JS
1261#ifdef __WXMSW__
1262 wxFrame* topFrame = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame);
1263 if (topFrame)
1264 SetIcon(topFrame->GetIcon());
e71fd398 1265#endif
c801d85f
KB
1266}
1267
34da0970 1268wxPreviewFrame::~wxPreviewFrame()
c801d85f
KB
1269{
1270}
1271
74e3313b 1272void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
c801d85f 1273{
7c995553
VZ
1274 if (m_windowDisabler)
1275 delete m_windowDisabler;
8826f46f 1276
7bcb11d3
JS
1277 // Need to delete the printout and the print preview
1278 wxPrintout *printout = m_printPreview->GetPrintout();
1279 if (printout)
1280 {
1281 delete printout;
1282 m_printPreview->SetPrintout(NULL);
1283 m_printPreview->SetCanvas(NULL);
1284 m_printPreview->SetFrame(NULL);
1285 }
b88bf073
VS
1286
1287 m_previewCanvas->SetPreview(NULL);
1288 wxDELETE(m_printPreview);
8826f46f 1289
7bcb11d3 1290 Destroy();
c801d85f
KB
1291}
1292
34da0970 1293void wxPreviewFrame::Initialize()
c801d85f 1294{
3080bf59 1295#if wxUSE_STATUSBAR
7bcb11d3 1296 CreateStatusBar();
3080bf59 1297#endif
7bcb11d3
JS
1298 CreateCanvas();
1299 CreateControlBar();
8826f46f 1300
7bcb11d3
JS
1301 m_printPreview->SetCanvas(m_previewCanvas);
1302 m_printPreview->SetFrame(this);
8826f46f 1303
9dff8515 1304 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
8826f46f 1305
9dff8515
JS
1306 item0->Add( m_controlBar, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );
1307 item0->Add( m_previewCanvas, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );
8826f46f 1308
7e548f6b 1309 SetAutoLayout( true );
9dff8515 1310 SetSizer( item0 );
8826f46f 1311
7c995553 1312 m_windowDisabler = new wxWindowDisabler(this);
8826f46f 1313
7bcb11d3 1314 Layout();
e71fd398 1315
d2b354f9
JS
1316 m_printPreview->AdjustScrollbars(m_previewCanvas);
1317 m_previewCanvas->SetFocus();
1318 m_controlBar->SetFocus();
c801d85f
KB
1319}
1320
34da0970 1321void wxPreviewFrame::CreateCanvas()
c801d85f 1322{
7bcb11d3 1323 m_previewCanvas = new wxPreviewCanvas(m_printPreview, this);
c801d85f
KB
1324}
1325
34da0970 1326void wxPreviewFrame::CreateControlBar()
c801d85f 1327{
7bcb11d3
JS
1328 long buttons = wxPREVIEW_DEFAULT;
1329 if (m_printPreview->GetPrintoutForPrinting())
1330 buttons |= wxPREVIEW_PRINT;
8826f46f 1331
c47addef 1332 m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0,0), wxSize(400, 40));
7bcb11d3 1333 m_controlBar->CreateButtons();
c801d85f 1334}
7bcb11d3 1335
c801d85f 1336/*
7bcb11d3
JS
1337* Print preview
1338*/
c801d85f 1339
891daf8c
RR
1340IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject)
1341
8826f46f
VZ
1342wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
1343 wxPrintout *printoutForPrinting,
1344 wxPrintData *data)
1345{
1346 if (data)
1347 m_printDialogData = (*data);
1348
1349 Init(printout, printoutForPrinting);
1350}
1351
1352wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout,
1353 wxPrintout *printoutForPrinting,
1354 wxPrintDialogData *data)
1355{
1356 if (data)
1357 m_printDialogData = (*data);
1358
1359 Init(printout, printoutForPrinting);
1360}
1361
1362void wxPrintPreviewBase::Init(wxPrintout *printout,
1363 wxPrintout *printoutForPrinting)
c801d85f 1364{
7e548f6b 1365 m_isOk = true;
7bcb11d3
JS
1366 m_previewPrintout = printout;
1367 if (m_previewPrintout)
7e548f6b 1368 m_previewPrintout->SetIsPreview(true);
8826f46f 1369
7bcb11d3 1370 m_printPrintout = printoutForPrinting;
8826f46f 1371
7bcb11d3
JS
1372 m_previewCanvas = NULL;
1373 m_previewFrame = NULL;
1374 m_previewBitmap = NULL;
1375 m_currentPage = 1;
c25ccf85 1376 m_currentZoom = 70;
7bcb11d3
JS
1377 m_topMargin = 40;
1378 m_leftMargin = 40;
1379 m_pageWidth = 0;
1380 m_pageHeight = 0;
7e548f6b 1381 m_printingPrepared = false;
d2b354f9
JS
1382 m_minPage = 1;
1383 m_maxPage = 1;
c801d85f
KB
1384}
1385
34da0970 1386wxPrintPreviewBase::~wxPrintPreviewBase()
c801d85f 1387{
7bcb11d3
JS
1388 if (m_previewPrintout)
1389 delete m_previewPrintout;
1390 if (m_previewBitmap)
1391 delete m_previewBitmap;
1392 if (m_printPrintout)
1393 delete m_printPrintout;
c801d85f
KB
1394}
1395
1396bool wxPrintPreviewBase::SetCurrentPage(int pageNum)
1397{
7bcb11d3 1398 if (m_currentPage == pageNum)
7e548f6b 1399 return true;
8826f46f 1400
7bcb11d3
JS
1401 m_currentPage = pageNum;
1402 if (m_previewBitmap)
1403 {
1404 delete m_previewBitmap;
1405 m_previewBitmap = NULL;
1406 }
e71fd398 1407
7bcb11d3
JS
1408 if (m_previewCanvas)
1409 {
d2b354f9 1410 AdjustScrollbars(m_previewCanvas);
e71fd398 1411
7bcb11d3 1412 m_previewCanvas->Refresh();
d2b354f9 1413 m_previewCanvas->SetFocus();
7bcb11d3 1414 }
7e548f6b 1415 return true;
c801d85f
KB
1416}
1417
383f6abd 1418int wxPrintPreviewBase::GetCurrentPage() const
259c43f6 1419 { return m_currentPage; }
383f6abd 1420void wxPrintPreviewBase::SetPrintout(wxPrintout *printout)
259c43f6 1421 { m_previewPrintout = printout; }
383f6abd 1422wxPrintout *wxPrintPreviewBase::GetPrintout() const
259c43f6 1423 { return m_previewPrintout; }
383f6abd 1424wxPrintout *wxPrintPreviewBase::GetPrintoutForPrinting() const
259c43f6 1425 { return m_printPrintout; }
383f6abd 1426void wxPrintPreviewBase::SetFrame(wxFrame *frame)
259c43f6 1427 { m_previewFrame = frame; }
383f6abd 1428void wxPrintPreviewBase::SetCanvas(wxPreviewCanvas *canvas)
259c43f6 1429 { m_previewCanvas = canvas; }
383f6abd 1430wxFrame *wxPrintPreviewBase::GetFrame() const
e81e3883 1431 { return m_previewFrame; }
383f6abd 1432wxPreviewCanvas *wxPrintPreviewBase::GetCanvas() const
e81e3883
RR
1433 { return m_previewCanvas; }
1434
f415cab9
JS
1435void wxPrintPreviewBase::CalcRects(wxPreviewCanvas *canvas, wxRect& pageRect, wxRect& paperRect)
1436{
1437 // Calculate the rectangles for the printable area of the page and the
1438 // entire paper as they appear on the canvas on-screen.
1439 int canvasWidth, canvasHeight;
1440 canvas->GetSize(&canvasWidth, &canvasHeight);
1441
1442 float zoomScale = float(m_currentZoom) / 100;
1443 float screenPrintableWidth = zoomScale * m_pageWidth * m_previewScaleX;
1444 float screenPrintableHeight = zoomScale * m_pageHeight * m_previewScaleY;
1445
1446 wxRect devicePaperRect = m_previewPrintout->GetPaperRectPixels();
1447 wxCoord devicePrintableWidth, devicePrintableHeight;
1448 m_previewPrintout->GetPageSizePixels(&devicePrintableWidth, &devicePrintableHeight);
1449 float scaleX = screenPrintableWidth / devicePrintableWidth;
1450 float scaleY = screenPrintableHeight / devicePrintableHeight;
1451 paperRect.width = wxCoord(scaleX * devicePaperRect.width);
1452 paperRect.height = wxCoord(scaleY * devicePaperRect.height);
1453
1454 paperRect.x = wxCoord((canvasWidth - paperRect.width)/ 2.0);
1455 if (paperRect.x < m_leftMargin)
1456 paperRect.x = m_leftMargin;
1457 paperRect.y = wxCoord((canvasHeight - paperRect.height)/ 2.0);
1458 if (paperRect.y < m_topMargin)
1459 paperRect.y = m_topMargin;
1460
1461 pageRect.x = paperRect.x - wxCoord(scaleX * devicePaperRect.x);
1462 pageRect.y = paperRect.y - wxCoord(scaleY * devicePaperRect.y);
1463 pageRect.width = wxCoord(screenPrintableWidth);
1464 pageRect.height = wxCoord(screenPrintableHeight);
1465}
1466
1467
b88bf073
VS
1468bool wxPrintPreviewBase::UpdatePageRendering()
1469{
1470 if ( m_previewBitmap )
1471 return false;
1472
1473 if ( !RenderPage(m_currentPage) )
1474 return false;
1475
1476 return true;
1477}
1478
d2b354f9 1479bool wxPrintPreviewBase::PaintPage(wxPreviewCanvas *canvas, wxDC& dc)
c801d85f 1480{
7bcb11d3 1481 DrawBlankPage(canvas, dc);
8826f46f 1482
7bcb11d3 1483 if (!m_previewBitmap)
7e548f6b 1484 return false;
7bcb11d3 1485 if (!canvas)
7e548f6b 1486 return false;
8826f46f 1487
f415cab9
JS
1488 wxRect pageRect, paperRect;
1489 CalcRects(canvas, pageRect, paperRect);
7bcb11d3
JS
1490 wxMemoryDC temp_dc;
1491 temp_dc.SelectObject(*m_previewBitmap);
8826f46f 1492
f415cab9
JS
1493 dc.Blit(pageRect.x, pageRect.y,
1494 m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0);
8826f46f 1495
7bcb11d3 1496 temp_dc.SelectObject(wxNullBitmap);
7e548f6b 1497 return true;
c801d85f
KB
1498}
1499
d2b354f9
JS
1500// Adjusts the scrollbars for the current scale
1501void wxPrintPreviewBase::AdjustScrollbars(wxPreviewCanvas *canvas)
1502{
1503 if (!canvas)
1504 return ;
1505
f415cab9
JS
1506 wxRect pageRect, paperRect;
1507 CalcRects(canvas, pageRect, paperRect);
1508 int totalWidth = paperRect.width + 2 * m_leftMargin;
1509 int totalHeight = paperRect.height + 2 * m_topMargin;
1510 int scrollUnitsX = totalWidth / 10;
1511 int scrollUnitsY = totalHeight / 10;
d2b354f9
JS
1512 wxSize virtualSize = canvas->GetVirtualSize();
1513 if (virtualSize.GetWidth() != totalWidth || virtualSize.GetHeight() != totalHeight)
7e548f6b 1514 canvas->SetScrollbars(10, 10, scrollUnitsX, scrollUnitsY, 0, 0, true);
d2b354f9
JS
1515}
1516
c801d85f
KB
1517bool wxPrintPreviewBase::RenderPage(int pageNum)
1518{
f6bcfd97
BP
1519 wxBusyCursor busy;
1520
7bcb11d3 1521 if (!m_previewCanvas)
c801d85f 1522 {
f6bcfd97 1523 wxFAIL_MSG(_T("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"));
7e548f6b 1524 return false;
c801d85f 1525 }
8826f46f 1526
f415cab9
JS
1527 wxRect pageRect, paperRect;
1528 CalcRects(m_previewCanvas, pageRect, paperRect);
8826f46f 1529
7bcb11d3
JS
1530 if (!m_previewBitmap)
1531 {
f415cab9
JS
1532 m_previewBitmap = new wxBitmap(pageRect.width, pageRect.height);
1533
7bcb11d3
JS
1534 if (!m_previewBitmap || !m_previewBitmap->Ok())
1535 {
9eee81a4 1536 if (m_previewBitmap) {
7bcb11d3 1537 delete m_previewBitmap;
9eee81a4
GD
1538 m_previewBitmap = NULL;
1539 }
7bcb11d3 1540 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK);
7e548f6b 1541 return false;
7bcb11d3
JS
1542 }
1543 }
8826f46f 1544
7bcb11d3
JS
1545 wxMemoryDC memoryDC;
1546 memoryDC.SelectObject(*m_previewBitmap);
8826f46f 1547
7bcb11d3 1548 memoryDC.Clear();
8826f46f 1549
7bcb11d3
JS
1550 m_previewPrintout->SetDC(&memoryDC);
1551 m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
8826f46f 1552
1044a386
JS
1553 // Need to delay OnPreparePrinting until here, so we have enough information.
1554 if (!m_printingPrepared)
1555 {
1556 m_previewPrintout->OnPreparePrinting();
d2b354f9
JS
1557 int selFrom, selTo;
1558 m_previewPrintout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo);
7e548f6b 1559 m_printingPrepared = true;
1044a386
JS
1560 }
1561
7bcb11d3 1562 m_previewPrintout->OnBeginPrinting();
c801d85f 1563
7bcb11d3
JS
1564 if (!m_previewPrintout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
1565 {
1566 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK);
8826f46f 1567
7bcb11d3 1568 memoryDC.SelectObject(wxNullBitmap);
8826f46f 1569
7bcb11d3 1570 delete m_previewBitmap;
9eee81a4 1571 m_previewBitmap = NULL;
7e548f6b 1572 return false;
7bcb11d3 1573 }
8826f46f 1574
7bcb11d3
JS
1575 m_previewPrintout->OnPrintPage(pageNum);
1576 m_previewPrintout->OnEndDocument();
1577 m_previewPrintout->OnEndPrinting();
8826f46f 1578
7bcb11d3 1579 m_previewPrintout->SetDC(NULL);
8826f46f 1580
c801d85f 1581 memoryDC.SelectObject(wxNullBitmap);
8826f46f 1582
3080bf59
VZ
1583#if wxUSE_STATUSBAR
1584 wxString status;
7bcb11d3 1585 if (m_maxPage != 0)
7e548f6b 1586 status = wxString::Format(_("Page %d of %d"), pageNum, m_maxPage);
7bcb11d3 1587 else
7e548f6b 1588 status = wxString::Format(_("Page %d"), pageNum);
8826f46f 1589
7bcb11d3 1590 if (m_previewFrame)
3080bf59
VZ
1591 m_previewFrame->SetStatusText(status);
1592#endif
8826f46f 1593
7e548f6b 1594 return true;
c801d85f
KB
1595}
1596
d2b354f9 1597bool wxPrintPreviewBase::DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc)
c801d85f 1598{
f415cab9 1599 wxRect pageRect, paperRect;
8826f46f 1600
f415cab9 1601 CalcRects(canvas, pageRect, paperRect);
8826f46f 1602
f415cab9
JS
1603 // Draw shadow, allowing for 1-pixel border AROUND the actual paper
1604 wxCoord shadowOffset = 4;
8826f46f 1605
7bcb11d3
JS
1606 dc.SetPen(*wxBLACK_PEN);
1607 dc.SetBrush(*wxBLACK_BRUSH);
f415cab9
JS
1608 dc.DrawRectangle(paperRect.x + shadowOffset, paperRect.y + paperRect.height + 1,
1609 paperRect.width, shadowOffset);
1610
1611 dc.DrawRectangle(paperRect.x + paperRect.width, paperRect.y + shadowOffset,
1612 shadowOffset, paperRect.height);
8826f46f 1613
f415cab9 1614 // Draw blank page allowing for 1-pixel border AROUND the actual paper
7bcb11d3
JS
1615 dc.SetPen(*wxBLACK_PEN);
1616 dc.SetBrush(*wxWHITE_BRUSH);
f415cab9
JS
1617 dc.DrawRectangle(paperRect.x - 2, paperRect.y - 1,
1618 paperRect.width + 3, paperRect.height + 2);
8826f46f 1619
7e548f6b 1620 return true;
2a47d3c1
JS
1621}
1622
7bcb11d3 1623void wxPrintPreviewBase::SetZoom(int percent)
2a47d3c1 1624{
7bcb11d3
JS
1625 if (m_currentZoom == percent)
1626 return;
8826f46f 1627
7bcb11d3
JS
1628 m_currentZoom = percent;
1629 if (m_previewBitmap)
1630 {
1631 delete m_previewBitmap;
1632 m_previewBitmap = NULL;
1633 }
aff37a19 1634
7bcb11d3
JS
1635 if (m_previewCanvas)
1636 {
d2b354f9 1637 AdjustScrollbars(m_previewCanvas);
95724b1a 1638 ((wxScrolledWindow *) m_previewCanvas)->Scroll(0, 0);
e71fd398 1639 m_previewCanvas->ClearBackground();
7bcb11d3 1640 m_previewCanvas->Refresh();
d2b354f9 1641 m_previewCanvas->SetFocus();
7bcb11d3 1642 }
2a47d3c1
JS
1643}
1644
383f6abd
WS
1645wxPrintDialogData& wxPrintPreviewBase::GetPrintDialogData()
1646{
e81e3883
RR
1647 return m_printDialogData;
1648}
1649
383f6abd 1650int wxPrintPreviewBase::GetZoom() const
e81e3883 1651{ return m_currentZoom; }
383f6abd 1652int wxPrintPreviewBase::GetMaxPage() const
e81e3883 1653{ return m_maxPage; }
383f6abd 1654int wxPrintPreviewBase::GetMinPage() const
e81e3883 1655{ return m_minPage; }
b7cacb43 1656bool wxPrintPreviewBase::IsOk() const
e81e3883 1657{ return m_isOk; }
383f6abd 1658void wxPrintPreviewBase::SetOk(bool ok)
e81e3883 1659{ m_isOk = ok; }
f415cab9 1660
e81e3883
RR
1661//----------------------------------------------------------------------------
1662// wxPrintPreview
1663//----------------------------------------------------------------------------
1664
1665IMPLEMENT_CLASS(wxPrintPreview, wxPrintPreviewBase)
1666
1667wxPrintPreview::wxPrintPreview(wxPrintout *printout,
1668 wxPrintout *printoutForPrinting,
1669 wxPrintDialogData *data) :
1670 wxPrintPreviewBase( printout, printoutForPrinting, data )
1671{
1672 m_pimpl = wxPrintFactory::GetFactory()->
1673 CreatePrintPreview( printout, printoutForPrinting, data );
1674}
1675
1676wxPrintPreview::wxPrintPreview(wxPrintout *printout,
1677 wxPrintout *printoutForPrinting,
1678 wxPrintData *data ) :
1679 wxPrintPreviewBase( printout, printoutForPrinting, data )
1680{
1681 m_pimpl = wxPrintFactory::GetFactory()->
1682 CreatePrintPreview( printout, printoutForPrinting, data );
1683}
1684
1685wxPrintPreview::~wxPrintPreview()
1686{
1687 delete m_pimpl;
383f6abd 1688
e81e3883
RR
1689 // don't delete twice
1690 m_printPrintout = NULL;
1691 m_previewPrintout = NULL;
1692 m_previewBitmap = NULL;
1693}
1694
1695bool wxPrintPreview::SetCurrentPage(int pageNum)
1696{
1697 return m_pimpl->SetCurrentPage( pageNum );
1698}
1699
383f6abd
WS
1700int wxPrintPreview::GetCurrentPage() const
1701{
e81e3883
RR
1702 return m_pimpl->GetCurrentPage();
1703}
1704
383f6abd
WS
1705void wxPrintPreview::SetPrintout(wxPrintout *printout)
1706{
e81e3883
RR
1707 m_pimpl->SetPrintout( printout );
1708}
1709
383f6abd
WS
1710wxPrintout *wxPrintPreview::GetPrintout() const
1711{
e81e3883
RR
1712 return m_pimpl->GetPrintout();
1713}
1714
383f6abd
WS
1715wxPrintout *wxPrintPreview::GetPrintoutForPrinting() const
1716{
e81e3883
RR
1717 return m_pimpl->GetPrintoutForPrinting();
1718}
1719
383f6abd
WS
1720void wxPrintPreview::SetFrame(wxFrame *frame)
1721{
e81e3883
RR
1722 m_pimpl->SetFrame( frame );
1723}
1724
383f6abd
WS
1725void wxPrintPreview::SetCanvas(wxPreviewCanvas *canvas)
1726{
e81e3883
RR
1727 m_pimpl->SetCanvas( canvas );
1728}
1729
383f6abd 1730wxFrame *wxPrintPreview::GetFrame() const
e81e3883
RR
1731{
1732 return m_pimpl->GetFrame();
1733}
1734
383f6abd
WS
1735wxPreviewCanvas *wxPrintPreview::GetCanvas() const
1736{
e81e3883
RR
1737 return m_pimpl->GetCanvas();
1738}
1739
1740bool wxPrintPreview::PaintPage(wxPreviewCanvas *canvas, wxDC& dc)
1741{
1742 return m_pimpl->PaintPage( canvas, dc );
1743}
1744
b88bf073
VS
1745bool wxPrintPreview::UpdatePageRendering()
1746{
1747 return m_pimpl->UpdatePageRendering();
1748}
1749
e81e3883
RR
1750bool wxPrintPreview::DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc)
1751{
1752 return m_pimpl->DrawBlankPage( canvas, dc );
1753}
1754
1755void wxPrintPreview::AdjustScrollbars(wxPreviewCanvas *canvas)
1756{
1757 m_pimpl->AdjustScrollbars( canvas );
1758}
1759
1760bool wxPrintPreview::RenderPage(int pageNum)
1761{
1762 return m_pimpl->RenderPage( pageNum );
1763}
1764
1765void wxPrintPreview::SetZoom(int percent)
1766{
1767 m_pimpl->SetZoom( percent );
1768}
1769
d8766675
JS
1770int wxPrintPreview::GetZoom() const
1771{
1772 return m_pimpl->GetZoom();
1773}
1774
e81e3883
RR
1775wxPrintDialogData& wxPrintPreview::GetPrintDialogData()
1776{
1777 return m_pimpl->GetPrintDialogData();
1778}
1779
1780int wxPrintPreview::GetMaxPage() const
1781{
1782 return m_pimpl->GetMaxPage();
1783}
1784
1785int wxPrintPreview::GetMinPage() const
1786{
1787 return m_pimpl->GetMinPage();
1788}
1789
b7cacb43 1790bool wxPrintPreview::IsOk() const
e81e3883
RR
1791{
1792 return m_pimpl->Ok();
1793}
1794
1795void wxPrintPreview::SetOk(bool ok)
1796{
1797 m_pimpl->SetOk( ok );
1798}
1799
1800bool wxPrintPreview::Print(bool interactive)
1801{
1802 return m_pimpl->Print( interactive );
1803}
1804
1805void wxPrintPreview::DetermineScaling()
1806{
1807 m_pimpl->DetermineScaling();
1808}
1809
d427503c 1810#endif // wxUSE_PRINTING_ARCHITECTURE