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