]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/prntbase.h
Added a wxDataFormat::SetAtom() inline function.
[wxWidgets.git] / include / wx / prntbase.h
... / ...
CommitLineData
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
27class WXDLLEXPORT wxDC;
28class WXDLLEXPORT wxButton;
29class WXDLLEXPORT wxChoice;
30class WXDLLEXPORT wxPrintout;
31class WXDLLEXPORT wxPrinterBase;
32class WXDLLEXPORT wxPrintDialog;
33class WXDLLEXPORT wxPrintPreviewBase;
34class WXDLLEXPORT wxPreviewCanvas;
35class WXDLLEXPORT wxPreviewControlBar;
36class WXDLLEXPORT wxPreviewFrame;
37
38/*
39 * Represents the printer: manages printing a wxPrintout object
40 */
41
42class WXDLLEXPORT wxPrinterBase: public wxObject
43{
44 DECLARE_CLASS(wxPrinterBase)
45
46public:
47 wxPrinterBase(wxPrintDialogData *data = (wxPrintDialogData *) NULL);
48 virtual ~wxPrinterBase();
49
50 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout);
51 virtual void ReportError(wxWindow *parent, wxPrintout *printout, char *message);
52
53 wxPrintDialogData& GetPrintDialogData() const
54 { return (wxPrintDialogData&) m_printDialogData; }
55 bool GetAbort() const { return sm_abortIt; }
56
57 ///////////////////////////////////////////////////////////////////////////
58 // OVERRIDES
59
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;
63
64protected:
65 wxPrintDialogData m_printDialogData;
66 wxPrintout* m_currentPrintout;
67public:
68 static wxWindow* sm_abortWindow;
69 static bool sm_abortIt;
70
71};
72
73/*
74 * wxPrintout
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.
79 */
80
81class WXDLLEXPORT wxPrintout: public wxObject
82{
83DECLARE_ABSTRACT_CLASS(wxPrintout)
84
85public:
86 wxPrintout(const wxString& title = "Printout");
87 virtual ~wxPrintout();
88
89 virtual bool OnBeginDocument(int startPage, int endPage);
90 virtual void OnEndDocument();
91 virtual void OnBeginPrinting();
92 virtual void OnEndPrinting();
93
94 // Guaranteed to be before any other functions are called
95 virtual void OnPreparePrinting() { }
96
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);
100
101 virtual wxString GetTitle() const { return m_printoutTitle; }
102
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; }
109
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; }
114
115 virtual bool IsPreview() const { return m_isPreview; }
116
117 virtual void SetIsPreview(bool p) { m_isPreview = p; }
118
119private:
120 wxString m_printoutTitle;
121 wxDC* m_printoutDC;
122
123 int m_pageWidthPixels;
124 int m_pageHeightPixels;
125
126 int m_pageWidthMM;
127 int m_pageHeightMM;
128
129 int m_PPIScreenX;
130 int m_PPIScreenY;
131 int m_PPIPrinterX;
132 int m_PPIPrinterY;
133
134 bool m_isPreview;
135};
136
137/*
138 * wxPreviewCanvas
139 * Canvas upon which a preview is drawn.
140 */
141
142class WXDLLEXPORT wxPreviewCanvas: public wxScrolledWindow
143{
144 DECLARE_CLASS(wxPreviewCanvas)
145
146public:
147 wxPreviewCanvas(wxPrintPreviewBase *preview,
148 wxWindow *parent,
149 const wxPoint& pos = wxDefaultPosition,
150 const wxSize& size = wxDefaultSize,
151 long style = 0,
152 const wxString& name = "canvas");
153 ~wxPreviewCanvas();
154
155 void OnPaint(wxPaintEvent& event);
156
157 // Responds to colour changes
158 void OnSysColourChanged(wxSysColourChangedEvent& event);
159
160private:
161 wxPrintPreviewBase* m_printPreview;
162
163 DECLARE_EVENT_TABLE()
164};
165
166/*
167 * wxPreviewFrame
168 * Default frame for showing preview.
169 */
170
171class WXDLLEXPORT wxPreviewFrame: public wxFrame
172{
173 DECLARE_CLASS(wxPreviewFrame)
174
175public:
176 wxPreviewFrame(wxPrintPreviewBase *preview,
177 wxFrame *parent,
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");
183 ~wxPreviewFrame();
184
185 void OnCloseWindow(wxCloseEvent& event);
186 virtual void Initialize();
187 virtual void CreateCanvas();
188 virtual void CreateControlBar();
189
190protected:
191 wxWindow* m_previewCanvas;
192 wxPreviewControlBar* m_controlBar;
193 wxPrintPreviewBase* m_printPreview;
194
195private:
196 DECLARE_EVENT_TABLE()
197};
198
199/*
200 * wxPreviewControlBar
201 * A panel with buttons for controlling a print preview.
202 * The programmer may wish to use other means for controlling
203 * the print preview.
204 */
205
206#define wxPREVIEW_PRINT 1
207#define wxPREVIEW_PREVIOUS 2
208#define wxPREVIEW_NEXT 4
209#define wxPREVIEW_ZOOM 8
210
211#define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM
212
213// Ids for controls
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
219
220class WXDLLEXPORT wxPreviewControlBar: public wxPanel
221{
222 DECLARE_CLASS(wxPreviewControlBar)
223
224public:
225 wxPreviewControlBar(wxPrintPreviewBase *preview,
226 long buttons,
227 wxWindow *parent,
228 const wxPoint& pos = wxDefaultPosition,
229 const wxSize& size = wxDefaultSize,
230 long style = 0,
231 const wxString& name = "panel");
232 ~wxPreviewControlBar();
233
234 virtual void CreateButtons();
235 virtual void SetZoomControl(int zoom);
236 virtual int GetZoomControl();
237 virtual wxPrintPreviewBase *GetPrintPreview() const
238 { return m_printPreview; }
239
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);
246
247protected:
248 wxPrintPreviewBase* m_printPreview;
249 wxButton* m_closeButton;
250 wxButton* m_nextPageButton;
251 wxButton* m_previousPageButton;
252 wxButton* m_printButton;
253 wxChoice* m_zoomControl;
254 long m_buttonFlags;
255
256private:
257 DECLARE_EVENT_TABLE()
258};
259
260/*
261 * wxPrintPreview
262 * Programmer creates an object of this class to preview a wxPrintout.
263 */
264
265class WXDLLEXPORT wxPrintPreviewBase: public wxObject
266{
267 DECLARE_CLASS(wxPrintPreviewBase)
268
269public:
270 wxPrintPreviewBase(wxPrintout *printout,
271 wxPrintout *printoutForPrinting = (wxPrintout *) NULL,
272 wxPrintDialogData *data = (wxPrintDialogData *) NULL);
273 wxPrintPreviewBase(wxPrintout *printout,
274 wxPrintout *printoutForPrinting,
275 wxPrintData *data);
276 virtual ~wxPrintPreviewBase();
277
278 virtual bool SetCurrentPage(int pageNum);
279 int GetCurrentPage() const { return m_currentPage; };
280
281 void SetPrintout(wxPrintout *printout) { m_previewPrintout = printout; };
282 wxPrintout *GetPrintout() const { return m_previewPrintout; };
283 wxPrintout *GetPrintoutForPrinting() const { return m_printPrintout; };
284
285 void SetFrame(wxFrame *frame) { m_previewFrame = frame; };
286 void SetCanvas(wxWindow *canvas) { m_previewCanvas = canvas; };
287
288 virtual wxFrame *GetFrame() const { return m_previewFrame; }
289 virtual wxWindow *GetCanvas() const { return m_previewCanvas; }
290
291 // The preview canvas should call this from OnPaint
292 virtual bool PaintPage(wxWindow *canvas, wxDC& dc);
293
294 // This draws a blank page onto the preview canvas
295 virtual bool DrawBlankPage(wxWindow *canvas, wxDC& dc);
296
297 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
298 virtual bool RenderPage(int pageNum);
299
300 wxPrintDialogData& GetPrintDialogData() { return m_printDialogData; }
301
302 virtual void SetZoom(int percent);
303 int GetZoom() const { return m_currentZoom; };
304
305 int GetMaxPage() const { return m_maxPage; }
306 int GetMinPage() const { return m_minPage; }
307
308 bool Ok() const { return m_isOk; }
309 void SetOk(bool ok) { m_isOk = ok; }
310
311 ///////////////////////////////////////////////////////////////////////////
312 // OVERRIDES
313
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;
318
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;
323
324protected:
325 wxPrintDialogData m_printDialogData;
326 wxWindow* m_previewCanvas;
327 wxFrame* m_previewFrame;
328 wxBitmap* m_previewBitmap;
329 wxPrintout* m_previewPrintout;
330 wxPrintout* m_printPrintout;
331 int m_currentPage;
332 int m_currentZoom;
333 float m_previewScale;
334 int m_topMargin;
335 int m_leftMargin;
336 int m_pageWidth;
337 int m_pageHeight;
338 int m_minPage;
339 int m_maxPage;
340
341 bool m_isOk;
342
343private:
344 void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
345};
346
347/*
348 * Abort dialog
349 */
350
351class WXDLLEXPORT wxPrintAbortDialog: public wxDialog
352{
353public:
354 wxPrintAbortDialog(wxWindow *parent,
355 const wxString& title,
356 const wxPoint& pos = wxDefaultPosition,
357 const wxSize& size = wxDefaultSize,
358 long style = 0,
359 const wxString& name = "dialog")
360 : wxDialog(parent, -1, title, pos, size, style, name)
361 {
362 }
363
364 void OnCancel(wxCommandEvent& event);
365
366private:
367 DECLARE_EVENT_TABLE()
368};
369
370#endif
371 // _WX_PRNTBASEH__