1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Base classes for printing framework
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PRNTBASEH__
13 #define _WX_PRNTBASEH__
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "prntbase.h"
21 #if wxUSE_PRINTING_ARCHITECTURE
24 #include "wx/cmndata.h"
26 #include "wx/scrolwin.h"
27 #include "wx/dialog.h"
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
;
44 //----------------------------------------------------------------------------
46 //----------------------------------------------------------------------------
50 wxPRINTER_NO_ERROR
= 0,
55 //----------------------------------------------------------------------------
57 //----------------------------------------------------------------------------
59 class WXDLLEXPORT wxPrintFactory
63 virtual ~wxPrintFactory() {}
65 virtual bool HasPageSetupDialog() = 0;
66 virtual bool HasPrintSetupDialog() = 0;
68 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
* data
) = 0;
70 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
71 wxPrintout
*printout
= NULL
,
72 wxPrintDialogData
*data
= NULL
) = 0;
73 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
75 wxPrintData
*data
) = 0;
77 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
78 wxPrintDialogData
*data
= NULL
) = 0;
79 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
80 wxPrintData
*data
) = 0;
82 virtual wxPrintNativeDataBase
*CreatePrintNativeData() = 0;
84 static void SetPrintFactory( wxPrintFactory
*factory
);
85 static wxPrintFactory
*GetFactory();
86 static wxPrintFactory
*m_factory
;
89 class WXDLLEXPORT wxNativePrintFactory
: public wxPrintFactory
92 virtual bool HasPageSetupDialog()
94 virtual bool HasPrintSetupDialog()
97 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
99 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
100 wxPrintout
*printout
= NULL
,
101 wxPrintDialogData
*data
= NULL
);
102 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
103 wxPrintout
*printout
,
106 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
107 wxPrintDialogData
*data
= NULL
);
108 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
111 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
114 //----------------------------------------------------------------------------
115 // wxPrintNativeDataBase
116 //----------------------------------------------------------------------------
118 class WXDLLEXPORT wxPrintNativeDataBase
: public wxObject
121 wxPrintNativeDataBase();
122 virtual ~wxPrintNativeDataBase() {}
124 virtual bool TransferTo( wxPrintData
&data
) = 0;
125 virtual bool TransferFrom( const wxPrintData
&data
) = 0;
127 virtual bool Ok() const = 0;
132 DECLARE_CLASS(wxPrintNativeDataBase
)
133 DECLARE_NO_COPY_CLASS(wxPrintNativeDataBase
)
136 //----------------------------------------------------------------------------
138 //----------------------------------------------------------------------------
141 * Represents the printer: manages printing a wxPrintout object
144 class WXDLLEXPORT wxPrinterBase
: public wxObject
147 wxPrinterBase(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
148 virtual ~wxPrinterBase();
150 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
151 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
153 virtual wxPrintDialogData
& GetPrintDialogData() const;
154 bool GetAbort() const { return sm_abortIt
; }
156 static wxPrinterError
GetLastError() { return sm_lastError
; }
158 ///////////////////////////////////////////////////////////////////////////
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;
166 wxPrintDialogData m_printDialogData
;
167 wxPrintout
* m_currentPrintout
;
169 static wxPrinterError sm_lastError
;
172 static wxWindow
* sm_abortWindow
;
173 static bool sm_abortIt
;
176 DECLARE_CLASS(wxPrinterBase
)
177 DECLARE_NO_COPY_CLASS(wxPrinterBase
)
180 //----------------------------------------------------------------------------
182 //----------------------------------------------------------------------------
184 class WXDLLEXPORT wxPrinter
: public wxPrinterBase
187 wxPrinter(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
188 virtual ~wxPrinter();
190 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
191 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
193 virtual bool Setup(wxWindow
*parent
);
194 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true);
195 virtual wxDC
* PrintDialog(wxWindow
*parent
);
197 virtual wxPrintDialogData
& GetPrintDialogData() const;
200 wxPrinterBase
*m_pimpl
;
203 DECLARE_CLASS(wxPrinter
)
204 DECLARE_NO_COPY_CLASS(wxPrinter
)
207 //----------------------------------------------------------------------------
209 //----------------------------------------------------------------------------
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.
218 class WXDLLEXPORT wxPrintout
: public wxObject
221 wxPrintout(const wxString
& title
= wxT("Printout"));
222 virtual ~wxPrintout();
224 virtual bool OnBeginDocument(int startPage
, int endPage
);
225 virtual void OnEndDocument();
226 virtual void OnBeginPrinting();
227 virtual void OnEndPrinting();
229 // Guaranteed to be before any other functions are called
230 virtual void OnPreparePrinting() { }
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
);
236 virtual wxString
GetTitle() const { return m_printoutTitle
; }
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
; }
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
; }
250 virtual bool IsPreview() const { return m_isPreview
; }
252 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
255 wxString m_printoutTitle
;
258 int m_pageWidthPixels
;
259 int m_pageHeightPixels
;
272 DECLARE_ABSTRACT_CLASS(wxPrintout
)
273 DECLARE_NO_COPY_CLASS(wxPrintout
)
278 * Canvas upon which a preview is drawn.
281 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
284 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
286 const wxPoint
& pos
= wxDefaultPosition
,
287 const wxSize
& size
= wxDefaultSize
,
289 const wxString
& name
= wxT("canvas"));
292 void OnPaint(wxPaintEvent
& event
);
293 void OnChar(wxKeyEvent
&event
);
295 // Responds to colour changes
296 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
299 wxPrintPreviewBase
* m_printPreview
;
301 DECLARE_CLASS(wxPreviewCanvas
)
302 DECLARE_EVENT_TABLE()
303 DECLARE_NO_COPY_CLASS(wxPreviewCanvas
)
308 * Default frame for showing preview.
311 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
314 wxPreviewFrame(wxPrintPreviewBase
*preview
,
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"));
323 void OnCloseWindow(wxCloseEvent
& event
);
324 virtual void Initialize();
325 virtual void CreateCanvas();
326 virtual void CreateControlBar();
328 inline wxPreviewControlBar
* GetControlBar() const { return m_controlBar
; }
331 wxPreviewCanvas
* m_previewCanvas
;
332 wxPreviewControlBar
* m_controlBar
;
333 wxPrintPreviewBase
* m_printPreview
;
334 wxWindowDisabler
* m_windowDisabler
;
337 DECLARE_CLASS(wxPreviewFrame
)
338 DECLARE_EVENT_TABLE()
339 DECLARE_NO_COPY_CLASS(wxPreviewFrame
)
343 * wxPreviewControlBar
344 * A panel with buttons for controlling a print preview.
345 * The programmer may wish to use other means for controlling
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
357 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
358 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST
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
370 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
372 DECLARE_CLASS(wxPreviewControlBar
)
375 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
378 const wxPoint
& pos
= wxDefaultPosition
,
379 const wxSize
& size
= wxDefaultSize
,
380 long style
= wxTAB_TRAVERSAL
,
381 const wxString
& name
= wxT("panel"));
382 ~wxPreviewControlBar();
384 virtual void CreateButtons();
385 virtual void SetZoomControl(int zoom
);
386 virtual int GetZoomControl();
387 virtual wxPrintPreviewBase
*GetPrintPreview() const
388 { return m_printPreview
; }
390 void OnWindowClose(wxCommandEvent
& event
);
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
);
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
;
419 DECLARE_EVENT_TABLE()
420 DECLARE_NO_COPY_CLASS(wxPreviewControlBar
)
423 //----------------------------------------------------------------------------
424 // wxPrintPreviewBase
425 //----------------------------------------------------------------------------
428 * Programmer creates an object of this class to preview a wxPrintout.
431 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
434 wxPrintPreviewBase(wxPrintout
*printout
,
435 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
436 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
437 wxPrintPreviewBase(wxPrintout
*printout
,
438 wxPrintout
*printoutForPrinting
,
440 virtual ~wxPrintPreviewBase();
442 virtual bool SetCurrentPage(int pageNum
);
443 virtual int GetCurrentPage() const;
445 virtual void SetPrintout(wxPrintout
*printout
);
446 virtual wxPrintout
*GetPrintout() const;
447 virtual wxPrintout
*GetPrintoutForPrinting() const;
449 virtual void SetFrame(wxFrame
*frame
);
450 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
452 virtual wxFrame
*GetFrame() const;
453 virtual wxPreviewCanvas
*GetCanvas() const;
455 // The preview canvas should call this from OnPaint
456 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
458 // This draws a blank page onto the preview canvas
459 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
461 // Adjusts the scrollbars for the current scale
462 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
464 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
465 virtual bool RenderPage(int pageNum
);
468 virtual void SetZoom(int percent
);
469 virtual int GetZoom() const;
471 virtual wxPrintDialogData
& GetPrintDialogData();
473 virtual int GetMaxPage() const;
474 virtual int GetMinPage() const;
476 virtual bool Ok() const;
477 virtual void SetOk(bool ok
);
479 ///////////////////////////////////////////////////////////////////////////
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;
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;
493 wxPrintDialogData m_printDialogData
;
494 wxPreviewCanvas
* m_previewCanvas
;
495 wxFrame
* m_previewFrame
;
496 wxBitmap
* m_previewBitmap
;
497 wxPrintout
* m_previewPrintout
;
498 wxPrintout
* m_printPrintout
;
501 float m_previewScale
;
510 bool m_printingPrepared
; // Called OnPreparePrinting?
513 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
515 DECLARE_NO_COPY_CLASS(wxPrintPreviewBase
)
516 DECLARE_CLASS(wxPrintPreviewBase
)
519 //----------------------------------------------------------------------------
521 //----------------------------------------------------------------------------
523 class WXDLLEXPORT wxPrintPreview
: public wxPrintPreviewBase
526 wxPrintPreview(wxPrintout
*printout
,
527 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
528 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
529 wxPrintPreview(wxPrintout
*printout
,
530 wxPrintout
*printoutForPrinting
,
532 virtual ~wxPrintPreview();
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
);
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
);
550 virtual bool Print(bool interactive
);
551 virtual void DetermineScaling();
553 virtual wxPrintDialogData
& GetPrintDialogData();
555 virtual int GetMaxPage() const;
556 virtual int GetMinPage() const;
558 virtual bool Ok() const;
559 virtual void SetOk(bool ok
);
562 wxPrintPreviewBase
*m_pimpl
;
565 DECLARE_CLASS(wxPrintPreview
)
566 DECLARE_NO_COPY_CLASS(wxPrintPreview
)
569 //----------------------------------------------------------------------------
570 // wxPrintAbortDialog
571 //----------------------------------------------------------------------------
573 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
576 wxPrintAbortDialog(wxWindow
*parent
,
577 const wxString
& title
,
578 const wxPoint
& pos
= wxDefaultPosition
,
579 const wxSize
& size
= wxDefaultSize
,
581 const wxString
& name
= wxT("dialog"))
582 : wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
586 void OnCancel(wxCommandEvent
& event
);
589 DECLARE_EVENT_TABLE()
590 DECLARE_NO_COPY_CLASS(wxPrintAbortDialog
)
593 #endif // wxUSE_PRINTING_ARCHITECTURE