print.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/print.h
  3. // Author: Anthony Bretaudeau
  4. // Purpose: GTK printing support
  5. // Created: 2007-08-25
  6. // Copyright: (c) Anthony Bretaudeau
  7. // Licence: wxWindows Licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_GTK_PRINT_H_
  10. #define _WX_GTK_PRINT_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_GTKPRINT
  13. #include "wx/print.h"
  14. #include "wx/printdlg.h"
  15. #include "wx/prntbase.h"
  16. #include "wx/dc.h"
  17. typedef struct _GtkPrintOperation GtkPrintOperation;
  18. typedef struct _GtkPrintContext GtkPrintContext;
  19. typedef struct _GtkPrintSettings GtkPrintSettings;
  20. typedef struct _GtkPageSetup GtkPageSetup;
  21. typedef struct _cairo cairo_t;
  22. //----------------------------------------------------------------------------
  23. // wxGtkPrintFactory
  24. //----------------------------------------------------------------------------
  25. class wxGtkPrintFactory: public wxPrintFactory
  26. {
  27. public:
  28. virtual wxPrinterBase *CreatePrinter( wxPrintDialogData *data );
  29. virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
  30. wxPrintout *printout = NULL,
  31. wxPrintDialogData *data = NULL );
  32. virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
  33. wxPrintout *printout,
  34. wxPrintData *data );
  35. virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
  36. wxPrintDialogData *data = NULL );
  37. virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
  38. wxPrintData *data );
  39. virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
  40. wxPageSetupDialogData * data = NULL );
  41. virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data );
  42. virtual bool HasPrintSetupDialog();
  43. virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
  44. virtual bool HasOwnPrintToFile();
  45. virtual bool HasPrinterLine();
  46. virtual wxString CreatePrinterLine();
  47. virtual bool HasStatusLine();
  48. virtual wxString CreateStatusLine();
  49. virtual wxPrintNativeDataBase *CreatePrintNativeData();
  50. };
  51. //----------------------------------------------------------------------------
  52. // wxGtkPrintDialog
  53. //----------------------------------------------------------------------------
  54. class WXDLLIMPEXP_CORE wxGtkPrintDialog: public wxPrintDialogBase
  55. {
  56. public:
  57. wxGtkPrintDialog( wxWindow *parent,
  58. wxPrintDialogData* data = NULL );
  59. wxGtkPrintDialog( wxWindow *parent, wxPrintData* data);
  60. virtual ~wxGtkPrintDialog();
  61. wxPrintData& GetPrintData()
  62. { return m_printDialogData.GetPrintData(); }
  63. wxPrintDialogData& GetPrintDialogData()
  64. { return m_printDialogData; }
  65. wxDC *GetPrintDC() { return m_dc; }
  66. void SetPrintDC(wxDC * printDC) { m_dc = printDC; }
  67. virtual int ShowModal();
  68. virtual bool Validate() { return true; }
  69. virtual bool TransferDataToWindow() { return true; }
  70. virtual bool TransferDataFromWindow() { return true; }
  71. void SetShowDialog(bool show) { m_showDialog = show; }
  72. bool GetShowDialog() { return m_showDialog; }
  73. protected:
  74. // Implement some base class methods to do nothing to avoid asserts and
  75. // GTK warnings, since this is not a real wxDialog.
  76. virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
  77. int WXUNUSED(width), int WXUNUSED(height),
  78. int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
  79. virtual void DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y),
  80. int WXUNUSED(width), int WXUNUSED(height)) {}
  81. private:
  82. wxPrintDialogData m_printDialogData;
  83. wxWindow *m_parent;
  84. bool m_showDialog;
  85. wxDC *m_dc;
  86. DECLARE_DYNAMIC_CLASS(wxGtkPrintDialog)
  87. };
  88. //----------------------------------------------------------------------------
  89. // wxGtkPageSetupDialog
  90. //----------------------------------------------------------------------------
  91. class WXDLLIMPEXP_CORE wxGtkPageSetupDialog: public wxPageSetupDialogBase
  92. {
  93. public:
  94. wxGtkPageSetupDialog( wxWindow *parent,
  95. wxPageSetupDialogData* data = NULL );
  96. virtual ~wxGtkPageSetupDialog();
  97. virtual wxPageSetupDialogData& GetPageSetupDialogData() { return m_pageDialogData; }
  98. virtual int ShowModal();
  99. virtual bool Validate() { return true; }
  100. virtual bool TransferDataToWindow() { return true; }
  101. virtual bool TransferDataFromWindow() { return true; }
  102. protected:
  103. // Implement some base class methods to do nothing to avoid asserts and
  104. // GTK warnings, since this is not a real wxDialog.
  105. virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
  106. int WXUNUSED(width), int WXUNUSED(height),
  107. int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
  108. virtual void DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y),
  109. int WXUNUSED(width), int WXUNUSED(height)) {}
  110. private:
  111. wxPageSetupDialogData m_pageDialogData;
  112. wxWindow *m_parent;
  113. DECLARE_DYNAMIC_CLASS(wxGtkPageSetupDialog)
  114. };
  115. //----------------------------------------------------------------------------
  116. // wxGtkPrinter
  117. //----------------------------------------------------------------------------
  118. class WXDLLIMPEXP_CORE wxGtkPrinter : public wxPrinterBase
  119. {
  120. public:
  121. wxGtkPrinter(wxPrintDialogData *data = NULL);
  122. virtual ~wxGtkPrinter();
  123. virtual bool Print(wxWindow *parent,
  124. wxPrintout *printout,
  125. bool prompt = true);
  126. virtual wxDC* PrintDialog(wxWindow *parent);
  127. virtual bool Setup(wxWindow *parent);
  128. GtkPrintContext *GetPrintContext() { return m_gpc; }
  129. void SetPrintContext(GtkPrintContext *context) {m_gpc = context;}
  130. void BeginPrint(wxPrintout *printout, GtkPrintOperation *operation, GtkPrintContext *context);
  131. void DrawPage(wxPrintout *printout, GtkPrintOperation *operation, GtkPrintContext *context, int page_nr);
  132. private:
  133. GtkPrintContext *m_gpc;
  134. wxDC *m_dc;
  135. DECLARE_DYNAMIC_CLASS(wxGtkPrinter)
  136. wxDECLARE_NO_COPY_CLASS(wxGtkPrinter);
  137. };
  138. //----------------------------------------------------------------------------
  139. // wxGtkPrintNativeData
  140. //----------------------------------------------------------------------------
  141. class WXDLLIMPEXP_CORE wxGtkPrintNativeData : public wxPrintNativeDataBase
  142. {
  143. public:
  144. wxGtkPrintNativeData();
  145. virtual ~wxGtkPrintNativeData();
  146. virtual bool TransferTo( wxPrintData &data );
  147. virtual bool TransferFrom( const wxPrintData &data );
  148. virtual bool Ok() const { return IsOk(); }
  149. virtual bool IsOk() const { return true; }
  150. GtkPrintSettings* GetPrintConfig() { return m_config; }
  151. void SetPrintConfig( GtkPrintSettings * config );
  152. GtkPrintOperation* GetPrintJob() { return m_job; }
  153. void SetPrintJob(GtkPrintOperation *job) { m_job = job; }
  154. GtkPrintContext *GetPrintContext() { return m_context; }
  155. void SetPrintContext(GtkPrintContext *context) {m_context = context; }
  156. GtkPageSetup* GetPageSetupFromSettings(GtkPrintSettings* settings);
  157. void SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup);
  158. private:
  159. // NB: m_config is created and owned by us, but the other objects are not
  160. // and their accessors don't change their ref count.
  161. GtkPrintSettings *m_config;
  162. GtkPrintOperation *m_job;
  163. GtkPrintContext *m_context;
  164. DECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData)
  165. };
  166. //-----------------------------------------------------------------------------
  167. // wxGtkPrinterDC
  168. //-----------------------------------------------------------------------------
  169. class WXDLLIMPEXP_CORE wxGtkPrinterDCImpl : public wxDCImpl
  170. {
  171. public:
  172. wxGtkPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data );
  173. virtual ~wxGtkPrinterDCImpl();
  174. bool Ok() const { return IsOk(); }
  175. bool IsOk() const;
  176. virtual void* GetCairoContext() const;
  177. virtual void* GetHandle() const;
  178. bool CanDrawBitmap() const { return true; }
  179. void Clear();
  180. void SetFont( const wxFont& font );
  181. void SetPen( const wxPen& pen );
  182. void SetBrush( const wxBrush& brush );
  183. void SetLogicalFunction( wxRasterOperationMode function );
  184. void SetBackground( const wxBrush& brush );
  185. void DestroyClippingRegion();
  186. bool StartDoc(const wxString& message);
  187. void EndDoc();
  188. void StartPage();
  189. void EndPage();
  190. wxCoord GetCharHeight() const;
  191. wxCoord GetCharWidth() const;
  192. bool CanGetTextExtent() const { return true; }
  193. wxSize GetPPI() const;
  194. virtual int GetDepth() const { return 24; }
  195. void SetBackgroundMode(int mode);
  196. void SetPalette(const wxPalette& WXUNUSED(palette)) { }
  197. void SetResolution(int ppi);
  198. // overridden for wxPrinterDC Impl
  199. virtual int GetResolution() const;
  200. virtual wxRect GetPaperRect() const;
  201. protected:
  202. bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col,
  203. wxFloodFillStyle style=wxFLOOD_SURFACE );
  204. void DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter);
  205. void DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection = wxEAST);
  206. bool DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const;
  207. void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
  208. void DoCrossHair(wxCoord x, wxCoord y);
  209. void DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc);
  210. void DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea);
  211. void DoDrawPoint(wxCoord x, wxCoord y);
  212. void DoDrawLines(int n, const wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0);
  213. void DoDrawPolygon(int n, const wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, wxPolygonFillMode fillStyle=wxODDEVEN_RULE);
  214. void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, wxPolygonFillMode fillStyle=wxODDEVEN_RULE);
  215. void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
  216. void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20.0);
  217. void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
  218. #if wxUSE_SPLINES
  219. void DoDrawSpline(const wxPointList *points);
  220. #endif
  221. bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
  222. wxDC *source, wxCoord xsrc, wxCoord ysrc,
  223. wxRasterOperationMode rop = wxCOPY, bool useMask = false,
  224. wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
  225. void DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y );
  226. void DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask = false );
  227. void DoDrawText(const wxString& text, wxCoord x, wxCoord y );
  228. void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
  229. void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
  230. void DoSetDeviceClippingRegion( const wxRegion &WXUNUSED(clip) )
  231. {
  232. wxFAIL_MSG( "not implemented" );
  233. }
  234. void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
  235. wxCoord *descent = NULL,
  236. wxCoord *externalLeading = NULL,
  237. const wxFont *theFont = NULL ) const;
  238. void DoGetSize(int* width, int* height) const;
  239. void DoGetSizeMM(int *width, int *height) const;
  240. wxPrintData& GetPrintData() { return m_printData; }
  241. void SetPrintData(const wxPrintData& data);
  242. private:
  243. wxPrintData m_printData;
  244. PangoContext *m_context;
  245. PangoLayout *m_layout;
  246. PangoFontDescription *m_fontdesc;
  247. cairo_t *m_cairo;
  248. unsigned char m_currentRed;
  249. unsigned char m_currentGreen;
  250. unsigned char m_currentBlue;
  251. unsigned char m_currentAlpha;
  252. GtkPrintContext *m_gpc;
  253. int m_resolution;
  254. double m_PS2DEV;
  255. double m_DEV2PS;
  256. DECLARE_DYNAMIC_CLASS(wxGtkPrinterDCImpl)
  257. wxDECLARE_NO_COPY_CLASS(wxGtkPrinterDCImpl);
  258. };
  259. // ----------------------------------------------------------------------------
  260. // wxGtkPrintPreview: programmer creates an object of this class to preview a
  261. // wxPrintout.
  262. // ----------------------------------------------------------------------------
  263. class WXDLLIMPEXP_CORE wxGtkPrintPreview : public wxPrintPreviewBase
  264. {
  265. public:
  266. wxGtkPrintPreview(wxPrintout *printout,
  267. wxPrintout *printoutForPrinting = NULL,
  268. wxPrintDialogData *data = NULL);
  269. wxGtkPrintPreview(wxPrintout *printout,
  270. wxPrintout *printoutForPrinting,
  271. wxPrintData *data);
  272. virtual ~wxGtkPrintPreview();
  273. virtual bool Print(bool interactive);
  274. virtual void DetermineScaling();
  275. private:
  276. void Init(wxPrintout *printout,
  277. wxPrintout *printoutForPrinting,
  278. wxPrintData *data);
  279. // resolution to use in DPI
  280. int m_resolution;
  281. DECLARE_CLASS(wxGtkPrintPreview)
  282. };
  283. #endif // wxUSE_GTKPRINT
  284. #endif // _WX_GTK_PRINT_H_