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