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