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 wxPrintData printData
;
48 wxPrintout
*currentPrintout
;
50 static wxWindow
*abortWindow
;
53 wxPrinterBase(wxPrintData
*data
= NULL
);
56 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
57 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, char *message
);
58 inline wxPrintData
& GetPrintData(void) { return printData
; };
59 inline bool GetAbort(void) { return abortIt
; }
61 ///////////////////////////////////////////////////////////////////////////
64 virtual bool Setup(wxWindow
*parent
) = 0;
65 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= TRUE
) = 0;
66 virtual bool PrintDialog(wxWindow
*parent
) = 0;
71 * Represents an object via which a document may be printed.
72 * The programmer derives from this, overrides (at least) OnPrintPage,
73 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
74 * object for previewing.
77 class WXDLLEXPORT wxPrintout
: public wxObject
79 DECLARE_ABSTRACT_CLASS(wxPrintout
)
98 wxPrintout(const char *title
= "Printout");
101 virtual bool OnBeginDocument(int startPage
, int endPage
);
102 virtual void OnEndDocument(void);
103 virtual void OnBeginPrinting(void);
104 virtual void OnEndPrinting(void);
106 // Guaranteed to be before any other functions are called
107 inline virtual void OnPreparePrinting(void) { }
109 virtual bool HasPage(int page
);
110 virtual bool OnPrintPage(int page
) = 0;
111 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
113 inline virtual char *GetTitle(void) { return printoutTitle
; }
115 inline wxDC
*GetDC(void) { return printoutDC
; }
116 inline void SetDC(wxDC
*dc
) { printoutDC
= dc
; }
117 inline void SetPageSizePixels(int w
, int h
) { pageWidthPixels
= w
; pageHeightPixels
= h
; }
118 inline void GetPageSizePixels(int *w
, int *h
) { *w
= pageWidthPixels
; *h
= pageHeightPixels
; }
119 inline void SetPageSizeMM(int w
, int h
) { pageWidthMM
= w
; pageHeightMM
= h
; }
120 inline void GetPageSizeMM(int *w
, int *h
) { *w
= pageWidthMM
; *h
= pageHeightMM
; }
122 inline void SetPPIScreen(int x
, int y
) { PPIScreenX
= x
; PPIScreenY
= y
; }
123 inline void GetPPIScreen(int *x
, int *y
) { *x
= PPIScreenX
; *y
= PPIScreenY
; }
124 inline void SetPPIPrinter(int x
, int y
) { PPIPrinterX
= x
; PPIPrinterY
= y
; }
125 inline void GetPPIPrinter(int *x
, int *y
) { *x
= PPIPrinterX
; *y
= PPIPrinterY
; }
127 inline virtual bool IsPreview(void) { return isPreview
; }
129 inline virtual void SetIsPreview(bool p
) { isPreview
= p
; }
134 * Canvas upon which a preview is drawn.
137 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
139 DECLARE_CLASS(wxPreviewCanvas
)
142 wxPrintPreviewBase
*printPreview
;
144 wxPreviewCanvas(wxPrintPreviewBase
*preview
, wxWindow
*parent
,
145 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
146 long style
= 0, const wxString
& name
= "canvas");
147 ~wxPreviewCanvas(void);
149 void OnPaint(wxPaintEvent
& event
);
151 // Responds to colour changes
152 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
154 DECLARE_EVENT_TABLE()
159 * Default frame for showing preview.
162 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
164 DECLARE_CLASS(wxPreviewFrame
)
167 wxWindow
*previewCanvas
;
168 wxPreviewControlBar
*controlBar
;
169 wxPrintPreviewBase
*printPreview
;
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
, const wxString
& name
= "frame");
174 ~wxPreviewFrame(void);
177 virtual void Initialize(void);
178 virtual void CreateCanvas(void);
179 virtual void CreateControlBar(void);
183 * wxPreviewControlBar
184 * A panel with buttons for controlling a print preview.
185 * The programmer may wish to use other means for controlling
189 #define wxPREVIEW_PRINT 1
190 #define wxPREVIEW_PREVIOUS 2
191 #define wxPREVIEW_NEXT 4
192 #define wxPREVIEW_ZOOM 8
194 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
197 #define wxID_PREVIEW_CLOSE 1
198 #define wxID_PREVIEW_NEXT 2
199 #define wxID_PREVIEW_PREVIOUS 3
200 #define wxID_PREVIEW_PRINT 4
201 #define wxID_PREVIEW_ZOOM 5
203 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
205 DECLARE_CLASS(wxPreviewControlBar
)
208 wxPrintPreviewBase
*printPreview
;
209 wxButton
*closeButton
;
210 wxButton
*nextPageButton
;
211 wxButton
*previousPageButton
;
212 wxButton
*printButton
;
213 wxChoice
*zoomControl
;
214 static wxFont
*buttonFont
;
217 wxPreviewControlBar(wxPrintPreviewBase
*preview
, long buttons
,
218 wxWindow
*parent
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
219 long style
= 0, const wxString
& name
= "panel");
220 ~wxPreviewControlBar(void);
222 virtual void CreateButtons(void);
223 virtual void SetZoomControl(int zoom
);
224 virtual int GetZoomControl(void);
225 inline virtual wxPrintPreviewBase
*GetPrintPreview(void) { return printPreview
; }
227 void OnPrint(wxCommandEvent
& event
);
228 void OnClose(wxCommandEvent
& event
);
229 void OnNext(wxCommandEvent
& event
);
230 void OnPrevious(wxCommandEvent
& event
);
231 void OnZoom(wxCommandEvent
& event
);
232 void OnPaint(wxPaintEvent
& event
);
234 DECLARE_EVENT_TABLE()
239 * Programmer creates an object of this class to preview a wxPrintout.
242 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
244 DECLARE_CLASS(wxPrintPreviewBase
)
247 wxPrintData printData
;
248 wxWindow
*previewCanvas
;
249 wxFrame
*previewFrame
;
250 wxBitmap
*previewBitmap
;
251 wxPrintout
*previewPrintout
;
252 wxPrintout
*printPrintout
;
265 wxPrintPreviewBase(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
= NULL
, wxPrintData
*data
= NULL
);
266 ~wxPrintPreviewBase(void);
268 virtual bool SetCurrentPage(int pageNum
);
269 inline int GetCurrentPage(void) { return currentPage
; };
271 inline void SetPrintout(wxPrintout
*printout
) { previewPrintout
= printout
; };
272 inline wxPrintout
*GetPrintout(void) { return previewPrintout
; };
273 inline wxPrintout
*GetPrintoutForPrinting(void) { return printPrintout
; };
275 inline void SetFrame(wxFrame
*frame
) { previewFrame
= frame
; };
276 inline void SetCanvas(wxWindow
*canvas
) { previewCanvas
= canvas
; };
278 inline virtual wxFrame
*GetFrame(void) { return previewFrame
; }
279 inline virtual wxWindow
*GetCanvas(void) { return previewCanvas
; }
281 // The preview canvas should call this from OnPaint
282 virtual bool PaintPage(wxWindow
*canvas
, wxDC
& dc
);
284 // This draws a blank page onto the preview canvas
285 virtual bool DrawBlankPage(wxWindow
*canvas
, wxDC
& dc
);
287 // This is called by wxPrintPreview to render a page into
289 virtual bool RenderPage(int pageNum
);
291 inline wxPrintData
& GetPrintData(void) { return printData
; }
293 virtual void SetZoom(int percent
);
294 int GetZoom(void) { return currentZoom
; };
296 inline int GetMaxPage(void) { return maxPage
; }
297 inline int GetMinPage(void) { return minPage
; }
299 inline bool Ok(void) { return isOk
; }
300 inline void SetOk(bool ok
) { isOk
= ok
; }
302 ///////////////////////////////////////////////////////////////////////////
305 // If we own a wxPrintout that can be used for printing, this
306 // will invoke the actual printing procedure. Called
307 // by the wxPreviewControlBar.
308 virtual bool Print(bool interactive
) = 0;
310 // Calculate scaling that needs to be done to get roughly
311 // the right scaling for the screen pretending to be
312 // the currently selected printer.
313 virtual void DetermineScaling(void) = 0;
320 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
323 void OnCancel(wxCommandEvent
& event
);
325 wxPrintAbortDialog(wxWindow
*parent
,
326 const wxString
& title
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
327 long style
= 0, const wxString
& name
= "dialog"):
328 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
332 DECLARE_EVENT_TABLE()