]>
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$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "prntbase.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
c801d85f KB |
23 | #include "wx/defs.h" |
24 | ||
a4294b78 | 25 | #ifndef __WXGTK__ |
da87a1ca JS |
26 | #define __GOOD_COMPILER__ |
27 | #endif | |
28 | ||
c801d85f KB |
29 | #ifndef WX_PRECOMP |
30 | #include "wx/utils.h" | |
31 | #include "wx/dc.h" | |
32 | #include "wx/app.h" | |
33 | #include "wx/msgdlg.h" | |
34 | #include "wx/layout.h" | |
35 | #include "wx/choice.h" | |
36 | #include "wx/button.h" | |
37 | #include "wx/settings.h" | |
38 | #include "wx/dcmemory.h" | |
39 | #include "wx/stattext.h" | |
40 | #include "wx/intl.h" | |
41 | #endif | |
42 | ||
43 | #include "wx/prntbase.h" | |
44 | #include "wx/dcprint.h" | |
45 | #include "wx/printdlg.h" | |
46 | ||
47 | #include <stdlib.h> | |
48 | #include <string.h> | |
49 | ||
2049ba38 | 50 | #ifdef __WXMSW__ |
c801d85f KB |
51 | #include <windows.h> |
52 | #include <commdlg.h> | |
53 | ||
54 | // Clash with Windows header files | |
55 | #ifdef StartDoc | |
56 | #undef StartDoc | |
57 | #endif | |
58 | ||
59 | #ifndef __WIN32__ | |
60 | #include <print.h> | |
61 | #endif | |
62 | ||
c801d85f | 63 | #endif |
2049ba38 | 64 | // End __WXMSW__ |
c801d85f KB |
65 | |
66 | #if !USE_SHARED_LIBRARY | |
67 | IMPLEMENT_CLASS(wxPrinterBase, wxObject) | |
68 | IMPLEMENT_ABSTRACT_CLASS(wxPrintout, wxObject) | |
69 | IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow) | |
70 | IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow) | |
71 | IMPLEMENT_CLASS(wxPreviewFrame, wxFrame) | |
72 | IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject) | |
73 | ||
74 | BEGIN_EVENT_TABLE(wxPrintAbortDialog, wxDialog) | |
75 | EVT_BUTTON(wxID_CANCEL, wxPrintAbortDialog::OnCancel) | |
76 | END_EVENT_TABLE() | |
77 | ||
78 | BEGIN_EVENT_TABLE(wxPreviewCanvas, wxScrolledWindow) | |
79 | EVT_PAINT(wxPreviewCanvas::OnPaint) | |
80 | EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged) | |
81 | END_EVENT_TABLE() | |
82 | #endif | |
83 | ||
84 | /* | |
85 | * Printer | |
86 | */ | |
87 | ||
88 | wxPrinterBase::wxPrinterBase(wxPrintData *data) | |
89 | { | |
34da0970 JS |
90 | m_currentPrintout = (wxPrintout *) NULL; |
91 | sm_abortWindow = (wxWindow *) NULL; | |
92 | sm_abortIt = FALSE; | |
c801d85f | 93 | if (data) |
34da0970 | 94 | m_printData = (*data); |
c801d85f KB |
95 | } |
96 | ||
34da0970 JS |
97 | wxWindow *wxPrinterBase::sm_abortWindow = (wxWindow *) NULL; |
98 | bool wxPrinterBase::sm_abortIt = FALSE; | |
c801d85f | 99 | |
34da0970 | 100 | wxPrinterBase::~wxPrinterBase() |
c801d85f KB |
101 | { |
102 | } | |
103 | ||
104 | void wxPrintAbortDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) | |
105 | { | |
34da0970 JS |
106 | wxPrinterBase::sm_abortIt = TRUE; |
107 | wxPrinterBase::sm_abortWindow->Show(FALSE); | |
108 | wxPrinterBase::sm_abortWindow->Close(TRUE); | |
109 | wxPrinterBase::sm_abortWindow = (wxWindow *) NULL; | |
c801d85f KB |
110 | } |
111 | ||
112 | wxWindow *wxPrinterBase::CreateAbortWindow(wxWindow *parent, wxPrintout *WXUNUSED(printout)) | |
113 | { | |
34da0970 | 114 | wxPrintAbortDialog *dialog = new wxPrintAbortDialog(parent, _("Printing"), wxPoint(0, 0), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE); |
c801d85f KB |
115 | (void) new wxStaticText(dialog, -1, _("Please wait..."), wxPoint(5, 5)); |
116 | ||
117 | wxButton *button = new wxButton(dialog, wxID_CANCEL, _("Cancel"), wxPoint(5, 30)); | |
118 | ||
119 | dialog->Fit(); | |
120 | button->Centre(wxHORIZONTAL); | |
121 | ||
122 | dialog->Centre(); | |
123 | return dialog; | |
124 | } | |
125 | ||
126 | void wxPrinterBase::ReportError(wxWindow *parent, wxPrintout *WXUNUSED(printout), char *message) | |
127 | { | |
1a5a8367 | 128 | wxMessageBox(message, _("Printing Error"), wxOK, parent); |
c801d85f KB |
129 | } |
130 | ||
131 | /* | |
132 | * Printout class | |
133 | */ | |
134 | ||
34da0970 | 135 | wxPrintout::wxPrintout(const wxString& title) |
c801d85f | 136 | { |
34da0970 JS |
137 | m_printoutTitle = title ; |
138 | m_printoutDC = (wxDC *) NULL; | |
139 | m_pageWidthMM = 0; | |
140 | m_pageHeightMM = 0; | |
141 | m_pageWidthPixels = 0; | |
142 | m_pageHeightPixels = 0; | |
143 | m_PPIScreenX = 0; | |
144 | m_PPIScreenY = 0; | |
145 | m_PPIPrinterX = 0; | |
146 | m_PPIPrinterY = 0; | |
147 | m_isPreview = FALSE; | |
c801d85f KB |
148 | } |
149 | ||
34da0970 | 150 | wxPrintout::~wxPrintout() |
c801d85f | 151 | { |
c801d85f KB |
152 | } |
153 | ||
154 | bool wxPrintout::OnBeginDocument(int WXUNUSED(startPage), int WXUNUSED(endPage)) | |
155 | { | |
1a5a8367 | 156 | return GetDC()->StartDoc(_("Printing")); |
c801d85f KB |
157 | } |
158 | ||
34da0970 | 159 | void wxPrintout::OnEndDocument() |
c801d85f KB |
160 | { |
161 | GetDC()->EndDoc(); | |
162 | } | |
163 | ||
34da0970 | 164 | void wxPrintout::OnBeginPrinting() |
c801d85f KB |
165 | { |
166 | } | |
167 | ||
34da0970 | 168 | void wxPrintout::OnEndPrinting() |
c801d85f KB |
169 | { |
170 | } | |
171 | ||
172 | bool wxPrintout::HasPage(int page) | |
173 | { | |
174 | return (page == 1); | |
175 | } | |
176 | ||
177 | void wxPrintout::GetPageInfo(int *minPage, int *maxPage, int *fromPage, int *toPage) | |
178 | { | |
179 | *minPage = 1; | |
180 | *maxPage = 32000; | |
181 | *fromPage = 1; | |
182 | *toPage = 1; | |
183 | } | |
184 | ||
185 | /* | |
186 | * Preview canvas | |
187 | */ | |
188 | ||
189 | wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent, | |
190 | const wxPoint& pos, const wxSize& size, long style, const wxString& name): | |
191 | wxScrolledWindow(parent, -1, pos, size, style, name) | |
192 | { | |
34da0970 | 193 | m_printPreview = preview; |
c801d85f KB |
194 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); |
195 | ||
196 | SetScrollbars(40, 40, 100, 100); | |
197 | } | |
198 | ||
34da0970 | 199 | wxPreviewCanvas::~wxPreviewCanvas() |
c801d85f KB |
200 | { |
201 | } | |
202 | ||
203 | void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
204 | { | |
205 | wxPaintDC dc(this); | |
206 | ||
34da0970 | 207 | if (m_printPreview) |
c801d85f | 208 | { |
34da0970 | 209 | m_printPreview->PaintPage(this, dc); |
c801d85f KB |
210 | } |
211 | } | |
212 | ||
213 | // Responds to colour changes, and passes event on to children. | |
214 | void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event) | |
215 | { | |
216 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
217 | Refresh(); | |
218 | ||
219 | // Propagate the event to the non-top-level children | |
220 | wxWindow::OnSysColourChanged(event); | |
221 | } | |
222 | ||
223 | /* | |
224 | * Preview control bar | |
225 | */ | |
226 | ||
227 | BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel) | |
228 | EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnClose) | |
229 | EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrint) | |
230 | EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPrevious) | |
231 | EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNext) | |
232 | EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom) | |
233 | EVT_PAINT(wxPreviewControlBar::OnPaint) | |
234 | END_EVENT_TABLE() | |
235 | ||
236 | wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons, | |
237 | wxWindow *parent, const wxPoint& pos, const wxSize& size, | |
238 | long style, const wxString& name): | |
239 | wxPanel(parent, -1, pos, size, style, name) | |
240 | { | |
34da0970 JS |
241 | m_printPreview = preview; |
242 | m_closeButton = (wxButton *) NULL; | |
243 | m_nextPageButton = (wxButton *) NULL; | |
244 | m_previousPageButton = (wxButton *) NULL; | |
245 | m_printButton = (wxButton *) NULL; | |
246 | m_zoomControl = (wxChoice *) NULL; | |
247 | m_buttonFlags = buttons; | |
c801d85f KB |
248 | } |
249 | ||
34da0970 | 250 | wxPreviewControlBar::~wxPreviewControlBar() |
c801d85f KB |
251 | { |
252 | } | |
253 | ||
254 | void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
255 | { | |
256 | wxPaintDC dc(this); | |
257 | ||
258 | int w, h; | |
259 | GetSize(&w, &h); | |
260 | dc.SetPen(*wxBLACK_PEN); | |
261 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
262 | dc.DrawLine( 0, h-1, w, h-1 ); | |
263 | } | |
264 | ||
265 | void wxPreviewControlBar::OnClose(wxCommandEvent& WXUNUSED(event)) | |
266 | { | |
267 | wxPreviewFrame *frame = (wxPreviewFrame *)GetParent(); | |
268 | frame->Close(TRUE); | |
269 | } | |
270 | ||
271 | void wxPreviewControlBar::OnPrint(wxCommandEvent& WXUNUSED(event)) | |
272 | { | |
273 | wxPrintPreviewBase *preview = GetPrintPreview(); | |
274 | preview->Print(TRUE); | |
275 | } | |
276 | ||
277 | void wxPreviewControlBar::OnNext(wxCommandEvent& WXUNUSED(event)) | |
278 | { | |
279 | wxPrintPreviewBase *preview = GetPrintPreview(); | |
280 | if (preview) | |
281 | { | |
282 | int currentPage = preview->GetCurrentPage(); | |
283 | if ((preview->GetMaxPage() > 0) && | |
284 | (currentPage < preview->GetMaxPage()) && | |
285 | preview->GetPrintout()->HasPage(currentPage + 1)) | |
286 | { | |
287 | preview->SetCurrentPage(currentPage + 1); | |
288 | } | |
289 | } | |
290 | } | |
291 | ||
292 | void wxPreviewControlBar::OnPrevious(wxCommandEvent& WXUNUSED(event)) | |
293 | { | |
294 | wxPrintPreviewBase *preview = GetPrintPreview(); | |
295 | if (preview) | |
296 | { | |
297 | int currentPage = preview->GetCurrentPage(); | |
298 | if ((preview->GetMinPage() > 0) && | |
299 | (currentPage > preview->GetMinPage()) && | |
300 | preview->GetPrintout()->HasPage(currentPage - 1)) | |
301 | { | |
302 | preview->SetCurrentPage(currentPage - 1); | |
303 | } | |
304 | } | |
305 | } | |
306 | ||
307 | void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event)) | |
308 | { | |
309 | int zoom = GetZoomControl(); | |
310 | if (GetPrintPreview()) | |
311 | GetPrintPreview()->SetZoom(zoom); | |
312 | } | |
313 | ||
34da0970 | 314 | void wxPreviewControlBar::CreateButtons() |
c801d85f KB |
315 | { |
316 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
317 | ||
318 | SetSize(0, 0, 400, 40); | |
319 | ||
2049ba38 | 320 | #ifdef __WXMSW__ |
c801d85f KB |
321 | int fontSize = 9; |
322 | #else | |
323 | int fontSize = 10; | |
324 | #endif | |
325 | ||
34da0970 | 326 | wxFont buttonFont(fontSize, wxSWISS, wxNORMAL, wxBOLD); |
a4294b78 | 327 | SetFont(buttonFont); |
c801d85f KB |
328 | |
329 | int buttonWidth = 65; | |
330 | int buttonHeight = 24; | |
331 | ||
332 | int x = 5; | |
333 | int y = 5; | |
334 | int gap = 5; | |
335 | ||
34da0970 | 336 | m_closeButton = new wxButton(this, wxID_PREVIEW_CLOSE, _("Close"), |
c801d85f KB |
337 | wxPoint(x, y), wxSize(buttonWidth, buttonHeight)); |
338 | ||
339 | x += gap + buttonWidth; | |
340 | ||
34da0970 | 341 | if (m_buttonFlags & wxPREVIEW_PRINT) |
c801d85f | 342 | { |
34da0970 | 343 | m_printButton = new wxButton(this, wxID_PREVIEW_PRINT, _("Print..."), wxPoint(x, y), |
c801d85f KB |
344 | wxSize(buttonWidth, buttonHeight)); |
345 | x += gap + buttonWidth; | |
346 | } | |
347 | ||
34da0970 | 348 | if (m_buttonFlags & wxPREVIEW_PREVIOUS) |
c801d85f | 349 | { |
34da0970 | 350 | m_previousPageButton = new wxButton(this, wxID_PREVIEW_PREVIOUS, "<<", wxPoint(x, y), |
c801d85f KB |
351 | wxSize(buttonWidth, buttonHeight)); |
352 | x += gap + buttonWidth; | |
353 | } | |
354 | ||
34da0970 | 355 | if (m_buttonFlags & wxPREVIEW_NEXT) |
c801d85f | 356 | { |
34da0970 | 357 | m_nextPageButton = new wxButton(this, wxID_PREVIEW_NEXT, ">>", |
c801d85f KB |
358 | wxPoint(x, y), wxSize(buttonWidth, buttonHeight)); |
359 | x += gap + buttonWidth; | |
360 | } | |
361 | ||
a4294b78 JS |
362 | // Can't be static because gcc bails out |
363 | wxString choices[] = { "10%", "20%", "25%", "30%", "35%", "40%", "45%", "50%", "55%", "60%", | |
c801d85f KB |
364 | "65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%", "110%", "120%", "150%", "200%" }; |
365 | int n = 22; | |
34da0970 | 366 | if (m_buttonFlags & wxPREVIEW_ZOOM) |
c801d85f | 367 | { |
34da0970 | 368 | m_zoomControl = new wxChoice(this, wxID_PREVIEW_ZOOM, wxPoint(x, y), |
c801d85f | 369 | wxSize(100, -1), n, (wxString *)choices); |
34da0970 | 370 | SetZoomControl(m_printPreview->GetZoom()); |
c801d85f KB |
371 | } |
372 | ||
34da0970 | 373 | m_closeButton->SetDefault(); |
a4294b78 | 374 | |
c801d85f KB |
375 | #endif |
376 | } | |
377 | ||
378 | void wxPreviewControlBar::SetZoomControl(int zoom) | |
379 | { | |
380 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
381 | char buf[20]; | |
382 | sprintf(buf, "%d%%", zoom); | |
34da0970 JS |
383 | if (m_zoomControl) |
384 | m_zoomControl->SetStringSelection(buf); | |
c801d85f KB |
385 | #endif |
386 | } | |
387 | ||
34da0970 | 388 | int wxPreviewControlBar::GetZoomControl() |
c801d85f KB |
389 | { |
390 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
391 | char buf[20]; | |
34da0970 | 392 | if (m_zoomControl && m_zoomControl->GetStringSelection()) |
c801d85f | 393 | { |
34da0970 | 394 | strcpy(buf, m_zoomControl->GetStringSelection()); |
c801d85f KB |
395 | buf[strlen(buf) - 1] = 0; |
396 | return (int)atoi(buf); | |
397 | } | |
398 | else return 0; | |
aad5220b JS |
399 | #else |
400 | return 0; | |
c801d85f KB |
401 | #endif |
402 | } | |
403 | ||
404 | ||
405 | /* | |
406 | * Preview frame | |
407 | */ | |
408 | ||
409 | wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxFrame *parent, const wxString& title, | |
410 | const wxPoint& pos, const wxSize& size, long style, const wxString& name): | |
411 | wxFrame(parent, -1, title, pos, size, style, name) | |
412 | { | |
413 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
34da0970 JS |
414 | m_printPreview = preview; |
415 | m_controlBar = NULL; | |
416 | m_previewCanvas = NULL; | |
c801d85f KB |
417 | #endif |
418 | } | |
419 | ||
34da0970 | 420 | wxPreviewFrame::~wxPreviewFrame() |
c801d85f KB |
421 | { |
422 | } | |
423 | ||
34da0970 | 424 | bool wxPreviewFrame::OnClose() |
c801d85f KB |
425 | { |
426 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
427 | ||
428 | MakeModal(FALSE); | |
429 | ||
430 | // Need to delete the printout and the print preview | |
34da0970 | 431 | wxPrintout *printout = m_printPreview->GetPrintout(); |
c801d85f KB |
432 | if (printout) |
433 | { | |
434 | delete printout; | |
34da0970 JS |
435 | m_printPreview->SetPrintout(NULL); |
436 | m_printPreview->SetCanvas(NULL); | |
437 | m_printPreview->SetFrame(NULL); | |
c801d85f | 438 | } |
34da0970 | 439 | delete m_printPreview; |
c801d85f | 440 | return TRUE; |
aad5220b JS |
441 | #else |
442 | return FALSE; | |
c801d85f KB |
443 | #endif |
444 | } | |
445 | ||
34da0970 | 446 | void wxPreviewFrame::Initialize() |
c801d85f KB |
447 | { |
448 | ||
449 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
450 | ||
451 | CreateStatusBar(); | |
452 | ||
453 | CreateCanvas(); | |
454 | CreateControlBar(); | |
455 | ||
34da0970 JS |
456 | m_printPreview->SetCanvas(m_previewCanvas); |
457 | m_printPreview->SetFrame(this); | |
c801d85f KB |
458 | |
459 | // Set layout constraints here | |
460 | ||
461 | // Control bar constraints | |
462 | wxLayoutConstraints *c1 = new wxLayoutConstraints; | |
463 | // int w, h; | |
34da0970 | 464 | // m_controlBar->GetSize(&w, &h); |
c801d85f | 465 | int h; |
2049ba38 | 466 | #ifdef __WXMSW__ |
c801d85f KB |
467 | h = 40; |
468 | #else | |
469 | h = 60; | |
470 | #endif | |
471 | ||
472 | c1->left.SameAs (this, wxLeft); | |
473 | c1->top.SameAs (this, wxTop); | |
474 | c1->right.SameAs (this, wxRight); | |
475 | c1->height.Absolute (h); | |
476 | ||
34da0970 | 477 | m_controlBar->SetConstraints(c1); |
c801d85f KB |
478 | |
479 | // Canvas constraints | |
480 | wxLayoutConstraints *c2 = new wxLayoutConstraints; | |
481 | ||
482 | c2->left.SameAs (this, wxLeft); | |
34da0970 | 483 | c2->top.Below (m_controlBar); |
c801d85f KB |
484 | c2->right.SameAs (this, wxRight); |
485 | c2->bottom.SameAs (this, wxBottom); | |
486 | ||
34da0970 | 487 | m_previewCanvas->SetConstraints(c2); |
c801d85f KB |
488 | |
489 | SetAutoLayout(TRUE); | |
490 | ||
491 | MakeModal(TRUE); | |
492 | ||
493 | Layout(); | |
494 | ||
495 | #endif | |
496 | } | |
497 | ||
34da0970 | 498 | void wxPreviewFrame::CreateCanvas() |
c801d85f KB |
499 | { |
500 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
501 | ||
34da0970 | 502 | m_previewCanvas = new wxPreviewCanvas(m_printPreview, this); |
c801d85f KB |
503 | |
504 | #endif | |
505 | } | |
506 | ||
34da0970 | 507 | void wxPreviewFrame::CreateControlBar() |
c801d85f KB |
508 | { |
509 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
510 | ||
511 | long buttons = wxPREVIEW_DEFAULT; | |
34da0970 | 512 | if (m_printPreview->GetPrintoutForPrinting()) |
c801d85f KB |
513 | buttons |= wxPREVIEW_PRINT; |
514 | ||
34da0970 JS |
515 | m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0, 0), wxSize(400, 40)); |
516 | m_controlBar->CreateButtons(); | |
c801d85f KB |
517 | #endif |
518 | } | |
519 | ||
520 | /* | |
521 | * Print preview | |
522 | */ | |
523 | ||
524 | wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data) | |
525 | { | |
526 | ||
527 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
528 | ||
34da0970 JS |
529 | m_isOk = TRUE; |
530 | m_previewPrintout = printout; | |
531 | if (m_previewPrintout) | |
532 | m_previewPrintout->SetIsPreview(TRUE); | |
c801d85f | 533 | |
34da0970 | 534 | m_printPrintout = printoutForPrinting; |
c801d85f | 535 | if (data) |
34da0970 JS |
536 | m_printData = (*data); |
537 | ||
538 | m_previewCanvas = NULL; | |
539 | m_previewFrame = NULL; | |
540 | m_previewBitmap = NULL; | |
541 | m_currentPage = 1; | |
542 | m_currentZoom = 30; | |
543 | m_topMargin = 40; | |
544 | m_leftMargin = 40; | |
545 | m_pageWidth = 0; | |
546 | m_pageHeight = 0; | |
c801d85f KB |
547 | |
548 | printout->OnPreparePrinting(); | |
549 | ||
550 | // Get some parameters from the printout, if defined | |
551 | int selFrom, selTo; | |
34da0970 | 552 | printout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo); |
c801d85f KB |
553 | |
554 | #endif | |
555 | } | |
556 | ||
34da0970 | 557 | wxPrintPreviewBase::~wxPrintPreviewBase() |
c801d85f KB |
558 | { |
559 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
560 | ||
34da0970 JS |
561 | if (m_previewPrintout) |
562 | delete m_previewPrintout; | |
563 | if (m_previewBitmap) | |
564 | delete m_previewBitmap; | |
565 | if (m_printPrintout) | |
566 | delete m_printPrintout; | |
c801d85f KB |
567 | |
568 | #endif | |
569 | } | |
570 | ||
571 | bool wxPrintPreviewBase::SetCurrentPage(int pageNum) | |
572 | { | |
573 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
34da0970 | 574 | if (m_currentPage == pageNum) |
c801d85f KB |
575 | return TRUE; |
576 | ||
34da0970 JS |
577 | m_currentPage = pageNum; |
578 | if (m_previewBitmap) | |
c801d85f | 579 | { |
34da0970 JS |
580 | delete m_previewBitmap; |
581 | m_previewBitmap = NULL; | |
c801d85f KB |
582 | } |
583 | ||
34da0970 | 584 | if (m_previewCanvas) |
c801d85f KB |
585 | { |
586 | RenderPage(pageNum); | |
34da0970 | 587 | m_previewCanvas->Refresh(); |
c801d85f KB |
588 | } |
589 | ||
590 | #endif | |
591 | return TRUE; | |
592 | } | |
593 | ||
594 | bool wxPrintPreviewBase::PaintPage(wxWindow *canvas, wxDC& dc) | |
595 | { | |
596 | ||
597 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
598 | ||
599 | DrawBlankPage(canvas, dc); | |
600 | ||
34da0970 JS |
601 | if (!m_previewBitmap) |
602 | RenderPage(m_currentPage); | |
c801d85f | 603 | |
34da0970 | 604 | if (!m_previewBitmap) |
c801d85f KB |
605 | return FALSE; |
606 | ||
607 | if (!canvas) | |
608 | return FALSE; | |
609 | ||
610 | int canvasWidth, canvasHeight; | |
611 | canvas->GetSize(&canvasWidth, &canvasHeight); | |
612 | ||
34da0970 JS |
613 | double zoomScale = ((float)m_currentZoom/(float)100); |
614 | double actualWidth = (zoomScale*m_pageWidth*m_previewScale); | |
615 | // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale); | |
c801d85f | 616 | |
341287bf | 617 | int x = (int) ((canvasWidth - actualWidth)/2.0); |
34da0970 JS |
618 | if (x < m_leftMargin) |
619 | x = m_leftMargin; | |
620 | int y = m_topMargin; | |
c801d85f KB |
621 | |
622 | wxMemoryDC temp_dc; | |
34da0970 | 623 | temp_dc.SelectObject(*m_previewBitmap); |
c801d85f | 624 | |
34da0970 | 625 | dc.Blit(x, y, m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0); |
c801d85f KB |
626 | |
627 | temp_dc.SelectObject(wxNullBitmap); | |
628 | ||
629 | #endif | |
630 | ||
631 | return TRUE; | |
632 | } | |
633 | ||
634 | bool wxPrintPreviewBase::RenderPage(int pageNum) | |
635 | { | |
636 | int canvasWidth, canvasHeight; | |
637 | ||
638 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
639 | ||
34da0970 | 640 | if (!m_previewCanvas) |
c801d85f | 641 | { |
1a5a8367 DP |
642 | wxMessageBox(_("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"), |
643 | _("Print Preview Failure"), wxOK); | |
c801d85f KB |
644 | return FALSE; |
645 | } | |
34da0970 | 646 | m_previewCanvas->GetSize(&canvasWidth, &canvasHeight); |
c801d85f | 647 | |
34da0970 JS |
648 | double zoomScale = (m_currentZoom/100.0); |
649 | int actualWidth = (int)(zoomScale*m_pageWidth*m_previewScale); | |
650 | int actualHeight = (int)(zoomScale*m_pageHeight*m_previewScale); | |
c801d85f | 651 | |
34da0970 JS |
652 | int x = (int)((canvasWidth - actualWidth)/2.0); |
653 | if (x < m_leftMargin) | |
654 | x = m_leftMargin; | |
655 | // int y = m_topMargin; | |
c801d85f KB |
656 | |
657 | ||
34da0970 | 658 | if (!m_previewBitmap) |
c801d85f | 659 | { |
34da0970 JS |
660 | m_previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight); |
661 | if (!m_previewBitmap || !m_previewBitmap->Ok()) | |
c801d85f | 662 | { |
34da0970 JS |
663 | if (m_previewBitmap) |
664 | delete m_previewBitmap; | |
1a5a8367 | 665 | wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK); |
c801d85f KB |
666 | return FALSE; |
667 | } | |
668 | } | |
669 | ||
670 | wxMemoryDC memoryDC; | |
34da0970 | 671 | memoryDC.SelectObject(*m_previewBitmap); |
c801d85f KB |
672 | |
673 | memoryDC.Clear(); | |
674 | ||
34da0970 JS |
675 | m_previewPrintout->SetDC(&memoryDC); |
676 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); | |
c801d85f | 677 | |
34da0970 | 678 | m_previewPrintout->OnBeginPrinting(); |
c801d85f KB |
679 | |
680 | ||
34da0970 | 681 | if (!m_previewPrintout->OnBeginDocument(m_printData.GetFromPage(), m_printData.GetToPage())) |
c801d85f | 682 | { |
1a5a8367 | 683 | wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK); |
c801d85f KB |
684 | |
685 | memoryDC.SelectObject(wxNullBitmap); | |
686 | ||
34da0970 | 687 | delete m_previewBitmap; |
c801d85f KB |
688 | return FALSE; |
689 | } | |
690 | ||
34da0970 JS |
691 | m_previewPrintout->OnPrintPage(pageNum); |
692 | m_previewPrintout->OnEndDocument(); | |
693 | m_previewPrintout->OnEndPrinting(); | |
c801d85f | 694 | |
34da0970 | 695 | m_previewPrintout->SetDC(NULL); |
c801d85f KB |
696 | |
697 | memoryDC.SelectObject(wxNullBitmap); | |
698 | #endif | |
699 | ||
700 | char buf[200]; | |
34da0970 JS |
701 | if (m_maxPage != 0) |
702 | sprintf(buf, _("Page %d of %d"), pageNum, m_maxPage); | |
c801d85f | 703 | else |
1a5a8367 | 704 | sprintf(buf, _("Page %d"), pageNum); |
c801d85f | 705 | |
34da0970 JS |
706 | if (m_previewFrame) |
707 | m_previewFrame->SetStatusText(buf); | |
c801d85f KB |
708 | |
709 | return TRUE; | |
710 | } | |
711 | ||
712 | ||
713 | bool wxPrintPreviewBase::DrawBlankPage(wxWindow *canvas, wxDC& dc) | |
714 | { | |
715 | ||
716 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
717 | ||
718 | int canvasWidth, canvasHeight; | |
719 | canvas->GetSize(&canvasWidth, &canvasHeight); | |
720 | ||
34da0970 JS |
721 | float zoomScale = (float)((float)m_currentZoom/(float)100); |
722 | float actualWidth = zoomScale*m_pageWidth*m_previewScale; | |
723 | float actualHeight = zoomScale*m_pageHeight*m_previewScale; | |
c801d85f KB |
724 | |
725 | float x = (float)((canvasWidth - actualWidth)/2.0); | |
34da0970 JS |
726 | if (x < m_leftMargin) |
727 | x = (float)m_leftMargin; | |
728 | float y = (float)m_topMargin; | |
c801d85f KB |
729 | |
730 | // Draw shadow, allowing for 1-pixel border AROUND the actual page | |
731 | int shadowOffset = 4; | |
732 | dc.SetPen(*wxBLACK_PEN); | |
733 | dc.SetBrush(*wxBLACK_BRUSH); | |
a4294b78 | 734 | dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2)); |
c801d85f KB |
735 | |
736 | // Draw blank page allowing for 1-pixel border AROUND the actual page | |
737 | dc.SetPen(*wxBLACK_PEN); | |
738 | dc.SetBrush(*wxWHITE_BRUSH); | |
739 | ||
740 | ||
a4294b78 | 741 | dc.DrawRectangle((int)(x-1), (int)(y-1), (int)(actualWidth+2), (int)(actualHeight+2)); |
c801d85f KB |
742 | |
743 | #endif | |
744 | ||
745 | return TRUE; | |
746 | } | |
747 | ||
748 | void wxPrintPreviewBase::SetZoom(int percent) | |
749 | { | |
750 | #ifdef __GOOD_COMPILER__ // Robert Roebling | |
34da0970 | 751 | if (m_currentZoom == percent) |
c801d85f KB |
752 | return; |
753 | ||
34da0970 JS |
754 | m_currentZoom = percent; |
755 | if (m_previewBitmap) | |
c801d85f | 756 | { |
34da0970 JS |
757 | delete m_previewBitmap; |
758 | m_previewBitmap = NULL; | |
c801d85f | 759 | } |
34da0970 | 760 | RenderPage(m_currentPage); |
c801d85f | 761 | |
34da0970 | 762 | if (m_previewCanvas) |
c801d85f | 763 | { |
34da0970 JS |
764 | m_previewCanvas->Clear(); |
765 | m_previewCanvas->Refresh(); | |
c801d85f KB |
766 | } |
767 | #endif | |
768 | ||
769 | } |