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 wxPrinterBase
*CreatePrinter( wxPrintDialogData
* data
) = 0;
67 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
68 wxPrintout
*printout
= NULL
,
69 wxPrintDialogData
*data
= NULL
) = 0;
70 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
72 wxPrintData
*data
) = 0;
74 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
75 wxPrintDialogData
*data
= NULL
) = 0;
76 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
77 wxPrintData
*data
) = 0;
79 // What to do and what to show in the wxPrintDialog
80 // a) Use the generic print setup dialog or a native one?
81 virtual bool HasPrintSetupDialog() = 0;
82 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
) = 0;
83 // b) Provide the "print to file" option ourselves or via print setup?
84 virtual bool HasOwnPrintToFile() = 0;
85 // c) Show current printer
86 virtual bool HasPrinterLine() = 0;
87 virtual wxString
CreatePrinterLine() = 0;
88 // d) Show Status line for current printer?
89 virtual bool HasStatusLine() = 0;
90 virtual wxString
CreateStatusLine() = 0;
93 virtual wxPrintNativeDataBase
*CreatePrintNativeData() = 0;
95 static void SetPrintFactory( wxPrintFactory
*factory
);
96 static wxPrintFactory
*GetFactory();
97 static wxPrintFactory
*m_factory
;
100 class WXDLLEXPORT wxNativePrintFactory
: public wxPrintFactory
103 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
105 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
106 wxPrintout
*printout
= NULL
,
107 wxPrintDialogData
*data
= NULL
);
108 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
109 wxPrintout
*printout
,
112 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
113 wxPrintDialogData
*data
= NULL
);
114 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
117 virtual bool HasPrintSetupDialog();
118 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
119 virtual bool HasOwnPrintToFile();
120 virtual bool HasPrinterLine();
121 virtual wxString
CreatePrinterLine();
122 virtual bool HasStatusLine();
123 virtual wxString
CreateStatusLine();
125 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
128 //----------------------------------------------------------------------------
129 // wxPrintNativeDataBase
130 //----------------------------------------------------------------------------
132 class WXDLLEXPORT wxPrintNativeDataBase
: public wxObject
135 wxPrintNativeDataBase();
136 virtual ~wxPrintNativeDataBase() {}
138 virtual bool TransferTo( wxPrintData
&data
) = 0;
139 virtual bool TransferFrom( const wxPrintData
&data
) = 0;
141 virtual bool Ok() const = 0;
146 DECLARE_CLASS(wxPrintNativeDataBase
)
147 DECLARE_NO_COPY_CLASS(wxPrintNativeDataBase
)
150 //----------------------------------------------------------------------------
152 //----------------------------------------------------------------------------
155 * Represents the printer: manages printing a wxPrintout object
158 class WXDLLEXPORT wxPrinterBase
: public wxObject
161 wxPrinterBase(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
162 virtual ~wxPrinterBase();
164 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
165 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
167 virtual wxPrintDialogData
& GetPrintDialogData() const;
168 bool GetAbort() const { return sm_abortIt
; }
170 static wxPrinterError
GetLastError() { return sm_lastError
; }
172 ///////////////////////////////////////////////////////////////////////////
175 virtual bool Setup(wxWindow
*parent
) = 0;
176 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true) = 0;
177 virtual wxDC
* PrintDialog(wxWindow
*parent
) = 0;
180 wxPrintDialogData m_printDialogData
;
181 wxPrintout
* m_currentPrintout
;
183 static wxPrinterError sm_lastError
;
186 static wxWindow
* sm_abortWindow
;
187 static bool sm_abortIt
;
190 DECLARE_CLASS(wxPrinterBase
)
191 DECLARE_NO_COPY_CLASS(wxPrinterBase
)
194 //----------------------------------------------------------------------------
196 //----------------------------------------------------------------------------
198 class WXDLLEXPORT wxPrinter
: public wxPrinterBase
201 wxPrinter(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
202 virtual ~wxPrinter();
204 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
205 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
207 virtual bool Setup(wxWindow
*parent
);
208 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true);
209 virtual wxDC
* PrintDialog(wxWindow
*parent
);
211 virtual wxPrintDialogData
& GetPrintDialogData() const;
214 wxPrinterBase
*m_pimpl
;
217 DECLARE_CLASS(wxPrinter
)
218 DECLARE_NO_COPY_CLASS(wxPrinter
)
221 //----------------------------------------------------------------------------
223 //----------------------------------------------------------------------------
226 * Represents an object via which a document may be printed.
227 * The programmer derives from this, overrides (at least) OnPrintPage,
228 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
229 * object for previewing.
232 class WXDLLEXPORT wxPrintout
: public wxObject
235 wxPrintout(const wxString
& title
= wxT("Printout"));
236 virtual ~wxPrintout();
238 virtual bool OnBeginDocument(int startPage
, int endPage
);
239 virtual void OnEndDocument();
240 virtual void OnBeginPrinting();
241 virtual void OnEndPrinting();
243 // Guaranteed to be before any other functions are called
244 virtual void OnPreparePrinting() { }
246 virtual bool HasPage(int page
);
247 virtual bool OnPrintPage(int page
) = 0;
248 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
250 virtual wxString
GetTitle() const { return m_printoutTitle
; }
252 wxDC
*GetDC() const { return m_printoutDC
; }
253 void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
254 void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
255 void GetPageSizePixels(int *w
, int *h
) const { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
256 void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
257 void GetPageSizeMM(int *w
, int *h
) const { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
259 void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
260 void GetPPIScreen(int *x
, int *y
) const { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
261 void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
262 void GetPPIPrinter(int *x
, int *y
) const { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
264 virtual bool IsPreview() const { return m_isPreview
; }
266 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
269 wxString m_printoutTitle
;
272 int m_pageWidthPixels
;
273 int m_pageHeightPixels
;
286 DECLARE_ABSTRACT_CLASS(wxPrintout
)
287 DECLARE_NO_COPY_CLASS(wxPrintout
)
292 * Canvas upon which a preview is drawn.
295 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
298 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
300 const wxPoint
& pos
= wxDefaultPosition
,
301 const wxSize
& size
= wxDefaultSize
,
303 const wxString
& name
= wxT("canvas"));
306 void OnPaint(wxPaintEvent
& event
);
307 void OnChar(wxKeyEvent
&event
);
309 // Responds to colour changes
310 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
313 wxPrintPreviewBase
* m_printPreview
;
315 DECLARE_CLASS(wxPreviewCanvas
)
316 DECLARE_EVENT_TABLE()
317 DECLARE_NO_COPY_CLASS(wxPreviewCanvas
)
322 * Default frame for showing preview.
325 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
328 wxPreviewFrame(wxPrintPreviewBase
*preview
,
330 const wxString
& title
= wxT("Print Preview"),
331 const wxPoint
& pos
= wxDefaultPosition
,
332 const wxSize
& size
= wxDefaultSize
,
333 long style
= wxDEFAULT_FRAME_STYLE
,
334 const wxString
& name
= wxT("frame"));
337 void OnCloseWindow(wxCloseEvent
& event
);
338 virtual void Initialize();
339 virtual void CreateCanvas();
340 virtual void CreateControlBar();
342 inline wxPreviewControlBar
* GetControlBar() const { return m_controlBar
; }
345 wxPreviewCanvas
* m_previewCanvas
;
346 wxPreviewControlBar
* m_controlBar
;
347 wxPrintPreviewBase
* m_printPreview
;
348 wxWindowDisabler
* m_windowDisabler
;
351 DECLARE_CLASS(wxPreviewFrame
)
352 DECLARE_EVENT_TABLE()
353 DECLARE_NO_COPY_CLASS(wxPreviewFrame
)
357 * wxPreviewControlBar
358 * A panel with buttons for controlling a print preview.
359 * The programmer may wish to use other means for controlling
363 #define wxPREVIEW_PRINT 1
364 #define wxPREVIEW_PREVIOUS 2
365 #define wxPREVIEW_NEXT 4
366 #define wxPREVIEW_ZOOM 8
367 #define wxPREVIEW_FIRST 16
368 #define wxPREVIEW_LAST 32
369 #define wxPREVIEW_GOTO 64
371 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
372 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST
375 #define wxID_PREVIEW_CLOSE 1
376 #define wxID_PREVIEW_NEXT 2
377 #define wxID_PREVIEW_PREVIOUS 3
378 #define wxID_PREVIEW_PRINT 4
379 #define wxID_PREVIEW_ZOOM 5
380 #define wxID_PREVIEW_FIRST 6
381 #define wxID_PREVIEW_LAST 7
382 #define wxID_PREVIEW_GOTO 8
384 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
386 DECLARE_CLASS(wxPreviewControlBar
)
389 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
392 const wxPoint
& pos
= wxDefaultPosition
,
393 const wxSize
& size
= wxDefaultSize
,
394 long style
= wxTAB_TRAVERSAL
,
395 const wxString
& name
= wxT("panel"));
396 ~wxPreviewControlBar();
398 virtual void CreateButtons();
399 virtual void SetZoomControl(int zoom
);
400 virtual int GetZoomControl();
401 virtual wxPrintPreviewBase
*GetPrintPreview() const
402 { return m_printPreview
; }
404 void OnWindowClose(wxCommandEvent
& event
);
411 void OnPrintButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrint(); }
412 void OnNextButton(wxCommandEvent
& WXUNUSED(event
)) { OnNext(); }
413 void OnPreviousButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrevious(); }
414 void OnFirstButton(wxCommandEvent
& WXUNUSED(event
)) { OnFirst(); }
415 void OnLastButton(wxCommandEvent
& WXUNUSED(event
)) { OnLast(); }
416 void OnGotoButton(wxCommandEvent
& WXUNUSED(event
)) { OnGoto(); }
417 void OnZoom(wxCommandEvent
& event
);
418 void OnPaint(wxPaintEvent
& event
);
421 wxPrintPreviewBase
* m_printPreview
;
422 wxButton
* m_closeButton
;
423 wxButton
* m_nextPageButton
;
424 wxButton
* m_previousPageButton
;
425 wxButton
* m_printButton
;
426 wxChoice
* m_zoomControl
;
427 wxButton
* m_firstPageButton
;
428 wxButton
* m_lastPageButton
;
429 wxButton
* m_gotoPageButton
;
433 DECLARE_EVENT_TABLE()
434 DECLARE_NO_COPY_CLASS(wxPreviewControlBar
)
437 //----------------------------------------------------------------------------
438 // wxPrintPreviewBase
439 //----------------------------------------------------------------------------
442 * Programmer creates an object of this class to preview a wxPrintout.
445 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
448 wxPrintPreviewBase(wxPrintout
*printout
,
449 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
450 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
451 wxPrintPreviewBase(wxPrintout
*printout
,
452 wxPrintout
*printoutForPrinting
,
454 virtual ~wxPrintPreviewBase();
456 virtual bool SetCurrentPage(int pageNum
);
457 virtual int GetCurrentPage() const;
459 virtual void SetPrintout(wxPrintout
*printout
);
460 virtual wxPrintout
*GetPrintout() const;
461 virtual wxPrintout
*GetPrintoutForPrinting() const;
463 virtual void SetFrame(wxFrame
*frame
);
464 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
466 virtual wxFrame
*GetFrame() const;
467 virtual wxPreviewCanvas
*GetCanvas() const;
469 // The preview canvas should call this from OnPaint
470 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
472 // This draws a blank page onto the preview canvas
473 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
475 // Adjusts the scrollbars for the current scale
476 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
478 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
479 virtual bool RenderPage(int pageNum
);
482 virtual void SetZoom(int percent
);
483 virtual int GetZoom() const;
485 virtual wxPrintDialogData
& GetPrintDialogData();
487 virtual int GetMaxPage() const;
488 virtual int GetMinPage() const;
490 virtual bool Ok() const;
491 virtual void SetOk(bool ok
);
493 ///////////////////////////////////////////////////////////////////////////
496 // If we own a wxPrintout that can be used for printing, this
497 // will invoke the actual printing procedure. Called
498 // by the wxPreviewControlBar.
499 virtual bool Print(bool interactive
) = 0;
501 // Calculate scaling that needs to be done to get roughly
502 // the right scaling for the screen pretending to be
503 // the currently selected printer.
504 virtual void DetermineScaling() = 0;
507 wxPrintDialogData m_printDialogData
;
508 wxPreviewCanvas
* m_previewCanvas
;
509 wxFrame
* m_previewFrame
;
510 wxBitmap
* m_previewBitmap
;
511 wxPrintout
* m_previewPrintout
;
512 wxPrintout
* m_printPrintout
;
515 float m_previewScale
;
524 bool m_printingPrepared
; // Called OnPreparePrinting?
527 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
529 DECLARE_NO_COPY_CLASS(wxPrintPreviewBase
)
530 DECLARE_CLASS(wxPrintPreviewBase
)
533 //----------------------------------------------------------------------------
535 //----------------------------------------------------------------------------
537 class WXDLLEXPORT wxPrintPreview
: public wxPrintPreviewBase
540 wxPrintPreview(wxPrintout
*printout
,
541 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
542 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
543 wxPrintPreview(wxPrintout
*printout
,
544 wxPrintout
*printoutForPrinting
,
546 virtual ~wxPrintPreview();
548 virtual bool SetCurrentPage(int pageNum
);
549 virtual int GetCurrentPage() const;
550 virtual void SetPrintout(wxPrintout
*printout
);
551 virtual wxPrintout
*GetPrintout() const;
552 virtual wxPrintout
*GetPrintoutForPrinting() const;
553 virtual void SetFrame(wxFrame
*frame
);
554 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
556 virtual wxFrame
*GetFrame() const;
557 virtual wxPreviewCanvas
*GetCanvas() const;
558 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
559 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
560 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
561 virtual bool RenderPage(int pageNum
);
562 virtual void SetZoom(int percent
);
564 virtual bool Print(bool interactive
);
565 virtual void DetermineScaling();
567 virtual wxPrintDialogData
& GetPrintDialogData();
569 virtual int GetMaxPage() const;
570 virtual int GetMinPage() const;
572 virtual bool Ok() const;
573 virtual void SetOk(bool ok
);
576 wxPrintPreviewBase
*m_pimpl
;
579 DECLARE_CLASS(wxPrintPreview
)
580 DECLARE_NO_COPY_CLASS(wxPrintPreview
)
583 //----------------------------------------------------------------------------
584 // wxPrintAbortDialog
585 //----------------------------------------------------------------------------
587 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
590 wxPrintAbortDialog(wxWindow
*parent
,
591 const wxString
& title
,
592 const wxPoint
& pos
= wxDefaultPosition
,
593 const wxSize
& size
= wxDefaultSize
,
595 const wxString
& name
= wxT("dialog"))
596 : wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
600 void OnCancel(wxCommandEvent
& event
);
603 DECLARE_EVENT_TABLE()
604 DECLARE_NO_COPY_CLASS(wxPrintAbortDialog
)
607 #endif // wxUSE_PRINTING_ARCHITECTURE