Improve print preview appearance and functionality.
[wxWidgets.git] / include / wx / prntbase.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/prntbase.h
3 // Purpose: Base classes for printing framework
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PRNTBASEH__
13 #define _WX_PRNTBASEH__
14
15 #include "wx/defs.h"
16
17 #if wxUSE_PRINTING_ARCHITECTURE
18
19 #include "wx/event.h"
20 #include "wx/cmndata.h"
21 #include "wx/panel.h"
22 #include "wx/scrolwin.h"
23 #include "wx/dialog.h"
24 #include "wx/frame.h"
25 #include "wx/dc.h"
26
27 class WXDLLIMPEXP_FWD_CORE wxDC;
28 class WXDLLIMPEXP_FWD_CORE wxButton;
29 class WXDLLIMPEXP_FWD_CORE wxChoice;
30 class WXDLLIMPEXP_FWD_CORE wxPrintout;
31 class WXDLLIMPEXP_FWD_CORE wxPrinterBase;
32 class WXDLLIMPEXP_FWD_CORE wxPrintDialogBase;
33 class WXDLLIMPEXP_FWD_CORE wxPrintDialog;
34 class WXDLLIMPEXP_FWD_CORE wxPageSetupDialogBase;
35 class WXDLLIMPEXP_FWD_CORE wxPageSetupDialog;
36 class WXDLLIMPEXP_FWD_CORE wxPrintPreviewBase;
37 class WXDLLIMPEXP_FWD_CORE wxPreviewCanvas;
38 class WXDLLIMPEXP_FWD_CORE wxPreviewControlBar;
39 class WXDLLIMPEXP_FWD_CORE wxPreviewFrame;
40 class WXDLLIMPEXP_FWD_CORE wxPrintFactory;
41 class WXDLLIMPEXP_FWD_CORE wxPrintNativeDataBase;
42 class WXDLLIMPEXP_FWD_CORE wxPrintPreview;
43 class wxPrintPageTextCtrl;
44
45 //----------------------------------------------------------------------------
46 // error consts
47 //----------------------------------------------------------------------------
48
49 enum wxPrinterError
50 {
51 wxPRINTER_NO_ERROR = 0,
52 wxPRINTER_CANCELLED,
53 wxPRINTER_ERROR
54 };
55
56 //----------------------------------------------------------------------------
57 // wxPrintFactory
58 //----------------------------------------------------------------------------
59
60 class WXDLLIMPEXP_CORE wxPrintFactory
61 {
62 public:
63 wxPrintFactory() {}
64 virtual ~wxPrintFactory() {}
65
66 virtual wxPrinterBase *CreatePrinter( wxPrintDialogData* data ) = 0;
67
68 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
69 wxPrintout *printout = NULL,
70 wxPrintDialogData *data = NULL ) = 0;
71 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
72 wxPrintout *printout,
73 wxPrintData *data ) = 0;
74
75 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
76 wxPrintDialogData *data = NULL ) = 0;
77 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
78 wxPrintData *data ) = 0;
79
80 virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
81 wxPageSetupDialogData * data = NULL ) = 0;
82
83 virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) = 0;
84
85 // What to do and what to show in the wxPrintDialog
86 // a) Use the generic print setup dialog or a native one?
87 virtual bool HasPrintSetupDialog() = 0;
88 virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) = 0;
89 // b) Provide the "print to file" option ourselves or via print setup?
90 virtual bool HasOwnPrintToFile() = 0;
91 // c) Show current printer
92 virtual bool HasPrinterLine() = 0;
93 virtual wxString CreatePrinterLine() = 0;
94 // d) Show Status line for current printer?
95 virtual bool HasStatusLine() = 0;
96 virtual wxString CreateStatusLine() = 0;
97
98
99 virtual wxPrintNativeDataBase *CreatePrintNativeData() = 0;
100
101 static void SetPrintFactory( wxPrintFactory *factory );
102 static wxPrintFactory *GetFactory();
103 private:
104 static wxPrintFactory *m_factory;
105 };
106
107 class WXDLLIMPEXP_CORE wxNativePrintFactory: public wxPrintFactory
108 {
109 public:
110 virtual wxPrinterBase *CreatePrinter( wxPrintDialogData *data );
111
112 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
113 wxPrintout *printout = NULL,
114 wxPrintDialogData *data = NULL );
115 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
116 wxPrintout *printout,
117 wxPrintData *data );
118
119 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
120 wxPrintDialogData *data = NULL );
121 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
122 wxPrintData *data );
123
124 virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
125 wxPageSetupDialogData * data = NULL );
126
127 virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data );
128
129 virtual bool HasPrintSetupDialog();
130 virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
131 virtual bool HasOwnPrintToFile();
132 virtual bool HasPrinterLine();
133 virtual wxString CreatePrinterLine();
134 virtual bool HasStatusLine();
135 virtual wxString CreateStatusLine();
136
137 virtual wxPrintNativeDataBase *CreatePrintNativeData();
138 };
139
140 //----------------------------------------------------------------------------
141 // wxPrintNativeDataBase
142 //----------------------------------------------------------------------------
143
144 class WXDLLIMPEXP_CORE wxPrintNativeDataBase: public wxObject
145 {
146 public:
147 wxPrintNativeDataBase();
148 virtual ~wxPrintNativeDataBase() {}
149
150 virtual bool TransferTo( wxPrintData &data ) = 0;
151 virtual bool TransferFrom( const wxPrintData &data ) = 0;
152
153 virtual bool Ok() const { return IsOk(); }
154 virtual bool IsOk() const = 0;
155
156 int m_ref;
157
158 private:
159 DECLARE_CLASS(wxPrintNativeDataBase)
160 wxDECLARE_NO_COPY_CLASS(wxPrintNativeDataBase);
161 };
162
163 //----------------------------------------------------------------------------
164 // wxPrinterBase
165 //----------------------------------------------------------------------------
166
167 /*
168 * Represents the printer: manages printing a wxPrintout object
169 */
170
171 class WXDLLIMPEXP_CORE wxPrinterBase: public wxObject
172 {
173 public:
174 wxPrinterBase(wxPrintDialogData *data = NULL);
175 virtual ~wxPrinterBase();
176
177 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout);
178 virtual void ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message);
179
180 virtual wxPrintDialogData& GetPrintDialogData() const;
181 bool GetAbort() const { return sm_abortIt; }
182
183 static wxPrinterError GetLastError() { return sm_lastError; }
184
185 ///////////////////////////////////////////////////////////////////////////
186 // OVERRIDES
187
188 virtual bool Setup(wxWindow *parent) = 0;
189 virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = true) = 0;
190 virtual wxDC* PrintDialog(wxWindow *parent) = 0;
191
192 protected:
193 wxPrintDialogData m_printDialogData;
194 wxPrintout* m_currentPrintout;
195
196 static wxPrinterError sm_lastError;
197
198 public:
199 static wxWindow* sm_abortWindow;
200 static bool sm_abortIt;
201
202 private:
203 DECLARE_CLASS(wxPrinterBase)
204 wxDECLARE_NO_COPY_CLASS(wxPrinterBase);
205 };
206
207 //----------------------------------------------------------------------------
208 // wxPrinter
209 //----------------------------------------------------------------------------
210
211 class WXDLLIMPEXP_CORE wxPrinter: public wxPrinterBase
212 {
213 public:
214 wxPrinter(wxPrintDialogData *data = NULL);
215 virtual ~wxPrinter();
216
217 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout);
218 virtual void ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message);
219
220 virtual bool Setup(wxWindow *parent);
221 virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = true);
222 virtual wxDC* PrintDialog(wxWindow *parent);
223
224 virtual wxPrintDialogData& GetPrintDialogData() const;
225
226 protected:
227 wxPrinterBase *m_pimpl;
228
229 private:
230 DECLARE_CLASS(wxPrinter)
231 wxDECLARE_NO_COPY_CLASS(wxPrinter);
232 };
233
234 //----------------------------------------------------------------------------
235 // wxPrintout
236 //----------------------------------------------------------------------------
237
238 /*
239 * Represents an object via which a document may be printed.
240 * The programmer derives from this, overrides (at least) OnPrintPage,
241 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
242 * object for previewing.
243 */
244
245 class WXDLLIMPEXP_CORE wxPrintout: public wxObject
246 {
247 public:
248 wxPrintout(const wxString& title = _("Printout"));
249 virtual ~wxPrintout();
250
251 virtual bool OnBeginDocument(int startPage, int endPage);
252 virtual void OnEndDocument();
253 virtual void OnBeginPrinting();
254 virtual void OnEndPrinting();
255
256 // Guaranteed to be before any other functions are called
257 virtual void OnPreparePrinting() { }
258
259 virtual bool HasPage(int page);
260 virtual bool OnPrintPage(int page) = 0;
261 virtual void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo);
262
263 virtual wxString GetTitle() const { return m_printoutTitle; }
264
265 wxDC *GetDC() const { return m_printoutDC; }
266 void SetDC(wxDC *dc) { m_printoutDC = dc; }
267
268 void FitThisSizeToPaper(const wxSize& imageSize);
269 void FitThisSizeToPage(const wxSize& imageSize);
270 void FitThisSizeToPageMargins(const wxSize& imageSize, const wxPageSetupDialogData& pageSetupData);
271 void MapScreenSizeToPaper();
272 void MapScreenSizeToPage();
273 void MapScreenSizeToPageMargins(const wxPageSetupDialogData& pageSetupData);
274 void MapScreenSizeToDevice();
275
276 wxRect GetLogicalPaperRect() const;
277 wxRect GetLogicalPageRect() const;
278 wxRect GetLogicalPageMarginsRect(const wxPageSetupDialogData& pageSetupData) const;
279
280 void SetLogicalOrigin(wxCoord x, wxCoord y);
281 void OffsetLogicalOrigin(wxCoord xoff, wxCoord yoff);
282
283 void SetPageSizePixels(int w, int h) { m_pageWidthPixels = w; m_pageHeightPixels = h; }
284 void GetPageSizePixels(int *w, int *h) const { *w = m_pageWidthPixels; *h = m_pageHeightPixels; }
285 void SetPageSizeMM(int w, int h) { m_pageWidthMM = w; m_pageHeightMM = h; }
286 void GetPageSizeMM(int *w, int *h) const { *w = m_pageWidthMM; *h = m_pageHeightMM; }
287
288 void SetPPIScreen(int x, int y) { m_PPIScreenX = x; m_PPIScreenY = y; }
289 void SetPPIScreen(const wxSize& ppi) { SetPPIScreen(ppi.x, ppi.y); }
290 void GetPPIScreen(int *x, int *y) const { *x = m_PPIScreenX; *y = m_PPIScreenY; }
291 void SetPPIPrinter(int x, int y) { m_PPIPrinterX = x; m_PPIPrinterY = y; }
292 void SetPPIPrinter(const wxSize& ppi) { SetPPIPrinter(ppi.x, ppi.y); }
293 void GetPPIPrinter(int *x, int *y) const { *x = m_PPIPrinterX; *y = m_PPIPrinterY; }
294
295 void SetPaperRectPixels(const wxRect& paperRectPixels) { m_paperRectPixels = paperRectPixels; }
296 wxRect GetPaperRectPixels() const { return m_paperRectPixels; }
297
298 // This must be called by wxPrintPreview to associate itself with the
299 // printout it uses.
300 virtual void SetPreview(wxPrintPreview *preview) { m_preview = preview; }
301
302 wxPrintPreview *GetPreview() const { return m_preview; }
303 virtual bool IsPreview() const { return GetPreview() != NULL; }
304
305 private:
306 wxString m_printoutTitle;
307 wxDC* m_printoutDC;
308 wxPrintPreview *m_preview;
309
310 int m_pageWidthPixels;
311 int m_pageHeightPixels;
312
313 int m_pageWidthMM;
314 int m_pageHeightMM;
315
316 int m_PPIScreenX;
317 int m_PPIScreenY;
318 int m_PPIPrinterX;
319 int m_PPIPrinterY;
320
321 wxRect m_paperRectPixels;
322
323 private:
324 DECLARE_ABSTRACT_CLASS(wxPrintout)
325 wxDECLARE_NO_COPY_CLASS(wxPrintout);
326 };
327
328 //----------------------------------------------------------------------------
329 // wxPreviewCanvas
330 //----------------------------------------------------------------------------
331
332 /*
333 * Canvas upon which a preview is drawn.
334 */
335
336 class WXDLLIMPEXP_CORE wxPreviewCanvas: public wxScrolledWindow
337 {
338 public:
339 wxPreviewCanvas(wxPrintPreviewBase *preview,
340 wxWindow *parent,
341 const wxPoint& pos = wxDefaultPosition,
342 const wxSize& size = wxDefaultSize,
343 long style = 0,
344 const wxString& name = wxT("canvas"));
345 virtual ~wxPreviewCanvas();
346
347 void SetPreview(wxPrintPreviewBase *preview) { m_printPreview = preview; }
348
349 void OnPaint(wxPaintEvent& event);
350 void OnChar(wxKeyEvent &event);
351 // Responds to colour changes
352 void OnSysColourChanged(wxSysColourChangedEvent& event);
353
354 private:
355 #if wxUSE_MOUSEWHEEL
356 void OnMouseWheel(wxMouseEvent& event);
357 #endif // wxUSE_MOUSEWHEEL
358 void OnIdle(wxIdleEvent& event);
359
360 wxPrintPreviewBase* m_printPreview;
361
362 DECLARE_CLASS(wxPreviewCanvas)
363 DECLARE_EVENT_TABLE()
364 wxDECLARE_NO_COPY_CLASS(wxPreviewCanvas);
365 };
366
367 //----------------------------------------------------------------------------
368 // wxPreviewFrame
369 //----------------------------------------------------------------------------
370
371 /*
372 * Default frame for showing preview.
373 */
374
375 class WXDLLIMPEXP_CORE wxPreviewFrame: public wxFrame
376 {
377 public:
378 wxPreviewFrame(wxPrintPreviewBase *preview,
379 wxWindow *parent,
380 const wxString& title = _("Print Preview"),
381 const wxPoint& pos = wxDefaultPosition,
382 const wxSize& size = wxDefaultSize,
383 long style = wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT,
384 const wxString& name = wxFrameNameStr);
385 virtual ~wxPreviewFrame();
386
387 void OnCloseWindow(wxCloseEvent& event);
388 virtual void Initialize();
389 virtual void CreateCanvas();
390 virtual void CreateControlBar();
391
392 inline wxPreviewControlBar* GetControlBar() const { return m_controlBar; }
393
394 protected:
395 wxPreviewCanvas* m_previewCanvas;
396 wxPreviewControlBar* m_controlBar;
397 wxPrintPreviewBase* m_printPreview;
398 wxWindowDisabler* m_windowDisabler;
399
400 private:
401 void OnChar(wxKeyEvent& event);
402
403 DECLARE_EVENT_TABLE()
404 DECLARE_CLASS(wxPreviewFrame)
405 wxDECLARE_NO_COPY_CLASS(wxPreviewFrame);
406 };
407
408 //----------------------------------------------------------------------------
409 // wxPreviewControlBar
410 //----------------------------------------------------------------------------
411
412 /*
413 * A panel with buttons for controlling a print preview.
414 * The programmer may wish to use other means for controlling
415 * the print preview.
416 */
417
418 #define wxPREVIEW_PRINT 1
419 #define wxPREVIEW_PREVIOUS 2
420 #define wxPREVIEW_NEXT 4
421 #define wxPREVIEW_ZOOM 8
422 #define wxPREVIEW_FIRST 16
423 #define wxPREVIEW_LAST 32
424 #define wxPREVIEW_GOTO 64
425
426 #define wxPREVIEW_DEFAULT (wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
427 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST)
428
429 // Ids for controls
430 #define wxID_PREVIEW_CLOSE 1
431 #define wxID_PREVIEW_NEXT 2
432 #define wxID_PREVIEW_PREVIOUS 3
433 #define wxID_PREVIEW_PRINT 4
434 #define wxID_PREVIEW_ZOOM 5
435 #define wxID_PREVIEW_FIRST 6
436 #define wxID_PREVIEW_LAST 7
437 #define wxID_PREVIEW_GOTO 8
438 #define wxID_PREVIEW_ZOOM_IN 9
439 #define wxID_PREVIEW_ZOOM_OUT 10
440
441 class WXDLLIMPEXP_CORE wxPreviewControlBar: public wxPanel
442 {
443 DECLARE_CLASS(wxPreviewControlBar)
444
445 public:
446 wxPreviewControlBar(wxPrintPreviewBase *preview,
447 long buttons,
448 wxWindow *parent,
449 const wxPoint& pos = wxDefaultPosition,
450 const wxSize& size = wxDefaultSize,
451 long style = wxTAB_TRAVERSAL,
452 const wxString& name = wxT("panel"));
453 virtual ~wxPreviewControlBar();
454
455 virtual void CreateButtons();
456 virtual void SetZoomControl(int zoom);
457 virtual int GetZoomControl();
458 virtual wxPrintPreviewBase *GetPrintPreview() const
459 { return m_printPreview; }
460
461
462 // Implementation only from now on.
463 void OnWindowClose(wxCommandEvent& event);
464 void OnNext();
465 void OnPrevious();
466 void OnFirst();
467 void OnLast();
468 void OnGotoPage();
469 void OnPrint();
470
471 void OnPrintButton(wxCommandEvent& WXUNUSED(event)) { OnPrint(); }
472 void OnNextButton(wxCommandEvent & WXUNUSED(event)) { OnNext(); }
473 void OnPreviousButton(wxCommandEvent & WXUNUSED(event)) { OnPrevious(); }
474 void OnFirstButton(wxCommandEvent & WXUNUSED(event)) { OnFirst(); }
475 void OnLastButton(wxCommandEvent & WXUNUSED(event)) { OnLast(); }
476 void OnPaint(wxPaintEvent& event);
477
478 void OnUpdateNextButton(wxUpdateUIEvent& event)
479 { event.Enable(IsNextEnabled()); }
480 void OnUpdatePreviousButton(wxUpdateUIEvent& event)
481 { event.Enable(IsPreviousEnabled()); }
482 void OnUpdateFirstButton(wxUpdateUIEvent& event)
483 { event.Enable(IsFirstEnabled()); }
484 void OnUpdateLastButton(wxUpdateUIEvent& event)
485 { event.Enable(IsLastEnabled()); }
486 void OnUpdateZoomInButton(wxUpdateUIEvent& event)
487 { event.Enable(IsZoomInEnabled()); }
488 void OnUpdateZoomOutButton(wxUpdateUIEvent& event)
489 { event.Enable(IsZoomOutEnabled()); }
490
491 // These methods are not private because they are called by wxPreviewCanvas.
492 void DoZoomIn();
493 void DoZoomOut();
494
495 protected:
496 wxPrintPreviewBase* m_printPreview;
497 wxButton* m_closeButton;
498 wxChoice* m_zoomControl;
499 wxPrintPageTextCtrl* m_currentPageText;
500
501 long m_buttonFlags;
502
503 private:
504 void DoGotoPage(int page);
505
506 void DoZoom();
507
508 bool IsNextEnabled() const;
509 bool IsPreviousEnabled() const;
510 bool IsFirstEnabled() const;
511 bool IsLastEnabled() const;
512 bool IsZoomInEnabled() const;
513 bool IsZoomOutEnabled() const;
514
515 void OnZoomInButton(wxCommandEvent & WXUNUSED(event)) { DoZoomIn(); }
516 void OnZoomOutButton(wxCommandEvent & WXUNUSED(event)) { DoZoomOut(); }
517 void OnZoomChoice(wxCommandEvent& WXUNUSED(event)) { DoZoom(); }
518
519 DECLARE_EVENT_TABLE()
520 wxDECLARE_NO_COPY_CLASS(wxPreviewControlBar);
521 };
522
523 //----------------------------------------------------------------------------
524 // wxPrintPreviewBase
525 //----------------------------------------------------------------------------
526
527 /*
528 * Programmer creates an object of this class to preview a wxPrintout.
529 */
530
531 class WXDLLIMPEXP_CORE wxPrintPreviewBase: public wxObject
532 {
533 public:
534 wxPrintPreviewBase(wxPrintout *printout,
535 wxPrintout *printoutForPrinting = NULL,
536 wxPrintDialogData *data = NULL);
537 wxPrintPreviewBase(wxPrintout *printout,
538 wxPrintout *printoutForPrinting,
539 wxPrintData *data);
540 virtual ~wxPrintPreviewBase();
541
542 virtual bool SetCurrentPage(int pageNum);
543 virtual int GetCurrentPage() const;
544
545 virtual void SetPrintout(wxPrintout *printout);
546 virtual wxPrintout *GetPrintout() const;
547 virtual wxPrintout *GetPrintoutForPrinting() const;
548
549 virtual void SetFrame(wxFrame *frame);
550 virtual void SetCanvas(wxPreviewCanvas *canvas);
551
552 virtual wxFrame *GetFrame() const;
553 virtual wxPreviewCanvas *GetCanvas() const;
554
555 // This is a helper routine, used by the next 4 routines.
556
557 virtual void CalcRects(wxPreviewCanvas *canvas, wxRect& printableAreaRect, wxRect& paperRect);
558
559 // The preview canvas should call this from OnPaint
560 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
561
562 // Updates rendered page by calling RenderPage() if needed, returns true
563 // if there was some change. Preview canvas should call it at idle time
564 virtual bool UpdatePageRendering();
565
566 // This draws a blank page onto the preview canvas
567 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
568
569 // Adjusts the scrollbars for the current scale
570 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
571
572 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
573 virtual bool RenderPage(int pageNum);
574
575
576 virtual void SetZoom(int percent);
577 virtual int GetZoom() const;
578
579 virtual wxPrintDialogData& GetPrintDialogData();
580
581 virtual int GetMaxPage() const;
582 virtual int GetMinPage() const;
583
584 virtual bool Ok() const { return IsOk(); }
585 virtual bool IsOk() const;
586 virtual void SetOk(bool ok);
587
588 ///////////////////////////////////////////////////////////////////////////
589 // OVERRIDES
590
591 // If we own a wxPrintout that can be used for printing, this
592 // will invoke the actual printing procedure. Called
593 // by the wxPreviewControlBar.
594 virtual bool Print(bool interactive) = 0;
595
596 // Calculate scaling that needs to be done to get roughly
597 // the right scaling for the screen pretending to be
598 // the currently selected printer.
599 virtual void DetermineScaling() = 0;
600
601 protected:
602 // helpers for RenderPage():
603 virtual bool RenderPageIntoDC(wxDC& dc, int pageNum);
604 // renders preview into m_previewBitmap
605 virtual bool RenderPageIntoBitmap(wxBitmap& bmp, int pageNum);
606
607 void InvalidatePreviewBitmap();
608
609 protected:
610 wxPrintDialogData m_printDialogData;
611 wxPreviewCanvas* m_previewCanvas;
612 wxFrame* m_previewFrame;
613 wxBitmap* m_previewBitmap;
614 bool m_previewFailed;
615 wxPrintout* m_previewPrintout;
616 wxPrintout* m_printPrintout;
617 int m_currentPage;
618 int m_currentZoom;
619 float m_previewScaleX;
620 float m_previewScaleY;
621 int m_topMargin;
622 int m_leftMargin;
623 int m_pageWidth;
624 int m_pageHeight;
625 int m_minPage;
626 int m_maxPage;
627
628 bool m_isOk;
629 bool m_printingPrepared; // Called OnPreparePrinting?
630
631 private:
632 void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
633
634 wxDECLARE_NO_COPY_CLASS(wxPrintPreviewBase);
635 DECLARE_CLASS(wxPrintPreviewBase)
636 };
637
638 //----------------------------------------------------------------------------
639 // wxPrintPreview
640 //----------------------------------------------------------------------------
641
642 class WXDLLIMPEXP_CORE wxPrintPreview: public wxPrintPreviewBase
643 {
644 public:
645 wxPrintPreview(wxPrintout *printout,
646 wxPrintout *printoutForPrinting = NULL,
647 wxPrintDialogData *data = NULL);
648 wxPrintPreview(wxPrintout *printout,
649 wxPrintout *printoutForPrinting,
650 wxPrintData *data);
651 virtual ~wxPrintPreview();
652
653 virtual bool SetCurrentPage(int pageNum);
654 virtual int GetCurrentPage() const;
655 virtual void SetPrintout(wxPrintout *printout);
656 virtual wxPrintout *GetPrintout() const;
657 virtual wxPrintout *GetPrintoutForPrinting() const;
658 virtual void SetFrame(wxFrame *frame);
659 virtual void SetCanvas(wxPreviewCanvas *canvas);
660
661 virtual wxFrame *GetFrame() const;
662 virtual wxPreviewCanvas *GetCanvas() const;
663 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
664 virtual bool UpdatePageRendering();
665 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
666 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
667 virtual bool RenderPage(int pageNum);
668 virtual void SetZoom(int percent);
669 virtual int GetZoom() const;
670
671 virtual bool Print(bool interactive);
672 virtual void DetermineScaling();
673
674 virtual wxPrintDialogData& GetPrintDialogData();
675
676 virtual int GetMaxPage() const;
677 virtual int GetMinPage() const;
678
679 virtual bool Ok() const { return IsOk(); }
680 virtual bool IsOk() const;
681 virtual void SetOk(bool ok);
682
683 private:
684 wxPrintPreviewBase *m_pimpl;
685
686 private:
687 DECLARE_CLASS(wxPrintPreview)
688 wxDECLARE_NO_COPY_CLASS(wxPrintPreview);
689 };
690
691 //----------------------------------------------------------------------------
692 // wxPrintAbortDialog
693 //----------------------------------------------------------------------------
694
695 class WXDLLIMPEXP_CORE wxPrintAbortDialog: public wxDialog
696 {
697 public:
698 wxPrintAbortDialog(wxWindow *parent,
699 const wxString& title,
700 const wxPoint& pos = wxDefaultPosition,
701 const wxSize& size = wxDefaultSize,
702 long style = 0,
703 const wxString& name = wxT("dialog"))
704 : wxDialog(parent, wxID_ANY, title, pos, size, style, name)
705 {
706 }
707
708 void OnCancel(wxCommandEvent& event);
709
710 private:
711 DECLARE_EVENT_TABLE()
712 wxDECLARE_NO_COPY_CLASS(wxPrintAbortDialog);
713 };
714
715 #endif // wxUSE_PRINTING_ARCHITECTURE
716
717 #endif
718 // _WX_PRNTBASEH__