1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gnome/gprint.cpp
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME printing support
7 // Copyright: Robert Roebling
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 #include "wx/gtk/gnome/gprint.h"
20 #if wxUSE_LIBGNOMEPRINT
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"
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>
37 static const double RAD2DEG
= 180.0 / M_PI
;
39 #include "wx/html/forcelnk.h"
40 FORCE_LINK_ME(gnome_print
)
42 //----------------------------------------------------------------------------
43 // wxGnomePrintLibrary
44 //----------------------------------------------------------------------------
46 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
47 typedef rettype (* name ## Type) args ; \
48 name ## Type pfn_ ## name; \
50 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
52 #define wxDL_METHOD_LOAD( lib, name, success ) \
53 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
56 class wxGnomePrintLibrary
59 wxGnomePrintLibrary();
60 ~wxGnomePrintLibrary();
63 void InitializeMethods();
67 wxDynamicLibrary
*m_gnome_print_lib
;
68 wxDynamicLibrary
*m_gnome_printui_lib
;
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 )
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 )
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 )
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 )
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 )
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
), /**/ )
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 )
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 )
141 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
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 )
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 )
163 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
164 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
166 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
167 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
170 wxGnomePrintLibrary::wxGnomePrintLibrary()
172 m_gnome_print_lib
= NULL
;
173 m_gnome_printui_lib
= NULL
;
177 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
178 m_ok
= m_gnome_print_lib
->IsLoaded();
181 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
182 m_ok
= m_gnome_printui_lib
->IsLoaded();
188 wxGnomePrintLibrary::~wxGnomePrintLibrary()
190 if (m_gnome_print_lib
)
191 delete m_gnome_print_lib
;
192 if (m_gnome_printui_lib
)
193 delete m_gnome_printui_lib
;
196 bool wxGnomePrintLibrary::IsOk()
201 void wxGnomePrintLibrary::InitializeMethods()
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
)
218 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
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
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
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
)
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
)
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
)
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
)
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
)
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
)
256 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
258 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
263 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
265 //----------------------------------------------------------------------------
266 // wxGnomePrintNativeData
267 //----------------------------------------------------------------------------
269 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
271 wxGnomePrintNativeData::wxGnomePrintNativeData()
273 m_config
= gs_lgp
->gnome_print_config_default();
274 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
277 wxGnomePrintNativeData::~wxGnomePrintNativeData()
279 g_object_unref (G_OBJECT (m_config
));
282 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
288 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
294 //----------------------------------------------------------------------------
295 // wxGnomePrintFactory
296 //----------------------------------------------------------------------------
298 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
300 return new wxGnomePrinter( data
);
303 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
304 wxPrintout
*printout
,
305 wxPrintDialogData
*data
)
307 return new wxPostScriptPrintPreview( preview
, printout
, data
);
310 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
311 wxPrintout
*printout
,
314 return new wxPostScriptPrintPreview( preview
, printout
, data
);
317 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
318 wxPrintDialogData
*data
)
320 return new wxGnomePrintDialog( parent
, data
);
323 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
326 return new wxGnomePrintDialog( parent
, data
);
329 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
330 wxPageSetupDialogData
* data
)
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)
339 return new wxGnomePageSetupDialog( parent
, data
);
342 bool wxGnomePrintFactory::HasPrintSetupDialog()
347 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
352 bool wxGnomePrintFactory::HasOwnPrintToFile()
357 bool wxGnomePrintFactory::HasPrinterLine()
362 wxString
wxGnomePrintFactory::CreatePrinterLine()
365 return wxEmptyString
;
368 bool wxGnomePrintFactory::HasStatusLine()
374 wxString
wxGnomePrintFactory::CreateStatusLine()
377 return wxEmptyString
;
380 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
382 return new wxGnomePrintNativeData
;
385 //----------------------------------------------------------------------------
386 // wxGnomePrintSetupDialog
387 //----------------------------------------------------------------------------
389 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
391 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
392 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
393 wxPoint(0, 0), wxSize(600, 600),
394 wxDEFAULT_DIALOG_STYLE
|
398 m_printDialogData
= *data
;
403 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
404 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
405 wxPoint(0, 0), wxSize(600, 600),
406 wxDEFAULT_DIALOG_STYLE
|
410 m_printDialogData
= *data
;
415 void wxGnomePrintDialog::Init()
417 wxPrintData data
= m_printDialogData
.GetPrintData();
419 wxGnomePrintNativeData
*native
=
420 (wxGnomePrintNativeData
*) data
.GetNativeData();
422 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
424 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
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
;
432 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
434 m_printDialogData
.GetMinPage(),
435 m_printDialogData
.GetMaxPage(),
440 wxGnomePrintDialog::~wxGnomePrintDialog()
445 int wxGnomePrintDialog::ShowModal()
447 // Transfer data from m_printDalogData to dialog here
449 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
451 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
453 gtk_widget_destroy(m_widget
);
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
);
465 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
467 case GNOME_PRINT_RANGE_SELECTION
:
468 m_printDialogData
.SetSelection( true );
470 case GNOME_PRINT_RANGE_ALL
:
471 m_printDialogData
.SetAllPages( true );
472 m_printDialogData
.SetFromPage( 0 );
473 m_printDialogData
.SetToPage( 9999 );
475 case GNOME_PRINT_RANGE_RANGE
:
478 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
479 m_printDialogData
.SetFromPage( start
);
480 m_printDialogData
.SetToPage( end
);
484 gtk_widget_destroy(m_widget
);
487 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
493 wxDC
*wxGnomePrintDialog::GetPrintDC()
499 bool wxGnomePrintDialog::Validate()
504 bool wxGnomePrintDialog::TransferDataToWindow()
509 bool wxGnomePrintDialog::TransferDataFromWindow()
514 //----------------------------------------------------------------------------
515 // wxGnomePageSetupDialog
516 //----------------------------------------------------------------------------
518 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
520 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
521 wxPageSetupDialogData
* data
)
524 m_pageDialogData
= *data
;
526 wxGnomePrintNativeData
*native
=
527 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
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" );
535 m_widget
= gtk_dialog_new();
537 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
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
);
544 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
546 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
548 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
549 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
550 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
553 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
557 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
561 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
563 return m_pageDialogData
;
566 int wxGnomePageSetupDialog::ShowModal()
568 wxGnomePrintNativeData
*native
=
569 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
570 GnomePrintConfig
*config
= native
->GetPrintConfig();
572 // Transfer data from m_pageDialogData to native dialog
574 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
576 if (ret
== GTK_RESPONSE_OK
)
578 // Transfer data back to m_pageDialogData
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
);
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
);
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)) );
612 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
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
);
628 gtk_widget_destroy( m_widget
);
634 bool wxGnomePageSetupDialog::Validate()
639 bool wxGnomePageSetupDialog::TransferDataToWindow()
644 bool wxGnomePageSetupDialog::TransferDataFromWindow()
649 //----------------------------------------------------------------------------
651 //----------------------------------------------------------------------------
653 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
655 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
656 wxPrinterBase( data
)
659 m_native_preview
= false;
662 wxGnomePrinter::~wxGnomePrinter()
666 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
670 sm_lastError
= wxPRINTER_ERROR
;
674 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
675 wxGnomePrintNativeData
*native
=
676 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
678 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
679 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
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
);
687 printout
->SetIsPreview(false);
689 if (m_printDialogData
.GetMinPage() < 1)
690 m_printDialogData
.SetMinPage(1);
691 if (m_printDialogData
.GetMaxPage() < 1)
692 m_printDialogData
.SetMaxPage(9999);
696 dc
= PrintDialog( parent
);
698 dc
= new wxGnomePrintDC( this );
700 if (m_native_preview
)
701 printout
->SetIsPreview(true);
705 gs_lgp
->gnome_print_job_close( job
);
706 g_object_unref (G_OBJECT (job
));
707 sm_lastError
= wxPRINTER_ERROR
;
711 wxSize ScreenPixels
= wxGetDisplaySize();
712 wxSize ScreenMM
= wxGetDisplaySizeMM();
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() );
723 printout
->SetPageSizePixels((int)w
, (int)h
);
724 dc
->GetSizeMM(&w
, &h
);
725 printout
->SetPageSizeMM((int)w
, (int)h
);
727 printout
->OnPreparePrinting();
729 // Get some parameters from the printout, if defined
730 int fromPage
, toPage
;
731 int minPage
, maxPage
;
732 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
736 gs_lgp
->gnome_print_job_close( job
);
737 g_object_unref (G_OBJECT (job
));
738 sm_lastError
= wxPRINTER_ERROR
;
742 printout
->OnBeginPrinting();
744 int minPageNum
= minPage
, maxPageNum
= maxPage
;
746 if ( !m_printDialogData
.GetAllPages() )
748 minPageNum
= m_printDialogData
.GetFromPage();
749 maxPageNum
= m_printDialogData
.GetToPage();
755 copyCount
<= m_printDialogData
.GetNoCopies();
758 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
760 wxLogError(_("Could not start printing."));
761 sm_lastError
= wxPRINTER_ERROR
;
766 for ( pn
= minPageNum
;
767 pn
<= maxPageNum
&& printout
->HasPage(pn
);
771 printout
->OnPrintPage(pn
);
775 printout
->OnEndDocument();
776 printout
->OnEndPrinting();
779 gs_lgp
->gnome_print_job_close( job
);
780 if (m_native_preview
)
782 wxString
title( _("Print preview") );
783 gtk_widget_show( gs_lgp
->gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
787 gs_lgp
->gnome_print_job_print( job
);
790 g_object_unref (G_OBJECT (job
));
793 return (sm_lastError
== wxPRINTER_NO_ERROR
);
796 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
798 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
799 int ret
= dialog
.ShowModal();
800 if (ret
== wxID_CANCEL
)
802 sm_lastError
= wxPRINTER_CANCELLED
;
806 m_native_preview
= ret
== wxID_PREVIEW
;
808 m_printDialogData
= dialog
.GetPrintDialogData();
809 return new wxGnomePrintDC( this );
812 bool wxGnomePrinter::Setup( wxWindow
*parent
)
817 //-----------------------------------------------------------------------------
819 //-----------------------------------------------------------------------------
821 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
823 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
827 m_gpc
= printer
->GetPrintContext();
829 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
830 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
836 m_signX
= 1; // default x-axis left to right
837 m_signY
= -1; // default y-axis bottom up -> top down
840 wxGnomePrintDC::~wxGnomePrintDC()
844 bool wxGnomePrintDC::Ok() const
849 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
854 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
859 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
861 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
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
);
869 CalcBoundingBox( x1
, y1
);
870 CalcBoundingBox( x2
, y2
);
873 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
877 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
881 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
882 double alpha1
, alpha2
;
883 if (x1
== x2
&& y1
== y2
)
891 alpha1
= alpha2
= 0.0;
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
;
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;
908 if (m_brush
.GetStyle() != wxTRANSPARENT
)
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 );
914 gs_lgp
->gnome_print_fill( m_gpc
);
917 if (m_pen
.GetStyle() != wxTRANSPARENT
)
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
);
925 gs_lgp
->gnome_print_stroke( m_gpc
);
928 CalcBoundingBox (x1
, y1
);
929 CalcBoundingBox (x2
, y2
);
930 CalcBoundingBox (xc
, yc
);
933 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
938 int xx
= XLOG2DEV(x
);
939 int yy
= YLOG2DEV(y
);
941 gs_lgp
->gnome_print_gsave( m_gpc
);
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
);
950 if (m_brush
.GetStyle () != wxTRANSPARENT
)
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
);
959 gs_lgp
->gnome_print_fill( m_gpc
);
962 if (m_pen
.GetStyle () != wxTRANSPARENT
)
966 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
967 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
969 gs_lgp
->gnome_print_stroke( m_gpc
);
972 gs_lgp
->gnome_print_grestore( m_gpc
);
974 CalcBoundingBox( x
, y
);
975 CalcBoundingBox( x
+w
, y
+h
);
978 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
982 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
984 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
991 for ( i
=0; i
<n
; i
++ )
992 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
994 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
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
) );
999 gs_lgp
->gnome_print_stroke ( m_gpc
);
1002 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1006 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1008 SetBrush( m_brush
);
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
) );
1016 for (i
= 1; i
< n
; i
++)
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
);
1023 gs_lgp
->gnome_print_closepath( m_gpc
);
1024 gs_lgp
->gnome_print_fill( m_gpc
);
1027 if (m_pen
.GetStyle () != wxTRANSPARENT
)
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
) );
1036 for (i
= 1; i
< n
; i
++)
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
);
1043 gs_lgp
->gnome_print_closepath( m_gpc
);
1044 gs_lgp
->gnome_print_stroke( m_gpc
);
1048 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1050 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1053 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1055 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1057 SetBrush( m_brush
);
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
);
1067 CalcBoundingBox( x
, y
);
1068 CalcBoundingBox( x
+ width
, y
+ height
);
1071 if (m_pen
.GetStyle () != wxTRANSPARENT
)
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
);
1083 CalcBoundingBox( x
, y
);
1084 CalcBoundingBox( x
+ width
, y
+ height
);
1088 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1090 wxCoord rad
= (wxCoord
) radius
;
1092 if (m_brush
.GetStyle() != wxTRANSPARENT
)
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
);
1120 CalcBoundingBox(x
,y
);
1121 CalcBoundingBox(x
+width
,y
+height
);
1124 if (m_pen
.GetStyle() != wxTRANSPARENT
)
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
);
1152 CalcBoundingBox(x
,y
);
1153 CalcBoundingBox(x
+width
,y
+height
);
1157 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1159 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1161 SetBrush( m_brush
);
1163 gs_lgp
->gnome_print_newpath( m_gpc
);
1164 gs_lgp
->gnome_print_moveto( m_gpc
,
1165 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
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) );
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) );
1178 gs_lgp
->gnome_print_closepath( m_gpc
);
1179 gs_lgp
->gnome_print_fill( m_gpc
);
1181 CalcBoundingBox( x
, y
);
1182 CalcBoundingBox( x
+ width
, y
+ height
);
1185 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1189 gs_lgp
->gnome_print_newpath( m_gpc
);
1190 gs_lgp
->gnome_print_moveto( m_gpc
,
1191 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
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) );
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) );
1204 gs_lgp
->gnome_print_closepath( m_gpc
);
1205 gs_lgp
->gnome_print_stroke( m_gpc
);
1207 CalcBoundingBox( x
, y
);
1208 CalcBoundingBox( x
+ width
, y
+ height
);
1213 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1217 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1220 wxList::compatibility_iterator node
= points
->GetFirst();
1221 p
= (wxPoint
*)node
->GetData();
1225 node
= node
->GetNext();
1226 p
= (wxPoint
*)node
->GetData();
1230 (double)(x1
+ c
) / 2;
1232 (double)(y1
+ d
) / 2;
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
) );
1238 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1239 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1241 node
= node
->GetNext();
1244 q
= (wxPoint
*)node
->GetData();
1252 x3
= (double)(x2
+ c
) / 2;
1253 y3
= (double)(y2
+ d
) / 2;
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
) );
1260 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1261 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1263 node
= node
->GetNext();
1266 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1268 gs_lgp
->gnome_print_stroke( m_gpc
);
1270 #endif // wxUSE_SPLINES
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
)
1276 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1278 // blit into a bitmap
1279 wxBitmap
bitmap( width
, height
);
1281 memDC
.SelectObject(bitmap
);
1282 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1283 memDC
.SelectObject(wxNullBitmap
);
1285 // draw bitmap. scaling and positioning is done there
1286 DrawBitmap( bitmap
, xdest
, ydest
);
1291 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1293 DoDrawBitmap( icon
, x
, y
, true );
1296 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1298 if (!bitmap
.Ok()) return;
1300 if (bitmap
.HasPixbuf())
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
);
1309 gs_lgp
->gnome_print_gsave( m_gpc
);
1311 matrix
[0] = XLOG2DEVREL(width
);
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 );
1320 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1322 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1323 gs_lgp
->gnome_print_grestore( m_gpc
);
1327 wxImage image
= bitmap
.ConvertToImage();
1329 if (!image
.Ok()) return;
1331 gs_lgp
->gnome_print_gsave( m_gpc
);
1333 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
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
);
1346 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1348 DoDrawRotatedText( text
, x
, y
, 0.0 );
1351 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1356 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1359 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1361 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1364 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1367 size_t datalen
= strlen((const char*)data
);
1368 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1372 PangoAttrList
*attrs
= pango_attr_list_new();
1373 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
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
);
1381 if (m_textForegroundColour
.Ok())
1383 unsigned char red
= m_textForegroundColour
.Red();
1384 unsigned char blue
= m_textForegroundColour
.Blue();
1385 unsigned char green
= m_textForegroundColour
.Green();
1387 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1389 double redPS
= (double)(red
) / 255.0;
1390 double bluePS
= (double)(blue
) / 255.0;
1391 double greenPS
= (double)(green
) / 255.0;
1393 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1396 m_currentBlue
= blue
;
1397 m_currentGreen
= green
;
1403 if (fabs(m_scaleY
- 1.0) > 0.00001)
1405 // If there is a user or actually any scale applied to
1406 // the device context, scale the font.
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
);
1414 // actually apply scaled font
1415 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1417 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1419 if ( m_backgroundMode
== wxSOLID
)
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());
1427 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1428 if (fabs(angle
) > 0.00001)
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
);
1437 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1440 // reset unscaled size
1441 pango_font_description_set_size( m_fontdesc
, oldSize
);
1443 // actually apply unscaled font
1444 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1448 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1450 if ( m_backgroundMode
== wxSOLID
)
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());
1458 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1459 if (fabs(angle
) > 0.00001)
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
);
1468 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1474 // undo underline attributes setting:
1475 pango_layout_set_attributes(m_layout
, NULL
);
1478 CalcBoundingBox (x
+ w
, y
+ h
);
1481 void wxGnomePrintDC::Clear()
1485 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1492 pango_font_description_free( m_fontdesc
);
1494 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1496 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1500 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1502 if (!pen
.Ok()) return;
1506 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
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};
1513 switch (m_pen
.GetStyle())
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;
1521 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1525 unsigned char red
= m_pen
.GetColour().Red();
1526 unsigned char blue
= m_pen
.GetColour().Blue();
1527 unsigned char green
= m_pen
.GetColour().Green();
1529 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1531 double redPS
= (double)(red
) / 255.0;
1532 double bluePS
= (double)(blue
) / 255.0;
1533 double greenPS
= (double)(green
) / 255.0;
1535 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1538 m_currentBlue
= blue
;
1539 m_currentGreen
= green
;
1543 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1545 if (!brush
.Ok()) return;
1550 unsigned char red
= m_brush
.GetColour().Red();
1551 unsigned char blue
= m_brush
.GetColour().Blue();
1552 unsigned char green
= m_brush
.GetColour().Green();
1556 // Anything not white is black
1557 if (! (red
== (unsigned char) 255 &&
1558 blue
== (unsigned char) 255 &&
1559 green
== (unsigned char) 255) )
1561 red
= (unsigned char) 0;
1562 green
= (unsigned char) 0;
1563 blue
= (unsigned char) 0;
1568 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1570 double redPS
= (double)(red
) / 255.0;
1571 double bluePS
= (double)(blue
) / 255.0;
1572 double greenPS
= (double)(green
) / 255.0;
1574 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1577 m_currentBlue
= blue
;
1578 m_currentGreen
= green
;
1582 void wxGnomePrintDC::SetLogicalFunction( int function
)
1586 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1590 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1594 void wxGnomePrintDC::DestroyClippingRegion()
1598 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1600 SetDeviceOrigin( 0,0 );
1605 void wxGnomePrintDC::EndDoc()
1607 gs_lgp
->gnome_print_end_doc( m_gpc
);
1610 void wxGnomePrintDC::StartPage()
1612 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1615 void wxGnomePrintDC::EndPage()
1617 gs_lgp
->gnome_print_showpage( m_gpc
);
1620 wxCoord
wxGnomePrintDC::GetCharHeight() const
1622 pango_layout_set_text( m_layout
, "H", 1 );
1625 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1630 wxCoord
wxGnomePrintDC::GetCharWidth() const
1632 pango_layout_set_text( m_layout
, "H", 1 );
1635 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1640 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1642 wxCoord
*externalLeading
,
1643 wxFont
*theFont
) const
1651 if ( externalLeading
)
1652 *externalLeading
= 0;
1659 // Set new font description
1661 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1663 // Set layout's text
1665 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1666 const char *dataUTF8
= (const char *)data
;
1668 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1671 if (width
) (*width
) = 0;
1672 if (height
) (*height
) = 0;
1675 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1676 const char *dataUTF8
= (const char *)data
;
1681 // hardly ideal, but what else can we do if conversion failed?
1685 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1688 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1691 *width
= (wxCoord
)(w
/ m_scaleX
);
1693 *height
= (wxCoord
)(h
/ m_scaleY
);
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
);
1702 // Reset old font description
1704 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1707 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1709 wxGnomePrintNativeData
*native
=
1710 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1712 // Query page size. This seems to omit the margins
1713 // right now, although it shouldn't
1715 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1718 *width
= (int) (pw
+ 0.5);
1720 *height
= (int) (ph
+ 0.5);
1723 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1725 wxGnomePrintNativeData
*native
=
1726 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1728 // This code assumes values in Pts.
1731 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
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
);
1741 *width
= (int) (pw
+ 0.5);
1743 *height
= (int) (ph
+ 0.5);
1746 wxSize
wxGnomePrintDC::GetPPI() const
1748 return wxSize(72,72);
1751 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1753 m_signX
= (xLeftRight
? 1 : -1);
1754 m_signY
= (yBottomUp
? 1 : -1);
1756 ComputeScaleAndOrigin();
1759 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1765 wxDC::SetDeviceOrigin( x
, h
-y
);
1768 void wxGnomePrintDC::SetResolution(int ppi
)
1772 int wxGnomePrintDC::GetResolution()
1778 class wxGnomePrintModule
: public wxModule
1781 wxGnomePrintModule() {}
1786 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1789 bool wxGnomePrintModule::OnInit()
1791 gs_lgp
= new wxGnomePrintLibrary
;
1793 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1797 void wxGnomePrintModule::OnExit()
1802 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1805 // wxUSE_LIBGNOMEPRINT