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 wxPrintPreviewBase
;
37 class WXDLLEXPORT wxPreviewCanvas
;
38 class WXDLLEXPORT wxPreviewControlBar
;
39 class WXDLLEXPORT wxPreviewFrame
;
40 class WXDLLEXPORT wxPrintFactory
;
42 //----------------------------------------------------------------------------
44 //----------------------------------------------------------------------------
48 wxPRINTER_NO_ERROR
= 0,
53 //----------------------------------------------------------------------------
55 //----------------------------------------------------------------------------
57 class WXDLLEXPORT wxPrintFactory
61 virtual ~wxPrintFactory() {}
63 virtual bool HasPageSetupDialog() = 0;
64 virtual bool HasPrintSetupDialog() = 0;
66 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 static void SetPrintFactory( wxPrintFactory
*factory
);
75 static wxPrintFactory
*GetFactory();
76 static wxPrintFactory
*m_factory
;
79 class WXDLLEXPORT wxNativePrintFactory
: public wxPrintFactory
82 virtual bool HasPageSetupDialog()
84 virtual bool HasPrintSetupDialog()
87 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
88 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
89 wxPrintout
*printout
= NULL
,
90 wxPrintDialogData
*data
= NULL
);
91 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
96 //----------------------------------------------------------------------------
98 //----------------------------------------------------------------------------
101 * Represents the printer: manages printing a wxPrintout object
104 class WXDLLEXPORT wxPrinterBase
: public wxObject
107 wxPrinterBase(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
108 virtual ~wxPrinterBase();
110 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
111 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
113 wxPrintDialogData
& GetPrintDialogData() const
114 { return (wxPrintDialogData
&) m_printDialogData
; }
115 bool GetAbort() const { return sm_abortIt
; }
117 static wxPrinterError
GetLastError() { return sm_lastError
; }
119 ///////////////////////////////////////////////////////////////////////////
122 virtual bool Setup(wxWindow
*parent
) = 0;
123 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true) = 0;
124 virtual wxDC
* PrintDialog(wxWindow
*parent
) = 0;
127 wxPrintDialogData m_printDialogData
;
128 wxPrintout
* m_currentPrintout
;
130 static wxPrinterError sm_lastError
;
133 static wxWindow
* sm_abortWindow
;
134 static bool sm_abortIt
;
137 DECLARE_CLASS(wxPrinterBase
)
138 DECLARE_NO_COPY_CLASS(wxPrinterBase
)
141 //----------------------------------------------------------------------------
143 //----------------------------------------------------------------------------
145 class WXDLLEXPORT wxPrinter
: public wxPrinterBase
148 wxPrinter(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
149 virtual ~wxPrinter();
151 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
152 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
154 virtual bool Setup(wxWindow
*parent
);
155 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true);
156 virtual wxDC
* PrintDialog(wxWindow
*parent
);
159 wxPrinterBase
*m_pimpl
;
162 DECLARE_CLASS(wxPrinter
)
163 DECLARE_NO_COPY_CLASS(wxPrinter
)
166 //----------------------------------------------------------------------------
168 //----------------------------------------------------------------------------
171 * Represents an object via which a document may be printed.
172 * The programmer derives from this, overrides (at least) OnPrintPage,
173 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
174 * object for previewing.
177 class WXDLLEXPORT wxPrintout
: public wxObject
180 wxPrintout(const wxString
& title
= wxT("Printout"));
181 virtual ~wxPrintout();
183 virtual bool OnBeginDocument(int startPage
, int endPage
);
184 virtual void OnEndDocument();
185 virtual void OnBeginPrinting();
186 virtual void OnEndPrinting();
188 // Guaranteed to be before any other functions are called
189 virtual void OnPreparePrinting() { }
191 virtual bool HasPage(int page
);
192 virtual bool OnPrintPage(int page
) = 0;
193 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
195 virtual wxString
GetTitle() const { return m_printoutTitle
; }
197 wxDC
*GetDC() const { return m_printoutDC
; }
198 void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
199 void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
200 void GetPageSizePixels(int *w
, int *h
) const { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
201 void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
202 void GetPageSizeMM(int *w
, int *h
) const { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
204 void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
205 void GetPPIScreen(int *x
, int *y
) const { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
206 void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
207 void GetPPIPrinter(int *x
, int *y
) const { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
209 virtual bool IsPreview() const { return m_isPreview
; }
211 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
214 wxString m_printoutTitle
;
217 int m_pageWidthPixels
;
218 int m_pageHeightPixels
;
231 DECLARE_ABSTRACT_CLASS(wxPrintout
)
232 DECLARE_NO_COPY_CLASS(wxPrintout
)
237 * Canvas upon which a preview is drawn.
240 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
243 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
245 const wxPoint
& pos
= wxDefaultPosition
,
246 const wxSize
& size
= wxDefaultSize
,
248 const wxString
& name
= wxT("canvas"));
251 void OnPaint(wxPaintEvent
& event
);
252 void OnChar(wxKeyEvent
&event
);
254 // Responds to colour changes
255 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
258 wxPrintPreviewBase
* m_printPreview
;
260 DECLARE_CLASS(wxPreviewCanvas
)
261 DECLARE_EVENT_TABLE()
262 DECLARE_NO_COPY_CLASS(wxPreviewCanvas
)
267 * Default frame for showing preview.
270 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
273 wxPreviewFrame(wxPrintPreviewBase
*preview
,
275 const wxString
& title
= wxT("Print Preview"),
276 const wxPoint
& pos
= wxDefaultPosition
,
277 const wxSize
& size
= wxDefaultSize
,
278 long style
= wxDEFAULT_FRAME_STYLE
,
279 const wxString
& name
= wxT("frame"));
282 void OnCloseWindow(wxCloseEvent
& event
);
283 virtual void Initialize();
284 virtual void CreateCanvas();
285 virtual void CreateControlBar();
287 inline wxPreviewControlBar
* GetControlBar() const { return m_controlBar
; }
290 wxPreviewCanvas
* m_previewCanvas
;
291 wxPreviewControlBar
* m_controlBar
;
292 wxPrintPreviewBase
* m_printPreview
;
293 wxWindowDisabler
* m_windowDisabler
;
296 DECLARE_CLASS(wxPreviewFrame
)
297 DECLARE_EVENT_TABLE()
298 DECLARE_NO_COPY_CLASS(wxPreviewFrame
)
302 * wxPreviewControlBar
303 * A panel with buttons for controlling a print preview.
304 * The programmer may wish to use other means for controlling
308 #define wxPREVIEW_PRINT 1
309 #define wxPREVIEW_PREVIOUS 2
310 #define wxPREVIEW_NEXT 4
311 #define wxPREVIEW_ZOOM 8
312 #define wxPREVIEW_FIRST 16
313 #define wxPREVIEW_LAST 32
314 #define wxPREVIEW_GOTO 64
316 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
317 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST
320 #define wxID_PREVIEW_CLOSE 1
321 #define wxID_PREVIEW_NEXT 2
322 #define wxID_PREVIEW_PREVIOUS 3
323 #define wxID_PREVIEW_PRINT 4
324 #define wxID_PREVIEW_ZOOM 5
325 #define wxID_PREVIEW_FIRST 6
326 #define wxID_PREVIEW_LAST 7
327 #define wxID_PREVIEW_GOTO 8
329 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
331 DECLARE_CLASS(wxPreviewControlBar
)
334 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
337 const wxPoint
& pos
= wxDefaultPosition
,
338 const wxSize
& size
= wxDefaultSize
,
339 long style
= wxTAB_TRAVERSAL
,
340 const wxString
& name
= wxT("panel"));
341 ~wxPreviewControlBar();
343 virtual void CreateButtons();
344 virtual void SetZoomControl(int zoom
);
345 virtual int GetZoomControl();
346 virtual wxPrintPreviewBase
*GetPrintPreview() const
347 { return m_printPreview
; }
349 void OnWindowClose(wxCommandEvent
& event
);
356 void OnPrintButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrint(); }
357 void OnNextButton(wxCommandEvent
& WXUNUSED(event
)) { OnNext(); }
358 void OnPreviousButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrevious(); }
359 void OnFirstButton(wxCommandEvent
& WXUNUSED(event
)) { OnFirst(); }
360 void OnLastButton(wxCommandEvent
& WXUNUSED(event
)) { OnLast(); }
361 void OnGotoButton(wxCommandEvent
& WXUNUSED(event
)) { OnGoto(); }
362 void OnZoom(wxCommandEvent
& event
);
363 void OnPaint(wxPaintEvent
& event
);
366 wxPrintPreviewBase
* m_printPreview
;
367 wxButton
* m_closeButton
;
368 wxButton
* m_nextPageButton
;
369 wxButton
* m_previousPageButton
;
370 wxButton
* m_printButton
;
371 wxChoice
* m_zoomControl
;
372 wxButton
* m_firstPageButton
;
373 wxButton
* m_lastPageButton
;
374 wxButton
* m_gotoPageButton
;
378 DECLARE_EVENT_TABLE()
379 DECLARE_NO_COPY_CLASS(wxPreviewControlBar
)
382 //----------------------------------------------------------------------------
383 // wxPrintPreviewBase
384 //----------------------------------------------------------------------------
387 * Programmer creates an object of this class to preview a wxPrintout.
390 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
393 wxPrintPreviewBase(wxPrintout
*printout
,
394 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
395 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
396 wxPrintPreviewBase(wxPrintout
*printout
,
397 wxPrintout
*printoutForPrinting
,
399 virtual ~wxPrintPreviewBase();
401 virtual bool SetCurrentPage(int pageNum
);
402 virtual int GetCurrentPage() const;
404 virtual void SetPrintout(wxPrintout
*printout
);
405 virtual wxPrintout
*GetPrintout() const;
406 virtual wxPrintout
*GetPrintoutForPrinting() const;
408 virtual void SetFrame(wxFrame
*frame
);
409 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
411 virtual wxFrame
*GetFrame() const;
412 virtual wxPreviewCanvas
*GetCanvas() const;
414 // The preview canvas should call this from OnPaint
415 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
417 // This draws a blank page onto the preview canvas
418 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
420 // Adjusts the scrollbars for the current scale
421 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
423 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
424 virtual bool RenderPage(int pageNum
);
427 virtual void SetZoom(int percent
);
428 virtual int GetZoom() const;
430 virtual wxPrintDialogData
& GetPrintDialogData();
432 virtual int GetMaxPage() const;
433 virtual int GetMinPage() const;
435 virtual bool Ok() const;
436 virtual void SetOk(bool ok
);
438 ///////////////////////////////////////////////////////////////////////////
441 // If we own a wxPrintout that can be used for printing, this
442 // will invoke the actual printing procedure. Called
443 // by the wxPreviewControlBar.
444 virtual bool Print(bool interactive
) = 0;
446 // Calculate scaling that needs to be done to get roughly
447 // the right scaling for the screen pretending to be
448 // the currently selected printer.
449 virtual void DetermineScaling() = 0;
452 wxPrintDialogData m_printDialogData
;
453 wxPreviewCanvas
* m_previewCanvas
;
454 wxFrame
* m_previewFrame
;
455 wxBitmap
* m_previewBitmap
;
456 wxPrintout
* m_previewPrintout
;
457 wxPrintout
* m_printPrintout
;
460 float m_previewScale
;
469 bool m_printingPrepared
; // Called OnPreparePrinting?
472 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
474 DECLARE_NO_COPY_CLASS(wxPrintPreviewBase
)
475 DECLARE_CLASS(wxPrintPreviewBase
)
478 //----------------------------------------------------------------------------
480 //----------------------------------------------------------------------------
482 class WXDLLEXPORT wxPrintPreview
: public wxPrintPreviewBase
485 wxPrintPreview(wxPrintout
*printout
,
486 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
487 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
488 wxPrintPreview(wxPrintout
*printout
,
489 wxPrintout
*printoutForPrinting
,
491 virtual ~wxPrintPreview();
493 virtual bool SetCurrentPage(int pageNum
);
494 virtual int GetCurrentPage() const;
495 virtual void SetPrintout(wxPrintout
*printout
);
496 virtual wxPrintout
*GetPrintout() const;
497 virtual wxPrintout
*GetPrintoutForPrinting() const;
498 virtual void SetFrame(wxFrame
*frame
);
499 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
501 virtual wxFrame
*GetFrame() const;
502 virtual wxPreviewCanvas
*GetCanvas() const;
503 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
504 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
505 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
506 virtual bool RenderPage(int pageNum
);
507 virtual void SetZoom(int percent
);
509 virtual bool Print(bool interactive
);
510 virtual void DetermineScaling();
512 virtual wxPrintDialogData
& GetPrintDialogData();
514 virtual int GetMaxPage() const;
515 virtual int GetMinPage() const;
517 virtual bool Ok() const;
518 virtual void SetOk(bool ok
);
521 wxPrintPreviewBase
*m_pimpl
;
524 DECLARE_CLASS(wxPrintPreview
)
525 DECLARE_NO_COPY_CLASS(wxPrintPreview
)
528 //----------------------------------------------------------------------------
529 // wxPrintAbortDialog
530 //----------------------------------------------------------------------------
532 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
535 wxPrintAbortDialog(wxWindow
*parent
,
536 const wxString
& title
,
537 const wxPoint
& pos
= wxDefaultPosition
,
538 const wxSize
& size
= wxDefaultSize
,
540 const wxString
& name
= wxT("dialog"))
541 : wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
545 void OnCancel(wxCommandEvent
& event
);
548 DECLARE_EVENT_TABLE()
549 DECLARE_NO_COPY_CLASS(wxPrintAbortDialog
)
552 #endif // wxUSE_PRINTING_ARCHITECTURE