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