print.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: print.h
  3. // Purpose: interface of wxPreviewControlBar
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. enum wxPrinterError
  8. {
  9. wxPRINTER_NO_ERROR = 0,
  10. wxPRINTER_CANCELLED,
  11. wxPRINTER_ERROR
  12. };
  13. #define wxPREVIEW_PRINT 1
  14. #define wxPREVIEW_PREVIOUS 2
  15. #define wxPREVIEW_NEXT 4
  16. #define wxPREVIEW_ZOOM 8
  17. #define wxPREVIEW_FIRST 16
  18. #define wxPREVIEW_LAST 32
  19. #define wxPREVIEW_GOTO 64
  20. #define wxPREVIEW_DEFAULT (wxPREVIEW_PREVIOUS|wxPREVIEW_NEXT|wxPREVIEW_ZOOM\
  21. |wxPREVIEW_FIRST|wxPREVIEW_GOTO|wxPREVIEW_LAST)
  22. // Ids for controls
  23. #define wxID_PREVIEW_CLOSE 1
  24. #define wxID_PREVIEW_NEXT 2
  25. #define wxID_PREVIEW_PREVIOUS 3
  26. #define wxID_PREVIEW_PRINT 4
  27. #define wxID_PREVIEW_ZOOM 5
  28. #define wxID_PREVIEW_FIRST 6
  29. #define wxID_PREVIEW_LAST 7
  30. #define wxID_PREVIEW_GOTO 8
  31. #define wxID_PREVIEW_ZOOM_IN 9
  32. #define wxID_PREVIEW_ZOOM_OUT 10
  33. /**
  34. @class wxPreviewControlBar
  35. This is the default implementation of the preview control bar, a panel
  36. with buttons and a zoom control.
  37. You can derive a new class from this and override some or all member functions
  38. to change the behaviour and appearance; or you can leave it as it is.
  39. @library{wxcore}
  40. @category{printing}
  41. @see wxPreviewFrame, wxPreviewCanvas, wxPrintPreview
  42. */
  43. class wxPreviewControlBar : public wxPanel
  44. {
  45. public:
  46. /**
  47. Constructor.
  48. The @a buttons parameter may be a combination of the following, using the bitwise
  49. 'or' operator:
  50. @beginFlagTable
  51. @flag{wxPREVIEW_PRINT}
  52. Create a print button.
  53. @flag{wxPREVIEW_NEXT}
  54. Create a next page button.
  55. @flag{wxPREVIEW_PREVIOUS}
  56. Create a previous page button.
  57. @flag{wxPREVIEW_ZOOM}
  58. Create a zoom control.
  59. @flag{wxPREVIEW_DEFAULT}
  60. Equivalent to a combination of @c wxPREVIEW_PREVIOUS, @c wxPREVIEW_NEXT
  61. and @c wxPREVIEW_ZOOM.
  62. @endFlagTable
  63. */
  64. wxPreviewControlBar(wxPrintPreview* preview,
  65. long buttons,
  66. wxWindow* parent,
  67. const wxPoint& pos = wxDefaultPosition,
  68. const wxSize& size = wxDefaultSize,
  69. long style = 0,
  70. const wxString& name = "panel");
  71. /**
  72. Destructor.
  73. */
  74. virtual ~wxPreviewControlBar();
  75. /**
  76. Creates buttons, according to value of the button style flags.
  77. @todo which flags??
  78. */
  79. virtual void CreateButtons();
  80. /**
  81. Gets the print preview object associated with the control bar.
  82. */
  83. virtual wxPrintPreviewBase* GetPrintPreview() const;
  84. /**
  85. Gets the current zoom setting in percent.
  86. */
  87. virtual int GetZoomControl();
  88. /**
  89. Sets the zoom control.
  90. */
  91. virtual void SetZoomControl(int percent);
  92. };
  93. /**
  94. @class wxPreviewCanvas
  95. A preview canvas is the default canvas used by the print preview
  96. system to display the preview.
  97. @library{wxcore}
  98. @category{printing}
  99. @see wxPreviewFrame, wxPreviewControlBar, wxPrintPreview
  100. */
  101. class wxPreviewCanvas : public wxScrolledWindow
  102. {
  103. public:
  104. /**
  105. Constructor.
  106. */
  107. wxPreviewCanvas(wxPrintPreview* preview, wxWindow* parent,
  108. const wxPoint& pos = wxDefaultPosition,
  109. const wxSize& size = wxDefaultSize,
  110. long style = 0,
  111. const wxString& name = "canvas");
  112. /**
  113. Destructor.
  114. */
  115. virtual ~wxPreviewCanvas();
  116. /**
  117. Calls wxPrintPreview::PaintPage() to refresh the canvas.
  118. */
  119. void OnPaint(wxPaintEvent& event);
  120. };
  121. /**
  122. Preview frame modality kind.
  123. The elements of this enum can be used with wxPreviewFrame::Initialize() to
  124. indicate how should the preview frame be shown.
  125. @since 2.9.2
  126. */
  127. enum wxPreviewFrameModalityKind
  128. {
  129. /**
  130. Disable all the other top level windows while the preview frame is shown.
  131. This is the default behaviour.
  132. */
  133. wxPreviewFrame_AppModal,
  134. /**
  135. Disable only the parent window while the preview frame is shown.
  136. */
  137. wxPreviewFrame_WindowModal,
  138. /**
  139. Show the preview frame non-modally and don't disable any other windows.
  140. */
  141. wxPreviewFrame_NonModal
  142. };
  143. /**
  144. @class wxPreviewFrame
  145. This class provides the default method of managing the print preview interface.
  146. Member functions may be overridden to replace functionality, or the
  147. class may be used without derivation.
  148. @library{wxcore}
  149. @category{printing}
  150. @see wxPreviewCanvas, wxPreviewControlBar, wxPrintPreview
  151. */
  152. class wxPreviewFrame : public wxFrame
  153. {
  154. public:
  155. /**
  156. Constructor.
  157. Pass a print preview object plus other normal frame arguments.
  158. The print preview object will be destroyed by the frame when it closes.
  159. */
  160. wxPreviewFrame(wxPrintPreviewBase* preview, wxWindow* parent,
  161. const wxString& title = "Print Preview",
  162. const wxPoint& pos = wxDefaultPosition,
  163. const wxSize& size = wxDefaultSize,
  164. long style = wxDEFAULT_FRAME_STYLE,
  165. const wxString& name = wxFrameNameStr);
  166. /**
  167. Destructor.
  168. */
  169. virtual ~wxPreviewFrame();
  170. /**
  171. Creates a wxPreviewCanvas.
  172. Override this function to allow a user-defined preview canvas object
  173. to be created.
  174. */
  175. virtual void CreateCanvas();
  176. /**
  177. Creates a wxPreviewControlBar.
  178. Override this function to allow a user-defined preview control bar object
  179. to be created.
  180. */
  181. virtual void CreateControlBar();
  182. /**
  183. Initializes the frame elements and prepares for showing it.
  184. Calling this method is equivalent to calling InitializeWithModality()
  185. with wxPreviewFrame_AppModal argument, please see its documentation for
  186. more details.
  187. Please notice that this function is virtual mostly for backwards
  188. compatibility only, there is no real need to override it as it's never
  189. called by wxWidgets itself.
  190. */
  191. virtual void Initialize();
  192. /**
  193. Initializes the frame elements and prepares for showing it with the
  194. given modality kind.
  195. This method creates the frame elements by calling CreateCanvas() and
  196. CreateControlBar() methods (which may be overridden to customize them)
  197. and prepares to show the frame according to the value of @a kind
  198. parameter:
  199. - If it is wxPreviewFrame_AppModal, all the other application
  200. windows will be disabled when this frame is shown. This is the same
  201. behaviour as that of simple Initialize().
  202. - If it is wxPreviewFrame_WindowModal, only the parent window of
  203. the preview frame will be disabled when it is shown.
  204. - And if it is wxPreviewFrame_NonModal, no windows at all will be
  205. disabled while the preview is shown.
  206. Notice that this function (or Initialize()) must be called by the
  207. application prior to showing the frame but you still must call @c
  208. Show(true) to actually show it afterwards.
  209. @param kind
  210. The modality kind of preview frame.
  211. @since 2.9.2
  212. */
  213. virtual void InitializeWithModality(wxPreviewFrameModalityKind kind);
  214. /**
  215. Enables any disabled frames in the application, and deletes the print preview
  216. object, implicitly deleting any printout objects associated with the print
  217. preview object.
  218. */
  219. void OnCloseWindow(wxCloseEvent& event);
  220. };
  221. /**
  222. @class wxPrintPreview
  223. Objects of this class manage the print preview process. The object is passed
  224. a wxPrintout object, and the wxPrintPreview object itself is passed to
  225. a wxPreviewFrame object. Previewing is started by initializing and showing
  226. the preview frame. Unlike wxPrinter::Print(), flow of control returns to the
  227. application immediately after the frame is shown.
  228. @note
  229. The preview shown is only exact on Windows. On other platforms, the wxDC
  230. used for preview is different from what is used for printing and the
  231. results may be significantly different, depending on how is the output
  232. created. In particular, printing code relying on wxDC::GetTextExtent()
  233. heavily (for example, wxHtmlEasyPrinting and other wxHTML classes do) is
  234. affected. It is recommended to use native preview functionality on
  235. platforms that offer it (OS X, GTK+).
  236. @library{wxcore}
  237. @category{printing}
  238. @see @ref overview_printing, wxPrinterDC, wxPrintDialog, wxPrintout, wxPrinter,
  239. wxPreviewCanvas, wxPreviewControlBar, wxPreviewFrame
  240. */
  241. class wxPrintPreview : public wxObject
  242. {
  243. public:
  244. /**
  245. Constructor.
  246. Pass a printout object, an optional printout object to be used for actual
  247. printing, and the address of an optional block of printer data, which will
  248. be copied to the print preview object's print data.
  249. If @a printoutForPrinting is non-@NULL, a @b "Print..." button will be placed on
  250. the preview frame so that the user can print directly from the preview interface.
  251. @remarks
  252. Do not explicitly delete the printout objects once this constructor has been
  253. called, since they will be deleted in the wxPrintPreview destructor.
  254. The same does not apply to the @a data argument.
  255. Use IsOk() to check whether the wxPrintPreview object was created correctly.
  256. */
  257. wxPrintPreview(wxPrintout* printout,
  258. wxPrintout* printoutForPrinting = NULL,
  259. wxPrintDialogData* data = NULL);
  260. wxPrintPreview(wxPrintout* printout,
  261. wxPrintout* printoutForPrinting,
  262. wxPrintData* data);
  263. /**
  264. Destructor.
  265. Deletes both print preview objects, so do not destroy these objects
  266. in your application.
  267. */
  268. ~wxPrintPreview();
  269. /**
  270. Gets the preview window used for displaying the print preview image.
  271. */
  272. virtual wxPreviewCanvas* GetCanvas() const;
  273. /**
  274. Gets the page currently being previewed.
  275. */
  276. virtual int GetCurrentPage() const;
  277. /**
  278. Gets the frame used for displaying the print preview canvas
  279. and control bar.
  280. */
  281. virtual wxFrame* GetFrame() const;
  282. /**
  283. Returns the maximum page number.
  284. */
  285. virtual int GetMaxPage() const;
  286. /**
  287. Returns the minimum page number.
  288. */
  289. virtual int GetMinPage() const;
  290. /**
  291. Gets the preview printout object associated with the wxPrintPreview object.
  292. */
  293. virtual wxPrintout* GetPrintout() const;
  294. /**
  295. Gets the printout object to be used for printing from within the preview
  296. interface,
  297. or @NULL if none exists.
  298. */
  299. virtual wxPrintout* GetPrintoutForPrinting() const;
  300. /**
  301. Returns @true if the wxPrintPreview is valid, @false otherwise.
  302. It could return @false if there was a problem initializing the printer
  303. device context (current printer not set, for example).
  304. */
  305. virtual bool IsOk() const;
  306. /**
  307. This refreshes the preview window with the preview image.
  308. It must be called from the preview window's OnPaint member.
  309. The implementation simply blits the preview bitmap onto
  310. the canvas, creating a new preview bitmap if none exists.
  311. */
  312. virtual bool PaintPage(wxPreviewCanvas* canvas, wxDC& dc);
  313. /**
  314. Invokes the print process using the second wxPrintout object
  315. supplied in the wxPrintPreview constructor.
  316. Will normally be called by the @b Print... panel item on the
  317. preview frame's control bar.
  318. Returns @false in case of error -- call wxPrinter::GetLastError()
  319. to get detailed information about the kind of the error.
  320. */
  321. virtual bool Print(bool prompt);
  322. /**
  323. Renders a page into a wxMemoryDC. Used internally by wxPrintPreview.
  324. */
  325. virtual bool RenderPage(int pageNum);
  326. /**
  327. Sets the window to be used for displaying the print preview image.
  328. */
  329. virtual void SetCanvas(wxPreviewCanvas* window);
  330. /**
  331. Sets the current page to be previewed.
  332. */
  333. virtual bool SetCurrentPage(int pageNum);
  334. /**
  335. Sets the frame to be used for displaying the print preview canvas
  336. and control bar.
  337. */
  338. virtual void SetFrame(wxFrame* frame);
  339. /**
  340. Associates a printout object with the wxPrintPreview object.
  341. */
  342. virtual void SetPrintout(wxPrintout* printout);
  343. /**
  344. Sets the percentage preview zoom, and refreshes the preview canvas accordingly.
  345. */
  346. virtual void SetZoom(int percent);
  347. };
  348. /**
  349. @class wxPrinter
  350. This class represents the Windows or PostScript printer, and is the vehicle
  351. through which printing may be launched by an application.
  352. Printing can also be achieved through using of lower functions and classes,
  353. but this and associated classes provide a more convenient and general method
  354. of printing.
  355. @library{wxcore}
  356. @category{printing}
  357. @see @ref overview_printing, wxPrinterDC, wxPrintDialog, wxPrintout, wxPrintPreview
  358. */
  359. class wxPrinter : public wxObject
  360. {
  361. public:
  362. /**
  363. Constructor.
  364. Pass an optional pointer to a block of print dialog data, which will be
  365. copied to the printer object's local data.
  366. @see wxPrintDialogData, wxPrintData
  367. */
  368. wxPrinter(wxPrintDialogData* data = NULL);
  369. /**
  370. Creates the default printing abort window, with a cancel button.
  371. */
  372. virtual wxPrintAbortDialog* CreateAbortWindow(wxWindow* parent, wxPrintout* printout);
  373. /**
  374. Returns @true if the user has aborted the print job.
  375. */
  376. bool GetAbort() const;
  377. /**
  378. Return last error. Valid after calling Print(), PrintDialog() or
  379. wxPrintPreview::Print().
  380. These functions set last error to @c wxPRINTER_NO_ERROR if no error happened.
  381. Returned value is one of the following:
  382. @beginTable
  383. @row2col{wxPRINTER_NO_ERROR, No error happened.}
  384. @row2col{wxPRINTER_CANCELLED, The user cancelled printing.}
  385. @row2col{wxPRINTER_ERROR, There was an error during printing.}
  386. @endTable
  387. */
  388. static wxPrinterError GetLastError();
  389. /**
  390. Returns the @ref overview_printing_printdata "print data" associated with
  391. the printer object.
  392. */
  393. virtual wxPrintDialogData& GetPrintDialogData() const;
  394. /**
  395. Starts the printing process. Provide a parent window, a user-defined wxPrintout
  396. object which controls the printing of a document, and whether the print dialog
  397. should be invoked first.
  398. Print() could return @false if there was a problem initializing the printer device
  399. context (current printer not set, for example) or the user cancelled printing.
  400. Call GetLastError() to get detailed information about the kind of the error.
  401. */
  402. virtual bool Print(wxWindow* parent, wxPrintout* printout,
  403. bool prompt = true);
  404. /**
  405. Invokes the print dialog.
  406. If successful (the user did not press Cancel and no error occurred),
  407. a suitable device context will be returned; otherwise @NULL is returned;
  408. call GetLastError() to get detailed information about the kind of the error.
  409. @remarks
  410. The application must delete this device context to avoid a memory leak.
  411. */
  412. virtual wxDC* PrintDialog(wxWindow* parent);
  413. /**
  414. Default error-reporting function.
  415. */
  416. virtual void ReportError(wxWindow* parent, wxPrintout* printout,
  417. const wxString& message);
  418. /**
  419. Invokes the print setup dialog.
  420. @remarks
  421. The setup dialog is obsolete from Windows 95, though retained
  422. for backward compatibility.
  423. */
  424. virtual bool Setup(wxWindow* parent);
  425. };
  426. /**
  427. @class wxPrintout
  428. This class encapsulates the functionality of printing out an application document.
  429. A new class must be derived and members overridden to respond to calls such as
  430. OnPrintPage() and HasPage() and to render the print image onto an associated wxDC.
  431. Instances of this class are passed to wxPrinter::Print() or
  432. to a wxPrintPreview object to initiate printing or previewing.
  433. Your derived wxPrintout is responsible for drawing both the preview image and
  434. the printed page. If your windows' drawing routines accept an arbitrary DC as an
  435. argument, you can re-use those routines within your wxPrintout subclass to draw
  436. the printout image. You may also add additional drawing elements within your
  437. wxPrintout subclass, like headers, footers, and/or page numbers. However, the
  438. image on the printed page will often differ from the image drawn on the screen,
  439. as will the print preview image -- not just in the presence of headers and
  440. footers, but typically in scale. A high-resolution printer presents a much
  441. larger drawing surface (i.e., a higher-resolution DC); a zoomed-out preview
  442. image presents a much smaller drawing surface (lower-resolution DC). By using
  443. the routines FitThisSizeToXXX() and/or MapScreenSizeToXXX() within your
  444. wxPrintout subclass to set the user scale and origin of the associated DC, you
  445. can easily use a single drawing routine to draw on your application's windows,
  446. to create the print preview image, and to create the printed paper image, and
  447. achieve a common appearance to the preview image and the printed page.
  448. @library{wxcore}
  449. @category{printing}
  450. @see @ref overview_printing, wxPrinterDC, wxPrintDialog, wxPageSetupDialog,
  451. wxPrinter, wxPrintPreview
  452. */
  453. class wxPrintout : public wxObject
  454. {
  455. public:
  456. /**
  457. Constructor.
  458. Pass an optional title argument - the current filename would be a
  459. good idea. This will appear in the printing list (at least in MSW)
  460. */
  461. wxPrintout(const wxString& title = "Printout");
  462. /**
  463. Destructor.
  464. */
  465. virtual ~wxPrintout();
  466. /**
  467. Set the user scale and device origin of the wxDC associated with this wxPrintout
  468. so that the given image size fits entirely within the page rectangle and the
  469. origin is at the top left corner of the page rectangle.
  470. On MSW and Mac, the page rectangle is the printable area of the page.
  471. On other platforms and PostScript printing, the page rectangle is the entire paper.
  472. Use this if you want your printed image as large as possible, but with the caveat
  473. that on some platforms, portions of the image might be cut off at the edges.
  474. */
  475. void FitThisSizeToPage(const wxSize& imageSize);
  476. /**
  477. Set the user scale and device origin of the wxDC associated with this wxPrintout
  478. so that the given image size fits entirely within the page margins set in the
  479. given wxPageSetupDialogData object.
  480. This function provides the greatest consistency across all platforms because it
  481. does not depend on having access to the printable area of the paper.
  482. @remarks
  483. On Mac, the native wxPageSetupDialog does not let you set the page margins;
  484. you'll have to provide your own mechanism, or you can use the Mac-only class
  485. wxMacPageMarginsDialog.
  486. */
  487. void FitThisSizeToPageMargins(const wxSize& imageSize,
  488. const wxPageSetupDialogData& pageSetupData);
  489. /**
  490. Set the user scale and device origin of the wxDC associated with this wxPrintout
  491. so that the given image size fits entirely within the paper and the origin is at
  492. the top left corner of the paper.
  493. Use this if you're managing your own page margins.
  494. @note
  495. With most printers, the region around the edges of the paper are not
  496. printable so that the edges of the image could be cut off.
  497. */
  498. void FitThisSizeToPaper(const wxSize& imageSize);
  499. /**
  500. Returns the device context associated with the printout (given to the printout
  501. at start of printing or previewing).
  502. The application can use GetDC() to obtain a device context to draw on.
  503. This will be a wxPrinterDC if printing under Windows or Mac, a wxPostScriptDC
  504. if printing on other platforms, and a wxMemoryDC if previewing.
  505. */
  506. wxDC* GetDC() const;
  507. /**
  508. Return the rectangle corresponding to the page margins specified by the given
  509. wxPageSetupDialogData object in the associated wxDC's logical coordinates for
  510. the current user scale and device origin.
  511. The page margins are specified with respect to the edges of the paper on all
  512. platforms.
  513. */
  514. wxRect GetLogicalPageMarginsRect(const wxPageSetupDialogData& pageSetupData) const;
  515. /**
  516. Return the rectangle corresponding to the page in the associated wxDC 's
  517. logical coordinates for the current user scale and device origin.
  518. On MSW and Mac, this will be the printable area of the paper.
  519. On other platforms and PostScript printing, this will be the full paper
  520. rectangle.
  521. */
  522. wxRect GetLogicalPageRect() const;
  523. /**
  524. Return the rectangle corresponding to the paper in the associated wxDC 's
  525. logical coordinates for the current user scale and device origin.
  526. */
  527. wxRect GetLogicalPaperRect() const;
  528. /**
  529. Returns the number of pixels per logical inch of the printer device context.
  530. Dividing the printer PPI by the screen PPI can give a suitable scaling factor
  531. for drawing text onto the printer.
  532. Remember to multiply this by a scaling factor to take the preview DC size into
  533. account.
  534. Or you can just use the FitThisSizeToXXX() and MapScreenSizeToXXX routines below,
  535. which do most of the scaling calculations for you.
  536. @beginWxPerlOnly
  537. In wxPerl this method takes no arguments and returns a
  538. 2-element list (w, h).
  539. @endWxPerlOnly
  540. */
  541. void GetPPIPrinter(int* w, int* h) const;
  542. /**
  543. Returns the number of pixels per logical inch of the screen device context.
  544. Dividing the printer PPI by the screen PPI can give a suitable scaling factor
  545. for drawing text onto the printer.
  546. If you are doing your own scaling, remember to multiply this by a scaling
  547. factor to take the preview DC size into account.
  548. @beginWxPerlOnly
  549. In wxPerl this method takes no arguments and returns a
  550. 2-element list (w, h).
  551. @endWxPerlOnly
  552. */
  553. void GetPPIScreen(int* w, int* h) const;
  554. /**
  555. Called by the framework to obtain information from the application about minimum
  556. and maximum page values that the user can select, and the required page range to
  557. be printed.
  558. By default this returns (1, 32000) for the page minimum and maximum values, and
  559. (1, 1) for the required page range.
  560. @a minPage must be greater than zero and @a maxPage must be greater
  561. than @a minPage.
  562. */
  563. virtual void GetPageInfo(int* minPage, int* maxPage, int* pageFrom,
  564. int* pageTo);
  565. /**
  566. Returns the size of the printer page in millimetres.
  567. @beginWxPerlOnly
  568. In wxPerl this method takes no arguments and returns a
  569. 2-element list (w, h).
  570. @endWxPerlOnly
  571. */
  572. void GetPageSizeMM(int* w, int* h) const;
  573. /**
  574. Returns the size of the printer page in pixels, called the page rectangle.
  575. The page rectangle has a top left corner at (0,0) and a bottom right corner at
  576. (w,h). These values may not be the same as the values returned from
  577. wxDC::GetSize(); if the printout is being used for
  578. previewing, a memory device context is used, which uses a bitmap size reflecting
  579. the current preview zoom. The application must take this discrepancy into
  580. account if previewing is to be supported.
  581. */
  582. void GetPageSizePixels(int* w, int* h) const;
  583. /**
  584. Returns the rectangle that corresponds to the entire paper in pixels, called the
  585. paper rectangle.
  586. This distinction between paper rectangle and page rectangle reflects the fact that
  587. most printers cannot print all the way to the edge of the paper.
  588. The page rectangle is a rectangle whose top left corner is at (0,0) and whose width
  589. and height are given by wxDC::GetPageSizePixels().
  590. On MSW and Mac, the page rectangle gives the printable area of the paper, while the
  591. paper rectangle represents the entire paper, including non-printable borders.
  592. Thus, the rectangle returned by wxDC::GetPaperRectPixels() will have a top left corner
  593. whose coordinates are small negative numbers and the bottom right corner will have
  594. values somewhat larger than the width and height given by wxDC::GetPageSizePixels().
  595. On other platforms and for PostScript printing, the paper is treated as if its entire
  596. area were printable, so this function will return the same rectangle as the page
  597. rectangle.
  598. */
  599. wxRect GetPaperRectPixels() const;
  600. /**
  601. Returns the title of the printout.
  602. @todo the python note here was wrong
  603. */
  604. virtual wxString GetTitle() const;
  605. /**
  606. Should be overridden to return @true if the document has this page, or @false
  607. if not.
  608. Returning @false signifies the end of the document. By default,
  609. HasPage behaves as if the document has only one page.
  610. */
  611. virtual bool HasPage(int pageNum);
  612. /**
  613. Returns @true if the printout is currently being used for previewing.
  614. @see GetPreview()
  615. */
  616. virtual bool IsPreview() const;
  617. /**
  618. Returns the associated preview object if any.
  619. If this printout object is used for previewing, returns the associated
  620. wxPrintPreview. Otherwise returns @NULL.
  621. The returned pointer is not owned by the printout and must not be
  622. deleted.
  623. @see IsPreview()
  624. @since 2.9.1.
  625. */
  626. wxPrintPreview *GetPreview() const;
  627. /**
  628. Set the user scale and device origin of the wxDC associated with this wxPrintout
  629. so that one screen pixel maps to one device pixel on the DC.
  630. That is, the user scale is set to (1,1) and the device origin is set to (0,0).
  631. Use this if you want to do your own scaling prior to calling wxDC drawing calls,
  632. for example, if your underlying model is floating-point and you want to achieve
  633. maximum drawing precision on high-resolution printers.
  634. You can use the GetLogicalXXXRect() routines below to obtain the paper rectangle,
  635. page rectangle, or page margins rectangle to perform your own scaling.
  636. @note
  637. While the underlying drawing model of Mac OS X is floating-point,
  638. wxWidgets's drawing model scales from integer coordinates.
  639. */
  640. void MapScreenSizeToDevice();
  641. /**
  642. This sets the user scale of the wxDC associated with this wxPrintout to the same
  643. scale as MapScreenSizeToPaper() but sets the logical origin to the top left corner
  644. of the page rectangle.
  645. */
  646. void MapScreenSizeToPage();
  647. /**
  648. This sets the user scale of the wxDC associated with this wxPrintout to the same
  649. scale as MapScreenSizeToPageMargins() but sets the logical origin to the top left
  650. corner of the page margins specified by the given wxPageSetupDialogData object.
  651. */
  652. void MapScreenSizeToPageMargins(const wxPageSetupDialogData& pageSetupData);
  653. /**
  654. Set the user scale and device origin of the wxDC associated with this wxPrintout
  655. so that the printed page matches the screen size as closely as possible
  656. and the logical origin is in the top left corner of the paper rectangle.
  657. That is, a 100-pixel object on screen should appear at the same size on the
  658. printed page.
  659. (It will, of course, be larger or smaller in the preview image, depending on the
  660. zoom factor.)
  661. Use this if you want WYSIWYG behaviour, e.g., in a text editor.
  662. */
  663. void MapScreenSizeToPaper();
  664. /**
  665. Shift the device origin by an amount specified in logical coordinates.
  666. */
  667. void OffsetLogicalOrigin(wxCoord xoff, wxCoord yoff);
  668. /**
  669. Called by the framework at the start of document printing. Return @false from
  670. this function cancels the print job.
  671. OnBeginDocument() is called once for every copy printed.
  672. @remarks
  673. The base OnBeginDocument() must be called (and the return value
  674. checked) from within the overridden function, since it calls wxDC::StartDoc().
  675. */
  676. virtual bool OnBeginDocument(int startPage, int endPage);
  677. /**
  678. Called by the framework at the start of printing.
  679. OnBeginPrinting() is called once for every print job
  680. (regardless of how many copies are being printed).
  681. */
  682. virtual void OnBeginPrinting();
  683. /**
  684. Called by the framework at the end of document printing.
  685. OnEndDocument() is called once for every copy printed.
  686. @remarks
  687. The base OnEndDocument() must be called from within the overridden function,
  688. since it calls wxDC::EndDoc().
  689. */
  690. virtual void OnEndDocument();
  691. /**
  692. Called by the framework at the end of printing.
  693. OnEndPrinting is called once for every print job
  694. (regardless of how many copies are being printed).
  695. */
  696. virtual void OnEndPrinting();
  697. /**
  698. Called once by the framework before any other demands are made of the
  699. wxPrintout object.
  700. This gives the object an opportunity to calculate the number of pages
  701. in the document, for example.
  702. */
  703. virtual void OnPreparePrinting();
  704. /**
  705. Called by the framework when a page should be printed. Returning @false cancels
  706. the print job.
  707. */
  708. virtual bool OnPrintPage(int pageNum) = 0;
  709. /**
  710. Set the device origin of the associated wxDC so that the current logical point
  711. becomes the new logical origin.
  712. */
  713. void SetLogicalOrigin(wxCoord x, wxCoord y);
  714. };
  715. /**
  716. @class wxPrintAbortDialog
  717. The dialog created by default by the print framework that enables aborting
  718. the printing process.
  719. */
  720. class wxPrintAbortDialog: public wxDialog
  721. {
  722. public:
  723. wxPrintAbortDialog(wxWindow *parent,
  724. const wxString& documentTitle,
  725. const wxPoint& pos = wxDefaultPosition,
  726. const wxSize& size = wxDefaultSize,
  727. long style = wxDEFAULT_DIALOG_STYLE,
  728. const wxString& name = "dialog");
  729. void SetProgress(int currentPage, int totalPages,
  730. int currentCopy, int totalCopies);
  731. };