]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/gnome/gprint.h
Added support for native print preview (GNOME)
[wxWidgets.git] / include / wx / gtk / 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 bool m_native_preview;
154
155 private:
156 DECLARE_DYNAMIC_CLASS(wxGnomePrinter)
157 DECLARE_NO_COPY_CLASS(wxGnomePrinter)
158 };
159
160 //-----------------------------------------------------------------------------
161 // wxGnomePrintDC
162 //-----------------------------------------------------------------------------
163
164 class wxGnomePrintDC: public wxDC
165 {
166 public:
167 wxGnomePrintDC( wxGnomePrinter *printer );
168 ~wxGnomePrintDC();
169
170 bool Ok() const;
171
172 virtual void BeginDrawing() {}
173 virtual void EndDrawing() {}
174
175 bool DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style=wxFLOOD_SURFACE );
176 bool DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const;
177 void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
178 void DoCrossHair(wxCoord x, wxCoord y);
179 void DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc);
180 void DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea);
181 void DoDrawPoint(wxCoord x, wxCoord y);
182 void DoDrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0);
183 void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
184 void DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0, int fillStyle=wxODDEVEN_RULE);
185 void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
186 void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20.0);
187 void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
188 void DoDrawSpline(wxList *points);
189
190 bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
191 wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop = wxCOPY, bool useMask = false,
192 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
193 void DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y );
194 void DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask = false );
195 bool CanDrawBitmap() const { return true; }
196
197 void DoDrawText(const wxString& text, wxCoord x, wxCoord y );
198 void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
199 void Clear();
200 void SetFont( const wxFont& font );
201 void SetPen( const wxPen& pen );
202 void SetBrush( const wxBrush& brush );
203 void SetLogicalFunction( int function );
204 void SetBackground( const wxBrush& brush );
205
206 void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
207 void DestroyClippingRegion();
208 void DoSetClippingRegionAsRegion( const wxRegion &WXUNUSED(clip) ) { }
209
210 bool StartDoc(const wxString& message);
211 void EndDoc();
212 void StartPage();
213 void EndPage();
214
215 wxCoord GetCharHeight() const;
216 wxCoord GetCharWidth() const;
217 bool CanGetTextExtent() const { return true; }
218 void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
219 wxCoord *descent = (wxCoord *) NULL,
220 wxCoord *externalLeading = (wxCoord *) NULL,
221 wxFont *theFont = (wxFont *) NULL ) const;
222
223 void DoGetSize(int* width, int* height) const;
224 void DoGetSizeMM(int *width, int *height) const;
225 wxSize GetPPI() const;
226 void SetAxisOrientation( bool xLeftRight, bool yBottomUp );
227 void SetDeviceOrigin( wxCoord x, wxCoord y );
228
229 virtual int GetDepth() const { return 24; }
230
231 void SetBackgroundMode(int WXUNUSED(mode)) { }
232 void SetPalette(const wxPalette& WXUNUSED(palette)) { }
233
234 wxPrintData& GetPrintData() { return m_printData; }
235 void SetPrintData(const wxPrintData& data) { m_printData = data; }
236
237 static void SetResolution(int ppi);
238 static int GetResolution();
239
240 private:
241 static float ms_PSScaleFactor;
242
243 private:
244 PangoContext *m_context;
245 PangoLayout *m_layout;
246 PangoFontDescription *m_fontdesc;
247
248 unsigned char m_currentRed;
249 unsigned char m_currentGreen;
250 unsigned char m_currentBlue;
251 wxPrintData m_printData;
252
253 wxGnomePrinter *m_printer;
254 GnomePrintContext *m_gpc;
255
256 private:
257 wxCoord XDEV2LOG(wxCoord x) const
258 {
259 wxCoord new_x = x - m_deviceOriginX;
260 if (new_x > 0)
261 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
262 else
263 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
264 }
265 wxCoord XDEV2LOGREL(wxCoord x) const
266 {
267 if (x > 0)
268 return (wxCoord)((double)(x) / m_scaleX + 0.5);
269 else
270 return (wxCoord)((double)(x) / m_scaleX - 0.5);
271 }
272 wxCoord YDEV2LOG(wxCoord y) const
273 {
274 wxCoord new_y = y - m_deviceOriginY;
275 if (new_y > 0)
276 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
277 else
278 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
279 }
280 wxCoord YDEV2LOGREL(wxCoord y) const
281 {
282 if (y > 0)
283 return (wxCoord)((double)(y) / m_scaleY + 0.5);
284 else
285 return (wxCoord)((double)(y) / m_scaleY - 0.5);
286 }
287 wxCoord XLOG2DEV(wxCoord x) const
288 {
289 wxCoord new_x = x - m_logicalOriginX;
290 if (new_x > 0)
291 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
292 else
293 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
294 }
295 wxCoord XLOG2DEVREL(wxCoord x) const
296 {
297 if (x > 0)
298 return (wxCoord)((double)(x) * m_scaleX + 0.5);
299 else
300 return (wxCoord)((double)(x) * m_scaleX - 0.5);
301 }
302 wxCoord YLOG2DEV(wxCoord y) const
303 {
304 wxCoord new_y = y - m_logicalOriginY;
305 if (new_y > 0)
306 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
307 else
308 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
309 }
310 wxCoord YLOG2DEVREL(wxCoord y) const
311 {
312 if (y > 0)
313 return (wxCoord)((double)(y) * m_scaleY + 0.5);
314 else
315 return (wxCoord)((double)(y) * m_scaleY - 0.5);
316 }
317 private:
318 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC)
319 DECLARE_NO_COPY_CLASS(wxGnomePrintDC)
320 };
321
322 #endif
323 // wxUSE_LIBGNOMEPRINT
324
325 #endif