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