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