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