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