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
;
44 wxPRINTER_NO_ERROR
= 0,
51 * Represents the printer: manages printing a wxPrintout object
54 class WXDLLEXPORT wxPrinterBase
: public wxObject
57 wxPrinterBase(wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
58 virtual ~wxPrinterBase();
60 virtual wxWindow
*CreateAbortWindow(wxWindow
*parent
, wxPrintout
*printout
);
61 virtual void ReportError(wxWindow
*parent
, wxPrintout
*printout
, const wxString
& message
);
63 wxPrintDialogData
& GetPrintDialogData() const
64 { return (wxPrintDialogData
&) m_printDialogData
; }
65 bool GetAbort() const { return sm_abortIt
; }
67 static wxPrinterError
GetLastError() { return sm_lastError
; }
69 ///////////////////////////////////////////////////////////////////////////
72 virtual bool Setup(wxWindow
*parent
) = 0;
73 virtual bool Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
= TRUE
) = 0;
74 virtual wxDC
* PrintDialog(wxWindow
*parent
) = 0;
77 wxPrintDialogData m_printDialogData
;
78 wxPrintout
* m_currentPrintout
;
80 static wxPrinterError sm_lastError
;
83 static wxWindow
* sm_abortWindow
;
84 static bool sm_abortIt
;
87 DECLARE_CLASS(wxPrinterBase
)
88 DECLARE_NO_COPY_CLASS(wxPrinterBase
)
93 * Represents an object via which a document may be printed.
94 * The programmer derives from this, overrides (at least) OnPrintPage,
95 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
96 * object for previewing.
99 class WXDLLEXPORT wxPrintout
: public wxObject
102 wxPrintout(const wxString
& title
= wxT("Printout"));
103 virtual ~wxPrintout();
105 virtual bool OnBeginDocument(int startPage
, int endPage
);
106 virtual void OnEndDocument();
107 virtual void OnBeginPrinting();
108 virtual void OnEndPrinting();
110 // Guaranteed to be before any other functions are called
111 virtual void OnPreparePrinting() { }
113 virtual bool HasPage(int page
);
114 virtual bool OnPrintPage(int page
) = 0;
115 virtual void GetPageInfo(int *minPage
, int *maxPage
, int *pageFrom
, int *pageTo
);
117 virtual wxString
GetTitle() const { return m_printoutTitle
; }
119 wxDC
*GetDC() const { return m_printoutDC
; }
120 void SetDC(wxDC
*dc
) { m_printoutDC
= dc
; }
121 void SetPageSizePixels(int w
, int h
) { m_pageWidthPixels
= w
; m_pageHeightPixels
= h
; }
122 void GetPageSizePixels(int *w
, int *h
) const { *w
= m_pageWidthPixels
; *h
= m_pageHeightPixels
; }
123 void SetPageSizeMM(int w
, int h
) { m_pageWidthMM
= w
; m_pageHeightMM
= h
; }
124 void GetPageSizeMM(int *w
, int *h
) const { *w
= m_pageWidthMM
; *h
= m_pageHeightMM
; }
126 void SetPPIScreen(int x
, int y
) { m_PPIScreenX
= x
; m_PPIScreenY
= y
; }
127 void GetPPIScreen(int *x
, int *y
) const { *x
= m_PPIScreenX
; *y
= m_PPIScreenY
; }
128 void SetPPIPrinter(int x
, int y
) { m_PPIPrinterX
= x
; m_PPIPrinterY
= y
; }
129 void GetPPIPrinter(int *x
, int *y
) const { *x
= m_PPIPrinterX
; *y
= m_PPIPrinterY
; }
131 virtual bool IsPreview() const { return m_isPreview
; }
133 virtual void SetIsPreview(bool p
) { m_isPreview
= p
; }
136 wxString m_printoutTitle
;
139 int m_pageWidthPixels
;
140 int m_pageHeightPixels
;
153 DECLARE_ABSTRACT_CLASS(wxPrintout
)
154 DECLARE_NO_COPY_CLASS(wxPrintout
)
159 * Canvas upon which a preview is drawn.
162 class WXDLLEXPORT wxPreviewCanvas
: public wxScrolledWindow
165 wxPreviewCanvas(wxPrintPreviewBase
*preview
,
167 const wxPoint
& pos
= wxDefaultPosition
,
168 const wxSize
& size
= wxDefaultSize
,
170 const wxString
& name
= wxT("canvas"));
173 void OnPaint(wxPaintEvent
& event
);
174 void OnChar(wxKeyEvent
&event
);
176 // Responds to colour changes
177 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
180 wxPrintPreviewBase
* m_printPreview
;
182 DECLARE_CLASS(wxPreviewCanvas
)
183 DECLARE_EVENT_TABLE()
184 DECLARE_NO_COPY_CLASS(wxPreviewCanvas
)
189 * Default frame for showing preview.
192 class WXDLLEXPORT wxPreviewFrame
: public wxFrame
195 wxPreviewFrame(wxPrintPreviewBase
*preview
,
197 const wxString
& title
= wxT("Print Preview"),
198 const wxPoint
& pos
= wxDefaultPosition
,
199 const wxSize
& size
= wxDefaultSize
,
200 long style
= wxDEFAULT_FRAME_STYLE
,
201 const wxString
& name
= wxT("frame"));
204 void OnCloseWindow(wxCloseEvent
& event
);
205 virtual void Initialize();
206 virtual void CreateCanvas();
207 virtual void CreateControlBar();
209 inline wxPreviewControlBar
* GetControlBar() const { return m_controlBar
; }
212 wxPreviewCanvas
* m_previewCanvas
;
213 wxPreviewControlBar
* m_controlBar
;
214 wxPrintPreviewBase
* m_printPreview
;
215 wxWindowDisabler
* m_windowDisabler
;
218 DECLARE_CLASS(wxPreviewFrame
)
219 DECLARE_EVENT_TABLE()
220 DECLARE_NO_COPY_CLASS(wxPreviewFrame
)
224 * wxPreviewControlBar
225 * A panel with buttons for controlling a print preview.
226 * The programmer may wish to use other means for controlling
230 #define wxPREVIEW_PRINT 1
231 #define wxPREVIEW_PREVIOUS 2
232 #define wxPREVIEW_NEXT 4
233 #define wxPREVIEW_ZOOM 8
234 #define wxPREVIEW_FIRST 16
235 #define wxPREVIEW_LAST 32
236 #define wxPREVIEW_GOTO 64
238 #define wxPREVIEW_DEFAULT wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
239 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST
242 #define wxID_PREVIEW_CLOSE 1
243 #define wxID_PREVIEW_NEXT 2
244 #define wxID_PREVIEW_PREVIOUS 3
245 #define wxID_PREVIEW_PRINT 4
246 #define wxID_PREVIEW_ZOOM 5
247 #define wxID_PREVIEW_FIRST 6
248 #define wxID_PREVIEW_LAST 7
249 #define wxID_PREVIEW_GOTO 8
251 class WXDLLEXPORT wxPreviewControlBar
: public wxPanel
253 DECLARE_CLASS(wxPreviewControlBar
)
256 wxPreviewControlBar(wxPrintPreviewBase
*preview
,
259 const wxPoint
& pos
= wxDefaultPosition
,
260 const wxSize
& size
= wxDefaultSize
,
261 long style
= wxTAB_TRAVERSAL
,
262 const wxString
& name
= wxT("panel"));
263 ~wxPreviewControlBar();
265 virtual void CreateButtons();
266 virtual void SetZoomControl(int zoom
);
267 virtual int GetZoomControl();
268 virtual wxPrintPreviewBase
*GetPrintPreview() const
269 { return m_printPreview
; }
271 void OnWindowClose(wxCommandEvent
& event
);
278 void OnPrintButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrint(); }
279 void OnNextButton(wxCommandEvent
& WXUNUSED(event
)) { OnNext(); }
280 void OnPreviousButton(wxCommandEvent
& WXUNUSED(event
)) { OnPrevious(); }
281 void OnFirstButton(wxCommandEvent
& WXUNUSED(event
)) { OnFirst(); }
282 void OnLastButton(wxCommandEvent
& WXUNUSED(event
)) { OnLast(); }
283 void OnGotoButton(wxCommandEvent
& WXUNUSED(event
)) { OnGoto(); }
284 void OnZoom(wxCommandEvent
& event
);
285 void OnPaint(wxPaintEvent
& event
);
288 wxPrintPreviewBase
* m_printPreview
;
289 wxButton
* m_closeButton
;
290 wxButton
* m_nextPageButton
;
291 wxButton
* m_previousPageButton
;
292 wxButton
* m_printButton
;
293 wxChoice
* m_zoomControl
;
294 wxButton
* m_firstPageButton
;
295 wxButton
* m_lastPageButton
;
296 wxButton
* m_gotoPageButton
;
300 DECLARE_EVENT_TABLE()
301 DECLARE_NO_COPY_CLASS(wxPreviewControlBar
)
306 * Programmer creates an object of this class to preview a wxPrintout.
309 class WXDLLEXPORT wxPrintPreviewBase
: public wxObject
311 DECLARE_CLASS(wxPrintPreviewBase
)
314 wxPrintPreviewBase(wxPrintout
*printout
,
315 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
316 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
317 wxPrintPreviewBase(wxPrintout
*printout
,
318 wxPrintout
*printoutForPrinting
,
320 virtual ~wxPrintPreviewBase();
322 virtual bool SetCurrentPage(int pageNum
);
323 int GetCurrentPage() const { return m_currentPage
; };
325 void SetPrintout(wxPrintout
*printout
) { m_previewPrintout
= printout
; };
326 wxPrintout
*GetPrintout() const { return m_previewPrintout
; };
327 wxPrintout
*GetPrintoutForPrinting() const { return m_printPrintout
; };
329 void SetFrame(wxFrame
*frame
) { m_previewFrame
= frame
; };
330 void SetCanvas(wxPreviewCanvas
*canvas
) { m_previewCanvas
= canvas
; };
332 virtual wxFrame
*GetFrame() const { return m_previewFrame
; }
333 virtual wxPreviewCanvas
*GetCanvas() const { return m_previewCanvas
; }
335 // The preview canvas should call this from OnPaint
336 virtual bool PaintPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
338 // This draws a blank page onto the preview canvas
339 virtual bool DrawBlankPage(wxPreviewCanvas
*canvas
, wxDC
& dc
);
341 // Adjusts the scrollbars for the current scale
342 virtual void AdjustScrollbars(wxPreviewCanvas
*canvas
);
344 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
345 virtual bool RenderPage(int pageNum
);
347 wxPrintDialogData
& GetPrintDialogData() { return m_printDialogData
; }
349 virtual void SetZoom(int percent
);
350 int GetZoom() const { return m_currentZoom
; };
352 int GetMaxPage() const { return m_maxPage
; }
353 int GetMinPage() const { return m_minPage
; }
355 bool Ok() const { return m_isOk
; }
356 void SetOk(bool ok
) { m_isOk
= ok
; }
358 ///////////////////////////////////////////////////////////////////////////
361 // If we own a wxPrintout that can be used for printing, this
362 // will invoke the actual printing procedure. Called
363 // by the wxPreviewControlBar.
364 virtual bool Print(bool interactive
) = 0;
366 // Calculate scaling that needs to be done to get roughly
367 // the right scaling for the screen pretending to be
368 // the currently selected printer.
369 virtual void DetermineScaling() = 0;
372 wxPrintDialogData m_printDialogData
;
373 wxPreviewCanvas
* m_previewCanvas
;
374 wxFrame
* m_previewFrame
;
375 wxBitmap
* m_previewBitmap
;
376 wxPrintout
* m_previewPrintout
;
377 wxPrintout
* m_printPrintout
;
380 float m_previewScale
;
389 bool m_printingPrepared
; // Called OnPreparePrinting?
392 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
394 DECLARE_NO_COPY_CLASS(wxPrintPreviewBase
)
401 class WXDLLEXPORT wxPrintAbortDialog
: public wxDialog
404 wxPrintAbortDialog(wxWindow
*parent
,
405 const wxString
& title
,
406 const wxPoint
& pos
= wxDefaultPosition
,
407 const wxSize
& size
= wxDefaultSize
,
409 const wxString
& name
= wxT("dialog"))
410 : wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
414 void OnCancel(wxCommandEvent
& event
);
417 DECLARE_EVENT_TABLE()
418 DECLARE_NO_COPY_CLASS(wxPrintAbortDialog
)
421 #endif // wxUSE_PRINTING_ARCHITECTURE