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(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
48 virtual ~wxPrinterBase();
50 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
51 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, char *message
);
53 wxPrintDialogData
& GetPrintDialogData() const
54 { return (wxPrintDialogData
&) m_printDialogData
; }
55 bool GetAbort() const { return sm_abortIt
; }
57 ///////////////////////////////////////////////////////////////////////////
60 virtual bool Setup(wxWindow
*parent
) = 0;
61 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= TRUE
) = 0;
62 virtual wxDC
* PrintDialog(wxWindow
*parent
) = 0;
65 wxPrintDialogData m_printDialogData
;
66 wxPrintout
* m_currentPrintout
;
69 static wxWindow
* sm_abortWindow
;
70 static bool sm_abortIt
;
76 * Represents an object via which a document may be printed.
77 * The programmer derives from this, overrides (at least) OnPrintPage,
78 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
79 * object for previewing.
82 class WXDLLEXPORT wxPrintout
: public wxObject
84 DECLARE_ABSTRACT_CLASS(wxPrintout
)
87 wxPrintout(const wxString
& title
= "Printout");
88 virtual ~wxPrintout();
90 virtual bool OnBeginDocument(int startPage
, int endPage
);
91 virtual void OnEndDocument();
92 virtual void OnBeginPrinting();
93 virtual void OnEndPrinting();
95 // Guaranteed to be before any other functions are called
96 virtual void OnPreparePrinting() { }
98 virtual bool HasPage(int page
);
99 virtual bool OnPrintPage(int page
) = 0;
100 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
102 virtual wxString
GetTitle() const { return m_printoutTitle
; }
104 wxDC
*GetDC() const { return m_printoutDC
; }
105 void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
106 void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
107 void GetPageSizePixels(int *w
, int *h
) const { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
108 void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
109 void GetPageSizeMM(int *w
, int *h
) const { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
111 void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
112 void GetPPIScreen(int *x
, int *y
) const { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
113 void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
114 void GetPPIPrinter(int *x
, int *y
) const { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
116 virtual bool IsPreview() const { return m_isPreview
; }
118 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
121 wxString m_printoutTitle
;
124 int m_pageWidthPixels
;
125 int m_pageHeightPixels
;
140 * Canvas upon which a preview is drawn.
143 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
145 DECLARE_CLASS(wxPreviewCanvas
)
148 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
150 const wxPoint
& pos
= wxDefaultPosition
,
151 const wxSize
& size
= wxDefaultSize
,
153 const wxString
& name
= "canvas");
156 void OnPaint(wxPaintEvent
& event
);
158 // Responds to colour changes
159 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
162 wxPrintPreviewBase
* m_printPreview
;
164 DECLARE_EVENT_TABLE()
169 * Default frame for showing preview.
172 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
174 DECLARE_CLASS(wxPreviewFrame
)
177 wxPreviewFrame(wxPrintPreviewBase
*preview
,
179 const wxString
& title
= "Print Preview",
180 const wxPoint
& pos
= wxDefaultPosition
,
181 const wxSize
& size
= wxDefaultSize
,
182 long style
= wxDEFAULT_FRAME_STYLE
,
183 const wxString
& name
= "frame");
186 void OnCloseWindow(wxCloseEvent
& event
);
187 virtual void Initialize();
188 virtual void CreateCanvas();
189 virtual void CreateControlBar();
192 wxWindow
* m_previewCanvas
;
193 wxPreviewControlBar
* m_controlBar
;
194 wxPrintPreviewBase
* m_printPreview
;
197 DECLARE_EVENT_TABLE()
201 * wxPreviewControlBar
202 * A panel with buttons for controlling a print preview.
203 * The programmer may wish to use other means for controlling
207 #define wxPREVIEW_PRINT 1
208 #define wxPREVIEW_PREVIOUS 2
209 #define wxPREVIEW_NEXT 4
210 #define wxPREVIEW_ZOOM 8
212 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
215 #define wxID_PREVIEW_CLOSE 1
216 #define wxID_PREVIEW_NEXT 2
217 #define wxID_PREVIEW_PREVIOUS 3
218 #define wxID_PREVIEW_PRINT 4
219 #define wxID_PREVIEW_ZOOM 5
221 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
223 DECLARE_CLASS(wxPreviewControlBar
)
226 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
229 const wxPoint
& pos
= wxDefaultPosition
,
230 const wxSize
& size
= wxDefaultSize
,
232 const wxString
& name
= "panel");
233 ~wxPreviewControlBar();
235 virtual void CreateButtons();
236 virtual void SetZoomControl(int zoom
);
237 virtual int GetZoomControl();
238 virtual wxPrintPreviewBase
*GetPrintPreview() const
239 { return m_printPreview
; }
241 void OnPrint(wxCommandEvent
& event
);
242 void OnWindowClose(wxCommandEvent
& event
);
243 void OnNext(wxCommandEvent
& event
);
244 void OnPrevious(wxCommandEvent
& event
);
245 void OnZoom(wxCommandEvent
& event
);
246 void OnPaint(wxPaintEvent
& event
);
249 wxPrintPreviewBase
* m_printPreview
;
250 wxButton
* m_closeButton
;
251 wxButton
* m_nextPageButton
;
252 wxButton
* m_previousPageButton
;
253 wxButton
* m_printButton
;
254 wxChoice
* m_zoomControl
;
258 DECLARE_EVENT_TABLE()
263 * Programmer creates an object of this class to preview a wxPrintout.
266 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
268 DECLARE_CLASS(wxPrintPreviewBase
)
271 wxPrintPreviewBase(wxPrintout
*printout
,
272 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
273 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
274 wxPrintPreviewBase(wxPrintout
*printout
,
275 wxPrintout
*printoutForPrinting
,
277 virtual ~wxPrintPreviewBase();
279 virtual bool SetCurrentPage(int pageNum
);
280 int GetCurrentPage() const { return m_currentPage
; };
282 void SetPrintout(wxPrintout
*printout
) { m_previewPrintout
= printout
; };
283 wxPrintout
*GetPrintout() const { return m_previewPrintout
; };
284 wxPrintout
*GetPrintoutForPrinting() const { return m_printPrintout
; };
286 void SetFrame(wxFrame
*frame
) { m_previewFrame
= frame
; };
287 void SetCanvas(wxWindow
*canvas
) { m_previewCanvas
= canvas
; };
289 virtual wxFrame
*GetFrame() const { return m_previewFrame
; }
290 virtual wxWindow
*GetCanvas() const { return m_previewCanvas
; }
292 // The preview canvas should call this from OnPaint
293 virtual bool PaintPage(wxWindow
*canvas
, wxDC
& dc
);
295 // This draws a blank page onto the preview canvas
296 virtual bool DrawBlankPage(wxWindow
*canvas
, wxDC
& dc
);
298 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
299 virtual bool RenderPage(int pageNum
);
301 wxPrintDialogData
& GetPrintDialogData() { return m_printDialogData
; }
303 virtual void SetZoom(int percent
);
304 int GetZoom() const { return m_currentZoom
; };
306 int GetMaxPage() const { return m_maxPage
; }
307 int GetMinPage() const { return m_minPage
; }
309 bool Ok() const { return m_isOk
; }
310 void SetOk(bool ok
) { m_isOk
= ok
; }
312 ///////////////////////////////////////////////////////////////////////////
315 // If we own a wxPrintout that can be used for printing, this
316 // will invoke the actual printing procedure. Called
317 // by the wxPreviewControlBar.
318 virtual bool Print(bool interactive
) = 0;
320 // Calculate scaling that needs to be done to get roughly
321 // the right scaling for the screen pretending to be
322 // the currently selected printer.
323 virtual void DetermineScaling() = 0;
326 wxPrintDialogData m_printDialogData
;
327 wxWindow
* m_previewCanvas
;
328 wxFrame
* m_previewFrame
;
329 wxBitmap
* m_previewBitmap
;
330 wxPrintout
* m_previewPrintout
;
331 wxPrintout
* m_printPrintout
;
334 float m_previewScale
;
345 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
352 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
355 wxPrintAbortDialog(wxWindow
*parent
,
356 const wxString
& title
,
357 const wxPoint
& pos
= wxDefaultPosition
,
358 const wxSize
& size
= wxDefaultSize
,
360 const wxString
& name
= "dialog")
361 : wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
365 void OnCancel(wxCommandEvent
& event
);
368 DECLARE_EVENT_TABLE()