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