prntbase.h 26 KB

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