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