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