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
24 #include "wx/dcmemory.h"
28 #include "wx/module.h"
31 #include "wx/fontutil.h"
32 #include "wx/gtk/private.h"
33 #include "wx/dynlib.h"
35 #include <libgnomeprint/gnome-print.h>
36 #include <libgnomeprint/gnome-print-pango.h>
37 #include <libgnomeprint/gnome-print-config.h>
38 #include <libgnomeprintui/gnome-print-dialog.h>
39 #include <libgnomeprintui/gnome-print-job-preview.h>
40 #include <libgnomeprintui/gnome-print-paper-selector.h>
42 static const double RAD2DEG
= 180.0 / M_PI
;
44 #include "wx/html/forcelnk.h"
45 FORCE_LINK_ME(gnome_print
)
47 //----------------------------------------------------------------------------
48 // wxGnomePrintLibrary
49 //----------------------------------------------------------------------------
51 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
52 typedef rettype (* name ## Type) args ; \
53 name ## Type pfn_ ## name; \
55 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
57 #define wxDL_METHOD_LOAD( lib, name, success ) \
58 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
61 class wxGnomePrintLibrary
64 wxGnomePrintLibrary();
65 ~wxGnomePrintLibrary();
68 void InitializeMethods();
72 wxDynamicLibrary
*m_gnome_print_lib
;
73 wxDynamicLibrary
*m_gnome_printui_lib
;
76 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
77 (GnomePrintContext
*pc
), (pc
), 0 )
78 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
79 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
80 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
81 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
82 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
83 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
84 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
85 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
86 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
87 (GnomePrintContext
*pc
), (pc
), 0 )
88 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
89 (GnomePrintContext
*pc
), (pc
), 0 )
90 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
91 (GnomePrintContext
*pc
), (pc
), 0 )
92 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
93 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
94 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
95 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
96 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
97 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
99 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
100 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
101 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
102 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
104 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
105 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
106 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
107 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
108 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
109 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
110 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
111 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
113 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
114 (GnomePrintContext
*pc
), (pc
), 0 )
115 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
116 (GnomePrintContext
*pc
), (pc
), 0 )
118 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
119 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
120 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
121 (GnomePrintContext
*pc
), (pc
), 0 )
122 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
123 (GnomePrintContext
*pc
), (pc
), 0 )
125 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
126 (GnomePrintContext
*gpc
), (gpc
), NULL
)
127 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
128 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
130 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
131 (GnomePrintConfig
*config
), (config
), NULL
)
132 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
133 (GnomePrintJob
*job
), (job
), NULL
)
134 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
135 (GnomePrintJob
*job
), (job
), 0 )
136 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
137 (GnomePrintJob
*job
), (job
), 0 )
138 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
139 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
141 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
142 (const guchar
*abbreviation
), (abbreviation
), NULL
)
143 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
144 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
146 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
148 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
149 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
150 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
151 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
153 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
154 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
155 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
156 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
157 const guchar
*currentlabel
, const guchar
*rangelabel
),
158 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
159 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
160 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
161 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
162 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
163 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
164 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
165 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
166 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
168 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
169 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
171 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
172 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
175 wxGnomePrintLibrary::wxGnomePrintLibrary()
177 m_gnome_print_lib
= NULL
;
178 m_gnome_printui_lib
= NULL
;
182 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
183 m_ok
= m_gnome_print_lib
->IsLoaded();
186 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
187 m_ok
= m_gnome_printui_lib
->IsLoaded();
193 wxGnomePrintLibrary::~wxGnomePrintLibrary()
195 if (m_gnome_print_lib
)
196 delete m_gnome_print_lib
;
197 if (m_gnome_printui_lib
)
198 delete m_gnome_printui_lib
;
201 bool wxGnomePrintLibrary::IsOk()
206 void wxGnomePrintLibrary::InitializeMethods()
211 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
212 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
213 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
214 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
215 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_arcto
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
217 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
218 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
221 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
223 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
228 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_translate
, success
)
231 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
234 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
238 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
241 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
242 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
243 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
244 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
245 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
247 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
248 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
250 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
251 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
252 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
254 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
255 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
256 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
257 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
258 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
259 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
261 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
263 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
268 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
270 //----------------------------------------------------------------------------
271 // wxGnomePrintNativeData
272 //----------------------------------------------------------------------------
274 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
276 wxGnomePrintNativeData::wxGnomePrintNativeData()
278 m_config
= gs_lgp
->gnome_print_config_default();
279 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
282 wxGnomePrintNativeData::~wxGnomePrintNativeData()
284 g_object_unref (m_config
);
287 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
293 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
299 //----------------------------------------------------------------------------
300 // wxGnomePrintFactory
301 //----------------------------------------------------------------------------
303 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
305 return new wxGnomePrinter( data
);
308 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
309 wxPrintout
*printout
,
310 wxPrintDialogData
*data
)
312 return new wxPostScriptPrintPreview( preview
, printout
, data
);
315 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
316 wxPrintout
*printout
,
319 return new wxPostScriptPrintPreview( preview
, printout
, data
);
322 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
323 wxPrintDialogData
*data
)
325 return new wxGnomePrintDialog( parent
, data
);
328 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
331 return new wxGnomePrintDialog( parent
, data
);
334 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
335 wxPageSetupDialogData
* data
)
337 // The native page setup dialog is broken. It
338 // miscalculates newly entered values for the
339 // margins if you have not chose "points" but
340 // e.g. centimerters.
341 // This has been fixed in GNOME CVS (maybe
342 // fixed in libgnomeprintui 2.8.1)
344 return new wxGnomePageSetupDialog( parent
, data
);
347 bool wxGnomePrintFactory::HasPrintSetupDialog()
352 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
357 bool wxGnomePrintFactory::HasOwnPrintToFile()
362 bool wxGnomePrintFactory::HasPrinterLine()
367 wxString
wxGnomePrintFactory::CreatePrinterLine()
370 return wxEmptyString
;
373 bool wxGnomePrintFactory::HasStatusLine()
379 wxString
wxGnomePrintFactory::CreateStatusLine()
382 return wxEmptyString
;
385 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
387 return new wxGnomePrintNativeData
;
390 //----------------------------------------------------------------------------
391 // wxGnomePrintSetupDialog
392 //----------------------------------------------------------------------------
394 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
396 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
397 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
398 wxPoint(0, 0), wxSize(600, 600),
399 wxDEFAULT_DIALOG_STYLE
|
403 m_printDialogData
= *data
;
408 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
409 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
410 wxPoint(0, 0), wxSize(600, 600),
411 wxDEFAULT_DIALOG_STYLE
|
415 m_printDialogData
= *data
;
420 void wxGnomePrintDialog::Init()
422 wxPrintData data
= m_printDialogData
.GetPrintData();
424 wxGnomePrintNativeData
*native
=
425 (wxGnomePrintNativeData
*) data
.GetNativeData();
427 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
429 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
432 if (m_printDialogData
.GetEnableSelection())
433 flag
|= GNOME_PRINT_RANGE_SELECTION
;
434 if (m_printDialogData
.GetEnablePageNumbers())
435 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
437 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
439 m_printDialogData
.GetMinPage(),
440 m_printDialogData
.GetMaxPage(),
445 wxGnomePrintDialog::~wxGnomePrintDialog()
450 int wxGnomePrintDialog::ShowModal()
452 // Transfer data from m_printDalogData to dialog here
454 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
456 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
458 gtk_widget_destroy(m_widget
);
465 gboolean collate
= false;
466 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
467 m_printDialogData
.SetNoCopies( copies
);
468 m_printDialogData
.SetCollate( collate
);
470 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
472 case GNOME_PRINT_RANGE_SELECTION
:
473 m_printDialogData
.SetSelection( true );
475 case GNOME_PRINT_RANGE_ALL
:
476 m_printDialogData
.SetAllPages( true );
477 m_printDialogData
.SetFromPage( 0 );
478 m_printDialogData
.SetToPage( 9999 );
480 case GNOME_PRINT_RANGE_RANGE
:
483 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
484 m_printDialogData
.SetFromPage( start
);
485 m_printDialogData
.SetToPage( end
);
489 gtk_widget_destroy(m_widget
);
492 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
498 wxDC
*wxGnomePrintDialog::GetPrintDC()
504 bool wxGnomePrintDialog::Validate()
509 bool wxGnomePrintDialog::TransferDataToWindow()
514 bool wxGnomePrintDialog::TransferDataFromWindow()
519 //----------------------------------------------------------------------------
520 // wxGnomePageSetupDialog
521 //----------------------------------------------------------------------------
523 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
525 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
526 wxPageSetupDialogData
* data
)
529 m_pageDialogData
= *data
;
531 wxGnomePrintNativeData
*native
=
532 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
534 // This is required as the page setup dialog
535 // calculates wrong values otherwise.
536 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
537 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
538 (const guchar
*) "Pts" );
540 m_widget
= gtk_dialog_new();
542 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
544 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
545 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
546 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
547 gtk_widget_show (main
);
549 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
551 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
553 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
554 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
555 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
558 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
562 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
566 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
568 return m_pageDialogData
;
571 int wxGnomePageSetupDialog::ShowModal()
573 wxGnomePrintNativeData
*native
=
574 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
575 GnomePrintConfig
*config
= native
->GetPrintConfig();
577 // Transfer data from m_pageDialogData to native dialog
579 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
581 if (ret
== GTK_RESPONSE_OK
)
583 // Transfer data back to m_pageDialogData
585 // I don't know how querying the last parameter works
586 // I cannot test it as the dialog is currently broken
587 // anyways (it only works for points).
588 double ml
,mr
,mt
,mb
,pw
,ph
;
589 gs_lgp
->gnome_print_config_get_length (config
,
590 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
591 gs_lgp
->gnome_print_config_get_length (config
,
592 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
593 gs_lgp
->gnome_print_config_get_length (config
,
594 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
595 gs_lgp
->gnome_print_config_get_length (config
,
596 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
597 gs_lgp
->gnome_print_config_get_length (config
,
598 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
599 gs_lgp
->gnome_print_config_get_length (config
,
600 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
602 // This probably assumes that the user entered the
603 // values in Pts. Since that is the only the dialog
604 // works right now, we need to fix this later.
605 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
606 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
607 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
608 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
609 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
610 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
611 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
612 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
614 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
615 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
617 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
620 wxPrintf( wxT("paper %d %d, top margin %d\n"),
621 m_pageDialogData
.GetPaperSize().x
,
622 m_pageDialogData
.GetPaperSize().y
,
623 m_pageDialogData
.GetMarginTopLeft().x
);
633 gtk_widget_destroy( m_widget
);
639 bool wxGnomePageSetupDialog::Validate()
644 bool wxGnomePageSetupDialog::TransferDataToWindow()
649 bool wxGnomePageSetupDialog::TransferDataFromWindow()
654 //----------------------------------------------------------------------------
656 //----------------------------------------------------------------------------
658 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
660 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
661 wxPrinterBase( data
)
664 m_native_preview
= false;
667 wxGnomePrinter::~wxGnomePrinter()
671 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
675 sm_lastError
= wxPRINTER_ERROR
;
679 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
680 wxGnomePrintNativeData
*native
=
681 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
683 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
684 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
686 // The GnomePrintJob is temporarily stored in the
687 // native print data as the native print dialog
688 // needs to access it.
689 native
->SetPrintJob( job
);
692 printout
->SetIsPreview(false);
694 if (m_printDialogData
.GetMinPage() < 1)
695 m_printDialogData
.SetMinPage(1);
696 if (m_printDialogData
.GetMaxPage() < 1)
697 m_printDialogData
.SetMaxPage(9999);
701 dc
= PrintDialog( parent
);
703 dc
= new wxGnomePrintDC( this );
705 if (m_native_preview
)
706 printout
->SetIsPreview(true);
710 gs_lgp
->gnome_print_job_close( job
);
711 g_object_unref (job
);
712 sm_lastError
= wxPRINTER_ERROR
;
716 wxSize ScreenPixels
= wxGetDisplaySize();
717 wxSize ScreenMM
= wxGetDisplaySizeMM();
719 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
720 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
721 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
722 wxGnomePrintDC::GetResolution() );
728 printout
->SetPageSizePixels((int)w
, (int)h
);
729 dc
->GetSizeMM(&w
, &h
);
730 printout
->SetPageSizeMM((int)w
, (int)h
);
732 printout
->OnPreparePrinting();
734 // Get some parameters from the printout, if defined
735 int fromPage
, toPage
;
736 int minPage
, maxPage
;
737 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
741 gs_lgp
->gnome_print_job_close( job
);
742 g_object_unref (job
);
743 sm_lastError
= wxPRINTER_ERROR
;
747 printout
->OnBeginPrinting();
749 int minPageNum
= minPage
, maxPageNum
= maxPage
;
751 if ( !m_printDialogData
.GetAllPages() )
753 minPageNum
= m_printDialogData
.GetFromPage();
754 maxPageNum
= m_printDialogData
.GetToPage();
760 copyCount
<= m_printDialogData
.GetNoCopies();
763 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
765 wxLogError(_("Could not start printing."));
766 sm_lastError
= wxPRINTER_ERROR
;
771 for ( pn
= minPageNum
;
772 pn
<= maxPageNum
&& printout
->HasPage(pn
);
776 printout
->OnPrintPage(pn
);
780 printout
->OnEndDocument();
781 printout
->OnEndPrinting();
784 gs_lgp
->gnome_print_job_close( job
);
785 if (m_native_preview
)
787 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
788 GtkWidget
*preview
= gs_lgp
->gnome_print_job_preview_new
791 (const guchar
*)title
.data()
793 gtk_widget_show(preview
);
797 gs_lgp
->gnome_print_job_print( job
);
800 g_object_unref (job
);
803 return (sm_lastError
== wxPRINTER_NO_ERROR
);
806 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
808 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
809 int ret
= dialog
.ShowModal();
810 if (ret
== wxID_CANCEL
)
812 sm_lastError
= wxPRINTER_CANCELLED
;
816 m_native_preview
= ret
== wxID_PREVIEW
;
818 m_printDialogData
= dialog
.GetPrintDialogData();
819 return new wxGnomePrintDC( this );
822 bool wxGnomePrinter::Setup( wxWindow
*parent
)
827 //-----------------------------------------------------------------------------
829 //-----------------------------------------------------------------------------
831 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
833 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
837 m_gpc
= printer
->GetPrintContext();
839 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
840 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
846 m_signX
= 1; // default x-axis left to right
847 m_signY
= -1; // default y-axis bottom up -> top down
850 wxGnomePrintDC::~wxGnomePrintDC()
854 bool wxGnomePrintDC::IsOk() const
859 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
864 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
869 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
871 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
875 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
876 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
877 gs_lgp
->gnome_print_stroke ( m_gpc
);
879 CalcBoundingBox( x1
, y1
);
880 CalcBoundingBox( x2
, y2
);
883 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
887 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
891 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
892 double alpha1
, alpha2
;
893 if (x1
== x2
&& y1
== y2
)
901 alpha1
= alpha2
= 0.0;
905 alpha1
= (x1
- xc
== 0) ?
906 (y1
- yc
< 0) ? 90.0 : -90.0 :
907 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
908 alpha2
= (x2
- xc
== 0) ?
909 (y2
- yc
< 0) ? 90.0 : -90.0 :
910 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
912 while (alpha1
<= 0) alpha1
+= 360;
913 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
914 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
915 while (alpha2
> 360) alpha2
-= 360;
918 if (m_brush
.GetStyle() != wxTRANSPARENT
)
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 );
924 gs_lgp
->gnome_print_fill( m_gpc
);
927 if (m_pen
.GetStyle() != wxTRANSPARENT
)
930 gs_lgp
->gnome_print_newpath( m_gpc
);
931 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
932 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
933 gs_lgp
->gnome_print_closepath( m_gpc
);
935 gs_lgp
->gnome_print_stroke( m_gpc
);
938 CalcBoundingBox (x1
, y1
);
939 CalcBoundingBox (x2
, y2
);
940 CalcBoundingBox (xc
, yc
);
943 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
948 int xx
= XLOG2DEV(x
);
949 int yy
= YLOG2DEV(y
);
951 gs_lgp
->gnome_print_gsave( m_gpc
);
953 gs_lgp
->gnome_print_translate( m_gpc
, xx
, yy
);
954 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
955 gs_lgp
->gnome_print_scale( m_gpc
, 1.0, scale
);
960 if (m_brush
.GetStyle () != wxTRANSPARENT
)
964 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
965 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
966 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
967 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
969 gs_lgp
->gnome_print_fill( m_gpc
);
972 if (m_pen
.GetStyle () != wxTRANSPARENT
)
976 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
977 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
979 gs_lgp
->gnome_print_stroke( m_gpc
);
982 gs_lgp
->gnome_print_grestore( m_gpc
);
984 CalcBoundingBox( x
, y
);
985 CalcBoundingBox( x
+w
, y
+h
);
988 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
992 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
994 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1001 for ( i
=0; i
<n
; i
++ )
1002 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1004 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1006 for (i
= 1; i
< n
; i
++)
1007 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1009 gs_lgp
->gnome_print_stroke ( m_gpc
);
1012 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1016 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1018 SetBrush( m_brush
);
1020 int x
= points
[0].x
+ xoffset
;
1021 int y
= points
[0].y
+ yoffset
;
1022 CalcBoundingBox( x
, y
);
1023 gs_lgp
->gnome_print_newpath( m_gpc
);
1024 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1026 for (i
= 1; i
< n
; i
++)
1028 int x
= points
[i
].x
+ xoffset
;
1029 int y
= points
[i
].y
+ yoffset
;
1030 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1031 CalcBoundingBox( x
, y
);
1033 gs_lgp
->gnome_print_closepath( m_gpc
);
1034 gs_lgp
->gnome_print_fill( m_gpc
);
1037 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1041 int x
= points
[0].x
+ xoffset
;
1042 int y
= points
[0].y
+ yoffset
;
1043 gs_lgp
->gnome_print_newpath( m_gpc
);
1044 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1046 for (i
= 1; i
< n
; i
++)
1048 int x
= points
[i
].x
+ xoffset
;
1049 int y
= points
[i
].y
+ yoffset
;
1050 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1051 CalcBoundingBox( x
, y
);
1053 gs_lgp
->gnome_print_closepath( m_gpc
);
1054 gs_lgp
->gnome_print_stroke( m_gpc
);
1058 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1060 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1063 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1065 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1067 SetBrush( m_brush
);
1069 gs_lgp
->gnome_print_newpath( m_gpc
);
1070 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1071 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1072 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1073 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1074 gs_lgp
->gnome_print_closepath( m_gpc
);
1075 gs_lgp
->gnome_print_fill( m_gpc
);
1077 CalcBoundingBox( x
, y
);
1078 CalcBoundingBox( x
+ width
, y
+ height
);
1081 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1085 gs_lgp
->gnome_print_newpath( m_gpc
);
1086 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1087 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1088 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1089 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1090 gs_lgp
->gnome_print_closepath( m_gpc
);
1091 gs_lgp
->gnome_print_stroke( m_gpc
);
1093 CalcBoundingBox( x
, y
);
1094 CalcBoundingBox( x
+ width
, y
+ height
);
1098 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1100 wxCoord rad
= (wxCoord
) radius
;
1102 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1105 gs_lgp
->gnome_print_newpath(m_gpc
);
1106 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1107 gs_lgp
->gnome_print_curveto(m_gpc
,
1108 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1109 XLOG2DEV(x
),YLOG2DEV(y
),
1110 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1111 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1112 gs_lgp
->gnome_print_curveto(m_gpc
,
1113 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1114 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1115 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1116 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1117 gs_lgp
->gnome_print_curveto(m_gpc
,
1118 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1119 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1120 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1121 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1122 gs_lgp
->gnome_print_curveto(m_gpc
,
1123 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1124 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1125 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1126 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1127 gs_lgp
->gnome_print_closepath(m_gpc
);
1128 gs_lgp
->gnome_print_fill(m_gpc
);
1130 CalcBoundingBox(x
,y
);
1131 CalcBoundingBox(x
+width
,y
+height
);
1134 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1137 gs_lgp
->gnome_print_newpath(m_gpc
);
1138 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1139 gs_lgp
->gnome_print_curveto(m_gpc
,
1140 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1141 XLOG2DEV(x
),YLOG2DEV(y
),
1142 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1143 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1144 gs_lgp
->gnome_print_curveto(m_gpc
,
1145 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1146 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1147 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1148 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1149 gs_lgp
->gnome_print_curveto(m_gpc
,
1150 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1151 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1152 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1153 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1154 gs_lgp
->gnome_print_curveto(m_gpc
,
1155 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1156 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1157 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1158 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1159 gs_lgp
->gnome_print_closepath(m_gpc
);
1160 gs_lgp
->gnome_print_stroke(m_gpc
);
1162 CalcBoundingBox(x
,y
);
1163 CalcBoundingBox(x
+width
,y
+height
);
1167 void wxGnomePrintDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1168 wxCoord width
, wxCoord height
)
1170 double r
= 4 * (sqrt (2) - 1) / 3;
1171 double halfW
= 0.5 * width
,
1172 halfH
= 0.5 * height
,
1175 wxCoord halfWI
= (wxCoord
) halfW
,
1176 halfHI
= (wxCoord
) halfH
;
1178 gs_lgp
->gnome_print_newpath( m_gpc
);
1180 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1181 gs_lgp
->gnome_print_moveto( m_gpc
,
1182 XLOG2DEV(x
+ width
),
1183 YLOG2DEV(y
+ halfHI
) );
1184 gs_lgp
->gnome_print_curveto( m_gpc
,
1185 XLOG2DEV(x
+ width
),
1186 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1187 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1188 YLOG2DEV(y
+ height
),
1189 XLOG2DEV(x
+ halfWI
),
1190 YLOG2DEV(y
+ height
) );
1191 gs_lgp
->gnome_print_curveto( m_gpc
,
1192 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1193 YLOG2DEV(y
+ height
),
1195 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1196 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1197 gs_lgp
->gnome_print_curveto( m_gpc
,
1199 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1200 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1202 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1203 gs_lgp
->gnome_print_curveto( m_gpc
,
1204 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1206 XLOG2DEV(x
+ width
),
1207 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1208 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1210 gs_lgp
->gnome_print_closepath(m_gpc
);
1213 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1215 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1217 SetBrush( m_brush
);
1218 makeEllipticalPath( x
, y
, width
, height
);
1219 gs_lgp
->gnome_print_fill( m_gpc
);
1220 CalcBoundingBox( x
, y
);
1221 CalcBoundingBox( x
+ width
, y
+ height
);
1224 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1227 makeEllipticalPath( x
, y
, width
, height
);
1228 gs_lgp
->gnome_print_stroke( m_gpc
);
1229 CalcBoundingBox( x
, y
);
1230 CalcBoundingBox( x
+ width
, y
+ height
);
1235 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1239 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1242 wxList::compatibility_iterator node
= points
->GetFirst();
1243 p
= (wxPoint
*)node
->GetData();
1247 node
= node
->GetNext();
1248 p
= (wxPoint
*)node
->GetData();
1252 (double)(x1
+ c
) / 2;
1254 (double)(y1
+ d
) / 2;
1256 gs_lgp
->gnome_print_newpath( m_gpc
);
1257 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1258 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1260 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1261 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1263 node
= node
->GetNext();
1266 q
= (wxPoint
*)node
->GetData();
1274 x3
= (double)(x2
+ c
) / 2;
1275 y3
= (double)(y2
+ d
) / 2;
1277 gs_lgp
->gnome_print_curveto(m_gpc
,
1278 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1279 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1280 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1282 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1283 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1285 node
= node
->GetNext();
1288 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1290 gs_lgp
->gnome_print_stroke( m_gpc
);
1292 #endif // wxUSE_SPLINES
1294 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1295 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1296 wxCoord xsrcMask
, wxCoord ysrcMask
)
1298 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1300 // blit into a bitmap
1301 wxBitmap
bitmap( width
, height
);
1303 memDC
.SelectObject(bitmap
);
1304 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1305 memDC
.SelectObject(wxNullBitmap
);
1307 // draw bitmap. scaling and positioning is done there
1308 DrawBitmap( bitmap
, xdest
, ydest
);
1313 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1315 DoDrawBitmap( icon
, x
, y
, true );
1318 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1320 if (!bitmap
.Ok()) return;
1322 if (bitmap
.HasPixbuf())
1324 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1325 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1326 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1327 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1328 int height
= gdk_pixbuf_get_height( pixbuf
);
1329 int width
= gdk_pixbuf_get_width( pixbuf
);
1331 gs_lgp
->gnome_print_gsave( m_gpc
);
1333 matrix
[0] = XLOG2DEVREL(width
);
1336 matrix
[3] = YLOG2DEVREL(height
);
1337 matrix
[4] = XLOG2DEV(x
);
1338 matrix
[5] = YLOG2DEV(y
+height
);
1339 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1340 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1342 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1344 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1345 gs_lgp
->gnome_print_grestore( m_gpc
);
1349 wxImage image
= bitmap
.ConvertToImage();
1351 if (!image
.Ok()) return;
1353 gs_lgp
->gnome_print_gsave( m_gpc
);
1355 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1358 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1359 matrix
[4] = XLOG2DEV(x
);
1360 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1361 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1362 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1363 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1364 gs_lgp
->gnome_print_grestore( m_gpc
);
1368 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1370 DoDrawRotatedText( text
, x
, y
, 0.0 );
1373 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1378 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1381 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1383 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1386 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1389 size_t datalen
= strlen((const char*)data
);
1390 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1394 PangoAttrList
*attrs
= pango_attr_list_new();
1395 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1397 a
->end_index
= datalen
;
1398 pango_attr_list_insert(attrs
, a
);
1399 pango_layout_set_attributes(m_layout
, attrs
);
1400 pango_attr_list_unref(attrs
);
1403 if (m_textForegroundColour
.Ok())
1405 unsigned char red
= m_textForegroundColour
.Red();
1406 unsigned char blue
= m_textForegroundColour
.Blue();
1407 unsigned char green
= m_textForegroundColour
.Green();
1409 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1411 double redPS
= (double)(red
) / 255.0;
1412 double bluePS
= (double)(blue
) / 255.0;
1413 double greenPS
= (double)(green
) / 255.0;
1415 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1418 m_currentBlue
= blue
;
1419 m_currentGreen
= green
;
1425 if (fabs(m_scaleY
- 1.0) > 0.00001)
1427 // If there is a user or actually any scale applied to
1428 // the device context, scale the font.
1430 // scale font description
1431 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1432 double size
= oldSize
;
1433 size
= size
* m_scaleY
;
1434 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1436 // actually apply scaled font
1437 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1439 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1441 if ( m_backgroundMode
== wxSOLID
)
1443 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1444 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1445 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1449 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1450 if (fabs(angle
) > 0.00001)
1452 gs_lgp
->gnome_print_gsave( m_gpc
);
1453 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1454 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1455 gs_lgp
->gnome_print_grestore( m_gpc
);
1459 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1462 // reset unscaled size
1463 pango_font_description_set_size( m_fontdesc
, oldSize
);
1465 // actually apply unscaled font
1466 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1470 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1472 if ( m_backgroundMode
== wxSOLID
)
1474 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1475 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1476 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1480 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1481 if (fabs(angle
) > 0.00001)
1483 gs_lgp
->gnome_print_gsave( m_gpc
);
1484 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1485 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1486 gs_lgp
->gnome_print_grestore( m_gpc
);
1490 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1496 // undo underline attributes setting:
1497 pango_layout_set_attributes(m_layout
, NULL
);
1500 CalcBoundingBox (x
+ w
, y
+ h
);
1503 void wxGnomePrintDC::Clear()
1507 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1514 pango_font_description_free( m_fontdesc
);
1516 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1518 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1522 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1524 if (!pen
.Ok()) return;
1528 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1530 static const double dotted
[] = {2.0, 5.0};
1531 static const double short_dashed
[] = {4.0, 4.0};
1532 static const double wxCoord_dashed
[] = {4.0, 8.0};
1533 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1535 switch (m_pen
.GetStyle())
1537 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1538 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1539 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1540 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1543 // It may be noted that libgnomeprint between at least
1544 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1545 // and then leak the memory since it doesn't set the
1546 // internal flag "privatedash" to 0.
1548 int num
= m_pen
.GetDashes (&wx_dashes
);
1549 gdouble
*g_dashes
= g_new( gdouble
, num
);
1551 for (i
= 0; i
< num
; ++i
)
1552 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1553 gs_lgp
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1559 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1563 unsigned char red
= m_pen
.GetColour().Red();
1564 unsigned char blue
= m_pen
.GetColour().Blue();
1565 unsigned char green
= m_pen
.GetColour().Green();
1567 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1569 double redPS
= (double)(red
) / 255.0;
1570 double bluePS
= (double)(blue
) / 255.0;
1571 double greenPS
= (double)(green
) / 255.0;
1573 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1576 m_currentBlue
= blue
;
1577 m_currentGreen
= green
;
1581 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1583 if (!brush
.Ok()) return;
1588 unsigned char red
= m_brush
.GetColour().Red();
1589 unsigned char blue
= m_brush
.GetColour().Blue();
1590 unsigned char green
= m_brush
.GetColour().Green();
1594 // Anything not white is black
1595 if (! (red
== (unsigned char) 255 &&
1596 blue
== (unsigned char) 255 &&
1597 green
== (unsigned char) 255) )
1599 red
= (unsigned char) 0;
1600 green
= (unsigned char) 0;
1601 blue
= (unsigned char) 0;
1606 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1608 double redPS
= (double)(red
) / 255.0;
1609 double bluePS
= (double)(blue
) / 255.0;
1610 double greenPS
= (double)(green
) / 255.0;
1612 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1615 m_currentBlue
= blue
;
1616 m_currentGreen
= green
;
1620 void wxGnomePrintDC::SetLogicalFunction( int function
)
1624 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1628 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1632 void wxGnomePrintDC::DestroyClippingRegion()
1636 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1638 SetDeviceOrigin( 0,0 );
1643 void wxGnomePrintDC::EndDoc()
1645 gs_lgp
->gnome_print_end_doc( m_gpc
);
1648 void wxGnomePrintDC::StartPage()
1650 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1653 void wxGnomePrintDC::EndPage()
1655 gs_lgp
->gnome_print_showpage( m_gpc
);
1658 wxCoord
wxGnomePrintDC::GetCharHeight() const
1660 pango_layout_set_text( m_layout
, "H", 1 );
1663 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1668 wxCoord
wxGnomePrintDC::GetCharWidth() const
1670 pango_layout_set_text( m_layout
, "H", 1 );
1673 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1678 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1680 wxCoord
*externalLeading
,
1681 wxFont
*theFont
) const
1689 if ( externalLeading
)
1690 *externalLeading
= 0;
1697 // Set new font description
1699 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1701 // Set layout's text
1703 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1704 const char *dataUTF8
= (const char *)data
;
1706 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1709 if (width
) (*width
) = 0;
1710 if (height
) (*height
) = 0;
1713 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1714 const char *dataUTF8
= (const char *)data
;
1719 // hardly ideal, but what else can we do if conversion failed?
1723 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1726 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1729 *width
= (wxCoord
)(w
/ m_scaleX
);
1731 *height
= (wxCoord
)(h
/ m_scaleY
);
1734 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1735 int baseline
= pango_layout_iter_get_baseline(iter
);
1736 pango_layout_iter_free(iter
);
1737 *descent
= h
- PANGO_PIXELS(baseline
);
1740 // Reset old font description
1742 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1745 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1747 wxGnomePrintNativeData
*native
=
1748 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1750 // Query page size. This seems to omit the margins
1751 // right now, although it shouldn't
1753 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1756 *width
= (int) (pw
+ 0.5);
1758 *height
= (int) (ph
+ 0.5);
1761 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1763 wxGnomePrintNativeData
*native
=
1764 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1766 // This code assumes values in Pts.
1769 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1773 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1774 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1775 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1776 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1779 *width
= (int) (pw
+ 0.5);
1781 *height
= (int) (ph
+ 0.5);
1784 wxSize
wxGnomePrintDC::GetPPI() const
1786 return wxSize(72,72);
1789 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1791 m_signX
= (xLeftRight
? 1 : -1);
1792 m_signY
= (yBottomUp
? 1 : -1);
1794 ComputeScaleAndOrigin();
1797 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1803 wxDC::SetDeviceOrigin( x
, h
-y
);
1806 void wxGnomePrintDC::SetResolution(int ppi
)
1810 int wxGnomePrintDC::GetResolution()
1816 class wxGnomePrintModule
: public wxModule
1819 wxGnomePrintModule() {}
1824 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1827 bool wxGnomePrintModule::OnInit()
1829 gs_lgp
= new wxGnomePrintLibrary
;
1831 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1835 void wxGnomePrintModule::OnExit()
1840 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1843 // wxUSE_LIBGNOMEPRINT