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