]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
ce7208d4 | 2 | // Name: wx/prntbase.h |
c801d85f KB |
3 | // Purpose: Base classes for printing framework |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
371a5b4e | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_PRNTBASEH__ |
13 | #define _WX_PRNTBASEH__ | |
c801d85f | 14 | |
c801d85f | 15 | #include "wx/defs.h" |
d427503c VZ |
16 | |
17 | #if wxUSE_PRINTING_ARCHITECTURE | |
18 | ||
c801d85f KB |
19 | #include "wx/event.h" |
20 | #include "wx/cmndata.h" | |
21 | #include "wx/panel.h" | |
22 | #include "wx/scrolwin.h" | |
23 | #include "wx/dialog.h" | |
34138703 | 24 | #include "wx/frame.h" |
888dde65 | 25 | #include "wx/dc.h" |
c801d85f | 26 | |
b5dbe15d VS |
27 | class WXDLLIMPEXP_FWD_CORE wxDC; |
28 | class WXDLLIMPEXP_FWD_CORE wxButton; | |
29 | class WXDLLIMPEXP_FWD_CORE wxChoice; | |
30 | class WXDLLIMPEXP_FWD_CORE wxPrintout; | |
31 | class WXDLLIMPEXP_FWD_CORE wxPrinterBase; | |
32 | class WXDLLIMPEXP_FWD_CORE wxPrintDialogBase; | |
33 | class WXDLLIMPEXP_FWD_CORE wxPrintDialog; | |
34 | class WXDLLIMPEXP_FWD_CORE wxPageSetupDialogBase; | |
35 | class WXDLLIMPEXP_FWD_CORE wxPageSetupDialog; | |
36 | class WXDLLIMPEXP_FWD_CORE wxPrintPreviewBase; | |
37 | class WXDLLIMPEXP_FWD_CORE wxPreviewCanvas; | |
38 | class WXDLLIMPEXP_FWD_CORE wxPreviewControlBar; | |
39 | class WXDLLIMPEXP_FWD_CORE wxPreviewFrame; | |
40 | class WXDLLIMPEXP_FWD_CORE wxPrintFactory; | |
41 | class WXDLLIMPEXP_FWD_CORE wxPrintNativeDataBase; | |
1bd122dd | 42 | class WXDLLIMPEXP_FWD_CORE wxPrintPreview; |
82579461 | 43 | class wxPrintPageTextCtrl; |
c801d85f | 44 | |
e81e3883 RR |
45 | //---------------------------------------------------------------------------- |
46 | // error consts | |
47 | //---------------------------------------------------------------------------- | |
f6bcfd97 BP |
48 | |
49 | enum wxPrinterError | |
50 | { | |
51 | wxPRINTER_NO_ERROR = 0, | |
52 | wxPRINTER_CANCELLED, | |
53 | wxPRINTER_ERROR | |
54 | }; | |
55 | ||
e81e3883 RR |
56 | //---------------------------------------------------------------------------- |
57 | // wxPrintFactory | |
58 | //---------------------------------------------------------------------------- | |
59 | ||
53a2db12 | 60 | class WXDLLIMPEXP_CORE wxPrintFactory |
e81e3883 RR |
61 | { |
62 | public: | |
63 | wxPrintFactory() {} | |
64 | virtual ~wxPrintFactory() {} | |
d0ee33f5 | 65 | |
e81e3883 | 66 | virtual wxPrinterBase *CreatePrinter( wxPrintDialogData* data ) = 0; |
d0ee33f5 WS |
67 | |
68 | virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview, | |
69 | wxPrintout *printout = NULL, | |
e81e3883 | 70 | wxPrintDialogData *data = NULL ) = 0; |
d0ee33f5 WS |
71 | virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview, |
72 | wxPrintout *printout, | |
e81e3883 | 73 | wxPrintData *data ) = 0; |
c061373d | 74 | |
d0ee33f5 | 75 | virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent, |
c061373d | 76 | wxPrintDialogData *data = NULL ) = 0; |
d0ee33f5 | 77 | virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent, |
c061373d | 78 | wxPrintData *data ) = 0; |
d0ee33f5 | 79 | |
08680429 RR |
80 | virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent, |
81 | wxPageSetupDialogData * data = NULL ) = 0; | |
d0ee33f5 | 82 | |
888dde65 | 83 | virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) = 0; |
147bf263 | 84 | |
6038ec8e RR |
85 | // What to do and what to show in the wxPrintDialog |
86 | // a) Use the generic print setup dialog or a native one? | |
87 | virtual bool HasPrintSetupDialog() = 0; | |
88 | virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) = 0; | |
89 | // b) Provide the "print to file" option ourselves or via print setup? | |
90 | virtual bool HasOwnPrintToFile() = 0; | |
91 | // c) Show current printer | |
92 | virtual bool HasPrinterLine() = 0; | |
93 | virtual wxString CreatePrinterLine() = 0; | |
94 | // d) Show Status line for current printer? | |
95 | virtual bool HasStatusLine() = 0; | |
96 | virtual wxString CreateStatusLine() = 0; | |
97 | ||
d0ee33f5 | 98 | |
8850cbd3 | 99 | virtual wxPrintNativeDataBase *CreatePrintNativeData() = 0; |
d0ee33f5 | 100 | |
e81e3883 RR |
101 | static void SetPrintFactory( wxPrintFactory *factory ); |
102 | static wxPrintFactory *GetFactory(); | |
33d094d1 | 103 | private: |
e81e3883 RR |
104 | static wxPrintFactory *m_factory; |
105 | }; | |
106 | ||
53a2db12 | 107 | class WXDLLIMPEXP_CORE wxNativePrintFactory: public wxPrintFactory |
e81e3883 RR |
108 | { |
109 | public: | |
e81e3883 | 110 | virtual wxPrinterBase *CreatePrinter( wxPrintDialogData *data ); |
d0ee33f5 WS |
111 | |
112 | virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview, | |
113 | wxPrintout *printout = NULL, | |
e81e3883 | 114 | wxPrintDialogData *data = NULL ); |
d0ee33f5 | 115 | virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview, |
e81e3883 RR |
116 | wxPrintout *printout, |
117 | wxPrintData *data ); | |
d0ee33f5 WS |
118 | |
119 | virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent, | |
c061373d | 120 | wxPrintDialogData *data = NULL ); |
d0ee33f5 | 121 | virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent, |
c061373d | 122 | wxPrintData *data ); |
d0ee33f5 | 123 | |
08680429 RR |
124 | virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent, |
125 | wxPageSetupDialogData * data = NULL ); | |
d0ee33f5 | 126 | |
888dde65 | 127 | virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ); |
147bf263 | 128 | |
6038ec8e RR |
129 | virtual bool HasPrintSetupDialog(); |
130 | virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ); | |
131 | virtual bool HasOwnPrintToFile(); | |
132 | virtual bool HasPrinterLine(); | |
133 | virtual wxString CreatePrinterLine(); | |
134 | virtual bool HasStatusLine(); | |
135 | virtual wxString CreateStatusLine(); | |
d0ee33f5 | 136 | |
8850cbd3 RR |
137 | virtual wxPrintNativeDataBase *CreatePrintNativeData(); |
138 | }; | |
139 | ||
140 | //---------------------------------------------------------------------------- | |
141 | // wxPrintNativeDataBase | |
142 | //---------------------------------------------------------------------------- | |
143 | ||
53a2db12 | 144 | class WXDLLIMPEXP_CORE wxPrintNativeDataBase: public wxObject |
8850cbd3 RR |
145 | { |
146 | public: | |
147 | wxPrintNativeDataBase(); | |
148 | virtual ~wxPrintNativeDataBase() {} | |
d0ee33f5 | 149 | |
fd64de59 | 150 | virtual bool TransferTo( wxPrintData &data ) = 0; |
d0ee33f5 WS |
151 | virtual bool TransferFrom( const wxPrintData &data ) = 0; |
152 | ||
b7cacb43 VZ |
153 | virtual bool Ok() const { return IsOk(); } |
154 | virtual bool IsOk() const = 0; | |
d0ee33f5 | 155 | |
8850cbd3 | 156 | int m_ref; |
d0ee33f5 | 157 | |
8850cbd3 RR |
158 | private: |
159 | DECLARE_CLASS(wxPrintNativeDataBase) | |
c0c133e1 | 160 | wxDECLARE_NO_COPY_CLASS(wxPrintNativeDataBase); |
e81e3883 RR |
161 | }; |
162 | ||
163 | //---------------------------------------------------------------------------- | |
164 | // wxPrinterBase | |
165 | //---------------------------------------------------------------------------- | |
f6bcfd97 | 166 | |
c801d85f KB |
167 | /* |
168 | * Represents the printer: manages printing a wxPrintout object | |
169 | */ | |
d6b9496a | 170 | |
53a2db12 | 171 | class WXDLLIMPEXP_CORE wxPrinterBase: public wxObject |
c801d85f | 172 | { |
34da0970 | 173 | public: |
d3b9f782 | 174 | wxPrinterBase(wxPrintDialogData *data = NULL); |
d6b9496a VZ |
175 | virtual ~wxPrinterBase(); |
176 | ||
177 | virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout); | |
161f4f73 | 178 | virtual void ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message); |
c801d85f | 179 | |
c061373d | 180 | virtual wxPrintDialogData& GetPrintDialogData() const; |
d6b9496a | 181 | bool GetAbort() const { return sm_abortIt; } |
7e548f6b | 182 | |
f6bcfd97 | 183 | static wxPrinterError GetLastError() { return sm_lastError; } |
c801d85f | 184 | |
d6b9496a VZ |
185 | /////////////////////////////////////////////////////////////////////////// |
186 | // OVERRIDES | |
c801d85f | 187 | |
d6b9496a | 188 | virtual bool Setup(wxWindow *parent) = 0; |
7e548f6b | 189 | virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = true) = 0; |
d6b9496a | 190 | virtual wxDC* PrintDialog(wxWindow *parent) = 0; |
34da0970 JS |
191 | |
192 | protected: | |
d6b9496a VZ |
193 | wxPrintDialogData m_printDialogData; |
194 | wxPrintout* m_currentPrintout; | |
7e548f6b | 195 | |
f6bcfd97 | 196 | static wxPrinterError sm_lastError; |
7e548f6b | 197 | |
34da0970 | 198 | public: |
d6b9496a VZ |
199 | static wxWindow* sm_abortWindow; |
200 | static bool sm_abortIt; | |
34da0970 | 201 | |
2b5f62a0 VZ |
202 | private: |
203 | DECLARE_CLASS(wxPrinterBase) | |
c0c133e1 | 204 | wxDECLARE_NO_COPY_CLASS(wxPrinterBase); |
c801d85f KB |
205 | }; |
206 | ||
e81e3883 RR |
207 | //---------------------------------------------------------------------------- |
208 | // wxPrinter | |
209 | //---------------------------------------------------------------------------- | |
210 | ||
53a2db12 | 211 | class WXDLLIMPEXP_CORE wxPrinter: public wxPrinterBase |
e81e3883 RR |
212 | { |
213 | public: | |
d3b9f782 | 214 | wxPrinter(wxPrintDialogData *data = NULL); |
e81e3883 RR |
215 | virtual ~wxPrinter(); |
216 | ||
217 | virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout); | |
218 | virtual void ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message); | |
219 | ||
220 | virtual bool Setup(wxWindow *parent); | |
221 | virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = true); | |
222 | virtual wxDC* PrintDialog(wxWindow *parent); | |
d0ee33f5 | 223 | |
c061373d | 224 | virtual wxPrintDialogData& GetPrintDialogData() const; |
e81e3883 RR |
225 | |
226 | protected: | |
227 | wxPrinterBase *m_pimpl; | |
d0ee33f5 | 228 | |
e81e3883 RR |
229 | private: |
230 | DECLARE_CLASS(wxPrinter) | |
c0c133e1 | 231 | wxDECLARE_NO_COPY_CLASS(wxPrinter); |
e81e3883 RR |
232 | }; |
233 | ||
234 | //---------------------------------------------------------------------------- | |
235 | // wxPrintout | |
236 | //---------------------------------------------------------------------------- | |
237 | ||
c801d85f | 238 | /* |
c801d85f KB |
239 | * Represents an object via which a document may be printed. |
240 | * The programmer derives from this, overrides (at least) OnPrintPage, | |
241 | * and passes it to a wxPrinter object for printing, or a wxPrintPreview | |
242 | * object for previewing. | |
243 | */ | |
d6b9496a | 244 | |
53a2db12 | 245 | class WXDLLIMPEXP_CORE wxPrintout: public wxObject |
c801d85f | 246 | { |
34da0970 | 247 | public: |
6c4da6d6 | 248 | wxPrintout(const wxString& title = _("Printout")); |
d6b9496a | 249 | virtual ~wxPrintout(); |
c801d85f | 250 | |
d6b9496a VZ |
251 | virtual bool OnBeginDocument(int startPage, int endPage); |
252 | virtual void OnEndDocument(); | |
253 | virtual void OnBeginPrinting(); | |
254 | virtual void OnEndPrinting(); | |
c801d85f | 255 | |
d6b9496a VZ |
256 | // Guaranteed to be before any other functions are called |
257 | virtual void OnPreparePrinting() { } | |
c801d85f | 258 | |
d6b9496a VZ |
259 | virtual bool HasPage(int page); |
260 | virtual bool OnPrintPage(int page) = 0; | |
261 | virtual void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo); | |
c801d85f | 262 | |
d6b9496a | 263 | virtual wxString GetTitle() const { return m_printoutTitle; } |
34da0970 | 264 | |
d6b9496a VZ |
265 | wxDC *GetDC() const { return m_printoutDC; } |
266 | void SetDC(wxDC *dc) { m_printoutDC = dc; } | |
f415cab9 JS |
267 | |
268 | void FitThisSizeToPaper(const wxSize& imageSize); | |
269 | void FitThisSizeToPage(const wxSize& imageSize); | |
270 | void FitThisSizeToPageMargins(const wxSize& imageSize, const wxPageSetupDialogData& pageSetupData); | |
271 | void MapScreenSizeToPaper(); | |
272 | void MapScreenSizeToPage(); | |
273 | void MapScreenSizeToPageMargins(const wxPageSetupDialogData& pageSetupData); | |
274 | void MapScreenSizeToDevice(); | |
275 | ||
276 | wxRect GetLogicalPaperRect() const; | |
277 | wxRect GetLogicalPageRect() const; | |
278 | wxRect GetLogicalPageMarginsRect(const wxPageSetupDialogData& pageSetupData) const; | |
279 | ||
280 | void SetLogicalOrigin(wxCoord x, wxCoord y); | |
281 | void OffsetLogicalOrigin(wxCoord xoff, wxCoord yoff); | |
282 | ||
d6b9496a VZ |
283 | void SetPageSizePixels(int w, int h) { m_pageWidthPixels = w; m_pageHeightPixels = h; } |
284 | void GetPageSizePixels(int *w, int *h) const { *w = m_pageWidthPixels; *h = m_pageHeightPixels; } | |
285 | void SetPageSizeMM(int w, int h) { m_pageWidthMM = w; m_pageHeightMM = h; } | |
286 | void GetPageSizeMM(int *w, int *h) const { *w = m_pageWidthMM; *h = m_pageHeightMM; } | |
34da0970 | 287 | |
d6b9496a | 288 | void SetPPIScreen(int x, int y) { m_PPIScreenX = x; m_PPIScreenY = y; } |
40fcf546 | 289 | void SetPPIScreen(const wxSize& ppi) { SetPPIScreen(ppi.x, ppi.y); } |
d6b9496a VZ |
290 | void GetPPIScreen(int *x, int *y) const { *x = m_PPIScreenX; *y = m_PPIScreenY; } |
291 | void SetPPIPrinter(int x, int y) { m_PPIPrinterX = x; m_PPIPrinterY = y; } | |
40fcf546 | 292 | void SetPPIPrinter(const wxSize& ppi) { SetPPIPrinter(ppi.x, ppi.y); } |
d6b9496a | 293 | void GetPPIPrinter(int *x, int *y) const { *x = m_PPIPrinterX; *y = m_PPIPrinterY; } |
34da0970 | 294 | |
f415cab9 JS |
295 | void SetPaperRectPixels(const wxRect& paperRectPixels) { m_paperRectPixels = paperRectPixels; } |
296 | wxRect GetPaperRectPixels() const { return m_paperRectPixels; } | |
297 | ||
1bd122dd VZ |
298 | // This must be called by wxPrintPreview to associate itself with the |
299 | // printout it uses. | |
300 | virtual void SetPreview(wxPrintPreview *preview) { m_preview = preview; } | |
34da0970 | 301 | |
1bd122dd VZ |
302 | wxPrintPreview *GetPreview() const { return m_preview; } |
303 | virtual bool IsPreview() const { return GetPreview() != NULL; } | |
34da0970 JS |
304 | |
305 | private: | |
d6b9496a VZ |
306 | wxString m_printoutTitle; |
307 | wxDC* m_printoutDC; | |
1bd122dd | 308 | wxPrintPreview *m_preview; |
c801d85f | 309 | |
d6b9496a VZ |
310 | int m_pageWidthPixels; |
311 | int m_pageHeightPixels; | |
c801d85f | 312 | |
d6b9496a VZ |
313 | int m_pageWidthMM; |
314 | int m_pageHeightMM; | |
c801d85f | 315 | |
d6b9496a VZ |
316 | int m_PPIScreenX; |
317 | int m_PPIScreenY; | |
318 | int m_PPIPrinterX; | |
319 | int m_PPIPrinterY; | |
c801d85f | 320 | |
f415cab9 JS |
321 | wxRect m_paperRectPixels; |
322 | ||
2b5f62a0 VZ |
323 | private: |
324 | DECLARE_ABSTRACT_CLASS(wxPrintout) | |
c0c133e1 | 325 | wxDECLARE_NO_COPY_CLASS(wxPrintout); |
c801d85f KB |
326 | }; |
327 | ||
f415cab9 JS |
328 | //---------------------------------------------------------------------------- |
329 | // wxPreviewCanvas | |
330 | //---------------------------------------------------------------------------- | |
331 | ||
c801d85f | 332 | /* |
c801d85f KB |
333 | * Canvas upon which a preview is drawn. |
334 | */ | |
d6b9496a | 335 | |
53a2db12 | 336 | class WXDLLIMPEXP_CORE wxPreviewCanvas: public wxScrolledWindow |
c801d85f | 337 | { |
34da0970 | 338 | public: |
d6b9496a VZ |
339 | wxPreviewCanvas(wxPrintPreviewBase *preview, |
340 | wxWindow *parent, | |
341 | const wxPoint& pos = wxDefaultPosition, | |
342 | const wxSize& size = wxDefaultSize, | |
343 | long style = 0, | |
2b5f62a0 | 344 | const wxString& name = wxT("canvas")); |
d3c7fc99 | 345 | virtual ~wxPreviewCanvas(); |
c801d85f | 346 | |
b88bf073 VS |
347 | void SetPreview(wxPrintPreviewBase *preview) { m_printPreview = preview; } |
348 | ||
d6b9496a | 349 | void OnPaint(wxPaintEvent& event); |
d2b354f9 | 350 | void OnChar(wxKeyEvent &event); |
d6b9496a VZ |
351 | // Responds to colour changes |
352 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
c801d85f | 353 | |
34da0970 | 354 | private: |
fb6efdf2 VZ |
355 | #if wxUSE_MOUSEWHEEL |
356 | void OnMouseWheel(wxMouseEvent& event); | |
357 | #endif // wxUSE_MOUSEWHEEL | |
b88bf073 | 358 | void OnIdle(wxIdleEvent& event); |
fb6efdf2 | 359 | |
d6b9496a | 360 | wxPrintPreviewBase* m_printPreview; |
34da0970 | 361 | |
2b5f62a0 | 362 | DECLARE_CLASS(wxPreviewCanvas) |
d6b9496a | 363 | DECLARE_EVENT_TABLE() |
c0c133e1 | 364 | wxDECLARE_NO_COPY_CLASS(wxPreviewCanvas); |
c801d85f KB |
365 | }; |
366 | ||
f415cab9 JS |
367 | //---------------------------------------------------------------------------- |
368 | // wxPreviewFrame | |
369 | //---------------------------------------------------------------------------- | |
370 | ||
c801d85f | 371 | /* |
c801d85f KB |
372 | * Default frame for showing preview. |
373 | */ | |
374 | ||
53a2db12 | 375 | class WXDLLIMPEXP_CORE wxPreviewFrame: public wxFrame |
c801d85f | 376 | { |
34da0970 | 377 | public: |
d6b9496a | 378 | wxPreviewFrame(wxPrintPreviewBase *preview, |
a5ae8241 | 379 | wxWindow *parent, |
6c4da6d6 | 380 | const wxString& title = _("Print Preview"), |
d6b9496a VZ |
381 | const wxPoint& pos = wxDefaultPosition, |
382 | const wxSize& size = wxDefaultSize, | |
ca44dbde | 383 | long style = wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT, |
3366d55c | 384 | const wxString& name = wxFrameNameStr); |
d3c7fc99 | 385 | virtual ~wxPreviewFrame(); |
d6b9496a VZ |
386 | |
387 | void OnCloseWindow(wxCloseEvent& event); | |
388 | virtual void Initialize(); | |
389 | virtual void CreateCanvas(); | |
390 | virtual void CreateControlBar(); | |
d2b354f9 JS |
391 | |
392 | inline wxPreviewControlBar* GetControlBar() const { return m_controlBar; } | |
393 | ||
34da0970 | 394 | protected: |
d2b354f9 | 395 | wxPreviewCanvas* m_previewCanvas; |
d6b9496a VZ |
396 | wxPreviewControlBar* m_controlBar; |
397 | wxPrintPreviewBase* m_printPreview; | |
7c995553 | 398 | wxWindowDisabler* m_windowDisabler; |
e3065973 | 399 | |
d6b9496a | 400 | private: |
043c6705 VZ |
401 | void OnChar(wxKeyEvent& event); |
402 | ||
d6b9496a | 403 | DECLARE_EVENT_TABLE() |
043c6705 | 404 | DECLARE_CLASS(wxPreviewFrame) |
c0c133e1 | 405 | wxDECLARE_NO_COPY_CLASS(wxPreviewFrame); |
c801d85f KB |
406 | }; |
407 | ||
f415cab9 JS |
408 | //---------------------------------------------------------------------------- |
409 | // wxPreviewControlBar | |
410 | //---------------------------------------------------------------------------- | |
411 | ||
c801d85f | 412 | /* |
c801d85f KB |
413 | * A panel with buttons for controlling a print preview. |
414 | * The programmer may wish to use other means for controlling | |
415 | * the print preview. | |
416 | */ | |
417 | ||
418 | #define wxPREVIEW_PRINT 1 | |
419 | #define wxPREVIEW_PREVIOUS 2 | |
420 | #define wxPREVIEW_NEXT 4 | |
421 | #define wxPREVIEW_ZOOM 8 | |
bf89b538 JS |
422 | #define wxPREVIEW_FIRST 16 |
423 | #define wxPREVIEW_LAST 32 | |
424 | #define wxPREVIEW_GOTO 64 | |
c801d85f | 425 | |
d0ee33f5 WS |
426 | #define wxPREVIEW_DEFAULT (wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\ |
427 | |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST) | |
c801d85f KB |
428 | |
429 | // Ids for controls | |
430 | #define wxID_PREVIEW_CLOSE 1 | |
431 | #define wxID_PREVIEW_NEXT 2 | |
432 | #define wxID_PREVIEW_PREVIOUS 3 | |
433 | #define wxID_PREVIEW_PRINT 4 | |
434 | #define wxID_PREVIEW_ZOOM 5 | |
bf89b538 JS |
435 | #define wxID_PREVIEW_FIRST 6 |
436 | #define wxID_PREVIEW_LAST 7 | |
437 | #define wxID_PREVIEW_GOTO 8 | |
82579461 VZ |
438 | #define wxID_PREVIEW_ZOOM_IN 9 |
439 | #define wxID_PREVIEW_ZOOM_OUT 10 | |
c801d85f | 440 | |
53a2db12 | 441 | class WXDLLIMPEXP_CORE wxPreviewControlBar: public wxPanel |
c801d85f | 442 | { |
d6b9496a | 443 | DECLARE_CLASS(wxPreviewControlBar) |
c801d85f | 444 | |
34da0970 | 445 | public: |
d6b9496a VZ |
446 | wxPreviewControlBar(wxPrintPreviewBase *preview, |
447 | long buttons, | |
448 | wxWindow *parent, | |
449 | const wxPoint& pos = wxDefaultPosition, | |
450 | const wxSize& size = wxDefaultSize, | |
d2b354f9 | 451 | long style = wxTAB_TRAVERSAL, |
2b5f62a0 | 452 | const wxString& name = wxT("panel")); |
d3c7fc99 | 453 | virtual ~wxPreviewControlBar(); |
d6b9496a VZ |
454 | |
455 | virtual void CreateButtons(); | |
456 | virtual void SetZoomControl(int zoom); | |
457 | virtual int GetZoomControl(); | |
458 | virtual wxPrintPreviewBase *GetPrintPreview() const | |
459 | { return m_printPreview; } | |
460 | ||
82579461 VZ |
461 | |
462 | // Implementation only from now on. | |
d6b9496a | 463 | void OnWindowClose(wxCommandEvent& event); |
0f90ec93 KB |
464 | void OnNext(); |
465 | void OnPrevious(); | |
bf89b538 JS |
466 | void OnFirst(); |
467 | void OnLast(); | |
82579461 | 468 | void OnGotoPage(); |
b38b0d22 | 469 | void OnPrint(); |
82579461 | 470 | |
90b6b974 | 471 | void OnPrintButton(wxCommandEvent& WXUNUSED(event)) { OnPrint(); } |
014b0d06 VZ |
472 | void OnNextButton(wxCommandEvent & WXUNUSED(event)) { OnNext(); } |
473 | void OnPreviousButton(wxCommandEvent & WXUNUSED(event)) { OnPrevious(); } | |
bf89b538 JS |
474 | void OnFirstButton(wxCommandEvent & WXUNUSED(event)) { OnFirst(); } |
475 | void OnLastButton(wxCommandEvent & WXUNUSED(event)) { OnLast(); } | |
d6b9496a | 476 | void OnPaint(wxPaintEvent& event); |
c801d85f | 477 | |
82579461 VZ |
478 | void OnUpdateNextButton(wxUpdateUIEvent& event) |
479 | { event.Enable(IsNextEnabled()); } | |
480 | void OnUpdatePreviousButton(wxUpdateUIEvent& event) | |
481 | { event.Enable(IsPreviousEnabled()); } | |
482 | void OnUpdateFirstButton(wxUpdateUIEvent& event) | |
483 | { event.Enable(IsFirstEnabled()); } | |
484 | void OnUpdateLastButton(wxUpdateUIEvent& event) | |
485 | { event.Enable(IsLastEnabled()); } | |
486 | void OnUpdateZoomInButton(wxUpdateUIEvent& event) | |
487 | { event.Enable(IsZoomInEnabled()); } | |
488 | void OnUpdateZoomOutButton(wxUpdateUIEvent& event) | |
489 | { event.Enable(IsZoomOutEnabled()); } | |
490 | ||
491 | // These methods are not private because they are called by wxPreviewCanvas. | |
492 | void DoZoomIn(); | |
493 | void DoZoomOut(); | |
494 | ||
34da0970 | 495 | protected: |
d6b9496a VZ |
496 | wxPrintPreviewBase* m_printPreview; |
497 | wxButton* m_closeButton; | |
d6b9496a | 498 | wxChoice* m_zoomControl; |
82579461 VZ |
499 | wxPrintPageTextCtrl* m_currentPageText; |
500 | ||
d6b9496a VZ |
501 | long m_buttonFlags; |
502 | ||
503 | private: | |
82579461 VZ |
504 | void DoGotoPage(int page); |
505 | ||
506 | void DoZoom(); | |
507 | ||
508 | bool IsNextEnabled() const; | |
509 | bool IsPreviousEnabled() const; | |
510 | bool IsFirstEnabled() const; | |
511 | bool IsLastEnabled() const; | |
512 | bool IsZoomInEnabled() const; | |
513 | bool IsZoomOutEnabled() const; | |
514 | ||
515 | void OnZoomInButton(wxCommandEvent & WXUNUSED(event)) { DoZoomIn(); } | |
516 | void OnZoomOutButton(wxCommandEvent & WXUNUSED(event)) { DoZoomOut(); } | |
517 | void OnZoomChoice(wxCommandEvent& WXUNUSED(event)) { DoZoom(); } | |
518 | ||
d6b9496a | 519 | DECLARE_EVENT_TABLE() |
c0c133e1 | 520 | wxDECLARE_NO_COPY_CLASS(wxPreviewControlBar); |
c801d85f KB |
521 | }; |
522 | ||
e81e3883 RR |
523 | //---------------------------------------------------------------------------- |
524 | // wxPrintPreviewBase | |
525 | //---------------------------------------------------------------------------- | |
526 | ||
c801d85f | 527 | /* |
c801d85f KB |
528 | * Programmer creates an object of this class to preview a wxPrintout. |
529 | */ | |
d6b9496a | 530 | |
53a2db12 | 531 | class WXDLLIMPEXP_CORE wxPrintPreviewBase: public wxObject |
c801d85f | 532 | { |
34da0970 | 533 | public: |
d6b9496a | 534 | wxPrintPreviewBase(wxPrintout *printout, |
d3b9f782 VZ |
535 | wxPrintout *printoutForPrinting = NULL, |
536 | wxPrintDialogData *data = NULL); | |
d6b9496a VZ |
537 | wxPrintPreviewBase(wxPrintout *printout, |
538 | wxPrintout *printoutForPrinting, | |
539 | wxPrintData *data); | |
540 | virtual ~wxPrintPreviewBase(); | |
c801d85f | 541 | |
d6b9496a | 542 | virtual bool SetCurrentPage(int pageNum); |
e81e3883 | 543 | virtual int GetCurrentPage() const; |
c801d85f | 544 | |
e81e3883 RR |
545 | virtual void SetPrintout(wxPrintout *printout); |
546 | virtual wxPrintout *GetPrintout() const; | |
547 | virtual wxPrintout *GetPrintoutForPrinting() const; | |
c801d85f | 548 | |
e81e3883 RR |
549 | virtual void SetFrame(wxFrame *frame); |
550 | virtual void SetCanvas(wxPreviewCanvas *canvas); | |
c801d85f | 551 | |
e81e3883 RR |
552 | virtual wxFrame *GetFrame() const; |
553 | virtual wxPreviewCanvas *GetCanvas() const; | |
c801d85f | 554 | |
f415cab9 JS |
555 | // This is a helper routine, used by the next 4 routines. |
556 | ||
557 | virtual void CalcRects(wxPreviewCanvas *canvas, wxRect& printableAreaRect, wxRect& paperRect); | |
558 | ||
d6b9496a | 559 | // The preview canvas should call this from OnPaint |
d2b354f9 | 560 | virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc); |
c801d85f | 561 | |
b88bf073 VS |
562 | // Updates rendered page by calling RenderPage() if needed, returns true |
563 | // if there was some change. Preview canvas should call it at idle time | |
564 | virtual bool UpdatePageRendering(); | |
565 | ||
d6b9496a | 566 | // This draws a blank page onto the preview canvas |
d2b354f9 JS |
567 | virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc); |
568 | ||
569 | // Adjusts the scrollbars for the current scale | |
570 | virtual void AdjustScrollbars(wxPreviewCanvas *canvas); | |
c801d85f | 571 | |
d6b9496a VZ |
572 | // This is called by wxPrintPreview to render a page into a wxMemoryDC. |
573 | virtual bool RenderPage(int pageNum); | |
c801d85f | 574 | |
c801d85f | 575 | |
d6b9496a | 576 | virtual void SetZoom(int percent); |
e81e3883 | 577 | virtual int GetZoom() const; |
34da0970 | 578 | |
e81e3883 | 579 | virtual wxPrintDialogData& GetPrintDialogData(); |
d0ee33f5 | 580 | |
e81e3883 RR |
581 | virtual int GetMaxPage() const; |
582 | virtual int GetMinPage() const; | |
c801d85f | 583 | |
b7cacb43 VZ |
584 | virtual bool Ok() const { return IsOk(); } |
585 | virtual bool IsOk() const; | |
e81e3883 | 586 | virtual void SetOk(bool ok); |
c801d85f | 587 | |
d6b9496a VZ |
588 | /////////////////////////////////////////////////////////////////////////// |
589 | // OVERRIDES | |
c801d85f | 590 | |
d6b9496a VZ |
591 | // If we own a wxPrintout that can be used for printing, this |
592 | // will invoke the actual printing procedure. Called | |
593 | // by the wxPreviewControlBar. | |
594 | virtual bool Print(bool interactive) = 0; | |
c801d85f | 595 | |
d6b9496a VZ |
596 | // Calculate scaling that needs to be done to get roughly |
597 | // the right scaling for the screen pretending to be | |
598 | // the currently selected printer. | |
599 | virtual void DetermineScaling() = 0; | |
34da0970 | 600 | |
88b98787 | 601 | protected: |
25a3fca2 VS |
602 | // helpers for RenderPage(): |
603 | virtual bool RenderPageIntoDC(wxDC& dc, int pageNum); | |
604 | // renders preview into m_previewBitmap | |
605 | virtual bool RenderPageIntoBitmap(wxBitmap& bmp, int pageNum); | |
606 | ||
88b98787 VS |
607 | void InvalidatePreviewBitmap(); |
608 | ||
34da0970 | 609 | protected: |
d6b9496a | 610 | wxPrintDialogData m_printDialogData; |
d2b354f9 | 611 | wxPreviewCanvas* m_previewCanvas; |
d6b9496a VZ |
612 | wxFrame* m_previewFrame; |
613 | wxBitmap* m_previewBitmap; | |
88b98787 | 614 | bool m_previewFailed; |
d6b9496a VZ |
615 | wxPrintout* m_previewPrintout; |
616 | wxPrintout* m_printPrintout; | |
617 | int m_currentPage; | |
618 | int m_currentZoom; | |
f415cab9 JS |
619 | float m_previewScaleX; |
620 | float m_previewScaleY; | |
d6b9496a VZ |
621 | int m_topMargin; |
622 | int m_leftMargin; | |
623 | int m_pageWidth; | |
624 | int m_pageHeight; | |
625 | int m_minPage; | |
626 | int m_maxPage; | |
627 | ||
628 | bool m_isOk; | |
1044a386 | 629 | bool m_printingPrepared; // Called OnPreparePrinting? |
d6b9496a VZ |
630 | |
631 | private: | |
632 | void Init(wxPrintout *printout, wxPrintout *printoutForPrinting); | |
22f3361e | 633 | |
c0c133e1 | 634 | wxDECLARE_NO_COPY_CLASS(wxPrintPreviewBase); |
e81e3883 | 635 | DECLARE_CLASS(wxPrintPreviewBase) |
c801d85f KB |
636 | }; |
637 | ||
e81e3883 RR |
638 | //---------------------------------------------------------------------------- |
639 | // wxPrintPreview | |
640 | //---------------------------------------------------------------------------- | |
641 | ||
53a2db12 | 642 | class WXDLLIMPEXP_CORE wxPrintPreview: public wxPrintPreviewBase |
e81e3883 RR |
643 | { |
644 | public: | |
645 | wxPrintPreview(wxPrintout *printout, | |
d3b9f782 VZ |
646 | wxPrintout *printoutForPrinting = NULL, |
647 | wxPrintDialogData *data = NULL); | |
e81e3883 RR |
648 | wxPrintPreview(wxPrintout *printout, |
649 | wxPrintout *printoutForPrinting, | |
650 | wxPrintData *data); | |
651 | virtual ~wxPrintPreview(); | |
652 | ||
653 | virtual bool SetCurrentPage(int pageNum); | |
654 | virtual int GetCurrentPage() const; | |
655 | virtual void SetPrintout(wxPrintout *printout); | |
656 | virtual wxPrintout *GetPrintout() const; | |
657 | virtual wxPrintout *GetPrintoutForPrinting() const; | |
658 | virtual void SetFrame(wxFrame *frame); | |
659 | virtual void SetCanvas(wxPreviewCanvas *canvas); | |
660 | ||
661 | virtual wxFrame *GetFrame() const; | |
662 | virtual wxPreviewCanvas *GetCanvas() const; | |
663 | virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc); | |
b88bf073 | 664 | virtual bool UpdatePageRendering(); |
e81e3883 RR |
665 | virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc); |
666 | virtual void AdjustScrollbars(wxPreviewCanvas *canvas); | |
667 | virtual bool RenderPage(int pageNum); | |
668 | virtual void SetZoom(int percent); | |
d8766675 | 669 | virtual int GetZoom() const; |
e81e3883 RR |
670 | |
671 | virtual bool Print(bool interactive); | |
672 | virtual void DetermineScaling(); | |
d0ee33f5 | 673 | |
e81e3883 | 674 | virtual wxPrintDialogData& GetPrintDialogData(); |
d0ee33f5 | 675 | |
e81e3883 RR |
676 | virtual int GetMaxPage() const; |
677 | virtual int GetMinPage() const; | |
678 | ||
b7cacb43 VZ |
679 | virtual bool Ok() const { return IsOk(); } |
680 | virtual bool IsOk() const; | |
e81e3883 | 681 | virtual void SetOk(bool ok); |
d0ee33f5 | 682 | |
e81e3883 RR |
683 | private: |
684 | wxPrintPreviewBase *m_pimpl; | |
685 | ||
686 | private: | |
687 | DECLARE_CLASS(wxPrintPreview) | |
c0c133e1 | 688 | wxDECLARE_NO_COPY_CLASS(wxPrintPreview); |
e81e3883 RR |
689 | }; |
690 | ||
691 | //---------------------------------------------------------------------------- | |
692 | // wxPrintAbortDialog | |
693 | //---------------------------------------------------------------------------- | |
c801d85f | 694 | |
53a2db12 | 695 | class WXDLLIMPEXP_CORE wxPrintAbortDialog: public wxDialog |
c801d85f KB |
696 | { |
697 | public: | |
d6b9496a VZ |
698 | wxPrintAbortDialog(wxWindow *parent, |
699 | const wxString& title, | |
700 | const wxPoint& pos = wxDefaultPosition, | |
701 | const wxSize& size = wxDefaultSize, | |
702 | long style = 0, | |
2b5f62a0 | 703 | const wxString& name = wxT("dialog")) |
7e548f6b | 704 | : wxDialog(parent, wxID_ANY, title, pos, size, style, name) |
d6b9496a VZ |
705 | { |
706 | } | |
707 | ||
708 | void OnCancel(wxCommandEvent& event); | |
34da0970 | 709 | |
d6b9496a VZ |
710 | private: |
711 | DECLARE_EVENT_TABLE() | |
c0c133e1 | 712 | wxDECLARE_NO_COPY_CLASS(wxPrintAbortDialog); |
c801d85f KB |
713 | }; |
714 | ||
d427503c VZ |
715 | #endif // wxUSE_PRINTING_ARCHITECTURE |
716 | ||
c801d85f | 717 | #endif |
34138703 | 718 | // _WX_PRNTBASEH__ |