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