1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Base classes for printing framework
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PRNTBASEH__
13 #define _WX_PRNTBASEH__
16 #pragma interface "prntbase.h"
21 #include "wx/cmndata.h"
23 #include "wx/scrolwin.h"
24 #include "wx/dialog.h"
27 class WXDLLEXPORT wxDC
;
28 class WXDLLEXPORT wxButton
;
29 class WXDLLEXPORT wxChoice
;
30 class WXDLLEXPORT wxPrintout
;
31 class WXDLLEXPORT wxPrinterBase
;
32 class WXDLLEXPORT wxPrintDialog
;
33 class WXDLLEXPORT wxPrintPreviewBase
;
34 class WXDLLEXPORT wxPreviewCanvas
;
35 class WXDLLEXPORT wxPreviewControlBar
;
36 class WXDLLEXPORT wxPreviewFrame
;
39 * Represents the printer: manages printing a wxPrintout object
42 class WXDLLEXPORT wxPrinterBase
: public wxObject
44 DECLARE_CLASS(wxPrinterBase
)
47 wxPrinterBase(wxPrintData
*data
= (wxPrintData
*) NULL
);
50 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
51 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, char *message
);
52 inline wxPrintData
& GetPrintData() { return m_printData
; };
53 inline bool GetAbort() { return sm_abortIt
; }
55 ///////////////////////////////////////////////////////////////////////////
58 virtual bool Setup(wxWindow
*parent
) = 0;
59 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= TRUE
) = 0;
60 virtual bool PrintDialog(wxWindow
*parent
) = 0;
63 wxPrintData m_printData
;
64 wxPrintout
* m_currentPrintout
;
66 static wxWindow
* sm_abortWindow
;
67 static bool sm_abortIt
;
73 * Represents an object via which a document may be printed.
74 * The programmer derives from this, overrides (at least) OnPrintPage,
75 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
76 * object for previewing.
79 class WXDLLEXPORT wxPrintout
: public wxObject
81 DECLARE_ABSTRACT_CLASS(wxPrintout
)
84 wxPrintout(const wxString
& title
= "Printout");
87 virtual bool OnBeginDocument(int startPage
, int endPage
);
88 virtual void OnEndDocument();
89 virtual void OnBeginPrinting();
90 virtual void OnEndPrinting();
92 // Guaranteed to be before any other functions are called
93 inline virtual void OnPreparePrinting() { }
95 virtual bool HasPage(int page
);
96 virtual bool OnPrintPage(int page
) = 0;
97 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
99 inline virtual wxString
GetTitle() { return m_printoutTitle
; }
101 inline wxDC
*GetDC() { return m_printoutDC
; }
102 inline void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
103 inline void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
104 inline void GetPageSizePixels(int *w
, int *h
) { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
105 inline void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
106 inline void GetPageSizeMM(int *w
, int *h
) { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
108 inline void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
109 inline void GetPPIScreen(int *x
, int *y
) { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
110 inline void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
111 inline void GetPPIPrinter(int *x
, int *y
) { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
113 inline virtual bool IsPreview() { return m_isPreview
; }
115 inline virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
118 wxString m_printoutTitle
;
121 int m_pageWidthPixels
;
122 int m_pageHeightPixels
;
137 * Canvas upon which a preview is drawn.
140 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
142 DECLARE_CLASS(wxPreviewCanvas
)
145 wxPreviewCanvas(wxPrintPreviewBase
*preview
, wxWindow
*parent
,
146 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
147 long style
= 0, const wxString
& name
= "canvas");
150 void OnPaint(wxPaintEvent
& event
);
152 // Responds to colour changes
153 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
156 wxPrintPreviewBase
* m_printPreview
;
158 DECLARE_EVENT_TABLE()
163 * Default frame for showing preview.
166 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
168 DECLARE_CLASS(wxPreviewFrame
)
171 wxPreviewFrame(wxPrintPreviewBase
*preview
, wxFrame
*parent
, const wxString
& title
= "Print Preview",
172 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
173 long style
= wxDEFAULT_FRAME_STYLE
, const wxString
& name
= "frame");
176 void OnCloseWindow(wxCloseEvent
& event
);
177 virtual void Initialize();
178 virtual void CreateCanvas();
179 virtual void CreateControlBar();
182 wxWindow
* m_previewCanvas
;
183 wxPreviewControlBar
* m_controlBar
;
184 wxPrintPreviewBase
* m_printPreview
;
186 DECLARE_EVENT_TABLE()
190 * wxPreviewControlBar
191 * A panel with buttons for controlling a print preview.
192 * The programmer may wish to use other means for controlling
196 #define wxPREVIEW_PRINT 1
197 #define wxPREVIEW_PREVIOUS 2
198 #define wxPREVIEW_NEXT 4
199 #define wxPREVIEW_ZOOM 8
201 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
204 #define wxID_PREVIEW_CLOSE 1
205 #define wxID_PREVIEW_NEXT 2
206 #define wxID_PREVIEW_PREVIOUS 3
207 #define wxID_PREVIEW_PRINT 4
208 #define wxID_PREVIEW_ZOOM 5
210 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
212 DECLARE_CLASS(wxPreviewControlBar
)
215 wxPreviewControlBar(wxPrintPreviewBase
*preview
, long buttons
,
216 wxWindow
*parent
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
217 long style
= 0, const wxString
& name
= "panel");
218 ~wxPreviewControlBar();
220 virtual void CreateButtons();
221 virtual void SetZoomControl(int zoom
);
222 virtual int GetZoomControl();
223 inline virtual wxPrintPreviewBase
*GetPrintPreview() const { return m_printPreview
; }
225 void OnPrint(wxCommandEvent
& event
);
226 void OnWindowClose(wxCommandEvent
& event
);
227 void OnNext(wxCommandEvent
& event
);
228 void OnPrevious(wxCommandEvent
& event
);
229 void OnZoom(wxCommandEvent
& event
);
230 void OnPaint(wxPaintEvent
& event
);
233 wxPrintPreviewBase
* m_printPreview
;
234 wxButton
* m_closeButton
;
235 wxButton
* m_nextPageButton
;
236 wxButton
* m_previousPageButton
;
237 wxButton
* m_printButton
;
238 wxChoice
* m_zoomControl
;
241 DECLARE_EVENT_TABLE()
246 * Programmer creates an object of this class to preview a wxPrintout.
249 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
251 DECLARE_CLASS(wxPrintPreviewBase
)
254 wxPrintPreviewBase(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
, wxPrintData
*data
= (wxPrintData
*) NULL
);
255 ~wxPrintPreviewBase();
257 virtual bool SetCurrentPage(int pageNum
);
258 inline int GetCurrentPage() const { return m_currentPage
; };
260 inline void SetPrintout(wxPrintout
*printout
) { m_previewPrintout
= printout
; };
261 inline wxPrintout
*GetPrintout() const { return m_previewPrintout
; };
262 inline wxPrintout
*GetPrintoutForPrinting() const { return m_printPrintout
; };
264 inline void SetFrame(wxFrame
*frame
) { m_previewFrame
= frame
; };
265 inline void SetCanvas(wxWindow
*canvas
) { m_previewCanvas
= canvas
; };
267 inline virtual wxFrame
*GetFrame() const { return m_previewFrame
; }
268 inline virtual wxWindow
*GetCanvas() const { return m_previewCanvas
; }
270 // The preview canvas should call this from OnPaint
271 virtual bool PaintPage(wxWindow
*canvas
, wxDC
& dc
);
273 // This draws a blank page onto the preview canvas
274 virtual bool DrawBlankPage(wxWindow
*canvas
, wxDC
& dc
);
276 // This is called by wxPrintPreview to render a page into
278 virtual bool RenderPage(int pageNum
);
280 inline wxPrintData
& GetPrintData() { return m_printData
; }
282 virtual void SetZoom(int percent
);
283 inline int GetZoom() const { return m_currentZoom
; };
285 inline int GetMaxPage() const { return m_maxPage
; }
286 inline int GetMinPage() const { return m_minPage
; }
288 inline bool Ok() const { return m_isOk
; }
289 inline void SetOk(bool ok
) { m_isOk
= ok
; }
291 ///////////////////////////////////////////////////////////////////////////
294 // If we own a wxPrintout that can be used for printing, this
295 // will invoke the actual printing procedure. Called
296 // by the wxPreviewControlBar.
297 virtual bool Print(bool interactive
) = 0;
299 // Calculate scaling that needs to be done to get roughly
300 // the right scaling for the screen pretending to be
301 // the currently selected printer.
302 virtual void DetermineScaling() = 0;
305 wxPrintData m_printData
;
306 wxWindow
* m_previewCanvas
;
307 wxFrame
* m_previewFrame
;
308 wxBitmap
* m_previewBitmap
;
309 wxPrintout
* m_previewPrintout
;
310 wxPrintout
* m_printPrintout
;
313 float m_previewScale
;
328 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
331 wxPrintAbortDialog(wxWindow
*parent
,
332 const wxString
& title
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
333 long style
= 0, const wxString
& name
= "dialog"):
334 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
338 void OnCancel(wxCommandEvent
& event
);
340 DECLARE_EVENT_TABLE()