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