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