]>
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 | { | |
728ddc45 RR |
1201 | width--; |
1202 | height--; | |
1203 | ||
ff910433 RR |
1204 | if (m_brush.GetStyle () != wxTRANSPARENT) |
1205 | { | |
1206 | SetBrush( m_brush ); | |
389076f1 | 1207 | |
ced3df77 VZ |
1208 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1209 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1210 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1211 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1212 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1213 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1214 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
ff910433 RR |
1215 | |
1216 | CalcBoundingBox( x, y ); | |
1217 | CalcBoundingBox( x + width, y + height ); | |
1218 | } | |
1219 | ||
1220 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1221 | { | |
1222 | SetPen (m_pen); | |
1223 | ||
ced3df77 VZ |
1224 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1225 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1226 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1227 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1228 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1229 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1230 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
389076f1 | 1231 | |
ff910433 RR |
1232 | CalcBoundingBox( x, y ); |
1233 | CalcBoundingBox( x + width, y + height ); | |
1234 | } | |
1235 | } | |
1236 | ||
1237 | void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
1238 | { | |
728ddc45 RR |
1239 | width--; |
1240 | height--; | |
1241 | ||
1242 | wxCoord rad = wxRound( radius ); | |
9a2fe010 RR |
1243 | |
1244 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1245 | { | |
1246 | SetBrush(m_brush); | |
ced3df77 VZ |
1247 | gs_libGnomePrint->gnome_print_newpath(m_gpc); |
1248 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1249 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1250 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1251 | XLOG2DEV(x),YLOG2DEV(y), | |
1252 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
ced3df77 VZ |
1253 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1254 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1255 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1256 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1257 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
ced3df77 VZ |
1258 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1259 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1260 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1261 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1262 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
ced3df77 VZ |
1263 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1264 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1265 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1266 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1267 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
ced3df77 VZ |
1268 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1269 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1270 | gs_libGnomePrint->gnome_print_fill(m_gpc); | |
389076f1 | 1271 | |
9a2fe010 RR |
1272 | CalcBoundingBox(x,y); |
1273 | CalcBoundingBox(x+width,y+height); | |
1274 | } | |
389076f1 | 1275 | |
9a2fe010 RR |
1276 | if (m_pen.GetStyle() != wxTRANSPARENT) |
1277 | { | |
1278 | SetPen(m_pen); | |
ced3df77 VZ |
1279 | gs_libGnomePrint->gnome_print_newpath(m_gpc); |
1280 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1281 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1282 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1283 | XLOG2DEV(x),YLOG2DEV(y), | |
1284 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
ced3df77 VZ |
1285 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1286 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1287 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1288 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1289 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
ced3df77 VZ |
1290 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1291 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1292 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1293 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1294 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
ced3df77 VZ |
1295 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1296 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1297 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1298 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1299 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
ced3df77 VZ |
1300 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1301 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1302 | gs_libGnomePrint->gnome_print_stroke(m_gpc); | |
389076f1 | 1303 | |
9a2fe010 RR |
1304 | CalcBoundingBox(x,y); |
1305 | CalcBoundingBox(x+width,y+height); | |
1306 | } | |
ff910433 RR |
1307 | } |
1308 | ||
e4db172a | 1309 | void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y, |
74ab0bfb RR |
1310 | wxCoord width, wxCoord height) |
1311 | { | |
61643018 | 1312 | double r = 4 * (sqrt(2.) - 1) / 3; |
74ab0bfb RR |
1313 | double halfW = 0.5 * width, |
1314 | halfH = 0.5 * height, | |
1315 | halfWR = r * halfW, | |
1316 | halfHR = r * halfH; | |
1317 | wxCoord halfWI = (wxCoord) halfW, | |
1318 | halfHI = (wxCoord) halfH; | |
e4db172a | 1319 | |
ced3df77 | 1320 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
e4db172a | 1321 | |
74ab0bfb | 1322 | // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ |
ced3df77 | 1323 | gs_libGnomePrint->gnome_print_moveto( m_gpc, |
e4db172a | 1324 | XLOG2DEV(x + width), |
74ab0bfb | 1325 | YLOG2DEV(y + halfHI) ); |
ced3df77 | 1326 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1327 | XLOG2DEV(x + width), |
1328 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
e4db172a | 1329 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
74ab0bfb | 1330 | YLOG2DEV(y + height), |
e4db172a | 1331 | XLOG2DEV(x + halfWI), |
74ab0bfb | 1332 | YLOG2DEV(y + height) ); |
ced3df77 | 1333 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
e4db172a | 1334 | XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), |
74ab0bfb RR |
1335 | YLOG2DEV(y + height), |
1336 | XLOG2DEV(x), | |
1337 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
1338 | XLOG2DEV(x), YLOG2DEV(y+halfHI) ); | |
ced3df77 | 1339 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1340 | XLOG2DEV(x), |
1341 | YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)), | |
1342 | XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)), | |
1343 | YLOG2DEV(y), | |
1344 | XLOG2DEV(x+halfWI), YLOG2DEV(y) ); | |
ced3df77 | 1345 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1346 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
1347 | YLOG2DEV(y), | |
1348 | XLOG2DEV(x + width), | |
1349 | YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), | |
1350 | XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); | |
e4db172a | 1351 | |
ced3df77 | 1352 | gs_libGnomePrint->gnome_print_closepath(m_gpc); |
74ab0bfb RR |
1353 | } |
1354 | ||
ff910433 RR |
1355 | void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
1356 | { | |
728ddc45 RR |
1357 | width--; |
1358 | height--; | |
1359 | ||
cac7ac30 RR |
1360 | if (m_brush.GetStyle () != wxTRANSPARENT) |
1361 | { | |
1362 | SetBrush( m_brush ); | |
74ab0bfb | 1363 | makeEllipticalPath( x, y, width, height ); |
ced3df77 | 1364 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
cac7ac30 RR |
1365 | CalcBoundingBox( x, y ); |
1366 | CalcBoundingBox( x + width, y + height ); | |
1367 | } | |
1368 | ||
1369 | if (m_pen.GetStyle () != wxTRANSPARENT) | |
1370 | { | |
1371 | SetPen (m_pen); | |
74ab0bfb | 1372 | makeEllipticalPath( x, y, width, height ); |
ced3df77 | 1373 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
cac7ac30 RR |
1374 | CalcBoundingBox( x, y ); |
1375 | CalcBoundingBox( x + width, y + height ); | |
1376 | } | |
ff910433 RR |
1377 | } |
1378 | ||
389076f1 | 1379 | #if wxUSE_SPLINES |
ff910433 RR |
1380 | void wxGnomePrintDC::DoDrawSpline(wxList *points) |
1381 | { | |
121c09cd RR |
1382 | SetPen (m_pen); |
1383 | ||
1384 | double c, d, x1, y1, x2, y2, x3, y3; | |
1385 | wxPoint *p, *q; | |
1386 | ||
1387 | wxList::compatibility_iterator node = points->GetFirst(); | |
1388 | p = (wxPoint *)node->GetData(); | |
1389 | x1 = p->x; | |
1390 | y1 = p->y; | |
1391 | ||
1392 | node = node->GetNext(); | |
1393 | p = (wxPoint *)node->GetData(); | |
1394 | c = p->x; | |
1395 | d = p->y; | |
1396 | x3 = | |
1397 | (double)(x1 + c) / 2; | |
1398 | y3 = | |
1399 | (double)(y1 + d) / 2; | |
1400 | ||
ced3df77 VZ |
1401 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1402 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); | |
1403 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
389076f1 | 1404 | |
121c09cd RR |
1405 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); |
1406 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1407 | ||
1408 | node = node->GetNext(); | |
1409 | while (node) | |
1410 | { | |
1411 | q = (wxPoint *)node->GetData(); | |
1412 | ||
1413 | x1 = x3; | |
1414 | y1 = y3; | |
1415 | x2 = c; | |
1416 | y2 = d; | |
1417 | c = q->x; | |
1418 | d = q->y; | |
1419 | x3 = (double)(x2 + c) / 2; | |
1420 | y3 = (double)(y2 + d) / 2; | |
1421 | ||
ced3df77 | 1422 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
121c09cd RR |
1423 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), |
1424 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), | |
1425 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
1426 | ||
1427 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1428 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1429 | ||
1430 | node = node->GetNext(); | |
1431 | } | |
389076f1 | 1432 | |
ced3df77 | 1433 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); |
389076f1 | 1434 | |
ced3df77 | 1435 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
ff910433 | 1436 | } |
389076f1 | 1437 | #endif // wxUSE_SPLINES |
ff910433 RR |
1438 | |
1439 | bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
1440 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, | |
1441 | wxCoord xsrcMask, wxCoord ysrcMask) | |
1442 | { | |
2f41910a RR |
1443 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
1444 | ||
1445 | // blit into a bitmap | |
1446 | wxBitmap bitmap( width, height ); | |
1447 | wxMemoryDC memDC; | |
1448 | memDC.SelectObject(bitmap); | |
1449 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ | |
1450 | memDC.SelectObject(wxNullBitmap); | |
1451 | ||
1452 | // draw bitmap. scaling and positioning is done there | |
1453 | DrawBitmap( bitmap, xdest, ydest ); | |
1454 | ||
1455 | return true; | |
ff910433 RR |
1456 | } |
1457 | ||
1458 | void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) | |
1459 | { | |
e1bf3ad3 | 1460 | DoDrawBitmap( icon, x, y, true ); |
ff910433 RR |
1461 | } |
1462 | ||
1463 | void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask ) | |
1464 | { | |
e1bf3ad3 | 1465 | if (!bitmap.Ok()) return; |
389076f1 | 1466 | |
e1bf3ad3 RR |
1467 | if (bitmap.HasPixbuf()) |
1468 | { | |
2934005d | 1469 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); |
389076f1 WS |
1470 | guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf ); |
1471 | bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf ); | |
1472 | int rowstride = gdk_pixbuf_get_rowstride( pixbuf ); | |
1473 | int height = gdk_pixbuf_get_height( pixbuf ); | |
1474 | int width = gdk_pixbuf_get_width( pixbuf ); | |
1475 | ||
ced3df77 | 1476 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
2934005d | 1477 | double matrix[6]; |
389076f1 WS |
1478 | matrix[0] = XLOG2DEVREL(width); |
1479 | matrix[1] = 0; | |
1480 | matrix[2] = 0; | |
1481 | matrix[3] = YLOG2DEVREL(height); | |
1482 | matrix[4] = XLOG2DEV(x); | |
2934005d | 1483 | matrix[5] = YLOG2DEV(y+height); |
ced3df77 VZ |
1484 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); |
1485 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); | |
2934005d | 1486 | if (has_alpha) |
ced3df77 | 1487 | gs_libGnomePrint->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
2934005d | 1488 | else |
ced3df77 VZ |
1489 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
1490 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
e1bf3ad3 RR |
1491 | } |
1492 | else | |
e1bf3ad3 RR |
1493 | { |
1494 | wxImage image = bitmap.ConvertToImage(); | |
1495 | ||
1496 | if (!image.Ok()) return; | |
2934005d | 1497 | |
ced3df77 | 1498 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
b4382784 | 1499 | double matrix[6]; |
389076f1 WS |
1500 | matrix[0] = XLOG2DEVREL(image.GetWidth()); |
1501 | matrix[1] = 0; | |
1502 | matrix[2] = 0; | |
1503 | matrix[3] = YLOG2DEVREL(image.GetHeight()); | |
1504 | matrix[4] = XLOG2DEV(x); | |
b4382784 | 1505 | matrix[5] = YLOG2DEV(y+image.GetHeight()); |
ced3df77 VZ |
1506 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); |
1507 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); | |
1508 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); | |
1509 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
e1bf3ad3 | 1510 | } |
ff910433 RR |
1511 | } |
1512 | ||
1513 | void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) | |
b199de59 RR |
1514 | { |
1515 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1516 | } | |
1517 | ||
1518 | void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
ff910433 | 1519 | { |
02255e07 RR |
1520 | double xx = XLOG2DEV(x); |
1521 | double yy = YLOG2DEV(y); | |
389076f1 | 1522 | |
ff910433 RR |
1523 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); |
1524 | ||
e0a050e3 VS |
1525 | // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer |
1526 | #if wxUSE_UNICODE_UTF8 | |
1527 | const char *data = text.utf8_str(); | |
ff910433 | 1528 | #else |
e0a050e3 | 1529 | const wxCharBuffer data = text.utf8_str(); |
ff910433 RR |
1530 | #endif |
1531 | ||
e0a050e3 VS |
1532 | size_t datalen = strlen(data); |
1533 | pango_layout_set_text( m_layout, data, datalen); | |
389076f1 | 1534 | |
ff910433 RR |
1535 | if (underlined) |
1536 | { | |
1537 | PangoAttrList *attrs = pango_attr_list_new(); | |
1538 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1539 | a->start_index = 0; | |
1540 | a->end_index = datalen; | |
1541 | pango_attr_list_insert(attrs, a); | |
1542 | pango_layout_set_attributes(m_layout, attrs); | |
1543 | pango_attr_list_unref(attrs); | |
1544 | } | |
1545 | ||
2934005d RR |
1546 | if (m_textForegroundColour.Ok()) |
1547 | { | |
1548 | unsigned char red = m_textForegroundColour.Red(); | |
1549 | unsigned char blue = m_textForegroundColour.Blue(); | |
1550 | unsigned char green = m_textForegroundColour.Green(); | |
1551 | ||
b199de59 RR |
1552 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
1553 | { | |
1554 | double redPS = (double)(red) / 255.0; | |
1555 | double bluePS = (double)(blue) / 255.0; | |
1556 | double greenPS = (double)(green) / 255.0; | |
1557 | ||
ced3df77 | 1558 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
b199de59 RR |
1559 | |
1560 | m_currentRed = red; | |
1561 | m_currentBlue = blue; | |
1562 | m_currentGreen = green; | |
1563 | } | |
2934005d RR |
1564 | } |
1565 | ||
fa499247 | 1566 | int w,h; |
02255e07 | 1567 | pango_layout_get_pixel_size( m_layout, &w, &h ); |
fa499247 RR |
1568 | #if 0 |
1569 | if ( m_backgroundMode == wxSOLID ) | |
1570 | { | |
1571 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
02255e07 | 1572 | gdk_draw_rectangle(m_window, m_textGC, TRUE, xx, yy, w, h); |
fa499247 RR |
1573 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); |
1574 | } | |
389076f1 | 1575 | #endif |
fa499247 | 1576 | |
02255e07 RR |
1577 | // Draw layout. |
1578 | gs_libGnomePrint->gnome_print_moveto (m_gpc, xx, yy); | |
1579 | ||
1580 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); | |
1581 | ||
1582 | gs_libGnomePrint->gnome_print_scale( m_gpc, m_scaleX * DEV2PS, m_scaleY * DEV2PS ); | |
1583 | ||
1584 | if (fabs(angle) > 0.00001) | |
1585 | gs_libGnomePrint->gnome_print_rotate( m_gpc, angle ); | |
1586 | ||
1587 | gs_libGnomePrint->gnome_print_pango_layout( m_gpc, m_layout ); | |
1588 | ||
1589 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
1590 | ||
ff910433 RR |
1591 | if (underlined) |
1592 | { | |
1593 | // undo underline attributes setting: | |
1594 | pango_layout_set_attributes(m_layout, NULL); | |
1595 | } | |
389076f1 | 1596 | |
b199de59 | 1597 | CalcBoundingBox (x + w, y + h); |
ff910433 RR |
1598 | } |
1599 | ||
1600 | void wxGnomePrintDC::Clear() | |
1601 | { | |
1602 | } | |
1603 | ||
1604 | void wxGnomePrintDC::SetFont( const wxFont& font ) | |
1605 | { | |
1606 | m_font = font; | |
389076f1 | 1607 | |
ff910433 RR |
1608 | if (m_font.Ok()) |
1609 | { | |
1610 | if (m_fontdesc) | |
1611 | pango_font_description_free( m_fontdesc ); | |
389076f1 | 1612 | |
ff910433 | 1613 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
389076f1 | 1614 | |
ff910433 RR |
1615 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
1616 | } | |
1617 | } | |
1618 | ||
1619 | void wxGnomePrintDC::SetPen( const wxPen& pen ) | |
1620 | { | |
1621 | if (!pen.Ok()) return; | |
1622 | ||
ff910433 RR |
1623 | m_pen = pen; |
1624 | ||
f62edb0e RR |
1625 | double width; |
1626 | ||
1627 | if (m_pen.GetWidth() <= 0) | |
1628 | width = 0.1; | |
1629 | else | |
1630 | width = (double) m_pen.GetWidth(); | |
1631 | ||
1632 | gs_libGnomePrint->gnome_print_setlinewidth( m_gpc, width * DEV2PS * m_scaleX ); | |
cac7ac30 RR |
1633 | |
1634 | static const double dotted[] = {2.0, 5.0}; | |
1635 | static const double short_dashed[] = {4.0, 4.0}; | |
1636 | static const double wxCoord_dashed[] = {4.0, 8.0}; | |
1637 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1638 | ||
1639 | switch (m_pen.GetStyle()) | |
1640 | { | |
ced3df77 VZ |
1641 | case wxDOT: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break; |
1642 | case wxSHORT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; | |
1643 | case wxLONG_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; | |
1644 | case wxDOT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; | |
e4db172a | 1645 | case wxUSER_DASH: |
8c419a5c RR |
1646 | { |
1647 | // It may be noted that libgnomeprint between at least | |
1648 | // versions 2.8.0 and 2.12.1 makes a copy of the dashes | |
1649 | // and then leak the memory since it doesn't set the | |
1650 | // internal flag "privatedash" to 0. | |
1651 | wxDash *wx_dashes; | |
1652 | int num = m_pen.GetDashes (&wx_dashes); | |
1653 | gdouble *g_dashes = g_new( gdouble, num ); | |
1654 | int i; | |
1655 | for (i = 0; i < num; ++i) | |
1656 | g_dashes[i] = (gdouble) wx_dashes[i]; | |
ced3df77 | 1657 | gs_libGnomePrint -> gnome_print_setdash( m_gpc, num, g_dashes, 0); |
8c419a5c RR |
1658 | g_free( g_dashes ); |
1659 | } | |
1660 | break; | |
cac7ac30 RR |
1661 | case wxSOLID: |
1662 | case wxTRANSPARENT: | |
ced3df77 | 1663 | default: gs_libGnomePrint->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; |
cac7ac30 RR |
1664 | } |
1665 | ||
389076f1 | 1666 | |
ff910433 RR |
1667 | unsigned char red = m_pen.GetColour().Red(); |
1668 | unsigned char blue = m_pen.GetColour().Blue(); | |
1669 | unsigned char green = m_pen.GetColour().Green(); | |
1670 | ||
1671 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1672 | { | |
1673 | double redPS = (double)(red) / 255.0; | |
1674 | double bluePS = (double)(blue) / 255.0; | |
1675 | double greenPS = (double)(green) / 255.0; | |
1676 | ||
ced3df77 | 1677 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
ff910433 RR |
1678 | |
1679 | m_currentRed = red; | |
1680 | m_currentBlue = blue; | |
1681 | m_currentGreen = green; | |
1682 | } | |
1683 | } | |
1684 | ||
1685 | void wxGnomePrintDC::SetBrush( const wxBrush& brush ) | |
1686 | { | |
fa499247 RR |
1687 | if (!brush.Ok()) return; |
1688 | ||
1689 | m_brush = brush; | |
1690 | ||
1691 | // Brush colour | |
1692 | unsigned char red = m_brush.GetColour().Red(); | |
1693 | unsigned char blue = m_brush.GetColour().Blue(); | |
1694 | unsigned char green = m_brush.GetColour().Green(); | |
1695 | ||
1696 | if (!m_colour) | |
1697 | { | |
1698 | // Anything not white is black | |
1699 | if (! (red == (unsigned char) 255 && | |
1700 | blue == (unsigned char) 255 && | |
1701 | green == (unsigned char) 255) ) | |
1702 | { | |
1703 | red = (unsigned char) 0; | |
1704 | green = (unsigned char) 0; | |
1705 | blue = (unsigned char) 0; | |
1706 | } | |
1707 | // setgray here ? | |
1708 | } | |
1709 | ||
1710 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1711 | { | |
1712 | double redPS = (double)(red) / 255.0; | |
1713 | double bluePS = (double)(blue) / 255.0; | |
1714 | double greenPS = (double)(green) / 255.0; | |
1715 | ||
ced3df77 | 1716 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
fa499247 RR |
1717 | |
1718 | m_currentRed = red; | |
1719 | m_currentBlue = blue; | |
1720 | m_currentGreen = green; | |
1721 | } | |
ff910433 RR |
1722 | } |
1723 | ||
1724 | void wxGnomePrintDC::SetLogicalFunction( int function ) | |
1725 | { | |
1726 | } | |
1727 | ||
1728 | void wxGnomePrintDC::SetBackground( const wxBrush& brush ) | |
1729 | { | |
1730 | } | |
1731 | ||
1732 | void wxGnomePrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1733 | { | |
75aa53c9 RR |
1734 | wxDC::DoSetClippingRegion( x, y, width, height ); |
1735 | ||
ced3df77 | 1736 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
3b7ab6bd | 1737 | |
ced3df77 VZ |
1738 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1739 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1740 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1741 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1742 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1743 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1744 | gs_libGnomePrint->gnome_print_clip( m_gpc ); | |
ff910433 RR |
1745 | } |
1746 | ||
1747 | void wxGnomePrintDC::DestroyClippingRegion() | |
1748 | { | |
75aa53c9 RR |
1749 | wxDC::DestroyClippingRegion(); |
1750 | ||
ced3df77 | 1751 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
3b7ab6bd RR |
1752 | |
1753 | #if 0 | |
1754 | // not needed, we set the values in each | |
1755 | // drawing method anyways | |
1756 | SetPen( m_pen ); | |
1757 | SetBrush( m_brush ); | |
1758 | SetFont( m_font ); | |
1759 | #endif | |
ff910433 RR |
1760 | } |
1761 | ||
1762 | bool wxGnomePrintDC::StartDoc(const wxString& message) | |
1763 | { | |
ff910433 RR |
1764 | return true; |
1765 | } | |
1766 | ||
1767 | void wxGnomePrintDC::EndDoc() | |
1768 | { | |
ced3df77 | 1769 | gs_libGnomePrint->gnome_print_end_doc( m_gpc ); |
ff910433 RR |
1770 | } |
1771 | ||
1772 | void wxGnomePrintDC::StartPage() | |
1773 | { | |
ced3df77 | 1774 | gs_libGnomePrint->gnome_print_beginpage( m_gpc, (const guchar*) "page" ); |
ff910433 RR |
1775 | } |
1776 | ||
1777 | void wxGnomePrintDC::EndPage() | |
1778 | { | |
ced3df77 | 1779 | gs_libGnomePrint->gnome_print_showpage( m_gpc ); |
ff910433 RR |
1780 | } |
1781 | ||
1782 | wxCoord wxGnomePrintDC::GetCharHeight() const | |
1783 | { | |
b199de59 | 1784 | pango_layout_set_text( m_layout, "H", 1 ); |
389076f1 | 1785 | |
b199de59 RR |
1786 | int w,h; |
1787 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1788 | |
b199de59 | 1789 | return h; |
ff910433 RR |
1790 | } |
1791 | ||
1792 | wxCoord wxGnomePrintDC::GetCharWidth() const | |
1793 | { | |
b199de59 | 1794 | pango_layout_set_text( m_layout, "H", 1 ); |
389076f1 | 1795 | |
b199de59 RR |
1796 | int w,h; |
1797 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1798 | |
b199de59 | 1799 | return w; |
ff910433 RR |
1800 | } |
1801 | ||
981a6af1 | 1802 | void wxGnomePrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
ff910433 RR |
1803 | wxCoord *descent, |
1804 | wxCoord *externalLeading, | |
c94f845b | 1805 | const wxFont *theFont ) const |
ff910433 | 1806 | { |
981a6af1 RR |
1807 | if ( width ) |
1808 | *width = 0; | |
1809 | if ( height ) | |
1810 | *height = 0; | |
1811 | if ( descent ) | |
1812 | *descent = 0; | |
1813 | if ( externalLeading ) | |
1814 | *externalLeading = 0; | |
1815 | ||
389076f1 | 1816 | if (string.empty()) |
981a6af1 RR |
1817 | { |
1818 | return; | |
1819 | } | |
389076f1 | 1820 | |
981a6af1 | 1821 | // Set layout's text |
e0a050e3 VS |
1822 | |
1823 | // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer | |
1824 | #if wxUSE_UNICODE_UTF8 | |
1825 | const char *dataUTF8 = string.utf8_str(); | |
981a6af1 | 1826 | #else |
e0a050e3 | 1827 | const wxCharBuffer dataUTF8 = string.utf8_str(); |
981a6af1 RR |
1828 | #endif |
1829 | ||
0cc0ce06 RR |
1830 | PangoFontDescription *desc = (theFont) ? theFont->GetNativeFontInfo()->description : m_fontdesc; |
1831 | ||
1832 | gint oldSize = pango_font_description_get_size( desc ); | |
1833 | double size = oldSize; | |
1834 | size = size * m_scaleY; | |
1835 | pango_font_description_set_size( desc, (gint)size ); | |
1836 | ||
1837 | // apply scaled font | |
1838 | pango_layout_set_font_description( m_layout, desc ); | |
1839 | ||
981a6af1 | 1840 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); |
389076f1 | 1841 | |
0cc0ce06 | 1842 | int w, h; |
981a6af1 | 1843 | pango_layout_get_pixel_size( m_layout, &w, &h ); |
389076f1 | 1844 | |
0cc0ce06 | 1845 | |
981a6af1 | 1846 | if (width) |
389076f1 | 1847 | *width = (wxCoord)(w / m_scaleX); |
981a6af1 | 1848 | if (height) |
15236815 | 1849 | *height = (wxCoord)(h / m_scaleY); |
0cc0ce06 | 1850 | |
981a6af1 RR |
1851 | if (descent) |
1852 | { | |
1853 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
1854 | int baseline = pango_layout_iter_get_baseline(iter); | |
1855 | pango_layout_iter_free(iter); | |
1856 | *descent = h - PANGO_PIXELS(baseline); | |
1857 | } | |
389076f1 | 1858 | |
0cc0ce06 RR |
1859 | // reset unscaled size |
1860 | pango_font_description_set_size( desc, oldSize ); | |
1861 | ||
1862 | // reset unscaled font | |
1863 | pango_layout_set_font_description( m_layout, m_fontdesc ); | |
ff910433 RR |
1864 | } |
1865 | ||
1866 | void wxGnomePrintDC::DoGetSize(int* width, int* height) const | |
1867 | { | |
cffcf831 RR |
1868 | wxGnomePrintNativeData *native = |
1869 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1870 | ||
1871 | // Query page size. This seems to omit the margins | |
cffcf831 | 1872 | double pw,ph; |
ced3df77 | 1873 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
ff910433 | 1874 | |
ff910433 | 1875 | if (width) |
02255e07 | 1876 | *width = wxRound( pw * PS2DEV ); |
f62edb0e | 1877 | |
ff910433 | 1878 | if (height) |
02255e07 | 1879 | *height = wxRound( ph * PS2DEV ); |
ff910433 RR |
1880 | } |
1881 | ||
1882 | void wxGnomePrintDC::DoGetSizeMM(int *width, int *height) const | |
1883 | { | |
cffcf831 RR |
1884 | wxGnomePrintNativeData *native = |
1885 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1886 | ||
389076f1 WS |
1887 | // This code assumes values in Pts. |
1888 | ||
cffcf831 | 1889 | double pw,ph; |
ced3df77 | 1890 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
cffcf831 RR |
1891 | |
1892 | // Convert to mm. | |
389076f1 | 1893 | |
ced3df77 VZ |
1894 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
1895 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
1896 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
1897 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
389076f1 | 1898 | |
ff910433 | 1899 | if (width) |
cffcf831 | 1900 | *width = (int) (pw + 0.5); |
ff910433 | 1901 | if (height) |
cffcf831 | 1902 | *height = (int) (ph + 0.5); |
ff910433 RR |
1903 | } |
1904 | ||
1905 | wxSize wxGnomePrintDC::GetPPI() const | |
1906 | { | |
02255e07 | 1907 | return wxSize(DPI,DPI); |
92120c6e RR |
1908 | } |
1909 | ||
3b7ab6bd RR |
1910 | void wxGnomePrintDC::SetPrintData(const wxPrintData& data) |
1911 | { | |
1912 | m_printData = data; | |
1913 | ||
02255e07 | 1914 | int height; |
3b7ab6bd | 1915 | if (m_printData.GetOrientation() == wxPORTRAIT) |
02255e07 | 1916 | GetSize( NULL, &height ); |
3b7ab6bd | 1917 | else |
02255e07 RR |
1918 | GetSize( &height, NULL ); |
1919 | m_deviceLocalOriginY = height; | |
3b7ab6bd RR |
1920 | } |
1921 | ||
ff910433 RR |
1922 | void wxGnomePrintDC::SetResolution(int ppi) |
1923 | { | |
1924 | } | |
1925 | ||
1926 | int wxGnomePrintDC::GetResolution() | |
1927 | { | |
02255e07 | 1928 | return DPI; |
ff910433 | 1929 | } |
7c72311f | 1930 | |
1ff62f51 RR |
1931 | // ---------------------------------------------------------------------------- |
1932 | // wxGnomePrintModule | |
1933 | // ---------------------------------------------------------------------------- | |
58c30cd8 | 1934 | |
c6efd6e0 RR |
1935 | bool wxGnomePrintModule::OnInit() |
1936 | { | |
ced3df77 VZ |
1937 | gs_libGnomePrint = new wxGnomePrintLibrary; |
1938 | if (gs_libGnomePrint->IsOk()) | |
c6efd6e0 RR |
1939 | wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); |
1940 | return true; | |
1941 | } | |
1942 | ||
1943 | void wxGnomePrintModule::OnExit() | |
1944 | { | |
ced3df77 VZ |
1945 | delete gs_libGnomePrint; |
1946 | gs_libGnomePrint = NULL; | |
c6efd6e0 RR |
1947 | } |
1948 | ||
58c30cd8 | 1949 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) |
389076f1 | 1950 | |
147bf263 JS |
1951 | // ---------------------------------------------------------------------------- |
1952 | // Print preview | |
1953 | // ---------------------------------------------------------------------------- | |
1954 | ||
1955 | IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase) | |
1956 | ||
1957 | void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout), | |
1958 | wxPrintout * WXUNUSED(printoutForPrinting)) | |
1959 | { | |
1960 | DetermineScaling(); | |
1961 | } | |
1962 | ||
1963 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
1964 | wxPrintout *printoutForPrinting, | |
1965 | wxPrintDialogData *data) | |
1966 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
1967 | { | |
1968 | Init(printout, printoutForPrinting); | |
1969 | } | |
1970 | ||
1971 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
1972 | wxPrintout *printoutForPrinting, | |
1973 | wxPrintData *data) | |
1974 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
1975 | { | |
1976 | Init(printout, printoutForPrinting); | |
1977 | } | |
1978 | ||
1979 | wxGnomePrintPreview::~wxGnomePrintPreview() | |
1980 | { | |
1981 | } | |
1982 | ||
1983 | bool wxGnomePrintPreview::Print(bool interactive) | |
1984 | { | |
1985 | if (!m_printPrintout) | |
1986 | return false; | |
1987 | ||
1988 | wxPrinter printer(& m_printDialogData); | |
1989 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
1990 | } | |
1991 | ||
1992 | void wxGnomePrintPreview::DetermineScaling() | |
1993 | { | |
1994 | wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); | |
1995 | if (paperType == wxPAPER_NONE) | |
1996 | paperType = wxPAPER_NONE; | |
1997 | ||
1998 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); | |
1999 | if (!paper) | |
2000 | paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); | |
2001 | ||
2002 | if (paper) | |
2003 | { | |
2004 | wxSize ScreenPixels = wxGetDisplaySize(); | |
2005 | wxSize ScreenMM = wxGetDisplaySizeMM(); | |
2006 | ||
2007 | m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), | |
2008 | (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); | |
2009 | m_previewPrintout->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution()); | |
2010 | ||
2011 | wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); | |
f4322df6 | 2012 | |
147bf263 JS |
2013 | // TODO: get better resolution information from wxGnomePrintDC, if possible. |
2014 | ||
2015 | sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxGnomePrintDC::GetResolution() / 72.0); | |
2016 | sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxGnomePrintDC::GetResolution() / 72.0); | |
2017 | wxSize sizeTenthsMM(paper->GetSize()); | |
2018 | wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); | |
2019 | ||
2020 | // If in landscape mode, we need to swap the width and height. | |
2021 | if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) | |
2022 | { | |
2023 | m_pageWidth = sizeDevUnits.y; | |
2024 | m_pageHeight = sizeDevUnits.x; | |
2025 | m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); | |
147bf263 JS |
2026 | } |
2027 | else | |
2028 | { | |
2029 | m_pageWidth = sizeDevUnits.x; | |
2030 | m_pageHeight = sizeDevUnits.y; | |
2031 | m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); | |
147bf263 | 2032 | } |
f415cab9 JS |
2033 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); |
2034 | m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); | |
147bf263 JS |
2035 | |
2036 | // At 100%, the page should look about page-size on the screen. | |
f415cab9 JS |
2037 | m_previewScaleX = (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution(); |
2038 | m_previewScaleY = m_previewScaleX; | |
147bf263 JS |
2039 | } |
2040 | } | |
2041 | ||
32f34982 RR |
2042 | #endif |
2043 | // wxUSE_LIBGNOMEPRINT |