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 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "prntbase.h"
21 #include "wx/cmndata.h"
23 #include "wx/scrolwin.h"
24 #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 wxPrintDialog
;
32 class WXDLLEXPORT wxPrintPreviewBase
;
33 class WXDLLEXPORT wxPreviewCanvas
;
34 class WXDLLEXPORT wxPreviewControlBar
;
35 class WXDLLEXPORT wxPreviewFrame
;
38 * Represents the printer: manages printing a wxPrintout object
41 class WXDLLEXPORT wxPrinterBase
: public wxObject
43 DECLARE_CLASS(wxPrinterBase
)
46 wxPrintData printData
;
47 wxPrintout
*currentPrintout
;
49 static wxWindow
*abortWindow
;
52 wxPrinterBase(wxPrintData
*data
= NULL
);
55 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
56 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, char *message
);
57 inline wxPrintData
& GetPrintData(void) { return printData
; };
58 inline bool GetAbort(void) { return abortIt
; }
60 ///////////////////////////////////////////////////////////////////////////
63 virtual bool Setup(wxWindow
*parent
) = 0;
64 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= TRUE
) = 0;
65 virtual bool PrintDialog(wxWindow
*parent
) = 0;
70 * Represents an object via which a document may be printed.
71 * The programmer derives from this, overrides (at least) OnPrintPage,
72 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
73 * object for previewing.
76 class WXDLLEXPORT wxPrintout
: public wxObject
78 DECLARE_ABSTRACT_CLASS(wxPrintout
)
97 wxPrintout(const char *title
= "Printout");
100 virtual bool OnBeginDocument(int startPage
, int endPage
);
101 virtual void OnEndDocument(void);
102 virtual void OnBeginPrinting(void);
103 virtual void OnEndPrinting(void);
105 // Guaranteed to be before any other functions are called
106 inline virtual void OnPreparePrinting(void) { }
108 virtual bool HasPage(int page
);
109 virtual bool OnPrintPage(int page
) = 0;
110 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
112 inline virtual char *GetTitle(void) { return printoutTitle
; }
114 inline wxDC
*GetDC(void) { return printoutDC
; }
115 inline void SetDC(wxDC
*dc
) { printoutDC
= dc
; }
116 inline void SetPageSizePixels(int w
, int h
) { pageWidthPixels
= w
; pageHeightPixels
= h
; }
117 inline void GetPageSizePixels(int *w
, int *h
) { *w
= pageWidthPixels
; *h
= pageHeightPixels
; }
118 inline void SetPageSizeMM(int w
, int h
) { pageWidthMM
= w
; pageHeightMM
= h
; }
119 inline void GetPageSizeMM(int *w
, int *h
) { *w
= pageWidthMM
; *h
= pageHeightMM
; }
121 inline void SetPPIScreen(int x
, int y
) { PPIScreenX
= x
; PPIScreenY
= y
; }
122 inline void GetPPIScreen(int *x
, int *y
) { *x
= PPIScreenX
; *y
= PPIScreenY
; }
123 inline void SetPPIPrinter(int x
, int y
) { PPIPrinterX
= x
; PPIPrinterY
= y
; }
124 inline void GetPPIPrinter(int *x
, int *y
) { *x
= PPIPrinterX
; *y
= PPIPrinterY
; }
126 inline virtual bool IsPreview(void) { return isPreview
; }
128 inline virtual void SetIsPreview(bool p
) { isPreview
= p
; }
133 * Canvas upon which a preview is drawn.
136 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
138 DECLARE_CLASS(wxPreviewCanvas
)
141 wxPrintPreviewBase
*printPreview
;
143 wxPreviewCanvas(wxPrintPreviewBase
*preview
, wxWindow
*parent
,
144 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
145 long style
= 0, const wxString
& name
= "canvas");
146 ~wxPreviewCanvas(void);
148 void OnPaint(wxPaintEvent
& event
);
150 // Responds to colour changes
151 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
153 DECLARE_EVENT_TABLE()
158 * Default frame for showing preview.
161 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
163 DECLARE_CLASS(wxPreviewFrame
)
166 wxWindow
*previewCanvas
;
167 wxPreviewControlBar
*controlBar
;
168 wxPrintPreviewBase
*printPreview
;
170 wxPreviewFrame(wxPrintPreviewBase
*preview
, wxFrame
*parent
, const wxString
& title
= "Print Preview",
171 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
172 long style
= wxDEFAULT_FRAME
, const wxString
& name
= "frame");
173 ~wxPreviewFrame(void);
176 virtual void Initialize(void);
177 virtual void CreateCanvas(void);
178 virtual void CreateControlBar(void);
182 * wxPreviewControlBar
183 * A panel with buttons for controlling a print preview.
184 * The programmer may wish to use other means for controlling
188 #define wxPREVIEW_PRINT 1
189 #define wxPREVIEW_PREVIOUS 2
190 #define wxPREVIEW_NEXT 4
191 #define wxPREVIEW_ZOOM 8
193 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
196 #define wxID_PREVIEW_CLOSE 1
197 #define wxID_PREVIEW_NEXT 2
198 #define wxID_PREVIEW_PREVIOUS 3
199 #define wxID_PREVIEW_PRINT 4
200 #define wxID_PREVIEW_ZOOM 5
202 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
204 DECLARE_CLASS(wxPreviewControlBar
)
207 wxPrintPreviewBase
*printPreview
;
208 wxButton
*closeButton
;
209 wxButton
*nextPageButton
;
210 wxButton
*previousPageButton
;
211 wxButton
*printButton
;
212 wxChoice
*zoomControl
;
213 static wxFont
*buttonFont
;
216 wxPreviewControlBar(wxPrintPreviewBase
*preview
, long buttons
,
217 wxWindow
*parent
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
218 long style
= 0, const wxString
& name
= "panel");
219 ~wxPreviewControlBar(void);
221 virtual void CreateButtons(void);
222 virtual void SetZoomControl(int zoom
);
223 virtual int GetZoomControl(void);
224 inline virtual wxPrintPreviewBase
*GetPrintPreview(void) { return printPreview
; }
226 void OnPrint(wxCommandEvent
& event
);
227 void OnClose(wxCommandEvent
& event
);
228 void OnNext(wxCommandEvent
& event
);
229 void OnPrevious(wxCommandEvent
& event
);
230 void OnZoom(wxCommandEvent
& event
);
231 void OnPaint(wxPaintEvent
& event
);
233 DECLARE_EVENT_TABLE()
238 * Programmer creates an object of this class to preview a wxPrintout.
241 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
243 DECLARE_CLASS(wxPrintPreviewBase
)
246 wxPrintData printData
;
247 wxWindow
*previewCanvas
;
248 wxFrame
*previewFrame
;
249 wxBitmap
*previewBitmap
;
250 wxPrintout
*previewPrintout
;
251 wxPrintout
*printPrintout
;
264 wxPrintPreviewBase(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
= NULL
, wxPrintData
*data
= NULL
);
265 ~wxPrintPreviewBase(void);
267 virtual bool SetCurrentPage(int pageNum
);
268 inline int GetCurrentPage(void) { return currentPage
; };
270 inline void SetPrintout(wxPrintout
*printout
) { previewPrintout
= printout
; };
271 inline wxPrintout
*GetPrintout(void) { return previewPrintout
; };
272 inline wxPrintout
*GetPrintoutForPrinting(void) { return printPrintout
; };
274 inline void SetFrame(wxFrame
*frame
) { previewFrame
= frame
; };
275 inline void SetCanvas(wxWindow
*canvas
) { previewCanvas
= canvas
; };
277 inline virtual wxFrame
*GetFrame(void) { return previewFrame
; }
278 inline virtual wxWindow
*GetCanvas(void) { return previewCanvas
; }
280 // The preview canvas should call this from OnPaint
281 virtual bool PaintPage(wxWindow
*canvas
, wxDC
& dc
);
283 // This draws a blank page onto the preview canvas
284 virtual bool DrawBlankPage(wxWindow
*canvas
, wxDC
& dc
);
286 // This is called by wxPrintPreview to render a page into
288 virtual bool RenderPage(int pageNum
);
290 inline wxPrintData
& GetPrintData(void) { return printData
; }
292 virtual void SetZoom(int percent
);
293 int GetZoom(void) { return currentZoom
; };
295 inline int GetMaxPage(void) { return maxPage
; }
296 inline int GetMinPage(void) { return minPage
; }
298 inline bool Ok(void) { return isOk
; }
299 inline void SetOk(bool ok
) { isOk
= ok
; }
301 ///////////////////////////////////////////////////////////////////////////
304 // If we own a wxPrintout that can be used for printing, this
305 // will invoke the actual printing procedure. Called
306 // by the wxPreviewControlBar.
307 virtual bool Print(bool interactive
) = 0;
309 // Calculate scaling that needs to be done to get roughly
310 // the right scaling for the screen pretending to be
311 // the currently selected printer.
312 virtual void DetermineScaling(void) = 0;
319 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
322 void OnCancel(wxCommandEvent
& event
);
324 wxPrintAbortDialog(wxWindow
*parent
,
325 const wxString
& title
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
326 long style
= 0, const wxString
& name
= "dialog"):
327 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
331 DECLARE_EVENT_TABLE()