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