]> git.saurik.com Git - wxWidgets.git/blame - include/wx/prntbase.h
Add RunScript and implement on all backends. Document and add a very simple unit...
[wxWidgets.git] / include / wx / prntbase.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
ce7208d4 2// Name: wx/prntbase.h
c801d85f
KB
3// Purpose: Base classes for printing framework
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
371a5b4e 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_PRNTBASEH__
13#define _WX_PRNTBASEH__
c801d85f 14
c801d85f 15#include "wx/defs.h"
d427503c
VZ
16
17#if wxUSE_PRINTING_ARCHITECTURE
18
c801d85f
KB
19#include "wx/event.h"
20#include "wx/cmndata.h"
21#include "wx/panel.h"
22#include "wx/scrolwin.h"
23#include "wx/dialog.h"
34138703 24#include "wx/frame.h"
888dde65 25#include "wx/dc.h"
c801d85f 26
b5dbe15d
VS
27class WXDLLIMPEXP_FWD_CORE wxDC;
28class WXDLLIMPEXP_FWD_CORE wxButton;
29class WXDLLIMPEXP_FWD_CORE wxChoice;
30class WXDLLIMPEXP_FWD_CORE wxPrintout;
31class WXDLLIMPEXP_FWD_CORE wxPrinterBase;
32class WXDLLIMPEXP_FWD_CORE wxPrintDialogBase;
33class WXDLLIMPEXP_FWD_CORE wxPrintDialog;
34class WXDLLIMPEXP_FWD_CORE wxPageSetupDialogBase;
35class WXDLLIMPEXP_FWD_CORE wxPageSetupDialog;
36class WXDLLIMPEXP_FWD_CORE wxPrintPreviewBase;
37class WXDLLIMPEXP_FWD_CORE wxPreviewCanvas;
38class WXDLLIMPEXP_FWD_CORE wxPreviewControlBar;
39class WXDLLIMPEXP_FWD_CORE wxPreviewFrame;
40class WXDLLIMPEXP_FWD_CORE wxPrintFactory;
41class WXDLLIMPEXP_FWD_CORE wxPrintNativeDataBase;
1bd122dd 42class WXDLLIMPEXP_FWD_CORE wxPrintPreview;
d7cfeeb4 43class wxPrintPageMaxCtrl;
82579461 44class wxPrintPageTextCtrl;
c801d85f 45
e81e3883
RR
46//----------------------------------------------------------------------------
47// error consts
48//----------------------------------------------------------------------------
f6bcfd97
BP
49
50enum wxPrinterError
51{
52 wxPRINTER_NO_ERROR = 0,
53 wxPRINTER_CANCELLED,
54 wxPRINTER_ERROR
55};
56
6aacfc73
VZ
57// Preview frame modality kind used with wxPreviewFrame::Initialize()
58enum wxPreviewFrameModalityKind
59{
60 // Disable all the other top level windows while the preview is shown.
61 wxPreviewFrame_AppModal,
62
63 // Disable only the parent window while the preview is shown.
64 wxPreviewFrame_WindowModal,
65
66 // Don't disable any windows.
67 wxPreviewFrame_NonModal
68};
69
e81e3883
RR
70//----------------------------------------------------------------------------
71// wxPrintFactory
72//----------------------------------------------------------------------------
73
53a2db12 74class WXDLLIMPEXP_CORE wxPrintFactory
e81e3883
RR
75{
76public:
77 wxPrintFactory() {}
78 virtual ~wxPrintFactory() {}
d0ee33f5 79
e81e3883 80 virtual wxPrinterBase *CreatePrinter( wxPrintDialogData* data ) = 0;
d0ee33f5
WS
81
82 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
83 wxPrintout *printout = NULL,
e81e3883 84 wxPrintDialogData *data = NULL ) = 0;
d0ee33f5
WS
85 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
86 wxPrintout *printout,
e81e3883 87 wxPrintData *data ) = 0;
c061373d 88
d0ee33f5 89 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
c061373d 90 wxPrintDialogData *data = NULL ) = 0;
d0ee33f5 91 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
c061373d 92 wxPrintData *data ) = 0;
d0ee33f5 93
08680429
RR
94 virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
95 wxPageSetupDialogData * data = NULL ) = 0;
d0ee33f5 96
888dde65 97 virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) = 0;
147bf263 98
6038ec8e
RR
99 // What to do and what to show in the wxPrintDialog
100 // a) Use the generic print setup dialog or a native one?
101 virtual bool HasPrintSetupDialog() = 0;
102 virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) = 0;
103 // b) Provide the "print to file" option ourselves or via print setup?
104 virtual bool HasOwnPrintToFile() = 0;
105 // c) Show current printer
106 virtual bool HasPrinterLine() = 0;
107 virtual wxString CreatePrinterLine() = 0;
108 // d) Show Status line for current printer?
109 virtual bool HasStatusLine() = 0;
110 virtual wxString CreateStatusLine() = 0;
111
d0ee33f5 112
8850cbd3 113 virtual wxPrintNativeDataBase *CreatePrintNativeData() = 0;
d0ee33f5 114
e81e3883
RR
115 static void SetPrintFactory( wxPrintFactory *factory );
116 static wxPrintFactory *GetFactory();
33d094d1 117private:
e81e3883
RR
118 static wxPrintFactory *m_factory;
119};
120
53a2db12 121class WXDLLIMPEXP_CORE wxNativePrintFactory: public wxPrintFactory
e81e3883
RR
122{
123public:
e81e3883 124 virtual wxPrinterBase *CreatePrinter( wxPrintDialogData *data );
d0ee33f5
WS
125
126 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
127 wxPrintout *printout = NULL,
e81e3883 128 wxPrintDialogData *data = NULL );
d0ee33f5 129 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
e81e3883
RR
130 wxPrintout *printout,
131 wxPrintData *data );
d0ee33f5
WS
132
133 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
c061373d 134 wxPrintDialogData *data = NULL );
d0ee33f5 135 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
c061373d 136 wxPrintData *data );
d0ee33f5 137
08680429
RR
138 virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
139 wxPageSetupDialogData * data = NULL );
d0ee33f5 140
888dde65 141 virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data );
147bf263 142
6038ec8e
RR
143 virtual bool HasPrintSetupDialog();
144 virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
145 virtual bool HasOwnPrintToFile();
146 virtual bool HasPrinterLine();
147 virtual wxString CreatePrinterLine();
148 virtual bool HasStatusLine();
149 virtual wxString CreateStatusLine();
d0ee33f5 150
8850cbd3
RR
151 virtual wxPrintNativeDataBase *CreatePrintNativeData();
152};
153
154//----------------------------------------------------------------------------
155// wxPrintNativeDataBase
156//----------------------------------------------------------------------------
157
53a2db12 158class WXDLLIMPEXP_CORE wxPrintNativeDataBase: public wxObject
8850cbd3
RR
159{
160public:
161 wxPrintNativeDataBase();
162 virtual ~wxPrintNativeDataBase() {}
d0ee33f5 163
fd64de59 164 virtual bool TransferTo( wxPrintData &data ) = 0;
d0ee33f5
WS
165 virtual bool TransferFrom( const wxPrintData &data ) = 0;
166
b7cacb43
VZ
167 virtual bool Ok() const { return IsOk(); }
168 virtual bool IsOk() const = 0;
d0ee33f5 169
8850cbd3 170 int m_ref;
d0ee33f5 171
8850cbd3
RR
172private:
173 DECLARE_CLASS(wxPrintNativeDataBase)
c0c133e1 174 wxDECLARE_NO_COPY_CLASS(wxPrintNativeDataBase);
e81e3883
RR
175};
176
177//----------------------------------------------------------------------------
178// wxPrinterBase
179//----------------------------------------------------------------------------
f6bcfd97 180
c801d85f
KB
181/*
182 * Represents the printer: manages printing a wxPrintout object
183 */
d6b9496a 184
53a2db12 185class WXDLLIMPEXP_CORE wxPrinterBase: public wxObject
c801d85f 186{
34da0970 187public:
d3b9f782 188 wxPrinterBase(wxPrintDialogData *data = NULL);
d6b9496a
VZ
189 virtual ~wxPrinterBase();
190
191 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout);
161f4f73 192 virtual void ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message);
c801d85f 193
c061373d 194 virtual wxPrintDialogData& GetPrintDialogData() const;
d6b9496a 195 bool GetAbort() const { return sm_abortIt; }
7e548f6b 196
f6bcfd97 197 static wxPrinterError GetLastError() { return sm_lastError; }
c801d85f 198
d6b9496a
VZ
199 ///////////////////////////////////////////////////////////////////////////
200 // OVERRIDES
c801d85f 201
d6b9496a 202 virtual bool Setup(wxWindow *parent) = 0;
7e548f6b 203 virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = true) = 0;
d6b9496a 204 virtual wxDC* PrintDialog(wxWindow *parent) = 0;
34da0970
JS
205
206protected:
d6b9496a
VZ
207 wxPrintDialogData m_printDialogData;
208 wxPrintout* m_currentPrintout;
7e548f6b 209
f6bcfd97 210 static wxPrinterError sm_lastError;
7e548f6b 211
34da0970 212public:
d6b9496a
VZ
213 static wxWindow* sm_abortWindow;
214 static bool sm_abortIt;
34da0970 215
2b5f62a0
VZ
216private:
217 DECLARE_CLASS(wxPrinterBase)
c0c133e1 218 wxDECLARE_NO_COPY_CLASS(wxPrinterBase);
c801d85f
KB
219};
220
e81e3883
RR
221//----------------------------------------------------------------------------
222// wxPrinter
223//----------------------------------------------------------------------------
224
53a2db12 225class WXDLLIMPEXP_CORE wxPrinter: public wxPrinterBase
e81e3883
RR
226{
227public:
d3b9f782 228 wxPrinter(wxPrintDialogData *data = NULL);
e81e3883
RR
229 virtual ~wxPrinter();
230
231 virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout);
232 virtual void ReportError(wxWindow *parent, wxPrintout *printout, const wxString& message);
233
234 virtual bool Setup(wxWindow *parent);
235 virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = true);
236 virtual wxDC* PrintDialog(wxWindow *parent);
d0ee33f5 237
c061373d 238 virtual wxPrintDialogData& GetPrintDialogData() const;
e81e3883
RR
239
240protected:
241 wxPrinterBase *m_pimpl;
d0ee33f5 242
e81e3883
RR
243private:
244 DECLARE_CLASS(wxPrinter)
c0c133e1 245 wxDECLARE_NO_COPY_CLASS(wxPrinter);
e81e3883
RR
246};
247
248//----------------------------------------------------------------------------
249// wxPrintout
250//----------------------------------------------------------------------------
251
c801d85f 252/*
c801d85f
KB
253 * Represents an object via which a document may be printed.
254 * The programmer derives from this, overrides (at least) OnPrintPage,
255 * and passes it to a wxPrinter object for printing, or a wxPrintPreview
256 * object for previewing.
257 */
d6b9496a 258
53a2db12 259class WXDLLIMPEXP_CORE wxPrintout: public wxObject
c801d85f 260{
34da0970 261public:
6c4da6d6 262 wxPrintout(const wxString& title = _("Printout"));
d6b9496a 263 virtual ~wxPrintout();
c801d85f 264
d6b9496a
VZ
265 virtual bool OnBeginDocument(int startPage, int endPage);
266 virtual void OnEndDocument();
267 virtual void OnBeginPrinting();
268 virtual void OnEndPrinting();
c801d85f 269
d6b9496a
VZ
270 // Guaranteed to be before any other functions are called
271 virtual void OnPreparePrinting() { }
c801d85f 272
d6b9496a
VZ
273 virtual bool HasPage(int page);
274 virtual bool OnPrintPage(int page) = 0;
275 virtual void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo);
c801d85f 276
d6b9496a 277 virtual wxString GetTitle() const { return m_printoutTitle; }
34da0970 278
d6b9496a
VZ
279 wxDC *GetDC() const { return m_printoutDC; }
280 void SetDC(wxDC *dc) { m_printoutDC = dc; }
f415cab9
JS
281
282 void FitThisSizeToPaper(const wxSize& imageSize);
283 void FitThisSizeToPage(const wxSize& imageSize);
284 void FitThisSizeToPageMargins(const wxSize& imageSize, const wxPageSetupDialogData& pageSetupData);
285 void MapScreenSizeToPaper();
286 void MapScreenSizeToPage();
287 void MapScreenSizeToPageMargins(const wxPageSetupDialogData& pageSetupData);
288 void MapScreenSizeToDevice();
289
290 wxRect GetLogicalPaperRect() const;
291 wxRect GetLogicalPageRect() const;
292 wxRect GetLogicalPageMarginsRect(const wxPageSetupDialogData& pageSetupData) const;
293
294 void SetLogicalOrigin(wxCoord x, wxCoord y);
295 void OffsetLogicalOrigin(wxCoord xoff, wxCoord yoff);
296
d6b9496a
VZ
297 void SetPageSizePixels(int w, int h) { m_pageWidthPixels = w; m_pageHeightPixels = h; }
298 void GetPageSizePixels(int *w, int *h) const { *w = m_pageWidthPixels; *h = m_pageHeightPixels; }
299 void SetPageSizeMM(int w, int h) { m_pageWidthMM = w; m_pageHeightMM = h; }
300 void GetPageSizeMM(int *w, int *h) const { *w = m_pageWidthMM; *h = m_pageHeightMM; }
34da0970 301
d6b9496a 302 void SetPPIScreen(int x, int y) { m_PPIScreenX = x; m_PPIScreenY = y; }
40fcf546 303 void SetPPIScreen(const wxSize& ppi) { SetPPIScreen(ppi.x, ppi.y); }
d6b9496a
VZ
304 void GetPPIScreen(int *x, int *y) const { *x = m_PPIScreenX; *y = m_PPIScreenY; }
305 void SetPPIPrinter(int x, int y) { m_PPIPrinterX = x; m_PPIPrinterY = y; }
40fcf546 306 void SetPPIPrinter(const wxSize& ppi) { SetPPIPrinter(ppi.x, ppi.y); }
d6b9496a 307 void GetPPIPrinter(int *x, int *y) const { *x = m_PPIPrinterX; *y = m_PPIPrinterY; }
34da0970 308
f415cab9
JS
309 void SetPaperRectPixels(const wxRect& paperRectPixels) { m_paperRectPixels = paperRectPixels; }
310 wxRect GetPaperRectPixels() const { return m_paperRectPixels; }
311
1bd122dd
VZ
312 // This must be called by wxPrintPreview to associate itself with the
313 // printout it uses.
314 virtual void SetPreview(wxPrintPreview *preview) { m_preview = preview; }
34da0970 315
1bd122dd
VZ
316 wxPrintPreview *GetPreview() const { return m_preview; }
317 virtual bool IsPreview() const { return GetPreview() != NULL; }
34da0970
JS
318
319private:
d6b9496a
VZ
320 wxString m_printoutTitle;
321 wxDC* m_printoutDC;
1bd122dd 322 wxPrintPreview *m_preview;
c801d85f 323
d6b9496a
VZ
324 int m_pageWidthPixels;
325 int m_pageHeightPixels;
c801d85f 326
d6b9496a
VZ
327 int m_pageWidthMM;
328 int m_pageHeightMM;
c801d85f 329
d6b9496a
VZ
330 int m_PPIScreenX;
331 int m_PPIScreenY;
332 int m_PPIPrinterX;
333 int m_PPIPrinterY;
c801d85f 334
f415cab9
JS
335 wxRect m_paperRectPixels;
336
2b5f62a0
VZ
337private:
338 DECLARE_ABSTRACT_CLASS(wxPrintout)
c0c133e1 339 wxDECLARE_NO_COPY_CLASS(wxPrintout);
c801d85f
KB
340};
341
f415cab9
JS
342//----------------------------------------------------------------------------
343// wxPreviewCanvas
344//----------------------------------------------------------------------------
345
c801d85f 346/*
c801d85f
KB
347 * Canvas upon which a preview is drawn.
348 */
d6b9496a 349
53a2db12 350class WXDLLIMPEXP_CORE wxPreviewCanvas: public wxScrolledWindow
c801d85f 351{
34da0970 352public:
d6b9496a
VZ
353 wxPreviewCanvas(wxPrintPreviewBase *preview,
354 wxWindow *parent,
355 const wxPoint& pos = wxDefaultPosition,
356 const wxSize& size = wxDefaultSize,
357 long style = 0,
2b5f62a0 358 const wxString& name = wxT("canvas"));
d3c7fc99 359 virtual ~wxPreviewCanvas();
c801d85f 360
b88bf073
VS
361 void SetPreview(wxPrintPreviewBase *preview) { m_printPreview = preview; }
362
d6b9496a 363 void OnPaint(wxPaintEvent& event);
d2b354f9 364 void OnChar(wxKeyEvent &event);
d6b9496a
VZ
365 // Responds to colour changes
366 void OnSysColourChanged(wxSysColourChangedEvent& event);
c801d85f 367
34da0970 368private:
fb6efdf2
VZ
369#if wxUSE_MOUSEWHEEL
370 void OnMouseWheel(wxMouseEvent& event);
371#endif // wxUSE_MOUSEWHEEL
b88bf073 372 void OnIdle(wxIdleEvent& event);
fb6efdf2 373
d6b9496a 374 wxPrintPreviewBase* m_printPreview;
34da0970 375
2b5f62a0 376 DECLARE_CLASS(wxPreviewCanvas)
d6b9496a 377 DECLARE_EVENT_TABLE()
c0c133e1 378 wxDECLARE_NO_COPY_CLASS(wxPreviewCanvas);
c801d85f
KB
379};
380
f415cab9
JS
381//----------------------------------------------------------------------------
382// wxPreviewFrame
383//----------------------------------------------------------------------------
384
c801d85f 385/*
c801d85f
KB
386 * Default frame for showing preview.
387 */
388
53a2db12 389class WXDLLIMPEXP_CORE wxPreviewFrame: public wxFrame
c801d85f 390{
34da0970 391public:
d6b9496a 392 wxPreviewFrame(wxPrintPreviewBase *preview,
a5ae8241 393 wxWindow *parent,
6c4da6d6 394 const wxString& title = _("Print Preview"),
d6b9496a
VZ
395 const wxPoint& pos = wxDefaultPosition,
396 const wxSize& size = wxDefaultSize,
ca44dbde 397 long style = wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT,
3366d55c 398 const wxString& name = wxFrameNameStr);
d3c7fc99 399 virtual ~wxPreviewFrame();
d6b9496a
VZ
400
401 void OnCloseWindow(wxCloseEvent& event);
6aacfc73
VZ
402 virtual void Initialize(wxPreviewFrameModalityKind kind
403 = wxPreviewFrame_AppModal);
d6b9496a
VZ
404 virtual void CreateCanvas();
405 virtual void CreateControlBar();
d2b354f9
JS
406
407 inline wxPreviewControlBar* GetControlBar() const { return m_controlBar; }
408
34da0970 409protected:
d2b354f9 410 wxPreviewCanvas* m_previewCanvas;
d6b9496a
VZ
411 wxPreviewControlBar* m_controlBar;
412 wxPrintPreviewBase* m_printPreview;
7c995553 413 wxWindowDisabler* m_windowDisabler;
e3065973 414
6aacfc73
VZ
415 wxPreviewFrameModalityKind m_modalityKind;
416
417
d6b9496a 418private:
043c6705
VZ
419 void OnChar(wxKeyEvent& event);
420
d6b9496a 421 DECLARE_EVENT_TABLE()
043c6705 422 DECLARE_CLASS(wxPreviewFrame)
c0c133e1 423 wxDECLARE_NO_COPY_CLASS(wxPreviewFrame);
c801d85f
KB
424};
425
f415cab9
JS
426//----------------------------------------------------------------------------
427// wxPreviewControlBar
428//----------------------------------------------------------------------------
429
c801d85f 430/*
c801d85f
KB
431 * A panel with buttons for controlling a print preview.
432 * The programmer may wish to use other means for controlling
433 * the print preview.
434 */
435
436#define wxPREVIEW_PRINT 1
437#define wxPREVIEW_PREVIOUS 2
438#define wxPREVIEW_NEXT 4
439#define wxPREVIEW_ZOOM 8
bf89b538
JS
440#define wxPREVIEW_FIRST 16
441#define wxPREVIEW_LAST 32
442#define wxPREVIEW_GOTO 64
c801d85f 443
d0ee33f5
WS
444#define wxPREVIEW_DEFAULT (wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
445 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST)
c801d85f
KB
446
447// Ids for controls
448#define wxID_PREVIEW_CLOSE 1
449#define wxID_PREVIEW_NEXT 2
450#define wxID_PREVIEW_PREVIOUS 3
451#define wxID_PREVIEW_PRINT 4
452#define wxID_PREVIEW_ZOOM 5
bf89b538
JS
453#define wxID_PREVIEW_FIRST 6
454#define wxID_PREVIEW_LAST 7
455#define wxID_PREVIEW_GOTO 8
82579461
VZ
456#define wxID_PREVIEW_ZOOM_IN 9
457#define wxID_PREVIEW_ZOOM_OUT 10
c801d85f 458
53a2db12 459class WXDLLIMPEXP_CORE wxPreviewControlBar: public wxPanel
c801d85f 460{
d6b9496a 461 DECLARE_CLASS(wxPreviewControlBar)
c801d85f 462
34da0970 463public:
d6b9496a
VZ
464 wxPreviewControlBar(wxPrintPreviewBase *preview,
465 long buttons,
466 wxWindow *parent,
467 const wxPoint& pos = wxDefaultPosition,
468 const wxSize& size = wxDefaultSize,
d2b354f9 469 long style = wxTAB_TRAVERSAL,
2b5f62a0 470 const wxString& name = wxT("panel"));
d3c7fc99 471 virtual ~wxPreviewControlBar();
d6b9496a
VZ
472
473 virtual void CreateButtons();
d7cfeeb4 474 virtual void SetPageInfo(int minPage, int maxPage);
d6b9496a
VZ
475 virtual void SetZoomControl(int zoom);
476 virtual int GetZoomControl();
477 virtual wxPrintPreviewBase *GetPrintPreview() const
478 { return m_printPreview; }
479
82579461
VZ
480
481 // Implementation only from now on.
d6b9496a 482 void OnWindowClose(wxCommandEvent& event);
0f90ec93
KB
483 void OnNext();
484 void OnPrevious();
bf89b538
JS
485 void OnFirst();
486 void OnLast();
82579461 487 void OnGotoPage();
b38b0d22 488 void OnPrint();
82579461 489
90b6b974 490 void OnPrintButton(wxCommandEvent& WXUNUSED(event)) { OnPrint(); }
014b0d06
VZ
491 void OnNextButton(wxCommandEvent & WXUNUSED(event)) { OnNext(); }
492 void OnPreviousButton(wxCommandEvent & WXUNUSED(event)) { OnPrevious(); }
bf89b538
JS
493 void OnFirstButton(wxCommandEvent & WXUNUSED(event)) { OnFirst(); }
494 void OnLastButton(wxCommandEvent & WXUNUSED(event)) { OnLast(); }
d6b9496a 495 void OnPaint(wxPaintEvent& event);
c801d85f 496
82579461
VZ
497 void OnUpdateNextButton(wxUpdateUIEvent& event)
498 { event.Enable(IsNextEnabled()); }
499 void OnUpdatePreviousButton(wxUpdateUIEvent& event)
500 { event.Enable(IsPreviousEnabled()); }
501 void OnUpdateFirstButton(wxUpdateUIEvent& event)
502 { event.Enable(IsFirstEnabled()); }
503 void OnUpdateLastButton(wxUpdateUIEvent& event)
504 { event.Enable(IsLastEnabled()); }
505 void OnUpdateZoomInButton(wxUpdateUIEvent& event)
506 { event.Enable(IsZoomInEnabled()); }
507 void OnUpdateZoomOutButton(wxUpdateUIEvent& event)
508 { event.Enable(IsZoomOutEnabled()); }
509
510 // These methods are not private because they are called by wxPreviewCanvas.
511 void DoZoomIn();
512 void DoZoomOut();
513
34da0970 514protected:
d6b9496a
VZ
515 wxPrintPreviewBase* m_printPreview;
516 wxButton* m_closeButton;
d6b9496a 517 wxChoice* m_zoomControl;
d7cfeeb4
VZ
518 wxPrintPageTextCtrl* m_currentPageText;
519 wxPrintPageMaxCtrl* m_maxPageText;
82579461 520
d6b9496a
VZ
521 long m_buttonFlags;
522
523private:
82579461
VZ
524 void DoGotoPage(int page);
525
526 void DoZoom();
527
528 bool IsNextEnabled() const;
529 bool IsPreviousEnabled() const;
530 bool IsFirstEnabled() const;
531 bool IsLastEnabled() const;
532 bool IsZoomInEnabled() const;
533 bool IsZoomOutEnabled() const;
534
535 void OnZoomInButton(wxCommandEvent & WXUNUSED(event)) { DoZoomIn(); }
536 void OnZoomOutButton(wxCommandEvent & WXUNUSED(event)) { DoZoomOut(); }
537 void OnZoomChoice(wxCommandEvent& WXUNUSED(event)) { DoZoom(); }
538
d6b9496a 539 DECLARE_EVENT_TABLE()
c0c133e1 540 wxDECLARE_NO_COPY_CLASS(wxPreviewControlBar);
c801d85f
KB
541};
542
e81e3883
RR
543//----------------------------------------------------------------------------
544// wxPrintPreviewBase
545//----------------------------------------------------------------------------
546
c801d85f 547/*
c801d85f
KB
548 * Programmer creates an object of this class to preview a wxPrintout.
549 */
d6b9496a 550
53a2db12 551class WXDLLIMPEXP_CORE wxPrintPreviewBase: public wxObject
c801d85f 552{
34da0970 553public:
d6b9496a 554 wxPrintPreviewBase(wxPrintout *printout,
d3b9f782
VZ
555 wxPrintout *printoutForPrinting = NULL,
556 wxPrintDialogData *data = NULL);
d6b9496a
VZ
557 wxPrintPreviewBase(wxPrintout *printout,
558 wxPrintout *printoutForPrinting,
559 wxPrintData *data);
560 virtual ~wxPrintPreviewBase();
c801d85f 561
d6b9496a 562 virtual bool SetCurrentPage(int pageNum);
e81e3883 563 virtual int GetCurrentPage() const;
c801d85f 564
e81e3883
RR
565 virtual void SetPrintout(wxPrintout *printout);
566 virtual wxPrintout *GetPrintout() const;
567 virtual wxPrintout *GetPrintoutForPrinting() const;
c801d85f 568
e81e3883
RR
569 virtual void SetFrame(wxFrame *frame);
570 virtual void SetCanvas(wxPreviewCanvas *canvas);
c801d85f 571
e81e3883
RR
572 virtual wxFrame *GetFrame() const;
573 virtual wxPreviewCanvas *GetCanvas() const;
c801d85f 574
f415cab9
JS
575 // This is a helper routine, used by the next 4 routines.
576
577 virtual void CalcRects(wxPreviewCanvas *canvas, wxRect& printableAreaRect, wxRect& paperRect);
578
d6b9496a 579 // The preview canvas should call this from OnPaint
d2b354f9 580 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
c801d85f 581
b88bf073
VS
582 // Updates rendered page by calling RenderPage() if needed, returns true
583 // if there was some change. Preview canvas should call it at idle time
584 virtual bool UpdatePageRendering();
585
d6b9496a 586 // This draws a blank page onto the preview canvas
d2b354f9
JS
587 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
588
589 // Adjusts the scrollbars for the current scale
590 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
c801d85f 591
d6b9496a
VZ
592 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
593 virtual bool RenderPage(int pageNum);
c801d85f 594
c801d85f 595
d6b9496a 596 virtual void SetZoom(int percent);
e81e3883 597 virtual int GetZoom() const;
34da0970 598
e81e3883 599 virtual wxPrintDialogData& GetPrintDialogData();
d0ee33f5 600
e81e3883
RR
601 virtual int GetMaxPage() const;
602 virtual int GetMinPage() const;
c801d85f 603
b7cacb43
VZ
604 virtual bool Ok() const { return IsOk(); }
605 virtual bool IsOk() const;
e81e3883 606 virtual void SetOk(bool ok);
c801d85f 607
d6b9496a
VZ
608 ///////////////////////////////////////////////////////////////////////////
609 // OVERRIDES
c801d85f 610
d6b9496a
VZ
611 // If we own a wxPrintout that can be used for printing, this
612 // will invoke the actual printing procedure. Called
613 // by the wxPreviewControlBar.
614 virtual bool Print(bool interactive) = 0;
c801d85f 615
d6b9496a
VZ
616 // Calculate scaling that needs to be done to get roughly
617 // the right scaling for the screen pretending to be
618 // the currently selected printer.
619 virtual void DetermineScaling() = 0;
34da0970 620
88b98787 621protected:
25a3fca2
VS
622 // helpers for RenderPage():
623 virtual bool RenderPageIntoDC(wxDC& dc, int pageNum);
624 // renders preview into m_previewBitmap
625 virtual bool RenderPageIntoBitmap(wxBitmap& bmp, int pageNum);
626
88b98787
VS
627 void InvalidatePreviewBitmap();
628
34da0970 629protected:
d6b9496a 630 wxPrintDialogData m_printDialogData;
d2b354f9 631 wxPreviewCanvas* m_previewCanvas;
d6b9496a
VZ
632 wxFrame* m_previewFrame;
633 wxBitmap* m_previewBitmap;
88b98787 634 bool m_previewFailed;
d6b9496a
VZ
635 wxPrintout* m_previewPrintout;
636 wxPrintout* m_printPrintout;
637 int m_currentPage;
638 int m_currentZoom;
f415cab9
JS
639 float m_previewScaleX;
640 float m_previewScaleY;
d6b9496a
VZ
641 int m_topMargin;
642 int m_leftMargin;
643 int m_pageWidth;
644 int m_pageHeight;
645 int m_minPage;
646 int m_maxPage;
647
648 bool m_isOk;
1044a386 649 bool m_printingPrepared; // Called OnPreparePrinting?
d6b9496a
VZ
650
651private:
652 void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
22f3361e 653
c0c133e1 654 wxDECLARE_NO_COPY_CLASS(wxPrintPreviewBase);
e81e3883 655 DECLARE_CLASS(wxPrintPreviewBase)
c801d85f
KB
656};
657
e81e3883
RR
658//----------------------------------------------------------------------------
659// wxPrintPreview
660//----------------------------------------------------------------------------
661
53a2db12 662class WXDLLIMPEXP_CORE wxPrintPreview: public wxPrintPreviewBase
e81e3883
RR
663{
664public:
665 wxPrintPreview(wxPrintout *printout,
d3b9f782
VZ
666 wxPrintout *printoutForPrinting = NULL,
667 wxPrintDialogData *data = NULL);
e81e3883
RR
668 wxPrintPreview(wxPrintout *printout,
669 wxPrintout *printoutForPrinting,
670 wxPrintData *data);
671 virtual ~wxPrintPreview();
672
673 virtual bool SetCurrentPage(int pageNum);
674 virtual int GetCurrentPage() const;
675 virtual void SetPrintout(wxPrintout *printout);
676 virtual wxPrintout *GetPrintout() const;
677 virtual wxPrintout *GetPrintoutForPrinting() const;
678 virtual void SetFrame(wxFrame *frame);
679 virtual void SetCanvas(wxPreviewCanvas *canvas);
680
681 virtual wxFrame *GetFrame() const;
682 virtual wxPreviewCanvas *GetCanvas() const;
683 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
b88bf073 684 virtual bool UpdatePageRendering();
e81e3883
RR
685 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
686 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
687 virtual bool RenderPage(int pageNum);
688 virtual void SetZoom(int percent);
d8766675 689 virtual int GetZoom() const;
e81e3883
RR
690
691 virtual bool Print(bool interactive);
692 virtual void DetermineScaling();
d0ee33f5 693
e81e3883 694 virtual wxPrintDialogData& GetPrintDialogData();
d0ee33f5 695
e81e3883
RR
696 virtual int GetMaxPage() const;
697 virtual int GetMinPage() const;
698
b7cacb43
VZ
699 virtual bool Ok() const { return IsOk(); }
700 virtual bool IsOk() const;
e81e3883 701 virtual void SetOk(bool ok);
d0ee33f5 702
e81e3883
RR
703private:
704 wxPrintPreviewBase *m_pimpl;
705
706private:
707 DECLARE_CLASS(wxPrintPreview)
c0c133e1 708 wxDECLARE_NO_COPY_CLASS(wxPrintPreview);
e81e3883
RR
709};
710
711//----------------------------------------------------------------------------
712// wxPrintAbortDialog
713//----------------------------------------------------------------------------
c801d85f 714
53a2db12 715class WXDLLIMPEXP_CORE wxPrintAbortDialog: public wxDialog
c801d85f
KB
716{
717public:
d6b9496a
VZ
718 wxPrintAbortDialog(wxWindow *parent,
719 const wxString& title,
720 const wxPoint& pos = wxDefaultPosition,
721 const wxSize& size = wxDefaultSize,
722 long style = 0,
2b5f62a0 723 const wxString& name = wxT("dialog"))
7e548f6b 724 : wxDialog(parent, wxID_ANY, title, pos, size, style, name)
d6b9496a
VZ
725 {
726 }
727
728 void OnCancel(wxCommandEvent& event);
34da0970 729
d6b9496a
VZ
730private:
731 DECLARE_EVENT_TABLE()
c0c133e1 732 wxDECLARE_NO_COPY_CLASS(wxPrintAbortDialog);
c801d85f
KB
733};
734
d427503c
VZ
735#endif // wxUSE_PRINTING_ARCHITECTURE
736
c801d85f 737#endif
34138703 738 // _WX_PRNTBASEH__