]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/gnome/gprint.h
Use native printing dialog for wxPrintDialog,
[wxWidgets.git] / include / wx / gtk1 / gnome / gprint.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gprint.h
3 // Author: Robert Roebling
4 // Purpose: GNOME printing support
5 // Created: 09/20/04
6 // Copyright: Robert Roebling
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef __gprint_H__
11 #define __gprint_H__
12
13 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
14 #pragma interface
15 #endif
16
17 // Include wxWindows' headers
18
19 #ifndef WX_PRECOMP
20 #include <wx/wx.h>
21 #endif
22
23 #if wxUSE_LIBGNOMEPRINT
24
25 #include "wx/print.h"
26 #include "wx/prntbase.h"
27 #include "wx/printdlg.h"
28
29 typedef struct _GnomePrintJob GnomePrintJob;
30 typedef struct _GnomePrintContext GnomePrintContext;
31 typedef struct _GnomePrintConfig GnomePrintConfig;
32
33 //----------------------------------------------------------------------------
34 // wxGnomePrintNativeData
35 //----------------------------------------------------------------------------
36
37 class wxGnomePrintNativeData: public wxPrintNativeDataBase
38 {
39 public:
40 wxGnomePrintNativeData();
41 virtual ~wxGnomePrintNativeData();
42
43 virtual bool TransferTo( wxPrintData &data );
44 virtual bool TransferFrom( const wxPrintData &data );
45
46 virtual bool Ok() const { return true; }
47
48 GnomePrintConfig* GetPrintConfig() { return m_config; }
49 GnomePrintJob* GetPrintJob() { return m_job; }
50
51
52 private:
53 GnomePrintConfig *m_config;
54 GnomePrintJob *m_job;
55
56 private:
57 DECLARE_DYNAMIC_CLASS(wxGnomePrintNativeData)
58 };
59
60 //----------------------------------------------------------------------------
61 // wxGnomePrintFactory
62 //----------------------------------------------------------------------------
63
64 class wxGnomePrintFactory: public wxPrintFactory
65 {
66 public:
67 virtual wxPrinterBase *CreatePrinter( wxPrintDialogData *data );
68
69 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
70 wxPrintout *printout = NULL,
71 wxPrintDialogData *data = NULL );
72 virtual wxPrintPreviewBase *CreatePrintPreview( wxPrintout *preview,
73 wxPrintout *printout,
74 wxPrintData *data );
75
76 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
77 wxPrintDialogData *data = NULL );
78 virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
79 wxPrintData *data );
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 = (wxPrintDialogData*)NULL );
101 wxGnomePrintDialog( wxWindow *parent, wxPrintData* data);
102 ~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 // wxGnomePrinter
135 //----------------------------------------------------------------------------
136
137 class wxGnomePrinter: public wxPrinterBase
138 {
139 public:
140 wxGnomePrinter(wxPrintDialogData *data = NULL);
141 virtual ~wxGnomePrinter();
142
143 virtual bool Print(wxWindow *parent,
144 wxPrintout *printout,
145 bool prompt = true);
146 virtual wxDC* PrintDialog(wxWindow *parent);
147 virtual bool Setup(wxWindow *parent);
148
149 GnomePrintContext *GetPrintContext() { return m_gpc; }
150
151 private:
152 GnomePrintContext *m_gpc;
153
154 private:
155 DECLARE_DYNAMIC_CLASS(wxGnomePrinter)
156 DECLARE_NO_COPY_CLASS(wxGnomePrinter)
157 };
158
159 //-----------------------------------------------------------------------------
160 // wxGnomePrintDC
161 //-----------------------------------------------------------------------------
162
163 class wxGnomePrintDC: public wxDC
164 {
165 public:
166 wxGnomePrintDC( wxGnomePrinter *printer );
167 ~wxGnomePrintDC();
168
169 bool Ok() const;
170
171 virtual void BeginDrawing() {}
172 virtual void EndDrawing() {}
173
174 bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style=wxFLOOD_SURFACE );
175 bool DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const;
176 void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
177 void DoCrossHair(wxCoord x, wxCoord y);
178 void DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc);
179 void DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea);
180 void DoDrawPoint(wxCoord x, wxCoord y);
181 void DoDrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0);
182 void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
183 void DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
184 void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
185 void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20.0);
186 void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
187 void DoDrawSpline(wxList *points);
188
189 bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
190 wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop = wxCOPY, bool useMask = false,
191 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
192 void DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y );
193 void DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask = false );
194 bool CanDrawBitmap() const { return true; }
195
196 void DoDrawText(const wxString& text, wxCoord x, wxCoord y );
197 void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
198 void Clear();
199 void SetFont( const wxFont& font );
200 void SetPen( const wxPen& pen );
201 void SetBrush( const wxBrush& brush );
202 void SetLogicalFunction( int function );
203 void SetBackground( const wxBrush& brush );
204
205 void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
206 void DestroyClippingRegion();
207 void DoSetClippingRegionAsRegion( const wxRegion &WXUNUSED(clip) ) { }
208
209 bool StartDoc(const wxString& message);
210 void EndDoc();
211 void StartPage();
212 void EndPage();
213
214 wxCoord GetCharHeight() const;
215 wxCoord GetCharWidth() const;
216 bool CanGetTextExtent() const { return true; }
217 void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
218 wxCoord *descent = (wxCoord *) NULL,
219 wxCoord *externalLeading = (wxCoord *) NULL,
220 wxFont *theFont = (wxFont *) NULL ) const;
221
222 void DoGetSize(int* width, int* height) const;
223 void DoGetSizeMM(int *width, int *height) const;
224 wxSize GetPPI() const;
225 void SetAxisOrientation( bool xLeftRight, bool yBottomUp );
226 void SetDeviceOrigin( wxCoord x, wxCoord y );
227
228 virtual int GetDepth() const { return 24; }
229
230 void SetBackgroundMode(int WXUNUSED(mode)) { }
231 void SetPalette(const wxPalette& WXUNUSED(palette)) { }
232
233 wxPrintData& GetPrintData() { return m_printData; }
234 void SetPrintData(const wxPrintData& data) { m_printData = data; }
235
236 static void SetResolution(int ppi);
237 static int GetResolution();
238
239 private:
240 static float ms_PSScaleFactor;
241
242 private:
243 PangoContext *m_context;
244 PangoLayout *m_layout;
245 PangoFontDescription *m_fontdesc;
246
247 unsigned char m_currentRed;
248 unsigned char m_currentGreen;
249 unsigned char m_currentBlue;
250 wxPrintData m_printData;
251
252 wxGnomePrinter *m_printer;
253 GnomePrintContext *m_gpc;
254
255 private:
256 wxCoord XDEV2LOG(wxCoord x) const
257 {
258 wxCoord new_x = x - m_deviceOriginX;
259 if (new_x > 0)
260 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
261 else
262 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
263 }
264 wxCoord XDEV2LOGREL(wxCoord x) const
265 {
266 if (x > 0)
267 return (wxCoord)((double)(x) / m_scaleX + 0.5);
268 else
269 return (wxCoord)((double)(x) / m_scaleX - 0.5);
270 }
271 wxCoord YDEV2LOG(wxCoord y) const
272 {
273 wxCoord new_y = y - m_deviceOriginY;
274 if (new_y > 0)
275 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
276 else
277 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
278 }
279 wxCoord YDEV2LOGREL(wxCoord y) const
280 {
281 if (y > 0)
282 return (wxCoord)((double)(y) / m_scaleY + 0.5);
283 else
284 return (wxCoord)((double)(y) / m_scaleY - 0.5);
285 }
286 wxCoord XLOG2DEV(wxCoord x) const
287 {
288 wxCoord new_x = x - m_logicalOriginX;
289 if (new_x > 0)
290 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
291 else
292 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
293 }
294 wxCoord XLOG2DEVREL(wxCoord x) const
295 {
296 if (x > 0)
297 return (wxCoord)((double)(x) * m_scaleX + 0.5);
298 else
299 return (wxCoord)((double)(x) * m_scaleX - 0.5);
300 }
301 wxCoord YLOG2DEV(wxCoord y) const
302 {
303 wxCoord new_y = y - m_logicalOriginY;
304 if (new_y > 0)
305 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
306 else
307 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
308 }
309 wxCoord YLOG2DEVREL(wxCoord y) const
310 {
311 if (y > 0)
312 return (wxCoord)((double)(y) * m_scaleY + 0.5);
313 else
314 return (wxCoord)((double)(y) * m_scaleY - 0.5);
315 }
316 private:
317 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC)
318 DECLARE_NO_COPY_CLASS(wxGnomePrintDC)
319 };
320
321 #endif
322 // wxUSE_LIBGNOMEPRINT
323
324 #endif