]> git.saurik.com Git - wxWidgets.git/blame - include/wx/prntbase.h
supporting clang memory management annotations
[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 400
1e5ad6e1
VZ
401 // Either Initialize() or InitializeWithModality() must be called before
402 // showing the preview frame, the former being just a particular case of
403 // the latter initializing the frame for being showing app-modally.
404
405 // Notice that we must keep Initialize() with its existing signature to
406 // avoid breaking the old code that overrides it and we can't reuse the
407 // same name for the other functions to avoid virtual function hiding
408 // problem and the associated warnings given by some compilers (e.g. from
409 // g++ with -Woverloaded-virtual).
410 virtual void Initialize()
411 {
412 InitializeWithModality(wxPreviewFrame_AppModal);
413 }
414
415 // Also note that this method is not virtual as it doesn't need to be
416 // overridden: it's never called by wxWidgets (of course, the same is true
417 // for Initialize() but, again, it must remain virtual for compatibility).
418 void InitializeWithModality(wxPreviewFrameModalityKind kind);
419
d6b9496a 420 void OnCloseWindow(wxCloseEvent& event);
d6b9496a
VZ
421 virtual void CreateCanvas();
422 virtual void CreateControlBar();
d2b354f9
JS
423
424 inline wxPreviewControlBar* GetControlBar() const { return m_controlBar; }
425
34da0970 426protected:
d2b354f9 427 wxPreviewCanvas* m_previewCanvas;
d6b9496a
VZ
428 wxPreviewControlBar* m_controlBar;
429 wxPrintPreviewBase* m_printPreview;
7c995553 430 wxWindowDisabler* m_windowDisabler;
e3065973 431
6aacfc73
VZ
432 wxPreviewFrameModalityKind m_modalityKind;
433
434
d6b9496a 435private:
043c6705
VZ
436 void OnChar(wxKeyEvent& event);
437
d6b9496a 438 DECLARE_EVENT_TABLE()
043c6705 439 DECLARE_CLASS(wxPreviewFrame)
c0c133e1 440 wxDECLARE_NO_COPY_CLASS(wxPreviewFrame);
c801d85f
KB
441};
442
f415cab9
JS
443//----------------------------------------------------------------------------
444// wxPreviewControlBar
445//----------------------------------------------------------------------------
446
c801d85f 447/*
c801d85f
KB
448 * A panel with buttons for controlling a print preview.
449 * The programmer may wish to use other means for controlling
450 * the print preview.
451 */
452
453#define wxPREVIEW_PRINT 1
454#define wxPREVIEW_PREVIOUS 2
455#define wxPREVIEW_NEXT 4
456#define wxPREVIEW_ZOOM 8
bf89b538
JS
457#define wxPREVIEW_FIRST 16
458#define wxPREVIEW_LAST 32
459#define wxPREVIEW_GOTO 64
c801d85f 460
d0ee33f5
WS
461#define wxPREVIEW_DEFAULT (wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
462 |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST)
c801d85f
KB
463
464// Ids for controls
465#define wxID_PREVIEW_CLOSE 1
466#define wxID_PREVIEW_NEXT 2
467#define wxID_PREVIEW_PREVIOUS 3
468#define wxID_PREVIEW_PRINT 4
469#define wxID_PREVIEW_ZOOM 5
bf89b538
JS
470#define wxID_PREVIEW_FIRST 6
471#define wxID_PREVIEW_LAST 7
472#define wxID_PREVIEW_GOTO 8
82579461
VZ
473#define wxID_PREVIEW_ZOOM_IN 9
474#define wxID_PREVIEW_ZOOM_OUT 10
c801d85f 475
53a2db12 476class WXDLLIMPEXP_CORE wxPreviewControlBar: public wxPanel
c801d85f 477{
d6b9496a 478 DECLARE_CLASS(wxPreviewControlBar)
c801d85f 479
34da0970 480public:
d6b9496a
VZ
481 wxPreviewControlBar(wxPrintPreviewBase *preview,
482 long buttons,
483 wxWindow *parent,
484 const wxPoint& pos = wxDefaultPosition,
485 const wxSize& size = wxDefaultSize,
d2b354f9 486 long style = wxTAB_TRAVERSAL,
2b5f62a0 487 const wxString& name = wxT("panel"));
d3c7fc99 488 virtual ~wxPreviewControlBar();
d6b9496a
VZ
489
490 virtual void CreateButtons();
d7cfeeb4 491 virtual void SetPageInfo(int minPage, int maxPage);
d6b9496a
VZ
492 virtual void SetZoomControl(int zoom);
493 virtual int GetZoomControl();
494 virtual wxPrintPreviewBase *GetPrintPreview() const
495 { return m_printPreview; }
496
82579461
VZ
497
498 // Implementation only from now on.
d6b9496a 499 void OnWindowClose(wxCommandEvent& event);
0f90ec93
KB
500 void OnNext();
501 void OnPrevious();
bf89b538
JS
502 void OnFirst();
503 void OnLast();
82579461 504 void OnGotoPage();
b38b0d22 505 void OnPrint();
82579461 506
90b6b974 507 void OnPrintButton(wxCommandEvent& WXUNUSED(event)) { OnPrint(); }
014b0d06
VZ
508 void OnNextButton(wxCommandEvent & WXUNUSED(event)) { OnNext(); }
509 void OnPreviousButton(wxCommandEvent & WXUNUSED(event)) { OnPrevious(); }
bf89b538
JS
510 void OnFirstButton(wxCommandEvent & WXUNUSED(event)) { OnFirst(); }
511 void OnLastButton(wxCommandEvent & WXUNUSED(event)) { OnLast(); }
d6b9496a 512 void OnPaint(wxPaintEvent& event);
c801d85f 513
82579461
VZ
514 void OnUpdateNextButton(wxUpdateUIEvent& event)
515 { event.Enable(IsNextEnabled()); }
516 void OnUpdatePreviousButton(wxUpdateUIEvent& event)
517 { event.Enable(IsPreviousEnabled()); }
518 void OnUpdateFirstButton(wxUpdateUIEvent& event)
519 { event.Enable(IsFirstEnabled()); }
520 void OnUpdateLastButton(wxUpdateUIEvent& event)
521 { event.Enable(IsLastEnabled()); }
522 void OnUpdateZoomInButton(wxUpdateUIEvent& event)
523 { event.Enable(IsZoomInEnabled()); }
524 void OnUpdateZoomOutButton(wxUpdateUIEvent& event)
525 { event.Enable(IsZoomOutEnabled()); }
526
527 // These methods are not private because they are called by wxPreviewCanvas.
528 void DoZoomIn();
529 void DoZoomOut();
530
34da0970 531protected:
d6b9496a
VZ
532 wxPrintPreviewBase* m_printPreview;
533 wxButton* m_closeButton;
d6b9496a 534 wxChoice* m_zoomControl;
d7cfeeb4
VZ
535 wxPrintPageTextCtrl* m_currentPageText;
536 wxPrintPageMaxCtrl* m_maxPageText;
82579461 537
d6b9496a
VZ
538 long m_buttonFlags;
539
540private:
82579461
VZ
541 void DoGotoPage(int page);
542
543 void DoZoom();
544
545 bool IsNextEnabled() const;
546 bool IsPreviousEnabled() const;
547 bool IsFirstEnabled() const;
548 bool IsLastEnabled() const;
549 bool IsZoomInEnabled() const;
550 bool IsZoomOutEnabled() const;
551
552 void OnZoomInButton(wxCommandEvent & WXUNUSED(event)) { DoZoomIn(); }
553 void OnZoomOutButton(wxCommandEvent & WXUNUSED(event)) { DoZoomOut(); }
554 void OnZoomChoice(wxCommandEvent& WXUNUSED(event)) { DoZoom(); }
555
d6b9496a 556 DECLARE_EVENT_TABLE()
c0c133e1 557 wxDECLARE_NO_COPY_CLASS(wxPreviewControlBar);
c801d85f
KB
558};
559
e81e3883
RR
560//----------------------------------------------------------------------------
561// wxPrintPreviewBase
562//----------------------------------------------------------------------------
563
c801d85f 564/*
c801d85f
KB
565 * Programmer creates an object of this class to preview a wxPrintout.
566 */
d6b9496a 567
53a2db12 568class WXDLLIMPEXP_CORE wxPrintPreviewBase: public wxObject
c801d85f 569{
34da0970 570public:
d6b9496a 571 wxPrintPreviewBase(wxPrintout *printout,
d3b9f782
VZ
572 wxPrintout *printoutForPrinting = NULL,
573 wxPrintDialogData *data = NULL);
d6b9496a
VZ
574 wxPrintPreviewBase(wxPrintout *printout,
575 wxPrintout *printoutForPrinting,
576 wxPrintData *data);
577 virtual ~wxPrintPreviewBase();
c801d85f 578
d6b9496a 579 virtual bool SetCurrentPage(int pageNum);
e81e3883 580 virtual int GetCurrentPage() const;
c801d85f 581
e81e3883
RR
582 virtual void SetPrintout(wxPrintout *printout);
583 virtual wxPrintout *GetPrintout() const;
584 virtual wxPrintout *GetPrintoutForPrinting() const;
c801d85f 585
e81e3883
RR
586 virtual void SetFrame(wxFrame *frame);
587 virtual void SetCanvas(wxPreviewCanvas *canvas);
c801d85f 588
e81e3883
RR
589 virtual wxFrame *GetFrame() const;
590 virtual wxPreviewCanvas *GetCanvas() const;
c801d85f 591
f415cab9
JS
592 // This is a helper routine, used by the next 4 routines.
593
594 virtual void CalcRects(wxPreviewCanvas *canvas, wxRect& printableAreaRect, wxRect& paperRect);
595
d6b9496a 596 // The preview canvas should call this from OnPaint
d2b354f9 597 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
c801d85f 598
b88bf073
VS
599 // Updates rendered page by calling RenderPage() if needed, returns true
600 // if there was some change. Preview canvas should call it at idle time
601 virtual bool UpdatePageRendering();
602
d6b9496a 603 // This draws a blank page onto the preview canvas
d2b354f9
JS
604 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
605
606 // Adjusts the scrollbars for the current scale
607 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
c801d85f 608
d6b9496a
VZ
609 // This is called by wxPrintPreview to render a page into a wxMemoryDC.
610 virtual bool RenderPage(int pageNum);
c801d85f 611
c801d85f 612
d6b9496a 613 virtual void SetZoom(int percent);
e81e3883 614 virtual int GetZoom() const;
34da0970 615
e81e3883 616 virtual wxPrintDialogData& GetPrintDialogData();
d0ee33f5 617
e81e3883
RR
618 virtual int GetMaxPage() const;
619 virtual int GetMinPage() const;
c801d85f 620
b7cacb43
VZ
621 virtual bool Ok() const { return IsOk(); }
622 virtual bool IsOk() const;
e81e3883 623 virtual void SetOk(bool ok);
c801d85f 624
d6b9496a
VZ
625 ///////////////////////////////////////////////////////////////////////////
626 // OVERRIDES
c801d85f 627
d6b9496a
VZ
628 // If we own a wxPrintout that can be used for printing, this
629 // will invoke the actual printing procedure. Called
630 // by the wxPreviewControlBar.
631 virtual bool Print(bool interactive) = 0;
c801d85f 632
d6b9496a
VZ
633 // Calculate scaling that needs to be done to get roughly
634 // the right scaling for the screen pretending to be
635 // the currently selected printer.
636 virtual void DetermineScaling() = 0;
34da0970 637
88b98787 638protected:
25a3fca2
VS
639 // helpers for RenderPage():
640 virtual bool RenderPageIntoDC(wxDC& dc, int pageNum);
641 // renders preview into m_previewBitmap
642 virtual bool RenderPageIntoBitmap(wxBitmap& bmp, int pageNum);
643
88b98787
VS
644 void InvalidatePreviewBitmap();
645
34da0970 646protected:
d6b9496a 647 wxPrintDialogData m_printDialogData;
d2b354f9 648 wxPreviewCanvas* m_previewCanvas;
d6b9496a
VZ
649 wxFrame* m_previewFrame;
650 wxBitmap* m_previewBitmap;
88b98787 651 bool m_previewFailed;
d6b9496a
VZ
652 wxPrintout* m_previewPrintout;
653 wxPrintout* m_printPrintout;
654 int m_currentPage;
655 int m_currentZoom;
f415cab9
JS
656 float m_previewScaleX;
657 float m_previewScaleY;
d6b9496a
VZ
658 int m_topMargin;
659 int m_leftMargin;
660 int m_pageWidth;
661 int m_pageHeight;
662 int m_minPage;
663 int m_maxPage;
664
665 bool m_isOk;
1044a386 666 bool m_printingPrepared; // Called OnPreparePrinting?
d6b9496a
VZ
667
668private:
669 void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
22f3361e 670
c0c133e1 671 wxDECLARE_NO_COPY_CLASS(wxPrintPreviewBase);
e81e3883 672 DECLARE_CLASS(wxPrintPreviewBase)
c801d85f
KB
673};
674
e81e3883
RR
675//----------------------------------------------------------------------------
676// wxPrintPreview
677//----------------------------------------------------------------------------
678
53a2db12 679class WXDLLIMPEXP_CORE wxPrintPreview: public wxPrintPreviewBase
e81e3883
RR
680{
681public:
682 wxPrintPreview(wxPrintout *printout,
d3b9f782
VZ
683 wxPrintout *printoutForPrinting = NULL,
684 wxPrintDialogData *data = NULL);
e81e3883
RR
685 wxPrintPreview(wxPrintout *printout,
686 wxPrintout *printoutForPrinting,
687 wxPrintData *data);
688 virtual ~wxPrintPreview();
689
690 virtual bool SetCurrentPage(int pageNum);
691 virtual int GetCurrentPage() const;
692 virtual void SetPrintout(wxPrintout *printout);
693 virtual wxPrintout *GetPrintout() const;
694 virtual wxPrintout *GetPrintoutForPrinting() const;
695 virtual void SetFrame(wxFrame *frame);
696 virtual void SetCanvas(wxPreviewCanvas *canvas);
697
698 virtual wxFrame *GetFrame() const;
699 virtual wxPreviewCanvas *GetCanvas() const;
700 virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
b88bf073 701 virtual bool UpdatePageRendering();
e81e3883
RR
702 virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
703 virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
704 virtual bool RenderPage(int pageNum);
705 virtual void SetZoom(int percent);
d8766675 706 virtual int GetZoom() const;
e81e3883
RR
707
708 virtual bool Print(bool interactive);
709 virtual void DetermineScaling();
d0ee33f5 710
e81e3883 711 virtual wxPrintDialogData& GetPrintDialogData();
d0ee33f5 712
e81e3883
RR
713 virtual int GetMaxPage() const;
714 virtual int GetMinPage() const;
715
b7cacb43
VZ
716 virtual bool Ok() const { return IsOk(); }
717 virtual bool IsOk() const;
e81e3883 718 virtual void SetOk(bool ok);
d0ee33f5 719
e81e3883
RR
720private:
721 wxPrintPreviewBase *m_pimpl;
722
723private:
724 DECLARE_CLASS(wxPrintPreview)
c0c133e1 725 wxDECLARE_NO_COPY_CLASS(wxPrintPreview);
e81e3883
RR
726};
727
728//----------------------------------------------------------------------------
729// wxPrintAbortDialog
730//----------------------------------------------------------------------------
c801d85f 731
53a2db12 732class WXDLLIMPEXP_CORE wxPrintAbortDialog: public wxDialog
c801d85f
KB
733{
734public:
d6b9496a
VZ
735 wxPrintAbortDialog(wxWindow *parent,
736 const wxString& title,
737 const wxPoint& pos = wxDefaultPosition,
738 const wxSize& size = wxDefaultSize,
739 long style = 0,
2b5f62a0 740 const wxString& name = wxT("dialog"))
7e548f6b 741 : wxDialog(parent, wxID_ANY, title, pos, size, style, name)
d6b9496a
VZ
742 {
743 }
744
745 void OnCancel(wxCommandEvent& event);
34da0970 746
d6b9496a
VZ
747private:
748 DECLARE_EVENT_TABLE()
c0c133e1 749 wxDECLARE_NO_COPY_CLASS(wxPrintAbortDialog);
c801d85f
KB
750};
751
d427503c
VZ
752#endif // wxUSE_PRINTING_ARCHITECTURE
753
c801d85f 754#endif
34138703 755 // _WX_PRNTBASEH__