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__
17 #if wxUSE_PRINTING_ARCHITECTURE
20 #include "wx/cmndata.h"
22 #include "wx/scrolwin.h"
23 #include "wx/dialog.h"
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
;
42 //----------------------------------------------------------------------------
44 //----------------------------------------------------------------------------
48 wxPRINTER_NO_ERROR
= 0,
53 //----------------------------------------------------------------------------
55 //----------------------------------------------------------------------------
57 class WXDLLEXPORT wxPrintFactory
61 virtual ~wxPrintFactory() {}
63 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
* data
) = 0;
65 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
66 wxPrintout
*printout
= NULL
,
67 wxPrintDialogData
*data
= NULL
) = 0;
68 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
70 wxPrintData
*data
) = 0;
72 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
73 wxPrintDialogData
*data
= NULL
) = 0;
74 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
75 wxPrintData
*data
) = 0;
77 virtual wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
78 wxPageSetupDialogData
* data
= NULL
) = 0;
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;
94 virtual wxPrintNativeDataBase
*CreatePrintNativeData() = 0;
96 static void SetPrintFactory( wxPrintFactory
*factory
);
97 static wxPrintFactory
*GetFactory();
98 static wxPrintFactory
*m_factory
;
101 class WXDLLEXPORT wxNativePrintFactory
: public wxPrintFactory
104 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
106 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
107 wxPrintout
*printout
= NULL
,
108 wxPrintDialogData
*data
= NULL
);
109 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
110 wxPrintout
*printout
,
113 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
114 wxPrintDialogData
*data
= NULL
);
115 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
118 virtual wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
119 wxPageSetupDialogData
* data
= NULL
);
121 virtual bool HasPrintSetupDialog();
122 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
123 virtual bool HasOwnPrintToFile();
124 virtual bool HasPrinterLine();
125 virtual wxString
CreatePrinterLine();
126 virtual bool HasStatusLine();
127 virtual wxString
CreateStatusLine();
129 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
132 //----------------------------------------------------------------------------
133 // wxPrintNativeDataBase
134 //----------------------------------------------------------------------------
136 class WXDLLEXPORT wxPrintNativeDataBase
: public wxObject
139 wxPrintNativeDataBase();
140 virtual ~wxPrintNativeDataBase() {}
142 virtual bool TransferTo( wxPrintData
&data
) = 0;
143 virtual bool TransferFrom( const wxPrintData
&data
) = 0;
145 virtual bool Ok() const = 0;
150 DECLARE_CLASS(wxPrintNativeDataBase
)
151 DECLARE_NO_COPY_CLASS(wxPrintNativeDataBase
)
154 //----------------------------------------------------------------------------
156 //----------------------------------------------------------------------------
159 * Represents the printer: manages printing a wxPrintout object
162 class WXDLLEXPORT wxPrinterBase
: public wxObject
165 wxPrinterBase(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
166 virtual ~wxPrinterBase();
168 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
169 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
171 virtual wxPrintDialogData
& GetPrintDialogData() const;
172 bool GetAbort() const { return sm_abortIt
; }
174 static wxPrinterError
GetLastError() { return sm_lastError
; }
176 ///////////////////////////////////////////////////////////////////////////
179 virtual bool Setup(wxWindow
*parent
) = 0;
180 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true) = 0;
181 virtual wxDC
* PrintDialog(wxWindow
*parent
) = 0;
184 wxPrintDialogData m_printDialogData
;
185 wxPrintout
* m_currentPrintout
;
187 static wxPrinterError sm_lastError
;
190 static wxWindow
* sm_abortWindow
;
191 static bool sm_abortIt
;
194 DECLARE_CLASS(wxPrinterBase
)
195 DECLARE_NO_COPY_CLASS(wxPrinterBase
)
198 //----------------------------------------------------------------------------
200 //----------------------------------------------------------------------------
202 class WXDLLEXPORT wxPrinter
: public wxPrinterBase
205 wxPrinter(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
206 virtual ~wxPrinter();
208 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
209 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
211 virtual bool Setup(wxWindow
*parent
);
212 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true);
213 virtual wxDC
* PrintDialog(wxWindow
*parent
);
215 virtual wxPrintDialogData
& GetPrintDialogData() const;
218 wxPrinterBase
*m_pimpl
;
221 DECLARE_CLASS(wxPrinter
)
222 DECLARE_NO_COPY_CLASS(wxPrinter
)
225 //----------------------------------------------------------------------------
227 //----------------------------------------------------------------------------
230 * Represents an object via which a document may be printed.
231 * The programmer derives from this, overrides (at least) OnPrintPage,
232 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
233 * object for previewing.
236 class WXDLLEXPORT wxPrintout
: public wxObject
239 wxPrintout(const wxString
& title
= wxT("Printout"));
240 virtual ~wxPrintout();
242 virtual bool OnBeginDocument(int startPage
, int endPage
);
243 virtual void OnEndDocument();
244 virtual void OnBeginPrinting();
245 virtual void OnEndPrinting();
247 // Guaranteed to be before any other functions are called
248 virtual void OnPreparePrinting() { }
250 virtual bool HasPage(int page
);
251 virtual bool OnPrintPage(int page
) = 0;
252 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
254 virtual wxString
GetTitle() const { return m_printoutTitle
; }
256 wxDC
*GetDC() const { return m_printoutDC
; }
257 void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
258 void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
259 void GetPageSizePixels(int *w
, int *h
) const { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
260 void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
261 void GetPageSizeMM(int *w
, int *h
) const { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
263 void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
264 void GetPPIScreen(int *x
, int *y
) const { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
265 void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
266 void GetPPIPrinter(int *x
, int *y
) const { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
268 virtual bool IsPreview() const { return m_isPreview
; }
270 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
273 wxString m_printoutTitle
;
276 int m_pageWidthPixels
;
277 int m_pageHeightPixels
;
290 DECLARE_ABSTRACT_CLASS(wxPrintout
)
291 DECLARE_NO_COPY_CLASS(wxPrintout
)
296 * Canvas upon which a preview is drawn.
299 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
302 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
304 const wxPoint
& pos
= wxDefaultPosition
,
305 const wxSize
& size
= wxDefaultSize
,
307 const wxString
& name
= wxT("canvas"));
310 void OnPaint(wxPaintEvent
& event
);
311 void OnChar(wxKeyEvent
&event
);
312 // Responds to colour changes
313 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
317 void OnMouseWheel(wxMouseEvent
& event
);
318 #endif // wxUSE_MOUSEWHEEL
320 wxPrintPreviewBase
* m_printPreview
;
322 DECLARE_CLASS(wxPreviewCanvas
)
323 DECLARE_EVENT_TABLE()
324 DECLARE_NO_COPY_CLASS(wxPreviewCanvas
)
329 * Default frame for showing preview.
332 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
335 wxPreviewFrame(wxPrintPreviewBase
*preview
,
337 const wxString
& title
= wxT("Print Preview"),
338 const wxPoint
& pos
= wxDefaultPosition
,
339 const wxSize
& size
= wxDefaultSize
,
340 long style
= wxDEFAULT_FRAME_STYLE
,
341 const wxString
& name
= wxT("frame"));
344 void OnCloseWindow(wxCloseEvent
& event
);
345 virtual void Initialize();
346 virtual void CreateCanvas();
347 virtual void CreateControlBar();
349 inline wxPreviewControlBar
* GetControlBar() const { return m_controlBar
; }
352 wxPreviewCanvas
* m_previewCanvas
;
353 wxPreviewControlBar
* m_controlBar
;
354 wxPrintPreviewBase
* m_printPreview
;
355 wxWindowDisabler
* m_windowDisabler
;
358 DECLARE_CLASS(wxPreviewFrame
)
359 DECLARE_EVENT_TABLE()
360 DECLARE_NO_COPY_CLASS(wxPreviewFrame
)
364 * wxPreviewControlBar
365 * A panel with buttons for controlling a print preview.
366 * The programmer may wish to use other means for controlling
370 #define wxPREVIEW_PRINT 1
371 #define wxPREVIEW_PREVIOUS 2
372 #define wxPREVIEW_NEXT 4
373 #define wxPREVIEW_ZOOM 8
374 #define wxPREVIEW_FIRST 16
375 #define wxPREVIEW_LAST 32
376 #define wxPREVIEW_GOTO 64
378 #define wxPREVIEW_DEFAULT (wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
379 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST)
382 #define wxID_PREVIEW_CLOSE 1
383 #define wxID_PREVIEW_NEXT 2
384 #define wxID_PREVIEW_PREVIOUS 3
385 #define wxID_PREVIEW_PRINT 4
386 #define wxID_PREVIEW_ZOOM 5
387 #define wxID_PREVIEW_FIRST 6
388 #define wxID_PREVIEW_LAST 7
389 #define wxID_PREVIEW_GOTO 8
391 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
393 DECLARE_CLASS(wxPreviewControlBar
)
396 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
399 const wxPoint
& pos
= wxDefaultPosition
,
400 const wxSize
& size
= wxDefaultSize
,
401 long style
= wxTAB_TRAVERSAL
,
402 const wxString
& name
= wxT("panel"));
403 ~wxPreviewControlBar();
405 virtual void CreateButtons();
406 virtual void SetZoomControl(int zoom
);
407 virtual int GetZoomControl();
408 virtual wxPrintPreviewBase
*GetPrintPreview() const
409 { return m_printPreview
; }
411 void OnWindowClose(wxCommandEvent
& event
);
418 void OnPrintButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrint(); }
419 void OnNextButton(wxCommandEvent
& WXUNUSED(event
)) { OnNext(); }
420 void OnPreviousButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrevious(); }
421 void OnFirstButton(wxCommandEvent
& WXUNUSED(event
)) { OnFirst(); }
422 void OnLastButton(wxCommandEvent
& WXUNUSED(event
)) { OnLast(); }
423 void OnGotoButton(wxCommandEvent
& WXUNUSED(event
)) { OnGoto(); }
424 void OnZoom(wxCommandEvent
& event
);
425 void OnPaint(wxPaintEvent
& event
);
428 wxPrintPreviewBase
* m_printPreview
;
429 wxButton
* m_closeButton
;
430 wxButton
* m_nextPageButton
;
431 wxButton
* m_previousPageButton
;
432 wxButton
* m_printButton
;
433 wxChoice
* m_zoomControl
;
434 wxButton
* m_firstPageButton
;
435 wxButton
* m_lastPageButton
;
436 wxButton
* m_gotoPageButton
;
440 DECLARE_EVENT_TABLE()
441 DECLARE_NO_COPY_CLASS(wxPreviewControlBar
)
444 //----------------------------------------------------------------------------
445 // wxPrintPreviewBase
446 //----------------------------------------------------------------------------
449 * Programmer creates an object of this class to preview a wxPrintout.
452 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
455 wxPrintPreviewBase(wxPrintout
*printout
,
456 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
457 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
458 wxPrintPreviewBase(wxPrintout
*printout
,
459 wxPrintout
*printoutForPrinting
,
461 virtual ~wxPrintPreviewBase();
463 virtual bool SetCurrentPage(int pageNum
);
464 virtual int GetCurrentPage() const;
466 virtual void SetPrintout(wxPrintout
*printout
);
467 virtual wxPrintout
*GetPrintout() const;
468 virtual wxPrintout
*GetPrintoutForPrinting() const;
470 virtual void SetFrame(wxFrame
*frame
);
471 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
473 virtual wxFrame
*GetFrame() const;
474 virtual wxPreviewCanvas
*GetCanvas() const;
476 // The preview canvas should call this from OnPaint
477 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
479 // This draws a blank page onto the preview canvas
480 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
482 // Adjusts the scrollbars for the current scale
483 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
485 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
486 virtual bool RenderPage(int pageNum
);
489 virtual void SetZoom(int percent
);
490 virtual int GetZoom() const;
492 virtual wxPrintDialogData
& GetPrintDialogData();
494 virtual int GetMaxPage() const;
495 virtual int GetMinPage() const;
497 virtual bool Ok() const;
498 virtual void SetOk(bool ok
);
500 ///////////////////////////////////////////////////////////////////////////
503 // If we own a wxPrintout that can be used for printing, this
504 // will invoke the actual printing procedure. Called
505 // by the wxPreviewControlBar.
506 virtual bool Print(bool interactive
) = 0;
508 // Calculate scaling that needs to be done to get roughly
509 // the right scaling for the screen pretending to be
510 // the currently selected printer.
511 virtual void DetermineScaling() = 0;
514 wxPrintDialogData m_printDialogData
;
515 wxPreviewCanvas
* m_previewCanvas
;
516 wxFrame
* m_previewFrame
;
517 wxBitmap
* m_previewBitmap
;
518 wxPrintout
* m_previewPrintout
;
519 wxPrintout
* m_printPrintout
;
522 float m_previewScale
;
531 bool m_printingPrepared
; // Called OnPreparePrinting?
534 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
536 DECLARE_NO_COPY_CLASS(wxPrintPreviewBase
)
537 DECLARE_CLASS(wxPrintPreviewBase
)
540 //----------------------------------------------------------------------------
542 //----------------------------------------------------------------------------
544 class WXDLLEXPORT wxPrintPreview
: public wxPrintPreviewBase
547 wxPrintPreview(wxPrintout
*printout
,
548 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
549 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
550 wxPrintPreview(wxPrintout
*printout
,
551 wxPrintout
*printoutForPrinting
,
553 virtual ~wxPrintPreview();
555 virtual bool SetCurrentPage(int pageNum
);
556 virtual int GetCurrentPage() const;
557 virtual void SetPrintout(wxPrintout
*printout
);
558 virtual wxPrintout
*GetPrintout() const;
559 virtual wxPrintout
*GetPrintoutForPrinting() const;
560 virtual void SetFrame(wxFrame
*frame
);
561 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
563 virtual wxFrame
*GetFrame() const;
564 virtual wxPreviewCanvas
*GetCanvas() const;
565 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
566 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
567 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
568 virtual bool RenderPage(int pageNum
);
569 virtual void SetZoom(int percent
);
571 virtual bool Print(bool interactive
);
572 virtual void DetermineScaling();
574 virtual wxPrintDialogData
& GetPrintDialogData();
576 virtual int GetMaxPage() const;
577 virtual int GetMinPage() const;
579 virtual bool Ok() const;
580 virtual void SetOk(bool ok
);
583 wxPrintPreviewBase
*m_pimpl
;
586 DECLARE_CLASS(wxPrintPreview
)
587 DECLARE_NO_COPY_CLASS(wxPrintPreview
)
590 //----------------------------------------------------------------------------
591 // wxPrintAbortDialog
592 //----------------------------------------------------------------------------
594 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
597 wxPrintAbortDialog(wxWindow
*parent
,
598 const wxString
& title
,
599 const wxPoint
& pos
= wxDefaultPosition
,
600 const wxSize
& size
= wxDefaultSize
,
602 const wxString
& name
= wxT("dialog"))
603 : wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
607 void OnCancel(wxCommandEvent
& event
);
610 DECLARE_EVENT_TABLE()
611 DECLARE_NO_COPY_CLASS(wxPrintAbortDialog
)
614 #endif // wxUSE_PRINTING_ARCHITECTURE