]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __PRNTBASEH__ | |
13 | #define __PRNTBASEH__ | |
14 | ||
15 | #ifdef __GNUG__ | |
0d3820b3 | 16 | #pragma interface "prntbase.h" |
c801d85f KB |
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 | ||
26 | class WXDLLEXPORT wxDC; | |
27 | class WXDLLEXPORT wxButton; | |
28 | class WXDLLEXPORT wxChoice; | |
29 | class WXDLLEXPORT wxPrintout; | |
30 | class WXDLLEXPORT wxPrinterBase; | |
31 | class WXDLLEXPORT wxPrintDialog; | |
32 | class WXDLLEXPORT wxPrintPreviewBase; | |
33 | class WXDLLEXPORT wxPreviewCanvas; | |
34 | class WXDLLEXPORT wxPreviewControlBar; | |
35 | class WXDLLEXPORT wxPreviewFrame; | |
36 | ||
37 | /* | |
38 | * Represents the printer: manages printing a wxPrintout object | |
39 | */ | |
40 | ||
41 | class WXDLLEXPORT wxPrinterBase: public wxObject | |
42 | { | |
43 | DECLARE_CLASS(wxPrinterBase) | |
44 | ||
45 | protected: | |
46 | wxPrintData printData; | |
47 | wxPrintout *currentPrintout; | |
48 | public: | |
49 | static wxWindow *abortWindow; | |
50 | static bool abortIt; | |
51 | ||
52 | wxPrinterBase(wxPrintData *data = NULL); | |
53 | ~wxPrinterBase(void); | |
54 | ||
55 | virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout); | |
56 | virtual void ReportError(wxWindow *parent, wxPrintout *printout, char *message); | |
57 | inline wxPrintData& GetPrintData(void) { return printData; }; | |
58 | inline bool GetAbort(void) { return abortIt; } | |
59 | ||
60 | /////////////////////////////////////////////////////////////////////////// | |
61 | // OVERRIDES | |
62 | ||
63 | virtual bool Setup(wxWindow *parent) = 0; | |
64 | virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = TRUE) = 0; | |
65 | virtual bool PrintDialog(wxWindow *parent) = 0; | |
66 | }; | |
67 | ||
68 | /* | |
69 | * wxPrintout | |
70 | * Represents an object via which a document may be printed. | |
71 | * The programmer derives from this, overrides (at least) OnPrintPage, | |
72 | * and passes it to a wxPrinter object for printing, or a wxPrintPreview | |
73 | * object for previewing. | |
74 | */ | |
75 | ||
76 | class WXDLLEXPORT wxPrintout: public wxObject | |
77 | { | |
78 | DECLARE_ABSTRACT_CLASS(wxPrintout) | |
79 | ||
80 | private: | |
81 | char *printoutTitle; | |
82 | wxDC *printoutDC; | |
83 | ||
84 | int pageWidthPixels; | |
85 | int pageHeightPixels; | |
86 | ||
87 | int pageWidthMM; | |
88 | int pageHeightMM; | |
89 | ||
90 | int PPIScreenX; | |
91 | int PPIScreenY; | |
92 | int PPIPrinterX; | |
93 | int PPIPrinterY; | |
94 | ||
95 | bool isPreview; | |
96 | public: | |
97 | wxPrintout(char *title = "Printout"); | |
98 | ~wxPrintout(void); | |
99 | ||
100 | virtual bool OnBeginDocument(int startPage, int endPage); | |
101 | virtual void OnEndDocument(void); | |
102 | virtual void OnBeginPrinting(void); | |
103 | virtual void OnEndPrinting(void); | |
104 | ||
105 | // Guaranteed to be before any other functions are called | |
106 | inline virtual void OnPreparePrinting(void) { } | |
107 | ||
108 | virtual bool HasPage(int page); | |
109 | virtual bool OnPrintPage(int page) = 0; | |
110 | virtual void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo); | |
111 | ||
112 | inline virtual char *GetTitle(void) { return printoutTitle; } | |
113 | ||
114 | inline wxDC *GetDC(void) { return printoutDC; } | |
115 | inline void SetDC(wxDC *dc) { printoutDC = dc; } | |
116 | inline void SetPageSizePixels(int w, int h) { pageWidthPixels = w; pageHeightPixels = h; } | |
117 | inline void GetPageSizePixels(int *w, int *h) { *w = pageWidthPixels; *h = pageHeightPixels; } | |
118 | inline void SetPageSizeMM(int w, int h) { pageWidthMM = w; pageHeightMM = h; } | |
119 | inline void GetPageSizeMM(int *w, int *h) { *w = pageWidthMM; *h = pageHeightMM; } | |
120 | ||
121 | inline void SetPPIScreen(int x, int y) { PPIScreenX = x; PPIScreenY = y; } | |
122 | inline void GetPPIScreen(int *x, int *y) { *x = PPIScreenX; *y = PPIScreenY; } | |
123 | inline void SetPPIPrinter(int x, int y) { PPIPrinterX = x; PPIPrinterY = y; } | |
124 | inline void GetPPIPrinter(int *x, int *y) { *x = PPIPrinterX; *y = PPIPrinterY; } | |
125 | ||
126 | inline virtual bool IsPreview(void) { return isPreview; } | |
127 | ||
128 | inline virtual void SetIsPreview(bool p) { isPreview = p; } | |
129 | }; | |
130 | ||
131 | /* | |
132 | * wxPreviewCanvas | |
133 | * Canvas upon which a preview is drawn. | |
134 | */ | |
135 | ||
136 | class WXDLLEXPORT wxPreviewCanvas: public wxScrolledWindow | |
137 | { | |
138 | DECLARE_CLASS(wxPreviewCanvas) | |
139 | ||
140 | private: | |
141 | wxPrintPreviewBase *printPreview; | |
142 | public: | |
143 | wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent, | |
144 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
145 | long style = 0, const wxString& name = "canvas"); | |
146 | ~wxPreviewCanvas(void); | |
147 | ||
148 | void OnPaint(wxPaintEvent& event); | |
149 | ||
150 | // Responds to colour changes | |
151 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
152 | ||
153 | DECLARE_EVENT_TABLE() | |
154 | }; | |
155 | ||
156 | /* | |
157 | * wxPreviewFrame | |
158 | * Default frame for showing preview. | |
159 | */ | |
160 | ||
161 | class WXDLLEXPORT wxPreviewFrame: public wxFrame | |
162 | { | |
163 | DECLARE_CLASS(wxPreviewFrame) | |
164 | ||
165 | protected: | |
166 | wxWindow *previewCanvas; | |
167 | wxPreviewControlBar *controlBar; | |
168 | wxPrintPreviewBase *printPreview; | |
169 | public: | |
170 | wxPreviewFrame(wxPrintPreviewBase *preview, wxFrame *parent, const wxString& title = "Print Preview", | |
171 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
172 | long style = wxDEFAULT_FRAME, const wxString& name = "frame"); | |
173 | ~wxPreviewFrame(void); | |
174 | ||
175 | bool OnClose(void); | |
176 | virtual void Initialize(void); | |
177 | virtual void CreateCanvas(void); | |
178 | virtual void CreateControlBar(void); | |
179 | }; | |
180 | ||
181 | /* | |
182 | * wxPreviewControlBar | |
183 | * A panel with buttons for controlling a print preview. | |
184 | * The programmer may wish to use other means for controlling | |
185 | * the print preview. | |
186 | */ | |
187 | ||
188 | #define wxPREVIEW_PRINT 1 | |
189 | #define wxPREVIEW_PREVIOUS 2 | |
190 | #define wxPREVIEW_NEXT 4 | |
191 | #define wxPREVIEW_ZOOM 8 | |
192 | ||
193 | #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM | |
194 | ||
195 | // Ids for controls | |
196 | #define wxID_PREVIEW_CLOSE 1 | |
197 | #define wxID_PREVIEW_NEXT 2 | |
198 | #define wxID_PREVIEW_PREVIOUS 3 | |
199 | #define wxID_PREVIEW_PRINT 4 | |
200 | #define wxID_PREVIEW_ZOOM 5 | |
201 | ||
202 | class WXDLLEXPORT wxPreviewControlBar: public wxPanel | |
203 | { | |
204 | DECLARE_CLASS(wxPreviewControlBar) | |
205 | ||
206 | protected: | |
207 | wxPrintPreviewBase *printPreview; | |
208 | wxButton *closeButton; | |
209 | wxButton *nextPageButton; | |
210 | wxButton *previousPageButton; | |
211 | wxButton *printButton; | |
212 | wxChoice *zoomControl; | |
213 | static wxFont *buttonFont; | |
214 | long buttonFlags; | |
215 | public: | |
216 | wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons, | |
217 | wxWindow *parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
218 | long style = 0, const wxString& name = "panel"); | |
219 | ~wxPreviewControlBar(void); | |
220 | ||
221 | virtual void CreateButtons(void); | |
222 | virtual void SetZoomControl(int zoom); | |
223 | virtual int GetZoomControl(void); | |
224 | inline virtual wxPrintPreviewBase *GetPrintPreview(void) { return printPreview; } | |
225 | ||
226 | void OnPrint(wxCommandEvent& event); | |
227 | void OnClose(wxCommandEvent& event); | |
228 | void OnNext(wxCommandEvent& event); | |
229 | void OnPrevious(wxCommandEvent& event); | |
230 | void OnZoom(wxCommandEvent& event); | |
231 | void OnPaint(wxPaintEvent& event); | |
232 | ||
233 | DECLARE_EVENT_TABLE() | |
234 | }; | |
235 | ||
236 | /* | |
237 | * wxPrintPreview | |
238 | * Programmer creates an object of this class to preview a wxPrintout. | |
239 | */ | |
240 | ||
241 | class WXDLLEXPORT wxPrintPreviewBase: public wxObject | |
242 | { | |
243 | DECLARE_CLASS(wxPrintPreviewBase) | |
244 | ||
245 | protected: | |
246 | wxPrintData printData; | |
247 | wxWindow *previewCanvas; | |
248 | wxFrame *previewFrame; | |
249 | wxBitmap *previewBitmap; | |
250 | wxPrintout *previewPrintout; | |
251 | wxPrintout *printPrintout; | |
252 | int currentPage; | |
253 | int currentZoom; | |
254 | float previewScale; | |
255 | int topMargin; | |
256 | int leftMargin; | |
257 | int pageWidth; | |
258 | int pageHeight; | |
259 | int minPage; | |
260 | int maxPage; | |
261 | protected: | |
262 | bool isOk; | |
263 | public: | |
264 | wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting = NULL, wxPrintData *data = NULL); | |
265 | ~wxPrintPreviewBase(void); | |
266 | ||
267 | virtual bool SetCurrentPage(int pageNum); | |
268 | inline int GetCurrentPage(void) { return currentPage; }; | |
269 | ||
270 | inline void SetPrintout(wxPrintout *printout) { previewPrintout = printout; }; | |
271 | inline wxPrintout *GetPrintout(void) { return previewPrintout; }; | |
272 | inline wxPrintout *GetPrintoutForPrinting(void) { return printPrintout; }; | |
273 | ||
274 | inline void SetFrame(wxFrame *frame) { previewFrame = frame; }; | |
275 | inline void SetCanvas(wxWindow *canvas) { previewCanvas = canvas; }; | |
276 | ||
277 | inline virtual wxFrame *GetFrame(void) { return previewFrame; } | |
278 | inline virtual wxWindow *GetCanvas(void) { return previewCanvas; } | |
279 | ||
280 | // The preview canvas should call this from OnPaint | |
281 | virtual bool PaintPage(wxWindow *canvas, wxDC& dc); | |
282 | ||
283 | // This draws a blank page onto the preview canvas | |
284 | virtual bool DrawBlankPage(wxWindow *canvas, wxDC& dc); | |
285 | ||
286 | // This is called by wxPrintPreview to render a page into | |
287 | // a wxMemoryDC. | |
288 | virtual bool RenderPage(int pageNum); | |
289 | ||
290 | inline wxPrintData& GetPrintData(void) { return printData; } | |
291 | ||
292 | virtual void SetZoom(int percent); | |
293 | int GetZoom(void) { return currentZoom; }; | |
294 | ||
295 | inline int GetMaxPage(void) { return maxPage; } | |
296 | inline int GetMinPage(void) { return minPage; } | |
297 | ||
298 | inline bool Ok(void) { return isOk; } | |
299 | inline void SetOk(bool ok) { isOk = ok; } | |
300 | ||
301 | /////////////////////////////////////////////////////////////////////////// | |
302 | // OVERRIDES | |
303 | ||
304 | // If we own a wxPrintout that can be used for printing, this | |
305 | // will invoke the actual printing procedure. Called | |
306 | // by the wxPreviewControlBar. | |
307 | virtual bool Print(bool interactive) = 0; | |
308 | ||
309 | // Calculate scaling that needs to be done to get roughly | |
310 | // the right scaling for the screen pretending to be | |
311 | // the currently selected printer. | |
312 | virtual void DetermineScaling(void) = 0; | |
313 | }; | |
314 | ||
315 | /* | |
316 | * Abort dialog | |
317 | */ | |
318 | ||
319 | class WXDLLEXPORT wxPrintAbortDialog: public wxDialog | |
320 | { | |
321 | public: | |
322 | void OnCancel(wxCommandEvent& event); | |
323 | ||
324 | wxPrintAbortDialog(wxWindow *parent, | |
325 | const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
326 | long style = 0, const wxString& name = "dialog"): | |
327 | wxDialog(parent, -1, title, pos, size, style, name) | |
328 | { | |
329 | } | |
330 | ||
331 | DECLARE_EVENT_TABLE() | |
332 | }; | |
333 | ||
334 | #endif | |
335 | // __PRNTBASEH__ |