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