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