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