1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Base classes for printing framework
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PRNTBASEH__
13 #define _WX_PRNTBASEH__
17 #if wxUSE_PRINTING_ARCHITECTURE
20 #include "wx/cmndata.h"
22 #include "wx/scrolwin.h"
23 #include "wx/dialog.h"
26 class WXDLLEXPORT wxDC
;
27 class WXDLLEXPORT wxButton
;
28 class WXDLLEXPORT wxChoice
;
29 class WXDLLEXPORT wxPrintout
;
30 class WXDLLEXPORT wxPrinterBase
;
31 class WXDLLEXPORT wxPrintDialogBase
;
32 class WXDLLEXPORT wxPrintDialog
;
33 class WXDLLEXPORT wxPageSetupDialogBase
;
34 class WXDLLEXPORT wxPageSetupDialog
;
35 class WXDLLEXPORT wxPrintPreviewBase
;
36 class WXDLLEXPORT wxPreviewCanvas
;
37 class WXDLLEXPORT wxPreviewControlBar
;
38 class WXDLLEXPORT wxPreviewFrame
;
39 class WXDLLEXPORT wxPrintFactory
;
40 class WXDLLEXPORT wxPrintNativeDataBase
;
42 //----------------------------------------------------------------------------
44 //----------------------------------------------------------------------------
48 wxPRINTER_NO_ERROR
= 0,
53 //----------------------------------------------------------------------------
55 //----------------------------------------------------------------------------
57 class WXDLLEXPORT wxPrintFactory
61 virtual ~wxPrintFactory() {}
63 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
* data
) = 0;
65 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
66 wxPrintout
*printout
= NULL
,
67 wxPrintDialogData
*data
= NULL
) = 0;
68 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
70 wxPrintData
*data
) = 0;
72 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
73 wxPrintDialogData
*data
= NULL
) = 0;
74 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
75 wxPrintData
*data
) = 0;
77 virtual wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
78 wxPageSetupDialogData
* data
= NULL
) = 0;
80 virtual wxDC
* CreatePrinterDC( const wxPrintData
& data
) = 0;
82 // What to do and what to show in the wxPrintDialog
83 // a) Use the generic print setup dialog or a native one?
84 virtual bool HasPrintSetupDialog() = 0;
85 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
) = 0;
86 // b) Provide the "print to file" option ourselves or via print setup?
87 virtual bool HasOwnPrintToFile() = 0;
88 // c) Show current printer
89 virtual bool HasPrinterLine() = 0;
90 virtual wxString
CreatePrinterLine() = 0;
91 // d) Show Status line for current printer?
92 virtual bool HasStatusLine() = 0;
93 virtual wxString
CreateStatusLine() = 0;
96 virtual wxPrintNativeDataBase
*CreatePrintNativeData() = 0;
98 static void SetPrintFactory( wxPrintFactory
*factory
);
99 static wxPrintFactory
*GetFactory();
101 static wxPrintFactory
*m_factory
;
104 class WXDLLEXPORT wxNativePrintFactory
: public wxPrintFactory
107 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
109 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
110 wxPrintout
*printout
= NULL
,
111 wxPrintDialogData
*data
= NULL
);
112 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
113 wxPrintout
*printout
,
116 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
117 wxPrintDialogData
*data
= NULL
);
118 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
121 virtual wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
122 wxPageSetupDialogData
* data
= NULL
);
124 virtual wxDC
* CreatePrinterDC( const wxPrintData
& data
);
126 virtual bool HasPrintSetupDialog();
127 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
128 virtual bool HasOwnPrintToFile();
129 virtual bool HasPrinterLine();
130 virtual wxString
CreatePrinterLine();
131 virtual bool HasStatusLine();
132 virtual wxString
CreateStatusLine();
134 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
137 //----------------------------------------------------------------------------
138 // wxPrintNativeDataBase
139 //----------------------------------------------------------------------------
141 class WXDLLEXPORT wxPrintNativeDataBase
: public wxObject
144 wxPrintNativeDataBase();
145 virtual ~wxPrintNativeDataBase() {}
147 virtual bool TransferTo( wxPrintData
&data
) = 0;
148 virtual bool TransferFrom( const wxPrintData
&data
) = 0;
150 virtual bool Ok() const { return IsOk(); }
151 virtual bool IsOk() const = 0;
156 DECLARE_CLASS(wxPrintNativeDataBase
)
157 DECLARE_NO_COPY_CLASS(wxPrintNativeDataBase
)
160 //----------------------------------------------------------------------------
162 //----------------------------------------------------------------------------
165 * Represents the printer: manages printing a wxPrintout object
168 class WXDLLEXPORT wxPrinterBase
: public wxObject
171 wxPrinterBase(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
172 virtual ~wxPrinterBase();
174 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
175 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
177 virtual wxPrintDialogData
& GetPrintDialogData() const;
178 bool GetAbort() const { return sm_abortIt
; }
180 static wxPrinterError
GetLastError() { return sm_lastError
; }
182 ///////////////////////////////////////////////////////////////////////////
185 virtual bool Setup(wxWindow
*parent
) = 0;
186 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true) = 0;
187 virtual wxDC
* PrintDialog(wxWindow
*parent
) = 0;
190 wxPrintDialogData m_printDialogData
;
191 wxPrintout
* m_currentPrintout
;
193 static wxPrinterError sm_lastError
;
196 static wxWindow
* sm_abortWindow
;
197 static bool sm_abortIt
;
200 DECLARE_CLASS(wxPrinterBase
)
201 DECLARE_NO_COPY_CLASS(wxPrinterBase
)
204 //----------------------------------------------------------------------------
206 //----------------------------------------------------------------------------
208 class WXDLLEXPORT wxPrinter
: public wxPrinterBase
211 wxPrinter(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
212 virtual ~wxPrinter();
214 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
215 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
217 virtual bool Setup(wxWindow
*parent
);
218 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true);
219 virtual wxDC
* PrintDialog(wxWindow
*parent
);
221 virtual wxPrintDialogData
& GetPrintDialogData() const;
224 wxPrinterBase
*m_pimpl
;
227 DECLARE_CLASS(wxPrinter
)
228 DECLARE_NO_COPY_CLASS(wxPrinter
)
231 //----------------------------------------------------------------------------
233 //----------------------------------------------------------------------------
236 * Represents an object via which a document may be printed.
237 * The programmer derives from this, overrides (at least) OnPrintPage,
238 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
239 * object for previewing.
242 class WXDLLEXPORT wxPrintout
: public wxObject
245 wxPrintout(const wxString
& title
= wxT("Printout"));
246 virtual ~wxPrintout();
248 virtual bool OnBeginDocument(int startPage
, int endPage
);
249 virtual void OnEndDocument();
250 virtual void OnBeginPrinting();
251 virtual void OnEndPrinting();
253 // Guaranteed to be before any other functions are called
254 virtual void OnPreparePrinting() { }
256 virtual bool HasPage(int page
);
257 virtual bool OnPrintPage(int page
) = 0;
258 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
260 virtual wxString
GetTitle() const { return m_printoutTitle
; }
262 wxDC
*GetDC() const { return m_printoutDC
; }
263 void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
264 void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
265 void GetPageSizePixels(int *w
, int *h
) const { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
266 void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
267 void GetPageSizeMM(int *w
, int *h
) const { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
269 void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
270 void GetPPIScreen(int *x
, int *y
) const { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
271 void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
272 void GetPPIPrinter(int *x
, int *y
) const { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
274 virtual bool IsPreview() const { return m_isPreview
; }
276 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
279 wxString m_printoutTitle
;
282 int m_pageWidthPixels
;
283 int m_pageHeightPixels
;
296 DECLARE_ABSTRACT_CLASS(wxPrintout
)
297 DECLARE_NO_COPY_CLASS(wxPrintout
)
302 * Canvas upon which a preview is drawn.
305 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
308 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
310 const wxPoint
& pos
= wxDefaultPosition
,
311 const wxSize
& size
= wxDefaultSize
,
313 const wxString
& name
= wxT("canvas"));
314 virtual ~wxPreviewCanvas();
316 void OnPaint(wxPaintEvent
& event
);
317 void OnChar(wxKeyEvent
&event
);
318 // Responds to colour changes
319 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
323 void OnMouseWheel(wxMouseEvent
& event
);
324 #endif // wxUSE_MOUSEWHEEL
326 wxPrintPreviewBase
* m_printPreview
;
328 DECLARE_CLASS(wxPreviewCanvas
)
329 DECLARE_EVENT_TABLE()
330 DECLARE_NO_COPY_CLASS(wxPreviewCanvas
)
335 * Default frame for showing preview.
338 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
341 wxPreviewFrame(wxPrintPreviewBase
*preview
,
343 const wxString
& title
= wxT("Print Preview"),
344 const wxPoint
& pos
= wxDefaultPosition
,
345 const wxSize
& size
= wxDefaultSize
,
346 long style
= wxDEFAULT_FRAME_STYLE
,
347 const wxString
& name
= wxT("frame"));
348 virtual ~wxPreviewFrame();
350 void OnCloseWindow(wxCloseEvent
& event
);
351 virtual void Initialize();
352 virtual void CreateCanvas();
353 virtual void CreateControlBar();
355 inline wxPreviewControlBar
* GetControlBar() const { return m_controlBar
; }
358 wxPreviewCanvas
* m_previewCanvas
;
359 wxPreviewControlBar
* m_controlBar
;
360 wxPrintPreviewBase
* m_printPreview
;
361 wxWindowDisabler
* m_windowDisabler
;
364 DECLARE_CLASS(wxPreviewFrame
)
365 DECLARE_EVENT_TABLE()
366 DECLARE_NO_COPY_CLASS(wxPreviewFrame
)
370 * wxPreviewControlBar
371 * A panel with buttons for controlling a print preview.
372 * The programmer may wish to use other means for controlling
376 #define wxPREVIEW_PRINT 1
377 #define wxPREVIEW_PREVIOUS 2
378 #define wxPREVIEW_NEXT 4
379 #define wxPREVIEW_ZOOM 8
380 #define wxPREVIEW_FIRST 16
381 #define wxPREVIEW_LAST 32
382 #define wxPREVIEW_GOTO 64
384 #define wxPREVIEW_DEFAULT (wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
385 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST)
388 #define wxID_PREVIEW_CLOSE 1
389 #define wxID_PREVIEW_NEXT 2
390 #define wxID_PREVIEW_PREVIOUS 3
391 #define wxID_PREVIEW_PRINT 4
392 #define wxID_PREVIEW_ZOOM 5
393 #define wxID_PREVIEW_FIRST 6
394 #define wxID_PREVIEW_LAST 7
395 #define wxID_PREVIEW_GOTO 8
397 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
399 DECLARE_CLASS(wxPreviewControlBar
)
402 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
405 const wxPoint
& pos
= wxDefaultPosition
,
406 const wxSize
& size
= wxDefaultSize
,
407 long style
= wxTAB_TRAVERSAL
,
408 const wxString
& name
= wxT("panel"));
409 virtual ~wxPreviewControlBar();
411 virtual void CreateButtons();
412 virtual void SetZoomControl(int zoom
);
413 virtual int GetZoomControl();
414 virtual wxPrintPreviewBase
*GetPrintPreview() const
415 { return m_printPreview
; }
417 void OnWindowClose(wxCommandEvent
& event
);
424 void OnPrintButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrint(); }
425 void OnNextButton(wxCommandEvent
& WXUNUSED(event
)) { OnNext(); }
426 void OnPreviousButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrevious(); }
427 void OnFirstButton(wxCommandEvent
& WXUNUSED(event
)) { OnFirst(); }
428 void OnLastButton(wxCommandEvent
& WXUNUSED(event
)) { OnLast(); }
429 void OnGotoButton(wxCommandEvent
& WXUNUSED(event
)) { OnGoto(); }
430 void OnZoom(wxCommandEvent
& event
);
431 void OnPaint(wxPaintEvent
& event
);
434 wxPrintPreviewBase
* m_printPreview
;
435 wxButton
* m_closeButton
;
436 wxButton
* m_nextPageButton
;
437 wxButton
* m_previousPageButton
;
438 wxButton
* m_printButton
;
439 wxChoice
* m_zoomControl
;
440 wxButton
* m_firstPageButton
;
441 wxButton
* m_lastPageButton
;
442 wxButton
* m_gotoPageButton
;
446 DECLARE_EVENT_TABLE()
447 DECLARE_NO_COPY_CLASS(wxPreviewControlBar
)
450 //----------------------------------------------------------------------------
451 // wxPrintPreviewBase
452 //----------------------------------------------------------------------------
455 * Programmer creates an object of this class to preview a wxPrintout.
458 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
461 wxPrintPreviewBase(wxPrintout
*printout
,
462 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
463 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
464 wxPrintPreviewBase(wxPrintout
*printout
,
465 wxPrintout
*printoutForPrinting
,
467 virtual ~wxPrintPreviewBase();
469 virtual bool SetCurrentPage(int pageNum
);
470 virtual int GetCurrentPage() const;
472 virtual void SetPrintout(wxPrintout
*printout
);
473 virtual wxPrintout
*GetPrintout() const;
474 virtual wxPrintout
*GetPrintoutForPrinting() const;
476 virtual void SetFrame(wxFrame
*frame
);
477 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
479 virtual wxFrame
*GetFrame() const;
480 virtual wxPreviewCanvas
*GetCanvas() const;
482 // The preview canvas should call this from OnPaint
483 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
485 // This draws a blank page onto the preview canvas
486 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
488 // Adjusts the scrollbars for the current scale
489 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
491 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
492 virtual bool RenderPage(int pageNum
);
495 virtual void SetZoom(int percent
);
496 virtual int GetZoom() const;
498 virtual wxPrintDialogData
& GetPrintDialogData();
500 virtual int GetMaxPage() const;
501 virtual int GetMinPage() const;
503 virtual bool Ok() const { return IsOk(); }
504 virtual bool IsOk() const;
505 virtual void SetOk(bool ok
);
507 ///////////////////////////////////////////////////////////////////////////
510 // If we own a wxPrintout that can be used for printing, this
511 // will invoke the actual printing procedure. Called
512 // by the wxPreviewControlBar.
513 virtual bool Print(bool interactive
) = 0;
515 // Calculate scaling that needs to be done to get roughly
516 // the right scaling for the screen pretending to be
517 // the currently selected printer.
518 virtual void DetermineScaling() = 0;
521 wxPrintDialogData m_printDialogData
;
522 wxPreviewCanvas
* m_previewCanvas
;
523 wxFrame
* m_previewFrame
;
524 wxBitmap
* m_previewBitmap
;
525 wxPrintout
* m_previewPrintout
;
526 wxPrintout
* m_printPrintout
;
529 float m_previewScale
;
538 bool m_printingPrepared
; // Called OnPreparePrinting?
541 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
543 DECLARE_NO_COPY_CLASS(wxPrintPreviewBase
)
544 DECLARE_CLASS(wxPrintPreviewBase
)
547 //----------------------------------------------------------------------------
549 //----------------------------------------------------------------------------
551 class WXDLLEXPORT wxPrintPreview
: public wxPrintPreviewBase
554 wxPrintPreview(wxPrintout
*printout
,
555 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
556 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
557 wxPrintPreview(wxPrintout
*printout
,
558 wxPrintout
*printoutForPrinting
,
560 virtual ~wxPrintPreview();
562 virtual bool SetCurrentPage(int pageNum
);
563 virtual int GetCurrentPage() const;
564 virtual void SetPrintout(wxPrintout
*printout
);
565 virtual wxPrintout
*GetPrintout() const;
566 virtual wxPrintout
*GetPrintoutForPrinting() const;
567 virtual void SetFrame(wxFrame
*frame
);
568 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
570 virtual wxFrame
*GetFrame() const;
571 virtual wxPreviewCanvas
*GetCanvas() const;
572 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
573 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
574 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
575 virtual bool RenderPage(int pageNum
);
576 virtual void SetZoom(int percent
);
577 virtual int GetZoom() const;
579 virtual bool Print(bool interactive
);
580 virtual void DetermineScaling();
582 virtual wxPrintDialogData
& GetPrintDialogData();
584 virtual int GetMaxPage() const;
585 virtual int GetMinPage() const;
587 virtual bool Ok() const { return IsOk(); }
588 virtual bool IsOk() const;
589 virtual void SetOk(bool ok
);
592 wxPrintPreviewBase
*m_pimpl
;
595 DECLARE_CLASS(wxPrintPreview
)
596 DECLARE_NO_COPY_CLASS(wxPrintPreview
)
599 //----------------------------------------------------------------------------
600 // wxPrintAbortDialog
601 //----------------------------------------------------------------------------
603 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
606 wxPrintAbortDialog(wxWindow
*parent
,
607 const wxString
& title
,
608 const wxPoint
& pos
= wxDefaultPosition
,
609 const wxSize
& size
= wxDefaultSize
,
611 const wxString
& name
= wxT("dialog"))
612 : wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
616 void OnCancel(wxCommandEvent
& event
);
619 DECLARE_EVENT_TABLE()
620 DECLARE_NO_COPY_CLASS(wxPrintAbortDialog
)
623 #endif // wxUSE_PRINTING_ARCHITECTURE