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