]> git.saurik.com Git - wxWidgets.git/blob - include/wx/prntbase.h
_MSC_VER change fixes - now compiles again
[wxWidgets.git] / include / wx / prntbase.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: prntbase.h
3 // Purpose: Base classes for printing framework
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PRNTBASEH__
13 #define _WX_PRNTBASEH__
14
15 #ifdef __GNUG__
16 #pragma interface "prntbase.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/event.h"
21 #include "wx/cmndata.h"
22 #include "wx/panel.h"
23 #include "wx/scrolwin.h"
24 #include "wx/dialog.h"
25 #include "wx/frame.h"
26
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;
37
38 /*
39 * Represents the printer: manages printing a wxPrintout object
40 */
41
42 class WXDLLEXPORT wxPrinterBase: public wxObject
43 {
44 DECLARE_CLASS(wxPrinterBase)
45
46 public:
47 wxPrinterBase(wxPrintData *data = (wxPrintData *) NULL);
48 ~wxPrinterBase();
49
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; }
54
55 ///////////////////////////////////////////////////////////////////////////
56 // OVERRIDES
57
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;
61
62 protected:
63 wxPrintData m_printData;
64 wxPrintout* m_currentPrintout;
65 public:
66 static wxWindow* sm_abortWindow;
67 static bool sm_abortIt;
68
69 };
70
71 /*
72 * wxPrintout
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.
77 */
78
79 class WXDLLEXPORT wxPrintout: public wxObject
80 {
81 DECLARE_ABSTRACT_CLASS(wxPrintout)
82
83 public:
84 wxPrintout(const wxString& title = "Printout");
85 ~wxPrintout();
86
87 virtual bool OnBeginDocument(int startPage, int endPage);
88 virtual void OnEndDocument();
89 virtual void OnBeginPrinting();
90 virtual void OnEndPrinting();
91
92 // Guaranteed to be before any other functions are called
93 inline virtual void OnPreparePrinting() { }
94
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);
98
99 inline virtual wxString GetTitle() { return m_printoutTitle; }
100
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; }
107
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; }
112
113 inline virtual bool IsPreview() { return m_isPreview; }
114
115 inline virtual void SetIsPreview(bool p) { m_isPreview = p; }
116
117 private:
118 wxString m_printoutTitle;
119 wxDC* m_printoutDC;
120
121 int m_pageWidthPixels;
122 int m_pageHeightPixels;
123
124 int m_pageWidthMM;
125 int m_pageHeightMM;
126
127 int m_PPIScreenX;
128 int m_PPIScreenY;
129 int m_PPIPrinterX;
130 int m_PPIPrinterY;
131
132 bool m_isPreview;
133 };
134
135 /*
136 * wxPreviewCanvas
137 * Canvas upon which a preview is drawn.
138 */
139
140 class WXDLLEXPORT wxPreviewCanvas: public wxScrolledWindow
141 {
142 DECLARE_CLASS(wxPreviewCanvas)
143
144 public:
145 wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent,
146 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
147 long style = 0, const wxString& name = "canvas");
148 ~wxPreviewCanvas();
149
150 void OnPaint(wxPaintEvent& event);
151
152 // Responds to colour changes
153 void OnSysColourChanged(wxSysColourChangedEvent& event);
154
155 private:
156 wxPrintPreviewBase* m_printPreview;
157
158 DECLARE_EVENT_TABLE()
159 };
160
161 /*
162 * wxPreviewFrame
163 * Default frame for showing preview.
164 */
165
166 class WXDLLEXPORT wxPreviewFrame: public wxFrame
167 {
168 DECLARE_CLASS(wxPreviewFrame)
169
170 public:
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");
174 ~wxPreviewFrame();
175
176 bool OnClose();
177 virtual void Initialize();
178 virtual void CreateCanvas();
179 virtual void CreateControlBar();
180
181 protected:
182 wxWindow* m_previewCanvas;
183 wxPreviewControlBar* m_controlBar;
184 wxPrintPreviewBase* m_printPreview;
185 };
186
187 /*
188 * wxPreviewControlBar
189 * A panel with buttons for controlling a print preview.
190 * The programmer may wish to use other means for controlling
191 * the print preview.
192 */
193
194 #define wxPREVIEW_PRINT 1
195 #define wxPREVIEW_PREVIOUS 2
196 #define wxPREVIEW_NEXT 4
197 #define wxPREVIEW_ZOOM 8
198
199 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
200
201 // Ids for controls
202 #define wxID_PREVIEW_CLOSE 1
203 #define wxID_PREVIEW_NEXT 2
204 #define wxID_PREVIEW_PREVIOUS 3
205 #define wxID_PREVIEW_PRINT 4
206 #define wxID_PREVIEW_ZOOM 5
207
208 class WXDLLEXPORT wxPreviewControlBar: public wxPanel
209 {
210 DECLARE_CLASS(wxPreviewControlBar)
211
212 public:
213 wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons,
214 wxWindow *parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
215 long style = 0, const wxString& name = "panel");
216 ~wxPreviewControlBar();
217
218 virtual void CreateButtons();
219 virtual void SetZoomControl(int zoom);
220 virtual int GetZoomControl();
221 inline virtual wxPrintPreviewBase *GetPrintPreview() const { return m_printPreview; }
222
223 void OnPrint(wxCommandEvent& event);
224 void OnWindowClose(wxCommandEvent& event);
225 void OnNext(wxCommandEvent& event);
226 void OnPrevious(wxCommandEvent& event);
227 void OnZoom(wxCommandEvent& event);
228 void OnPaint(wxPaintEvent& event);
229
230 protected:
231 wxPrintPreviewBase* m_printPreview;
232 wxButton* m_closeButton;
233 wxButton* m_nextPageButton;
234 wxButton* m_previousPageButton;
235 wxButton* m_printButton;
236 wxChoice* m_zoomControl;
237 long m_buttonFlags;
238
239 DECLARE_EVENT_TABLE()
240 };
241
242 /*
243 * wxPrintPreview
244 * Programmer creates an object of this class to preview a wxPrintout.
245 */
246
247 class WXDLLEXPORT wxPrintPreviewBase: public wxObject
248 {
249 DECLARE_CLASS(wxPrintPreviewBase)
250
251 public:
252 wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting = (wxPrintout *) NULL, wxPrintData *data = (wxPrintData *) NULL);
253 ~wxPrintPreviewBase();
254
255 virtual bool SetCurrentPage(int pageNum);
256 inline int GetCurrentPage() const { return m_currentPage; };
257
258 inline void SetPrintout(wxPrintout *printout) { m_previewPrintout = printout; };
259 inline wxPrintout *GetPrintout() const { return m_previewPrintout; };
260 inline wxPrintout *GetPrintoutForPrinting() const { return m_printPrintout; };
261
262 inline void SetFrame(wxFrame *frame) { m_previewFrame = frame; };
263 inline void SetCanvas(wxWindow *canvas) { m_previewCanvas = canvas; };
264
265 inline virtual wxFrame *GetFrame() const { return m_previewFrame; }
266 inline virtual wxWindow *GetCanvas() const { return m_previewCanvas; }
267
268 // The preview canvas should call this from OnPaint
269 virtual bool PaintPage(wxWindow *canvas, wxDC& dc);
270
271 // This draws a blank page onto the preview canvas
272 virtual bool DrawBlankPage(wxWindow *canvas, wxDC& dc);
273
274 // This is called by wxPrintPreview to render a page into
275 // a wxMemoryDC.
276 virtual bool RenderPage(int pageNum);
277
278 inline wxPrintData& GetPrintData() { return m_printData; }
279
280 virtual void SetZoom(int percent);
281 inline int GetZoom() const { return m_currentZoom; };
282
283 inline int GetMaxPage() const { return m_maxPage; }
284 inline int GetMinPage() const { return m_minPage; }
285
286 inline bool Ok() const { return m_isOk; }
287 inline void SetOk(bool ok) { m_isOk = ok; }
288
289 ///////////////////////////////////////////////////////////////////////////
290 // OVERRIDES
291
292 // If we own a wxPrintout that can be used for printing, this
293 // will invoke the actual printing procedure. Called
294 // by the wxPreviewControlBar.
295 virtual bool Print(bool interactive) = 0;
296
297 // Calculate scaling that needs to be done to get roughly
298 // the right scaling for the screen pretending to be
299 // the currently selected printer.
300 virtual void DetermineScaling() = 0;
301
302 protected:
303 wxPrintData m_printData;
304 wxWindow* m_previewCanvas;
305 wxFrame* m_previewFrame;
306 wxBitmap* m_previewBitmap;
307 wxPrintout* m_previewPrintout;
308 wxPrintout* m_printPrintout;
309 int m_currentPage;
310 int m_currentZoom;
311 float m_previewScale;
312 int m_topMargin;
313 int m_leftMargin;
314 int m_pageWidth;
315 int m_pageHeight;
316 int m_minPage;
317 int m_maxPage;
318 protected:
319 bool m_isOk;
320 };
321
322 /*
323 * Abort dialog
324 */
325
326 class WXDLLEXPORT wxPrintAbortDialog: public wxDialog
327 {
328 public:
329 wxPrintAbortDialog(wxWindow *parent,
330 const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
331 long style = 0, const wxString& name = "dialog"):
332 wxDialog(parent, -1, title, pos, size, style, name)
333 {
334 }
335
336 void OnCancel(wxCommandEvent& event);
337
338 DECLARE_EVENT_TABLE()
339 };
340
341 #endif
342 // _WX_PRNTBASEH__