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