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