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
;
43 //----------------------------------------------------------------------------
45 //----------------------------------------------------------------------------
49 wxPRINTER_NO_ERROR
= 0,
54 //----------------------------------------------------------------------------
56 //----------------------------------------------------------------------------
58 class WXDLLEXPORT wxPrintFactory
62 virtual ~wxPrintFactory() {}
64 virtual bool HasPageSetupDialog() = 0;
65 virtual bool HasPrintSetupDialog() = 0;
67 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
* data
) = 0;
69 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
70 wxPrintout
*printout
= NULL
,
71 wxPrintDialogData
*data
= NULL
) = 0;
72 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
74 wxPrintData
*data
) = 0;
76 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
77 wxPrintDialogData
*data
= NULL
) = 0;
78 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
79 wxPrintData
*data
) = 0;
81 static void SetPrintFactory( wxPrintFactory
*factory
);
82 static wxPrintFactory
*GetFactory();
83 static wxPrintFactory
*m_factory
;
86 class WXDLLEXPORT wxNativePrintFactory
: public wxPrintFactory
89 virtual bool HasPageSetupDialog()
91 virtual bool HasPrintSetupDialog()
94 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
96 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
97 wxPrintout
*printout
= NULL
,
98 wxPrintDialogData
*data
= NULL
);
99 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
100 wxPrintout
*printout
,
103 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
104 wxPrintDialogData
*data
= NULL
);
105 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
109 //----------------------------------------------------------------------------
111 //----------------------------------------------------------------------------
114 * Represents the printer: manages printing a wxPrintout object
117 class WXDLLEXPORT wxPrinterBase
: public wxObject
120 wxPrinterBase(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
121 virtual ~wxPrinterBase();
123 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
124 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
126 virtual wxPrintDialogData
& GetPrintDialogData() const;
127 bool GetAbort() const { return sm_abortIt
; }
129 static wxPrinterError
GetLastError() { return sm_lastError
; }
131 ///////////////////////////////////////////////////////////////////////////
134 virtual bool Setup(wxWindow
*parent
) = 0;
135 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true) = 0;
136 virtual wxDC
* PrintDialog(wxWindow
*parent
) = 0;
139 wxPrintDialogData m_printDialogData
;
140 wxPrintout
* m_currentPrintout
;
142 static wxPrinterError sm_lastError
;
145 static wxWindow
* sm_abortWindow
;
146 static bool sm_abortIt
;
149 DECLARE_CLASS(wxPrinterBase
)
150 DECLARE_NO_COPY_CLASS(wxPrinterBase
)
153 //----------------------------------------------------------------------------
155 //----------------------------------------------------------------------------
157 class WXDLLEXPORT wxPrinter
: public wxPrinterBase
160 wxPrinter(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
161 virtual ~wxPrinter();
163 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
164 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
166 virtual bool Setup(wxWindow
*parent
);
167 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= true);
168 virtual wxDC
* PrintDialog(wxWindow
*parent
);
170 virtual wxPrintDialogData
& GetPrintDialogData() const;
173 wxPrinterBase
*m_pimpl
;
176 DECLARE_CLASS(wxPrinter
)
177 DECLARE_NO_COPY_CLASS(wxPrinter
)
180 //----------------------------------------------------------------------------
182 //----------------------------------------------------------------------------
185 * Represents an object via which a document may be printed.
186 * The programmer derives from this, overrides (at least) OnPrintPage,
187 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
188 * object for previewing.
191 class WXDLLEXPORT wxPrintout
: public wxObject
194 wxPrintout(const wxString
& title
= wxT("Printout"));
195 virtual ~wxPrintout();
197 virtual bool OnBeginDocument(int startPage
, int endPage
);
198 virtual void OnEndDocument();
199 virtual void OnBeginPrinting();
200 virtual void OnEndPrinting();
202 // Guaranteed to be before any other functions are called
203 virtual void OnPreparePrinting() { }
205 virtual bool HasPage(int page
);
206 virtual bool OnPrintPage(int page
) = 0;
207 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
209 virtual wxString
GetTitle() const { return m_printoutTitle
; }
211 wxDC
*GetDC() const { return m_printoutDC
; }
212 void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
213 void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
214 void GetPageSizePixels(int *w
, int *h
) const { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
215 void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
216 void GetPageSizeMM(int *w
, int *h
) const { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
218 void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
219 void GetPPIScreen(int *x
, int *y
) const { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
220 void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
221 void GetPPIPrinter(int *x
, int *y
) const { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
223 virtual bool IsPreview() const { return m_isPreview
; }
225 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
228 wxString m_printoutTitle
;
231 int m_pageWidthPixels
;
232 int m_pageHeightPixels
;
245 DECLARE_ABSTRACT_CLASS(wxPrintout
)
246 DECLARE_NO_COPY_CLASS(wxPrintout
)
251 * Canvas upon which a preview is drawn.
254 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
257 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
259 const wxPoint
& pos
= wxDefaultPosition
,
260 const wxSize
& size
= wxDefaultSize
,
262 const wxString
& name
= wxT("canvas"));
265 void OnPaint(wxPaintEvent
& event
);
266 void OnChar(wxKeyEvent
&event
);
268 // Responds to colour changes
269 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
272 wxPrintPreviewBase
* m_printPreview
;
274 DECLARE_CLASS(wxPreviewCanvas
)
275 DECLARE_EVENT_TABLE()
276 DECLARE_NO_COPY_CLASS(wxPreviewCanvas
)
281 * Default frame for showing preview.
284 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
287 wxPreviewFrame(wxPrintPreviewBase
*preview
,
289 const wxString
& title
= wxT("Print Preview"),
290 const wxPoint
& pos
= wxDefaultPosition
,
291 const wxSize
& size
= wxDefaultSize
,
292 long style
= wxDEFAULT_FRAME_STYLE
,
293 const wxString
& name
= wxT("frame"));
296 void OnCloseWindow(wxCloseEvent
& event
);
297 virtual void Initialize();
298 virtual void CreateCanvas();
299 virtual void CreateControlBar();
301 inline wxPreviewControlBar
* GetControlBar() const { return m_controlBar
; }
304 wxPreviewCanvas
* m_previewCanvas
;
305 wxPreviewControlBar
* m_controlBar
;
306 wxPrintPreviewBase
* m_printPreview
;
307 wxWindowDisabler
* m_windowDisabler
;
310 DECLARE_CLASS(wxPreviewFrame
)
311 DECLARE_EVENT_TABLE()
312 DECLARE_NO_COPY_CLASS(wxPreviewFrame
)
316 * wxPreviewControlBar
317 * A panel with buttons for controlling a print preview.
318 * The programmer may wish to use other means for controlling
322 #define wxPREVIEW_PRINT 1
323 #define wxPREVIEW_PREVIOUS 2
324 #define wxPREVIEW_NEXT 4
325 #define wxPREVIEW_ZOOM 8
326 #define wxPREVIEW_FIRST 16
327 #define wxPREVIEW_LAST 32
328 #define wxPREVIEW_GOTO 64
330 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
331 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST
334 #define wxID_PREVIEW_CLOSE 1
335 #define wxID_PREVIEW_NEXT 2
336 #define wxID_PREVIEW_PREVIOUS 3
337 #define wxID_PREVIEW_PRINT 4
338 #define wxID_PREVIEW_ZOOM 5
339 #define wxID_PREVIEW_FIRST 6
340 #define wxID_PREVIEW_LAST 7
341 #define wxID_PREVIEW_GOTO 8
343 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
345 DECLARE_CLASS(wxPreviewControlBar
)
348 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
351 const wxPoint
& pos
= wxDefaultPosition
,
352 const wxSize
& size
= wxDefaultSize
,
353 long style
= wxTAB_TRAVERSAL
,
354 const wxString
& name
= wxT("panel"));
355 ~wxPreviewControlBar();
357 virtual void CreateButtons();
358 virtual void SetZoomControl(int zoom
);
359 virtual int GetZoomControl();
360 virtual wxPrintPreviewBase
*GetPrintPreview() const
361 { return m_printPreview
; }
363 void OnWindowClose(wxCommandEvent
& event
);
370 void OnPrintButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrint(); }
371 void OnNextButton(wxCommandEvent
& WXUNUSED(event
)) { OnNext(); }
372 void OnPreviousButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrevious(); }
373 void OnFirstButton(wxCommandEvent
& WXUNUSED(event
)) { OnFirst(); }
374 void OnLastButton(wxCommandEvent
& WXUNUSED(event
)) { OnLast(); }
375 void OnGotoButton(wxCommandEvent
& WXUNUSED(event
)) { OnGoto(); }
376 void OnZoom(wxCommandEvent
& event
);
377 void OnPaint(wxPaintEvent
& event
);
380 wxPrintPreviewBase
* m_printPreview
;
381 wxButton
* m_closeButton
;
382 wxButton
* m_nextPageButton
;
383 wxButton
* m_previousPageButton
;
384 wxButton
* m_printButton
;
385 wxChoice
* m_zoomControl
;
386 wxButton
* m_firstPageButton
;
387 wxButton
* m_lastPageButton
;
388 wxButton
* m_gotoPageButton
;
392 DECLARE_EVENT_TABLE()
393 DECLARE_NO_COPY_CLASS(wxPreviewControlBar
)
396 //----------------------------------------------------------------------------
397 // wxPrintPreviewBase
398 //----------------------------------------------------------------------------
401 * Programmer creates an object of this class to preview a wxPrintout.
404 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
407 wxPrintPreviewBase(wxPrintout
*printout
,
408 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
409 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
410 wxPrintPreviewBase(wxPrintout
*printout
,
411 wxPrintout
*printoutForPrinting
,
413 virtual ~wxPrintPreviewBase();
415 virtual bool SetCurrentPage(int pageNum
);
416 virtual int GetCurrentPage() const;
418 virtual void SetPrintout(wxPrintout
*printout
);
419 virtual wxPrintout
*GetPrintout() const;
420 virtual wxPrintout
*GetPrintoutForPrinting() const;
422 virtual void SetFrame(wxFrame
*frame
);
423 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
425 virtual wxFrame
*GetFrame() const;
426 virtual wxPreviewCanvas
*GetCanvas() const;
428 // The preview canvas should call this from OnPaint
429 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
431 // This draws a blank page onto the preview canvas
432 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
434 // Adjusts the scrollbars for the current scale
435 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
437 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
438 virtual bool RenderPage(int pageNum
);
441 virtual void SetZoom(int percent
);
442 virtual int GetZoom() const;
444 virtual wxPrintDialogData
& GetPrintDialogData();
446 virtual int GetMaxPage() const;
447 virtual int GetMinPage() const;
449 virtual bool Ok() const;
450 virtual void SetOk(bool ok
);
452 ///////////////////////////////////////////////////////////////////////////
455 // If we own a wxPrintout that can be used for printing, this
456 // will invoke the actual printing procedure. Called
457 // by the wxPreviewControlBar.
458 virtual bool Print(bool interactive
) = 0;
460 // Calculate scaling that needs to be done to get roughly
461 // the right scaling for the screen pretending to be
462 // the currently selected printer.
463 virtual void DetermineScaling() = 0;
466 wxPrintDialogData m_printDialogData
;
467 wxPreviewCanvas
* m_previewCanvas
;
468 wxFrame
* m_previewFrame
;
469 wxBitmap
* m_previewBitmap
;
470 wxPrintout
* m_previewPrintout
;
471 wxPrintout
* m_printPrintout
;
474 float m_previewScale
;
483 bool m_printingPrepared
; // Called OnPreparePrinting?
486 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
488 DECLARE_NO_COPY_CLASS(wxPrintPreviewBase
)
489 DECLARE_CLASS(wxPrintPreviewBase
)
492 //----------------------------------------------------------------------------
494 //----------------------------------------------------------------------------
496 class WXDLLEXPORT wxPrintPreview
: public wxPrintPreviewBase
499 wxPrintPreview(wxPrintout
*printout
,
500 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
501 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
502 wxPrintPreview(wxPrintout
*printout
,
503 wxPrintout
*printoutForPrinting
,
505 virtual ~wxPrintPreview();
507 virtual bool SetCurrentPage(int pageNum
);
508 virtual int GetCurrentPage() const;
509 virtual void SetPrintout(wxPrintout
*printout
);
510 virtual wxPrintout
*GetPrintout() const;
511 virtual wxPrintout
*GetPrintoutForPrinting() const;
512 virtual void SetFrame(wxFrame
*frame
);
513 virtual void SetCanvas(wxPreviewCanvas
*canvas
);
515 virtual wxFrame
*GetFrame() const;
516 virtual wxPreviewCanvas
*GetCanvas() const;
517 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
518 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
519 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
520 virtual bool RenderPage(int pageNum
);
521 virtual void SetZoom(int percent
);
523 virtual bool Print(bool interactive
);
524 virtual void DetermineScaling();
526 virtual wxPrintDialogData
& GetPrintDialogData();
528 virtual int GetMaxPage() const;
529 virtual int GetMinPage() const;
531 virtual bool Ok() const;
532 virtual void SetOk(bool ok
);
535 wxPrintPreviewBase
*m_pimpl
;
538 DECLARE_CLASS(wxPrintPreview
)
539 DECLARE_NO_COPY_CLASS(wxPrintPreview
)
542 //----------------------------------------------------------------------------
543 // wxPrintAbortDialog
544 //----------------------------------------------------------------------------
546 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
549 wxPrintAbortDialog(wxWindow
*parent
,
550 const wxString
& title
,
551 const wxPoint
& pos
= wxDefaultPosition
,
552 const wxSize
& size
= wxDefaultSize
,
554 const wxString
& name
= wxT("dialog"))
555 : wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
559 void OnCancel(wxCommandEvent
& event
);
562 DECLARE_EVENT_TABLE()
563 DECLARE_NO_COPY_CLASS(wxPrintAbortDialog
)
566 #endif // wxUSE_PRINTING_ARCHITECTURE