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