]> git.saurik.com Git - wxWidgets.git/blob - include/wx/prntbase.h
wxString::IsSameAs(char) added and documented as well as operator==(char)
[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
21 #if wxUSE_PRINTING_ARCHITECTURE
22
23 #include "wx/event.h"
24 #include "wx/cmndata.h"
25 #include "wx/panel.h"
26 #include "wx/scrolwin.h"
27 #include "wx/dialog.h"
28 #include "wx/frame.h"
29
30 class WXDLLEXPORT wxDC;
31 class WXDLLEXPORT wxButton;
32 class WXDLLEXPORT wxChoice;
33 class WXDLLEXPORT wxPrintout;
34 class WXDLLEXPORT wxPrinterBase;
35 class WXDLLEXPORT wxPrintDialog;
36 class WXDLLEXPORT wxPrintPreviewBase;
37 class WXDLLEXPORT wxPreviewCanvas;
38 class WXDLLEXPORT wxPreviewControlBar;
39 class WXDLLEXPORT wxPreviewFrame;
40
41 /*
42 * Represents the printer: manages printing a wxPrintout object
43 */
44
45 class WXDLLEXPORT wxPrinterBase: public wxObject
46 {
47 DECLARE_CLASS(wxPrinterBase)
48
49 public:
50 wxPrinterBase(wxPrintDialogData *data = (wxPrintDialogData *) NULL);
51 virtual ~wxPrinterBase();
52
53 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout);
54 virtual void ReportError(wxWindow *parent, wxPrintout *printout, char *message);
55
56 wxPrintDialogData& GetPrintDialogData() const
57 { return (wxPrintDialogData&) m_printDialogData; }
58 bool GetAbort() const { return sm_abortIt; }
59
60 ///////////////////////////////////////////////////////////////////////////
61 // OVERRIDES
62
63 virtual bool Setup(wxWindow *parent) = 0;
64 virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = TRUE) = 0;
65 virtual wxDC* PrintDialog(wxWindow *parent) = 0;
66
67 protected:
68 wxPrintDialogData m_printDialogData;
69 wxPrintout* m_currentPrintout;
70 public:
71 static wxWindow* sm_abortWindow;
72 static bool sm_abortIt;
73
74 };
75
76 /*
77 * wxPrintout
78 * Represents an object via which a document may be printed.
79 * The programmer derives from this, overrides (at least) OnPrintPage,
80 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
81 * object for previewing.
82 */
83
84 class WXDLLEXPORT wxPrintout: public wxObject
85 {
86 DECLARE_ABSTRACT_CLASS(wxPrintout)
87
88 public:
89 wxPrintout(const wxString& title = "Printout");
90 virtual ~wxPrintout();
91
92 virtual bool OnBeginDocument(int startPage, int endPage);
93 virtual void OnEndDocument();
94 virtual void OnBeginPrinting();
95 virtual void OnEndPrinting();
96
97 // Guaranteed to be before any other functions are called
98 virtual void OnPreparePrinting() { }
99
100 virtual bool HasPage(int page);
101 virtual bool OnPrintPage(int page) = 0;
102 virtual void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo);
103
104 virtual wxString GetTitle() const { return m_printoutTitle; }
105
106 wxDC *GetDC() const { return m_printoutDC; }
107 void SetDC(wxDC *dc) { m_printoutDC = dc; }
108 void SetPageSizePixels(int w, int h) { m_pageWidthPixels = w; m_pageHeightPixels = h; }
109 void GetPageSizePixels(int *w, int *h) const { *w = m_pageWidthPixels; *h = m_pageHeightPixels; }
110 void SetPageSizeMM(int w, int h) { m_pageWidthMM = w; m_pageHeightMM = h; }
111 void GetPageSizeMM(int *w, int *h) const { *w = m_pageWidthMM; *h = m_pageHeightMM; }
112
113 void SetPPIScreen(int x, int y) { m_PPIScreenX = x; m_PPIScreenY = y; }
114 void GetPPIScreen(int *x, int *y) const { *x = m_PPIScreenX; *y = m_PPIScreenY; }
115 void SetPPIPrinter(int x, int y) { m_PPIPrinterX = x; m_PPIPrinterY = y; }
116 void GetPPIPrinter(int *x, int *y) const { *x = m_PPIPrinterX; *y = m_PPIPrinterY; }
117
118 virtual bool IsPreview() const { return m_isPreview; }
119
120 virtual void SetIsPreview(bool p) { m_isPreview = p; }
121
122 private:
123 wxString m_printoutTitle;
124 wxDC* m_printoutDC;
125
126 int m_pageWidthPixels;
127 int m_pageHeightPixels;
128
129 int m_pageWidthMM;
130 int m_pageHeightMM;
131
132 int m_PPIScreenX;
133 int m_PPIScreenY;
134 int m_PPIPrinterX;
135 int m_PPIPrinterY;
136
137 bool m_isPreview;
138 };
139
140 /*
141 * wxPreviewCanvas
142 * Canvas upon which a preview is drawn.
143 */
144
145 class WXDLLEXPORT wxPreviewCanvas: public wxScrolledWindow
146 {
147 DECLARE_CLASS(wxPreviewCanvas)
148
149 public:
150 wxPreviewCanvas(wxPrintPreviewBase *preview,
151 wxWindow *parent,
152 const wxPoint& pos = wxDefaultPosition,
153 const wxSize& size = wxDefaultSize,
154 long style = 0,
155 const wxString& name = "canvas");
156 ~wxPreviewCanvas();
157
158 void OnPaint(wxPaintEvent& event);
159
160 // Responds to colour changes
161 void OnSysColourChanged(wxSysColourChangedEvent& event);
162
163 private:
164 wxPrintPreviewBase* m_printPreview;
165
166 DECLARE_EVENT_TABLE()
167 };
168
169 /*
170 * wxPreviewFrame
171 * Default frame for showing preview.
172 */
173
174 class WXDLLEXPORT wxPreviewFrame: public wxFrame
175 {
176 DECLARE_CLASS(wxPreviewFrame)
177
178 public:
179 wxPreviewFrame(wxPrintPreviewBase *preview,
180 wxFrame *parent,
181 const wxString& title = "Print Preview",
182 const wxPoint& pos = wxDefaultPosition,
183 const wxSize& size = wxDefaultSize,
184 long style = wxDEFAULT_FRAME_STYLE,
185 const wxString& name = "frame");
186 ~wxPreviewFrame();
187
188 void OnCloseWindow(wxCloseEvent& event);
189 virtual void Initialize();
190 virtual void CreateCanvas();
191 virtual void CreateControlBar();
192
193 protected:
194 wxWindow* m_previewCanvas;
195 wxPreviewControlBar* m_controlBar;
196 wxPrintPreviewBase* m_printPreview;
197
198 private:
199 DECLARE_EVENT_TABLE()
200 };
201
202 /*
203 * wxPreviewControlBar
204 * A panel with buttons for controlling a print preview.
205 * The programmer may wish to use other means for controlling
206 * the print preview.
207 */
208
209 #define wxPREVIEW_PRINT 1
210 #define wxPREVIEW_PREVIOUS 2
211 #define wxPREVIEW_NEXT 4
212 #define wxPREVIEW_ZOOM 8
213
214 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
215
216 // Ids for controls
217 #define wxID_PREVIEW_CLOSE 1
218 #define wxID_PREVIEW_NEXT 2
219 #define wxID_PREVIEW_PREVIOUS 3
220 #define wxID_PREVIEW_PRINT 4
221 #define wxID_PREVIEW_ZOOM 5
222
223 class WXDLLEXPORT wxPreviewControlBar: public wxPanel
224 {
225 DECLARE_CLASS(wxPreviewControlBar)
226
227 public:
228 wxPreviewControlBar(wxPrintPreviewBase *preview,
229 long buttons,
230 wxWindow *parent,
231 const wxPoint& pos = wxDefaultPosition,
232 const wxSize& size = wxDefaultSize,
233 long style = 0,
234 const wxString& name = "panel");
235 ~wxPreviewControlBar();
236
237 virtual void CreateButtons();
238 virtual void SetZoomControl(int zoom);
239 virtual int GetZoomControl();
240 virtual wxPrintPreviewBase *GetPrintPreview() const
241 { return m_printPreview; }
242
243 void OnPrint(wxCommandEvent& event);
244 void OnWindowClose(wxCommandEvent& event);
245 void OnNext(wxCommandEvent& event);
246 void OnPrevious(wxCommandEvent& event);
247 void OnZoom(wxCommandEvent& event);
248 void OnPaint(wxPaintEvent& event);
249
250 protected:
251 wxPrintPreviewBase* m_printPreview;
252 wxButton* m_closeButton;
253 wxButton* m_nextPageButton;
254 wxButton* m_previousPageButton;
255 wxButton* m_printButton;
256 wxChoice* m_zoomControl;
257 long m_buttonFlags;
258
259 private:
260 DECLARE_EVENT_TABLE()
261 };
262
263 /*
264 * wxPrintPreview
265 * Programmer creates an object of this class to preview a wxPrintout.
266 */
267
268 class WXDLLEXPORT wxPrintPreviewBase: public wxObject
269 {
270 DECLARE_CLASS(wxPrintPreviewBase)
271
272 public:
273 wxPrintPreviewBase(wxPrintout *printout,
274 wxPrintout *printoutForPrinting = (wxPrintout *) NULL,
275 wxPrintDialogData *data = (wxPrintDialogData *) NULL);
276 wxPrintPreviewBase(wxPrintout *printout,
277 wxPrintout *printoutForPrinting,
278 wxPrintData *data);
279 virtual ~wxPrintPreviewBase();
280
281 virtual bool SetCurrentPage(int pageNum);
282 int GetCurrentPage() const { return m_currentPage; };
283
284 void SetPrintout(wxPrintout *printout) { m_previewPrintout = printout; };
285 wxPrintout *GetPrintout() const { return m_previewPrintout; };
286 wxPrintout *GetPrintoutForPrinting() const { return m_printPrintout; };
287
288 void SetFrame(wxFrame *frame) { m_previewFrame = frame; };
289 void SetCanvas(wxWindow *canvas) { m_previewCanvas = canvas; };
290
291 virtual wxFrame *GetFrame() const { return m_previewFrame; }
292 virtual wxWindow *GetCanvas() const { return m_previewCanvas; }
293
294 // The preview canvas should call this from OnPaint
295 virtual bool PaintPage(wxWindow *canvas, wxDC& dc);
296
297 // This draws a blank page onto the preview canvas
298 virtual bool DrawBlankPage(wxWindow *canvas, wxDC& dc);
299
300 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
301 virtual bool RenderPage(int pageNum);
302
303 wxPrintDialogData& GetPrintDialogData() { return m_printDialogData; }
304
305 virtual void SetZoom(int percent);
306 int GetZoom() const { return m_currentZoom; };
307
308 int GetMaxPage() const { return m_maxPage; }
309 int GetMinPage() const { return m_minPage; }
310
311 bool Ok() const { return m_isOk; }
312 void SetOk(bool ok) { m_isOk = ok; }
313
314 ///////////////////////////////////////////////////////////////////////////
315 // OVERRIDES
316
317 // If we own a wxPrintout that can be used for printing, this
318 // will invoke the actual printing procedure. Called
319 // by the wxPreviewControlBar.
320 virtual bool Print(bool interactive) = 0;
321
322 // Calculate scaling that needs to be done to get roughly
323 // the right scaling for the screen pretending to be
324 // the currently selected printer.
325 virtual void DetermineScaling() = 0;
326
327 protected:
328 wxPrintDialogData m_printDialogData;
329 wxWindow* m_previewCanvas;
330 wxFrame* m_previewFrame;
331 wxBitmap* m_previewBitmap;
332 wxPrintout* m_previewPrintout;
333 wxPrintout* m_printPrintout;
334 int m_currentPage;
335 int m_currentZoom;
336 float m_previewScale;
337 int m_topMargin;
338 int m_leftMargin;
339 int m_pageWidth;
340 int m_pageHeight;
341 int m_minPage;
342 int m_maxPage;
343
344 bool m_isOk;
345
346 private:
347 void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
348 };
349
350 /*
351 * Abort dialog
352 */
353
354 class WXDLLEXPORT wxPrintAbortDialog: public wxDialog
355 {
356 public:
357 wxPrintAbortDialog(wxWindow *parent,
358 const wxString& title,
359 const wxPoint& pos = wxDefaultPosition,
360 const wxSize& size = wxDefaultSize,
361 long style = 0,
362 const wxString& name = "dialog")
363 : wxDialog(parent, -1, title, pos, size, style, name)
364 {
365 }
366
367 void OnCancel(wxCommandEvent& event);
368
369 private:
370 DECLARE_EVENT_TABLE()
371 };
372
373 #endif // wxUSE_PRINTING_ARCHITECTURE
374
375 #endif
376 // _WX_PRNTBASEH__