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