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