]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/print.h
First update patch for GTK+ print
[wxWidgets.git] / include / wx / gtk / print.h
CommitLineData
fa034c45
RR
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: print.h,v 1 2007-08-25 05:44:44 PC Exp $
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"
d494613a
RR
22#include "wx/cairo.h"
23
fa034c45
RR
24
25typedef struct _GtkPrintOperation GtkPrintOperation;
26typedef struct _GtkPrintContext GtkPrintContext;
27typedef struct _GtkPrintSettings GtkPrintSettings;
28typedef struct _GtkPageSetup GtkPageSetup;
29
30typedef struct _cairo cairo_t;
31
32//----------------------------------------------------------------------------
33// wxGtkPrintFactory
34//----------------------------------------------------------------------------
35
36class wxGtkPrintFactory: public wxPrintFactory
37{
38public:
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 wxDC* CreatePrinterDC( 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
73class WXDLLIMPEXP_CORE wxGtkPrintDialog: public wxPrintDialogBase
74{
75public:
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
98protected:
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
107private:
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
120class WXDLLIMPEXP_CORE wxGtkPageSetupDialog: public wxPageSetupDialogBase
121{
122public:
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
135protected:
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
144private:
145 wxPageSetupDialogData m_pageDialogData;
146 wxWindow *m_parent;
147
148 DECLARE_DYNAMIC_CLASS(wxGtkPageSetupDialog)
149};
150
151//----------------------------------------------------------------------------
152// wxGtkPrinter
153//----------------------------------------------------------------------------
154
155class WXDLLIMPEXP_CORE wxGtkPrinter : public wxPrinterBase
156{
157public:
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
172private:
173 GtkPrintContext *m_gpc;
174 bool m_showDialog;
175 wxDC *m_dc;
176
177 DECLARE_DYNAMIC_CLASS(wxGtkPrinter)
178 DECLARE_NO_COPY_CLASS(wxGtkPrinter)
179};
180
181//----------------------------------------------------------------------------
182// wxGtkPrintNativeData
183//----------------------------------------------------------------------------
184
185class WXDLLIMPEXP_CORE wxGtkPrintNativeData : public wxPrintNativeDataBase
186{
187public:
188 wxGtkPrintNativeData();
189 virtual ~wxGtkPrintNativeData();
190
191 virtual bool TransferTo( wxPrintData &data );
192 virtual bool TransferFrom( const wxPrintData &data );
193
194 virtual bool Ok() const { return IsOk(); }
195 virtual bool IsOk() const { return true; }
196
197 GtkPrintSettings* GetPrintConfig() { return m_config; }
198 void SetPrintConfig( GtkPrintSettings * config );
199
200 void SetPrintJob( GtkPrintOperation *job ) { m_job = job; }
201 GtkPrintOperation* GetPrintJob() { return m_job; }
202
203 GtkPrintContext *GetPrintContext() { return m_context; }
204 void SetPrintContext(GtkPrintContext *context) {m_context = context; }
205
206
207 GtkPageSetup* GetPageSetupFromSettings(GtkPrintSettings* settings);
208 void SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup);
209
210private:
211 GtkPrintSettings *m_config;
212 GtkPrintOperation *m_job;
213 GtkPrintContext *m_context;
214
215 DECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData)
216};
217
218//-----------------------------------------------------------------------------
219// wxGtkPrintDC
220//-----------------------------------------------------------------------------
221
222class WXDLLIMPEXP_CORE wxGtkPrintDC: public wxDC
223{
224public:
225 wxGtkPrintDC( const wxPrintData& data );
226 virtual ~wxGtkPrintDC();
227
228 bool Ok() const { return IsOk(); }
229 bool IsOk() const;
230
231 bool CanDrawBitmap() const { return true; }
232 void Clear();
233 void SetFont( const wxFont& font );
234 void SetPen( const wxPen& pen );
235 void SetBrush( const wxBrush& brush );
236 void SetLogicalFunction( int function );
237 void SetBackground( const wxBrush& brush );
238 void DestroyClippingRegion();
239 bool StartDoc(const wxString& message);
240 void EndDoc();
241 void StartPage();
242 void EndPage();
243 wxCoord GetCharHeight() const;
244 wxCoord GetCharWidth() const;
245 bool CanGetTextExtent() const { return true; }
246 wxSize GetPPI() const;
fa034c45 247 virtual int GetDepth() const { return 24; }
a9312950 248 void SetBackgroundMode(int mode);
fa034c45 249 void SetPalette(const wxPalette& WXUNUSED(palette)) { }
a9312950
RR
250 void SetResolution(int ppi);
251 int GetResolution();
fa034c45
RR
252
253protected:
254 bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style=wxFLOOD_SURFACE );
255 void DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter);
256 void DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection = wxEAST);
257 bool DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const;
258 void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
259 void DoCrossHair(wxCoord x, wxCoord y);
260 void DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc);
261 void DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea);
262 void DoDrawPoint(wxCoord x, wxCoord y);
263 void DoDrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0);
264 void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
265 void DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
266 void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
267 void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20.0);
268 void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
269#if wxUSE_SPLINES
270 void DoDrawSpline(wxList *points);
271#endif // wxUSE_SPLINES
272 bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
273 wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop = wxCOPY, bool useMask = false,
274 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
275 void DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y );
276 void DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask = false );
277 void DoDrawScaledBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, wxCoord w, wxCoord h, bool useMask = false, int quality = wxIMAGE_QUALITY_NORMAL );
278 void DoDrawText(const wxString& text, wxCoord x, wxCoord y );
279 void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
280 void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
281 void DoSetClippingRegionAsRegion( const wxRegion &WXUNUSED(clip) ) { }
282 void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
283 wxCoord *descent = (wxCoord *) NULL,
284 wxCoord *externalLeading = (wxCoord *) NULL,
285 const wxFont *theFont = (wxFont *) NULL ) const;
286 void DoGetSize(int* width, int* height) const;
287 void DoGetSizeMM(int *width, int *height) const;
288
289 wxPrintData& GetPrintData() { return m_printData; }
290 void SetPrintData(const wxPrintData& data);
291
fa034c45 292private:
fa034c45
RR
293 wxPrintData m_printData;
294 PangoContext *m_context;
295 PangoLayout *m_layout;
296 PangoFontDescription *m_fontdesc;
297 cairo_t *m_cairo;
298
299 unsigned char m_currentRed;
300 unsigned char m_currentGreen;
301 unsigned char m_currentBlue;
302 unsigned char m_currentAlpha;
303
a9312950
RR
304 GtkPrintContext *m_gpc;
305 int m_resolution;
306 double m_PS2DEV;
307 double m_DEV2PS;
308
fa034c45
RR
309 DECLARE_DYNAMIC_CLASS(wxGtkPrintDC)
310 DECLARE_NO_COPY_CLASS(wxGtkPrintDC)
311};
312
313// ----------------------------------------------------------------------------
314// wxGtkPrintPreview: programmer creates an object of this class to preview a
315// wxPrintout.
316// ----------------------------------------------------------------------------
317
318class WXDLLIMPEXP_CORE wxGtkPrintPreview : public wxPrintPreviewBase
319{
320public:
321 wxGtkPrintPreview(wxPrintout *printout,
322 wxPrintout *printoutForPrinting = (wxPrintout *) NULL,
323 wxPrintDialogData *data = (wxPrintDialogData *) NULL);
324 wxGtkPrintPreview(wxPrintout *printout,
325 wxPrintout *printoutForPrinting,
326 wxPrintData *data);
327
328 virtual ~wxGtkPrintPreview();
329
330 virtual bool Print(bool interactive);
331 virtual void DetermineScaling();
332
333private:
334 void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
335
336 DECLARE_CLASS(wxGtkPrintPreview)
337};
338
339#endif
340
341#endif