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