]> git.saurik.com Git - wxWidgets.git/blob - include/wx/prntbase.h
Changed floats to doubles in wxexpr.h; added a flag in accel.h (wxACCEL_NONE for
[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 protected:
47 wxPrintData printData;
48 wxPrintout *currentPrintout;
49 public:
50 static wxWindow *abortWindow;
51 static bool abortIt;
52
53 wxPrinterBase(wxPrintData *data = NULL);
54 ~wxPrinterBase(void);
55
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; }
60
61 ///////////////////////////////////////////////////////////////////////////
62 // OVERRIDES
63
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;
67 };
68
69 /*
70 * wxPrintout
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.
75 */
76
77 class WXDLLEXPORT wxPrintout: public wxObject
78 {
79 DECLARE_ABSTRACT_CLASS(wxPrintout)
80
81 private:
82 char *printoutTitle;
83 wxDC *printoutDC;
84
85 int pageWidthPixels;
86 int pageHeightPixels;
87
88 int pageWidthMM;
89 int pageHeightMM;
90
91 int PPIScreenX;
92 int PPIScreenY;
93 int PPIPrinterX;
94 int PPIPrinterY;
95
96 bool isPreview;
97 public:
98 wxPrintout(const char *title = "Printout");
99 ~wxPrintout(void);
100
101 virtual bool OnBeginDocument(int startPage, int endPage);
102 virtual void OnEndDocument(void);
103 virtual void OnBeginPrinting(void);
104 virtual void OnEndPrinting(void);
105
106 // Guaranteed to be before any other functions are called
107 inline virtual void OnPreparePrinting(void) { }
108
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);
112
113 inline virtual char *GetTitle(void) { return printoutTitle; }
114
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; }
121
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; }
126
127 inline virtual bool IsPreview(void) { return isPreview; }
128
129 inline virtual void SetIsPreview(bool p) { isPreview = p; }
130 };
131
132 /*
133 * wxPreviewCanvas
134 * Canvas upon which a preview is drawn.
135 */
136
137 class WXDLLEXPORT wxPreviewCanvas: public wxScrolledWindow
138 {
139 DECLARE_CLASS(wxPreviewCanvas)
140
141 private:
142 wxPrintPreviewBase *printPreview;
143 public:
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);
148
149 void OnPaint(wxPaintEvent& event);
150
151 // Responds to colour changes
152 void OnSysColourChanged(wxSysColourChangedEvent& event);
153
154 DECLARE_EVENT_TABLE()
155 };
156
157 /*
158 * wxPreviewFrame
159 * Default frame for showing preview.
160 */
161
162 class WXDLLEXPORT wxPreviewFrame: public wxFrame
163 {
164 DECLARE_CLASS(wxPreviewFrame)
165
166 protected:
167 wxWindow *previewCanvas;
168 wxPreviewControlBar *controlBar;
169 wxPrintPreviewBase *printPreview;
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, const wxString& name = "frame");
174 ~wxPreviewFrame(void);
175
176 bool OnClose(void);
177 virtual void Initialize(void);
178 virtual void CreateCanvas(void);
179 virtual void CreateControlBar(void);
180 };
181
182 /*
183 * wxPreviewControlBar
184 * A panel with buttons for controlling a print preview.
185 * The programmer may wish to use other means for controlling
186 * the print preview.
187 */
188
189 #define wxPREVIEW_PRINT 1
190 #define wxPREVIEW_PREVIOUS 2
191 #define wxPREVIEW_NEXT 4
192 #define wxPREVIEW_ZOOM 8
193
194 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
195
196 // Ids for controls
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
202
203 class WXDLLEXPORT wxPreviewControlBar: public wxPanel
204 {
205 DECLARE_CLASS(wxPreviewControlBar)
206
207 protected:
208 wxPrintPreviewBase *printPreview;
209 wxButton *closeButton;
210 wxButton *nextPageButton;
211 wxButton *previousPageButton;
212 wxButton *printButton;
213 wxChoice *zoomControl;
214 static wxFont *buttonFont;
215 long buttonFlags;
216 public:
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);
221
222 virtual void CreateButtons(void);
223 virtual void SetZoomControl(int zoom);
224 virtual int GetZoomControl(void);
225 inline virtual wxPrintPreviewBase *GetPrintPreview(void) { return printPreview; }
226
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);
233
234 DECLARE_EVENT_TABLE()
235 };
236
237 /*
238 * wxPrintPreview
239 * Programmer creates an object of this class to preview a wxPrintout.
240 */
241
242 class WXDLLEXPORT wxPrintPreviewBase: public wxObject
243 {
244 DECLARE_CLASS(wxPrintPreviewBase)
245
246 protected:
247 wxPrintData printData;
248 wxWindow *previewCanvas;
249 wxFrame *previewFrame;
250 wxBitmap *previewBitmap;
251 wxPrintout *previewPrintout;
252 wxPrintout *printPrintout;
253 int currentPage;
254 int currentZoom;
255 float previewScale;
256 int topMargin;
257 int leftMargin;
258 int pageWidth;
259 int pageHeight;
260 int minPage;
261 int maxPage;
262 protected:
263 bool isOk;
264 public:
265 wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting = NULL, wxPrintData *data = NULL);
266 ~wxPrintPreviewBase(void);
267
268 virtual bool SetCurrentPage(int pageNum);
269 inline int GetCurrentPage(void) { return currentPage; };
270
271 inline void SetPrintout(wxPrintout *printout) { previewPrintout = printout; };
272 inline wxPrintout *GetPrintout(void) { return previewPrintout; };
273 inline wxPrintout *GetPrintoutForPrinting(void) { return printPrintout; };
274
275 inline void SetFrame(wxFrame *frame) { previewFrame = frame; };
276 inline void SetCanvas(wxWindow *canvas) { previewCanvas = canvas; };
277
278 inline virtual wxFrame *GetFrame(void) { return previewFrame; }
279 inline virtual wxWindow *GetCanvas(void) { return previewCanvas; }
280
281 // The preview canvas should call this from OnPaint
282 virtual bool PaintPage(wxWindow *canvas, wxDC& dc);
283
284 // This draws a blank page onto the preview canvas
285 virtual bool DrawBlankPage(wxWindow *canvas, wxDC& dc);
286
287 // This is called by wxPrintPreview to render a page into
288 // a wxMemoryDC.
289 virtual bool RenderPage(int pageNum);
290
291 inline wxPrintData& GetPrintData(void) { return printData; }
292
293 virtual void SetZoom(int percent);
294 int GetZoom(void) { return currentZoom; };
295
296 inline int GetMaxPage(void) { return maxPage; }
297 inline int GetMinPage(void) { return minPage; }
298
299 inline bool Ok(void) { return isOk; }
300 inline void SetOk(bool ok) { isOk = ok; }
301
302 ///////////////////////////////////////////////////////////////////////////
303 // OVERRIDES
304
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;
309
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;
314 };
315
316 /*
317 * Abort dialog
318 */
319
320 class WXDLLEXPORT wxPrintAbortDialog: public wxDialog
321 {
322 public:
323 void OnCancel(wxCommandEvent& event);
324
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)
329 {
330 }
331
332 DECLARE_EVENT_TABLE()
333 };
334
335 #endif
336 // _WX_PRNTBASEH__