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