]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/print.h
Make a slider control created with a particular size/position adjust itself to the...
[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: print.h,v 1 2007-08-25 05:44:44 PC Exp $
7 // Copyright: (c) 2007 wxWidgets development team
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 wxDC* CreatePrinterDC( 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 bool m_showDialog;
173 wxDC *m_dc;
174
175 DECLARE_DYNAMIC_CLASS(wxGtkPrinter)
176 DECLARE_NO_COPY_CLASS(wxGtkPrinter)
177 };
178
179 //----------------------------------------------------------------------------
180 // wxGtkPrintNativeData
181 //----------------------------------------------------------------------------
182
183 class WXDLLIMPEXP_CORE wxGtkPrintNativeData : public wxPrintNativeDataBase
184 {
185 public:
186 wxGtkPrintNativeData();
187 virtual ~wxGtkPrintNativeData();
188
189 virtual bool TransferTo( wxPrintData &data );
190 virtual bool TransferFrom( const wxPrintData &data );
191
192 virtual bool Ok() const { return IsOk(); }
193 virtual bool IsOk() const { return true; }
194
195 GtkPrintSettings* GetPrintConfig() { return m_config; }
196 void SetPrintConfig( GtkPrintSettings * config );
197
198 void SetPrintJob( GtkPrintOperation *job ) { m_job = job; }
199 GtkPrintOperation* GetPrintJob() { return m_job; }
200
201 GtkPrintContext *GetPrintContext() { return m_context; }
202 void SetPrintContext(GtkPrintContext *context) {m_context = context; }
203
204
205 GtkPageSetup* GetPageSetupFromSettings(GtkPrintSettings* settings);
206 void SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup);
207
208 private:
209 GtkPrintSettings *m_config;
210 GtkPrintOperation *m_job;
211 GtkPrintContext *m_context;
212
213 DECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData)
214 };
215
216 //-----------------------------------------------------------------------------
217 // wxGtkPrintDC
218 //-----------------------------------------------------------------------------
219
220 class WXDLLIMPEXP_CORE wxGtkPrintDC: public wxDC
221 {
222 public:
223 wxGtkPrintDC( const wxPrintData& data );
224 virtual ~wxGtkPrintDC();
225
226 bool Ok() const { return IsOk(); }
227 bool IsOk() const;
228
229 bool CanDrawBitmap() const { return true; }
230 void Clear();
231 void SetFont( const wxFont& font );
232 void SetPen( const wxPen& pen );
233 void SetBrush( const wxBrush& brush );
234 void SetLogicalFunction( int function );
235 void SetBackground( const wxBrush& brush );
236 void DestroyClippingRegion();
237 bool StartDoc(const wxString& message);
238 void EndDoc();
239 void StartPage();
240 void EndPage();
241 wxCoord GetCharHeight() const;
242 wxCoord GetCharWidth() const;
243 bool CanGetTextExtent() const { return true; }
244 wxSize GetPPI() const;
245 void SetLogicalOrigin( wxCoord x, wxCoord y );
246 void SetDeviceOrigin( wxCoord x, wxCoord y );
247 virtual int GetDepth() const { return 24; }
248 void SetBackgroundMode(int WXUNUSED(mode));
249 void SetPalette(const wxPalette& WXUNUSED(palette)) { }
250 static void SetResolution(int ppi);
251 static int GetResolution();
252 void DrawScaledBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, wxCoord w, wxCoord h,
253 bool useMask = false, int quality = wxIMAGE_QUALITY_NORMAL)
254 { DoDrawScaledBitmap( bmp, x, y, w, h, useMask, quality ); }
255 void DrawScaledBitmap(const wxBitmap &bmp, const wxPoint& pt, const wxSize& sz,
256 bool useMask = false, int quality = wxIMAGE_QUALITY_NORMAL)
257 { DoDrawScaledBitmap( bmp, pt.x, pt.y, sz.x, sz.y, useMask, quality ); }
258 void DrawScaledBitmap(const wxBitmap &bmp, const wxRect& rect,
259 bool useMask = false, int quality = wxIMAGE_QUALITY_NORMAL)
260 { DoDrawScaledBitmap( bmp, rect.x, rect.y, rect.width, rect.height, useMask, quality ); }
261
262 protected:
263 bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style=wxFLOOD_SURFACE );
264 void DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter);
265 void DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection = wxEAST);
266 bool DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const;
267 void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
268 void DoCrossHair(wxCoord x, wxCoord y);
269 void DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc);
270 void DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea);
271 void DoDrawPoint(wxCoord x, wxCoord y);
272 void DoDrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0);
273 void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
274 void DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
275 void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
276 void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20.0);
277 void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
278 #if wxUSE_SPLINES
279 void DoDrawSpline(wxList *points);
280 #endif // wxUSE_SPLINES
281 bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
282 wxDC *source, wxCoord xsrc, wxCoord ysrc, int 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 DoDrawScaledBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, wxCoord w, wxCoord h, bool useMask = false, int quality = wxIMAGE_QUALITY_NORMAL );
287 void DoDrawText(const wxString& text, wxCoord x, wxCoord y );
288 void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
289 void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
290 void DoSetClippingRegionAsRegion( const wxRegion &WXUNUSED(clip) ) { }
291 void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
292 wxCoord *descent = (wxCoord *) NULL,
293 wxCoord *externalLeading = (wxCoord *) NULL,
294 const wxFont *theFont = (wxFont *) 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 void ComputeScaleAndOrigin();
302
303 private:
304 static float ms_PSScaleFactor;
305
306 wxPrintData m_printData;
307 PangoContext *m_context;
308 PangoLayout *m_layout;
309 PangoFontDescription *m_fontdesc;
310 cairo_t *m_cairo;
311
312 unsigned char m_currentRed;
313 unsigned char m_currentGreen;
314 unsigned char m_currentBlue;
315 unsigned char m_currentAlpha;
316
317 int m_deviceOffsetY;
318 int m_deviceOffsetX;
319
320 GtkPrintContext *m_gpc;
321 static int ms_resolution;
322
323 wxCoord DeviceToLogicalX(wxCoord x) const
324 {
325 int addValue = 0;
326 if (m_signX == -1) addValue = m_deviceOffsetX - m_deviceOriginX; // right to left
327 else addValue = m_deviceOriginX;// left to right
328 return (wxCoord) ((double)(x - addValue) * m_signX + m_logicalOriginX);
329 }
330 wxCoord DeviceToLogicalXRel(wxCoord x) const
331 {
332 return x;
333 }
334 wxCoord DeviceToLogicalY(wxCoord y) const
335 {
336 int addValue = 0;
337 if (m_signY == -1) addValue = m_deviceOffsetY - m_deviceOriginY; // bottom to up
338 else addValue = m_deviceOriginY;// up to bottom
339 return (wxCoord) ((double)(y - addValue) * m_signY + m_logicalOriginY);
340 }
341 wxCoord DeviceToLogicalYRel(wxCoord y) const
342 {
343 return y;
344 }
345 wxCoord LogicalToDeviceX(wxCoord x) const
346 {
347 int addValue = 0;
348 if (m_signX == -1) addValue = m_deviceOffsetX - m_deviceOriginX; // right to left
349 else addValue = m_deviceOriginX;// left to right
350 return (wxCoord) ((double)(x - m_logicalOriginX) * m_signX + addValue);
351 }
352 wxCoord LogicalToDeviceXRel(wxCoord x) const
353 {
354 return x;
355 }
356 wxCoord LogicalToDeviceY(wxCoord y) const
357 {
358 int addValue = 0;
359 if (m_signY == -1) addValue = m_deviceOffsetY - m_deviceOriginY; // bottom to up
360 else addValue = m_deviceOriginY;// up to bottom
361 return (wxCoord) ((double)(y - m_logicalOriginY) * m_signY + addValue);
362 }
363 wxCoord LogicalToDeviceYRel(wxCoord y) const
364 {
365 return y;
366 }
367
368 DECLARE_DYNAMIC_CLASS(wxGtkPrintDC)
369 DECLARE_NO_COPY_CLASS(wxGtkPrintDC)
370 };
371
372 // ----------------------------------------------------------------------------
373 // wxGtkPrintPreview: programmer creates an object of this class to preview a
374 // wxPrintout.
375 // ----------------------------------------------------------------------------
376
377 class WXDLLIMPEXP_CORE wxGtkPrintPreview : public wxPrintPreviewBase
378 {
379 public:
380 wxGtkPrintPreview(wxPrintout *printout,
381 wxPrintout *printoutForPrinting = (wxPrintout *) NULL,
382 wxPrintDialogData *data = (wxPrintDialogData *) NULL);
383 wxGtkPrintPreview(wxPrintout *printout,
384 wxPrintout *printoutForPrinting,
385 wxPrintData *data);
386
387 virtual ~wxGtkPrintPreview();
388
389 virtual bool Print(bool interactive);
390 virtual void DetermineScaling();
391
392 private:
393 void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
394
395 DECLARE_CLASS(wxGtkPrintPreview)
396 };
397
398 #endif
399
400 #endif