]>
Commit | Line | Data |
---|---|---|
ff910433 | 1 | ///////////////////////////////////////////////////////////////////////////// |
389076f1 | 2 | // Name: src/gtk/gnome/gprint.cpp |
f85b45fb RR |
3 | // Author: Robert Roebling |
4 | // Purpose: Implement GNOME printing support | |
5 | // Created: 09/20/04 | |
389076f1 | 6 | // RCS-ID: $Id$ |
f85b45fb RR |
7 | // Copyright: Robert Roebling |
8 | // Licence: wxWindows Licence | |
ff910433 RR |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
ff910433 RR |
11 | // For compilers that support precompilation, includes "wx/wx.h". |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
7c72311f RR |
18 | #if wxUSE_LIBGNOMEPRINT |
19 | ||
09a09455 PC |
20 | #include "wx/gtk/gnome/gprint.h" |
21 | ||
e4db172a WS |
22 | #ifndef WX_PRECOMP |
23 | #include "wx/log.h" | |
f38924e8 | 24 | #include "wx/dcmemory.h" |
923d28da | 25 | #include "wx/icon.h" |
18680f86 | 26 | #include "wx/math.h" |
bceff574 | 27 | #include "wx/image.h" |
02761f6c | 28 | #include "wx/module.h" |
e4db172a WS |
29 | #endif |
30 | ||
ff910433 | 31 | #include "wx/fontutil.h" |
ff910433 | 32 | #include "wx/gtk/private.h" |
c6efd6e0 | 33 | #include "wx/dynlib.h" |
459dbfc0 | 34 | #include "wx/paper.h" |
ff910433 RR |
35 | |
36 | #include <libgnomeprint/gnome-print.h> | |
37 | #include <libgnomeprint/gnome-print-pango.h> | |
06cfd325 | 38 | #include <libgnomeprint/gnome-print-config.h> |
ff910433 | 39 | #include <libgnomeprintui/gnome-print-dialog.h> |
0be7709e | 40 | #include <libgnomeprintui/gnome-print-job-preview.h> |
08680429 | 41 | #include <libgnomeprintui/gnome-print-paper-selector.h> |
ff910433 | 42 | |
09a09455 PC |
43 | #include "wx/link.h" |
44 | wxFORCE_LINK_THIS_MODULE(gnome_print) | |
d6c6acd6 | 45 | |
c6efd6e0 RR |
46 | //---------------------------------------------------------------------------- |
47 | // wxGnomePrintLibrary | |
48 | //---------------------------------------------------------------------------- | |
49 | ||
c6efd6e0 RR |
50 | class wxGnomePrintLibrary |
51 | { | |
52 | public: | |
53 | wxGnomePrintLibrary(); | |
54 | ~wxGnomePrintLibrary(); | |
389076f1 | 55 | |
c6efd6e0 | 56 | bool IsOk(); |
6950be01 | 57 | private: |
ced3df77 | 58 | bool InitializeMethods(); |
389076f1 | 59 | |
ced3df77 VZ |
60 | wxDynamicLibrary m_libGnomePrint; |
61 | wxDynamicLibrary m_libGnomePrintUI; | |
62 | ||
63 | // only true if we successfully loaded both libraries | |
64 | // | |
65 | // don't rename this field, it's used by wxDL_XXX macros internally | |
66 | bool m_ok; | |
c6efd6e0 RR |
67 | |
68 | public: | |
389076f1 | 69 | wxDL_METHOD_DEFINE( gint, gnome_print_newpath, |
c6efd6e0 | 70 | (GnomePrintContext *pc), (pc), 0 ) |
389076f1 | 71 | wxDL_METHOD_DEFINE( gint, gnome_print_moveto, |
c6efd6e0 | 72 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) |
389076f1 | 73 | wxDL_METHOD_DEFINE( gint, gnome_print_lineto, |
c6efd6e0 | 74 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) |
389076f1 | 75 | wxDL_METHOD_DEFINE( gint, gnome_print_arcto, |
16744532 | 76 | (GnomePrintContext *pc, gdouble x, gdouble y, gdouble radius, gdouble angle1, gdouble angle2, gint direction ), (pc, x, y, radius, angle1, angle2, direction), 0 ) |
389076f1 | 77 | wxDL_METHOD_DEFINE( gint, gnome_print_curveto, |
c6efd6e0 | 78 | (GnomePrintContext *pc, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble x3, gdouble y3), (pc, x1, y1, x2, y2, x3, y3), 0 ) |
389076f1 | 79 | wxDL_METHOD_DEFINE( gint, gnome_print_closepath, |
c6efd6e0 | 80 | (GnomePrintContext *pc), (pc), 0 ) |
389076f1 | 81 | wxDL_METHOD_DEFINE( gint, gnome_print_stroke, |
c6efd6e0 | 82 | (GnomePrintContext *pc), (pc), 0 ) |
389076f1 | 83 | wxDL_METHOD_DEFINE( gint, gnome_print_fill, |
c6efd6e0 | 84 | (GnomePrintContext *pc), (pc), 0 ) |
389076f1 | 85 | wxDL_METHOD_DEFINE( gint, gnome_print_setrgbcolor, |
c6efd6e0 | 86 | (GnomePrintContext *pc, gdouble r, gdouble g, gdouble b), (pc, r, g, b), 0 ) |
389076f1 | 87 | wxDL_METHOD_DEFINE( gint, gnome_print_setlinewidth, |
c6efd6e0 | 88 | (GnomePrintContext *pc, gdouble width), (pc, width), 0 ) |
59c73be8 RR |
89 | wxDL_METHOD_DEFINE( gint, gnome_print_setdash, |
90 | (GnomePrintContext *pc, gint n_values, const gdouble *values, gdouble offset), (pc, n_values, values, offset), 0 ) | |
91 | ||
92 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbimage, | |
93 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) | |
94 | wxDL_METHOD_DEFINE( gint, gnome_print_rgbaimage, | |
95 | (GnomePrintContext *pc, const guchar *data, gint width, gint height, gint rowstride), (pc, data, width, height, rowstride ), 0 ) | |
389076f1 | 96 | |
59c73be8 RR |
97 | wxDL_METHOD_DEFINE( gint, gnome_print_concat, |
98 | (GnomePrintContext *pc, const gdouble *matrix), (pc, matrix), 0 ) | |
99 | wxDL_METHOD_DEFINE( gint, gnome_print_scale, | |
100 | (GnomePrintContext *pc, gdouble sx, gdouble sy), (pc, sx, sy), 0 ) | |
101 | wxDL_METHOD_DEFINE( gint, gnome_print_rotate, | |
102 | (GnomePrintContext *pc, gdouble theta), (pc, theta), 0 ) | |
16744532 RR |
103 | wxDL_METHOD_DEFINE( gint, gnome_print_translate, |
104 | (GnomePrintContext *pc, gdouble x, gdouble y), (pc, x, y), 0 ) | |
59c73be8 RR |
105 | |
106 | wxDL_METHOD_DEFINE( gint, gnome_print_gsave, | |
107 | (GnomePrintContext *pc), (pc), 0 ) | |
108 | wxDL_METHOD_DEFINE( gint, gnome_print_grestore, | |
109 | (GnomePrintContext *pc), (pc), 0 ) | |
389076f1 | 110 | |
3b7ab6bd RR |
111 | wxDL_METHOD_DEFINE( gint, gnome_print_clip, |
112 | (GnomePrintContext *pc), (pc), 0 ) | |
113 | wxDL_METHOD_DEFINE( gint, gnome_print_eoclip, | |
114 | (GnomePrintContext *pc), (pc), 0 ) | |
115 | ||
59c73be8 RR |
116 | wxDL_METHOD_DEFINE( gint, gnome_print_beginpage, |
117 | (GnomePrintContext *pc, const guchar* name), (pc, name), 0 ) | |
118 | wxDL_METHOD_DEFINE( gint, gnome_print_showpage, | |
119 | (GnomePrintContext *pc), (pc), 0 ) | |
120 | wxDL_METHOD_DEFINE( gint, gnome_print_end_doc, | |
121 | (GnomePrintContext *pc), (pc), 0 ) | |
389076f1 | 122 | |
59c73be8 RR |
123 | wxDL_METHOD_DEFINE( PangoLayout*, gnome_print_pango_create_layout, |
124 | (GnomePrintContext *gpc), (gpc), NULL ) | |
32f34982 RR |
125 | wxDL_VOIDMETHOD_DEFINE( gnome_print_pango_layout, |
126 | (GnomePrintContext *gpc, PangoLayout *layout), (gpc, layout) ) | |
389076f1 | 127 | |
59c73be8 RR |
128 | wxDL_METHOD_DEFINE( GnomePrintJob*, gnome_print_job_new, |
129 | (GnomePrintConfig *config), (config), NULL ) | |
130 | wxDL_METHOD_DEFINE( GnomePrintContext*, gnome_print_job_get_context, | |
131 | (GnomePrintJob *job), (job), NULL ) | |
132 | wxDL_METHOD_DEFINE( gint, gnome_print_job_close, | |
133 | (GnomePrintJob *job), (job), 0 ) | |
134 | wxDL_METHOD_DEFINE( gint, gnome_print_job_print, | |
135 | (GnomePrintJob *job), (job), 0 ) | |
136 | wxDL_METHOD_DEFINE( gboolean, gnome_print_job_get_page_size, | |
137 | (GnomePrintJob *job, gdouble *width, gdouble *height), (job, width, height), 0 ) | |
138 | ||
139 | wxDL_METHOD_DEFINE( GnomePrintUnit*, gnome_print_unit_get_by_abbreviation, | |
140 | (const guchar *abbreviation), (abbreviation), NULL ) | |
141 | wxDL_METHOD_DEFINE( gboolean, gnome_print_convert_distance, | |
142 | (gdouble *distance, const GnomePrintUnit *from, const GnomePrintUnit *to), (distance, from, to), false ) | |
143 | ||
144 | wxDL_METHOD_DEFINE( GnomePrintConfig*, gnome_print_config_default, | |
145 | (void), (), NULL ) | |
146 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set, | |
147 | (GnomePrintConfig *config, const guchar *key, const guchar *value), (config, key, value), false ) | |
3b7ab6bd RR |
148 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_double, |
149 | (GnomePrintConfig *config, const guchar *key, gdouble value), (config, key, value), false ) | |
150 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_int, | |
151 | (GnomePrintConfig *config, const guchar *key, gint value), (config, key, value), false ) | |
152 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_boolean, | |
153 | (GnomePrintConfig *config, const guchar *key, gboolean value), (config, key, value), false ) | |
154 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_set_length, | |
155 | (GnomePrintConfig *config, const guchar *key, gdouble value, const GnomePrintUnit *unit), (config, key, value, unit), false ) | |
156 | ||
157 | wxDL_METHOD_DEFINE( guchar*, gnome_print_config_get, | |
158 | (GnomePrintConfig *config, const guchar *key), (config, key), NULL ) | |
59c73be8 RR |
159 | wxDL_METHOD_DEFINE( gboolean, gnome_print_config_get_length, |
160 | (GnomePrintConfig *config, const guchar *key, gdouble *val, const GnomePrintUnit **unit), (config, key, val, unit), false ) | |
161 | ||
389076f1 | 162 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_dialog_new, |
59c73be8 | 163 | (GnomePrintJob *gpj, const guchar *title, gint flags), (gpj, title, flags), NULL ) |
32f34982 | 164 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_construct_range_page, |
59c73be8 RR |
165 | (GnomePrintDialog *gpd, gint flags, gint start, gint end, |
166 | const guchar *currentlabel, const guchar *rangelabel), | |
32f34982 RR |
167 | (gpd, flags, start, end, currentlabel, rangelabel) ) |
168 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_get_copies, | |
169 | (GnomePrintDialog *gpd, gint *copies, gboolean *collate), (gpd, copies, collate) ) | |
170 | wxDL_VOIDMETHOD_DEFINE( gnome_print_dialog_set_copies, | |
171 | (GnomePrintDialog *gpd, gint copies, gint collate), (gpd, copies, collate) ) | |
59c73be8 RR |
172 | wxDL_METHOD_DEFINE( GnomePrintRangeType, gnome_print_dialog_get_range, |
173 | (GnomePrintDialog *gpd), (gpd), GNOME_PRINT_RANGETYPE_NONE ) | |
174 | wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page, | |
175 | (GnomePrintDialog *gpd, gint *start, gint *end), (gpd, start, end), 0 ) | |
389076f1 | 176 | |
59c73be8 RR |
177 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_paper_selector_new_with_flags, |
178 | (GnomePrintConfig *config, gint flags), (config, flags), NULL ) | |
179 | ||
180 | wxDL_METHOD_DEFINE( GtkWidget*, gnome_print_job_preview_new, | |
181 | (GnomePrintJob *gpm, const guchar *title), (gpm, title), NULL ) | |
7d7e4ed0 PC |
182 | |
183 | DECLARE_NO_COPY_CLASS(wxGnomePrintLibrary) | |
c6efd6e0 RR |
184 | }; |
185 | ||
186 | wxGnomePrintLibrary::wxGnomePrintLibrary() | |
187 | { | |
188 | wxLogNull log; | |
389076f1 | 189 | |
ced3df77 VZ |
190 | m_libGnomePrint.Load("libgnomeprint-2-2.so.0"); |
191 | m_ok = m_libGnomePrint.IsLoaded(); | |
192 | if ( !m_ok ) | |
193 | return; | |
389076f1 | 194 | |
ced3df77 | 195 | m_libGnomePrintUI.Load("libgnomeprintui-2-2.so.0"); |
32f34982 | 196 | m_ok = m_libGnomePrintUI.IsLoaded(); |
ced3df77 VZ |
197 | if ( !m_ok ) |
198 | { | |
199 | m_libGnomePrint.Unload(); | |
200 | return; | |
201 | } | |
389076f1 | 202 | |
ced3df77 | 203 | m_ok = InitializeMethods(); |
c6efd6e0 RR |
204 | } |
205 | ||
206 | wxGnomePrintLibrary::~wxGnomePrintLibrary() | |
207 | { | |
c6efd6e0 RR |
208 | } |
209 | ||
210 | bool wxGnomePrintLibrary::IsOk() | |
211 | { | |
212 | return m_ok; | |
213 | } | |
214 | ||
ced3df77 VZ |
215 | bool wxGnomePrintLibrary::InitializeMethods() |
216 | { | |
6950be01 RR |
217 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_newpath ); |
218 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_moveto ); | |
219 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_lineto ); | |
220 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_curveto ); | |
221 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_arcto ); | |
222 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_closepath ); | |
223 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_stroke ); | |
224 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_fill ); | |
225 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setrgbcolor ); | |
226 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setlinewidth ); | |
227 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_setdash ); | |
228 | ||
229 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rgbimage ); | |
230 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rgbaimage ); | |
231 | ||
232 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_concat ); | |
233 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_scale ); | |
234 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_rotate ); | |
235 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_translate ); | |
236 | ||
237 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_gsave ); | |
238 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_grestore ); | |
239 | ||
240 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_clip ); | |
241 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_eoclip ); | |
242 | ||
243 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_beginpage ); | |
244 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_showpage ); | |
245 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_end_doc ); | |
246 | ||
247 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_pango_create_layout ); | |
248 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_pango_layout ); | |
249 | ||
250 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_new ); | |
251 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_get_context ); | |
252 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_close ); | |
253 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_print ); | |
254 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_job_get_page_size ); | |
255 | ||
256 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_unit_get_by_abbreviation ); | |
257 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_convert_distance ); | |
258 | ||
259 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_default ); | |
260 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set ); | |
261 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_boolean ); | |
262 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_double ); | |
263 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_int ); | |
264 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_set_length ); | |
3b7ab6bd | 265 | |
6950be01 RR |
266 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_get ); |
267 | wxDL_METHOD_LOAD( m_libGnomePrint, gnome_print_config_get_length ); | |
59c73be8 | 268 | |
6950be01 RR |
269 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_new ); |
270 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_construct_range_page ); | |
271 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_copies ); | |
272 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_set_copies ); | |
273 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_range ); | |
274 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_dialog_get_range_page ); | |
59c73be8 | 275 | |
6950be01 | 276 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_paper_selector_new_with_flags ); |
59c73be8 | 277 | |
6950be01 | 278 | wxDL_METHOD_LOAD( m_libGnomePrintUI, gnome_print_job_preview_new ); |
389076f1 | 279 | |
ced3df77 | 280 | return true; |
c6efd6e0 RR |
281 | } |
282 | ||
ced3df77 | 283 | static wxGnomePrintLibrary* gs_libGnomePrint = NULL; |
c6efd6e0 | 284 | |
ff910433 RR |
285 | //---------------------------------------------------------------------------- |
286 | // wxGnomePrintNativeData | |
287 | //---------------------------------------------------------------------------- | |
288 | ||
289 | IMPLEMENT_CLASS(wxGnomePrintNativeData, wxPrintNativeDataBase) | |
290 | ||
291 | wxGnomePrintNativeData::wxGnomePrintNativeData() | |
292 | { | |
ced3df77 VZ |
293 | m_config = gs_libGnomePrint->gnome_print_config_default(); |
294 | m_job = gs_libGnomePrint->gnome_print_job_new( m_config ); | |
ff910433 RR |
295 | } |
296 | ||
297 | wxGnomePrintNativeData::~wxGnomePrintNativeData() | |
298 | { | |
3fe39b0c | 299 | g_object_unref (m_config); |
ff910433 RR |
300 | } |
301 | ||
302 | bool wxGnomePrintNativeData::TransferTo( wxPrintData &data ) | |
303 | { | |
ced3df77 | 304 | guchar *res = gs_libGnomePrint->gnome_print_config_get( m_config, |
3b7ab6bd RR |
305 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION ); |
306 | if (g_ascii_strcasecmp((const gchar *)res,"R90") == 0) | |
307 | data.SetOrientation( wxLANDSCAPE ); | |
308 | else | |
309 | data.SetOrientation( wxPORTRAIT ); | |
310 | g_free( res ); | |
311 | ||
ff910433 RR |
312 | return true; |
313 | } | |
314 | ||
315 | bool wxGnomePrintNativeData::TransferFrom( const wxPrintData &data ) | |
316 | { | |
3b7ab6bd RR |
317 | if (data.GetOrientation() == wxLANDSCAPE) |
318 | { | |
ced3df77 | 319 | gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
320 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION, |
321 | (guchar*)(char*)"R90" ); | |
322 | } | |
323 | else | |
324 | { | |
ced3df77 | 325 | gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
326 | (guchar*)(char*)GNOME_PRINT_KEY_PAGE_ORIENTATION, |
327 | (guchar*)(char*)"R0" ); | |
328 | } | |
329 | ||
330 | if (data.GetCollate()) | |
331 | { | |
ced3df77 | 332 | gs_libGnomePrint->gnome_print_config_set_boolean( m_config, |
3b7ab6bd RR |
333 | (guchar*)(char*)GNOME_PRINT_KEY_COLLATE, |
334 | TRUE ); | |
335 | } | |
336 | else | |
337 | { | |
ced3df77 | 338 | gs_libGnomePrint->gnome_print_config_set_boolean( m_config, |
3b7ab6bd RR |
339 | (guchar*)(char*)GNOME_PRINT_KEY_COLLATE, |
340 | FALSE ); | |
341 | } | |
342 | ||
343 | switch (data.GetPaperId()) | |
344 | { | |
ced3df77 | 345 | case wxPAPER_A3: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
346 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
347 | (guchar*)(char*)"A3" ); | |
348 | break; | |
ced3df77 | 349 | case wxPAPER_A5: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
350 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
351 | (guchar*)(char*)"A5" ); | |
352 | break; | |
ced3df77 | 353 | case wxPAPER_B4: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
354 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
355 | (guchar*)(char*)"B4" ); | |
356 | break; | |
ced3df77 | 357 | case wxPAPER_B5: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
358 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
359 | (guchar*)(char*)"B5" ); | |
360 | break; | |
ced3df77 | 361 | case wxPAPER_LETTER: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
362 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
363 | (guchar*)(char*)"USLetter" ); | |
364 | break; | |
ced3df77 | 365 | case wxPAPER_LEGAL: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
366 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
367 | (guchar*)(char*)"USLegal" ); | |
368 | break; | |
ced3df77 | 369 | case wxPAPER_EXECUTIVE: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
370 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
371 | (guchar*)(char*)"Executive" ); | |
372 | break; | |
ced3df77 | 373 | case wxPAPER_ENV_C5: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
374 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
375 | (guchar*)(char*)"C5" ); | |
376 | break; | |
ced3df77 | 377 | case wxPAPER_ENV_C6: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
378 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
379 | (guchar*)(char*)"C6" ); | |
380 | break; | |
381 | case wxPAPER_NONE: break; | |
382 | ||
383 | default: | |
ced3df77 | 384 | case wxPAPER_A4: gs_libGnomePrint->gnome_print_config_set( m_config, |
3b7ab6bd RR |
385 | (guchar*)(char*)GNOME_PRINT_KEY_PAPER_SIZE, |
386 | (guchar*)(char*)"A4" ); | |
387 | break; | |
388 | } | |
389 | ||
ff910433 RR |
390 | return true; |
391 | } | |
389076f1 | 392 | |
ff910433 RR |
393 | //---------------------------------------------------------------------------- |
394 | // wxGnomePrintFactory | |
395 | //---------------------------------------------------------------------------- | |
396 | ||
397 | wxPrinterBase* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData *data ) | |
398 | { | |
399 | return new wxGnomePrinter( data ); | |
400 | } | |
389076f1 WS |
401 | |
402 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, | |
403 | wxPrintout *printout, | |
ff910433 RR |
404 | wxPrintDialogData *data ) |
405 | { | |
147bf263 | 406 | return new wxGnomePrintPreview( preview, printout, data ); |
ff910433 RR |
407 | } |
408 | ||
389076f1 WS |
409 | wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview, |
410 | wxPrintout *printout, | |
ff910433 RR |
411 | wxPrintData *data ) |
412 | { | |
147bf263 | 413 | return new wxGnomePrintPreview( preview, printout, data ); |
ff910433 RR |
414 | } |
415 | ||
389076f1 | 416 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, |
ff910433 RR |
417 | wxPrintDialogData *data ) |
418 | { | |
2934005d | 419 | return new wxGnomePrintDialog( parent, data ); |
ff910433 RR |
420 | } |
421 | ||
389076f1 | 422 | wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent, |
ff910433 RR |
423 | wxPrintData *data ) |
424 | { | |
2934005d | 425 | return new wxGnomePrintDialog( parent, data ); |
ff910433 | 426 | } |
389076f1 | 427 | |
08680429 RR |
428 | wxPageSetupDialogBase *wxGnomePrintFactory::CreatePageSetupDialog( wxWindow *parent, |
429 | wxPageSetupDialogData * data ) | |
389076f1 | 430 | { |
06cfd325 RR |
431 | // The native page setup dialog is broken. It |
432 | // miscalculates newly entered values for the | |
433 | // margins if you have not chose "points" but | |
389076f1 | 434 | // e.g. centimerters. |
cffcf831 RR |
435 | // This has been fixed in GNOME CVS (maybe |
436 | // fixed in libgnomeprintui 2.8.1) | |
06cfd325 | 437 | |
cffcf831 | 438 | return new wxGnomePageSetupDialog( parent, data ); |
08680429 | 439 | } |
389076f1 | 440 | |
ff910433 RR |
441 | bool wxGnomePrintFactory::HasPrintSetupDialog() |
442 | { | |
2934005d | 443 | return false; |
ff910433 RR |
444 | } |
445 | ||
446 | wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data ) | |
447 | { | |
2934005d | 448 | return NULL; |
ff910433 RR |
449 | } |
450 | ||
147bf263 JS |
451 | wxDC* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData& data ) |
452 | { | |
453 | return new wxGnomePrintDC(data); | |
454 | } | |
455 | ||
ff910433 RR |
456 | bool wxGnomePrintFactory::HasOwnPrintToFile() |
457 | { | |
458 | return true; | |
459 | } | |
460 | ||
461 | bool wxGnomePrintFactory::HasPrinterLine() | |
462 | { | |
463 | return true; | |
464 | } | |
465 | ||
466 | wxString wxGnomePrintFactory::CreatePrinterLine() | |
467 | { | |
2934005d RR |
468 | // redundant now |
469 | return wxEmptyString; | |
ff910433 RR |
470 | } |
471 | ||
472 | bool wxGnomePrintFactory::HasStatusLine() | |
473 | { | |
2934005d | 474 | // redundant now |
389076f1 | 475 | return true; |
ff910433 RR |
476 | } |
477 | ||
478 | wxString wxGnomePrintFactory::CreateStatusLine() | |
479 | { | |
2934005d RR |
480 | // redundant now |
481 | return wxEmptyString; | |
ff910433 RR |
482 | } |
483 | ||
484 | wxPrintNativeDataBase *wxGnomePrintFactory::CreatePrintNativeData() | |
485 | { | |
486 | return new wxGnomePrintNativeData; | |
487 | } | |
488 | ||
489 | //---------------------------------------------------------------------------- | |
490 | // wxGnomePrintSetupDialog | |
491 | //---------------------------------------------------------------------------- | |
492 | ||
2934005d RR |
493 | IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase) |
494 | ||
495 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintDialogData *data ) | |
496 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
497 | wxPoint(0, 0), wxSize(600, 600), | |
498 | wxDEFAULT_DIALOG_STYLE | | |
499 | wxTAB_TRAVERSAL) | |
500 | { | |
501 | if (data) | |
502 | m_printDialogData = *data; | |
389076f1 | 503 | |
2934005d RR |
504 | Init(); |
505 | } | |
506 | ||
507 | wxGnomePrintDialog::wxGnomePrintDialog( wxWindow *parent, wxPrintData *data ) | |
508 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), | |
509 | wxPoint(0, 0), wxSize(600, 600), | |
510 | wxDEFAULT_DIALOG_STYLE | | |
511 | wxTAB_TRAVERSAL) | |
512 | { | |
513 | if (data) | |
514 | m_printDialogData = *data; | |
515 | ||
516 | Init(); | |
517 | } | |
ff910433 | 518 | |
2934005d | 519 | void wxGnomePrintDialog::Init() |
ff910433 | 520 | { |
2934005d | 521 | wxPrintData data = m_printDialogData.GetPrintData(); |
3b7ab6bd RR |
522 | |
523 | data.ConvertToNative(); | |
2934005d | 524 | |
ff910433 | 525 | wxGnomePrintNativeData *native = |
2934005d | 526 | (wxGnomePrintNativeData*) data.GetNativeData(); |
389076f1 | 527 | |
ced3df77 | 528 | m_widget = gs_libGnomePrint->gnome_print_dialog_new( native->GetPrintJob(), |
389076f1 | 529 | (guchar*)"Print", |
2934005d | 530 | GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES ); |
b199de59 RR |
531 | |
532 | int flag = 0; | |
533 | if (m_printDialogData.GetEnableSelection()) | |
534 | flag |= GNOME_PRINT_RANGE_SELECTION; | |
535 | if (m_printDialogData.GetEnablePageNumbers()) | |
536 | flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE; | |
537 | ||
ced3df77 | 538 | gs_libGnomePrint->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget, |
b199de59 RR |
539 | flag, |
540 | m_printDialogData.GetMinPage(), | |
541 | m_printDialogData.GetMaxPage(), | |
542 | NULL, | |
543 | NULL ); | |
ff910433 RR |
544 | } |
545 | ||
2934005d | 546 | wxGnomePrintDialog::~wxGnomePrintDialog() |
ff910433 RR |
547 | { |
548 | m_widget = NULL; | |
549 | } | |
550 | ||
2934005d | 551 | int wxGnomePrintDialog::ShowModal() |
ff910433 RR |
552 | { |
553 | int response = gtk_dialog_run (GTK_DIALOG (m_widget)); | |
389076f1 WS |
554 | |
555 | if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) | |
b199de59 RR |
556 | { |
557 | gtk_widget_destroy(m_widget); | |
558 | m_widget = NULL; | |
389076f1 | 559 | |
ff910433 | 560 | return wxID_CANCEL; |
b199de59 | 561 | } |
ff910433 | 562 | |
3b7ab6bd RR |
563 | m_printDialogData.GetPrintData().ConvertFromNative(); |
564 | ||
b199de59 RR |
565 | gint copies = 1; |
566 | gboolean collate = false; | |
ced3df77 | 567 | gs_libGnomePrint->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate ); |
b199de59 RR |
568 | m_printDialogData.SetNoCopies( copies ); |
569 | m_printDialogData.SetCollate( collate ); | |
2934005d | 570 | |
ced3df77 | 571 | switch (gs_libGnomePrint->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget )) |
b199de59 RR |
572 | { |
573 | case GNOME_PRINT_RANGE_SELECTION: | |
574 | m_printDialogData.SetSelection( true ); | |
575 | break; | |
576 | case GNOME_PRINT_RANGE_ALL: | |
577 | m_printDialogData.SetAllPages( true ); | |
578 | m_printDialogData.SetFromPage( 0 ); | |
579 | m_printDialogData.SetToPage( 9999 ); | |
580 | break; | |
581 | case GNOME_PRINT_RANGE_RANGE: | |
582 | default: | |
583 | gint start,end; | |
ced3df77 | 584 | gs_libGnomePrint->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end ); |
b199de59 RR |
585 | m_printDialogData.SetFromPage( start ); |
586 | m_printDialogData.SetToPage( end ); | |
587 | break; | |
588 | } | |
589 | ||
590 | gtk_widget_destroy(m_widget); | |
591 | m_widget = NULL; | |
389076f1 | 592 | |
0be7709e RR |
593 | if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) |
594 | return wxID_PREVIEW; | |
389076f1 | 595 | |
ff910433 RR |
596 | return wxID_OK; |
597 | } | |
598 | ||
2934005d | 599 | wxDC *wxGnomePrintDialog::GetPrintDC() |
ff910433 | 600 | { |
2934005d RR |
601 | // Later |
602 | return NULL; | |
ff910433 RR |
603 | } |
604 | ||
2934005d | 605 | bool wxGnomePrintDialog::Validate() |
ff910433 RR |
606 | { |
607 | return true; | |
608 | } | |
609 | ||
2934005d | 610 | bool wxGnomePrintDialog::TransferDataToWindow() |
ff910433 RR |
611 | { |
612 | return true; | |
613 | } | |
614 | ||
2934005d RR |
615 | bool wxGnomePrintDialog::TransferDataFromWindow() |
616 | { | |
617 | return true; | |
618 | } | |
ff910433 | 619 | |
08680429 RR |
620 | //---------------------------------------------------------------------------- |
621 | // wxGnomePageSetupDialog | |
622 | //---------------------------------------------------------------------------- | |
623 | ||
624 | IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase) | |
625 | ||
626 | wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow *parent, | |
627 | wxPageSetupDialogData* data ) | |
628 | { | |
629 | if (data) | |
630 | m_pageDialogData = *data; | |
389076f1 | 631 | |
3b7ab6bd RR |
632 | m_pageDialogData.GetPrintData().ConvertToNative(); |
633 | ||
08680429 RR |
634 | wxGnomePrintNativeData *native = |
635 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
cffcf831 | 636 | |
3b7ab6bd | 637 | // This *was* required as the page setup dialog |
cffcf831 | 638 | // calculates wrong values otherwise. |
3b7ab6bd | 639 | #if 0 |
ced3df77 | 640 | gs_libGnomePrint->gnome_print_config_set( native->GetPrintConfig(), |
cffcf831 RR |
641 | (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT, |
642 | (const guchar*) "Pts" ); | |
3b7ab6bd RR |
643 | #endif |
644 | ||
645 | GnomePrintConfig *config = native->GetPrintConfig(); | |
646 | ||
ced3df77 | 647 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
3b7ab6bd RR |
648 | |
649 | double ml = (double) m_pageDialogData.GetMarginTopLeft().x; | |
650 | double mt = (double) m_pageDialogData.GetMarginTopLeft().y; | |
651 | double mr = (double) m_pageDialogData.GetMarginBottomRight().x; | |
652 | double mb = (double) m_pageDialogData.GetMarginBottomRight().y; | |
653 | ||
ced3df77 | 654 | gs_libGnomePrint->gnome_print_config_set_length (config, |
3b7ab6bd | 655 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, ml, mm_unit ); |
ced3df77 | 656 | gs_libGnomePrint->gnome_print_config_set_length (config, |
3b7ab6bd | 657 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, mr, mm_unit ); |
ced3df77 | 658 | gs_libGnomePrint->gnome_print_config_set_length (config, |
3b7ab6bd | 659 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, mt, mm_unit ); |
ced3df77 | 660 | gs_libGnomePrint->gnome_print_config_set_length (config, |
3b7ab6bd | 661 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, mb, mm_unit ); |
389076f1 | 662 | |
08680429 | 663 | m_widget = gtk_dialog_new(); |
389076f1 | 664 | |
08680429 | 665 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) ); |
cffcf831 | 666 | |
ced3df77 | 667 | GtkWidget *main = gs_libGnomePrint->gnome_paper_selector_new_with_flags( native->GetPrintConfig(), |
08680429 RR |
668 | GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION ); |
669 | gtk_container_set_border_width (GTK_CONTAINER (main), 8); | |
670 | gtk_widget_show (main); | |
389076f1 | 671 | |
08680429 | 672 | gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main ); |
08680429 | 673 | |
389076f1 | 674 | gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE); |
08680429 | 675 | |
389076f1 WS |
676 | gtk_dialog_add_buttons (GTK_DIALOG (m_widget), |
677 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
678 | GTK_STOCK_OK, GTK_RESPONSE_OK, | |
679 | NULL); | |
680 | ||
681 | gtk_dialog_set_default_response (GTK_DIALOG (m_widget), | |
682 | GTK_RESPONSE_OK); | |
08680429 RR |
683 | } |
684 | ||
685 | wxGnomePageSetupDialog::~wxGnomePageSetupDialog() | |
686 | { | |
687 | } | |
688 | ||
689 | wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData() | |
690 | { | |
691 | return m_pageDialogData; | |
692 | } | |
693 | ||
694 | int wxGnomePageSetupDialog::ShowModal() | |
695 | { | |
06cfd325 RR |
696 | wxGnomePrintNativeData *native = |
697 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
3b7ab6bd | 698 | |
06cfd325 | 699 | GnomePrintConfig *config = native->GetPrintConfig(); |
389076f1 | 700 | |
08680429 RR |
701 | |
702 | int ret = gtk_dialog_run( GTK_DIALOG(m_widget) ); | |
703 | ||
704 | if (ret == GTK_RESPONSE_OK) | |
705 | { | |
706 | // Transfer data back to m_pageDialogData | |
3b7ab6bd | 707 | m_pageDialogData.GetPrintData().ConvertFromNative(); |
cffcf831 RR |
708 | |
709 | // I don't know how querying the last parameter works | |
06cfd325 | 710 | double ml,mr,mt,mb,pw,ph; |
ced3df77 | 711 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 712 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); |
ced3df77 | 713 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 714 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); |
ced3df77 | 715 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 716 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); |
ced3df77 | 717 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 718 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); |
ced3df77 | 719 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 720 | (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); |
ced3df77 | 721 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 WS |
722 | (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); |
723 | ||
3b7ab6bd RR |
724 | // This code converts correctly from what the user chose |
725 | // as the unit although I query Pts here | |
ced3df77 VZ |
726 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
727 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
728 | gs_libGnomePrint->gnome_print_convert_distance( &ml, pts_unit, mm_unit ); | |
729 | gs_libGnomePrint->gnome_print_convert_distance( &mr, pts_unit, mm_unit ); | |
730 | gs_libGnomePrint->gnome_print_convert_distance( &mt, pts_unit, mm_unit ); | |
731 | gs_libGnomePrint->gnome_print_convert_distance( &mb, pts_unit, mm_unit ); | |
732 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
733 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
cffcf831 RR |
734 | |
735 | m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); | |
06cfd325 | 736 | m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); |
389076f1 | 737 | |
06cfd325 | 738 | m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); |
cffcf831 | 739 | |
08680429 RR |
740 | ret = wxID_OK; |
741 | } | |
742 | else | |
743 | { | |
744 | ret = wxID_CANCEL; | |
745 | } | |
389076f1 | 746 | |
08680429 RR |
747 | gtk_widget_destroy( m_widget ); |
748 | m_widget = NULL; | |
749 | ||
750 | return ret; | |
751 | } | |
752 | ||
753 | bool wxGnomePageSetupDialog::Validate() | |
754 | { | |
755 | return true; | |
756 | } | |
757 | ||
758 | bool wxGnomePageSetupDialog::TransferDataToWindow() | |
759 | { | |
760 | return true; | |
761 | } | |
762 | ||
763 | bool wxGnomePageSetupDialog::TransferDataFromWindow() | |
764 | { | |
765 | return true; | |
766 | } | |
767 | ||
ff910433 RR |
768 | //---------------------------------------------------------------------------- |
769 | // wxGnomePrinter | |
770 | //---------------------------------------------------------------------------- | |
771 | ||
772 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) | |
773 | ||
774 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : | |
775 | wxPrinterBase( data ) | |
776 | { | |
0be7709e | 777 | m_native_preview = false; |
ff910433 RR |
778 | } |
779 | ||
780 | wxGnomePrinter::~wxGnomePrinter() | |
781 | { | |
782 | } | |
783 | ||
784 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
785 | { | |
786 | if (!printout) | |
787 | { | |
788 | sm_lastError = wxPRINTER_ERROR; | |
789 | return false; | |
790 | } | |
791 | ||
792 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
3b7ab6bd | 793 | |
389076f1 | 794 | wxGnomePrintNativeData *native = |
ff910433 RR |
795 | (wxGnomePrintNativeData*) printdata.GetNativeData(); |
796 | ||
ced3df77 | 797 | GnomePrintJob *job = gs_libGnomePrint->gnome_print_job_new( native->GetPrintConfig() ); |
cffcf831 | 798 | |
389076f1 | 799 | // The GnomePrintJob is temporarily stored in the |
2934005d | 800 | // native print data as the native print dialog |
981a6af1 | 801 | // needs to access it. |
cffcf831 RR |
802 | native->SetPrintJob( job ); |
803 | ||
981a6af1 RR |
804 | |
805 | printout->SetIsPreview(false); | |
806 | ||
807 | if (m_printDialogData.GetMinPage() < 1) | |
808 | m_printDialogData.SetMinPage(1); | |
809 | if (m_printDialogData.GetMaxPage() < 1) | |
810 | m_printDialogData.SetMaxPage(9999); | |
389076f1 | 811 | |
ff910433 | 812 | wxDC *dc; |
ff910433 RR |
813 | if (prompt) |
814 | dc = PrintDialog( parent ); | |
815 | else | |
3b7ab6bd | 816 | dc = new wxGnomePrintDC( printdata ); |
389076f1 | 817 | |
0be7709e RR |
818 | if (m_native_preview) |
819 | printout->SetIsPreview(true); | |
389076f1 | 820 | |
ff910433 RR |
821 | if (!dc) |
822 | { | |
ced3df77 | 823 | gs_libGnomePrint->gnome_print_job_close( job ); |
3fe39b0c | 824 | g_object_unref (job); |
a1b289f1 PC |
825 | if (sm_lastError != wxPRINTER_CANCELLED) |
826 | sm_lastError = wxPRINTER_ERROR; | |
ff910433 RR |
827 | return false; |
828 | } | |
829 | ||
981a6af1 RR |
830 | wxSize ScreenPixels = wxGetDisplaySize(); |
831 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
832 | ||
833 | printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
834 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
b199de59 RR |
835 | printout->SetPPIPrinter( wxGnomePrintDC::GetResolution(), |
836 | wxGnomePrintDC::GetResolution() ); | |
389076f1 | 837 | |
ff910433 RR |
838 | printout->SetDC(dc); |
839 | ||
981a6af1 RR |
840 | int w, h; |
841 | dc->GetSize(&w, &h); | |
842 | printout->SetPageSizePixels((int)w, (int)h); | |
f415cab9 JS |
843 | printout->SetPaperRectPixels(wxRect(0, 0, w, h)); |
844 | int mw, mh; | |
845 | dc->GetSizeMM(&mw, &mh); | |
846 | printout->SetPageSizeMM((int)mw, (int)mh); | |
ff910433 | 847 | printout->OnPreparePrinting(); |
389076f1 | 848 | |
b199de59 RR |
849 | // Get some parameters from the printout, if defined |
850 | int fromPage, toPage; | |
851 | int minPage, maxPage; | |
852 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
ff910433 | 853 | |
b199de59 | 854 | if (maxPage == 0) |
ff910433 | 855 | { |
ced3df77 | 856 | gs_libGnomePrint->gnome_print_job_close( job ); |
3fe39b0c | 857 | g_object_unref (job); |
ff910433 | 858 | sm_lastError = wxPRINTER_ERROR; |
b199de59 | 859 | return false; |
ff910433 | 860 | } |
389076f1 | 861 | |
b199de59 RR |
862 | printout->OnBeginPrinting(); |
863 | ||
864 | int minPageNum = minPage, maxPageNum = maxPage; | |
865 | ||
866 | if ( !m_printDialogData.GetAllPages() ) | |
ff910433 | 867 | { |
b199de59 RR |
868 | minPageNum = m_printDialogData.GetFromPage(); |
869 | maxPageNum = m_printDialogData.GetToPage(); | |
870 | } | |
871 | ||
389076f1 | 872 | |
b199de59 RR |
873 | int copyCount; |
874 | for ( copyCount = 1; | |
875 | copyCount <= m_printDialogData.GetNoCopies(); | |
876 | copyCount++ ) | |
877 | { | |
878 | if (!printout->OnBeginDocument(minPageNum, maxPageNum)) | |
ff910433 | 879 | { |
b199de59 RR |
880 | wxLogError(_("Could not start printing.")); |
881 | sm_lastError = wxPRINTER_ERROR; | |
882 | break; | |
883 | } | |
389076f1 | 884 | |
b199de59 RR |
885 | int pn; |
886 | for ( pn = minPageNum; | |
887 | pn <= maxPageNum && printout->HasPage(pn); | |
888 | pn++ ) | |
389076f1 | 889 | { |
ff910433 RR |
890 | dc->StartPage(); |
891 | printout->OnPrintPage(pn); | |
892 | dc->EndPage(); | |
893 | } | |
389076f1 | 894 | |
ff910433 RR |
895 | printout->OnEndDocument(); |
896 | printout->OnEndPrinting(); | |
897 | } | |
389076f1 | 898 | |
ced3df77 | 899 | gs_libGnomePrint->gnome_print_job_close( job ); |
0be7709e RR |
900 | if (m_native_preview) |
901 | { | |
46e86fc3 | 902 | const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview"))); |
ced3df77 | 903 | GtkWidget *preview = gs_libGnomePrint->gnome_print_job_preview_new |
b8f32576 VZ |
904 | ( |
905 | job, | |
46e86fc3 | 906 | (const guchar *)title.data() |
b8f32576 VZ |
907 | ); |
908 | gtk_widget_show(preview); | |
0be7709e RR |
909 | } |
910 | else | |
911 | { | |
ced3df77 | 912 | gs_libGnomePrint->gnome_print_job_print( job ); |
0be7709e | 913 | } |
389076f1 | 914 | |
3fe39b0c | 915 | g_object_unref (job); |
ff910433 | 916 | delete dc; |
389076f1 | 917 | |
ff910433 RR |
918 | return (sm_lastError == wxPRINTER_NO_ERROR); |
919 | } | |
920 | ||
921 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) | |
922 | { | |
2934005d | 923 | wxGnomePrintDialog dialog( parent, &m_printDialogData ); |
0be7709e RR |
924 | int ret = dialog.ShowModal(); |
925 | if (ret == wxID_CANCEL) | |
ff910433 | 926 | { |
4843cdfe | 927 | sm_lastError = wxPRINTER_CANCELLED; |
ff910433 RR |
928 | return NULL; |
929 | } | |
389076f1 | 930 | |
0be7709e | 931 | m_native_preview = ret == wxID_PREVIEW; |
389076f1 | 932 | |
b199de59 | 933 | m_printDialogData = dialog.GetPrintDialogData(); |
3b7ab6bd | 934 | return new wxGnomePrintDC( m_printDialogData.GetPrintData() ); |
ff910433 RR |
935 | } |
936 | ||
937 | bool wxGnomePrinter::Setup( wxWindow *parent ) | |
938 | { | |
58c30cd8 | 939 | return false; |
ff910433 RR |
940 | } |
941 | ||
942 | //----------------------------------------------------------------------------- | |
943 | // wxGnomePrintDC | |
944 | //----------------------------------------------------------------------------- | |
945 | ||
02255e07 RR |
946 | // conversion |
947 | static const double RAD2DEG = 180.0 / M_PI; | |
948 | ||
949 | // we don't want to use only 72 dpi from GNOME print | |
950 | static const int DPI = 600; | |
951 | static const double PS2DEV = 600.0 / 72.0; | |
952 | static const double DEV2PS = 72.0 / 600.0; | |
953 | ||
954 | #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS) | |
955 | #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS) | |
956 | #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS) | |
957 | #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS) | |
958 | ||
62075bca | 959 | IMPLEMENT_CLASS(wxGnomePrintDC, wxDC) |
ff910433 | 960 | |
147bf263 JS |
961 | wxGnomePrintDC::wxGnomePrintDC( const wxPrintData& data ) |
962 | { | |
147bf263 JS |
963 | m_printData = data; |
964 | ||
965 | wxGnomePrintNativeData *native = | |
966 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
967 | ||
3b7ab6bd | 968 | m_job = native->GetPrintJob(); |
ced3df77 | 969 | m_gpc = gs_libGnomePrint->gnome_print_job_get_context (m_job); |
147bf263 | 970 | |
ced3df77 | 971 | m_layout = gs_libGnomePrint->gnome_print_pango_create_layout( m_gpc ); |
147bf263 | 972 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); |
7d7e4ed0 | 973 | m_context = NULL; |
147bf263 JS |
974 | |
975 | m_currentRed = 0; | |
976 | m_currentBlue = 0; | |
977 | m_currentGreen = 0; | |
978 | ||
02255e07 RR |
979 | // Query page size. This seems to omit the margins |
980 | double pw,ph; | |
6950be01 | 981 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
f4322df6 | 982 | |
02255e07 | 983 | m_pageHeight = ph * PS2DEV; |
147bf263 JS |
984 | } |
985 | ||
ff910433 RR |
986 | wxGnomePrintDC::~wxGnomePrintDC() |
987 | { | |
988 | } | |
989 | ||
b7cacb43 | 990 | bool wxGnomePrintDC::IsOk() const |
ff910433 RR |
991 | { |
992 | return true; | |
993 | } | |
994 | ||
995 | bool wxGnomePrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style ) | |
996 | { | |
997 | return false; | |
998 | } | |
999 | ||
1000 | bool wxGnomePrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const | |
1001 | { | |
1002 | return false; | |
1003 | } | |
1004 | ||
1005 | void wxGnomePrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
1006 | { | |
1007 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
389076f1 | 1008 | |
ff910433 RR |
1009 | SetPen( m_pen ); |
1010 | ||
ced3df77 VZ |
1011 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) ); |
1012 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
1013 | gs_libGnomePrint->gnome_print_stroke ( m_gpc); | |
cac7ac30 | 1014 | |
ff910433 RR |
1015 | CalcBoundingBox( x1, y1 ); |
1016 | CalcBoundingBox( x2, y2 ); | |
1017 | } | |
1018 | ||
1019 | void wxGnomePrintDC::DoCrossHair(wxCoord x, wxCoord y) | |
1020 | { | |
1021 | } | |
1022 | ||
1023 | void wxGnomePrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) | |
1024 | { | |
2f41910a RR |
1025 | double dx = x1 - xc; |
1026 | double dy = y1 - yc; | |
1027 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
1028 | double alpha1, alpha2; | |
1029 | if (x1 == x2 && y1 == y2) | |
1030 | { | |
1031 | alpha1 = 0.0; | |
1032 | alpha2 = 360.0; | |
1033 | } | |
74ab5f5b | 1034 | else if ( wxIsNullDouble(radius) ) |
2f41910a | 1035 | { |
74ab5f5b VZ |
1036 | alpha1 = |
1037 | alpha2 = 0.0; | |
2f41910a RR |
1038 | } |
1039 | else | |
1040 | { | |
1041 | alpha1 = (x1 - xc == 0) ? | |
1042 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
1043 | -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
1044 | alpha2 = (x2 - xc == 0) ? | |
1045 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
1046 | -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
389076f1 | 1047 | |
2f41910a RR |
1048 | while (alpha1 <= 0) alpha1 += 360; |
1049 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between | |
1050 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree | |
1051 | while (alpha2 > 360) alpha2 -= 360; | |
1052 | } | |
1053 | ||
7d7e4ed0 PC |
1054 | if (m_brush.GetStyle() != wxTRANSPARENT) |
1055 | { | |
1056 | SetBrush( m_brush ); | |
ced3df77 VZ |
1057 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); |
1058 | gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
389076f1 | 1059 | |
ced3df77 | 1060 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
7d7e4ed0 | 1061 | } |
2f41910a | 1062 | |
7d7e4ed0 PC |
1063 | if (m_pen.GetStyle() != wxTRANSPARENT) |
1064 | { | |
1065 | SetPen (m_pen); | |
ced3df77 VZ |
1066 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1067 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); | |
1068 | gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
1069 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
389076f1 | 1070 | |
ced3df77 | 1071 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
7d7e4ed0 | 1072 | } |
2f41910a RR |
1073 | |
1074 | CalcBoundingBox (x1, y1); | |
1075 | CalcBoundingBox (x2, y2); | |
1076 | CalcBoundingBox (xc, yc); | |
ff910433 RR |
1077 | } |
1078 | ||
1079 | void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
1080 | { | |
16744532 RR |
1081 | x += w/2; |
1082 | y += h/2; | |
1083 | ||
02255e07 RR |
1084 | double xx = XLOG2DEV(x); |
1085 | double yy = YLOG2DEV(y); | |
16744532 | 1086 | |
ced3df77 | 1087 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
16744532 | 1088 | |
ced3df77 | 1089 | gs_libGnomePrint->gnome_print_translate( m_gpc, xx, yy ); |
16744532 | 1090 | double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); |
ced3df77 | 1091 | gs_libGnomePrint->gnome_print_scale( m_gpc, 1.0, scale ); |
389076f1 | 1092 | |
02255e07 RR |
1093 | xx = 0.0; |
1094 | yy = 0.0; | |
16744532 RR |
1095 | |
1096 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1097 | { | |
1098 | SetBrush( m_brush ); | |
389076f1 | 1099 | |
ced3df77 VZ |
1100 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy ); |
1101 | gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy, | |
16744532 | 1102 | XLOG2DEVREL(w)/2, sa, ea, 0 ); |
ced3df77 | 1103 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy ); |
389076f1 | 1104 | |
ced3df77 | 1105 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
16744532 | 1106 | } |
389076f1 | 1107 | |
16744532 RR |
1108 | if (m_pen.GetStyle () != wxTRANSPARENT) |
1109 | { | |
1110 | SetPen (m_pen); | |
389076f1 | 1111 | |
ced3df77 | 1112 | gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy, |
16744532 | 1113 | XLOG2DEVREL(w)/2, sa, ea, 0 ); |
389076f1 | 1114 | |
ced3df77 | 1115 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
16744532 | 1116 | } |
389076f1 | 1117 | |
ced3df77 | 1118 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
389076f1 | 1119 | |
16744532 RR |
1120 | CalcBoundingBox( x, y ); |
1121 | CalcBoundingBox( x+w, y+h ); | |
ff910433 RR |
1122 | } |
1123 | ||
1124 | void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y) | |
1125 | { | |
1126 | } | |
1127 | ||
1128 | void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
1129 | { | |
cac7ac30 RR |
1130 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
1131 | ||
1132 | if (n <= 0) return; | |
1133 | ||
1134 | SetPen (m_pen); | |
1135 | ||
1136 | int i; | |
1137 | for ( i =0; i<n ; i++ ) | |
16744532 | 1138 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset); |
cac7ac30 | 1139 | |
ced3df77 | 1140 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); |
389076f1 | 1141 | |
cac7ac30 | 1142 | for (i = 1; i < n; i++) |
ced3df77 | 1143 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); |
cac7ac30 | 1144 | |
ced3df77 | 1145 | gs_libGnomePrint->gnome_print_stroke ( m_gpc); |
ff910433 RR |
1146 | } |
1147 | ||
1148 | void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
1149 | { | |
a92964a2 RR |
1150 | if (n==0) return; |
1151 | ||
1152 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1153 | { | |
1154 | SetBrush( m_brush ); | |
389076f1 | 1155 | |
a92964a2 RR |
1156 | int x = points[0].x + xoffset; |
1157 | int y = points[0].y + yoffset; | |
1158 | CalcBoundingBox( x, y ); | |
ced3df77 VZ |
1159 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1160 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
a92964a2 RR |
1161 | int i; |
1162 | for (i = 1; i < n; i++) | |
1163 | { | |
74ab5f5b VZ |
1164 | x = points[i].x + xoffset; |
1165 | y = points[i].y + yoffset; | |
ced3df77 | 1166 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
a92964a2 RR |
1167 | CalcBoundingBox( x, y ); |
1168 | } | |
ced3df77 VZ |
1169 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
1170 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
a92964a2 RR |
1171 | } |
1172 | ||
1173 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1174 | { | |
1175 | SetPen (m_pen); | |
1176 | ||
1177 | int x = points[0].x + xoffset; | |
1178 | int y = points[0].y + yoffset; | |
ced3df77 VZ |
1179 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1180 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
a92964a2 RR |
1181 | int i; |
1182 | for (i = 1; i < n; i++) | |
1183 | { | |
74ab5f5b VZ |
1184 | x = points[i].x + xoffset; |
1185 | y = points[i].y + yoffset; | |
ced3df77 | 1186 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
a92964a2 RR |
1187 | CalcBoundingBox( x, y ); |
1188 | } | |
ced3df77 VZ |
1189 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
1190 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
a92964a2 | 1191 | } |
ff910433 RR |
1192 | } |
1193 | ||
1194 | void wxGnomePrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle) | |
1195 | { | |
a92964a2 | 1196 | wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); |
ff910433 RR |
1197 | } |
1198 | ||
1199 | void wxGnomePrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1200 | { | |
1201 | if (m_brush.GetStyle () != wxTRANSPARENT) | |
1202 | { | |
1203 | SetBrush( m_brush ); | |
389076f1 | 1204 | |
ced3df77 VZ |
1205 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1206 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1207 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1208 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1209 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1210 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1211 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
ff910433 RR |
1212 | |
1213 | CalcBoundingBox( x, y ); | |
1214 | CalcBoundingBox( x + width, y + height ); | |
1215 | } | |
1216 | ||
1217 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1218 | { | |
1219 | SetPen (m_pen); | |
1220 | ||
ced3df77 VZ |
1221 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1222 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1223 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1224 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1225 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1226 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1227 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
389076f1 | 1228 | |
ff910433 RR |
1229 | CalcBoundingBox( x, y ); |
1230 | CalcBoundingBox( x + width, y + height ); | |
1231 | } | |
1232 | } | |
1233 | ||
1234 | void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
1235 | { | |
9a2fe010 RR |
1236 | wxCoord rad = (wxCoord) radius; |
1237 | ||
1238 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1239 | { | |
1240 | SetBrush(m_brush); | |
ced3df77 VZ |
1241 | gs_libGnomePrint->gnome_print_newpath(m_gpc); |
1242 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1243 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1244 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1245 | XLOG2DEV(x),YLOG2DEV(y), | |
1246 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
ced3df77 VZ |
1247 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1248 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1249 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1250 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1251 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
ced3df77 VZ |
1252 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1253 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1254 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1255 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1256 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
ced3df77 VZ |
1257 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1258 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1259 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1260 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1261 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
ced3df77 VZ |
1262 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1263 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1264 | gs_libGnomePrint->gnome_print_fill(m_gpc); | |
389076f1 | 1265 | |
9a2fe010 RR |
1266 | CalcBoundingBox(x,y); |
1267 | CalcBoundingBox(x+width,y+height); | |
1268 | } | |
389076f1 | 1269 | |
9a2fe010 RR |
1270 | if (m_pen.GetStyle() != wxTRANSPARENT) |
1271 | { | |
1272 | SetPen(m_pen); | |
ced3df77 VZ |
1273 | gs_libGnomePrint->gnome_print_newpath(m_gpc); |
1274 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1275 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1276 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1277 | XLOG2DEV(x),YLOG2DEV(y), | |
1278 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
ced3df77 VZ |
1279 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1280 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1281 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1282 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1283 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
ced3df77 VZ |
1284 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1285 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1286 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1287 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1288 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
ced3df77 VZ |
1289 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1290 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1291 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1292 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1293 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
ced3df77 VZ |
1294 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1295 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1296 | gs_libGnomePrint->gnome_print_stroke(m_gpc); | |
389076f1 | 1297 | |
9a2fe010 RR |
1298 | CalcBoundingBox(x,y); |
1299 | CalcBoundingBox(x+width,y+height); | |
1300 | } | |
ff910433 RR |
1301 | } |
1302 | ||
e4db172a | 1303 | void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, |
74ab0bfb RR |
1304 | wxCoord width, wxCoord height) |
1305 | { | |
61643018 | 1306 | double r = 4 * (sqrt(2.) - 1) / 3; |
74ab0bfb RR |
1307 | double halfW = 0.5 * width, |
1308 | halfH = 0.5 * height, | |
1309 | halfWR = r * halfW, | |
1310 | halfHR = r * halfH; | |
1311 | wxCoord halfWI = (wxCoord) halfW, | |
1312 | halfHI = (wxCoord) halfH; | |
e4db172a | 1313 | |
ced3df77 | 1314 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
e4db172a | 1315 | |
74ab0bfb | 1316 | // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ |
ced3df77 | 1317 | gs_libGnomePrint->gnome_print_moveto( m_gpc, |
e4db172a | 1318 | XLOG2DEV(x + width), |
74ab0bfb | 1319 | YLOG2DEV(y + halfHI) ); |
ced3df77 | 1320 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1321 | XLOG2DEV(x + width), |
1322 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
e4db172a | 1323 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
74ab0bfb | 1324 | YLOG2DEV(y + height), |
e4db172a | 1325 | XLOG2DEV(x + halfWI), |
74ab0bfb | 1326 | YLOG2DEV(y + height) ); |
ced3df77 | 1327 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
e4db172a | 1328 | XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), |
74ab0bfb RR |
1329 | YLOG2DEV(y + height), |
1330 | XLOG2DEV(x), | |
1331 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
1332 | XLOG2DEV(x), YLOG2DEV(y+halfHI) ); | |
ced3df77 | 1333 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1334 | XLOG2DEV(x), |
1335 | YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)), | |
1336 | XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)), | |
1337 | YLOG2DEV(y), | |
1338 | XLOG2DEV(x+halfWI), YLOG2DEV(y) ); | |
ced3df77 | 1339 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1340 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
1341 | YLOG2DEV(y), | |
1342 | XLOG2DEV(x + width), | |
1343 | YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), | |
1344 | XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); | |
e4db172a | 1345 | |
ced3df77 | 1346 | gs_libGnomePrint->gnome_print_closepath(m_gpc); |
74ab0bfb RR |
1347 | } |
1348 | ||
ff910433 RR |
1349 | void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
1350 | { | |
cac7ac30 RR |
1351 | if (m_brush.GetStyle () != wxTRANSPARENT) |
1352 | { | |
1353 | SetBrush( m_brush ); | |
74ab0bfb | 1354 | makeEllipticalPath( x, y, width, height ); |
ced3df77 | 1355 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
cac7ac30 RR |
1356 | CalcBoundingBox( x, y ); |
1357 | CalcBoundingBox( x + width, y + height ); | |
1358 | } | |
1359 | ||
1360 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1361 | { | |
1362 | SetPen (m_pen); | |
74ab0bfb | 1363 | makeEllipticalPath( x, y, width, height ); |
ced3df77 | 1364 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
cac7ac30 RR |
1365 | CalcBoundingBox( x, y ); |
1366 | CalcBoundingBox( x + width, y + height ); | |
1367 | } | |
ff910433 RR |
1368 | } |
1369 | ||
389076f1 | 1370 | #if wxUSE_SPLINES |
ff910433 RR |
1371 | void wxGnomePrintDC::DoDrawSpline(wxList *points) |
1372 | { | |
121c09cd RR |
1373 | SetPen (m_pen); |
1374 | ||
1375 | double c, d, x1, y1, x2, y2, x3, y3; | |
1376 | wxPoint *p, *q; | |
1377 | ||
1378 | wxList::compatibility_iterator node = points->GetFirst(); | |
1379 | p = (wxPoint *)node->GetData(); | |
1380 | x1 = p->x; | |
1381 | y1 = p->y; | |
1382 | ||
1383 | node = node->GetNext(); | |
1384 | p = (wxPoint *)node->GetData(); | |
1385 | c = p->x; | |
1386 | d = p->y; | |
1387 | x3 = | |
1388 | (double)(x1 + c) / 2; | |
1389 | y3 = | |
1390 | (double)(y1 + d) / 2; | |
1391 | ||
ced3df77 VZ |
1392 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1393 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); | |
1394 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
389076f1 | 1395 | |
121c09cd RR |
1396 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); |
1397 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1398 | ||
1399 | node = node->GetNext(); | |
1400 | while (node) | |
1401 | { | |
1402 | q = (wxPoint *)node->GetData(); | |
1403 | ||
1404 | x1 = x3; | |
1405 | y1 = y3; | |
1406 | x2 = c; | |
1407 | y2 = d; | |
1408 | c = q->x; | |
1409 | d = q->y; | |
1410 | x3 = (double)(x2 + c) / 2; | |
1411 | y3 = (double)(y2 + d) / 2; | |
1412 | ||
ced3df77 | 1413 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
121c09cd RR |
1414 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), |
1415 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), | |
1416 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
1417 | ||
1418 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1419 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1420 | ||
1421 | node = node->GetNext(); | |
1422 | } | |
389076f1 | 1423 | |
ced3df77 | 1424 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); |
389076f1 | 1425 | |
ced3df77 | 1426 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
ff910433 | 1427 | } |
389076f1 | 1428 | #endif // wxUSE_SPLINES |
ff910433 RR |
1429 | |
1430 | bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
1431 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, | |
1432 | wxCoord xsrcMask, wxCoord ysrcMask) | |
1433 | { | |
2f41910a RR |
1434 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
1435 | ||
1436 | // blit into a bitmap | |
1437 | wxBitmap bitmap( width, height ); | |
1438 | wxMemoryDC memDC; | |
1439 | memDC.SelectObject(bitmap); | |
1440 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ | |
1441 | memDC.SelectObject(wxNullBitmap); | |
1442 | ||
1443 | // draw bitmap. scaling and positioning is done there | |
1444 | DrawBitmap( bitmap, xdest, ydest ); | |
1445 | ||
1446 | return true; | |
ff910433 RR |
1447 | } |
1448 | ||
1449 | void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) | |
1450 | { | |
e1bf3ad3 | 1451 | DoDrawBitmap( icon, x, y, true ); |
ff910433 RR |
1452 | } |
1453 | ||
1454 | void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) | |
1455 | { | |
e1bf3ad3 | 1456 | if (!bitmap.Ok()) return; |
389076f1 | 1457 | |
e1bf3ad3 RR |
1458 | if (bitmap.HasPixbuf()) |
1459 | { | |
2934005d | 1460 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); |
389076f1 WS |
1461 | guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf ); |
1462 | bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf ); | |
1463 | int rowstride = gdk_pixbuf_get_rowstride( pixbuf ); | |
1464 | int height = gdk_pixbuf_get_height( pixbuf ); | |
1465 | int width = gdk_pixbuf_get_width( pixbuf ); | |
1466 | ||
ced3df77 | 1467 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
2934005d | 1468 | double matrix[6]; |
389076f1 WS |
1469 | matrix[0] = XLOG2DEVREL(width); |
1470 | matrix[1] = 0; | |
1471 | matrix[2] = 0; | |
1472 | matrix[3] = YLOG2DEVREL(height); | |
1473 | matrix[4] = XLOG2DEV(x); | |
2934005d | 1474 | matrix[5] = YLOG2DEV(y+height); |
ced3df77 VZ |
1475 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); |
1476 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); | |
2934005d | 1477 | if (has_alpha) |
ced3df77 | 1478 | gs_libGnomePrint->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
2934005d | 1479 | else |
ced3df77 VZ |
1480 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
1481 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
e1bf3ad3 RR |
1482 | } |
1483 | else | |
e1bf3ad3 RR |
1484 | { |
1485 | wxImage image = bitmap.ConvertToImage(); | |
1486 | ||
1487 | if (!image.Ok()) return; | |
2934005d | 1488 | |
ced3df77 | 1489 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
b4382784 | 1490 | double matrix[6]; |
389076f1 WS |
1491 | matrix[0] = XLOG2DEVREL(image.GetWidth()); |
1492 | matrix[1] = 0; | |
1493 | matrix[2] = 0; | |
1494 | matrix[3] = YLOG2DEVREL(image.GetHeight()); | |
1495 | matrix[4] = XLOG2DEV(x); | |
b4382784 | 1496 | matrix[5] = YLOG2DEV(y+image.GetHeight()); |
ced3df77 VZ |
1497 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); |
1498 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); | |
1499 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); | |
1500 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
e1bf3ad3 | 1501 | } |
ff910433 RR |
1502 | } |
1503 | ||
1504 | void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) | |
b199de59 RR |
1505 | { |
1506 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1507 | } | |
1508 | ||
1509 | void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
ff910433 | 1510 | { |
02255e07 RR |
1511 | double xx = XLOG2DEV(x); |
1512 | double yy = YLOG2DEV(y); | |
389076f1 | 1513 | |
ff910433 RR |
1514 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); |
1515 | ||
e0a050e3 VS |
1516 | // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer |
1517 | #if wxUSE_UNICODE_UTF8 | |
1518 | const char *data = text.utf8_str(); | |
ff910433 | 1519 | #else |
e0a050e3 | 1520 | const wxCharBuffer data = text.utf8_str(); |
ff910433 RR |
1521 | #endif |
1522 | ||
e0a050e3 VS |
1523 | size_t datalen = strlen(data); |
1524 | pango_layout_set_text( m_layout, data, datalen); | |
389076f1 | 1525 | |
ff910433 RR |
1526 | if (underlined) |
1527 | { | |
1528 | PangoAttrList *attrs = pango_attr_list_new(); | |
1529 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1530 | a->start_index = 0; | |
1531 | a->end_index = datalen; | |
1532 | pango_attr_list_insert(attrs, a); | |
1533 | pango_layout_set_attributes(m_layout, attrs); | |
1534 | pango_attr_list_unref(attrs); | |
1535 | } | |
1536 | ||
2934005d RR |
1537 | if (m_textForegroundColour.Ok()) |
1538 | { | |
1539 | unsigned char red = m_textForegroundColour.Red(); | |
1540 | unsigned char blue = m_textForegroundColour.Blue(); | |
1541 | unsigned char green = m_textForegroundColour.Green(); | |
1542 | ||
b199de59 RR |
1543 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
1544 | { | |
1545 | double redPS = (double)(red) / 255.0; | |
1546 | double bluePS = (double)(blue) / 255.0; | |
1547 | double greenPS = (double)(green) / 255.0; | |
1548 | ||
ced3df77 | 1549 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
b199de59 RR |
1550 | |
1551 | m_currentRed = red; | |
1552 | m_currentBlue = blue; | |
1553 | m_currentGreen = green; | |
1554 | } | |
2934005d RR |
1555 | } |
1556 | ||
fa499247 | 1557 | int w,h; |
02255e07 | 1558 | pango_layout_get_pixel_size( m_layout, &w, &h ); |
fa499247 RR |
1559 | #if 0 |
1560 | if ( m_backgroundMode == wxSOLID ) | |
1561 | { | |
1562 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
02255e07 | 1563 | gdk_draw_rectangle(m_window, m_textGC, TRUE, xx, yy, w, h); |
fa499247 RR |
1564 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); |
1565 | } | |
389076f1 | 1566 | #endif |
fa499247 | 1567 | |
02255e07 RR |
1568 | // Draw layout. |
1569 | gs_libGnomePrint->gnome_print_moveto (m_gpc, xx, yy); | |
1570 | ||
1571 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); | |
1572 | ||
1573 | gs_libGnomePrint->gnome_print_scale( m_gpc, m_scaleX * DEV2PS, m_scaleY * DEV2PS ); | |
1574 | ||
1575 | if (fabs(angle) > 0.00001) | |
1576 | gs_libGnomePrint->gnome_print_rotate( m_gpc, angle ); | |
1577 | ||
1578 | gs_libGnomePrint->gnome_print_pango_layout( m_gpc, m_layout ); | |
1579 | ||
1580 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
1581 | ||
ff910433 RR |
1582 | if (underlined) |
1583 | { | |
1584 | // undo underline attributes setting: | |
1585 | pango_layout_set_attributes(m_layout, NULL); | |
1586 | } | |
389076f1 | 1587 | |
b199de59 | 1588 | CalcBoundingBox (x + w, y + h); |
ff910433 RR |
1589 | } |
1590 | ||
1591 | void wxGnomePrintDC::Clear() | |
1592 | { | |
1593 | } | |
1594 | ||
1595 | void wxGnomePrintDC::SetFont( const wxFont& font ) | |
1596 | { | |
1597 | m_font = font; | |
389076f1 | 1598 | |
ff910433 RR |
1599 | if (m_font.Ok()) |
1600 | { | |
1601 | if (m_fontdesc) | |
1602 | pango_font_description_free( m_fontdesc ); | |
389076f1 | 1603 | |
ff910433 | 1604 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
389076f1 | 1605 | |
ff910433 RR |
1606 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
1607 | } | |
1608 | } | |
1609 | ||
1610 | void wxGnomePrintDC::SetPen( const wxPen& pen ) | |
1611 | { | |
1612 | if (!pen.Ok()) return; | |
1613 | ||
ff910433 RR |
1614 | m_pen = pen; |
1615 | ||
f62edb0e RR |
1616 | double width; |
1617 | ||
1618 | if (m_pen.GetWidth() <= 0) | |
1619 | width = 0.1; | |
1620 | else | |
1621 | width = (double) m_pen.GetWidth(); | |
1622 | ||
1623 | gs_libGnomePrint->gnome_print_setlinewidth( m_gpc, width * DEV2PS * m_scaleX ); | |
cac7ac30 RR |
1624 | |
1625 | static const double dotted[] = {2.0, 5.0}; | |
1626 | static const double short_dashed[] = {4.0, 4.0}; | |
1627 | static const double wxCoord_dashed[] = {4.0, 8.0}; | |
1628 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1629 | ||
1630 | switch (m_pen.GetStyle()) | |
1631 | { | |
ced3df77 VZ |
1632 | case wxDOT: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break; |
1633 | case wxSHORT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; | |
1634 | case wxLONG_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; | |
1635 | case wxDOT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; | |
e4db172a | 1636 | case wxUSER_DASH: |
8c419a5c RR |
1637 | { |
1638 | // It may be noted that libgnomeprint between at least | |
1639 | // versions 2.8.0 and 2.12.1 makes a copy of the dashes | |
1640 | // and then leak the memory since it doesn't set the | |
1641 | // internal flag "privatedash" to 0. | |
1642 | wxDash *wx_dashes; | |
1643 | int num = m_pen.GetDashes (&wx_dashes); | |
1644 | gdouble *g_dashes = g_new( gdouble, num ); | |
1645 | int i; | |
1646 | for (i = 0; i < num; ++i) | |
1647 | g_dashes[i] = (gdouble) wx_dashes[i]; | |
ced3df77 | 1648 | gs_libGnomePrint -> gnome_print_setdash( m_gpc, num, g_dashes, 0); |
8c419a5c RR |
1649 | g_free( g_dashes ); |
1650 | } | |
1651 | break; | |
cac7ac30 RR |
1652 | case wxSOLID: |
1653 | case wxTRANSPARENT: | |
ced3df77 | 1654 | default: gs_libGnomePrint->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; |
cac7ac30 RR |
1655 | } |
1656 | ||
389076f1 | 1657 | |
ff910433 RR |
1658 | unsigned char red = m_pen.GetColour().Red(); |
1659 | unsigned char blue = m_pen.GetColour().Blue(); | |
1660 | unsigned char green = m_pen.GetColour().Green(); | |
1661 | ||
1662 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1663 | { | |
1664 | double redPS = (double)(red) / 255.0; | |
1665 | double bluePS = (double)(blue) / 255.0; | |
1666 | double greenPS = (double)(green) / 255.0; | |
1667 | ||
ced3df77 | 1668 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
ff910433 RR |
1669 | |
1670 | m_currentRed = red; | |
1671 | m_currentBlue = blue; | |
1672 | m_currentGreen = green; | |
1673 | } | |
1674 | } | |
1675 | ||
1676 | void wxGnomePrintDC::SetBrush( const wxBrush& brush ) | |
1677 | { | |
fa499247 RR |
1678 | if (!brush.Ok()) return; |
1679 | ||
1680 | m_brush = brush; | |
1681 | ||
1682 | // Brush colour | |
1683 | unsigned char red = m_brush.GetColour().Red(); | |
1684 | unsigned char blue = m_brush.GetColour().Blue(); | |
1685 | unsigned char green = m_brush.GetColour().Green(); | |
1686 | ||
1687 | if (!m_colour) | |
1688 | { | |
1689 | // Anything not white is black | |
1690 | if (! (red == (unsigned char) 255 && | |
1691 | blue == (unsigned char) 255 && | |
1692 | green == (unsigned char) 255) ) | |
1693 | { | |
1694 | red = (unsigned char) 0; | |
1695 | green = (unsigned char) 0; | |
1696 | blue = (unsigned char) 0; | |
1697 | } | |
1698 | // setgray here ? | |
1699 | } | |
1700 | ||
1701 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1702 | { | |
1703 | double redPS = (double)(red) / 255.0; | |
1704 | double bluePS = (double)(blue) / 255.0; | |
1705 | double greenPS = (double)(green) / 255.0; | |
1706 | ||
ced3df77 | 1707 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
fa499247 RR |
1708 | |
1709 | m_currentRed = red; | |
1710 | m_currentBlue = blue; | |
1711 | m_currentGreen = green; | |
1712 | } | |
ff910433 RR |
1713 | } |
1714 | ||
1715 | void wxGnomePrintDC::SetLogicalFunction( int function ) | |
1716 | { | |
1717 | } | |
1718 | ||
1719 | void wxGnomePrintDC::SetBackground( const wxBrush& brush ) | |
1720 | { | |
1721 | } | |
1722 | ||
1723 | void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1724 | { | |
75aa53c9 RR |
1725 | wxDC::DoSetClippingRegion( x, y, width, height ); |
1726 | ||
ced3df77 | 1727 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
3b7ab6bd | 1728 | |
ced3df77 VZ |
1729 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1730 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1731 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1732 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1733 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1734 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1735 | gs_libGnomePrint->gnome_print_clip( m_gpc ); | |
ff910433 RR |
1736 | } |
1737 | ||
1738 | void wxGnomePrintDC::DestroyClippingRegion() | |
1739 | { | |
75aa53c9 RR |
1740 | wxDC::DestroyClippingRegion(); |
1741 | ||
ced3df77 | 1742 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
3b7ab6bd RR |
1743 | |
1744 | #if 0 | |
1745 | // not needed, we set the values in each | |
1746 | // drawing method anyways | |
1747 | SetPen( m_pen ); | |
1748 | SetBrush( m_brush ); | |
1749 | SetFont( m_font ); | |
1750 | #endif | |
ff910433 RR |
1751 | } |
1752 | ||
1753 | bool wxGnomePrintDC::StartDoc(const wxString& message) | |
1754 | { | |
ff910433 RR |
1755 | return true; |
1756 | } | |
1757 | ||
1758 | void wxGnomePrintDC::EndDoc() | |
1759 | { | |
ced3df77 | 1760 | gs_libGnomePrint->gnome_print_end_doc( m_gpc ); |
ff910433 RR |
1761 | } |
1762 | ||
1763 | void wxGnomePrintDC::StartPage() | |
1764 | { | |
ced3df77 | 1765 | gs_libGnomePrint->gnome_print_beginpage( m_gpc, (const guchar*) "page" ); |
ff910433 RR |
1766 | } |
1767 | ||
1768 | void wxGnomePrintDC::EndPage() | |
1769 | { | |
ced3df77 | 1770 | gs_libGnomePrint->gnome_print_showpage( m_gpc ); |
ff910433 RR |
1771 | } |
1772 | ||
1773 | wxCoord wxGnomePrintDC::GetCharHeight() const | |
1774 | { | |
b199de59 | 1775 | pango_layout_set_text( m_layout, "H", 1 ); |
389076f1 | 1776 | |
b199de59 RR |
1777 | int w,h; |
1778 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1779 | |
b199de59 | 1780 | return h; |
ff910433 RR |
1781 | } |
1782 | ||
1783 | wxCoord wxGnomePrintDC::GetCharWidth() const | |
1784 | { | |
b199de59 | 1785 | pango_layout_set_text( m_layout, "H", 1 ); |
389076f1 | 1786 | |
b199de59 RR |
1787 | int w,h; |
1788 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1789 | |
b199de59 | 1790 | return w; |
ff910433 RR |
1791 | } |
1792 | ||
981a6af1 | 1793 | void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
ff910433 RR |
1794 | wxCoord *descent, |
1795 | wxCoord *externalLeading, | |
c94f845b | 1796 | const wxFont *theFont ) const |
ff910433 | 1797 | { |
981a6af1 RR |
1798 | if ( width ) |
1799 | *width = 0; | |
1800 | if ( height ) | |
1801 | *height = 0; | |
1802 | if ( descent ) | |
1803 | *descent = 0; | |
1804 | if ( externalLeading ) | |
1805 | *externalLeading = 0; | |
1806 | ||
389076f1 | 1807 | if (string.empty()) |
981a6af1 RR |
1808 | { |
1809 | return; | |
1810 | } | |
389076f1 | 1811 | |
981a6af1 | 1812 | // Set layout's text |
e0a050e3 VS |
1813 | |
1814 | // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer | |
1815 | #if wxUSE_UNICODE_UTF8 | |
1816 | const char *dataUTF8 = string.utf8_str(); | |
981a6af1 | 1817 | #else |
e0a050e3 | 1818 | const wxCharBuffer dataUTF8 = string.utf8_str(); |
981a6af1 RR |
1819 | #endif |
1820 | ||
0cc0ce06 RR |
1821 | PangoFontDescription *desc = (theFont) ? theFont->GetNativeFontInfo()->description : m_fontdesc; |
1822 | ||
1823 | gint oldSize = pango_font_description_get_size( desc ); | |
1824 | double size = oldSize; | |
1825 | size = size * m_scaleY; | |
1826 | pango_font_description_set_size( desc, (gint)size ); | |
1827 | ||
1828 | // apply scaled font | |
1829 | pango_layout_set_font_description( m_layout, desc ); | |
1830 | ||
981a6af1 | 1831 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); |
389076f1 | 1832 | |
0cc0ce06 | 1833 | int w, h; |
981a6af1 | 1834 | pango_layout_get_pixel_size( m_layout, &w, &h ); |
389076f1 | 1835 | |
0cc0ce06 | 1836 | |
981a6af1 | 1837 | if (width) |
389076f1 | 1838 | *width = (wxCoord)(w / m_scaleX); |
981a6af1 | 1839 | if (height) |
15236815 | 1840 | *height = (wxCoord)(h / m_scaleY); |
0cc0ce06 | 1841 | |
981a6af1 RR |
1842 | if (descent) |
1843 | { | |
1844 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
1845 | int baseline = pango_layout_iter_get_baseline(iter); | |
1846 | pango_layout_iter_free(iter); | |
1847 | *descent = h - PANGO_PIXELS(baseline); | |
1848 | } | |
389076f1 | 1849 | |
0cc0ce06 RR |
1850 | // reset unscaled size |
1851 | pango_font_description_set_size( desc, oldSize ); | |
1852 | ||
1853 | // reset unscaled font | |
1854 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
ff910433 RR |
1855 | } |
1856 | ||
1857 | void wxGnomePrintDC::DoGetSize(int* width, int* height) const | |
1858 | { | |
cffcf831 RR |
1859 | wxGnomePrintNativeData *native = |
1860 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1861 | ||
1862 | // Query page size. This seems to omit the margins | |
cffcf831 | 1863 | double pw,ph; |
ced3df77 | 1864 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
ff910433 | 1865 | |
ff910433 | 1866 | if (width) |
02255e07 | 1867 | *width = wxRound( pw * PS2DEV ); |
f62edb0e | 1868 | |
ff910433 | 1869 | if (height) |
02255e07 | 1870 | *height = wxRound( ph * PS2DEV ); |
ff910433 RR |
1871 | } |
1872 | ||
1873 | void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const | |
1874 | { | |
cffcf831 RR |
1875 | wxGnomePrintNativeData *native = |
1876 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1877 | ||
389076f1 WS |
1878 | // This code assumes values in Pts. |
1879 | ||
cffcf831 | 1880 | double pw,ph; |
ced3df77 | 1881 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
cffcf831 RR |
1882 | |
1883 | // Convert to mm. | |
389076f1 | 1884 | |
ced3df77 VZ |
1885 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
1886 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
1887 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
1888 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
389076f1 | 1889 | |
ff910433 | 1890 | if (width) |
cffcf831 | 1891 | *width = (int) (pw + 0.5); |
ff910433 | 1892 | if (height) |
cffcf831 | 1893 | *height = (int) (ph + 0.5); |
ff910433 RR |
1894 | } |
1895 | ||
1896 | wxSize wxGnomePrintDC::GetPPI() const | |
1897 | { | |
02255e07 | 1898 | return wxSize(DPI,DPI); |
92120c6e RR |
1899 | } |
1900 | ||
3b7ab6bd RR |
1901 | void wxGnomePrintDC::SetPrintData(const wxPrintData& data) |
1902 | { | |
1903 | m_printData = data; | |
1904 | ||
02255e07 | 1905 | int height; |
3b7ab6bd | 1906 | if (m_printData.GetOrientation() == wxPORTRAIT) |
02255e07 | 1907 | GetSize( NULL, &height ); |
3b7ab6bd | 1908 | else |
02255e07 RR |
1909 | GetSize( &height, NULL ); |
1910 | m_deviceLocalOriginY = height; | |
3b7ab6bd RR |
1911 | } |
1912 | ||
ff910433 RR |
1913 | void wxGnomePrintDC::SetResolution(int ppi) |
1914 | { | |
1915 | } | |
1916 | ||
1917 | int wxGnomePrintDC::GetResolution() | |
1918 | { | |
02255e07 | 1919 | return DPI; |
ff910433 | 1920 | } |
7c72311f | 1921 | |
1ff62f51 RR |
1922 | // ---------------------------------------------------------------------------- |
1923 | // wxGnomePrintModule | |
1924 | // ---------------------------------------------------------------------------- | |
58c30cd8 | 1925 | |
c6efd6e0 RR |
1926 | bool wxGnomePrintModule::OnInit() |
1927 | { | |
ced3df77 VZ |
1928 | gs_libGnomePrint = new wxGnomePrintLibrary; |
1929 | if (gs_libGnomePrint->IsOk()) | |
c6efd6e0 RR |
1930 | wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); |
1931 | return true; | |
1932 | } | |
1933 | ||
1934 | void wxGnomePrintModule::OnExit() | |
1935 | { | |
ced3df77 VZ |
1936 | delete gs_libGnomePrint; |
1937 | gs_libGnomePrint = NULL; | |
c6efd6e0 RR |
1938 | } |
1939 | ||
58c30cd8 | 1940 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) |
389076f1 | 1941 | |
147bf263 JS |
1942 | // ---------------------------------------------------------------------------- |
1943 | // Print preview | |
1944 | // ---------------------------------------------------------------------------- | |
1945 | ||
1946 | IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase) | |
1947 | ||
1948 | void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout), | |
1949 | wxPrintout * WXUNUSED(printoutForPrinting)) | |
1950 | { | |
1951 | DetermineScaling(); | |
1952 | } | |
1953 | ||
1954 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
1955 | wxPrintout *printoutForPrinting, | |
1956 | wxPrintDialogData *data) | |
1957 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
1958 | { | |
1959 | Init(printout, printoutForPrinting); | |
1960 | } | |
1961 | ||
1962 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
1963 | wxPrintout *printoutForPrinting, | |
1964 | wxPrintData *data) | |
1965 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
1966 | { | |
1967 | Init(printout, printoutForPrinting); | |
1968 | } | |
1969 | ||
1970 | wxGnomePrintPreview::~wxGnomePrintPreview() | |
1971 | { | |
1972 | } | |
1973 | ||
1974 | bool wxGnomePrintPreview::Print(bool interactive) | |
1975 | { | |
1976 | if (!m_printPrintout) | |
1977 | return false; | |
1978 | ||
1979 | wxPrinter printer(& m_printDialogData); | |
1980 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
1981 | } | |
1982 | ||
1983 | void wxGnomePrintPreview::DetermineScaling() | |
1984 | { | |
1985 | wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); | |
1986 | if (paperType == wxPAPER_NONE) | |
1987 | paperType = wxPAPER_NONE; | |
1988 | ||
1989 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); | |
1990 | if (!paper) | |
1991 | paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); | |
1992 | ||
1993 | if (paper) | |
1994 | { | |
1995 | wxSize ScreenPixels = wxGetDisplaySize(); | |
1996 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
1997 | ||
1998 | m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
1999 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
2000 | m_previewPrintout->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution()); | |
2001 | ||
2002 | wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); | |
f4322df6 | 2003 | |
147bf263 JS |
2004 | // TODO: get better resolution information from wxGnomePrintDC, if possible. |
2005 | ||
2006 | sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxGnomePrintDC::GetResolution() / 72.0); | |
2007 | sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxGnomePrintDC::GetResolution() / 72.0); | |
2008 | wxSize sizeTenthsMM(paper->GetSize()); | |
2009 | wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); | |
2010 | ||
2011 | // If in landscape mode, we need to swap the width and height. | |
2012 | if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) | |
2013 | { | |
2014 | m_pageWidth = sizeDevUnits.y; | |
2015 | m_pageHeight = sizeDevUnits.x; | |
2016 | m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); | |
147bf263 JS |
2017 | } |
2018 | else | |
2019 | { | |
2020 | m_pageWidth = sizeDevUnits.x; | |
2021 | m_pageHeight = sizeDevUnits.y; | |
2022 | m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); | |
147bf263 | 2023 | } |
f415cab9 JS |
2024 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); |
2025 | m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); | |
147bf263 JS |
2026 | |
2027 | // At 100%, the page should look about page-size on the screen. | |
f415cab9 JS |
2028 | m_previewScaleX = (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution(); |
2029 | m_previewScaleY = m_previewScaleX; | |
147bf263 JS |
2030 | } |
2031 | } | |
2032 | ||
32f34982 RR |
2033 | #endif |
2034 | // wxUSE_LIBGNOMEPRINT |