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