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