1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME printing support
6 // Copyright: Robert Roebling
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "gprint.h"
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
21 #include "wx/gtk/gnome/gprint.h"
23 #if wxUSE_LIBGNOMEPRINT
26 #include "wx/fontutil.h"
27 #include "wx/printdlg.h"
28 #include "wx/gtk/private.h"
29 #include "wx/module.h"
30 #include "wx/generic/prntdlgg.h"
31 #include "wx/dynlib.h"
33 #include <libgnomeprint/gnome-print.h>
34 #include <libgnomeprint/gnome-print-pango.h>
35 #include <libgnomeprint/gnome-print-config.h>
36 #include <libgnomeprintui/gnome-print-dialog.h>
37 #include <libgnomeprintui/gnome-print-job-preview.h>
38 #include <libgnomeprintui/gnome-print-paper-selector.h>
40 static const double RAD2DEG
= 180.0 / M_PI
;
42 #include "wx/html/forcelnk.h"
43 FORCE_LINK_ME(gnome_print
)
45 //----------------------------------------------------------------------------
46 // wxGnomePrintLibrary
47 //----------------------------------------------------------------------------
49 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
50 typedef rettype (* name ## Type) args ; \
51 name ## Type pfn_ ## name; \
53 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
55 #define wxDL_METHOD_LOAD( lib, name, success ) \
56 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
59 class wxGnomePrintLibrary
62 wxGnomePrintLibrary();
63 ~wxGnomePrintLibrary();
66 void InitializeMethods();
70 wxDynamicLibrary
*m_gnome_print_lib
;
71 wxDynamicLibrary
*m_gnome_printui_lib
;
74 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
75 (GnomePrintContext
*pc
), (pc
), 0 )
76 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
77 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
78 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
79 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
80 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
81 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
82 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
83 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
84 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
85 (GnomePrintContext
*pc
), (pc
), 0 )
86 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
87 (GnomePrintContext
*pc
), (pc
), 0 )
88 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
89 (GnomePrintContext
*pc
), (pc
), 0 )
90 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
91 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
92 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
93 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
94 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
95 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
97 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
98 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
99 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
100 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
102 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
103 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
104 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
105 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
106 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
107 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
108 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
109 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
111 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
112 (GnomePrintContext
*pc
), (pc
), 0 )
113 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
114 (GnomePrintContext
*pc
), (pc
), 0 )
116 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
117 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
118 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
119 (GnomePrintContext
*pc
), (pc
), 0 )
120 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
121 (GnomePrintContext
*pc
), (pc
), 0 )
123 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
124 (GnomePrintContext
*gpc
), (gpc
), NULL
)
125 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
126 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
128 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
129 (GnomePrintConfig
*config
), (config
), NULL
)
130 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
131 (GnomePrintJob
*job
), (job
), NULL
)
132 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
133 (GnomePrintJob
*job
), (job
), 0 )
134 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
135 (GnomePrintJob
*job
), (job
), 0 )
136 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
137 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
139 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
140 (const guchar
*abbreviation
), (abbreviation
), NULL
)
141 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
142 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
144 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
146 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
147 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
148 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
149 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
151 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
152 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
153 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
154 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
155 const guchar
*currentlabel
, const guchar
*rangelabel
),
156 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
157 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
158 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
159 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
160 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
161 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
162 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
163 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
164 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
166 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
167 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
169 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
170 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
173 wxGnomePrintLibrary::wxGnomePrintLibrary()
175 m_gnome_print_lib
= NULL
;
176 m_gnome_printui_lib
= NULL
;
180 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
181 m_ok
= m_gnome_print_lib
->IsLoaded();
184 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
185 m_ok
= m_gnome_printui_lib
->IsLoaded();
191 wxGnomePrintLibrary::~wxGnomePrintLibrary()
193 if (m_gnome_print_lib
)
194 delete m_gnome_print_lib
;
195 if (m_gnome_printui_lib
)
196 delete m_gnome_printui_lib
;
199 bool wxGnomePrintLibrary::IsOk()
204 void wxGnomePrintLibrary::InitializeMethods()
209 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
210 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
211 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
212 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
213 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_arcto
, success
)
214 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
215 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
217 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
218 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
221 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
222 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
225 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_translate
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
230 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
233 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
234 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
237 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
240 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
241 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
242 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
243 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
245 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
246 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
248 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
249 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
250 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
252 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
253 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
254 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
255 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
256 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
257 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
259 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
261 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
266 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
268 //----------------------------------------------------------------------------
269 // wxGnomePrintNativeData
270 //----------------------------------------------------------------------------
272 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
274 wxGnomePrintNativeData::wxGnomePrintNativeData()
276 m_config
= gs_lgp
->gnome_print_config_default();
277 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
280 wxGnomePrintNativeData::~wxGnomePrintNativeData()
282 g_object_unref (G_OBJECT (m_config
));
285 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
291 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
297 //----------------------------------------------------------------------------
298 // wxGnomePrintFactory
299 //----------------------------------------------------------------------------
301 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
303 return new wxGnomePrinter( data
);
306 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
307 wxPrintout
*printout
,
308 wxPrintDialogData
*data
)
310 return new wxPostScriptPrintPreview( preview
, printout
, data
);
313 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
314 wxPrintout
*printout
,
317 return new wxPostScriptPrintPreview( preview
, printout
, data
);
320 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
321 wxPrintDialogData
*data
)
323 return new wxGnomePrintDialog( parent
, data
);
326 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
329 return new wxGnomePrintDialog( parent
, data
);
332 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
333 wxPageSetupDialogData
* data
)
335 // The native page setup dialog is broken. It
336 // miscalculates newly entered values for the
337 // margins if you have not chose "points" but
338 // e.g. centimerters.
339 // This has been fixed in GNOME CVS (maybe
340 // fixed in libgnomeprintui 2.8.1)
342 return new wxGnomePageSetupDialog( parent
, data
);
345 bool wxGnomePrintFactory::HasPrintSetupDialog()
350 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
355 bool wxGnomePrintFactory::HasOwnPrintToFile()
360 bool wxGnomePrintFactory::HasPrinterLine()
365 wxString
wxGnomePrintFactory::CreatePrinterLine()
368 return wxEmptyString
;
371 bool wxGnomePrintFactory::HasStatusLine()
377 wxString
wxGnomePrintFactory::CreateStatusLine()
380 return wxEmptyString
;
383 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
385 return new wxGnomePrintNativeData
;
388 //----------------------------------------------------------------------------
389 // wxGnomePrintSetupDialog
390 //----------------------------------------------------------------------------
392 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
394 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
395 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
396 wxPoint(0, 0), wxSize(600, 600),
397 wxDEFAULT_DIALOG_STYLE
|
401 m_printDialogData
= *data
;
406 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
407 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
408 wxPoint(0, 0), wxSize(600, 600),
409 wxDEFAULT_DIALOG_STYLE
|
413 m_printDialogData
= *data
;
418 void wxGnomePrintDialog::Init()
420 wxPrintData data
= m_printDialogData
.GetPrintData();
422 wxGnomePrintNativeData
*native
=
423 (wxGnomePrintNativeData
*) data
.GetNativeData();
425 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
427 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
430 if (m_printDialogData
.GetEnableSelection())
431 flag
|= GNOME_PRINT_RANGE_SELECTION
;
432 if (m_printDialogData
.GetEnablePageNumbers())
433 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
435 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
437 m_printDialogData
.GetMinPage(),
438 m_printDialogData
.GetMaxPage(),
443 wxGnomePrintDialog::~wxGnomePrintDialog()
448 int wxGnomePrintDialog::ShowModal()
450 // Transfer data from m_printDalogData to dialog here
452 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
454 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
456 gtk_widget_destroy(m_widget
);
463 gboolean collate
= false;
464 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
465 m_printDialogData
.SetNoCopies( copies
);
466 m_printDialogData
.SetCollate( collate
);
468 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
470 case GNOME_PRINT_RANGE_SELECTION
:
471 m_printDialogData
.SetSelection( true );
473 case GNOME_PRINT_RANGE_ALL
:
474 m_printDialogData
.SetAllPages( true );
475 m_printDialogData
.SetFromPage( 0 );
476 m_printDialogData
.SetToPage( 9999 );
478 case GNOME_PRINT_RANGE_RANGE
:
481 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
482 m_printDialogData
.SetFromPage( start
);
483 m_printDialogData
.SetToPage( end
);
487 gtk_widget_destroy(m_widget
);
490 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
496 wxDC
*wxGnomePrintDialog::GetPrintDC()
502 bool wxGnomePrintDialog::Validate()
507 bool wxGnomePrintDialog::TransferDataToWindow()
512 bool wxGnomePrintDialog::TransferDataFromWindow()
517 //----------------------------------------------------------------------------
518 // wxGnomePageSetupDialog
519 //----------------------------------------------------------------------------
521 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
523 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
524 wxPageSetupDialogData
* data
)
527 m_pageDialogData
= *data
;
529 wxGnomePrintNativeData
*native
=
530 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
532 // This is required as the page setup dialog
533 // calculates wrong values otherwise.
534 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
535 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
536 (const guchar
*) "Pts" );
538 m_widget
= gtk_dialog_new();
540 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
542 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
543 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
544 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
545 gtk_widget_show (main
);
547 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
549 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
551 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
552 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
553 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
556 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
560 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
564 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
566 return m_pageDialogData
;
569 int wxGnomePageSetupDialog::ShowModal()
571 wxGnomePrintNativeData
*native
=
572 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
573 GnomePrintConfig
*config
= native
->GetPrintConfig();
575 // Transfer data from m_pageDialogData to native dialog
577 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
579 if (ret
== GTK_RESPONSE_OK
)
581 // Transfer data back to m_pageDialogData
583 // I don't know how querying the last parameter works
584 // I cannot test it as the dialog is currently broken
585 // anyways (it only works for points).
586 double ml
,mr
,mt
,mb
,pw
,ph
;
587 gs_lgp
->gnome_print_config_get_length (config
,
588 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
589 gs_lgp
->gnome_print_config_get_length (config
,
590 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
591 gs_lgp
->gnome_print_config_get_length (config
,
592 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
593 gs_lgp
->gnome_print_config_get_length (config
,
594 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
595 gs_lgp
->gnome_print_config_get_length (config
,
596 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
597 gs_lgp
->gnome_print_config_get_length (config
,
598 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
600 // This probably assumes that the user entered the
601 // values in Pts. Since that is the only the dialog
602 // works right now, we need to fix this later.
603 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
604 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
605 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
606 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
607 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
608 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
609 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
610 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
612 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
613 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
615 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
618 wxPrintf( wxT("paper %d %d, top margin %d\n"),
619 m_pageDialogData
.GetPaperSize().x
,
620 m_pageDialogData
.GetPaperSize().y
,
621 m_pageDialogData
.GetMarginTopLeft().x
);
631 gtk_widget_destroy( m_widget
);
637 bool wxGnomePageSetupDialog::Validate()
642 bool wxGnomePageSetupDialog::TransferDataToWindow()
647 bool wxGnomePageSetupDialog::TransferDataFromWindow()
652 //----------------------------------------------------------------------------
654 //----------------------------------------------------------------------------
656 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
658 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
659 wxPrinterBase( data
)
662 m_native_preview
= false;
665 wxGnomePrinter::~wxGnomePrinter()
669 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
673 sm_lastError
= wxPRINTER_ERROR
;
677 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
678 wxGnomePrintNativeData
*native
=
679 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
681 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
682 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
684 // The GnomePrintJob is temporarily stored in the
685 // native print data as the native print dialog
686 // needs to access it.
687 native
->SetPrintJob( job
);
690 printout
->SetIsPreview(false);
692 if (m_printDialogData
.GetMinPage() < 1)
693 m_printDialogData
.SetMinPage(1);
694 if (m_printDialogData
.GetMaxPage() < 1)
695 m_printDialogData
.SetMaxPage(9999);
699 dc
= PrintDialog( parent
);
701 dc
= new wxGnomePrintDC( this );
703 if (m_native_preview
)
704 printout
->SetIsPreview(true);
708 gs_lgp
->gnome_print_job_close( job
);
709 g_object_unref (G_OBJECT (job
));
710 sm_lastError
= wxPRINTER_ERROR
;
714 wxSize ScreenPixels
= wxGetDisplaySize();
715 wxSize ScreenMM
= wxGetDisplaySizeMM();
717 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
718 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
719 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
720 wxGnomePrintDC::GetResolution() );
726 printout
->SetPageSizePixels((int)w
, (int)h
);
727 dc
->GetSizeMM(&w
, &h
);
728 printout
->SetPageSizeMM((int)w
, (int)h
);
730 printout
->OnPreparePrinting();
732 // Get some parameters from the printout, if defined
733 int fromPage
, toPage
;
734 int minPage
, maxPage
;
735 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
739 gs_lgp
->gnome_print_job_close( job
);
740 g_object_unref (G_OBJECT (job
));
741 sm_lastError
= wxPRINTER_ERROR
;
745 printout
->OnBeginPrinting();
747 int minPageNum
= minPage
, maxPageNum
= maxPage
;
749 if ( !m_printDialogData
.GetAllPages() )
751 minPageNum
= m_printDialogData
.GetFromPage();
752 maxPageNum
= m_printDialogData
.GetToPage();
758 copyCount
<= m_printDialogData
.GetNoCopies();
761 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
763 wxLogError(_("Could not start printing."));
764 sm_lastError
= wxPRINTER_ERROR
;
769 for ( pn
= minPageNum
;
770 pn
<= maxPageNum
&& printout
->HasPage(pn
);
774 printout
->OnPrintPage(pn
);
778 printout
->OnEndDocument();
779 printout
->OnEndPrinting();
782 gs_lgp
->gnome_print_job_close( job
);
783 if (m_native_preview
)
785 wxString
title( _("Print preview") );
786 gtk_widget_show( gs_lgp
->gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
790 gs_lgp
->gnome_print_job_print( job
);
793 g_object_unref (G_OBJECT (job
));
796 return (sm_lastError
== wxPRINTER_NO_ERROR
);
799 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
801 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
802 int ret
= dialog
.ShowModal();
803 if (ret
== wxID_CANCEL
)
805 sm_lastError
= wxPRINTER_CANCELLED
;
809 m_native_preview
= ret
== wxID_PREVIEW
;
811 m_printDialogData
= dialog
.GetPrintDialogData();
812 return new wxGnomePrintDC( this );
815 bool wxGnomePrinter::Setup( wxWindow
*parent
)
820 //-----------------------------------------------------------------------------
822 //-----------------------------------------------------------------------------
824 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
826 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
830 m_gpc
= printer
->GetPrintContext();
832 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
833 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
839 m_signX
= 1; // default x-axis left to right
840 m_signY
= -1; // default y-axis bottom up -> top down
843 wxGnomePrintDC::~wxGnomePrintDC()
847 bool wxGnomePrintDC::Ok() const
852 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
857 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
862 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
864 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
868 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
869 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
870 gs_lgp
->gnome_print_stroke ( m_gpc
);
872 CalcBoundingBox( x1
, y1
);
873 CalcBoundingBox( x2
, y2
);
876 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
880 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
884 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
885 double alpha1
, alpha2
;
886 if (x1
== x2
&& y1
== y2
)
894 alpha1
= alpha2
= 0.0;
898 alpha1
= (x1
- xc
== 0) ?
899 (y1
- yc
< 0) ? 90.0 : -90.0 :
900 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
901 alpha2
= (x2
- xc
== 0) ?
902 (y2
- yc
< 0) ? 90.0 : -90.0 :
903 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
905 while (alpha1
<= 0) alpha1
+= 360;
906 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
907 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
908 while (alpha2
> 360) alpha2
-= 360;
911 if (m_brush
.GetStyle() != wxTRANSPARENT
)
914 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
915 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
917 gs_lgp
->gnome_print_fill( m_gpc
);
920 if (m_pen
.GetStyle() != wxTRANSPARENT
)
923 gs_lgp
->gnome_print_newpath( m_gpc
);
924 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
925 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
926 gs_lgp
->gnome_print_closepath( m_gpc
);
928 gs_lgp
->gnome_print_stroke( m_gpc
);
931 CalcBoundingBox (x1
, y1
);
932 CalcBoundingBox (x2
, y2
);
933 CalcBoundingBox (xc
, yc
);
936 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
941 int xx
= XLOG2DEV(x
);
942 int yy
= YLOG2DEV(y
);
944 gs_lgp
->gnome_print_gsave( m_gpc
);
946 gs_lgp
->gnome_print_translate( m_gpc
, xx
, yy
);
947 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
948 gs_lgp
->gnome_print_scale( m_gpc
, 1.0, scale
);
953 if (m_brush
.GetStyle () != wxTRANSPARENT
)
957 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
958 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
959 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
960 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
962 gs_lgp
->gnome_print_fill( m_gpc
);
965 if (m_pen
.GetStyle () != wxTRANSPARENT
)
969 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
970 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
972 gs_lgp
->gnome_print_stroke( m_gpc
);
975 gs_lgp
->gnome_print_grestore( m_gpc
);
977 CalcBoundingBox( x
, y
);
978 CalcBoundingBox( x
+w
, y
+h
);
981 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
985 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
987 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
994 for ( i
=0; i
<n
; i
++ )
995 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
997 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
999 for (i
= 1; i
< n
; i
++)
1000 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1002 gs_lgp
->gnome_print_stroke ( m_gpc
);
1005 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1009 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1011 SetBrush( m_brush
);
1013 int x
= points
[0].x
+ xoffset
;
1014 int y
= points
[0].y
+ yoffset
;
1015 CalcBoundingBox( x
, y
);
1016 gs_lgp
->gnome_print_newpath( m_gpc
);
1017 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1019 for (i
= 1; i
< n
; i
++)
1021 int x
= points
[i
].x
+ xoffset
;
1022 int y
= points
[i
].y
+ yoffset
;
1023 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1024 CalcBoundingBox( x
, y
);
1026 gs_lgp
->gnome_print_closepath( m_gpc
);
1027 gs_lgp
->gnome_print_fill( m_gpc
);
1030 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1034 int x
= points
[0].x
+ xoffset
;
1035 int y
= points
[0].y
+ yoffset
;
1036 gs_lgp
->gnome_print_newpath( m_gpc
);
1037 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1039 for (i
= 1; i
< n
; i
++)
1041 int x
= points
[i
].x
+ xoffset
;
1042 int y
= points
[i
].y
+ yoffset
;
1043 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1044 CalcBoundingBox( x
, y
);
1046 gs_lgp
->gnome_print_closepath( m_gpc
);
1047 gs_lgp
->gnome_print_stroke( m_gpc
);
1051 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1053 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1056 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1058 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1060 SetBrush( m_brush
);
1062 gs_lgp
->gnome_print_newpath( m_gpc
);
1063 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1064 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1065 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1066 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1067 gs_lgp
->gnome_print_closepath( m_gpc
);
1068 gs_lgp
->gnome_print_fill( m_gpc
);
1070 CalcBoundingBox( x
, y
);
1071 CalcBoundingBox( x
+ width
, y
+ height
);
1074 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1078 gs_lgp
->gnome_print_newpath( m_gpc
);
1079 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1080 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1081 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1082 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1083 gs_lgp
->gnome_print_closepath( m_gpc
);
1084 gs_lgp
->gnome_print_stroke( m_gpc
);
1086 CalcBoundingBox( x
, y
);
1087 CalcBoundingBox( x
+ width
, y
+ height
);
1091 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1093 wxCoord rad
= (wxCoord
) radius
;
1095 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1098 gs_lgp
->gnome_print_newpath(m_gpc
);
1099 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1100 gs_lgp
->gnome_print_curveto(m_gpc
,
1101 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1102 XLOG2DEV(x
),YLOG2DEV(y
),
1103 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1104 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1105 gs_lgp
->gnome_print_curveto(m_gpc
,
1106 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1107 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1108 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1109 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1110 gs_lgp
->gnome_print_curveto(m_gpc
,
1111 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1112 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1113 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1114 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1115 gs_lgp
->gnome_print_curveto(m_gpc
,
1116 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1117 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1118 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1119 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1120 gs_lgp
->gnome_print_closepath(m_gpc
);
1121 gs_lgp
->gnome_print_fill(m_gpc
);
1123 CalcBoundingBox(x
,y
);
1124 CalcBoundingBox(x
+width
,y
+height
);
1127 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1130 gs_lgp
->gnome_print_newpath(m_gpc
);
1131 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1132 gs_lgp
->gnome_print_curveto(m_gpc
,
1133 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1134 XLOG2DEV(x
),YLOG2DEV(y
),
1135 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1136 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1137 gs_lgp
->gnome_print_curveto(m_gpc
,
1138 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1139 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1140 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1141 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1142 gs_lgp
->gnome_print_curveto(m_gpc
,
1143 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1144 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1145 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1146 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1147 gs_lgp
->gnome_print_curveto(m_gpc
,
1148 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1149 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1150 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1151 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1152 gs_lgp
->gnome_print_closepath(m_gpc
);
1153 gs_lgp
->gnome_print_stroke(m_gpc
);
1155 CalcBoundingBox(x
,y
);
1156 CalcBoundingBox(x
+width
,y
+height
);
1160 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1162 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1164 SetBrush( m_brush
);
1166 gs_lgp
->gnome_print_newpath( m_gpc
);
1167 gs_lgp
->gnome_print_moveto( m_gpc
,
1168 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1170 // start with top half
1171 gs_lgp
->gnome_print_curveto( m_gpc
,
1172 XLOG2DEV(x
), YLOG2DEV(y
),
1173 XLOG2DEV(x
+width
), YLOG2DEV(y
),
1174 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
1176 gs_lgp
->gnome_print_curveto( m_gpc
,
1177 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
1178 XLOG2DEV(x
), YLOG2DEV(y
+height
),
1179 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1181 gs_lgp
->gnome_print_closepath( m_gpc
);
1182 gs_lgp
->gnome_print_fill( m_gpc
);
1184 CalcBoundingBox( x
, y
);
1185 CalcBoundingBox( x
+ width
, y
+ height
);
1188 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1192 gs_lgp
->gnome_print_newpath( m_gpc
);
1193 gs_lgp
->gnome_print_moveto( m_gpc
,
1194 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1196 // start with top half
1197 gs_lgp
->gnome_print_curveto( m_gpc
,
1198 XLOG2DEV(x
), YLOG2DEV(y
),
1199 XLOG2DEV(x
+width
), YLOG2DEV(y
),
1200 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
1202 gs_lgp
->gnome_print_curveto( m_gpc
,
1203 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
1204 XLOG2DEV(x
), YLOG2DEV(y
+height
),
1205 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1207 gs_lgp
->gnome_print_closepath( m_gpc
);
1208 gs_lgp
->gnome_print_stroke( m_gpc
);
1210 CalcBoundingBox( x
, y
);
1211 CalcBoundingBox( x
+ width
, y
+ height
);
1215 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1219 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1222 wxList::compatibility_iterator node
= points
->GetFirst();
1223 p
= (wxPoint
*)node
->GetData();
1227 node
= node
->GetNext();
1228 p
= (wxPoint
*)node
->GetData();
1232 (double)(x1
+ c
) / 2;
1234 (double)(y1
+ d
) / 2;
1236 gs_lgp
->gnome_print_newpath( m_gpc
);
1237 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1238 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1240 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1241 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1243 node
= node
->GetNext();
1246 q
= (wxPoint
*)node
->GetData();
1254 x3
= (double)(x2
+ c
) / 2;
1255 y3
= (double)(y2
+ d
) / 2;
1257 gs_lgp
->gnome_print_curveto(m_gpc
,
1258 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1259 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1260 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1262 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1263 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1265 node
= node
->GetNext();
1268 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1270 gs_lgp
->gnome_print_stroke( m_gpc
);
1273 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1274 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1275 wxCoord xsrcMask
, wxCoord ysrcMask
)
1277 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1279 // blit into a bitmap
1280 wxBitmap
bitmap( width
, height
);
1282 memDC
.SelectObject(bitmap
);
1283 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1284 memDC
.SelectObject(wxNullBitmap
);
1286 // draw bitmap. scaling and positioning is done there
1287 DrawBitmap( bitmap
, xdest
, ydest
);
1292 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1294 DoDrawBitmap( icon
, x
, y
, true );
1297 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1299 if (!bitmap
.Ok()) return;
1301 if (bitmap
.HasPixbuf())
1303 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1304 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1305 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1306 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1307 int height
= gdk_pixbuf_get_height( pixbuf
);
1308 int width
= gdk_pixbuf_get_width( pixbuf
);
1310 gs_lgp
->gnome_print_gsave( m_gpc
);
1312 matrix
[0] = XLOG2DEVREL(width
);
1315 matrix
[3] = YLOG2DEVREL(height
);
1316 matrix
[4] = XLOG2DEV(x
);
1317 matrix
[5] = YLOG2DEV(y
+height
);
1318 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1319 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1321 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1323 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1324 gs_lgp
->gnome_print_grestore( m_gpc
);
1328 wxImage image
= bitmap
.ConvertToImage();
1330 if (!image
.Ok()) return;
1332 gs_lgp
->gnome_print_gsave( m_gpc
);
1334 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1337 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1338 matrix
[4] = XLOG2DEV(x
);
1339 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1340 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1341 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1342 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1343 gs_lgp
->gnome_print_grestore( m_gpc
);
1347 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1349 DoDrawRotatedText( text
, x
, y
, 0.0 );
1352 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1357 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1360 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1362 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1365 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1368 size_t datalen
= strlen((const char*)data
);
1369 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1373 PangoAttrList
*attrs
= pango_attr_list_new();
1374 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1376 a
->end_index
= datalen
;
1377 pango_attr_list_insert(attrs
, a
);
1378 pango_layout_set_attributes(m_layout
, attrs
);
1379 pango_attr_list_unref(attrs
);
1382 if (m_textForegroundColour
.Ok())
1384 unsigned char red
= m_textForegroundColour
.Red();
1385 unsigned char blue
= m_textForegroundColour
.Blue();
1386 unsigned char green
= m_textForegroundColour
.Green();
1388 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1390 double redPS
= (double)(red
) / 255.0;
1391 double bluePS
= (double)(blue
) / 255.0;
1392 double greenPS
= (double)(green
) / 255.0;
1394 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1397 m_currentBlue
= blue
;
1398 m_currentGreen
= green
;
1404 if (fabs(m_scaleY
- 1.0) > 0.00001)
1406 // If there is a user or actually any scale applied to
1407 // the device context, scale the font.
1409 // scale font description
1410 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1411 double size
= oldSize
;
1412 size
= size
* m_scaleY
;
1413 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1415 // actually apply scaled font
1416 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1418 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1420 if ( m_backgroundMode
== wxSOLID
)
1422 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1423 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1424 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1428 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1429 if (fabs(angle
) > 0.00001)
1431 gs_lgp
->gnome_print_gsave( m_gpc
);
1432 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1433 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1434 gs_lgp
->gnome_print_grestore( m_gpc
);
1438 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1441 // reset unscaled size
1442 pango_font_description_set_size( m_fontdesc
, oldSize
);
1444 // actually apply unscaled font
1445 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1449 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1451 if ( m_backgroundMode
== wxSOLID
)
1453 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1454 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1455 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1459 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1460 if (fabs(angle
) > 0.00001)
1462 gs_lgp
->gnome_print_gsave( m_gpc
);
1463 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1464 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1465 gs_lgp
->gnome_print_grestore( m_gpc
);
1469 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1475 // undo underline attributes setting:
1476 pango_layout_set_attributes(m_layout
, NULL
);
1479 CalcBoundingBox (x
+ w
, y
+ h
);
1482 void wxGnomePrintDC::Clear()
1486 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1493 pango_font_description_free( m_fontdesc
);
1495 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1497 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1501 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1503 if (!pen
.Ok()) return;
1507 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1509 static const double dotted
[] = {2.0, 5.0};
1510 static const double short_dashed
[] = {4.0, 4.0};
1511 static const double wxCoord_dashed
[] = {4.0, 8.0};
1512 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1514 switch (m_pen
.GetStyle())
1516 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1517 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1518 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1519 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1522 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1526 unsigned char red
= m_pen
.GetColour().Red();
1527 unsigned char blue
= m_pen
.GetColour().Blue();
1528 unsigned char green
= m_pen
.GetColour().Green();
1530 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1532 double redPS
= (double)(red
) / 255.0;
1533 double bluePS
= (double)(blue
) / 255.0;
1534 double greenPS
= (double)(green
) / 255.0;
1536 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1539 m_currentBlue
= blue
;
1540 m_currentGreen
= green
;
1544 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1546 if (!brush
.Ok()) return;
1551 unsigned char red
= m_brush
.GetColour().Red();
1552 unsigned char blue
= m_brush
.GetColour().Blue();
1553 unsigned char green
= m_brush
.GetColour().Green();
1557 // Anything not white is black
1558 if (! (red
== (unsigned char) 255 &&
1559 blue
== (unsigned char) 255 &&
1560 green
== (unsigned char) 255) )
1562 red
= (unsigned char) 0;
1563 green
= (unsigned char) 0;
1564 blue
= (unsigned char) 0;
1569 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1571 double redPS
= (double)(red
) / 255.0;
1572 double bluePS
= (double)(blue
) / 255.0;
1573 double greenPS
= (double)(green
) / 255.0;
1575 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1578 m_currentBlue
= blue
;
1579 m_currentGreen
= green
;
1583 void wxGnomePrintDC::SetLogicalFunction( int function
)
1587 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1591 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1595 void wxGnomePrintDC::DestroyClippingRegion()
1599 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1601 SetDeviceOrigin( 0,0 );
1606 void wxGnomePrintDC::EndDoc()
1608 gs_lgp
->gnome_print_end_doc( m_gpc
);
1611 void wxGnomePrintDC::StartPage()
1613 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1616 void wxGnomePrintDC::EndPage()
1618 gs_lgp
->gnome_print_showpage( m_gpc
);
1621 wxCoord
wxGnomePrintDC::GetCharHeight() const
1623 pango_layout_set_text( m_layout
, "H", 1 );
1626 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1631 wxCoord
wxGnomePrintDC::GetCharWidth() const
1633 pango_layout_set_text( m_layout
, "H", 1 );
1636 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1641 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1643 wxCoord
*externalLeading
,
1644 wxFont
*theFont
) const
1652 if ( externalLeading
)
1653 *externalLeading
= 0;
1655 if (string
.IsEmpty())
1660 // Set new font description
1662 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1664 // Set layout's text
1666 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1667 const char *dataUTF8
= (const char *)data
;
1669 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1672 if (width
) (*width
) = 0;
1673 if (height
) (*height
) = 0;
1676 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1677 const char *dataUTF8
= (const char *)data
;
1682 // hardly ideal, but what else can we do if conversion failed?
1686 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1689 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1692 *width
= (wxCoord
)(w
/ m_scaleX
);
1694 *height
= (wxCoord
)(h
/ m_scaleY
);
1697 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1698 int baseline
= pango_layout_iter_get_baseline(iter
);
1699 pango_layout_iter_free(iter
);
1700 *descent
= h
- PANGO_PIXELS(baseline
);
1703 // Reset old font description
1705 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1708 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1710 wxGnomePrintNativeData
*native
=
1711 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1713 // Query page size. This seems to omit the margins
1714 // right now, although it shouldn't
1716 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1719 *width
= (int) (pw
+ 0.5);
1721 *height
= (int) (ph
+ 0.5);
1724 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1726 wxGnomePrintNativeData
*native
=
1727 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1729 // This code assumes values in Pts.
1732 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1736 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1737 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1738 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1739 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1742 *width
= (int) (pw
+ 0.5);
1744 *height
= (int) (ph
+ 0.5);
1747 wxSize
wxGnomePrintDC::GetPPI() const
1749 return wxSize(72,72);
1752 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1754 m_signX
= (xLeftRight
? 1 : -1);
1755 m_signY
= (yBottomUp
? 1 : -1);
1757 ComputeScaleAndOrigin();
1760 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1766 wxDC::SetDeviceOrigin( x
, h
-y
);
1769 void wxGnomePrintDC::SetResolution(int ppi
)
1773 int wxGnomePrintDC::GetResolution()
1779 class wxGnomePrintModule
: public wxModule
1782 wxGnomePrintModule() {}
1787 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1790 bool wxGnomePrintModule::OnInit()
1792 gs_lgp
= new wxGnomePrintLibrary
;
1794 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1798 void wxGnomePrintModule::OnExit()
1803 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1806 // wxUSE_LIBGNOMEPRINT