]> git.saurik.com Git - wxWidgets.git/blame - include/wx/prntbase.h
wxScrolledWindow inherits from wxPanel to
[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
d6b9496a 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_PRNTBASEH__
13#define _WX_PRNTBASEH__
c801d85f
KB
14
15#ifdef __GNUG__
d6b9496a 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 */
d6b9496a 41
c801d85f
KB
42class WXDLLEXPORT wxPrinterBase: public wxObject
43{
d6b9496a 44 DECLARE_CLASS(wxPrinterBase)
c801d85f 45
34da0970 46public:
d6b9496a
VZ
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);
c801d85f 52
d6b9496a
VZ
53 wxPrintDialogData& GetPrintDialogData() const
54 { return (wxPrintDialogData&) m_printDialogData; }
55 bool GetAbort() const { return sm_abortIt; }
c801d85f 56
d6b9496a
VZ
57 ///////////////////////////////////////////////////////////////////////////
58 // OVERRIDES
c801d85f 59
d6b9496a
VZ
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;
34da0970
JS
63
64protected:
d6b9496a
VZ
65 wxPrintDialogData m_printDialogData;
66 wxPrintout* m_currentPrintout;
34da0970 67public:
d6b9496a
VZ
68 static wxWindow* sm_abortWindow;
69 static bool sm_abortIt;
34da0970 70
c801d85f
KB
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 */
d6b9496a 80
c801d85f
KB
81class WXDLLEXPORT wxPrintout: public wxObject
82{
d6b9496a 83DECLARE_ABSTRACT_CLASS(wxPrintout)
c801d85f 84
34da0970 85public:
d6b9496a
VZ
86 wxPrintout(const wxString& title = "Printout");
87 virtual ~wxPrintout();
c801d85f 88
d6b9496a
VZ
89 virtual bool OnBeginDocument(int startPage, int endPage);
90 virtual void OnEndDocument();
91 virtual void OnBeginPrinting();
92 virtual void OnEndPrinting();
c801d85f 93
d6b9496a
VZ
94 // Guaranteed to be before any other functions are called
95 virtual void OnPreparePrinting() { }
c801d85f 96
d6b9496a
VZ
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);
c801d85f 100
d6b9496a 101 virtual wxString GetTitle() const { return m_printoutTitle; }
34da0970 102
d6b9496a
VZ
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; }
34da0970 109
d6b9496a
VZ
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; }
34da0970 114
d6b9496a 115 virtual bool IsPreview() const { return m_isPreview; }
34da0970 116
d6b9496a 117 virtual void SetIsPreview(bool p) { m_isPreview = p; }
34da0970
JS
118
119private:
d6b9496a
VZ
120 wxString m_printoutTitle;
121 wxDC* m_printoutDC;
c801d85f 122
d6b9496a
VZ
123 int m_pageWidthPixels;
124 int m_pageHeightPixels;
c801d85f 125
d6b9496a
VZ
126 int m_pageWidthMM;
127 int m_pageHeightMM;
c801d85f 128
d6b9496a
VZ
129 int m_PPIScreenX;
130 int m_PPIScreenY;
131 int m_PPIPrinterX;
132 int m_PPIPrinterY;
c801d85f 133
d6b9496a 134 bool m_isPreview;
c801d85f
KB
135};
136
137/*
138 * wxPreviewCanvas
139 * Canvas upon which a preview is drawn.
140 */
d6b9496a 141
c801d85f
KB
142class WXDLLEXPORT wxPreviewCanvas: public wxScrolledWindow
143{
d6b9496a 144 DECLARE_CLASS(wxPreviewCanvas)
c801d85f 145
34da0970 146public:
d6b9496a
VZ
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();
c801d85f 154
d6b9496a 155 void OnPaint(wxPaintEvent& event);
c801d85f 156
d6b9496a
VZ
157 // Responds to colour changes
158 void OnSysColourChanged(wxSysColourChangedEvent& event);
c801d85f 159
34da0970 160private:
d6b9496a 161 wxPrintPreviewBase* m_printPreview;
34da0970 162
d6b9496a 163 DECLARE_EVENT_TABLE()
c801d85f
KB
164};
165
166/*
167 * wxPreviewFrame
168 * Default frame for showing preview.
169 */
170
171class WXDLLEXPORT wxPreviewFrame: public wxFrame
172{
d6b9496a 173 DECLARE_CLASS(wxPreviewFrame)
c801d85f 174
34da0970 175public:
d6b9496a
VZ
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();
34da0970
JS
189
190protected:
d6b9496a
VZ
191 wxWindow* m_previewCanvas;
192 wxPreviewControlBar* m_controlBar;
193 wxPrintPreviewBase* m_printPreview;
e3065973 194
d6b9496a
VZ
195private:
196 DECLARE_EVENT_TABLE()
c801d85f
KB
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{
d6b9496a 222 DECLARE_CLASS(wxPreviewControlBar)
c801d85f 223
34da0970 224public:
d6b9496a
VZ
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);
c801d85f 246
34da0970 247protected:
d6b9496a
VZ
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()
c801d85f
KB
258};
259
260/*
261 * wxPrintPreview
262 * Programmer creates an object of this class to preview a wxPrintout.
263 */
d6b9496a 264
c801d85f
KB
265class WXDLLEXPORT wxPrintPreviewBase: public wxObject
266{
d6b9496a 267 DECLARE_CLASS(wxPrintPreviewBase)
c801d85f 268
34da0970 269public:
d6b9496a
VZ
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();
c801d85f 277
d6b9496a
VZ
278 virtual bool SetCurrentPage(int pageNum);
279 int GetCurrentPage() const { return m_currentPage; };
c801d85f 280
d6b9496a
VZ
281 void SetPrintout(wxPrintout *printout) { m_previewPrintout = printout; };
282 wxPrintout *GetPrintout() const { return m_previewPrintout; };
283 wxPrintout *GetPrintoutForPrinting() const { return m_printPrintout; };
c801d85f 284
d6b9496a
VZ
285 void SetFrame(wxFrame *frame) { m_previewFrame = frame; };
286 void SetCanvas(wxWindow *canvas) { m_previewCanvas = canvas; };
c801d85f 287
d6b9496a
VZ
288 virtual wxFrame *GetFrame() const { return m_previewFrame; }
289 virtual wxWindow *GetCanvas() const { return m_previewCanvas; }
c801d85f 290
d6b9496a
VZ
291 // The preview canvas should call this from OnPaint
292 virtual bool PaintPage(wxWindow *canvas, wxDC& dc);
c801d85f 293
d6b9496a
VZ
294 // This draws a blank page onto the preview canvas
295 virtual bool DrawBlankPage(wxWindow *canvas, wxDC& dc);
c801d85f 296
d6b9496a
VZ
297 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
298 virtual bool RenderPage(int pageNum);
c801d85f 299
d6b9496a 300 wxPrintDialogData& GetPrintDialogData() { return m_printDialogData; }
c801d85f 301
d6b9496a
VZ
302 virtual void SetZoom(int percent);
303 int GetZoom() const { return m_currentZoom; };
34da0970 304
d6b9496a
VZ
305 int GetMaxPage() const { return m_maxPage; }
306 int GetMinPage() const { return m_minPage; }
c801d85f 307
d6b9496a
VZ
308 bool Ok() const { return m_isOk; }
309 void SetOk(bool ok) { m_isOk = ok; }
c801d85f 310
d6b9496a
VZ
311 ///////////////////////////////////////////////////////////////////////////
312 // OVERRIDES
c801d85f 313
d6b9496a
VZ
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;
c801d85f 318
d6b9496a
VZ
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;
34da0970
JS
323
324protected:
d6b9496a
VZ
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);
c801d85f
KB
345};
346
347/*
348 * Abort dialog
349 */
350
351class WXDLLEXPORT wxPrintAbortDialog: public wxDialog
352{
353public:
d6b9496a
VZ
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);
34da0970 365
d6b9496a
VZ
366private:
367 DECLARE_EVENT_TABLE()
c801d85f
KB
368};
369
370#endif
34138703 371 // _WX_PRNTBASEH__