]>
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 | ||
f415cab9 JS |
569 | void wxPrintout::FitThisSizeToPaper(const wxSize& imageSize) |
570 | { | |
571 | // Set the DC scale and origin so that the given image size fits within the | |
572 | // entire page and the origin is at the top left corner of the page. Note | |
573 | // that with most printers, portions of the page will be non-printable. Use | |
574 | // this if you're managing your own page margins. | |
575 | if (!m_printoutDC) return; | |
576 | wxRect paperRect = GetPaperRectPixels(); | |
577 | wxCoord pw, ph; | |
578 | GetPageSizePixels(&pw, &ph); | |
579 | wxCoord w, h; | |
580 | m_printoutDC->GetSize(&w, &h); | |
581 | float scaleX = ((float(paperRect.width) * w) / (float(pw) * imageSize.x)); | |
582 | float scaleY = ((float(paperRect.height) * h) / (float(ph) * imageSize.y)); | |
583 | float actualScale = wxMin(scaleX, scaleY); | |
584 | m_printoutDC->SetUserScale(actualScale, actualScale); | |
585 | m_printoutDC->SetDeviceOrigin(0, 0); | |
586 | wxRect logicalPaperRect = GetLogicalPaperRect(); | |
587 | SetLogicalOrigin(logicalPaperRect.x, logicalPaperRect.y); | |
588 | } | |
589 | ||
590 | void wxPrintout::FitThisSizeToPage(const wxSize& imageSize) | |
591 | { | |
592 | // Set the DC scale and origin so that the given image size fits within the | |
593 | // printable area of the page and the origin is at the top left corner of | |
594 | // the printable area. | |
595 | if (!m_printoutDC) return; | |
596 | int w, h; | |
597 | m_printoutDC->GetSize(&w, &h); | |
598 | float scaleX = float(w) / imageSize.x; | |
599 | float scaleY = float(h) / imageSize.y; | |
600 | float actualScale = wxMin(scaleX, scaleY); | |
601 | m_printoutDC->SetUserScale(actualScale, actualScale); | |
602 | m_printoutDC->SetDeviceOrigin(0, 0); | |
603 | } | |
604 | ||
605 | void wxPrintout::FitThisSizeToPageMargins(const wxSize& imageSize, const wxPageSetupDialogData& pageSetupData) | |
606 | { | |
607 | // Set the DC scale and origin so that the given image size fits within the | |
608 | // page margins defined in the given wxPageSetupDialogData object and the | |
609 | // origin is at the top left corner of the page margins. | |
610 | if (!m_printoutDC) return; | |
611 | wxRect paperRect = GetPaperRectPixels(); | |
612 | wxCoord pw, ph; | |
613 | GetPageSizePixels(&pw, &ph); | |
614 | wxPoint topLeft = pageSetupData.GetMarginTopLeft(); | |
615 | wxPoint bottomRight = pageSetupData.GetMarginBottomRight(); | |
616 | wxCoord mw, mh; | |
617 | GetPageSizeMM(&mw, &mh); | |
618 | float mmToDeviceX = float(pw) / mw; | |
619 | float mmToDeviceY = float(ph) / mh; | |
6445acc7 JS |
620 | wxRect pageMarginsRect(paperRect.x + wxCoordRound(mmToDeviceX * topLeft.x), |
621 | paperRect.y + wxCoordRound(mmToDeviceY * topLeft.y), | |
622 | paperRect.width - wxCoordRound(mmToDeviceX * (topLeft.x + bottomRight.x)), | |
623 | paperRect.height - wxCoordRound(mmToDeviceY * (topLeft.y + bottomRight.y))); | |
f415cab9 JS |
624 | wxCoord w, h; |
625 | m_printoutDC->GetSize(&w, &h); | |
626 | float scaleX = (float(pageMarginsRect.width) * w) / (float(pw) * imageSize.x); | |
627 | float scaleY = (float(pageMarginsRect.height) * h) / (float(ph) * imageSize.y); | |
628 | float actualScale = wxMin(scaleX, scaleY); | |
629 | m_printoutDC->SetUserScale(actualScale, actualScale); | |
630 | m_printoutDC->SetDeviceOrigin(0, 0); | |
631 | wxRect logicalPageMarginsRect = GetLogicalPageMarginsRect(pageSetupData); | |
632 | SetLogicalOrigin(logicalPageMarginsRect.x, logicalPageMarginsRect.y); | |
633 | } | |
634 | ||
635 | void wxPrintout::MapScreenSizeToPaper() | |
636 | { | |
637 | // Set the DC scale so that an image on the screen is the same size on the | |
638 | // paper and the origin is at the top left of the paper. Note that with most | |
639 | // printers, portions of the page will be cut off. Use this if you're | |
640 | // managing your own page margins. | |
641 | if (!m_printoutDC) return; | |
642 | MapScreenSizeToPage(); | |
643 | wxRect logicalPaperRect = GetLogicalPaperRect(); | |
644 | SetLogicalOrigin(logicalPaperRect.x, logicalPaperRect.y); | |
645 | } | |
646 | ||
647 | void wxPrintout::MapScreenSizeToPage() | |
648 | { | |
649 | // Set the DC scale and origin so that an image on the screen is the same | |
650 | // size on the paper and the origin is at the top left of the printable area. | |
651 | if (!m_printoutDC) return; | |
652 | int ppiScreenX, ppiScreenY; | |
653 | GetPPIScreen(&ppiScreenX, &ppiScreenY); | |
654 | int ppiPrinterX, ppiPrinterY; | |
655 | GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); | |
656 | int w, h; | |
657 | m_printoutDC->GetSize(&w, &h); | |
658 | int pageSizePixelsX, pageSizePixelsY; | |
659 | GetPageSizePixels(&pageSizePixelsX, &pageSizePixelsY); | |
660 | float userScaleX = (float(ppiPrinterX) * w) / (float(ppiScreenX) * pageSizePixelsX); | |
661 | float userScaleY = (float(ppiPrinterY) * h) / (float(ppiScreenY) * pageSizePixelsY); | |
662 | m_printoutDC->SetUserScale(userScaleX, userScaleY); | |
663 | m_printoutDC->SetDeviceOrigin(0, 0); | |
664 | } | |
665 | ||
666 | void wxPrintout::MapScreenSizeToPageMargins(const wxPageSetupDialogData& pageSetupData) | |
667 | { | |
668 | // Set the DC scale so that an image on the screen is the same size on the | |
669 | // paper and the origin is at the top left of the page margins defined by | |
670 | // the given wxPageSetupDialogData object. | |
671 | if (!m_printoutDC) return; | |
672 | MapScreenSizeToPage(); | |
673 | wxRect logicalPageMarginsRect = GetLogicalPageMarginsRect(pageSetupData); | |
674 | SetLogicalOrigin(logicalPageMarginsRect.x, logicalPageMarginsRect.y); | |
675 | } | |
676 | ||
677 | void wxPrintout::MapScreenSizeToDevice() | |
678 | { | |
679 | // Set the DC scale so that a screen pixel is the same size as a device | |
680 | // pixel and the origin is at the top left of the printable area. | |
681 | if (!m_printoutDC) return; | |
682 | int w, h; | |
683 | m_printoutDC->GetSize(&w, &h); | |
684 | int pageSizePixelsX, pageSizePixelsY; | |
685 | GetPageSizePixels(&pageSizePixelsX, &pageSizePixelsY); | |
686 | float userScaleX = float(w) / pageSizePixelsX; | |
687 | float userScaleY = float(h) / pageSizePixelsY; | |
688 | m_printoutDC->SetUserScale(userScaleX, userScaleY); | |
689 | m_printoutDC->SetDeviceOrigin(0, 0); | |
690 | } | |
691 | ||
692 | wxRect wxPrintout::GetLogicalPaperRect() const | |
693 | { | |
694 | // Return the rectangle in logical units that corresponds to the paper | |
695 | // rectangle. | |
696 | wxRect paperRect = GetPaperRectPixels(); | |
697 | wxCoord pw, ph; | |
698 | GetPageSizePixels(&pw, &ph); | |
699 | wxCoord w, h; | |
700 | m_printoutDC->GetSize(&w, &h); | |
701 | if (w == pw && h == ph) { | |
702 | // this DC matches the printed page, so no scaling | |
703 | return wxRect(m_printoutDC->DeviceToLogicalX(paperRect.x), | |
704 | m_printoutDC->DeviceToLogicalY(paperRect.y), | |
705 | m_printoutDC->DeviceToLogicalXRel(paperRect.width), | |
706 | m_printoutDC->DeviceToLogicalYRel(paperRect.height)); | |
707 | } | |
708 | // This DC doesn't match the printed page, so we have to scale. | |
709 | float scaleX = float(w) / pw; | |
710 | float scaleY = float(h) / ph; | |
6445acc7 JS |
711 | return wxRect(m_printoutDC->DeviceToLogicalX(wxCoordRound(paperRect.x * scaleX)), |
712 | m_printoutDC->DeviceToLogicalY(wxCoordRound(paperRect.y * scaleY)), | |
713 | m_printoutDC->DeviceToLogicalXRel(wxCoordRound(paperRect.width * scaleX)), | |
714 | m_printoutDC->DeviceToLogicalYRel(wxCoordRound(paperRect.height * scaleY))); | |
f415cab9 JS |
715 | } |
716 | ||
717 | wxRect wxPrintout::GetLogicalPageRect() const | |
718 | { | |
719 | // Return the rectangle in logical units that corresponds to the printable | |
720 | // area. | |
721 | int w, h; | |
722 | m_printoutDC->GetSize(&w, &h); | |
723 | return wxRect(m_printoutDC->DeviceToLogicalX(0), | |
724 | m_printoutDC->DeviceToLogicalY(0), | |
725 | m_printoutDC->DeviceToLogicalXRel(w), | |
726 | m_printoutDC->DeviceToLogicalYRel(h)); | |
727 | } | |
728 | ||
729 | wxRect wxPrintout::GetLogicalPageMarginsRect(const wxPageSetupDialogData& pageSetupData) const | |
730 | { | |
731 | // Return the rectangle in logical units that corresponds to the region | |
732 | // within the page margins as specified by the given wxPageSetupDialogData | |
733 | // object. | |
734 | wxRect paperRect = GetPaperRectPixels(); | |
735 | wxCoord pw, ph; | |
736 | GetPageSizePixels(&pw, &ph); | |
737 | wxPoint topLeft = pageSetupData.GetMarginTopLeft(); | |
738 | wxPoint bottomRight = pageSetupData.GetMarginBottomRight(); | |
739 | wxCoord mw, mh; | |
740 | GetPageSizeMM(&mw, &mh); | |
741 | float mmToDeviceX = float(pw) / mw; | |
742 | float mmToDeviceY = float(ph) / mh; | |
6445acc7 JS |
743 | wxRect pageMarginsRect(paperRect.x + wxCoordRound(mmToDeviceX * topLeft.x), |
744 | paperRect.y + wxCoordRound(mmToDeviceY * topLeft.y), | |
745 | paperRect.width - wxCoordRound(mmToDeviceX * (topLeft.x + bottomRight.x)), | |
746 | paperRect.height - wxCoordRound(mmToDeviceY * (topLeft.y + bottomRight.y))); | |
f415cab9 JS |
747 | wxCoord w, h; |
748 | m_printoutDC->GetSize(&w, &h); | |
749 | if (w == pw && h == ph) { | |
750 | // this DC matches the printed page, so no scaling | |
751 | return wxRect(m_printoutDC->DeviceToLogicalX(pageMarginsRect.x), | |
752 | m_printoutDC->DeviceToLogicalY(pageMarginsRect.y), | |
753 | m_printoutDC->DeviceToLogicalXRel(pageMarginsRect.width), | |
754 | m_printoutDC->DeviceToLogicalYRel(pageMarginsRect.height)); | |
755 | } | |
756 | // This DC doesn't match the printed page, so we have to scale. | |
757 | float scaleX = float(w) / pw; | |
758 | float scaleY = float(h) / ph; | |
6445acc7 JS |
759 | return wxRect(m_printoutDC->DeviceToLogicalX(wxCoordRound(pageMarginsRect.x * scaleX)), |
760 | m_printoutDC->DeviceToLogicalY(wxCoordRound(pageMarginsRect.y * scaleY)), | |
761 | m_printoutDC->DeviceToLogicalXRel(wxCoordRound(pageMarginsRect.width * scaleX)), | |
762 | m_printoutDC->DeviceToLogicalYRel(wxCoordRound(pageMarginsRect.height * scaleY))); | |
f415cab9 JS |
763 | } |
764 | ||
765 | void wxPrintout::SetLogicalOrigin(wxCoord x, wxCoord y) | |
766 | { | |
767 | // Set the device origin by specifying a point in logical coordinates. | |
768 | m_printoutDC->SetDeviceOrigin(m_printoutDC->LogicalToDeviceX(x), | |
769 | m_printoutDC->LogicalToDeviceY(y)); | |
770 | } | |
771 | ||
772 | void wxPrintout::OffsetLogicalOrigin(wxCoord xoff, wxCoord yoff) | |
773 | { | |
774 | // Offset the device origin by a specified distance in device coordinates. | |
775 | wxCoord x = m_printoutDC->LogicalToDeviceX(0); | |
776 | wxCoord y = m_printoutDC->LogicalToDeviceY(0); | |
777 | m_printoutDC->SetDeviceOrigin(x + m_printoutDC->LogicalToDeviceXRel(xoff), | |
778 | y + m_printoutDC->LogicalToDeviceYRel(yoff)); | |
779 | } | |
780 | ||
781 | ||
e81e3883 RR |
782 | //---------------------------------------------------------------------------- |
783 | // wxPreviewCanvas | |
784 | //---------------------------------------------------------------------------- | |
785 | ||
786 | IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow) | |
787 | ||
788 | BEGIN_EVENT_TABLE(wxPreviewCanvas, wxScrolledWindow) | |
789 | EVT_PAINT(wxPreviewCanvas::OnPaint) | |
790 | EVT_CHAR(wxPreviewCanvas::OnChar) | |
791 | EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged) | |
fb6efdf2 VZ |
792 | #if wxUSE_MOUSEWHEEL |
793 | EVT_MOUSEWHEEL(wxPreviewCanvas::OnMouseWheel) | |
794 | #endif | |
e81e3883 | 795 | END_EVENT_TABLE() |
7bcb11d3 | 796 | |
e9cafd42 VZ |
797 | // VZ: the current code doesn't refresh properly without |
798 | // wxFULL_REPAINT_ON_RESIZE, this must be fixed as otherwise we have | |
799 | // really horrible flicker when resizing the preview frame, but without | |
800 | // this style it simply doesn't work correctly at all... | |
c801d85f | 801 | wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent, |
7bcb11d3 | 802 | const wxPoint& pos, const wxSize& size, long style, const wxString& name): |
7e548f6b | 803 | wxScrolledWindow(parent, wxID_ANY, pos, size, style | wxFULL_REPAINT_ON_RESIZE, name) |
c801d85f | 804 | { |
7bcb11d3 | 805 | m_printPreview = preview; |
46b24ef9 JS |
806 | #ifdef __WXMAC__ |
807 | // The app workspace colour is always white, but we should have | |
808 | // a contrast with the page. | |
ca5020c2 | 809 | wxSystemColour colourIndex = wxSYS_COLOUR_3DDKSHADOW; |
92b799e0 JS |
810 | #elif defined(__WXGTK__) |
811 | wxSystemColour colourIndex = wxSYS_COLOUR_BTNFACE; | |
46b24ef9 JS |
812 | #else |
813 | wxSystemColour colourIndex = wxSYS_COLOUR_APPWORKSPACE; | |
e71fd398 | 814 | #endif |
46b24ef9 | 815 | SetBackgroundColour(wxSystemSettings::GetColour(colourIndex)); |
8826f46f | 816 | |
d2b354f9 | 817 | SetScrollbars(10, 10, 100, 100); |
c801d85f KB |
818 | } |
819 | ||
34da0970 | 820 | wxPreviewCanvas::~wxPreviewCanvas() |
c801d85f KB |
821 | { |
822 | } | |
823 | ||
824 | void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
825 | { | |
7bcb11d3 JS |
826 | wxPaintDC dc(this); |
827 | PrepareDC( dc ); | |
8826f46f | 828 | |
a56fcaaf | 829 | /* |
809934d2 RR |
830 | #ifdef __WXGTK__ |
831 | if (!GetUpdateRegion().IsEmpty()) | |
832 | dc.SetClippingRegion( GetUpdateRegion() ); | |
833 | #endif | |
a56fcaaf | 834 | */ |
809934d2 | 835 | |
7bcb11d3 JS |
836 | if (m_printPreview) |
837 | { | |
838 | m_printPreview->PaintPage(this, dc); | |
839 | } | |
c801d85f KB |
840 | } |
841 | ||
842 | // Responds to colour changes, and passes event on to children. | |
843 | void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event) | |
844 | { | |
46b24ef9 JS |
845 | #ifdef __WXMAC__ |
846 | // The app workspace colour is always white, but we should have | |
847 | // a contrast with the page. | |
ca5020c2 | 848 | wxSystemColour colourIndex = wxSYS_COLOUR_3DDKSHADOW; |
92b799e0 JS |
849 | #elif defined(__WXGTK__) |
850 | wxSystemColour colourIndex = wxSYS_COLOUR_BTNFACE; | |
46b24ef9 JS |
851 | #else |
852 | wxSystemColour colourIndex = wxSYS_COLOUR_APPWORKSPACE; | |
e71fd398 | 853 | #endif |
46b24ef9 | 854 | SetBackgroundColour(wxSystemSettings::GetColour(colourIndex)); |
7bcb11d3 | 855 | Refresh(); |
8826f46f | 856 | |
7bcb11d3 JS |
857 | // Propagate the event to the non-top-level children |
858 | wxWindow::OnSysColourChanged(event); | |
c801d85f KB |
859 | } |
860 | ||
d2b354f9 JS |
861 | void wxPreviewCanvas::OnChar(wxKeyEvent &event) |
862 | { | |
b38b0d22 | 863 | wxPreviewControlBar* controlBar = ((wxPreviewFrame*) GetParent())->GetControlBar(); |
d2b354f9 JS |
864 | if (event.GetKeyCode() == WXK_ESCAPE) |
865 | { | |
7e548f6b | 866 | ((wxPreviewFrame*) GetParent())->Close(true); |
d2b354f9 | 867 | return; |
e71fd398 | 868 | } |
b38b0d22 JS |
869 | else if (event.GetKeyCode() == WXK_TAB) |
870 | { | |
871 | controlBar->OnGoto(); | |
872 | return; | |
d2b354f9 | 873 | } |
b38b0d22 JS |
874 | else if (event.GetKeyCode() == WXK_RETURN) |
875 | { | |
876 | controlBar->OnPrint(); | |
877 | return; | |
878 | } | |
879 | ||
d2b354f9 JS |
880 | if (!event.ControlDown()) |
881 | { | |
882 | event.Skip(); | |
883 | return; | |
884 | } | |
e71fd398 | 885 | |
b38b0d22 JS |
886 | switch(event.GetKeyCode()) |
887 | { | |
faa94f3e | 888 | case WXK_PAGEDOWN: |
b38b0d22 | 889 | controlBar->OnNext(); break; |
faa94f3e | 890 | case WXK_PAGEUP: |
b38b0d22 JS |
891 | controlBar->OnPrevious(); break; |
892 | case WXK_HOME: | |
893 | controlBar->OnFirst(); break; | |
894 | case WXK_END: | |
895 | controlBar->OnLast(); break; | |
896 | default: | |
897 | event.Skip(); | |
898 | } | |
d2b354f9 JS |
899 | } |
900 | ||
fb6efdf2 VZ |
901 | #if wxUSE_MOUSEWHEEL |
902 | ||
903 | void wxPreviewCanvas::OnMouseWheel(wxMouseEvent& event) | |
904 | { | |
905 | wxPreviewControlBar * | |
906 | controlBar = wxStaticCast(GetParent(), wxPreviewFrame)->GetControlBar(); | |
907 | ||
908 | if ( controlBar ) | |
909 | { | |
910 | if ( event.ControlDown() && event.GetWheelRotation() != 0 ) | |
911 | { | |
912 | int currentZoom = controlBar->GetZoomControl(); | |
913 | ||
914 | int delta; | |
915 | if ( currentZoom < 100 ) | |
916 | delta = 5; | |
917 | else if ( currentZoom <= 120 ) | |
918 | delta = 10; | |
919 | else | |
920 | delta = 50; | |
921 | ||
922 | if ( event.GetWheelRotation() > 0 ) | |
923 | delta = -delta; | |
924 | ||
925 | int newZoom = currentZoom + delta; | |
926 | if ( newZoom < 10 ) | |
927 | newZoom = 10; | |
928 | if ( newZoom > 200 ) | |
929 | newZoom = 200; | |
930 | if ( newZoom != currentZoom ) | |
931 | { | |
932 | controlBar->SetZoomControl(newZoom); | |
933 | m_printPreview->SetZoom(newZoom); | |
934 | Refresh(); | |
935 | } | |
936 | return; | |
937 | } | |
938 | } | |
939 | ||
940 | event.Skip(); | |
941 | } | |
942 | ||
943 | #endif // wxUSE_MOUSEWHEEL | |
944 | ||
e81e3883 RR |
945 | //---------------------------------------------------------------------------- |
946 | // wxPreviewControlBar | |
947 | //---------------------------------------------------------------------------- | |
948 | ||
949 | IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow) | |
c801d85f KB |
950 | |
951 | BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel) | |
8826f46f | 952 | EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnWindowClose) |
90b6b974 | 953 | EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrintButton) |
0f90ec93 KB |
954 | EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPreviousButton) |
955 | EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNextButton) | |
bf89b538 JS |
956 | EVT_BUTTON(wxID_PREVIEW_FIRST, wxPreviewControlBar::OnFirstButton) |
957 | EVT_BUTTON(wxID_PREVIEW_LAST, wxPreviewControlBar::OnLastButton) | |
958 | EVT_BUTTON(wxID_PREVIEW_GOTO, wxPreviewControlBar::OnGotoButton) | |
8826f46f VZ |
959 | EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom) |
960 | EVT_PAINT(wxPreviewControlBar::OnPaint) | |
c801d85f | 961 | END_EVENT_TABLE() |
7bcb11d3 | 962 | |
c801d85f | 963 | wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons, |
7bcb11d3 JS |
964 | wxWindow *parent, const wxPoint& pos, const wxSize& size, |
965 | long style, const wxString& name): | |
7e548f6b | 966 | wxPanel(parent, wxID_ANY, pos, size, style, name) |
c801d85f | 967 | { |
7bcb11d3 JS |
968 | m_printPreview = preview; |
969 | m_closeButton = (wxButton *) NULL; | |
970 | m_nextPageButton = (wxButton *) NULL; | |
971 | m_previousPageButton = (wxButton *) NULL; | |
972 | m_printButton = (wxButton *) NULL; | |
973 | m_zoomControl = (wxChoice *) NULL; | |
974 | m_buttonFlags = buttons; | |
c801d85f KB |
975 | } |
976 | ||
34da0970 | 977 | wxPreviewControlBar::~wxPreviewControlBar() |
c801d85f KB |
978 | { |
979 | } | |
980 | ||
981 | void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
982 | { | |
7bcb11d3 | 983 | wxPaintDC dc(this); |
8826f46f | 984 | |
7bcb11d3 JS |
985 | int w, h; |
986 | GetSize(&w, &h); | |
987 | dc.SetPen(*wxBLACK_PEN); | |
988 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
989 | dc.DrawLine( 0, h-1, w, h-1 ); | |
c801d85f KB |
990 | } |
991 | ||
c330a2cf | 992 | void wxPreviewControlBar::OnWindowClose(wxCommandEvent& WXUNUSED(event)) |
c801d85f | 993 | { |
7bcb11d3 | 994 | wxPreviewFrame *frame = (wxPreviewFrame *)GetParent(); |
7e548f6b | 995 | frame->Close(true); |
c801d85f KB |
996 | } |
997 | ||
b38b0d22 | 998 | void wxPreviewControlBar::OnPrint(void) |
c801d85f | 999 | { |
7bcb11d3 | 1000 | wxPrintPreviewBase *preview = GetPrintPreview(); |
7e548f6b | 1001 | preview->Print(true); |
c801d85f KB |
1002 | } |
1003 | ||
0f90ec93 | 1004 | void wxPreviewControlBar::OnNext(void) |
c801d85f | 1005 | { |
7bcb11d3 JS |
1006 | wxPrintPreviewBase *preview = GetPrintPreview(); |
1007 | if (preview) | |
c801d85f | 1008 | { |
7bcb11d3 JS |
1009 | int currentPage = preview->GetCurrentPage(); |
1010 | if ((preview->GetMaxPage() > 0) && | |
1011 | (currentPage < preview->GetMaxPage()) && | |
1012 | preview->GetPrintout()->HasPage(currentPage + 1)) | |
1013 | { | |
1014 | preview->SetCurrentPage(currentPage + 1); | |
1015 | } | |
c801d85f | 1016 | } |
c801d85f KB |
1017 | } |
1018 | ||
0f90ec93 | 1019 | void wxPreviewControlBar::OnPrevious(void) |
c801d85f | 1020 | { |
7bcb11d3 JS |
1021 | wxPrintPreviewBase *preview = GetPrintPreview(); |
1022 | if (preview) | |
c801d85f | 1023 | { |
7bcb11d3 JS |
1024 | int currentPage = preview->GetCurrentPage(); |
1025 | if ((preview->GetMinPage() > 0) && | |
1026 | (currentPage > preview->GetMinPage()) && | |
1027 | preview->GetPrintout()->HasPage(currentPage - 1)) | |
1028 | { | |
1029 | preview->SetCurrentPage(currentPage - 1); | |
1030 | } | |
c801d85f | 1031 | } |
c801d85f KB |
1032 | } |
1033 | ||
bf89b538 JS |
1034 | void wxPreviewControlBar::OnFirst(void) |
1035 | { | |
1036 | wxPrintPreviewBase *preview = GetPrintPreview(); | |
1037 | if (preview) | |
1038 | { | |
1039 | int currentPage = preview->GetMinPage(); | |
1040 | if (preview->GetPrintout()->HasPage(currentPage)) | |
1041 | { | |
1042 | preview->SetCurrentPage(currentPage); | |
1043 | } | |
1044 | } | |
1045 | } | |
1046 | ||
1047 | void wxPreviewControlBar::OnLast(void) | |
1048 | { | |
1049 | wxPrintPreviewBase *preview = GetPrintPreview(); | |
1050 | if (preview) | |
1051 | { | |
1052 | int currentPage = preview->GetMaxPage(); | |
1053 | if (preview->GetPrintout()->HasPage(currentPage)) | |
1054 | { | |
1055 | preview->SetCurrentPage(currentPage); | |
1056 | } | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | void wxPreviewControlBar::OnGoto(void) | |
1061 | { | |
1062 | wxPrintPreviewBase *preview = GetPrintPreview(); | |
1063 | if (preview) | |
1064 | { | |
1065 | long currentPage; | |
1066 | ||
1067 | if (preview->GetMinPage() > 0) | |
1068 | { | |
1069 | wxString strPrompt; | |
1070 | wxString strPage; | |
1071 | ||
d2b354f9 | 1072 | strPrompt.Printf( _("Enter a page number between %d and %d:"), |
bf89b538 | 1073 | preview->GetMinPage(), preview->GetMaxPage()); |
7e99eddf | 1074 | strPage.Printf( wxT("%d"), preview->GetCurrentPage() ); |
bf89b538 JS |
1075 | |
1076 | strPage = | |
d2b354f9 | 1077 | wxGetTextFromUser( strPrompt, _("Goto Page"), strPage, GetParent()); |
bf89b538 JS |
1078 | |
1079 | if ( strPage.ToLong( ¤tPage ) ) | |
1080 | if (preview->GetPrintout()->HasPage(currentPage)) | |
1081 | { | |
1082 | preview->SetCurrentPage(currentPage); | |
1083 | } | |
1084 | } | |
1085 | } | |
1086 | } | |
1087 | ||
c801d85f KB |
1088 | void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event)) |
1089 | { | |
7bcb11d3 JS |
1090 | int zoom = GetZoomControl(); |
1091 | if (GetPrintPreview()) | |
1092 | GetPrintPreview()->SetZoom(zoom); | |
c801d85f KB |
1093 | } |
1094 | ||
34da0970 | 1095 | void wxPreviewControlBar::CreateButtons() |
c801d85f | 1096 | { |
7bcb11d3 | 1097 | SetSize(0, 0, 400, 40); |
8826f46f | 1098 | |
9dff8515 | 1099 | wxBoxSizer *item0 = new wxBoxSizer( wxHORIZONTAL ); |
e71fd398 | 1100 | |
9dff8515 JS |
1101 | m_closeButton = new wxButton( this, wxID_PREVIEW_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 ); |
1102 | item0->Add( m_closeButton, 0, wxALIGN_CENTRE|wxALL, 5 ); | |
e71fd398 | 1103 | |
7bcb11d3 JS |
1104 | if (m_buttonFlags & wxPREVIEW_PRINT) |
1105 | { | |
9dff8515 JS |
1106 | m_printButton = new wxButton( this, wxID_PREVIEW_PRINT, _("&Print..."), wxDefaultPosition, wxDefaultSize, 0 ); |
1107 | item0->Add( m_printButton, 0, wxALIGN_CENTRE|wxALL, 5 ); | |
7bcb11d3 | 1108 | } |
e71fd398 | 1109 | |
892a76f7 JS |
1110 | // Exact-fit buttons are too tiny on wxUniversal |
1111 | int navButtonStyle; | |
1112 | wxSize navButtonSize; | |
1113 | #ifdef __WXUNIVERSAL__ | |
1114 | navButtonStyle = 0; | |
2981fc83 | 1115 | navButtonSize = wxSize(40, m_closeButton->GetSize().y); |
892a76f7 JS |
1116 | #else |
1117 | navButtonStyle = wxBU_EXACTFIT; | |
1118 | navButtonSize = wxDefaultSize; | |
1119 | #endif | |
1120 | ||
bf89b538 JS |
1121 | if (m_buttonFlags & wxPREVIEW_FIRST) |
1122 | { | |
892a76f7 | 1123 | m_firstPageButton = new wxButton( this, wxID_PREVIEW_FIRST, _("|<<"), wxDefaultPosition, navButtonSize, navButtonStyle ); |
9dff8515 | 1124 | item0->Add( m_firstPageButton, 0, wxALIGN_CENTRE|wxALL, 5 ); |
bf89b538 | 1125 | } |
e71fd398 | 1126 | |
7bcb11d3 JS |
1127 | if (m_buttonFlags & wxPREVIEW_PREVIOUS) |
1128 | { | |
892a76f7 | 1129 | m_previousPageButton = new wxButton( this, wxID_PREVIEW_PREVIOUS, _("<<"), wxDefaultPosition, navButtonSize, navButtonStyle ); |
9dff8515 | 1130 | item0->Add( m_previousPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 ); |
7bcb11d3 | 1131 | } |
e71fd398 | 1132 | |
7bcb11d3 JS |
1133 | if (m_buttonFlags & wxPREVIEW_NEXT) |
1134 | { | |
892a76f7 | 1135 | m_nextPageButton = new wxButton( this, wxID_PREVIEW_NEXT, _(">>"), wxDefaultPosition, navButtonSize, navButtonStyle ); |
9dff8515 | 1136 | item0->Add( m_nextPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 ); |
bf89b538 | 1137 | } |
e71fd398 | 1138 | |
bf89b538 JS |
1139 | if (m_buttonFlags & wxPREVIEW_LAST) |
1140 | { | |
892a76f7 | 1141 | m_lastPageButton = new wxButton( this, wxID_PREVIEW_LAST, _(">>|"), wxDefaultPosition, navButtonSize, navButtonStyle ); |
9dff8515 | 1142 | item0->Add( m_lastPageButton, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 ); |
bf89b538 | 1143 | } |
e71fd398 | 1144 | |
bf89b538 JS |
1145 | if (m_buttonFlags & wxPREVIEW_GOTO) |
1146 | { | |
9dff8515 JS |
1147 | m_gotoPageButton = new wxButton( this, wxID_PREVIEW_GOTO, _("&Goto..."), wxDefaultPosition, wxDefaultSize, 0 ); |
1148 | item0->Add( m_gotoPageButton, 0, wxALIGN_CENTRE|wxALL, 5 ); | |
7bcb11d3 | 1149 | } |
e71fd398 | 1150 | |
7bcb11d3 JS |
1151 | if (m_buttonFlags & wxPREVIEW_ZOOM) |
1152 | { | |
e71fd398 | 1153 | wxString choices[] = |
c25ccf85 | 1154 | { |
2b5f62a0 | 1155 | wxT("10%"), wxT("15%"), wxT("20%"), wxT("25%"), wxT("30%"), wxT("35%"), wxT("40%"), wxT("45%"), wxT("50%"), wxT("55%"), |
9dff8515 JS |
1156 | wxT("60%"), wxT("65%"), wxT("70%"), wxT("75%"), wxT("80%"), wxT("85%"), wxT("90%"), wxT("95%"), wxT("100%"), wxT("110%"), |
1157 | wxT("120%"), wxT("150%"), wxT("200%") | |
c25ccf85 | 1158 | }; |
c25ccf85 | 1159 | int n = WXSIZEOF(choices); |
e71fd398 | 1160 | |
7e548f6b | 1161 | m_zoomControl = new wxChoice( this, wxID_PREVIEW_ZOOM, wxDefaultPosition, wxSize(70,wxDefaultCoord), n, choices, 0 ); |
9dff8515 | 1162 | item0->Add( m_zoomControl, 0, wxALIGN_CENTRE|wxALL, 5 ); |
7bcb11d3 JS |
1163 | SetZoomControl(m_printPreview->GetZoom()); |
1164 | } | |
8826f46f | 1165 | |
9dff8515 JS |
1166 | SetSizer(item0); |
1167 | item0->Fit(this); | |
c801d85f KB |
1168 | } |
1169 | ||
1170 | void wxPreviewControlBar::SetZoomControl(int zoom) | |
1171 | { | |
7bcb11d3 | 1172 | if (m_zoomControl) |
963907fa RR |
1173 | { |
1174 | int n, count = m_zoomControl->GetCount(); | |
1175 | long val; | |
1176 | for (n=0; n<count; n++) | |
1177 | { | |
1178 | if (m_zoomControl->GetString(n).BeforeFirst(wxT('%')).ToLong(&val) && | |
1179 | (val >= long(zoom))) | |
1180 | { | |
1181 | m_zoomControl->SetSelection(n); | |
1182 | return; | |
1183 | } | |
1184 | } | |
7e548f6b | 1185 | |
963907fa RR |
1186 | m_zoomControl->SetSelection(count-1); |
1187 | } | |
c801d85f KB |
1188 | } |
1189 | ||
34da0970 | 1190 | int wxPreviewControlBar::GetZoomControl() |
c801d85f | 1191 | { |
963907fa | 1192 | if (m_zoomControl && (m_zoomControl->GetStringSelection() != wxEmptyString)) |
7bcb11d3 | 1193 | { |
963907fa RR |
1194 | long val; |
1195 | if (m_zoomControl->GetStringSelection().BeforeFirst(wxT('%')).ToLong(&val)) | |
1196 | return int(val); | |
7bcb11d3 | 1197 | } |
7e548f6b | 1198 | |
963907fa | 1199 | return 0; |
c801d85f KB |
1200 | } |
1201 | ||
1202 | ||
1203 | /* | |
7bcb11d3 JS |
1204 | * Preview frame |
1205 | */ | |
c801d85f | 1206 | |
e81e3883 RR |
1207 | IMPLEMENT_CLASS(wxPreviewFrame, wxFrame) |
1208 | ||
e3065973 | 1209 | BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame) |
0f90ec93 | 1210 | EVT_CLOSE(wxPreviewFrame::OnCloseWindow) |
e3065973 JS |
1211 | END_EVENT_TABLE() |
1212 | ||
a5ae8241 | 1213 | wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxWindow *parent, const wxString& title, |
7bcb11d3 | 1214 | const wxPoint& pos, const wxSize& size, long style, const wxString& name): |
7e548f6b | 1215 | wxFrame(parent, wxID_ANY, title, pos, size, style, name) |
c801d85f | 1216 | { |
7bcb11d3 JS |
1217 | m_printPreview = preview; |
1218 | m_controlBar = NULL; | |
1219 | m_previewCanvas = NULL; | |
7c995553 | 1220 | m_windowDisabler = NULL; |
46b24ef9 | 1221 | |
a5ae8241 | 1222 | // Give the application icon |
46b24ef9 JS |
1223 | #ifdef __WXMSW__ |
1224 | wxFrame* topFrame = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame); | |
1225 | if (topFrame) | |
1226 | SetIcon(topFrame->GetIcon()); | |
e71fd398 | 1227 | #endif |
c801d85f KB |
1228 | } |
1229 | ||
34da0970 | 1230 | wxPreviewFrame::~wxPreviewFrame() |
c801d85f KB |
1231 | { |
1232 | } | |
1233 | ||
74e3313b | 1234 | void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
c801d85f | 1235 | { |
7c995553 VZ |
1236 | if (m_windowDisabler) |
1237 | delete m_windowDisabler; | |
8826f46f | 1238 | |
7bcb11d3 JS |
1239 | // Need to delete the printout and the print preview |
1240 | wxPrintout *printout = m_printPreview->GetPrintout(); | |
1241 | if (printout) | |
1242 | { | |
1243 | delete printout; | |
1244 | m_printPreview->SetPrintout(NULL); | |
1245 | m_printPreview->SetCanvas(NULL); | |
1246 | m_printPreview->SetFrame(NULL); | |
1247 | } | |
1248 | delete m_printPreview; | |
8826f46f | 1249 | |
7bcb11d3 | 1250 | Destroy(); |
c801d85f KB |
1251 | } |
1252 | ||
34da0970 | 1253 | void wxPreviewFrame::Initialize() |
c801d85f | 1254 | { |
3080bf59 | 1255 | #if wxUSE_STATUSBAR |
7bcb11d3 | 1256 | CreateStatusBar(); |
3080bf59 | 1257 | #endif |
7bcb11d3 JS |
1258 | CreateCanvas(); |
1259 | CreateControlBar(); | |
8826f46f | 1260 | |
7bcb11d3 JS |
1261 | m_printPreview->SetCanvas(m_previewCanvas); |
1262 | m_printPreview->SetFrame(this); | |
8826f46f | 1263 | |
9dff8515 | 1264 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); |
8826f46f | 1265 | |
9dff8515 JS |
1266 | item0->Add( m_controlBar, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 ); |
1267 | item0->Add( m_previewCanvas, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 5 ); | |
8826f46f | 1268 | |
7e548f6b | 1269 | SetAutoLayout( true ); |
9dff8515 | 1270 | SetSizer( item0 ); |
8826f46f | 1271 | |
7c995553 | 1272 | m_windowDisabler = new wxWindowDisabler(this); |
8826f46f | 1273 | |
7bcb11d3 | 1274 | Layout(); |
e71fd398 | 1275 | |
d2b354f9 JS |
1276 | m_printPreview->AdjustScrollbars(m_previewCanvas); |
1277 | m_previewCanvas->SetFocus(); | |
1278 | m_controlBar->SetFocus(); | |
c801d85f KB |
1279 | } |
1280 | ||
34da0970 | 1281 | void wxPreviewFrame::CreateCanvas() |
c801d85f | 1282 | { |
7bcb11d3 | 1283 | m_previewCanvas = new wxPreviewCanvas(m_printPreview, this); |
c801d85f KB |
1284 | } |
1285 | ||
34da0970 | 1286 | void wxPreviewFrame::CreateControlBar() |
c801d85f | 1287 | { |
7bcb11d3 JS |
1288 | long buttons = wxPREVIEW_DEFAULT; |
1289 | if (m_printPreview->GetPrintoutForPrinting()) | |
1290 | buttons |= wxPREVIEW_PRINT; | |
8826f46f | 1291 | |
c47addef | 1292 | m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0,0), wxSize(400, 40)); |
7bcb11d3 | 1293 | m_controlBar->CreateButtons(); |
c801d85f | 1294 | } |
7bcb11d3 | 1295 | |
c801d85f | 1296 | /* |
7bcb11d3 JS |
1297 | * Print preview |
1298 | */ | |
c801d85f | 1299 | |
891daf8c RR |
1300 | IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject) |
1301 | ||
8826f46f VZ |
1302 | wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout, |
1303 | wxPrintout *printoutForPrinting, | |
1304 | wxPrintData *data) | |
1305 | { | |
1306 | if (data) | |
1307 | m_printDialogData = (*data); | |
1308 | ||
1309 | Init(printout, printoutForPrinting); | |
1310 | } | |
1311 | ||
1312 | wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout, | |
1313 | wxPrintout *printoutForPrinting, | |
1314 | wxPrintDialogData *data) | |
1315 | { | |
1316 | if (data) | |
1317 | m_printDialogData = (*data); | |
1318 | ||
1319 | Init(printout, printoutForPrinting); | |
1320 | } | |
1321 | ||
1322 | void wxPrintPreviewBase::Init(wxPrintout *printout, | |
1323 | wxPrintout *printoutForPrinting) | |
c801d85f | 1324 | { |
7e548f6b | 1325 | m_isOk = true; |
7bcb11d3 JS |
1326 | m_previewPrintout = printout; |
1327 | if (m_previewPrintout) | |
7e548f6b | 1328 | m_previewPrintout->SetIsPreview(true); |
8826f46f | 1329 | |
7bcb11d3 | 1330 | m_printPrintout = printoutForPrinting; |
8826f46f | 1331 | |
7bcb11d3 JS |
1332 | m_previewCanvas = NULL; |
1333 | m_previewFrame = NULL; | |
1334 | m_previewBitmap = NULL; | |
1335 | m_currentPage = 1; | |
c25ccf85 | 1336 | m_currentZoom = 70; |
7bcb11d3 JS |
1337 | m_topMargin = 40; |
1338 | m_leftMargin = 40; | |
1339 | m_pageWidth = 0; | |
1340 | m_pageHeight = 0; | |
7e548f6b | 1341 | m_printingPrepared = false; |
d2b354f9 JS |
1342 | m_minPage = 1; |
1343 | m_maxPage = 1; | |
c801d85f KB |
1344 | } |
1345 | ||
34da0970 | 1346 | wxPrintPreviewBase::~wxPrintPreviewBase() |
c801d85f | 1347 | { |
7bcb11d3 JS |
1348 | if (m_previewPrintout) |
1349 | delete m_previewPrintout; | |
1350 | if (m_previewBitmap) | |
1351 | delete m_previewBitmap; | |
1352 | if (m_printPrintout) | |
1353 | delete m_printPrintout; | |
c801d85f KB |
1354 | } |
1355 | ||
1356 | bool wxPrintPreviewBase::SetCurrentPage(int pageNum) | |
1357 | { | |
7bcb11d3 | 1358 | if (m_currentPage == pageNum) |
7e548f6b | 1359 | return true; |
8826f46f | 1360 | |
7bcb11d3 JS |
1361 | m_currentPage = pageNum; |
1362 | if (m_previewBitmap) | |
1363 | { | |
1364 | delete m_previewBitmap; | |
1365 | m_previewBitmap = NULL; | |
1366 | } | |
e71fd398 | 1367 | |
7bcb11d3 JS |
1368 | if (m_previewCanvas) |
1369 | { | |
d2b354f9 | 1370 | AdjustScrollbars(m_previewCanvas); |
e71fd398 | 1371 | |
9eee81a4 | 1372 | if (!RenderPage(pageNum)) |
7e548f6b | 1373 | return false; |
7bcb11d3 | 1374 | m_previewCanvas->Refresh(); |
d2b354f9 | 1375 | m_previewCanvas->SetFocus(); |
7bcb11d3 | 1376 | } |
7e548f6b | 1377 | return true; |
c801d85f KB |
1378 | } |
1379 | ||
383f6abd | 1380 | int wxPrintPreviewBase::GetCurrentPage() const |
259c43f6 | 1381 | { return m_currentPage; } |
383f6abd | 1382 | void wxPrintPreviewBase::SetPrintout(wxPrintout *printout) |
259c43f6 | 1383 | { m_previewPrintout = printout; } |
383f6abd | 1384 | wxPrintout *wxPrintPreviewBase::GetPrintout() const |
259c43f6 | 1385 | { return m_previewPrintout; } |
383f6abd | 1386 | wxPrintout *wxPrintPreviewBase::GetPrintoutForPrinting() const |
259c43f6 | 1387 | { return m_printPrintout; } |
383f6abd | 1388 | void wxPrintPreviewBase::SetFrame(wxFrame *frame) |
259c43f6 | 1389 | { m_previewFrame = frame; } |
383f6abd | 1390 | void wxPrintPreviewBase::SetCanvas(wxPreviewCanvas *canvas) |
259c43f6 | 1391 | { m_previewCanvas = canvas; } |
383f6abd | 1392 | wxFrame *wxPrintPreviewBase::GetFrame() const |
e81e3883 | 1393 | { return m_previewFrame; } |
383f6abd | 1394 | wxPreviewCanvas *wxPrintPreviewBase::GetCanvas() const |
e81e3883 RR |
1395 | { return m_previewCanvas; } |
1396 | ||
f415cab9 JS |
1397 | void wxPrintPreviewBase::CalcRects(wxPreviewCanvas *canvas, wxRect& pageRect, wxRect& paperRect) |
1398 | { | |
1399 | // Calculate the rectangles for the printable area of the page and the | |
1400 | // entire paper as they appear on the canvas on-screen. | |
1401 | int canvasWidth, canvasHeight; | |
1402 | canvas->GetSize(&canvasWidth, &canvasHeight); | |
1403 | ||
1404 | float zoomScale = float(m_currentZoom) / 100; | |
1405 | float screenPrintableWidth = zoomScale * m_pageWidth * m_previewScaleX; | |
1406 | float screenPrintableHeight = zoomScale * m_pageHeight * m_previewScaleY; | |
1407 | ||
1408 | wxRect devicePaperRect = m_previewPrintout->GetPaperRectPixels(); | |
1409 | wxCoord devicePrintableWidth, devicePrintableHeight; | |
1410 | m_previewPrintout->GetPageSizePixels(&devicePrintableWidth, &devicePrintableHeight); | |
1411 | float scaleX = screenPrintableWidth / devicePrintableWidth; | |
1412 | float scaleY = screenPrintableHeight / devicePrintableHeight; | |
1413 | paperRect.width = wxCoord(scaleX * devicePaperRect.width); | |
1414 | paperRect.height = wxCoord(scaleY * devicePaperRect.height); | |
1415 | ||
1416 | paperRect.x = wxCoord((canvasWidth - paperRect.width)/ 2.0); | |
1417 | if (paperRect.x < m_leftMargin) | |
1418 | paperRect.x = m_leftMargin; | |
1419 | paperRect.y = wxCoord((canvasHeight - paperRect.height)/ 2.0); | |
1420 | if (paperRect.y < m_topMargin) | |
1421 | paperRect.y = m_topMargin; | |
1422 | ||
1423 | pageRect.x = paperRect.x - wxCoord(scaleX * devicePaperRect.x); | |
1424 | pageRect.y = paperRect.y - wxCoord(scaleY * devicePaperRect.y); | |
1425 | pageRect.width = wxCoord(screenPrintableWidth); | |
1426 | pageRect.height = wxCoord(screenPrintableHeight); | |
1427 | } | |
1428 | ||
1429 | ||
d2b354f9 | 1430 | bool wxPrintPreviewBase::PaintPage(wxPreviewCanvas *canvas, wxDC& dc) |
c801d85f | 1431 | { |
7bcb11d3 | 1432 | DrawBlankPage(canvas, dc); |
8826f46f | 1433 | |
7bcb11d3 | 1434 | if (!m_previewBitmap) |
9eee81a4 | 1435 | if (!RenderPage(m_currentPage)) |
7e548f6b | 1436 | return false; |
7bcb11d3 | 1437 | if (!m_previewBitmap) |
7e548f6b | 1438 | return false; |
7bcb11d3 | 1439 | if (!canvas) |
7e548f6b | 1440 | return false; |
8826f46f | 1441 | |
f415cab9 JS |
1442 | wxRect pageRect, paperRect; |
1443 | CalcRects(canvas, pageRect, paperRect); | |
7bcb11d3 JS |
1444 | wxMemoryDC temp_dc; |
1445 | temp_dc.SelectObject(*m_previewBitmap); | |
8826f46f | 1446 | |
f415cab9 JS |
1447 | dc.Blit(pageRect.x, pageRect.y, |
1448 | m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0); | |
8826f46f | 1449 | |
7bcb11d3 | 1450 | temp_dc.SelectObject(wxNullBitmap); |
7e548f6b | 1451 | return true; |
c801d85f KB |
1452 | } |
1453 | ||
d2b354f9 JS |
1454 | // Adjusts the scrollbars for the current scale |
1455 | void wxPrintPreviewBase::AdjustScrollbars(wxPreviewCanvas *canvas) | |
1456 | { | |
1457 | if (!canvas) | |
1458 | return ; | |
1459 | ||
f415cab9 JS |
1460 | wxRect pageRect, paperRect; |
1461 | CalcRects(canvas, pageRect, paperRect); | |
1462 | int totalWidth = paperRect.width + 2 * m_leftMargin; | |
1463 | int totalHeight = paperRect.height + 2 * m_topMargin; | |
1464 | int scrollUnitsX = totalWidth / 10; | |
1465 | int scrollUnitsY = totalHeight / 10; | |
d2b354f9 JS |
1466 | wxSize virtualSize = canvas->GetVirtualSize(); |
1467 | if (virtualSize.GetWidth() != totalWidth || virtualSize.GetHeight() != totalHeight) | |
7e548f6b | 1468 | canvas->SetScrollbars(10, 10, scrollUnitsX, scrollUnitsY, 0, 0, true); |
d2b354f9 JS |
1469 | } |
1470 | ||
c801d85f KB |
1471 | bool wxPrintPreviewBase::RenderPage(int pageNum) |
1472 | { | |
f6bcfd97 BP |
1473 | wxBusyCursor busy; |
1474 | ||
7bcb11d3 | 1475 | if (!m_previewCanvas) |
c801d85f | 1476 | { |
f6bcfd97 | 1477 | wxFAIL_MSG(_T("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!")); |
7e548f6b | 1478 | return false; |
c801d85f | 1479 | } |
8826f46f | 1480 | |
f415cab9 JS |
1481 | wxRect pageRect, paperRect; |
1482 | CalcRects(m_previewCanvas, pageRect, paperRect); | |
8826f46f | 1483 | |
7bcb11d3 JS |
1484 | if (!m_previewBitmap) |
1485 | { | |
f415cab9 JS |
1486 | m_previewBitmap = new wxBitmap(pageRect.width, pageRect.height); |
1487 | ||
7bcb11d3 JS |
1488 | if (!m_previewBitmap || !m_previewBitmap->Ok()) |
1489 | { | |
9eee81a4 | 1490 | if (m_previewBitmap) { |
7bcb11d3 | 1491 | delete m_previewBitmap; |
9eee81a4 GD |
1492 | m_previewBitmap = NULL; |
1493 | } | |
7bcb11d3 | 1494 | wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK); |
7e548f6b | 1495 | return false; |
7bcb11d3 JS |
1496 | } |
1497 | } | |
8826f46f | 1498 | |
7bcb11d3 JS |
1499 | wxMemoryDC memoryDC; |
1500 | memoryDC.SelectObject(*m_previewBitmap); | |
8826f46f | 1501 | |
7bcb11d3 | 1502 | memoryDC.Clear(); |
8826f46f | 1503 | |
7bcb11d3 JS |
1504 | m_previewPrintout->SetDC(&memoryDC); |
1505 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); | |
8826f46f | 1506 | |
1044a386 JS |
1507 | // Need to delay OnPreparePrinting until here, so we have enough information. |
1508 | if (!m_printingPrepared) | |
1509 | { | |
1510 | m_previewPrintout->OnPreparePrinting(); | |
d2b354f9 JS |
1511 | int selFrom, selTo; |
1512 | m_previewPrintout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo); | |
7e548f6b | 1513 | m_printingPrepared = true; |
1044a386 JS |
1514 | } |
1515 | ||
7bcb11d3 | 1516 | m_previewPrintout->OnBeginPrinting(); |
c801d85f | 1517 | |
7bcb11d3 JS |
1518 | if (!m_previewPrintout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage())) |
1519 | { | |
1520 | wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK); | |
8826f46f | 1521 | |
7bcb11d3 | 1522 | memoryDC.SelectObject(wxNullBitmap); |
8826f46f | 1523 | |
7bcb11d3 | 1524 | delete m_previewBitmap; |
9eee81a4 | 1525 | m_previewBitmap = NULL; |
7e548f6b | 1526 | return false; |
7bcb11d3 | 1527 | } |
8826f46f | 1528 | |
7bcb11d3 JS |
1529 | m_previewPrintout->OnPrintPage(pageNum); |
1530 | m_previewPrintout->OnEndDocument(); | |
1531 | m_previewPrintout->OnEndPrinting(); | |
8826f46f | 1532 | |
7bcb11d3 | 1533 | m_previewPrintout->SetDC(NULL); |
8826f46f | 1534 | |
c801d85f | 1535 | memoryDC.SelectObject(wxNullBitmap); |
8826f46f | 1536 | |
3080bf59 VZ |
1537 | #if wxUSE_STATUSBAR |
1538 | wxString status; | |
7bcb11d3 | 1539 | if (m_maxPage != 0) |
7e548f6b | 1540 | status = wxString::Format(_("Page %d of %d"), pageNum, m_maxPage); |
7bcb11d3 | 1541 | else |
7e548f6b | 1542 | status = wxString::Format(_("Page %d"), pageNum); |
8826f46f | 1543 | |
7bcb11d3 | 1544 | if (m_previewFrame) |
3080bf59 VZ |
1545 | m_previewFrame->SetStatusText(status); |
1546 | #endif | |
8826f46f | 1547 | |
7e548f6b | 1548 | return true; |
c801d85f KB |
1549 | } |
1550 | ||
d2b354f9 | 1551 | bool wxPrintPreviewBase::DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc) |
c801d85f | 1552 | { |
f415cab9 | 1553 | wxRect pageRect, paperRect; |
8826f46f | 1554 | |
f415cab9 | 1555 | CalcRects(canvas, pageRect, paperRect); |
8826f46f | 1556 | |
f415cab9 JS |
1557 | // Draw shadow, allowing for 1-pixel border AROUND the actual paper |
1558 | wxCoord shadowOffset = 4; | |
8826f46f | 1559 | |
7bcb11d3 JS |
1560 | dc.SetPen(*wxBLACK_PEN); |
1561 | dc.SetBrush(*wxBLACK_BRUSH); | |
f415cab9 JS |
1562 | dc.DrawRectangle(paperRect.x + shadowOffset, paperRect.y + paperRect.height + 1, |
1563 | paperRect.width, shadowOffset); | |
1564 | ||
1565 | dc.DrawRectangle(paperRect.x + paperRect.width, paperRect.y + shadowOffset, | |
1566 | shadowOffset, paperRect.height); | |
8826f46f | 1567 | |
f415cab9 | 1568 | // Draw blank page allowing for 1-pixel border AROUND the actual paper |
7bcb11d3 JS |
1569 | dc.SetPen(*wxBLACK_PEN); |
1570 | dc.SetBrush(*wxWHITE_BRUSH); | |
f415cab9 JS |
1571 | dc.DrawRectangle(paperRect.x - 2, paperRect.y - 1, |
1572 | paperRect.width + 3, paperRect.height + 2); | |
8826f46f | 1573 | |
7e548f6b | 1574 | return true; |
2a47d3c1 JS |
1575 | } |
1576 | ||
7bcb11d3 | 1577 | void wxPrintPreviewBase::SetZoom(int percent) |
2a47d3c1 | 1578 | { |
7bcb11d3 JS |
1579 | if (m_currentZoom == percent) |
1580 | return; | |
8826f46f | 1581 | |
7bcb11d3 JS |
1582 | m_currentZoom = percent; |
1583 | if (m_previewBitmap) | |
1584 | { | |
1585 | delete m_previewBitmap; | |
1586 | m_previewBitmap = NULL; | |
1587 | } | |
aff37a19 | 1588 | |
7bcb11d3 JS |
1589 | if (m_previewCanvas) |
1590 | { | |
d2b354f9 | 1591 | AdjustScrollbars(m_previewCanvas); |
aff37a19 | 1592 | RenderPage(m_currentPage); |
95724b1a | 1593 | ((wxScrolledWindow *) m_previewCanvas)->Scroll(0, 0); |
e71fd398 | 1594 | m_previewCanvas->ClearBackground(); |
7bcb11d3 | 1595 | m_previewCanvas->Refresh(); |
d2b354f9 | 1596 | m_previewCanvas->SetFocus(); |
7bcb11d3 | 1597 | } |
2a47d3c1 JS |
1598 | } |
1599 | ||
383f6abd WS |
1600 | wxPrintDialogData& wxPrintPreviewBase::GetPrintDialogData() |
1601 | { | |
e81e3883 RR |
1602 | return m_printDialogData; |
1603 | } | |
1604 | ||
383f6abd | 1605 | int wxPrintPreviewBase::GetZoom() const |
e81e3883 | 1606 | { return m_currentZoom; } |
383f6abd | 1607 | int wxPrintPreviewBase::GetMaxPage() const |
e81e3883 | 1608 | { return m_maxPage; } |
383f6abd | 1609 | int wxPrintPreviewBase::GetMinPage() const |
e81e3883 | 1610 | { return m_minPage; } |
b7cacb43 | 1611 | bool wxPrintPreviewBase::IsOk() const |
e81e3883 | 1612 | { return m_isOk; } |
383f6abd | 1613 | void wxPrintPreviewBase::SetOk(bool ok) |
e81e3883 | 1614 | { m_isOk = ok; } |
f415cab9 | 1615 | |
e81e3883 RR |
1616 | //---------------------------------------------------------------------------- |
1617 | // wxPrintPreview | |
1618 | //---------------------------------------------------------------------------- | |
1619 | ||
1620 | IMPLEMENT_CLASS(wxPrintPreview, wxPrintPreviewBase) | |
1621 | ||
1622 | wxPrintPreview::wxPrintPreview(wxPrintout *printout, | |
1623 | wxPrintout *printoutForPrinting, | |
1624 | wxPrintDialogData *data) : | |
1625 | wxPrintPreviewBase( printout, printoutForPrinting, data ) | |
1626 | { | |
1627 | m_pimpl = wxPrintFactory::GetFactory()-> | |
1628 | CreatePrintPreview( printout, printoutForPrinting, data ); | |
1629 | } | |
1630 | ||
1631 | wxPrintPreview::wxPrintPreview(wxPrintout *printout, | |
1632 | wxPrintout *printoutForPrinting, | |
1633 | wxPrintData *data ) : | |
1634 | wxPrintPreviewBase( printout, printoutForPrinting, data ) | |
1635 | { | |
1636 | m_pimpl = wxPrintFactory::GetFactory()-> | |
1637 | CreatePrintPreview( printout, printoutForPrinting, data ); | |
1638 | } | |
1639 | ||
1640 | wxPrintPreview::~wxPrintPreview() | |
1641 | { | |
1642 | delete m_pimpl; | |
383f6abd | 1643 | |
e81e3883 RR |
1644 | // don't delete twice |
1645 | m_printPrintout = NULL; | |
1646 | m_previewPrintout = NULL; | |
1647 | m_previewBitmap = NULL; | |
1648 | } | |
1649 | ||
1650 | bool wxPrintPreview::SetCurrentPage(int pageNum) | |
1651 | { | |
1652 | return m_pimpl->SetCurrentPage( pageNum ); | |
1653 | } | |
1654 | ||
383f6abd WS |
1655 | int wxPrintPreview::GetCurrentPage() const |
1656 | { | |
e81e3883 RR |
1657 | return m_pimpl->GetCurrentPage(); |
1658 | } | |
1659 | ||
383f6abd WS |
1660 | void wxPrintPreview::SetPrintout(wxPrintout *printout) |
1661 | { | |
e81e3883 RR |
1662 | m_pimpl->SetPrintout( printout ); |
1663 | } | |
1664 | ||
383f6abd WS |
1665 | wxPrintout *wxPrintPreview::GetPrintout() const |
1666 | { | |
e81e3883 RR |
1667 | return m_pimpl->GetPrintout(); |
1668 | } | |
1669 | ||
383f6abd WS |
1670 | wxPrintout *wxPrintPreview::GetPrintoutForPrinting() const |
1671 | { | |
e81e3883 RR |
1672 | return m_pimpl->GetPrintoutForPrinting(); |
1673 | } | |
1674 | ||
383f6abd WS |
1675 | void wxPrintPreview::SetFrame(wxFrame *frame) |
1676 | { | |
e81e3883 RR |
1677 | m_pimpl->SetFrame( frame ); |
1678 | } | |
1679 | ||
383f6abd WS |
1680 | void wxPrintPreview::SetCanvas(wxPreviewCanvas *canvas) |
1681 | { | |
e81e3883 RR |
1682 | m_pimpl->SetCanvas( canvas ); |
1683 | } | |
1684 | ||
383f6abd | 1685 | wxFrame *wxPrintPreview::GetFrame() const |
e81e3883 RR |
1686 | { |
1687 | return m_pimpl->GetFrame(); | |
1688 | } | |
1689 | ||
383f6abd WS |
1690 | wxPreviewCanvas *wxPrintPreview::GetCanvas() const |
1691 | { | |
e81e3883 RR |
1692 | return m_pimpl->GetCanvas(); |
1693 | } | |
1694 | ||
1695 | bool wxPrintPreview::PaintPage(wxPreviewCanvas *canvas, wxDC& dc) | |
1696 | { | |
1697 | return m_pimpl->PaintPage( canvas, dc ); | |
1698 | } | |
1699 | ||
1700 | bool wxPrintPreview::DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc) | |
1701 | { | |
1702 | return m_pimpl->DrawBlankPage( canvas, dc ); | |
1703 | } | |
1704 | ||
1705 | void wxPrintPreview::AdjustScrollbars(wxPreviewCanvas *canvas) | |
1706 | { | |
1707 | m_pimpl->AdjustScrollbars( canvas ); | |
1708 | } | |
1709 | ||
1710 | bool wxPrintPreview::RenderPage(int pageNum) | |
1711 | { | |
1712 | return m_pimpl->RenderPage( pageNum ); | |
1713 | } | |
1714 | ||
1715 | void wxPrintPreview::SetZoom(int percent) | |
1716 | { | |
1717 | m_pimpl->SetZoom( percent ); | |
1718 | } | |
1719 | ||
d8766675 JS |
1720 | int wxPrintPreview::GetZoom() const |
1721 | { | |
1722 | return m_pimpl->GetZoom(); | |
1723 | } | |
1724 | ||
e81e3883 RR |
1725 | wxPrintDialogData& wxPrintPreview::GetPrintDialogData() |
1726 | { | |
1727 | return m_pimpl->GetPrintDialogData(); | |
1728 | } | |
1729 | ||
1730 | int wxPrintPreview::GetMaxPage() const | |
1731 | { | |
1732 | return m_pimpl->GetMaxPage(); | |
1733 | } | |
1734 | ||
1735 | int wxPrintPreview::GetMinPage() const | |
1736 | { | |
1737 | return m_pimpl->GetMinPage(); | |
1738 | } | |
1739 | ||
b7cacb43 | 1740 | bool wxPrintPreview::IsOk() const |
e81e3883 RR |
1741 | { |
1742 | return m_pimpl->Ok(); | |
1743 | } | |
1744 | ||
1745 | void wxPrintPreview::SetOk(bool ok) | |
1746 | { | |
1747 | m_pimpl->SetOk( ok ); | |
1748 | } | |
1749 | ||
1750 | bool wxPrintPreview::Print(bool interactive) | |
1751 | { | |
1752 | return m_pimpl->Print( interactive ); | |
1753 | } | |
1754 | ||
1755 | void wxPrintPreview::DetermineScaling() | |
1756 | { | |
1757 | m_pimpl->DetermineScaling(); | |
1758 | } | |
1759 | ||
d427503c | 1760 | #endif // wxUSE_PRINTING_ARCHITECTURE |