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