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