]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/print.h
virtual method hiding in GTK, so add direct implementation
[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
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
54 virtual wxDCImpl* CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data );
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;
172 wxDC *m_dc;
173
174 DECLARE_DYNAMIC_CLASS(wxGtkPrinter)
175 wxDECLARE_NO_COPY_CLASS(wxGtkPrinter);
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
197 GtkPrintOperation* GetPrintJob() { return m_job; }
198 void SetPrintJob(GtkPrintOperation *job) { m_job = job; }
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:
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.
210 GtkPrintSettings *m_config;
211 GtkPrintOperation *m_job;
212 GtkPrintContext *m_context;
213
214 DECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData)
215 };
216
217 //-----------------------------------------------------------------------------
218 // wxGtkPrinterDC
219 //-----------------------------------------------------------------------------
220
221 class WXDLLIMPEXP_CORE wxGtkPrinterDCImpl : public wxDCImpl
222 {
223 public:
224 wxGtkPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data );
225 virtual ~wxGtkPrinterDCImpl();
226
227 bool Ok() const { return IsOk(); }
228 bool IsOk() const;
229
230 virtual void* GetCairoContext() const;
231 virtual void* GetHandle() const;
232
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 );
238 void SetLogicalFunction( wxRasterOperationMode function );
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;
249 virtual int GetDepth() const { return 24; }
250 void SetBackgroundMode(int mode);
251 void SetPalette(const wxPalette& WXUNUSED(palette)) { }
252 void SetResolution(int ppi);
253
254 // overridden for wxPrinterDC Impl
255 virtual int GetResolution() const;
256 virtual wxRect GetPaperRect() const;
257
258 protected:
259 bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col,
260 wxFloodFillStyle style=wxFLOOD_SURFACE );
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);
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);
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
276 void DoDrawSpline(const wxPointList *points);
277 #endif
278 bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
279 wxDC *source, wxCoord xsrc, wxCoord ysrc,
280 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
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 );
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);
287 void DoSetDeviceClippingRegion( const wxRegion &WXUNUSED(clip) )
288 {
289 wxFAIL_MSG( "not implemented" );
290 }
291 void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
292 wxCoord *descent = NULL,
293 wxCoord *externalLeading = NULL,
294 const wxFont *theFont = NULL ) const;
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
301 private:
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
313 GtkPrintContext *m_gpc;
314 int m_resolution;
315 double m_PS2DEV;
316 double m_DEV2PS;
317
318 DECLARE_DYNAMIC_CLASS(wxGtkPrinterDCImpl)
319 wxDECLARE_NO_COPY_CLASS(wxGtkPrinterDCImpl);
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,
331 wxPrintout *printoutForPrinting = NULL,
332 wxPrintDialogData *data = NULL);
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:
343 void Init(wxPrintout *printout,
344 wxPrintout *printoutForPrinting,
345 wxPrintData *data);
346
347 // resolution to use in DPI
348 int m_resolution;
349
350 DECLARE_CLASS(wxGtkPrintPreview)
351 };
352
353 #endif // wxUSE_GTKPRINT
354
355 #endif // _WX_GTK_PRINT_H_