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