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