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