]>
Commit | Line | Data |
---|---|---|
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" | |
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 | |
30 | class WXDLLEXPORT wxDC; | |
31 | class WXDLLEXPORT wxButton; | |
32 | class WXDLLEXPORT wxChoice; | |
33 | class WXDLLEXPORT wxPrintout; | |
34 | class WXDLLEXPORT wxPrinterBase; | |
35 | class WXDLLEXPORT wxPrintDialog; | |
36 | class WXDLLEXPORT wxPrintPreviewBase; | |
37 | class WXDLLEXPORT wxPreviewCanvas; | |
38 | class WXDLLEXPORT wxPreviewControlBar; | |
39 | class WXDLLEXPORT wxPreviewFrame; | |
40 | ||
f6bcfd97 BP |
41 | |
42 | enum 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 |
54 | class WXDLLEXPORT wxPrinterBase: public wxObject |
55 | { | |
d6b9496a | 56 | DECLARE_CLASS(wxPrinterBase) |
c801d85f | 57 | |
34da0970 | 58 | public: |
d6b9496a VZ |
59 | wxPrinterBase(wxPrintDialogData *data = (wxPrintDialogData *) NULL); |
60 | virtual ~wxPrinterBase(); | |
61 | ||
62 | virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout); | |
161f4f73 | 63 | virtual void ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message); |
c801d85f | 64 | |
d6b9496a VZ |
65 | wxPrintDialogData& GetPrintDialogData() const |
66 | { return (wxPrintDialogData&) m_printDialogData; } | |
67 | bool GetAbort() const { return sm_abortIt; } | |
f6bcfd97 BP |
68 | |
69 | static wxPrinterError GetLastError() { return sm_lastError; } | |
c801d85f | 70 | |
d6b9496a VZ |
71 | /////////////////////////////////////////////////////////////////////////// |
72 | // OVERRIDES | |
c801d85f | 73 | |
d6b9496a VZ |
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; | |
34da0970 JS |
77 | |
78 | protected: | |
d6b9496a VZ |
79 | wxPrintDialogData m_printDialogData; |
80 | wxPrintout* m_currentPrintout; | |
f6bcfd97 BP |
81 | |
82 | static wxPrinterError sm_lastError; | |
83 | ||
34da0970 | 84 | public: |
d6b9496a VZ |
85 | static wxWindow* sm_abortWindow; |
86 | static bool sm_abortIt; | |
34da0970 | 87 | |
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 |
98 | class WXDLLEXPORT wxPrintout: public wxObject |
99 | { | |
d6b9496a | 100 | DECLARE_ABSTRACT_CLASS(wxPrintout) |
c801d85f | 101 | |
34da0970 | 102 | public: |
d6b9496a VZ |
103 | wxPrintout(const wxString& title = "Printout"); |
104 | virtual ~wxPrintout(); | |
c801d85f | 105 | |
d6b9496a VZ |
106 | virtual bool OnBeginDocument(int startPage, int endPage); |
107 | virtual void OnEndDocument(); | |
108 | virtual void OnBeginPrinting(); | |
109 | virtual void OnEndPrinting(); | |
c801d85f | 110 | |
d6b9496a VZ |
111 | // Guaranteed to be before any other functions are called |
112 | virtual void OnPreparePrinting() { } | |
c801d85f | 113 | |
d6b9496a VZ |
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); | |
c801d85f | 117 | |
d6b9496a | 118 | virtual wxString GetTitle() const { return m_printoutTitle; } |
34da0970 | 119 | |
d6b9496a VZ |
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; } | |
34da0970 | 126 | |
d6b9496a VZ |
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; } | |
34da0970 | 131 | |
d6b9496a | 132 | virtual bool IsPreview() const { return m_isPreview; } |
34da0970 | 133 | |
d6b9496a | 134 | virtual void SetIsPreview(bool p) { m_isPreview = p; } |
34da0970 JS |
135 | |
136 | private: | |
d6b9496a VZ |
137 | wxString m_printoutTitle; |
138 | wxDC* m_printoutDC; | |
c801d85f | 139 | |
d6b9496a VZ |
140 | int m_pageWidthPixels; |
141 | int m_pageHeightPixels; | |
c801d85f | 142 | |
d6b9496a VZ |
143 | int m_pageWidthMM; |
144 | int m_pageHeightMM; | |
c801d85f | 145 | |
d6b9496a VZ |
146 | int m_PPIScreenX; |
147 | int m_PPIScreenY; | |
148 | int m_PPIPrinterX; | |
149 | int m_PPIPrinterY; | |
c801d85f | 150 | |
d6b9496a | 151 | bool m_isPreview; |
c801d85f KB |
152 | }; |
153 | ||
154 | /* | |
155 | * wxPreviewCanvas | |
156 | * Canvas upon which a preview is drawn. | |
157 | */ | |
d6b9496a | 158 | |
c801d85f KB |
159 | class WXDLLEXPORT wxPreviewCanvas: public wxScrolledWindow |
160 | { | |
d6b9496a | 161 | DECLARE_CLASS(wxPreviewCanvas) |
c801d85f | 162 | |
34da0970 | 163 | public: |
d6b9496a VZ |
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(); | |
c801d85f | 171 | |
d6b9496a | 172 | void OnPaint(wxPaintEvent& event); |
c801d85f | 173 | |
d6b9496a VZ |
174 | // Responds to colour changes |
175 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
c801d85f | 176 | |
34da0970 | 177 | private: |
d6b9496a | 178 | wxPrintPreviewBase* m_printPreview; |
34da0970 | 179 | |
d6b9496a | 180 | DECLARE_EVENT_TABLE() |
c801d85f KB |
181 | }; |
182 | ||
183 | /* | |
184 | * wxPreviewFrame | |
185 | * Default frame for showing preview. | |
186 | */ | |
187 | ||
188 | class WXDLLEXPORT wxPreviewFrame: public wxFrame | |
189 | { | |
d6b9496a | 190 | DECLARE_CLASS(wxPreviewFrame) |
c801d85f | 191 | |
34da0970 | 192 | public: |
d6b9496a VZ |
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(); | |
34da0970 | 206 | protected: |
d6b9496a VZ |
207 | wxWindow* m_previewCanvas; |
208 | wxPreviewControlBar* m_controlBar; | |
209 | wxPrintPreviewBase* m_printPreview; | |
e3065973 | 210 | |
d6b9496a VZ |
211 | private: |
212 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
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 | |
bf89b538 JS |
226 | #define wxPREVIEW_FIRST 16 |
227 | #define wxPREVIEW_LAST 32 | |
228 | #define wxPREVIEW_GOTO 64 | |
c801d85f | 229 | |
bf89b538 JS |
230 | #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\ |
231 | |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST | |
c801d85f KB |
232 | |
233 | // Ids for controls | |
234 | #define wxID_PREVIEW_CLOSE 1 | |
235 | #define wxID_PREVIEW_NEXT 2 | |
236 | #define wxID_PREVIEW_PREVIOUS 3 | |
237 | #define wxID_PREVIEW_PRINT 4 | |
238 | #define wxID_PREVIEW_ZOOM 5 | |
bf89b538 JS |
239 | #define wxID_PREVIEW_FIRST 6 |
240 | #define wxID_PREVIEW_LAST 7 | |
241 | #define wxID_PREVIEW_GOTO 8 | |
c801d85f KB |
242 | |
243 | class WXDLLEXPORT wxPreviewControlBar: public wxPanel | |
244 | { | |
d6b9496a | 245 | DECLARE_CLASS(wxPreviewControlBar) |
c801d85f | 246 | |
34da0970 | 247 | public: |
d6b9496a VZ |
248 | wxPreviewControlBar(wxPrintPreviewBase *preview, |
249 | long buttons, | |
250 | wxWindow *parent, | |
251 | const wxPoint& pos = wxDefaultPosition, | |
252 | const wxSize& size = wxDefaultSize, | |
253 | long style = 0, | |
254 | const wxString& name = "panel"); | |
255 | ~wxPreviewControlBar(); | |
256 | ||
257 | virtual void CreateButtons(); | |
258 | virtual void SetZoomControl(int zoom); | |
259 | virtual int GetZoomControl(); | |
260 | virtual wxPrintPreviewBase *GetPrintPreview() const | |
261 | { return m_printPreview; } | |
262 | ||
263 | void OnPrint(wxCommandEvent& event); | |
264 | void OnWindowClose(wxCommandEvent& event); | |
0f90ec93 KB |
265 | void OnNext(); |
266 | void OnPrevious(); | |
bf89b538 JS |
267 | void OnFirst(); |
268 | void OnLast(); | |
269 | void OnGoto(); | |
014b0d06 VZ |
270 | void OnNextButton(wxCommandEvent & WXUNUSED(event)) { OnNext(); } |
271 | void OnPreviousButton(wxCommandEvent & WXUNUSED(event)) { OnPrevious(); } | |
bf89b538 JS |
272 | void OnFirstButton(wxCommandEvent & WXUNUSED(event)) { OnFirst(); } |
273 | void OnLastButton(wxCommandEvent & WXUNUSED(event)) { OnLast(); } | |
274 | void OnGotoButton(wxCommandEvent & WXUNUSED(event)) { OnGoto(); } | |
0f90ec93 | 275 | void OnChar(wxKeyEvent &event); |
d6b9496a VZ |
276 | void OnZoom(wxCommandEvent& event); |
277 | void OnPaint(wxPaintEvent& event); | |
c801d85f | 278 | |
34da0970 | 279 | protected: |
d6b9496a VZ |
280 | wxPrintPreviewBase* m_printPreview; |
281 | wxButton* m_closeButton; | |
282 | wxButton* m_nextPageButton; | |
283 | wxButton* m_previousPageButton; | |
284 | wxButton* m_printButton; | |
285 | wxChoice* m_zoomControl; | |
bf89b538 JS |
286 | wxButton* m_firstPageButton; |
287 | wxButton* m_lastPageButton; | |
288 | wxButton* m_gotoPageButton; | |
d6b9496a VZ |
289 | long m_buttonFlags; |
290 | ||
291 | private: | |
292 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
293 | }; |
294 | ||
295 | /* | |
296 | * wxPrintPreview | |
297 | * Programmer creates an object of this class to preview a wxPrintout. | |
298 | */ | |
d6b9496a | 299 | |
c801d85f KB |
300 | class WXDLLEXPORT wxPrintPreviewBase: public wxObject |
301 | { | |
d6b9496a | 302 | DECLARE_CLASS(wxPrintPreviewBase) |
c801d85f | 303 | |
34da0970 | 304 | public: |
d6b9496a VZ |
305 | wxPrintPreviewBase(wxPrintout *printout, |
306 | wxPrintout *printoutForPrinting = (wxPrintout *) NULL, | |
307 | wxPrintDialogData *data = (wxPrintDialogData *) NULL); | |
308 | wxPrintPreviewBase(wxPrintout *printout, | |
309 | wxPrintout *printoutForPrinting, | |
310 | wxPrintData *data); | |
311 | virtual ~wxPrintPreviewBase(); | |
c801d85f | 312 | |
d6b9496a VZ |
313 | virtual bool SetCurrentPage(int pageNum); |
314 | int GetCurrentPage() const { return m_currentPage; }; | |
c801d85f | 315 | |
d6b9496a VZ |
316 | void SetPrintout(wxPrintout *printout) { m_previewPrintout = printout; }; |
317 | wxPrintout *GetPrintout() const { return m_previewPrintout; }; | |
318 | wxPrintout *GetPrintoutForPrinting() const { return m_printPrintout; }; | |
c801d85f | 319 | |
d6b9496a VZ |
320 | void SetFrame(wxFrame *frame) { m_previewFrame = frame; }; |
321 | void SetCanvas(wxWindow *canvas) { m_previewCanvas = canvas; }; | |
c801d85f | 322 | |
d6b9496a VZ |
323 | virtual wxFrame *GetFrame() const { return m_previewFrame; } |
324 | virtual wxWindow *GetCanvas() const { return m_previewCanvas; } | |
c801d85f | 325 | |
d6b9496a VZ |
326 | // The preview canvas should call this from OnPaint |
327 | virtual bool PaintPage(wxWindow *canvas, wxDC& dc); | |
c801d85f | 328 | |
d6b9496a VZ |
329 | // This draws a blank page onto the preview canvas |
330 | virtual bool DrawBlankPage(wxWindow *canvas, wxDC& dc); | |
c801d85f | 331 | |
d6b9496a VZ |
332 | // This is called by wxPrintPreview to render a page into a wxMemoryDC. |
333 | virtual bool RenderPage(int pageNum); | |
c801d85f | 334 | |
d6b9496a | 335 | wxPrintDialogData& GetPrintDialogData() { return m_printDialogData; } |
c801d85f | 336 | |
d6b9496a VZ |
337 | virtual void SetZoom(int percent); |
338 | int GetZoom() const { return m_currentZoom; }; | |
34da0970 | 339 | |
d6b9496a VZ |
340 | int GetMaxPage() const { return m_maxPage; } |
341 | int GetMinPage() const { return m_minPage; } | |
c801d85f | 342 | |
d6b9496a VZ |
343 | bool Ok() const { return m_isOk; } |
344 | void SetOk(bool ok) { m_isOk = ok; } | |
c801d85f | 345 | |
d6b9496a VZ |
346 | /////////////////////////////////////////////////////////////////////////// |
347 | // OVERRIDES | |
c801d85f | 348 | |
d6b9496a VZ |
349 | // If we own a wxPrintout that can be used for printing, this |
350 | // will invoke the actual printing procedure. Called | |
351 | // by the wxPreviewControlBar. | |
352 | virtual bool Print(bool interactive) = 0; | |
c801d85f | 353 | |
d6b9496a VZ |
354 | // Calculate scaling that needs to be done to get roughly |
355 | // the right scaling for the screen pretending to be | |
356 | // the currently selected printer. | |
357 | virtual void DetermineScaling() = 0; | |
34da0970 JS |
358 | |
359 | protected: | |
d6b9496a VZ |
360 | wxPrintDialogData m_printDialogData; |
361 | wxWindow* m_previewCanvas; | |
362 | wxFrame* m_previewFrame; | |
363 | wxBitmap* m_previewBitmap; | |
364 | wxPrintout* m_previewPrintout; | |
365 | wxPrintout* m_printPrintout; | |
366 | int m_currentPage; | |
367 | int m_currentZoom; | |
368 | float m_previewScale; | |
369 | int m_topMargin; | |
370 | int m_leftMargin; | |
371 | int m_pageWidth; | |
372 | int m_pageHeight; | |
373 | int m_minPage; | |
374 | int m_maxPage; | |
375 | ||
376 | bool m_isOk; | |
1044a386 | 377 | bool m_printingPrepared; // Called OnPreparePrinting? |
d6b9496a VZ |
378 | |
379 | private: | |
380 | void Init(wxPrintout *printout, wxPrintout *printoutForPrinting); | |
c801d85f KB |
381 | }; |
382 | ||
383 | /* | |
384 | * Abort dialog | |
385 | */ | |
386 | ||
387 | class WXDLLEXPORT wxPrintAbortDialog: public wxDialog | |
388 | { | |
389 | public: | |
d6b9496a VZ |
390 | wxPrintAbortDialog(wxWindow *parent, |
391 | const wxString& title, | |
392 | const wxPoint& pos = wxDefaultPosition, | |
393 | const wxSize& size = wxDefaultSize, | |
394 | long style = 0, | |
395 | const wxString& name = "dialog") | |
396 | : wxDialog(parent, -1, title, pos, size, style, name) | |
397 | { | |
398 | } | |
399 | ||
400 | void OnCancel(wxCommandEvent& event); | |
34da0970 | 401 | |
d6b9496a VZ |
402 | private: |
403 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
404 | }; |
405 | ||
d427503c VZ |
406 | #endif // wxUSE_PRINTING_ARCHITECTURE |
407 | ||
c801d85f | 408 | #endif |
34138703 | 409 | // _WX_PRNTBASEH__ |