]> git.saurik.com Git - wxWidgets.git/blob - src/common/prntbase.cpp
Doc mods; fixed return non-processing problem; fixed toolbar sizing problems
[wxWidgets.git] / src / common / prntbase.cpp
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
23 #include "wx/defs.h"
24
25 #ifndef WX_PRECOMP
26 #include "wx/utils.h"
27 #include "wx/dc.h"
28 #include "wx/app.h"
29 #include "wx/msgdlg.h"
30 #include "wx/layout.h"
31 #include "wx/choice.h"
32 #include "wx/button.h"
33 #include "wx/settings.h"
34 #include "wx/dcmemory.h"
35 #include "wx/stattext.h"
36 #include "wx/intl.h"
37 #endif
38
39 #include "wx/prntbase.h"
40 #include "wx/dcprint.h"
41 #include "wx/printdlg.h"
42 #include "wx/module.h"
43
44 #include <stdlib.h>
45 #include <string.h>
46
47 #ifdef __WXMSW__
48 #include <windows.h>
49 #include <commdlg.h>
50
51 // Clash with Windows header files
52 #ifdef StartDoc
53 #undef StartDoc
54 #endif
55
56 #ifndef __WIN32__
57 #include <print.h>
58 #endif
59
60 #endif
61 // End __WXMSW__
62
63 #if !USE_SHARED_LIBRARY
64 IMPLEMENT_CLASS(wxPrinterBase, wxObject)
65 IMPLEMENT_ABSTRACT_CLASS(wxPrintout, wxObject)
66 IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow)
67 IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow)
68 IMPLEMENT_CLASS(wxPreviewFrame, wxFrame)
69 IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject)
70 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject)
71
72 BEGIN_EVENT_TABLE(wxPrintAbortDialog, wxDialog)
73 EVT_BUTTON(wxID_CANCEL, wxPrintAbortDialog::OnCancel)
74 END_EVENT_TABLE()
75
76 BEGIN_EVENT_TABLE(wxPreviewCanvas, wxScrolledWindow)
77 EVT_PAINT(wxPreviewCanvas::OnPaint)
78 EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged)
79 END_EVENT_TABLE()
80 #endif
81
82 /*
83 * Printer
84 */
85
86 wxPrinterBase::wxPrinterBase(wxPrintData *data)
87 {
88 m_currentPrintout = (wxPrintout *) NULL;
89 sm_abortWindow = (wxWindow *) NULL;
90 sm_abortIt = FALSE;
91 if (data)
92 m_printData = (*data);
93 }
94
95 wxWindow *wxPrinterBase::sm_abortWindow = (wxWindow *) NULL;
96 bool wxPrinterBase::sm_abortIt = FALSE;
97
98 wxPrinterBase::~wxPrinterBase()
99 {
100 }
101
102 void wxPrintAbortDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
103 {
104 wxPrinterBase::sm_abortIt = TRUE;
105 wxPrinterBase::sm_abortWindow->Show(FALSE);
106 wxPrinterBase::sm_abortWindow->Close(TRUE);
107 wxPrinterBase::sm_abortWindow = (wxWindow *) NULL;
108 }
109
110 wxWindow *wxPrinterBase::CreateAbortWindow(wxWindow *parent, wxPrintout *WXUNUSED(printout))
111 {
112 wxPrintAbortDialog *dialog = new wxPrintAbortDialog(parent, _("Printing"), wxPoint(0, 0), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE);
113 (void) new wxStaticText(dialog, -1, _("Please wait..."), wxPoint(5, 5));
114
115 wxButton *button = new wxButton(dialog, wxID_CANCEL, _("Cancel"), wxPoint(5, 30));
116
117 dialog->Fit();
118 button->Centre(wxHORIZONTAL);
119
120 dialog->Centre();
121 return dialog;
122 }
123
124 void wxPrinterBase::ReportError(wxWindow *parent, wxPrintout *WXUNUSED(printout), char *message)
125 {
126 wxMessageBox(message, _("Printing Error"), wxOK, parent);
127 }
128
129 /*
130 * Printout class
131 */
132
133 wxPrintout::wxPrintout(const wxString& title)
134 {
135 m_printoutTitle = title ;
136 m_printoutDC = (wxDC *) NULL;
137 m_pageWidthMM = 0;
138 m_pageHeightMM = 0;
139 m_pageWidthPixels = 0;
140 m_pageHeightPixels = 0;
141 m_PPIScreenX = 0;
142 m_PPIScreenY = 0;
143 m_PPIPrinterX = 0;
144 m_PPIPrinterY = 0;
145 m_isPreview = FALSE;
146 }
147
148 wxPrintout::~wxPrintout()
149 {
150 }
151
152 bool wxPrintout::OnBeginDocument(int WXUNUSED(startPage), int WXUNUSED(endPage))
153 {
154 return GetDC()->StartDoc(_("Printing"));
155 }
156
157 void wxPrintout::OnEndDocument()
158 {
159 GetDC()->EndDoc();
160 }
161
162 void wxPrintout::OnBeginPrinting()
163 {
164 }
165
166 void wxPrintout::OnEndPrinting()
167 {
168 }
169
170 bool wxPrintout::HasPage(int page)
171 {
172 return (page == 1);
173 }
174
175 void wxPrintout::GetPageInfo(int *minPage, int *maxPage, int *fromPage, int *toPage)
176 {
177 *minPage = 1;
178 *maxPage = 32000;
179 *fromPage = 1;
180 *toPage = 1;
181 }
182
183 /*
184 * Preview canvas
185 */
186
187 wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent,
188 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
189 wxScrolledWindow(parent, -1, pos, size, style, name)
190 {
191 m_printPreview = preview;
192 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
193
194 SetScrollbars(15, 18, 100, 100);
195 }
196
197 wxPreviewCanvas::~wxPreviewCanvas()
198 {
199 }
200
201 void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
202 {
203 wxPaintDC dc(this);
204 PrepareDC( dc );
205
206 if (m_printPreview)
207 {
208 m_printPreview->PaintPage(this, dc);
209 }
210 }
211
212 // Responds to colour changes, and passes event on to children.
213 void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event)
214 {
215 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
216 Refresh();
217
218 // Propagate the event to the non-top-level children
219 wxWindow::OnSysColourChanged(event);
220 }
221
222 /*
223 * Preview control bar
224 */
225
226 BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel)
227 EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnWindowClose)
228 EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrint)
229 EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPrevious)
230 EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNext)
231 EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom)
232 EVT_PAINT(wxPreviewControlBar::OnPaint)
233 END_EVENT_TABLE()
234
235 wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons,
236 wxWindow *parent, const wxPoint& pos, const wxSize& size,
237 long style, const wxString& name):
238 wxPanel(parent, -1, pos, size, style, name)
239 {
240 m_printPreview = preview;
241 m_closeButton = (wxButton *) NULL;
242 m_nextPageButton = (wxButton *) NULL;
243 m_previousPageButton = (wxButton *) NULL;
244 m_printButton = (wxButton *) NULL;
245 m_zoomControl = (wxChoice *) NULL;
246 m_buttonFlags = buttons;
247 }
248
249 wxPreviewControlBar::~wxPreviewControlBar()
250 {
251 }
252
253 void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event))
254 {
255 wxPaintDC dc(this);
256
257 int w, h;
258 GetSize(&w, &h);
259 dc.SetPen(*wxBLACK_PEN);
260 dc.SetBrush(*wxTRANSPARENT_BRUSH);
261 dc.DrawLine( 0, h-1, w, h-1 );
262 }
263
264 void wxPreviewControlBar::OnWindowClose(wxCommandEvent& WXUNUSED(event))
265 {
266 wxPreviewFrame *frame = (wxPreviewFrame *)GetParent();
267 frame->Close(TRUE);
268 }
269
270 void wxPreviewControlBar::OnPrint(wxCommandEvent& WXUNUSED(event))
271 {
272 wxPrintPreviewBase *preview = GetPrintPreview();
273 preview->Print(TRUE);
274 }
275
276 void wxPreviewControlBar::OnNext(wxCommandEvent& WXUNUSED(event))
277 {
278 wxPrintPreviewBase *preview = GetPrintPreview();
279 if (preview)
280 {
281 int currentPage = preview->GetCurrentPage();
282 if ((preview->GetMaxPage() > 0) &&
283 (currentPage < preview->GetMaxPage()) &&
284 preview->GetPrintout()->HasPage(currentPage + 1))
285 {
286 preview->SetCurrentPage(currentPage + 1);
287 }
288 }
289 }
290
291 void wxPreviewControlBar::OnPrevious(wxCommandEvent& WXUNUSED(event))
292 {
293 wxPrintPreviewBase *preview = GetPrintPreview();
294 if (preview)
295 {
296 int currentPage = preview->GetCurrentPage();
297 if ((preview->GetMinPage() > 0) &&
298 (currentPage > preview->GetMinPage()) &&
299 preview->GetPrintout()->HasPage(currentPage - 1))
300 {
301 preview->SetCurrentPage(currentPage - 1);
302 }
303 }
304 }
305
306 void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event))
307 {
308 int zoom = GetZoomControl();
309 if (GetPrintPreview())
310 GetPrintPreview()->SetZoom(zoom);
311 }
312
313 void wxPreviewControlBar::CreateButtons()
314 {
315 SetSize(0, 0, 400, 40);
316
317 /*
318 #ifdef __WXMSW__
319 int fontSize = 9;
320 #else
321 int fontSize = 10;
322 #endif
323
324 wxFont buttonFont(fontSize, wxSWISS, wxNORMAL, wxBOLD);
325 SetFont(buttonFont);
326 */
327
328 int buttonWidth = 65;
329 #ifdef __WXGTK__
330 int buttonHeight = -1;
331 #else
332 int buttonHeight = 24;
333 #endif
334
335 int x = 5;
336 int y = 5;
337
338 #ifdef __WXMOTIF__
339 int gap = 15;
340 #else
341 int gap = 5;
342 #endif
343
344 m_closeButton = new wxButton(this, wxID_PREVIEW_CLOSE, _("Close"),
345 wxPoint(x, y), wxSize(buttonWidth, buttonHeight));
346
347 x += gap + buttonWidth;
348
349 if (m_buttonFlags & wxPREVIEW_PRINT)
350 {
351 m_printButton = new wxButton(this, wxID_PREVIEW_PRINT, _("Print..."), wxPoint(x, y),
352 wxSize(buttonWidth, buttonHeight));
353 x += gap + buttonWidth;
354 }
355
356 if (m_buttonFlags & wxPREVIEW_PREVIOUS)
357 {
358 m_previousPageButton = new wxButton(this, wxID_PREVIEW_PREVIOUS, "<<", wxPoint(x, y),
359 wxSize(buttonWidth, buttonHeight));
360 x += gap + buttonWidth;
361 }
362
363 if (m_buttonFlags & wxPREVIEW_NEXT)
364 {
365 m_nextPageButton = new wxButton(this, wxID_PREVIEW_NEXT, ">>",
366 wxPoint(x, y), wxSize(buttonWidth, buttonHeight));
367 x += gap + buttonWidth;
368 }
369
370 // Yes, this look stupid, but this is because gcc gives up otherwise.
371 wxString *choices = new wxString[23];
372 choices[0] = "10%";
373 choices[1] = "15%";
374 choices[2] = "20%";
375 choices[3] = "25%";
376 choices[4] = "30%";
377 choices[5] = "35%";
378 choices[6] = "40%";
379 choices[7] = "45%";
380 choices[8] = "50%";
381 choices[9] = "55%";
382 choices[10] = "60%";
383 choices[11] = "65%";
384 choices[12] = "70%";
385 choices[13] = "75%";
386 choices[14] = "80%";
387 choices[15] = "85%";
388 choices[16] = "90%";
389 choices[17] = "95%";
390 choices[18] = "100%";
391 choices[19] = "110%";
392 choices[20] = "120%";
393 choices[21] = "150%";
394 choices[22] = "200%";
395
396 int n = 23;
397 if (m_buttonFlags & wxPREVIEW_ZOOM)
398 {
399 m_zoomControl = new wxChoice(this, wxID_PREVIEW_ZOOM, wxPoint(x, y),
400 wxSize(100, -1), n, (wxString *)choices);
401 SetZoomControl(m_printPreview->GetZoom());
402 }
403
404 delete[] choices;
405
406 // m_closeButton->SetDefault();
407 }
408
409 void wxPreviewControlBar::SetZoomControl(int zoom)
410 {
411 char buf[20];
412 sprintf(buf, "%d%%", zoom);
413 if (m_zoomControl)
414 m_zoomControl->SetStringSelection(buf);
415 }
416
417 int wxPreviewControlBar::GetZoomControl()
418 {
419 char buf[20];
420 if (m_zoomControl && (m_zoomControl->GetStringSelection() != ""))
421 {
422 strcpy(buf, m_zoomControl->GetStringSelection());
423 buf[strlen(buf) - 1] = 0;
424 return (int)atoi(buf);
425 }
426 else return 0;
427 }
428
429
430 /*
431 * Preview frame
432 */
433
434 BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame)
435 EVT_CLOSE(wxPreviewFrame::OnCloseWindow)
436 END_EVENT_TABLE()
437
438 wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxFrame *parent, const wxString& title,
439 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
440 wxFrame(parent, -1, title, pos, size, style, name)
441 {
442 m_printPreview = preview;
443 m_controlBar = NULL;
444 m_previewCanvas = NULL;
445 }
446
447 wxPreviewFrame::~wxPreviewFrame()
448 {
449 }
450
451 void wxPreviewFrame::OnCloseWindow(wxCloseEvent& event)
452 {
453 MakeModal(FALSE);
454
455 // Need to delete the printout and the print preview
456 wxPrintout *printout = m_printPreview->GetPrintout();
457 if (printout)
458 {
459 delete printout;
460 m_printPreview->SetPrintout(NULL);
461 m_printPreview->SetCanvas(NULL);
462 m_printPreview->SetFrame(NULL);
463 }
464 delete m_printPreview;
465
466 Destroy();
467 }
468
469 void wxPreviewFrame::Initialize()
470 {
471 CreateStatusBar();
472
473 CreateCanvas();
474 CreateControlBar();
475
476 m_printPreview->SetCanvas(m_previewCanvas);
477 m_printPreview->SetFrame(this);
478
479 // Set layout constraints here
480
481 // Control bar constraints
482 wxLayoutConstraints *c1 = new wxLayoutConstraints;
483 // int w, h;
484 // m_controlBar->GetSize(&w, &h);
485 int h;
486 #if (defined(__WXMSW__) || defined(__WXGTK__))
487 h = 40;
488 #else
489 h = 60;
490 #endif
491
492 c1->left.SameAs (this, wxLeft);
493 c1->top.SameAs (this, wxTop);
494 c1->right.SameAs (this, wxRight);
495 c1->height.Absolute (h);
496
497 m_controlBar->SetConstraints(c1);
498
499 // Canvas constraints
500 wxLayoutConstraints *c2 = new wxLayoutConstraints;
501
502 c2->left.SameAs (this, wxLeft);
503 c2->top.Below (m_controlBar);
504 c2->right.SameAs (this, wxRight);
505 c2->bottom.SameAs (this, wxBottom);
506
507 m_previewCanvas->SetConstraints(c2);
508
509 SetAutoLayout(TRUE);
510
511 MakeModal(TRUE);
512
513 Layout();
514 }
515
516 void wxPreviewFrame::CreateCanvas()
517 {
518 m_previewCanvas = new wxPreviewCanvas(m_printPreview, this);
519 }
520
521 void wxPreviewFrame::CreateControlBar()
522 {
523 long buttons = wxPREVIEW_DEFAULT;
524 if (m_printPreview->GetPrintoutForPrinting())
525 buttons |= wxPREVIEW_PRINT;
526
527 m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0, 0), wxSize(400, 40));
528 m_controlBar->CreateButtons();
529 }
530
531 /*
532 * Print preview
533 */
534
535 wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data)
536 {
537 m_isOk = TRUE;
538 m_previewPrintout = printout;
539 if (m_previewPrintout)
540 m_previewPrintout->SetIsPreview(TRUE);
541
542 m_printPrintout = printoutForPrinting;
543 if (data)
544 m_printData = (*data);
545
546 m_previewCanvas = NULL;
547 m_previewFrame = NULL;
548 m_previewBitmap = NULL;
549 m_currentPage = 1;
550 m_currentZoom = 30;
551 m_topMargin = 40;
552 m_leftMargin = 40;
553 m_pageWidth = 0;
554 m_pageHeight = 0;
555
556 printout->OnPreparePrinting();
557
558 // Get some parameters from the printout, if defined
559 int selFrom, selTo;
560 printout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo);
561 }
562
563 wxPrintPreviewBase::~wxPrintPreviewBase()
564 {
565 if (m_previewPrintout)
566 delete m_previewPrintout;
567 if (m_previewBitmap)
568 delete m_previewBitmap;
569 if (m_printPrintout)
570 delete m_printPrintout;
571 }
572
573 bool wxPrintPreviewBase::SetCurrentPage(int pageNum)
574 {
575 if (m_currentPage == pageNum)
576 return TRUE;
577
578 m_currentPage = pageNum;
579 if (m_previewBitmap)
580 {
581 delete m_previewBitmap;
582 m_previewBitmap = NULL;
583 }
584
585 if (m_previewCanvas)
586 {
587 RenderPage(pageNum);
588 m_previewCanvas->Refresh();
589 }
590 return TRUE;
591 }
592
593 bool wxPrintPreviewBase::PaintPage(wxWindow *canvas, wxDC& dc)
594 {
595 DrawBlankPage(canvas, dc);
596
597 if (!m_previewBitmap)
598 RenderPage(m_currentPage);
599
600 if (!m_previewBitmap)
601 return FALSE;
602
603 if (!canvas)
604 return FALSE;
605
606 int canvasWidth, canvasHeight;
607 canvas->GetSize(&canvasWidth, &canvasHeight);
608
609 double zoomScale = ((float)m_currentZoom/(float)100);
610 double actualWidth = (zoomScale*m_pageWidth*m_previewScale);
611 // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale);
612
613 int x = (int) ((canvasWidth - actualWidth)/2.0);
614 if (x < m_leftMargin)
615 x = m_leftMargin;
616 int y = m_topMargin;
617
618 wxMemoryDC temp_dc;
619 temp_dc.SelectObject(*m_previewBitmap);
620
621 dc.Blit(x, y, m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0);
622
623 temp_dc.SelectObject(wxNullBitmap);
624
625 return TRUE;
626 }
627
628 bool wxPrintPreviewBase::RenderPage(int pageNum)
629 {
630 int canvasWidth, canvasHeight;
631
632 if (!m_previewCanvas)
633 {
634 wxMessageBox(_("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"),
635 _("Print Preview Failure"), wxOK);
636 return FALSE;
637 }
638 m_previewCanvas->GetSize(&canvasWidth, &canvasHeight);
639
640 double zoomScale = (m_currentZoom/100.0);
641 int actualWidth = (int)(zoomScale*m_pageWidth*m_previewScale);
642 int actualHeight = (int)(zoomScale*m_pageHeight*m_previewScale);
643
644 int x = (int)((canvasWidth - actualWidth)/2.0);
645 if (x < m_leftMargin)
646 x = m_leftMargin;
647 // int y = m_topMargin;
648
649
650 if (!m_previewBitmap)
651 {
652 m_previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight);
653 if (!m_previewBitmap || !m_previewBitmap->Ok())
654 {
655 if (m_previewBitmap)
656 delete m_previewBitmap;
657 wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK);
658 return FALSE;
659 }
660 }
661
662 wxMemoryDC memoryDC;
663 memoryDC.SelectObject(*m_previewBitmap);
664
665 memoryDC.Clear();
666
667 m_previewPrintout->SetDC(&memoryDC);
668 m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
669
670 m_previewPrintout->OnBeginPrinting();
671
672
673 if (!m_previewPrintout->OnBeginDocument(m_printData.GetFromPage(), m_printData.GetToPage()))
674 {
675 wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK);
676
677 memoryDC.SelectObject(wxNullBitmap);
678
679 delete m_previewBitmap;
680 return FALSE;
681 }
682
683 m_previewPrintout->OnPrintPage(pageNum);
684 m_previewPrintout->OnEndDocument();
685 m_previewPrintout->OnEndPrinting();
686
687 m_previewPrintout->SetDC(NULL);
688
689 memoryDC.SelectObject(wxNullBitmap);
690
691 char buf[200];
692 if (m_maxPage != 0)
693 sprintf(buf, _("Page %d of %d"), pageNum, m_maxPage);
694 else
695 sprintf(buf, _("Page %d"), pageNum);
696
697 if (m_previewFrame)
698 m_previewFrame->SetStatusText(buf);
699
700 return TRUE;
701 }
702
703
704 bool wxPrintPreviewBase::DrawBlankPage(wxWindow *canvas, wxDC& dc)
705 {
706 int canvasWidth, canvasHeight;
707 canvas->GetSize(&canvasWidth, &canvasHeight);
708
709 float zoomScale = (float)((float)m_currentZoom/(float)100);
710 float actualWidth = zoomScale*m_pageWidth*m_previewScale;
711 float actualHeight = zoomScale*m_pageHeight*m_previewScale;
712
713 float x = (float)((canvasWidth - actualWidth)/2.0);
714 if (x < m_leftMargin)
715 x = (float)m_leftMargin;
716 float y = (float)m_topMargin;
717
718 // Draw shadow, allowing for 1-pixel border AROUND the actual page
719 int shadowOffset = 4;
720 dc.SetPen(*wxBLACK_PEN);
721 dc.SetBrush(*wxBLACK_BRUSH);
722 /*
723 dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2));
724 */
725 dc.DrawRectangle((int)(x + shadowOffset), (int)(y + actualHeight+1), (int)(actualWidth), shadowOffset);
726 dc.DrawRectangle((int)(x + actualWidth), (int)(y + shadowOffset), shadowOffset, (int)(actualHeight));
727
728 // Draw blank page allowing for 1-pixel border AROUND the actual page
729 dc.SetPen(*wxBLACK_PEN);
730 dc.SetBrush(*wxWHITE_BRUSH);
731
732 /*
733 wxRegion update_region = canvas->GetUpdateRegion();
734 wxRect r = update_region.GetBox();
735
736 printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height );
737 */
738
739 dc.DrawRectangle((int)(x-2), (int)(y-1), (int)(actualWidth+3), (int)(actualHeight+2));
740
741 return TRUE;
742 }
743
744 void wxPrintPreviewBase::SetZoom(int percent)
745 {
746 if (m_currentZoom == percent)
747 return;
748
749 m_currentZoom = percent;
750 if (m_previewBitmap)
751 {
752 delete m_previewBitmap;
753 m_previewBitmap = NULL;
754 }
755 RenderPage(m_currentPage);
756
757 if (m_previewCanvas)
758 {
759 m_previewCanvas->Clear();
760 m_previewCanvas->Refresh();
761 }
762 }
763
764 /*
765 * Paper size database for PostScript or where the generic page setup dialog is
766 * needed
767 */
768
769 wxPrintPaperType::wxPrintPaperType(const char *name, int wmm, int hmm, int wp, int hp)
770 {
771 widthMM = wmm;
772 heightMM = hmm;
773 widthPixels = wp;
774 heightPixels = hp;
775 pageName = copystring(name);
776 }
777
778 wxPrintPaperType::~wxPrintPaperType()
779 {
780 delete[] pageName;
781 }
782
783 /*
784 * Print paper database for PostScript
785 */
786
787 wxPrintPaperDatabase* wxThePrintPaperDatabase = (wxPrintPaperDatabase*) NULL;
788
789 #if !USE_SHARED_LIBRARIES
790 IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList)
791 #endif
792
793 wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING)
794 {
795 DeleteContents(TRUE);
796 }
797
798 wxPrintPaperDatabase::~wxPrintPaperDatabase()
799 {
800 }
801
802 void wxPrintPaperDatabase::CreateDatabase()
803 {
804 // Need correct values for page size in pixels.
805 // Each unit is one 'point' = 1/72 of an inch.
806 // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING
807 // in wxPostScriptDC code, so we can start from top left.
808 // So access this database and translate by appropriate number
809 // of points for this paper size. OR IS IT OK ALREADY?
810 // Can't remember where the PostScript origin is by default.
811 // Heck, someone will know how to make it hunky-dory...
812 // JACS 25/5/95
813
814 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842);
815 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191);
816 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791);
817 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
818
819 /*
820 This is for 100 ppi
821
822 AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 );
823 AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 );
824 AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 );
825 AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 );
826 */
827 }
828
829 void wxPrintPaperDatabase::ClearDatabase()
830 {
831 Clear();
832 }
833
834 void wxPrintPaperDatabase::AddPaperType(const char *name, int wmm, int hmm, int wp, int hp)
835 {
836 Append(name, new wxPrintPaperType(name, wmm, hmm, wp, hp));
837 }
838
839 wxPrintPaperType *wxPrintPaperDatabase::FindPaperType(const char *name)
840 {
841 wxNode *node = Find(name);
842 if (node)
843 return (wxPrintPaperType *)node->Data();
844 else
845 return (wxPrintPaperType *) NULL;
846 }
847
848 // A module to allow initialization/cleanup of print paper
849 // things without calling these functions from app.cpp.
850
851 class WXDLLEXPORT wxPrintBaseModule: public wxModule
852 {
853 DECLARE_DYNAMIC_CLASS(wxPrintBaseModule)
854 public:
855 wxPrintBaseModule() {}
856 bool OnInit();
857 void OnExit();
858 };
859
860 IMPLEMENT_DYNAMIC_CLASS(wxPrintBaseModule, wxModule)
861
862 /*
863 * Initialization/cleanup module
864 */
865
866 bool wxPrintBaseModule::OnInit()
867 {
868 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
869 wxThePrintPaperDatabase->CreateDatabase();
870
871 return TRUE;
872 }
873
874 void wxPrintBaseModule::OnExit()
875 {
876 delete wxThePrintPaperDatabase;
877 wxThePrintPaperDatabase = NULL;
878 }
879
880