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
;
68 static wxWindow
* sm_abortWindow
;
69 static bool sm_abortIt
;
75 * Represents an object via which a document may be printed.
76 * The programmer derives from this, overrides (at least) OnPrintPage,
77 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
78 * object for previewing.
81 class WXDLLEXPORT wxPrintout
: public wxObject
83 DECLARE_ABSTRACT_CLASS(wxPrintout
)
86 wxPrintout(const wxString
& title
= "Printout");
87 virtual ~wxPrintout();
89 virtual bool OnBeginDocument(int startPage
, int endPage
);
90 virtual void OnEndDocument();
91 virtual void OnBeginPrinting();
92 virtual void OnEndPrinting();
94 // Guaranteed to be before any other functions are called
95 virtual void OnPreparePrinting() { }
97 virtual bool HasPage(int page
);
98 virtual bool OnPrintPage(int page
) = 0;
99 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
101 virtual wxString
GetTitle() const { return m_printoutTitle
; }
103 wxDC
*GetDC() const { return m_printoutDC
; }
104 void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
105 void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
106 void GetPageSizePixels(int *w
, int *h
) const { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
107 void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
108 void GetPageSizeMM(int *w
, int *h
) const { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
110 void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
111 void GetPPIScreen(int *x
, int *y
) const { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
112 void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
113 void GetPPIPrinter(int *x
, int *y
) const { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
115 virtual bool IsPreview() const { return m_isPreview
; }
117 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
120 wxString m_printoutTitle
;
123 int m_pageWidthPixels
;
124 int m_pageHeightPixels
;
139 * Canvas upon which a preview is drawn.
142 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
144 DECLARE_CLASS(wxPreviewCanvas
)
147 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
149 const wxPoint
& pos
= wxDefaultPosition
,
150 const wxSize
& size
= wxDefaultSize
,
152 const wxString
& name
= "canvas");
155 void OnPaint(wxPaintEvent
& event
);
157 // Responds to colour changes
158 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
161 wxPrintPreviewBase
* m_printPreview
;
163 DECLARE_EVENT_TABLE()
168 * Default frame for showing preview.
171 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
173 DECLARE_CLASS(wxPreviewFrame
)
176 wxPreviewFrame(wxPrintPreviewBase
*preview
,
178 const wxString
& title
= "Print Preview",
179 const wxPoint
& pos
= wxDefaultPosition
,
180 const wxSize
& size
= wxDefaultSize
,
181 long style
= wxDEFAULT_FRAME_STYLE
,
182 const wxString
& name
= "frame");
185 void OnCloseWindow(wxCloseEvent
& event
);
186 virtual void Initialize();
187 virtual void CreateCanvas();
188 virtual void CreateControlBar();
191 wxWindow
* m_previewCanvas
;
192 wxPreviewControlBar
* m_controlBar
;
193 wxPrintPreviewBase
* m_printPreview
;
196 DECLARE_EVENT_TABLE()
200 * wxPreviewControlBar
201 * A panel with buttons for controlling a print preview.
202 * The programmer may wish to use other means for controlling
206 #define wxPREVIEW_PRINT 1
207 #define wxPREVIEW_PREVIOUS 2
208 #define wxPREVIEW_NEXT 4
209 #define wxPREVIEW_ZOOM 8
211 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
214 #define wxID_PREVIEW_CLOSE 1
215 #define wxID_PREVIEW_NEXT 2
216 #define wxID_PREVIEW_PREVIOUS 3
217 #define wxID_PREVIEW_PRINT 4
218 #define wxID_PREVIEW_ZOOM 5
220 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
222 DECLARE_CLASS(wxPreviewControlBar
)
225 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
228 const wxPoint
& pos
= wxDefaultPosition
,
229 const wxSize
& size
= wxDefaultSize
,
231 const wxString
& name
= "panel");
232 ~wxPreviewControlBar();
234 virtual void CreateButtons();
235 virtual void SetZoomControl(int zoom
);
236 virtual int GetZoomControl();
237 virtual wxPrintPreviewBase
*GetPrintPreview() const
238 { return m_printPreview
; }
240 void OnPrint(wxCommandEvent
& event
);
241 void OnWindowClose(wxCommandEvent
& event
);
242 void OnNext(wxCommandEvent
& event
);
243 void OnPrevious(wxCommandEvent
& event
);
244 void OnZoom(wxCommandEvent
& event
);
245 void OnPaint(wxPaintEvent
& event
);
248 wxPrintPreviewBase
* m_printPreview
;
249 wxButton
* m_closeButton
;
250 wxButton
* m_nextPageButton
;
251 wxButton
* m_previousPageButton
;
252 wxButton
* m_printButton
;
253 wxChoice
* m_zoomControl
;
257 DECLARE_EVENT_TABLE()
262 * Programmer creates an object of this class to preview a wxPrintout.
265 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
267 DECLARE_CLASS(wxPrintPreviewBase
)
270 wxPrintPreviewBase(wxPrintout
*printout
,
271 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
272 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
273 wxPrintPreviewBase(wxPrintout
*printout
,
274 wxPrintout
*printoutForPrinting
,
276 virtual ~wxPrintPreviewBase();
278 virtual bool SetCurrentPage(int pageNum
);
279 int GetCurrentPage() const { return m_currentPage
; };
281 void SetPrintout(wxPrintout
*printout
) { m_previewPrintout
= printout
; };
282 wxPrintout
*GetPrintout() const { return m_previewPrintout
; };
283 wxPrintout
*GetPrintoutForPrinting() const { return m_printPrintout
; };
285 void SetFrame(wxFrame
*frame
) { m_previewFrame
= frame
; };
286 void SetCanvas(wxWindow
*canvas
) { m_previewCanvas
= canvas
; };
288 virtual wxFrame
*GetFrame() const { return m_previewFrame
; }
289 virtual wxWindow
*GetCanvas() const { return m_previewCanvas
; }
291 // The preview canvas should call this from OnPaint
292 virtual bool PaintPage(wxWindow
*canvas
, wxDC
& dc
);
294 // This draws a blank page onto the preview canvas
295 virtual bool DrawBlankPage(wxWindow
*canvas
, wxDC
& dc
);
297 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
298 virtual bool RenderPage(int pageNum
);
300 wxPrintDialogData
& GetPrintDialogData() { return m_printDialogData
; }
302 virtual void SetZoom(int percent
);
303 int GetZoom() const { return m_currentZoom
; };
305 int GetMaxPage() const { return m_maxPage
; }
306 int GetMinPage() const { return m_minPage
; }
308 bool Ok() const { return m_isOk
; }
309 void SetOk(bool ok
) { m_isOk
= ok
; }
311 ///////////////////////////////////////////////////////////////////////////
314 // If we own a wxPrintout that can be used for printing, this
315 // will invoke the actual printing procedure. Called
316 // by the wxPreviewControlBar.
317 virtual bool Print(bool interactive
) = 0;
319 // Calculate scaling that needs to be done to get roughly
320 // the right scaling for the screen pretending to be
321 // the currently selected printer.
322 virtual void DetermineScaling() = 0;
325 wxPrintDialogData m_printDialogData
;
326 wxWindow
* m_previewCanvas
;
327 wxFrame
* m_previewFrame
;
328 wxBitmap
* m_previewBitmap
;
329 wxPrintout
* m_previewPrintout
;
330 wxPrintout
* m_printPrintout
;
333 float m_previewScale
;
344 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
351 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
354 wxPrintAbortDialog(wxWindow
*parent
,
355 const wxString
& title
,
356 const wxPoint
& pos
= wxDefaultPosition
,
357 const wxSize
& size
= wxDefaultSize
,
359 const wxString
& name
= "dialog")
360 : wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
364 void OnCancel(wxCommandEvent
& event
);
367 DECLARE_EVENT_TABLE()