]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/gnome/gprint.h
280380270b158ff133d2484c5970d26ab83315e0
[wxWidgets.git] / include / wx / gtk / gnome / gprint.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/gnome/gprint.h
3 // Author: Robert Roebling
4 // Purpose: GNOME printing support
5 // Created: 09/20/04
6 // RCS-ID: $Id$
7 // Copyright: Robert Roebling
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __gprint_H__
12 #define __gprint_H__
13
14 // Include wxWindows' headers
15
16 #include "wx/defs.h"
17
18 #if wxUSE_LIBGNOMEPRINT
19
20 #include "wx/print.h"
21 #include "wx/printdlg.h"
22 #include "wx/dc.h"
23
24 typedef struct _GnomePrintJob GnomePrintJob;
25 typedef struct _GnomePrintContext GnomePrintContext;
26 typedef struct _GnomePrintConfig GnomePrintConfig;
27
28 //----------------------------------------------------------------------------
29 // wxGnomePrintNativeData
30 //----------------------------------------------------------------------------
31
32 class wxGnomePrintNativeData: public wxPrintNativeDataBase
33 {
34 public:
35 wxGnomePrintNativeData();
36 virtual ~wxGnomePrintNativeData();
37
38 virtual bool TransferTo( wxPrintData &data );
39 virtual bool TransferFrom( const wxPrintData &data );
40
41 virtual bool Ok() const { return IsOk(); }
42 virtual bool IsOk() const { return true; }
43
44 GnomePrintConfig* GetPrintConfig() { return m_config; }
45 void SetPrintJob( GnomePrintJob *job ) { m_job = job; }
46 GnomePrintJob* GetPrintJob() { return m_job; }
47
48
49 private:
50 GnomePrintConfig *m_config;
51 GnomePrintJob *m_job;
52
53 private:
54 DECLARE_DYNAMIC_CLASS(wxGnomePrintNativeData)
55 };
56
57 //----------------------------------------------------------------------------
58 // wxGnomePrintFactory
59 //----------------------------------------------------------------------------
60
61 class wxGnomePrintFactory: public wxPrintFactory
62 {
63 public:
64 virtual wxPrinterBase *CreatePrinter( wxPrintDialogData *data );
65
66 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
67 wxPrintout *printout = NULL,
68 wxPrintDialogData *data = NULL );
69 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
70 wxPrintout *printout,
71 wxPrintData *data );
72
73 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
74 wxPrintDialogData *data = NULL );
75 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
76 wxPrintData *data );
77
78 virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
79 wxPageSetupDialogData * data = NULL );
80
81 virtual bool HasPrintSetupDialog();
82 virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
83 virtual bool HasOwnPrintToFile();
84 virtual bool HasPrinterLine();
85 virtual wxString CreatePrinterLine();
86 virtual bool HasStatusLine();
87 virtual wxString CreateStatusLine();
88
89 virtual wxPrintNativeDataBase *CreatePrintNativeData();
90 };
91
92 //----------------------------------------------------------------------------
93 // wxGnomePrintDialog
94 //----------------------------------------------------------------------------
95
96 class wxGnomePrintDialog: public wxPrintDialogBase
97 {
98 public:
99 wxGnomePrintDialog( wxWindow *parent,
100 wxPrintDialogData* data = NULL );
101 wxGnomePrintDialog( wxWindow *parent, wxPrintData* data);
102 virtual ~wxGnomePrintDialog();
103
104 wxPrintData& GetPrintData()
105 { return m_printDialogData.GetPrintData(); }
106 wxPrintDialogData& GetPrintDialogData()
107 { return m_printDialogData; }
108
109 wxDC *GetPrintDC();
110
111 virtual int ShowModal();
112
113 virtual bool Validate();
114 virtual bool TransferDataToWindow();
115 virtual bool TransferDataFromWindow();
116
117 private:
118 // Implement some base class methods to do nothing to avoid asserts and
119 // GTK warnings, since this is not a real wxDialog.
120 virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
121 int WXUNUSED(width), int WXUNUSED(height),
122 int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
123 virtual void DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y),
124 int WXUNUSED(width), int WXUNUSED(height)) {}
125
126 void Init();
127 wxPrintDialogData m_printDialogData;
128
129 private:
130 DECLARE_DYNAMIC_CLASS(wxGnomePrintDialog)
131 };
132
133 //----------------------------------------------------------------------------
134 // wxGnomePageSetupDialog
135 //----------------------------------------------------------------------------
136
137 class wxGnomePageSetupDialog: public wxPageSetupDialogBase
138 {
139 public:
140 wxGnomePageSetupDialog( wxWindow *parent,
141 wxPageSetupDialogData* data = NULL );
142 virtual ~wxGnomePageSetupDialog();
143
144 virtual wxPageSetupDialogData& GetPageSetupDialogData();
145
146 virtual int ShowModal();
147
148 virtual bool Validate();
149 virtual bool TransferDataToWindow();
150 virtual bool TransferDataFromWindow();
151
152 private:
153 // Implement some base class methods to do nothing to avoid asserts and
154 // GTK warnings, since this is not a real wxDialog.
155 virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
156 int WXUNUSED(width), int WXUNUSED(height),
157 int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
158 virtual void DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y),
159 int WXUNUSED(width), int WXUNUSED(height)) {}
160
161 wxPageSetupDialogData m_pageDialogData;
162
163 private:
164 DECLARE_DYNAMIC_CLASS(wxGnomePageSetupDialog)
165 };
166
167 //----------------------------------------------------------------------------
168 // wxGnomePrinter
169 //----------------------------------------------------------------------------
170
171 class wxGnomePrinter: public wxPrinterBase
172 {
173 public:
174 wxGnomePrinter(wxPrintDialogData *data = NULL);
175 virtual ~wxGnomePrinter();
176
177 virtual bool Print(wxWindow *parent,
178 wxPrintout *printout,
179 bool prompt = true);
180 virtual wxDC* PrintDialog(wxWindow *parent);
181 virtual bool Setup(wxWindow *parent);
182
183 GnomePrintContext *GetPrintContext() { return m_gpc; }
184
185 private:
186 GnomePrintContext *m_gpc;
187 bool m_native_preview;
188
189 private:
190 DECLARE_DYNAMIC_CLASS(wxGnomePrinter)
191 DECLARE_NO_COPY_CLASS(wxGnomePrinter)
192 };
193
194 //-----------------------------------------------------------------------------
195 // wxGnomePrintDC
196 //-----------------------------------------------------------------------------
197
198 class wxGnomePrintDC: public wxDC
199 {
200 public:
201 wxGnomePrintDC( wxGnomePrinter *printer );
202 virtual ~wxGnomePrintDC();
203
204 bool Ok() const { return IsOk(); }
205 bool IsOk() const;
206
207 bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style=wxFLOOD_SURFACE );
208 bool DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const;
209 void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
210 void DoCrossHair(wxCoord x, wxCoord y);
211 void DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc);
212 void DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea);
213 void DoDrawPoint(wxCoord x, wxCoord y);
214 void DoDrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0);
215 void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
216 void DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
217 void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
218 void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20.0);
219 void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
220 #if wxUSE_SPLINES
221 void DoDrawSpline(wxList *points);
222 #endif // wxUSE_SPLINES
223
224 bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
225 wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop = wxCOPY, bool useMask = false,
226 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
227 void DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y );
228 void DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask = false );
229 bool CanDrawBitmap() const { return true; }
230
231 void DoDrawText(const wxString& text, wxCoord x, wxCoord y );
232 void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
233 void Clear();
234 void SetFont( const wxFont& font );
235 void SetPen( const wxPen& pen );
236 void SetBrush( const wxBrush& brush );
237 void SetLogicalFunction( int function );
238 void SetBackground( const wxBrush& brush );
239
240 void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
241 void DestroyClippingRegion();
242 void DoSetClippingRegionAsRegion( const wxRegion &WXUNUSED(clip) ) { }
243
244 bool StartDoc(const wxString& message);
245 void EndDoc();
246 void StartPage();
247 void EndPage();
248
249 wxCoord GetCharHeight() const;
250 wxCoord GetCharWidth() const;
251 bool CanGetTextExtent() const { return true; }
252 void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
253 wxCoord *descent = (wxCoord *) NULL,
254 wxCoord *externalLeading = (wxCoord *) NULL,
255 wxFont *theFont = (wxFont *) NULL ) const;
256
257 void DoGetSize(int* width, int* height) const;
258 void DoGetSizeMM(int *width, int *height) const;
259 wxSize GetPPI() const;
260 void SetAxisOrientation( bool xLeftRight, bool yBottomUp );
261 void SetDeviceOrigin( wxCoord x, wxCoord y );
262
263 virtual int GetDepth() const { return 24; }
264
265 void SetBackgroundMode(int WXUNUSED(mode)) { }
266 void SetPalette(const wxPalette& WXUNUSED(palette)) { }
267
268 wxPrintData& GetPrintData() { return m_printData; }
269 void SetPrintData(const wxPrintData& data) { m_printData = data; }
270
271 static void SetResolution(int ppi);
272 static int GetResolution();
273
274 private:
275 static float ms_PSScaleFactor;
276
277 private:
278 PangoContext *m_context;
279 PangoLayout *m_layout;
280 PangoFontDescription *m_fontdesc;
281
282 unsigned char m_currentRed;
283 unsigned char m_currentGreen;
284 unsigned char m_currentBlue;
285 wxPrintData m_printData;
286
287 wxGnomePrinter *m_printer;
288 GnomePrintContext *m_gpc;
289
290 void makeEllipticalPath(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
291
292 private:
293 wxCoord XDEV2LOG(wxCoord x) const
294 {
295 wxCoord new_x = x - m_deviceOriginX;
296 if (new_x > 0)
297 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
298 else
299 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
300 }
301 wxCoord XDEV2LOGREL(wxCoord x) const
302 {
303 if (x > 0)
304 return (wxCoord)((double)(x) / m_scaleX + 0.5);
305 else
306 return (wxCoord)((double)(x) / m_scaleX - 0.5);
307 }
308 wxCoord YDEV2LOG(wxCoord y) const
309 {
310 wxCoord new_y = y - m_deviceOriginY;
311 if (new_y > 0)
312 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
313 else
314 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
315 }
316 wxCoord YDEV2LOGREL(wxCoord y) const
317 {
318 if (y > 0)
319 return (wxCoord)((double)(y) / m_scaleY + 0.5);
320 else
321 return (wxCoord)((double)(y) / m_scaleY - 0.5);
322 }
323 wxCoord XLOG2DEV(wxCoord x) const
324 {
325 wxCoord new_x = x - m_logicalOriginX;
326 if (new_x > 0)
327 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
328 else
329 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
330 }
331 wxCoord XLOG2DEVREL(wxCoord x) const
332 {
333 if (x > 0)
334 return (wxCoord)((double)(x) * m_scaleX + 0.5);
335 else
336 return (wxCoord)((double)(x) * m_scaleX - 0.5);
337 }
338 wxCoord YLOG2DEV(wxCoord y) const
339 {
340 wxCoord new_y = y - m_logicalOriginY;
341 if (new_y > 0)
342 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
343 else
344 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
345 }
346 wxCoord YLOG2DEVREL(wxCoord y) const
347 {
348 if (y > 0)
349 return (wxCoord)((double)(y) * m_scaleY + 0.5);
350 else
351 return (wxCoord)((double)(y) * m_scaleY - 0.5);
352 }
353 private:
354 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC)
355 DECLARE_NO_COPY_CLASS(wxGnomePrintDC)
356 };
357
358 #endif
359 // wxUSE_LIBGNOMEPRINT
360
361 #endif