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