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();
99 static wxPrintFactory
*m_factory
;
102 class WXDLLEXPORT wxNativePrintFactory
: public wxPrintFactory
105 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
107 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
108 wxPrintout
*printout
= NULL
,
109 wxPrintDialogData
*data
= NULL
);
110 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
111 wxPrintout
*printout
,
114 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
115 wxPrintDialogData
*data
= NULL
);
116 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
119 virtual wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
120 wxPageSetupDialogData
* data
= NULL
);
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();
130 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
133 //----------------------------------------------------------------------------
134 // wxPrintNativeDataBase
135 //----------------------------------------------------------------------------
137 class WXDLLEXPORT wxPrintNativeDataBase
: public wxObject
140 wxPrintNativeDataBase();
141 virtual ~wxPrintNativeDataBase() {}
143 virtual bool TransferTo( wxPrintData
&data
) = 0;
144 virtual bool TransferFrom( const wxPrintData
&data
) = 0;
146 virtual bool Ok() const { return IsOk(); }
147 virtual bool IsOk() const = 0;
152 DECLARE_CLASS(wxPrintNativeDataBase
)
153 DECLARE_NO_COPY_CLASS(wxPrintNativeDataBase
)
156 //----------------------------------------------------------------------------
158 //----------------------------------------------------------------------------
161 * Represents the printer: manages printing a wxPrintout object
164 class WXDLLEXPORT wxPrinterBase
: public wxObject
167 wxPrinterBase(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
168 virtual ~wxPrinterBase();
170 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
171 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
173 virtual wxPrintDialogData
& GetPrintDialogData() const;
174 bool GetAbort() const { return sm_abortIt
; }
176 static wxPrinterError
GetLastError() { return sm_lastError
; }
178 ///////////////////////////////////////////////////////////////////////////
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;
186 wxPrintDialogData m_printDialogData
;
187 wxPrintout
* m_currentPrintout
;
189 static wxPrinterError sm_lastError
;
192 static wxWindow
* sm_abortWindow
;
193 static bool sm_abortIt
;
196 DECLARE_CLASS(wxPrinterBase
)
197 DECLARE_NO_COPY_CLASS(wxPrinterBase
)
200 //----------------------------------------------------------------------------
202 //----------------------------------------------------------------------------
204 class WXDLLEXPORT wxPrinter
: public wxPrinterBase
207 wxPrinter(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
208 virtual ~wxPrinter();
210 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
211 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
213 virtual bool Setup(wxWindow
*parent
);
214 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true);
215 virtual wxDC
* PrintDialog(wxWindow
*parent
);
217 virtual wxPrintDialogData
& GetPrintDialogData() const;
220 wxPrinterBase
*m_pimpl
;
223 DECLARE_CLASS(wxPrinter
)
224 DECLARE_NO_COPY_CLASS(wxPrinter
)
227 //----------------------------------------------------------------------------
229 //----------------------------------------------------------------------------
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.
238 class WXDLLEXPORT wxPrintout
: public wxObject
241 wxPrintout(const wxString
& title
= wxT("Printout"));
242 virtual ~wxPrintout();
244 virtual bool OnBeginDocument(int startPage
, int endPage
);
245 virtual void OnEndDocument();
246 virtual void OnBeginPrinting();
247 virtual void OnEndPrinting();
249 // Guaranteed to be before any other functions are called
250 virtual void OnPreparePrinting() { }
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
);
256 virtual wxString
GetTitle() const { return m_printoutTitle
; }
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
; }
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
; }
270 virtual bool IsPreview() const { return m_isPreview
; }
272 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
275 wxString m_printoutTitle
;
278 int m_pageWidthPixels
;
279 int m_pageHeightPixels
;
292 DECLARE_ABSTRACT_CLASS(wxPrintout
)
293 DECLARE_NO_COPY_CLASS(wxPrintout
)
298 * Canvas upon which a preview is drawn.
301 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
304 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
306 const wxPoint
& pos
= wxDefaultPosition
,
307 const wxSize
& size
= wxDefaultSize
,
309 const wxString
& name
= wxT("canvas"));
310 virtual ~wxPreviewCanvas();
312 void OnPaint(wxPaintEvent
& event
);
313 void OnChar(wxKeyEvent
&event
);
314 // Responds to colour changes
315 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
319 void OnMouseWheel(wxMouseEvent
& event
);
320 #endif // wxUSE_MOUSEWHEEL
322 wxPrintPreviewBase
* m_printPreview
;
324 DECLARE_CLASS(wxPreviewCanvas
)
325 DECLARE_EVENT_TABLE()
326 DECLARE_NO_COPY_CLASS(wxPreviewCanvas
)
331 * Default frame for showing preview.
334 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
337 wxPreviewFrame(wxPrintPreviewBase
*preview
,
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();
346 void OnCloseWindow(wxCloseEvent
& event
);
347 virtual void Initialize();
348 virtual void CreateCanvas();
349 virtual void CreateControlBar();
351 inline wxPreviewControlBar
* GetControlBar() const { return m_controlBar
; }
354 wxPreviewCanvas
* m_previewCanvas
;
355 wxPreviewControlBar
* m_controlBar
;
356 wxPrintPreviewBase
* m_printPreview
;
357 wxWindowDisabler
* m_windowDisabler
;
360 DECLARE_CLASS(wxPreviewFrame
)
361 DECLARE_EVENT_TABLE()
362 DECLARE_NO_COPY_CLASS(wxPreviewFrame
)
366 * wxPreviewControlBar
367 * A panel with buttons for controlling a print preview.
368 * The programmer may wish to use other means for controlling
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
380 #define wxPREVIEW_DEFAULT (wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
381 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST)
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
393 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
395 DECLARE_CLASS(wxPreviewControlBar
)
398 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
401 const wxPoint
& pos
= wxDefaultPosition
,
402 const wxSize
& size
= wxDefaultSize
,
403 long style
= wxTAB_TRAVERSAL
,
404 const wxString
& name
= wxT("panel"));
405 virtual ~wxPreviewControlBar();
407 virtual void CreateButtons();
408 virtual void SetZoomControl(int zoom
);
409 virtual int GetZoomControl();
410 virtual wxPrintPreviewBase
*GetPrintPreview() const
411 { return m_printPreview
; }
413 void OnWindowClose(wxCommandEvent
& event
);
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
);
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
;
442 DECLARE_EVENT_TABLE()
443 DECLARE_NO_COPY_CLASS(wxPreviewControlBar
)
446 //----------------------------------------------------------------------------
447 // wxPrintPreviewBase
448 //----------------------------------------------------------------------------
451 * Programmer creates an object of this class to preview a wxPrintout.
454 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
457 wxPrintPreviewBase(wxPrintout
*printout
,
458 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
459 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
460 wxPrintPreviewBase(wxPrintout
*printout
,
461 wxPrintout
*printoutForPrinting
,
463 virtual ~wxPrintPreviewBase();
465 virtual bool SetCurrentPage(int pageNum
);
466 virtual int GetCurrentPage() const;
468 virtual void SetPrintout(wxPrintout
*printout
);
469 virtual wxPrintout
*GetPrintout() const;
470 virtual wxPrintout
*GetPrintoutForPrinting() const;
472 virtual void SetFrame(wxFrame
*frame
);
473 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
475 virtual wxFrame
*GetFrame() const;
476 virtual wxPreviewCanvas
*GetCanvas() const;
478 // The preview canvas should call this from OnPaint
479 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
481 // This draws a blank page onto the preview canvas
482 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
484 // Adjusts the scrollbars for the current scale
485 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
487 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
488 virtual bool RenderPage(int pageNum
);
491 virtual void SetZoom(int percent
);
492 virtual int GetZoom() const;
494 virtual wxPrintDialogData
& GetPrintDialogData();
496 virtual int GetMaxPage() const;
497 virtual int GetMinPage() const;
499 virtual bool Ok() const { return IsOk(); }
500 virtual bool IsOk() const;
501 virtual void SetOk(bool ok
);
503 ///////////////////////////////////////////////////////////////////////////
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;
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;
517 wxPrintDialogData m_printDialogData
;
518 wxPreviewCanvas
* m_previewCanvas
;
519 wxFrame
* m_previewFrame
;
520 wxBitmap
* m_previewBitmap
;
521 wxPrintout
* m_previewPrintout
;
522 wxPrintout
* m_printPrintout
;
525 float m_previewScale
;
534 bool m_printingPrepared
; // Called OnPreparePrinting?
537 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
539 DECLARE_NO_COPY_CLASS(wxPrintPreviewBase
)
540 DECLARE_CLASS(wxPrintPreviewBase
)
543 //----------------------------------------------------------------------------
545 //----------------------------------------------------------------------------
547 class WXDLLEXPORT wxPrintPreview
: public wxPrintPreviewBase
550 wxPrintPreview(wxPrintout
*printout
,
551 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
552 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
553 wxPrintPreview(wxPrintout
*printout
,
554 wxPrintout
*printoutForPrinting
,
556 virtual ~wxPrintPreview();
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
);
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;
575 virtual bool Print(bool interactive
);
576 virtual void DetermineScaling();
578 virtual wxPrintDialogData
& GetPrintDialogData();
580 virtual int GetMaxPage() const;
581 virtual int GetMinPage() const;
583 virtual bool Ok() const { return IsOk(); }
584 virtual bool IsOk() const;
585 virtual void SetOk(bool ok
);
588 wxPrintPreviewBase
*m_pimpl
;
591 DECLARE_CLASS(wxPrintPreview
)
592 DECLARE_NO_COPY_CLASS(wxPrintPreview
)
595 //----------------------------------------------------------------------------
596 // wxPrintAbortDialog
597 //----------------------------------------------------------------------------
599 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
602 wxPrintAbortDialog(wxWindow
*parent
,
603 const wxString
& title
,
604 const wxPoint
& pos
= wxDefaultPosition
,
605 const wxSize
& size
= wxDefaultSize
,
607 const wxString
& name
= wxT("dialog"))
608 : wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
612 void OnCancel(wxCommandEvent
& event
);
615 DECLARE_EVENT_TABLE()
616 DECLARE_NO_COPY_CLASS(wxPrintAbortDialog
)
619 #endif // wxUSE_PRINTING_ARCHITECTURE