]>
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 | |
ced3df77 | 612 | switch (gs_libGnomePrint->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget )) |
b199de59 RR |
613 | { |
614 | case GNOME_PRINT_RANGE_SELECTION: | |
615 | m_printDialogData.SetSelection( true ); | |
616 | break; | |
617 | case GNOME_PRINT_RANGE_ALL: | |
618 | m_printDialogData.SetAllPages( true ); | |
619 | m_printDialogData.SetFromPage( 0 ); | |
620 | m_printDialogData.SetToPage( 9999 ); | |
621 | break; | |
622 | case GNOME_PRINT_RANGE_RANGE: | |
623 | default: | |
624 | gint start,end; | |
ced3df77 | 625 | gs_libGnomePrint->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end ); |
b199de59 RR |
626 | m_printDialogData.SetFromPage( start ); |
627 | m_printDialogData.SetToPage( end ); | |
628 | break; | |
629 | } | |
630 | ||
631 | gtk_widget_destroy(m_widget); | |
632 | m_widget = NULL; | |
389076f1 | 633 | |
0be7709e RR |
634 | if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) |
635 | return wxID_PREVIEW; | |
389076f1 | 636 | |
ff910433 RR |
637 | return wxID_OK; |
638 | } | |
639 | ||
2934005d | 640 | wxDC *wxGnomePrintDialog::GetPrintDC() |
ff910433 | 641 | { |
2934005d RR |
642 | // Later |
643 | return NULL; | |
ff910433 RR |
644 | } |
645 | ||
2934005d | 646 | bool wxGnomePrintDialog::Validate() |
ff910433 RR |
647 | { |
648 | return true; | |
649 | } | |
650 | ||
2934005d | 651 | bool wxGnomePrintDialog::TransferDataToWindow() |
ff910433 RR |
652 | { |
653 | return true; | |
654 | } | |
655 | ||
2934005d RR |
656 | bool wxGnomePrintDialog::TransferDataFromWindow() |
657 | { | |
658 | return true; | |
659 | } | |
ff910433 | 660 | |
08680429 RR |
661 | //---------------------------------------------------------------------------- |
662 | // wxGnomePageSetupDialog | |
663 | //---------------------------------------------------------------------------- | |
664 | ||
665 | IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase) | |
666 | ||
e4161a2a VZ |
667 | wxGnomePageSetupDialog::wxGnomePageSetupDialog(wxWindow * WXUNUSED(parent), |
668 | wxPageSetupDialogData *data) | |
08680429 RR |
669 | { |
670 | if (data) | |
671 | m_pageDialogData = *data; | |
389076f1 | 672 | |
3b7ab6bd RR |
673 | m_pageDialogData.GetPrintData().ConvertToNative(); |
674 | ||
08680429 RR |
675 | wxGnomePrintNativeData *native = |
676 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
cffcf831 | 677 | |
3b7ab6bd | 678 | // This *was* required as the page setup dialog |
cffcf831 | 679 | // calculates wrong values otherwise. |
3b7ab6bd | 680 | #if 0 |
ced3df77 | 681 | gs_libGnomePrint->gnome_print_config_set( native->GetPrintConfig(), |
cffcf831 RR |
682 | (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT, |
683 | (const guchar*) "Pts" ); | |
3b7ab6bd RR |
684 | #endif |
685 | ||
686 | GnomePrintConfig *config = native->GetPrintConfig(); | |
687 | ||
ced3df77 | 688 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
3b7ab6bd RR |
689 | |
690 | double ml = (double) m_pageDialogData.GetMarginTopLeft().x; | |
691 | double mt = (double) m_pageDialogData.GetMarginTopLeft().y; | |
692 | double mr = (double) m_pageDialogData.GetMarginBottomRight().x; | |
693 | double mb = (double) m_pageDialogData.GetMarginBottomRight().y; | |
e4161a2a | 694 | |
ced3df77 | 695 | gs_libGnomePrint->gnome_print_config_set_length (config, |
3b7ab6bd | 696 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, ml, mm_unit ); |
ced3df77 | 697 | gs_libGnomePrint->gnome_print_config_set_length (config, |
3b7ab6bd | 698 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, mr, mm_unit ); |
ced3df77 | 699 | gs_libGnomePrint->gnome_print_config_set_length (config, |
3b7ab6bd | 700 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, mt, mm_unit ); |
ced3df77 | 701 | gs_libGnomePrint->gnome_print_config_set_length (config, |
3b7ab6bd | 702 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, mb, mm_unit ); |
389076f1 | 703 | |
08680429 | 704 | m_widget = gtk_dialog_new(); |
389076f1 | 705 | |
08680429 | 706 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) ); |
cffcf831 | 707 | |
ced3df77 | 708 | GtkWidget *main = gs_libGnomePrint->gnome_paper_selector_new_with_flags( native->GetPrintConfig(), |
08680429 RR |
709 | GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION ); |
710 | gtk_container_set_border_width (GTK_CONTAINER (main), 8); | |
711 | gtk_widget_show (main); | |
389076f1 | 712 | |
08680429 | 713 | gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main ); |
08680429 | 714 | |
389076f1 | 715 | gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE); |
08680429 | 716 | |
389076f1 WS |
717 | gtk_dialog_add_buttons (GTK_DIALOG (m_widget), |
718 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
719 | GTK_STOCK_OK, GTK_RESPONSE_OK, | |
720 | NULL); | |
721 | ||
722 | gtk_dialog_set_default_response (GTK_DIALOG (m_widget), | |
723 | GTK_RESPONSE_OK); | |
08680429 RR |
724 | } |
725 | ||
726 | wxGnomePageSetupDialog::~wxGnomePageSetupDialog() | |
727 | { | |
728 | } | |
729 | ||
730 | wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData() | |
731 | { | |
732 | return m_pageDialogData; | |
733 | } | |
734 | ||
735 | int wxGnomePageSetupDialog::ShowModal() | |
736 | { | |
06cfd325 RR |
737 | wxGnomePrintNativeData *native = |
738 | (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); | |
e4161a2a | 739 | |
06cfd325 | 740 | GnomePrintConfig *config = native->GetPrintConfig(); |
389076f1 | 741 | |
08680429 RR |
742 | |
743 | int ret = gtk_dialog_run( GTK_DIALOG(m_widget) ); | |
744 | ||
745 | if (ret == GTK_RESPONSE_OK) | |
746 | { | |
747 | // Transfer data back to m_pageDialogData | |
3b7ab6bd | 748 | m_pageDialogData.GetPrintData().ConvertFromNative(); |
cffcf831 RR |
749 | |
750 | // I don't know how querying the last parameter works | |
06cfd325 | 751 | double ml,mr,mt,mb,pw,ph; |
ced3df77 | 752 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 753 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); |
ced3df77 | 754 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 755 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); |
ced3df77 | 756 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 757 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); |
ced3df77 | 758 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 759 | (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); |
ced3df77 | 760 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 | 761 | (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); |
ced3df77 | 762 | gs_libGnomePrint->gnome_print_config_get_length (config, |
389076f1 WS |
763 | (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); |
764 | ||
3b7ab6bd RR |
765 | // This code converts correctly from what the user chose |
766 | // as the unit although I query Pts here | |
ced3df77 VZ |
767 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
768 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
769 | gs_libGnomePrint->gnome_print_convert_distance( &ml, pts_unit, mm_unit ); | |
770 | gs_libGnomePrint->gnome_print_convert_distance( &mr, pts_unit, mm_unit ); | |
771 | gs_libGnomePrint->gnome_print_convert_distance( &mt, pts_unit, mm_unit ); | |
772 | gs_libGnomePrint->gnome_print_convert_distance( &mb, pts_unit, mm_unit ); | |
773 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
774 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
cffcf831 RR |
775 | |
776 | m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); | |
06cfd325 | 777 | m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); |
389076f1 | 778 | |
06cfd325 | 779 | m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); |
cffcf831 | 780 | |
08680429 RR |
781 | ret = wxID_OK; |
782 | } | |
783 | else | |
784 | { | |
785 | ret = wxID_CANCEL; | |
786 | } | |
389076f1 | 787 | |
08680429 RR |
788 | gtk_widget_destroy( m_widget ); |
789 | m_widget = NULL; | |
790 | ||
791 | return ret; | |
792 | } | |
793 | ||
794 | bool wxGnomePageSetupDialog::Validate() | |
795 | { | |
796 | return true; | |
797 | } | |
798 | ||
799 | bool wxGnomePageSetupDialog::TransferDataToWindow() | |
800 | { | |
801 | return true; | |
802 | } | |
803 | ||
804 | bool wxGnomePageSetupDialog::TransferDataFromWindow() | |
805 | { | |
806 | return true; | |
807 | } | |
808 | ||
ff910433 RR |
809 | //---------------------------------------------------------------------------- |
810 | // wxGnomePrinter | |
811 | //---------------------------------------------------------------------------- | |
812 | ||
813 | IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase) | |
814 | ||
815 | wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : | |
816 | wxPrinterBase( data ) | |
817 | { | |
0be7709e | 818 | m_native_preview = false; |
ff910433 RR |
819 | } |
820 | ||
821 | wxGnomePrinter::~wxGnomePrinter() | |
822 | { | |
823 | } | |
824 | ||
825 | bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) | |
826 | { | |
827 | if (!printout) | |
828 | { | |
829 | sm_lastError = wxPRINTER_ERROR; | |
830 | return false; | |
831 | } | |
832 | ||
833 | wxPrintData printdata = GetPrintDialogData().GetPrintData(); | |
e4161a2a | 834 | |
389076f1 | 835 | wxGnomePrintNativeData *native = |
ff910433 RR |
836 | (wxGnomePrintNativeData*) printdata.GetNativeData(); |
837 | ||
ced3df77 | 838 | GnomePrintJob *job = gs_libGnomePrint->gnome_print_job_new( native->GetPrintConfig() ); |
cffcf831 | 839 | |
389076f1 | 840 | // The GnomePrintJob is temporarily stored in the |
2934005d | 841 | // native print data as the native print dialog |
981a6af1 | 842 | // needs to access it. |
cffcf831 RR |
843 | native->SetPrintJob( job ); |
844 | ||
981a6af1 | 845 | |
981a6af1 RR |
846 | if (m_printDialogData.GetMinPage() < 1) |
847 | m_printDialogData.SetMinPage(1); | |
848 | if (m_printDialogData.GetMaxPage() < 1) | |
849 | m_printDialogData.SetMaxPage(9999); | |
389076f1 | 850 | |
ff910433 | 851 | wxDC *dc; |
ff910433 RR |
852 | if (prompt) |
853 | dc = PrintDialog( parent ); | |
854 | else | |
3e4b352f RR |
855 | #if wxUSE_NEW_DC |
856 | dc = new wxPrinterDC( printdata ); // TODO: check that this works | |
857 | #else | |
858 | dc = new wxGnomePrinterDC( printdata ); // TODO: check that this works | |
859 | #endif | |
389076f1 | 860 | |
ff910433 RR |
861 | if (!dc) |
862 | { | |
ced3df77 | 863 | gs_libGnomePrint->gnome_print_job_close( job ); |
3fe39b0c | 864 | g_object_unref (job); |
a1b289f1 PC |
865 | if (sm_lastError != wxPRINTER_CANCELLED) |
866 | sm_lastError = wxPRINTER_ERROR; | |
ff910433 RR |
867 | return false; |
868 | } | |
869 | ||
40fcf546 | 870 | printout->SetPPIScreen(wxGetDisplayPPI()); |
3e4b352f RR |
871 | printout->SetPPIPrinter( dc->GetResolution(), |
872 | dc->GetResolution() ); | |
389076f1 | 873 | |
ff910433 RR |
874 | printout->SetDC(dc); |
875 | ||
981a6af1 RR |
876 | int w, h; |
877 | dc->GetSize(&w, &h); | |
878 | printout->SetPageSizePixels((int)w, (int)h); | |
f415cab9 JS |
879 | printout->SetPaperRectPixels(wxRect(0, 0, w, h)); |
880 | int mw, mh; | |
881 | dc->GetSizeMM(&mw, &mh); | |
882 | printout->SetPageSizeMM((int)mw, (int)mh); | |
ff910433 | 883 | printout->OnPreparePrinting(); |
389076f1 | 884 | |
b199de59 RR |
885 | // Get some parameters from the printout, if defined |
886 | int fromPage, toPage; | |
887 | int minPage, maxPage; | |
888 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
ff910433 | 889 | |
b199de59 | 890 | if (maxPage == 0) |
ff910433 | 891 | { |
ced3df77 | 892 | gs_libGnomePrint->gnome_print_job_close( job ); |
3fe39b0c | 893 | g_object_unref (job); |
ff910433 | 894 | sm_lastError = wxPRINTER_ERROR; |
b199de59 | 895 | return false; |
ff910433 | 896 | } |
389076f1 | 897 | |
b199de59 RR |
898 | printout->OnBeginPrinting(); |
899 | ||
900 | int minPageNum = minPage, maxPageNum = maxPage; | |
901 | ||
902 | if ( !m_printDialogData.GetAllPages() ) | |
ff910433 | 903 | { |
b199de59 RR |
904 | minPageNum = m_printDialogData.GetFromPage(); |
905 | maxPageNum = m_printDialogData.GetToPage(); | |
906 | } | |
907 | ||
389076f1 | 908 | |
b199de59 RR |
909 | int copyCount; |
910 | for ( copyCount = 1; | |
911 | copyCount <= m_printDialogData.GetNoCopies(); | |
912 | copyCount++ ) | |
913 | { | |
914 | if (!printout->OnBeginDocument(minPageNum, maxPageNum)) | |
ff910433 | 915 | { |
b199de59 RR |
916 | wxLogError(_("Could not start printing.")); |
917 | sm_lastError = wxPRINTER_ERROR; | |
918 | break; | |
919 | } | |
389076f1 | 920 | |
b199de59 RR |
921 | int pn; |
922 | for ( pn = minPageNum; | |
923 | pn <= maxPageNum && printout->HasPage(pn); | |
924 | pn++ ) | |
389076f1 | 925 | { |
ff910433 RR |
926 | dc->StartPage(); |
927 | printout->OnPrintPage(pn); | |
928 | dc->EndPage(); | |
929 | } | |
389076f1 | 930 | |
ff910433 RR |
931 | printout->OnEndDocument(); |
932 | printout->OnEndPrinting(); | |
933 | } | |
389076f1 | 934 | |
ced3df77 | 935 | gs_libGnomePrint->gnome_print_job_close( job ); |
0be7709e RR |
936 | if (m_native_preview) |
937 | { | |
46e86fc3 | 938 | const wxCharBuffer title(wxGTK_CONV_SYS(_("Print preview"))); |
ced3df77 | 939 | GtkWidget *preview = gs_libGnomePrint->gnome_print_job_preview_new |
b8f32576 VZ |
940 | ( |
941 | job, | |
46e86fc3 | 942 | (const guchar *)title.data() |
b8f32576 VZ |
943 | ); |
944 | gtk_widget_show(preview); | |
0be7709e RR |
945 | } |
946 | else | |
947 | { | |
ced3df77 | 948 | gs_libGnomePrint->gnome_print_job_print( job ); |
0be7709e | 949 | } |
389076f1 | 950 | |
3fe39b0c | 951 | g_object_unref (job); |
ff910433 | 952 | delete dc; |
389076f1 | 953 | |
ff910433 RR |
954 | return (sm_lastError == wxPRINTER_NO_ERROR); |
955 | } | |
956 | ||
957 | wxDC* wxGnomePrinter::PrintDialog( wxWindow *parent ) | |
958 | { | |
2934005d | 959 | wxGnomePrintDialog dialog( parent, &m_printDialogData ); |
0be7709e RR |
960 | int ret = dialog.ShowModal(); |
961 | if (ret == wxID_CANCEL) | |
ff910433 | 962 | { |
4843cdfe | 963 | sm_lastError = wxPRINTER_CANCELLED; |
ff910433 RR |
964 | return NULL; |
965 | } | |
389076f1 | 966 | |
0be7709e | 967 | m_native_preview = ret == wxID_PREVIEW; |
389076f1 | 968 | |
b199de59 | 969 | m_printDialogData = dialog.GetPrintDialogData(); |
3e4b352f RR |
970 | #if wxUSE_NEW_DC |
971 | return new wxPrinterDC( m_printDialogData.GetPrintData() ); | |
972 | #else | |
c8ddadff | 973 | return new wxGnomePrinterDC( m_printDialogData.GetPrintData() ); |
3e4b352f | 974 | #endif |
ff910433 RR |
975 | } |
976 | ||
e4161a2a | 977 | bool wxGnomePrinter::Setup(wxWindow * WXUNUSED(parent)) |
ff910433 | 978 | { |
58c30cd8 | 979 | return false; |
ff910433 RR |
980 | } |
981 | ||
982 | //----------------------------------------------------------------------------- | |
c8ddadff | 983 | // wxGnomePrinterDC |
ff910433 RR |
984 | //----------------------------------------------------------------------------- |
985 | ||
02255e07 RR |
986 | // conversion |
987 | static const double RAD2DEG = 180.0 / M_PI; | |
988 | ||
989 | // we don't want to use only 72 dpi from GNOME print | |
990 | static const int DPI = 600; | |
991 | static const double PS2DEV = 600.0 / 72.0; | |
992 | static const double DEV2PS = 72.0 / 600.0; | |
993 | ||
994 | #define XLOG2DEV(x) ((double)(LogicalToDeviceX(x)) * DEV2PS) | |
995 | #define XLOG2DEVREL(x) ((double)(LogicalToDeviceXRel(x)) * DEV2PS) | |
996 | #define YLOG2DEV(x) ((m_pageHeight - (double)LogicalToDeviceY(x)) * DEV2PS) | |
997 | #define YLOG2DEVREL(x) ((double)(LogicalToDeviceYRel(x)) * DEV2PS) | |
998 | ||
3e4b352f | 999 | #if wxUSE_NEW_DC |
888dde65 | 1000 | IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDCImpl, wxDCImpl) |
3e4b352f RR |
1001 | #else |
1002 | IMPLEMENT_ABSTRACT_CLASS(wxGnomePrinterDC, wxDC) | |
1003 | #endif | |
ff910433 | 1004 | |
3e4b352f | 1005 | #if wxUSE_NEW_DC |
888dde65 RR |
1006 | wxGnomePrinterDCImpl::wxGnomePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) : |
1007 | wxDCImpl( owner ) | |
3e4b352f | 1008 | #else |
c8ddadff | 1009 | wxGnomePrinterDC::wxGnomePrinterDC( const wxPrintData& data ) |
3e4b352f | 1010 | #endif |
147bf263 | 1011 | { |
147bf263 JS |
1012 | m_printData = data; |
1013 | ||
1014 | wxGnomePrintNativeData *native = | |
1015 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1016 | ||
3b7ab6bd | 1017 | m_job = native->GetPrintJob(); |
ced3df77 | 1018 | m_gpc = gs_libGnomePrint->gnome_print_job_get_context (m_job); |
147bf263 | 1019 | |
ced3df77 | 1020 | m_layout = gs_libGnomePrint->gnome_print_pango_create_layout( m_gpc ); |
147bf263 | 1021 | m_fontdesc = pango_font_description_from_string( "Sans 12" ); |
7d7e4ed0 | 1022 | m_context = NULL; |
147bf263 JS |
1023 | |
1024 | m_currentRed = 0; | |
1025 | m_currentBlue = 0; | |
1026 | m_currentGreen = 0; | |
1027 | ||
02255e07 RR |
1028 | // Query page size. This seems to omit the margins |
1029 | double pw,ph; | |
6950be01 | 1030 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
f4322df6 | 1031 | |
02255e07 | 1032 | m_pageHeight = ph * PS2DEV; |
147bf263 JS |
1033 | } |
1034 | ||
888dde65 | 1035 | wxGnomePrinterDCImpl::~wxGnomePrinterDCImpl() |
ff910433 RR |
1036 | { |
1037 | } | |
1038 | ||
888dde65 | 1039 | bool wxGnomePrinterDCImpl::IsOk() const |
ff910433 RR |
1040 | { |
1041 | return true; | |
1042 | } | |
1043 | ||
e4161a2a | 1044 | bool |
888dde65 | 1045 | wxGnomePrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1), |
e4161a2a VZ |
1046 | wxCoord WXUNUSED(y1), |
1047 | const wxColour& WXUNUSED(col), | |
89efaf2b | 1048 | wxFloodFillStyle WXUNUSED(style)) |
ff910433 RR |
1049 | { |
1050 | return false; | |
1051 | } | |
1052 | ||
e4161a2a | 1053 | bool |
888dde65 | 1054 | wxGnomePrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1), |
e4161a2a VZ |
1055 | wxCoord WXUNUSED(y1), |
1056 | wxColour * WXUNUSED(col)) const | |
ff910433 RR |
1057 | { |
1058 | return false; | |
1059 | } | |
1060 | ||
888dde65 | 1061 | void wxGnomePrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
ff910433 | 1062 | { |
04ee05f9 | 1063 | if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return; |
389076f1 | 1064 | |
ff910433 RR |
1065 | SetPen( m_pen ); |
1066 | ||
ced3df77 VZ |
1067 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(x1), YLOG2DEV(y1) ); |
1068 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(x2), YLOG2DEV(y2) ); | |
1069 | gs_libGnomePrint->gnome_print_stroke ( m_gpc); | |
cac7ac30 | 1070 | |
ff910433 RR |
1071 | CalcBoundingBox( x1, y1 ); |
1072 | CalcBoundingBox( x2, y2 ); | |
1073 | } | |
1074 | ||
888dde65 | 1075 | void wxGnomePrinterDCImpl::DoCrossHair(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) |
ff910433 RR |
1076 | { |
1077 | } | |
1078 | ||
888dde65 | 1079 | void wxGnomePrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc) |
ff910433 | 1080 | { |
2f41910a RR |
1081 | double dx = x1 - xc; |
1082 | double dy = y1 - yc; | |
1083 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
1084 | double alpha1, alpha2; | |
1085 | if (x1 == x2 && y1 == y2) | |
1086 | { | |
1087 | alpha1 = 0.0; | |
1088 | alpha2 = 360.0; | |
1089 | } | |
74ab5f5b | 1090 | else if ( wxIsNullDouble(radius) ) |
2f41910a | 1091 | { |
74ab5f5b VZ |
1092 | alpha1 = |
1093 | alpha2 = 0.0; | |
2f41910a RR |
1094 | } |
1095 | else | |
1096 | { | |
1097 | alpha1 = (x1 - xc == 0) ? | |
1098 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
1099 | -atan2(double(y1-yc), double(x1-xc)) * RAD2DEG; | |
1100 | alpha2 = (x2 - xc == 0) ? | |
1101 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
1102 | -atan2(double(y2-yc), double(x2-xc)) * RAD2DEG; | |
389076f1 | 1103 | |
2f41910a RR |
1104 | while (alpha1 <= 0) alpha1 += 360; |
1105 | while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between | |
1106 | while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree | |
1107 | while (alpha2 > 360) alpha2 -= 360; | |
1108 | } | |
1109 | ||
04ee05f9 | 1110 | if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) |
7d7e4ed0 PC |
1111 | { |
1112 | SetBrush( m_brush ); | |
ced3df77 VZ |
1113 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); |
1114 | gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
389076f1 | 1115 | |
ced3df77 | 1116 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
7d7e4ed0 | 1117 | } |
2f41910a | 1118 | |
04ee05f9 | 1119 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
7d7e4ed0 PC |
1120 | { |
1121 | SetPen (m_pen); | |
ced3df77 VZ |
1122 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1123 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) ); | |
1124 | gs_libGnomePrint->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 ); | |
1125 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
389076f1 | 1126 | |
ced3df77 | 1127 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
7d7e4ed0 | 1128 | } |
2f41910a RR |
1129 | |
1130 | CalcBoundingBox (x1, y1); | |
1131 | CalcBoundingBox (x2, y2); | |
1132 | CalcBoundingBox (xc, yc); | |
ff910433 RR |
1133 | } |
1134 | ||
888dde65 | 1135 | void wxGnomePrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) |
ff910433 | 1136 | { |
16744532 RR |
1137 | x += w/2; |
1138 | y += h/2; | |
1139 | ||
02255e07 RR |
1140 | double xx = XLOG2DEV(x); |
1141 | double yy = YLOG2DEV(y); | |
16744532 | 1142 | |
ced3df77 | 1143 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
16744532 | 1144 | |
ced3df77 | 1145 | gs_libGnomePrint->gnome_print_translate( m_gpc, xx, yy ); |
16744532 | 1146 | double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w); |
ced3df77 | 1147 | gs_libGnomePrint->gnome_print_scale( m_gpc, 1.0, scale ); |
389076f1 | 1148 | |
02255e07 RR |
1149 | xx = 0.0; |
1150 | yy = 0.0; | |
16744532 | 1151 | |
04ee05f9 | 1152 | if (m_brush.GetStyle () != wxBRUSHSTYLE_TRANSPARENT) |
16744532 RR |
1153 | { |
1154 | SetBrush( m_brush ); | |
389076f1 | 1155 | |
ced3df77 VZ |
1156 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy ); |
1157 | gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy, | |
16744532 | 1158 | XLOG2DEVREL(w)/2, sa, ea, 0 ); |
ced3df77 | 1159 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, xx, yy ); |
389076f1 | 1160 | |
ced3df77 | 1161 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
16744532 | 1162 | } |
389076f1 | 1163 | |
04ee05f9 | 1164 | if (m_pen.GetStyle () != wxPENSTYLE_TRANSPARENT) |
16744532 RR |
1165 | { |
1166 | SetPen (m_pen); | |
389076f1 | 1167 | |
ced3df77 | 1168 | gs_libGnomePrint->gnome_print_arcto( m_gpc, xx, yy, |
16744532 | 1169 | XLOG2DEVREL(w)/2, sa, ea, 0 ); |
389076f1 | 1170 | |
ced3df77 | 1171 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
16744532 | 1172 | } |
389076f1 | 1173 | |
ced3df77 | 1174 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
389076f1 | 1175 | |
16744532 RR |
1176 | CalcBoundingBox( x, y ); |
1177 | CalcBoundingBox( x+w, y+h ); | |
ff910433 RR |
1178 | } |
1179 | ||
888dde65 | 1180 | void wxGnomePrinterDCImpl::DoDrawPoint(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) |
ff910433 RR |
1181 | { |
1182 | } | |
1183 | ||
888dde65 | 1184 | void wxGnomePrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) |
ff910433 | 1185 | { |
04ee05f9 | 1186 | if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return; |
cac7ac30 RR |
1187 | |
1188 | if (n <= 0) return; | |
1189 | ||
1190 | SetPen (m_pen); | |
1191 | ||
1192 | int i; | |
1193 | for ( i =0; i<n ; i++ ) | |
16744532 | 1194 | CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset); |
cac7ac30 | 1195 | |
ced3df77 | 1196 | gs_libGnomePrint->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) ); |
389076f1 | 1197 | |
cac7ac30 | 1198 | for (i = 1; i < n; i++) |
ced3df77 | 1199 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) ); |
cac7ac30 | 1200 | |
ced3df77 | 1201 | gs_libGnomePrint->gnome_print_stroke ( m_gpc); |
ff910433 RR |
1202 | } |
1203 | ||
888dde65 | 1204 | void wxGnomePrinterDCImpl::DoDrawPolygon(int n, wxPoint points[], |
e4161a2a | 1205 | wxCoord xoffset, wxCoord yoffset, |
89efaf2b | 1206 | wxPolygonFillMode WXUNUSED(fillStyle)) |
ff910433 | 1207 | { |
a92964a2 RR |
1208 | if (n==0) return; |
1209 | ||
04ee05f9 | 1210 | if (m_brush.GetStyle () != wxBRUSHSTYLE_TRANSPARENT) |
a92964a2 RR |
1211 | { |
1212 | SetBrush( m_brush ); | |
389076f1 | 1213 | |
a92964a2 RR |
1214 | int x = points[0].x + xoffset; |
1215 | int y = points[0].y + yoffset; | |
1216 | CalcBoundingBox( x, y ); | |
ced3df77 VZ |
1217 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1218 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
a92964a2 RR |
1219 | int i; |
1220 | for (i = 1; i < n; i++) | |
1221 | { | |
74ab5f5b VZ |
1222 | x = points[i].x + xoffset; |
1223 | y = points[i].y + yoffset; | |
ced3df77 | 1224 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
a92964a2 RR |
1225 | CalcBoundingBox( x, y ); |
1226 | } | |
ced3df77 VZ |
1227 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
1228 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
a92964a2 RR |
1229 | } |
1230 | ||
04ee05f9 | 1231 | if (m_pen.GetStyle () != wxPENSTYLE_TRANSPARENT) |
a92964a2 RR |
1232 | { |
1233 | SetPen (m_pen); | |
1234 | ||
1235 | int x = points[0].x + xoffset; | |
1236 | int y = points[0].y + yoffset; | |
ced3df77 VZ |
1237 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1238 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
a92964a2 RR |
1239 | int i; |
1240 | for (i = 1; i < n; i++) | |
1241 | { | |
74ab5f5b VZ |
1242 | x = points[i].x + xoffset; |
1243 | y = points[i].y + yoffset; | |
ced3df77 | 1244 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); |
a92964a2 RR |
1245 | CalcBoundingBox( x, y ); |
1246 | } | |
ced3df77 VZ |
1247 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); |
1248 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
a92964a2 | 1249 | } |
ff910433 RR |
1250 | } |
1251 | ||
89efaf2b | 1252 | void wxGnomePrinterDCImpl::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, wxPolygonFillMode fillStyle) |
ff910433 | 1253 | { |
3e4b352f | 1254 | #if wxUSE_NEW_DC |
888dde65 | 1255 | wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); |
3e4b352f | 1256 | #else |
a92964a2 | 1257 | wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle ); |
3e4b352f | 1258 | #endif |
ff910433 RR |
1259 | } |
1260 | ||
888dde65 | 1261 | void wxGnomePrinterDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
ff910433 | 1262 | { |
728ddc45 RR |
1263 | width--; |
1264 | height--; | |
1265 | ||
04ee05f9 | 1266 | if (m_brush.GetStyle () != wxBRUSHSTYLE_TRANSPARENT) |
ff910433 RR |
1267 | { |
1268 | SetBrush( m_brush ); | |
389076f1 | 1269 | |
ced3df77 VZ |
1270 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1271 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1272 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1273 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1274 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1275 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1276 | gs_libGnomePrint->gnome_print_fill( m_gpc ); | |
ff910433 RR |
1277 | |
1278 | CalcBoundingBox( x, y ); | |
1279 | CalcBoundingBox( x + width, y + height ); | |
1280 | } | |
1281 | ||
04ee05f9 | 1282 | if (m_pen.GetStyle () != wxPENSTYLE_TRANSPARENT) |
ff910433 RR |
1283 | { |
1284 | SetPen (m_pen); | |
1285 | ||
ced3df77 VZ |
1286 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1287 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1288 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1289 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1290 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1291 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1292 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); | |
389076f1 | 1293 | |
ff910433 RR |
1294 | CalcBoundingBox( x, y ); |
1295 | CalcBoundingBox( x + width, y + height ); | |
1296 | } | |
1297 | } | |
1298 | ||
888dde65 | 1299 | void wxGnomePrinterDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) |
ff910433 | 1300 | { |
728ddc45 RR |
1301 | width--; |
1302 | height--; | |
1303 | ||
1304 | wxCoord rad = wxRound( radius ); | |
9a2fe010 | 1305 | |
04ee05f9 | 1306 | if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) |
9a2fe010 RR |
1307 | { |
1308 | SetBrush(m_brush); | |
ced3df77 VZ |
1309 | gs_libGnomePrint->gnome_print_newpath(m_gpc); |
1310 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1311 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1312 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1313 | XLOG2DEV(x),YLOG2DEV(y), | |
1314 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
ced3df77 VZ |
1315 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1316 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1317 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1318 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1319 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
ced3df77 VZ |
1320 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1321 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1322 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1323 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1324 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
ced3df77 VZ |
1325 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1326 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1327 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1328 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1329 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
ced3df77 VZ |
1330 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1331 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1332 | gs_libGnomePrint->gnome_print_fill(m_gpc); | |
389076f1 | 1333 | |
9a2fe010 RR |
1334 | CalcBoundingBox(x,y); |
1335 | CalcBoundingBox(x+width,y+height); | |
1336 | } | |
389076f1 | 1337 | |
04ee05f9 | 1338 | if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) |
9a2fe010 RR |
1339 | { |
1340 | SetPen(m_pen); | |
ced3df77 VZ |
1341 | gs_libGnomePrint->gnome_print_newpath(m_gpc); |
1342 | gs_libGnomePrint->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); | |
1343 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1344 | XLOG2DEV(x + rad),YLOG2DEV(y), |
1345 | XLOG2DEV(x),YLOG2DEV(y), | |
1346 | XLOG2DEV(x),YLOG2DEV(y + rad)); | |
ced3df77 VZ |
1347 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad)); |
1348 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1349 | XLOG2DEV(x),YLOG2DEV(y + height - rad), |
1350 | XLOG2DEV(x),YLOG2DEV(y + height), | |
1351 | XLOG2DEV(x + rad),YLOG2DEV(y + height)); | |
ced3df77 VZ |
1352 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height)); |
1353 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1354 | XLOG2DEV(x + width - rad),YLOG2DEV(y + height), |
1355 | XLOG2DEV(x + width),YLOG2DEV(y + height), | |
1356 | XLOG2DEV(x + width),YLOG2DEV(y + height - rad)); | |
ced3df77 VZ |
1357 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad)); |
1358 | gs_libGnomePrint->gnome_print_curveto(m_gpc, | |
389076f1 WS |
1359 | XLOG2DEV(x + width),YLOG2DEV(y + rad), |
1360 | XLOG2DEV(x + width),YLOG2DEV(y), | |
1361 | XLOG2DEV(x + width - rad),YLOG2DEV(y)); | |
ced3df77 VZ |
1362 | gs_libGnomePrint->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y)); |
1363 | gs_libGnomePrint->gnome_print_closepath(m_gpc); | |
1364 | gs_libGnomePrint->gnome_print_stroke(m_gpc); | |
389076f1 | 1365 | |
9a2fe010 RR |
1366 | CalcBoundingBox(x,y); |
1367 | CalcBoundingBox(x+width,y+height); | |
1368 | } | |
ff910433 RR |
1369 | } |
1370 | ||
888dde65 | 1371 | void wxGnomePrinterDCImpl::makeEllipticalPath(wxCoord x, wxCoord y, |
74ab0bfb RR |
1372 | wxCoord width, wxCoord height) |
1373 | { | |
61643018 | 1374 | double r = 4 * (sqrt(2.) - 1) / 3; |
74ab0bfb RR |
1375 | double halfW = 0.5 * width, |
1376 | halfH = 0.5 * height, | |
1377 | halfWR = r * halfW, | |
1378 | halfHR = r * halfH; | |
1379 | wxCoord halfWI = (wxCoord) halfW, | |
1380 | halfHI = (wxCoord) halfH; | |
e4db172a | 1381 | |
ced3df77 | 1382 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
e4db172a | 1383 | |
74ab0bfb | 1384 | // Approximate an ellipse using four cubic splines, clockwise from 0 deg */ |
ced3df77 | 1385 | gs_libGnomePrint->gnome_print_moveto( m_gpc, |
e4db172a | 1386 | XLOG2DEV(x + width), |
74ab0bfb | 1387 | YLOG2DEV(y + halfHI) ); |
ced3df77 | 1388 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1389 | XLOG2DEV(x + width), |
1390 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
e4db172a | 1391 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
74ab0bfb | 1392 | YLOG2DEV(y + height), |
e4db172a | 1393 | XLOG2DEV(x + halfWI), |
74ab0bfb | 1394 | YLOG2DEV(y + height) ); |
ced3df77 | 1395 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
e4db172a | 1396 | XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)), |
74ab0bfb RR |
1397 | YLOG2DEV(y + height), |
1398 | XLOG2DEV(x), | |
1399 | YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)), | |
1400 | XLOG2DEV(x), YLOG2DEV(y+halfHI) ); | |
ced3df77 | 1401 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1402 | XLOG2DEV(x), |
1403 | YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)), | |
1404 | XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)), | |
1405 | YLOG2DEV(y), | |
1406 | XLOG2DEV(x+halfWI), YLOG2DEV(y) ); | |
ced3df77 | 1407 | gs_libGnomePrint->gnome_print_curveto( m_gpc, |
74ab0bfb RR |
1408 | XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)), |
1409 | YLOG2DEV(y), | |
1410 | XLOG2DEV(x + width), | |
1411 | YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)), | |
1412 | XLOG2DEV(x + width), YLOG2DEV(y + halfHI) ); | |
e4db172a | 1413 | |
ced3df77 | 1414 | gs_libGnomePrint->gnome_print_closepath(m_gpc); |
74ab0bfb RR |
1415 | } |
1416 | ||
888dde65 | 1417 | void wxGnomePrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
ff910433 | 1418 | { |
728ddc45 RR |
1419 | width--; |
1420 | height--; | |
1421 | ||
04ee05f9 | 1422 | if (m_brush.GetStyle () != wxBRUSHSTYLE_TRANSPARENT) |
cac7ac30 RR |
1423 | { |
1424 | SetBrush( m_brush ); | |
74ab0bfb | 1425 | makeEllipticalPath( x, y, width, height ); |
ced3df77 | 1426 | gs_libGnomePrint->gnome_print_fill( m_gpc ); |
cac7ac30 RR |
1427 | CalcBoundingBox( x, y ); |
1428 | CalcBoundingBox( x + width, y + height ); | |
1429 | } | |
1430 | ||
04ee05f9 | 1431 | if (m_pen.GetStyle () != wxPENSTYLE_TRANSPARENT) |
cac7ac30 RR |
1432 | { |
1433 | SetPen (m_pen); | |
74ab0bfb | 1434 | makeEllipticalPath( x, y, width, height ); |
ced3df77 | 1435 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
cac7ac30 RR |
1436 | CalcBoundingBox( x, y ); |
1437 | CalcBoundingBox( x + width, y + height ); | |
1438 | } | |
ff910433 RR |
1439 | } |
1440 | ||
389076f1 | 1441 | #if wxUSE_SPLINES |
888dde65 | 1442 | void wxGnomePrinterDCImpl::DoDrawSpline(const wxPointList *points) |
ff910433 | 1443 | { |
121c09cd RR |
1444 | SetPen (m_pen); |
1445 | ||
1446 | double c, d, x1, y1, x2, y2, x3, y3; | |
1447 | wxPoint *p, *q; | |
1448 | ||
b0d7707b RR |
1449 | wxPointList::compatibility_iterator node = points->GetFirst(); |
1450 | p = node->GetData(); | |
121c09cd RR |
1451 | x1 = p->x; |
1452 | y1 = p->y; | |
1453 | ||
1454 | node = node->GetNext(); | |
b0d7707b | 1455 | p = node->GetData(); |
121c09cd RR |
1456 | c = p->x; |
1457 | d = p->y; | |
1458 | x3 = | |
1459 | (double)(x1 + c) / 2; | |
1460 | y3 = | |
1461 | (double)(y1 + d) / 2; | |
1462 | ||
ced3df77 VZ |
1463 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1464 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) ); | |
1465 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
389076f1 | 1466 | |
121c09cd RR |
1467 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); |
1468 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1469 | ||
1470 | node = node->GetNext(); | |
1471 | while (node) | |
1472 | { | |
b0d7707b | 1473 | q = node->GetData(); |
121c09cd RR |
1474 | |
1475 | x1 = x3; | |
1476 | y1 = y3; | |
1477 | x2 = c; | |
1478 | y2 = d; | |
1479 | c = q->x; | |
1480 | d = q->y; | |
1481 | x3 = (double)(x2 + c) / 2; | |
1482 | y3 = (double)(y2 + d) / 2; | |
1483 | ||
ced3df77 | 1484 | gs_libGnomePrint->gnome_print_curveto(m_gpc, |
121c09cd RR |
1485 | XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1), |
1486 | XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2), | |
1487 | XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) ); | |
1488 | ||
1489 | CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); | |
1490 | CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); | |
1491 | ||
1492 | node = node->GetNext(); | |
1493 | } | |
389076f1 | 1494 | |
ced3df77 | 1495 | gs_libGnomePrint->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) ); |
389076f1 | 1496 | |
ced3df77 | 1497 | gs_libGnomePrint->gnome_print_stroke( m_gpc ); |
ff910433 | 1498 | } |
389076f1 | 1499 | #endif // wxUSE_SPLINES |
ff910433 | 1500 | |
e4161a2a | 1501 | bool |
888dde65 | 1502 | wxGnomePrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, |
e4161a2a VZ |
1503 | wxCoord width, wxCoord height, |
1504 | wxDC *source, | |
1505 | wxCoord xsrc, wxCoord ysrc, | |
89efaf2b | 1506 | wxRasterOperationMode rop, |
e4161a2a VZ |
1507 | bool WXUNUSED(useMask), |
1508 | wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask)) | |
ff910433 | 1509 | { |
2f41910a RR |
1510 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); |
1511 | ||
1512 | // blit into a bitmap | |
1513 | wxBitmap bitmap( width, height ); | |
1514 | wxMemoryDC memDC; | |
1515 | memDC.SelectObject(bitmap); | |
1516 | memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ | |
1517 | memDC.SelectObject(wxNullBitmap); | |
1518 | ||
1519 | // draw bitmap. scaling and positioning is done there | |
3e4b352f | 1520 | GetOwner()->DrawBitmap( bitmap, xdest, ydest ); |
2f41910a RR |
1521 | |
1522 | return true; | |
ff910433 RR |
1523 | } |
1524 | ||
888dde65 | 1525 | void wxGnomePrinterDCImpl::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y ) |
ff910433 | 1526 | { |
e1bf3ad3 | 1527 | DoDrawBitmap( icon, x, y, true ); |
ff910433 RR |
1528 | } |
1529 | ||
e4161a2a | 1530 | void |
888dde65 | 1531 | wxGnomePrinterDCImpl::DoDrawBitmap(const wxBitmap& bitmap, |
e4161a2a VZ |
1532 | wxCoord x, wxCoord y, |
1533 | bool WXUNUSED(useMask)) | |
ff910433 | 1534 | { |
e1bf3ad3 | 1535 | if (!bitmap.Ok()) return; |
389076f1 | 1536 | |
e1bf3ad3 RR |
1537 | if (bitmap.HasPixbuf()) |
1538 | { | |
2934005d | 1539 | GdkPixbuf *pixbuf = bitmap.GetPixbuf(); |
389076f1 WS |
1540 | guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf ); |
1541 | bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf ); | |
1542 | int rowstride = gdk_pixbuf_get_rowstride( pixbuf ); | |
1543 | int height = gdk_pixbuf_get_height( pixbuf ); | |
1544 | int width = gdk_pixbuf_get_width( pixbuf ); | |
1545 | ||
ced3df77 | 1546 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
2934005d | 1547 | double matrix[6]; |
389076f1 WS |
1548 | matrix[0] = XLOG2DEVREL(width); |
1549 | matrix[1] = 0; | |
1550 | matrix[2] = 0; | |
1551 | matrix[3] = YLOG2DEVREL(height); | |
1552 | matrix[4] = XLOG2DEV(x); | |
2934005d | 1553 | matrix[5] = YLOG2DEV(y+height); |
ced3df77 VZ |
1554 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); |
1555 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); | |
2934005d | 1556 | if (has_alpha) |
ced3df77 | 1557 | gs_libGnomePrint->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
2934005d | 1558 | else |
ced3df77 VZ |
1559 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride ); |
1560 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
e1bf3ad3 RR |
1561 | } |
1562 | else | |
e1bf3ad3 RR |
1563 | { |
1564 | wxImage image = bitmap.ConvertToImage(); | |
1565 | ||
1566 | if (!image.Ok()) return; | |
2934005d | 1567 | |
ced3df77 | 1568 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
b4382784 | 1569 | double matrix[6]; |
389076f1 WS |
1570 | matrix[0] = XLOG2DEVREL(image.GetWidth()); |
1571 | matrix[1] = 0; | |
1572 | matrix[2] = 0; | |
1573 | matrix[3] = YLOG2DEVREL(image.GetHeight()); | |
1574 | matrix[4] = XLOG2DEV(x); | |
b4382784 | 1575 | matrix[5] = YLOG2DEV(y+image.GetHeight()); |
ced3df77 VZ |
1576 | gs_libGnomePrint->gnome_print_concat( m_gpc, matrix ); |
1577 | gs_libGnomePrint->gnome_print_moveto( m_gpc, 0, 0 ); | |
1578 | gs_libGnomePrint->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 ); | |
1579 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); | |
e1bf3ad3 | 1580 | } |
ff910433 RR |
1581 | } |
1582 | ||
888dde65 | 1583 | void wxGnomePrinterDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y ) |
b199de59 RR |
1584 | { |
1585 | DoDrawRotatedText( text, x, y, 0.0 ); | |
1586 | } | |
1587 | ||
888dde65 | 1588 | void wxGnomePrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) |
ff910433 | 1589 | { |
02255e07 RR |
1590 | double xx = XLOG2DEV(x); |
1591 | double yy = YLOG2DEV(y); | |
389076f1 | 1592 | |
ff910433 RR |
1593 | bool underlined = m_font.Ok() && m_font.GetUnderlined(); |
1594 | ||
f9dcd25d | 1595 | const wxScopedCharBuffer data(text.utf8_str()); |
ff910433 | 1596 | |
e0a050e3 VS |
1597 | size_t datalen = strlen(data); |
1598 | pango_layout_set_text( m_layout, data, datalen); | |
389076f1 | 1599 | |
ff910433 RR |
1600 | if (underlined) |
1601 | { | |
1602 | PangoAttrList *attrs = pango_attr_list_new(); | |
1603 | PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); | |
1604 | a->start_index = 0; | |
1605 | a->end_index = datalen; | |
1606 | pango_attr_list_insert(attrs, a); | |
1607 | pango_layout_set_attributes(m_layout, attrs); | |
1608 | pango_attr_list_unref(attrs); | |
1609 | } | |
1610 | ||
2934005d RR |
1611 | if (m_textForegroundColour.Ok()) |
1612 | { | |
1613 | unsigned char red = m_textForegroundColour.Red(); | |
1614 | unsigned char blue = m_textForegroundColour.Blue(); | |
1615 | unsigned char green = m_textForegroundColour.Green(); | |
1616 | ||
b199de59 RR |
1617 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) |
1618 | { | |
1619 | double redPS = (double)(red) / 255.0; | |
1620 | double bluePS = (double)(blue) / 255.0; | |
1621 | double greenPS = (double)(green) / 255.0; | |
1622 | ||
ced3df77 | 1623 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
b199de59 RR |
1624 | |
1625 | m_currentRed = red; | |
1626 | m_currentBlue = blue; | |
1627 | m_currentGreen = green; | |
1628 | } | |
2934005d RR |
1629 | } |
1630 | ||
fa499247 RR |
1631 | #if 0 |
1632 | if ( m_backgroundMode == wxSOLID ) | |
1633 | { | |
1634 | gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor()); | |
02255e07 | 1635 | gdk_draw_rectangle(m_window, m_textGC, TRUE, xx, yy, w, h); |
fa499247 RR |
1636 | gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); |
1637 | } | |
389076f1 | 1638 | #endif |
fa499247 | 1639 | |
02255e07 RR |
1640 | // Draw layout. |
1641 | gs_libGnomePrint->gnome_print_moveto (m_gpc, xx, yy); | |
e4161a2a | 1642 | |
02255e07 | 1643 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
e4161a2a | 1644 | |
02255e07 | 1645 | gs_libGnomePrint->gnome_print_scale( m_gpc, m_scaleX * DEV2PS, m_scaleY * DEV2PS ); |
e4161a2a | 1646 | |
02255e07 RR |
1647 | if (fabs(angle) > 0.00001) |
1648 | gs_libGnomePrint->gnome_print_rotate( m_gpc, angle ); | |
e4161a2a | 1649 | |
02255e07 | 1650 | gs_libGnomePrint->gnome_print_pango_layout( m_gpc, m_layout ); |
e4161a2a | 1651 | |
12ca5586 VS |
1652 | int w,h; |
1653 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
1654 | ||
02255e07 | 1655 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
e4161a2a | 1656 | |
ff910433 RR |
1657 | if (underlined) |
1658 | { | |
1659 | // undo underline attributes setting: | |
1660 | pango_layout_set_attributes(m_layout, NULL); | |
1661 | } | |
389076f1 | 1662 | |
12ca5586 VS |
1663 | CalcBoundingBox(x, y); |
1664 | CalcBoundingBox(x + w, y + h); | |
ff910433 RR |
1665 | } |
1666 | ||
888dde65 | 1667 | void wxGnomePrinterDCImpl::Clear() |
ff910433 RR |
1668 | { |
1669 | } | |
1670 | ||
888dde65 | 1671 | void wxGnomePrinterDCImpl::SetFont( const wxFont& font ) |
ff910433 RR |
1672 | { |
1673 | m_font = font; | |
389076f1 | 1674 | |
ff910433 RR |
1675 | if (m_font.Ok()) |
1676 | { | |
1677 | if (m_fontdesc) | |
1678 | pango_font_description_free( m_fontdesc ); | |
389076f1 | 1679 | |
ff910433 | 1680 | m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
389076f1 | 1681 | |
12ca5586 VS |
1682 | float size = pango_font_description_get_size( m_fontdesc ); |
1683 | size = size * GetFontPointSizeAdjustment(72.0); | |
1684 | pango_font_description_set_size( m_fontdesc, (gint)size ); | |
1685 | ||
ff910433 RR |
1686 | pango_layout_set_font_description( m_layout, m_fontdesc ); |
1687 | } | |
1688 | } | |
1689 | ||
888dde65 | 1690 | void wxGnomePrinterDCImpl::SetPen( const wxPen& pen ) |
ff910433 RR |
1691 | { |
1692 | if (!pen.Ok()) return; | |
1693 | ||
ff910433 RR |
1694 | m_pen = pen; |
1695 | ||
f62edb0e | 1696 | double width; |
e4161a2a | 1697 | |
f62edb0e RR |
1698 | if (m_pen.GetWidth() <= 0) |
1699 | width = 0.1; | |
1700 | else | |
1701 | width = (double) m_pen.GetWidth(); | |
1702 | ||
1703 | gs_libGnomePrint->gnome_print_setlinewidth( m_gpc, width * DEV2PS * m_scaleX ); | |
cac7ac30 RR |
1704 | |
1705 | static const double dotted[] = {2.0, 5.0}; | |
1706 | static const double short_dashed[] = {4.0, 4.0}; | |
1707 | static const double wxCoord_dashed[] = {4.0, 8.0}; | |
1708 | static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0}; | |
1709 | ||
1710 | switch (m_pen.GetStyle()) | |
1711 | { | |
04ee05f9 PC |
1712 | case wxPENSTYLE_DOT: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break; |
1713 | case wxPENSTYLE_SHORT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break; | |
1714 | case wxPENSTYLE_LONG_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break; | |
1715 | case wxPENSTYLE_DOT_DASH: gs_libGnomePrint->gnome_print_setdash( m_gpc, 4, dotted_dashed, 0 ); break; | |
1716 | case wxPENSTYLE_USER_DASH: | |
8c419a5c RR |
1717 | { |
1718 | // It may be noted that libgnomeprint between at least | |
1719 | // versions 2.8.0 and 2.12.1 makes a copy of the dashes | |
1720 | // and then leak the memory since it doesn't set the | |
1721 | // internal flag "privatedash" to 0. | |
1722 | wxDash *wx_dashes; | |
1723 | int num = m_pen.GetDashes (&wx_dashes); | |
1724 | gdouble *g_dashes = g_new( gdouble, num ); | |
1725 | int i; | |
1726 | for (i = 0; i < num; ++i) | |
1727 | g_dashes[i] = (gdouble) wx_dashes[i]; | |
ced3df77 | 1728 | gs_libGnomePrint -> gnome_print_setdash( m_gpc, num, g_dashes, 0); |
8c419a5c RR |
1729 | g_free( g_dashes ); |
1730 | } | |
1731 | break; | |
04ee05f9 PC |
1732 | case wxPENSTYLE_SOLID: |
1733 | case wxPENSTYLE_TRANSPARENT: | |
ced3df77 | 1734 | default: gs_libGnomePrint->gnome_print_setdash( m_gpc, 0, NULL, 0 ); break; |
cac7ac30 RR |
1735 | } |
1736 | ||
389076f1 | 1737 | |
ff910433 RR |
1738 | unsigned char red = m_pen.GetColour().Red(); |
1739 | unsigned char blue = m_pen.GetColour().Blue(); | |
1740 | unsigned char green = m_pen.GetColour().Green(); | |
1741 | ||
1742 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1743 | { | |
1744 | double redPS = (double)(red) / 255.0; | |
1745 | double bluePS = (double)(blue) / 255.0; | |
1746 | double greenPS = (double)(green) / 255.0; | |
1747 | ||
ced3df77 | 1748 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
ff910433 RR |
1749 | |
1750 | m_currentRed = red; | |
1751 | m_currentBlue = blue; | |
1752 | m_currentGreen = green; | |
1753 | } | |
1754 | } | |
1755 | ||
888dde65 | 1756 | void wxGnomePrinterDCImpl::SetBrush( const wxBrush& brush ) |
ff910433 | 1757 | { |
fa499247 RR |
1758 | if (!brush.Ok()) return; |
1759 | ||
1760 | m_brush = brush; | |
1761 | ||
1762 | // Brush colour | |
1763 | unsigned char red = m_brush.GetColour().Red(); | |
1764 | unsigned char blue = m_brush.GetColour().Blue(); | |
1765 | unsigned char green = m_brush.GetColour().Green(); | |
1766 | ||
1767 | if (!m_colour) | |
1768 | { | |
1769 | // Anything not white is black | |
1770 | if (! (red == (unsigned char) 255 && | |
1771 | blue == (unsigned char) 255 && | |
1772 | green == (unsigned char) 255) ) | |
1773 | { | |
1774 | red = (unsigned char) 0; | |
1775 | green = (unsigned char) 0; | |
1776 | blue = (unsigned char) 0; | |
1777 | } | |
1778 | // setgray here ? | |
1779 | } | |
1780 | ||
1781 | if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue)) | |
1782 | { | |
1783 | double redPS = (double)(red) / 255.0; | |
1784 | double bluePS = (double)(blue) / 255.0; | |
1785 | double greenPS = (double)(green) / 255.0; | |
1786 | ||
ced3df77 | 1787 | gs_libGnomePrint->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS ); |
fa499247 RR |
1788 | |
1789 | m_currentRed = red; | |
1790 | m_currentBlue = blue; | |
1791 | m_currentGreen = green; | |
1792 | } | |
ff910433 RR |
1793 | } |
1794 | ||
89efaf2b | 1795 | void wxGnomePrinterDCImpl::SetLogicalFunction(wxRasterOperationMode WXUNUSED(function)) |
ff910433 RR |
1796 | { |
1797 | } | |
1798 | ||
888dde65 | 1799 | void wxGnomePrinterDCImpl::SetBackground(const wxBrush& WXUNUSED(brush)) |
ff910433 RR |
1800 | { |
1801 | } | |
1802 | ||
888dde65 | 1803 | void wxGnomePrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
ff910433 | 1804 | { |
3e4b352f RR |
1805 | #if wxUSE_NEW_DC |
1806 | m_clipping = TRUE; // TODO move somewhere else | |
1807 | m_clipX1 = x; | |
1808 | m_clipY1 = y; | |
1809 | m_clipX2 = x + width; | |
1810 | m_clipY2 = y + height; | |
1811 | #else | |
75aa53c9 | 1812 | wxDC::DoSetClippingRegion( x, y, width, height ); |
3e4b352f | 1813 | #endif |
e4161a2a | 1814 | |
ced3df77 | 1815 | gs_libGnomePrint->gnome_print_gsave( m_gpc ); |
e4161a2a | 1816 | |
ced3df77 VZ |
1817 | gs_libGnomePrint->gnome_print_newpath( m_gpc ); |
1818 | gs_libGnomePrint->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) ); | |
1819 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) ); | |
1820 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) ); | |
1821 | gs_libGnomePrint->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) ); | |
1822 | gs_libGnomePrint->gnome_print_closepath( m_gpc ); | |
1823 | gs_libGnomePrint->gnome_print_clip( m_gpc ); | |
ff910433 RR |
1824 | } |
1825 | ||
888dde65 | 1826 | void wxGnomePrinterDCImpl::DestroyClippingRegion() |
ff910433 | 1827 | { |
3e4b352f | 1828 | #if wxUSE_NEW_DC |
888dde65 | 1829 | wxDCImpl::DestroyClippingRegion(); |
3e4b352f | 1830 | #else |
75aa53c9 | 1831 | wxDC::DestroyClippingRegion(); |
3e4b352f | 1832 | #endif |
75aa53c9 | 1833 | |
ced3df77 | 1834 | gs_libGnomePrint->gnome_print_grestore( m_gpc ); |
e4161a2a | 1835 | |
3b7ab6bd RR |
1836 | #if 0 |
1837 | // not needed, we set the values in each | |
1838 | // drawing method anyways | |
1839 | SetPen( m_pen ); | |
1840 | SetBrush( m_brush ); | |
1841 | SetFont( m_font ); | |
1842 | #endif | |
ff910433 RR |
1843 | } |
1844 | ||
888dde65 | 1845 | bool wxGnomePrinterDCImpl::StartDoc(const wxString& WXUNUSED(message)) |
ff910433 | 1846 | { |
ff910433 RR |
1847 | return true; |
1848 | } | |
1849 | ||
888dde65 | 1850 | void wxGnomePrinterDCImpl::EndDoc() |
ff910433 | 1851 | { |
ced3df77 | 1852 | gs_libGnomePrint->gnome_print_end_doc( m_gpc ); |
ff910433 RR |
1853 | } |
1854 | ||
888dde65 | 1855 | void wxGnomePrinterDCImpl::StartPage() |
ff910433 | 1856 | { |
ced3df77 | 1857 | gs_libGnomePrint->gnome_print_beginpage( m_gpc, (const guchar*) "page" ); |
ff910433 RR |
1858 | } |
1859 | ||
888dde65 | 1860 | void wxGnomePrinterDCImpl::EndPage() |
ff910433 | 1861 | { |
ced3df77 | 1862 | gs_libGnomePrint->gnome_print_showpage( m_gpc ); |
ff910433 RR |
1863 | } |
1864 | ||
888dde65 | 1865 | wxCoord wxGnomePrinterDCImpl::GetCharHeight() const |
ff910433 | 1866 | { |
b199de59 | 1867 | pango_layout_set_text( m_layout, "H", 1 ); |
389076f1 | 1868 | |
b199de59 RR |
1869 | int w,h; |
1870 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1871 | |
b199de59 | 1872 | return h; |
ff910433 RR |
1873 | } |
1874 | ||
888dde65 | 1875 | wxCoord wxGnomePrinterDCImpl::GetCharWidth() const |
ff910433 | 1876 | { |
b199de59 | 1877 | pango_layout_set_text( m_layout, "H", 1 ); |
389076f1 | 1878 | |
b199de59 RR |
1879 | int w,h; |
1880 | pango_layout_get_pixel_size( m_layout, &w, &h ); | |
389076f1 | 1881 | |
b199de59 | 1882 | return w; |
ff910433 RR |
1883 | } |
1884 | ||
888dde65 | 1885 | void wxGnomePrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, |
ff910433 RR |
1886 | wxCoord *descent, |
1887 | wxCoord *externalLeading, | |
c94f845b | 1888 | const wxFont *theFont ) const |
ff910433 | 1889 | { |
981a6af1 RR |
1890 | if ( width ) |
1891 | *width = 0; | |
1892 | if ( height ) | |
1893 | *height = 0; | |
1894 | if ( descent ) | |
1895 | *descent = 0; | |
1896 | if ( externalLeading ) | |
1897 | *externalLeading = 0; | |
1898 | ||
389076f1 | 1899 | if (string.empty()) |
981a6af1 RR |
1900 | { |
1901 | return; | |
1902 | } | |
389076f1 | 1903 | |
981a6af1 | 1904 | // Set layout's text |
e0a050e3 | 1905 | |
f9dcd25d | 1906 | const wxScopedCharBuffer dataUTF8(string.utf8_str()); |
981a6af1 | 1907 | |
59730a00 | 1908 | gint oldSize = 0; |
12ca5586 VS |
1909 | if ( theFont ) |
1910 | { | |
1911 | // scale the font and apply it | |
1912 | PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; | |
5bd57a7e VZ |
1913 | oldSize = pango_font_description_get_size(desc); |
1914 | float size = oldSize * GetFontPointSizeAdjustment(72.0); | |
12ca5586 | 1915 | pango_font_description_set_size(desc, (gint)size); |
0cc0ce06 | 1916 | |
12ca5586 VS |
1917 | pango_layout_set_font_description(m_layout, desc); |
1918 | } | |
0cc0ce06 | 1919 | |
981a6af1 | 1920 | pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); |
389076f1 | 1921 | |
12ca5586 VS |
1922 | int h; |
1923 | pango_layout_get_pixel_size( m_layout, width, &h ); | |
1924 | if ( height ) | |
1925 | *height = h; | |
0cc0ce06 | 1926 | |
981a6af1 RR |
1927 | if (descent) |
1928 | { | |
1929 | PangoLayoutIter *iter = pango_layout_get_iter(m_layout); | |
1930 | int baseline = pango_layout_iter_get_baseline(iter); | |
1931 | pango_layout_iter_free(iter); | |
1932 | *descent = h - PANGO_PIXELS(baseline); | |
1933 | } | |
389076f1 | 1934 | |
12ca5586 VS |
1935 | if ( theFont ) |
1936 | { | |
1937 | // restore font and reset font's size back | |
1938 | pango_layout_set_font_description(m_layout, m_fontdesc); | |
0cc0ce06 | 1939 | |
12ca5586 VS |
1940 | PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; |
1941 | pango_font_description_set_size(desc, oldSize); | |
1942 | } | |
ff910433 RR |
1943 | } |
1944 | ||
888dde65 | 1945 | void wxGnomePrinterDCImpl::DoGetSize(int* width, int* height) const |
ff910433 | 1946 | { |
cffcf831 RR |
1947 | wxGnomePrintNativeData *native = |
1948 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1949 | ||
1950 | // Query page size. This seems to omit the margins | |
cffcf831 | 1951 | double pw,ph; |
ced3df77 | 1952 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
ff910433 | 1953 | |
ff910433 | 1954 | if (width) |
02255e07 | 1955 | *width = wxRound( pw * PS2DEV ); |
e4161a2a | 1956 | |
ff910433 | 1957 | if (height) |
02255e07 | 1958 | *height = wxRound( ph * PS2DEV ); |
ff910433 RR |
1959 | } |
1960 | ||
888dde65 | 1961 | void wxGnomePrinterDCImpl::DoGetSizeMM(int *width, int *height) const |
ff910433 | 1962 | { |
cffcf831 RR |
1963 | wxGnomePrintNativeData *native = |
1964 | (wxGnomePrintNativeData*) m_printData.GetNativeData(); | |
1965 | ||
389076f1 WS |
1966 | // This code assumes values in Pts. |
1967 | ||
cffcf831 | 1968 | double pw,ph; |
ced3df77 | 1969 | gs_libGnomePrint->gnome_print_job_get_page_size( native->GetPrintJob(), &pw, &ph ); |
cffcf831 RR |
1970 | |
1971 | // Convert to mm. | |
389076f1 | 1972 | |
ced3df77 VZ |
1973 | const GnomePrintUnit *mm_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); |
1974 | const GnomePrintUnit *pts_unit = gs_libGnomePrint->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); | |
1975 | gs_libGnomePrint->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); | |
1976 | gs_libGnomePrint->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); | |
389076f1 | 1977 | |
ff910433 | 1978 | if (width) |
cffcf831 | 1979 | *width = (int) (pw + 0.5); |
ff910433 | 1980 | if (height) |
cffcf831 | 1981 | *height = (int) (ph + 0.5); |
ff910433 RR |
1982 | } |
1983 | ||
888dde65 | 1984 | wxSize wxGnomePrinterDCImpl::GetPPI() const |
ff910433 | 1985 | { |
02255e07 | 1986 | return wxSize(DPI,DPI); |
92120c6e RR |
1987 | } |
1988 | ||
888dde65 | 1989 | void wxGnomePrinterDCImpl::SetPrintData(const wxPrintData& data) |
e4161a2a | 1990 | { |
3b7ab6bd | 1991 | m_printData = data; |
e4161a2a | 1992 | |
02255e07 | 1993 | int height; |
3b7ab6bd | 1994 | if (m_printData.GetOrientation() == wxPORTRAIT) |
3e4b352f | 1995 | GetOwner()->GetSize( NULL, &height ); |
3b7ab6bd | 1996 | else |
3e4b352f | 1997 | GetOwner()->GetSize( &height, NULL ); |
02255e07 | 1998 | m_deviceLocalOriginY = height; |
3b7ab6bd RR |
1999 | } |
2000 | ||
3e4b352f RR |
2001 | // overridden for wxPrinterDC Impl |
2002 | ||
6d52ca53 | 2003 | int wxGnomePrinterDCImpl::GetResolution() const |
ff910433 | 2004 | { |
3e4b352f | 2005 | return DPI; |
ff910433 RR |
2006 | } |
2007 | ||
6d52ca53 | 2008 | wxRect wxGnomePrinterDCImpl::GetPaperRect() const |
ff910433 | 2009 | { |
3e4b352f RR |
2010 | // GNOME print doesn't support printer margins |
2011 | int w = 0; | |
2012 | int h = 0; | |
2013 | DoGetSize( &w, &h ); | |
2014 | return wxRect( 0, 0, w, h ); | |
ff910433 | 2015 | } |
7c72311f | 2016 | |
1ff62f51 RR |
2017 | // ---------------------------------------------------------------------------- |
2018 | // wxGnomePrintModule | |
2019 | // ---------------------------------------------------------------------------- | |
58c30cd8 | 2020 | |
c6efd6e0 RR |
2021 | bool wxGnomePrintModule::OnInit() |
2022 | { | |
ced3df77 VZ |
2023 | gs_libGnomePrint = new wxGnomePrintLibrary; |
2024 | if (gs_libGnomePrint->IsOk()) | |
c6efd6e0 RR |
2025 | wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory ); |
2026 | return true; | |
2027 | } | |
2028 | ||
2029 | void wxGnomePrintModule::OnExit() | |
2030 | { | |
ced3df77 VZ |
2031 | delete gs_libGnomePrint; |
2032 | gs_libGnomePrint = NULL; | |
c6efd6e0 RR |
2033 | } |
2034 | ||
58c30cd8 | 2035 | IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule) |
389076f1 | 2036 | |
147bf263 JS |
2037 | // ---------------------------------------------------------------------------- |
2038 | // Print preview | |
2039 | // ---------------------------------------------------------------------------- | |
2040 | ||
2041 | IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase) | |
2042 | ||
2043 | void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout), | |
2044 | wxPrintout * WXUNUSED(printoutForPrinting)) | |
2045 | { | |
2046 | DetermineScaling(); | |
2047 | } | |
2048 | ||
2049 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
2050 | wxPrintout *printoutForPrinting, | |
2051 | wxPrintDialogData *data) | |
2052 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
2053 | { | |
2054 | Init(printout, printoutForPrinting); | |
2055 | } | |
2056 | ||
2057 | wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout, | |
2058 | wxPrintout *printoutForPrinting, | |
2059 | wxPrintData *data) | |
2060 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
2061 | { | |
2062 | Init(printout, printoutForPrinting); | |
2063 | } | |
2064 | ||
2065 | wxGnomePrintPreview::~wxGnomePrintPreview() | |
2066 | { | |
2067 | } | |
2068 | ||
2069 | bool wxGnomePrintPreview::Print(bool interactive) | |
2070 | { | |
2071 | if (!m_printPrintout) | |
2072 | return false; | |
2073 | ||
2074 | wxPrinter printer(& m_printDialogData); | |
2075 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
2076 | } | |
2077 | ||
2078 | void wxGnomePrintPreview::DetermineScaling() | |
2079 | { | |
2080 | wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); | |
2081 | if (paperType == wxPAPER_NONE) | |
2082 | paperType = wxPAPER_NONE; | |
2083 | ||
2084 | wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); | |
2085 | if (!paper) | |
2086 | paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); | |
2087 | ||
2088 | if (paper) | |
2089 | { | |
40fcf546 | 2090 | m_previewPrintout->SetPPIScreen(wxGetDisplayPPI()); |
147bf263 | 2091 | |
3e4b352f RR |
2092 | int resolution = DPI; |
2093 | m_previewPrintout->SetPPIPrinter( resolution, resolution ); | |
147bf263 JS |
2094 | |
2095 | wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); | |
f4322df6 | 2096 | |
888dde65 | 2097 | // TODO: get better resolution information from wxGnomePrinterDCImpl, if possible. |
147bf263 | 2098 | |
3e4b352f RR |
2099 | sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * resolution / 72.0); |
2100 | sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * resolution / 72.0); | |
147bf263 JS |
2101 | wxSize sizeTenthsMM(paper->GetSize()); |
2102 | wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); | |
2103 | ||
2104 | // If in landscape mode, we need to swap the width and height. | |
2105 | if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) | |
2106 | { | |
2107 | m_pageWidth = sizeDevUnits.y; | |
2108 | m_pageHeight = sizeDevUnits.x; | |
2109 | m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); | |
147bf263 JS |
2110 | } |
2111 | else | |
2112 | { | |
2113 | m_pageWidth = sizeDevUnits.x; | |
2114 | m_pageHeight = sizeDevUnits.y; | |
2115 | m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); | |
147bf263 | 2116 | } |
f415cab9 JS |
2117 | m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); |
2118 | m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); | |
147bf263 JS |
2119 | |
2120 | // At 100%, the page should look about page-size on the screen. | |
3e4b352f | 2121 | m_previewScaleX = (double)0.8 * 72.0 / (double)resolution; |
f415cab9 | 2122 | m_previewScaleY = m_previewScaleX; |
147bf263 JS |
2123 | } |
2124 | } | |
2125 | ||
e4161a2a | 2126 | #endif |
32f34982 | 2127 | // wxUSE_LIBGNOMEPRINT |