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>
41 #include "wx/html/forcelnk.h"
42 FORCE_LINK_ME(gnome_print
)
44 //----------------------------------------------------------------------------
45 // wxGnomePrintLibrary
46 //----------------------------------------------------------------------------
48 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
49 typedef rettype (* name ## Type) args ; \
50 name ## Type pfn_ ## name; \
52 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
54 #define wxDL_METHOD_LOAD( lib, name, success ) \
55 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
58 class wxGnomePrintLibrary
61 wxGnomePrintLibrary();
62 ~wxGnomePrintLibrary();
65 void InitializeMethods();
69 wxDynamicLibrary
*m_gnome_print_lib
;
70 wxDynamicLibrary
*m_gnome_printui_lib
;
73 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
74 (GnomePrintContext
*pc
), (pc
), 0 )
75 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
76 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
77 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
78 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
79 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
80 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
81 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
82 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
83 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
84 (GnomePrintContext
*pc
), (pc
), 0 )
85 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
86 (GnomePrintContext
*pc
), (pc
), 0 )
87 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
88 (GnomePrintContext
*pc
), (pc
), 0 )
89 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
90 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
91 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
92 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
93 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
94 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
96 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
97 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
98 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
99 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
101 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
102 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
103 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
104 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
105 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
106 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
107 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
108 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
110 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
111 (GnomePrintContext
*pc
), (pc
), 0 )
112 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
113 (GnomePrintContext
*pc
), (pc
), 0 )
115 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
116 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
117 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
118 (GnomePrintContext
*pc
), (pc
), 0 )
119 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
120 (GnomePrintContext
*pc
), (pc
), 0 )
122 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
123 (GnomePrintContext
*gpc
), (gpc
), NULL
)
124 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
125 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
127 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
128 (GnomePrintConfig
*config
), (config
), NULL
)
129 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
130 (GnomePrintJob
*job
), (job
), NULL
)
131 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
132 (GnomePrintJob
*job
), (job
), 0 )
133 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
134 (GnomePrintJob
*job
), (job
), 0 )
135 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
136 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
138 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
139 (const guchar
*abbreviation
), (abbreviation
), NULL
)
140 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
141 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
143 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
145 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
146 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
147 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
148 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
150 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
151 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
152 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
153 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
154 const guchar
*currentlabel
, const guchar
*rangelabel
),
155 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
156 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
157 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
158 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
159 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
160 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
161 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
162 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
163 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
165 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
166 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
168 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
169 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
172 wxGnomePrintLibrary::wxGnomePrintLibrary()
174 m_gnome_print_lib
= NULL
;
175 m_gnome_printui_lib
= NULL
;
179 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
180 m_ok
= m_gnome_print_lib
->IsLoaded();
183 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
184 m_ok
= m_gnome_printui_lib
->IsLoaded();
190 wxGnomePrintLibrary::~wxGnomePrintLibrary()
192 if (m_gnome_print_lib
)
193 delete m_gnome_print_lib
;
194 if (m_gnome_printui_lib
)
195 delete m_gnome_printui_lib
;
198 bool wxGnomePrintLibrary::IsOk()
203 void wxGnomePrintLibrary::InitializeMethods()
208 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
209 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
210 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
211 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
212 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_arcto
, success
)
213 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
214 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
215 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
217 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
218 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
221 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
223 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
225 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_translate
, success
)
228 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
231 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
233 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
238 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
240 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
241 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
242 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
244 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
245 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
247 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
248 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
249 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
251 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
252 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
253 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
254 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
255 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
256 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
258 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
260 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
265 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
267 //----------------------------------------------------------------------------
268 // wxGnomePrintNativeData
269 //----------------------------------------------------------------------------
271 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
273 wxGnomePrintNativeData::wxGnomePrintNativeData()
275 m_config
= gs_lgp
->gnome_print_config_default();
276 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
279 wxGnomePrintNativeData::~wxGnomePrintNativeData()
281 g_object_unref (G_OBJECT (m_config
));
284 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
290 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
296 //----------------------------------------------------------------------------
297 // wxGnomePrintFactory
298 //----------------------------------------------------------------------------
300 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
302 return new wxGnomePrinter( data
);
305 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
306 wxPrintout
*printout
,
307 wxPrintDialogData
*data
)
309 return new wxPostScriptPrintPreview( preview
, printout
, data
);
312 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
313 wxPrintout
*printout
,
316 return new wxPostScriptPrintPreview( preview
, printout
, data
);
319 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
320 wxPrintDialogData
*data
)
322 return new wxGnomePrintDialog( parent
, data
);
325 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
328 return new wxGnomePrintDialog( parent
, data
);
331 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
332 wxPageSetupDialogData
* data
)
334 // The native page setup dialog is broken. It
335 // miscalculates newly entered values for the
336 // margins if you have not chose "points" but
337 // e.g. centimerters.
338 // This has been fixed in GNOME CVS (maybe
339 // fixed in libgnomeprintui 2.8.1)
341 return new wxGnomePageSetupDialog( parent
, data
);
344 bool wxGnomePrintFactory::HasPrintSetupDialog()
349 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
354 bool wxGnomePrintFactory::HasOwnPrintToFile()
359 bool wxGnomePrintFactory::HasPrinterLine()
364 wxString
wxGnomePrintFactory::CreatePrinterLine()
367 return wxEmptyString
;
370 bool wxGnomePrintFactory::HasStatusLine()
376 wxString
wxGnomePrintFactory::CreateStatusLine()
379 return wxEmptyString
;
382 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
384 return new wxGnomePrintNativeData
;
387 //----------------------------------------------------------------------------
388 // wxGnomePrintSetupDialog
389 //----------------------------------------------------------------------------
391 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
393 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
394 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
395 wxPoint(0, 0), wxSize(600, 600),
396 wxDEFAULT_DIALOG_STYLE
|
400 m_printDialogData
= *data
;
405 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
406 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
407 wxPoint(0, 0), wxSize(600, 600),
408 wxDEFAULT_DIALOG_STYLE
|
412 m_printDialogData
= *data
;
417 void wxGnomePrintDialog::Init()
419 wxPrintData data
= m_printDialogData
.GetPrintData();
421 wxGnomePrintNativeData
*native
=
422 (wxGnomePrintNativeData
*) data
.GetNativeData();
424 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
426 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
429 if (m_printDialogData
.GetEnableSelection())
430 flag
|= GNOME_PRINT_RANGE_SELECTION
;
431 if (m_printDialogData
.GetEnablePageNumbers())
432 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
434 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
436 m_printDialogData
.GetMinPage(),
437 m_printDialogData
.GetMaxPage(),
442 wxGnomePrintDialog::~wxGnomePrintDialog()
447 int wxGnomePrintDialog::ShowModal()
449 // Transfer data from m_printDalogData to dialog here
451 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
453 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
455 gtk_widget_destroy(m_widget
);
462 gboolean collate
= false;
463 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
464 m_printDialogData
.SetNoCopies( copies
);
465 m_printDialogData
.SetCollate( collate
);
467 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
469 case GNOME_PRINT_RANGE_SELECTION
:
470 m_printDialogData
.SetSelection( true );
472 case GNOME_PRINT_RANGE_ALL
:
473 m_printDialogData
.SetAllPages( true );
474 m_printDialogData
.SetFromPage( 0 );
475 m_printDialogData
.SetToPage( 9999 );
477 case GNOME_PRINT_RANGE_RANGE
:
480 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
481 m_printDialogData
.SetFromPage( start
);
482 m_printDialogData
.SetToPage( end
);
486 gtk_widget_destroy(m_widget
);
489 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
495 wxDC
*wxGnomePrintDialog::GetPrintDC()
501 bool wxGnomePrintDialog::Validate()
506 bool wxGnomePrintDialog::TransferDataToWindow()
511 bool wxGnomePrintDialog::TransferDataFromWindow()
516 //----------------------------------------------------------------------------
517 // wxGnomePageSetupDialog
518 //----------------------------------------------------------------------------
520 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
522 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
523 wxPageSetupDialogData
* data
)
526 m_pageDialogData
= *data
;
528 wxGnomePrintNativeData
*native
=
529 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
531 // This is required as the page setup dialog
532 // calculates wrong values otherwise.
533 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
534 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
535 (const guchar
*) "Pts" );
537 m_widget
= gtk_dialog_new();
539 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
541 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
542 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
543 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
544 gtk_widget_show (main
);
546 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
548 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
550 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
551 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
552 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
555 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
559 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
563 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
565 return m_pageDialogData
;
568 int wxGnomePageSetupDialog::ShowModal()
570 wxGnomePrintNativeData
*native
=
571 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
572 GnomePrintConfig
*config
= native
->GetPrintConfig();
574 // Transfer data from m_pageDialogData to native dialog
576 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
578 if (ret
== GTK_RESPONSE_OK
)
580 // Transfer data back to m_pageDialogData
582 // I don't know how querying the last parameter works
583 // I cannot test it as the dialog is currently broken
584 // anyways (it only works for points).
585 double ml
,mr
,mt
,mb
,pw
,ph
;
586 gs_lgp
->gnome_print_config_get_length (config
,
587 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
588 gs_lgp
->gnome_print_config_get_length (config
,
589 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
590 gs_lgp
->gnome_print_config_get_length (config
,
591 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
592 gs_lgp
->gnome_print_config_get_length (config
,
593 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
594 gs_lgp
->gnome_print_config_get_length (config
,
595 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
596 gs_lgp
->gnome_print_config_get_length (config
,
597 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
599 // This probably assumes that the user entered the
600 // values in Pts. Since that is the only the dialog
601 // works right now, we need to fix this later.
602 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
603 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
604 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
605 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
606 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
607 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
608 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
609 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
611 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
612 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
614 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
617 wxPrintf( wxT("paper %d %d, top margin %d\n"),
618 m_pageDialogData
.GetPaperSize().x
,
619 m_pageDialogData
.GetPaperSize().y
,
620 m_pageDialogData
.GetMarginTopLeft().x
);
630 gtk_widget_destroy( m_widget
);
636 bool wxGnomePageSetupDialog::Validate()
641 bool wxGnomePageSetupDialog::TransferDataToWindow()
646 bool wxGnomePageSetupDialog::TransferDataFromWindow()
651 //----------------------------------------------------------------------------
653 //----------------------------------------------------------------------------
655 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
657 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
658 wxPrinterBase( data
)
661 m_native_preview
= false;
664 wxGnomePrinter::~wxGnomePrinter()
668 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
672 sm_lastError
= wxPRINTER_ERROR
;
676 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
677 wxGnomePrintNativeData
*native
=
678 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
680 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
681 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
683 // The GnomePrintJob is temporarily stored in the
684 // native print data as the native print dialog
685 // needs to access it.
686 native
->SetPrintJob( job
);
689 printout
->SetIsPreview(false);
691 if (m_printDialogData
.GetMinPage() < 1)
692 m_printDialogData
.SetMinPage(1);
693 if (m_printDialogData
.GetMaxPage() < 1)
694 m_printDialogData
.SetMaxPage(9999);
698 dc
= PrintDialog( parent
);
700 dc
= new wxGnomePrintDC( this );
702 if (m_native_preview
)
703 printout
->SetIsPreview(true);
707 gs_lgp
->gnome_print_job_close( job
);
708 g_object_unref (G_OBJECT (job
));
709 sm_lastError
= wxPRINTER_ERROR
;
713 wxSize ScreenPixels
= wxGetDisplaySize();
714 wxSize ScreenMM
= wxGetDisplaySizeMM();
716 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
717 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
718 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
719 wxGnomePrintDC::GetResolution() );
725 printout
->SetPageSizePixels((int)w
, (int)h
);
726 dc
->GetSizeMM(&w
, &h
);
727 printout
->SetPageSizeMM((int)w
, (int)h
);
729 printout
->OnPreparePrinting();
731 // Get some parameters from the printout, if defined
732 int fromPage
, toPage
;
733 int minPage
, maxPage
;
734 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
738 gs_lgp
->gnome_print_job_close( job
);
739 g_object_unref (G_OBJECT (job
));
740 sm_lastError
= wxPRINTER_ERROR
;
744 printout
->OnBeginPrinting();
746 int minPageNum
= minPage
, maxPageNum
= maxPage
;
748 if ( !m_printDialogData
.GetAllPages() )
750 minPageNum
= m_printDialogData
.GetFromPage();
751 maxPageNum
= m_printDialogData
.GetToPage();
757 copyCount
<= m_printDialogData
.GetNoCopies();
760 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
762 wxLogError(_("Could not start printing."));
763 sm_lastError
= wxPRINTER_ERROR
;
768 for ( pn
= minPageNum
;
769 pn
<= maxPageNum
&& printout
->HasPage(pn
);
773 printout
->OnPrintPage(pn
);
777 printout
->OnEndDocument();
778 printout
->OnEndPrinting();
781 gs_lgp
->gnome_print_job_close( job
);
782 if (m_native_preview
)
784 wxString
title( _("Print preview") );
785 gtk_widget_show( gs_lgp
->gnome_print_job_preview_new( job
, (const guchar
*)(const char*)wxGTK_CONV(title
) ));
789 gs_lgp
->gnome_print_job_print( job
);
792 g_object_unref (G_OBJECT (job
));
795 return (sm_lastError
== wxPRINTER_NO_ERROR
);
798 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
800 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
801 int ret
= dialog
.ShowModal();
802 if (ret
== wxID_CANCEL
)
804 sm_lastError
= wxPRINTER_CANCELLED
;
808 m_native_preview
= ret
== wxID_PREVIEW
;
810 m_printDialogData
= dialog
.GetPrintDialogData();
811 return new wxGnomePrintDC( this );
814 bool wxGnomePrinter::Setup( wxWindow
*parent
)
819 //-----------------------------------------------------------------------------
821 //-----------------------------------------------------------------------------
823 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
825 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
829 m_gpc
= printer
->GetPrintContext();
831 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
832 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
838 m_signX
= 1; // default x-axis left to right
839 m_signY
= -1; // default y-axis bottom up -> top down
842 wxGnomePrintDC::~wxGnomePrintDC()
846 bool wxGnomePrintDC::Ok() const
851 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
856 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
861 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
863 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
867 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
868 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
869 gs_lgp
->gnome_print_stroke ( m_gpc
);
871 CalcBoundingBox( x1
, y1
);
872 CalcBoundingBox( x2
, y2
);
875 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
879 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
883 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
888 int xx
= XLOG2DEV(x
);
889 int yy
= YLOG2DEV(y
);
891 gs_lgp
->gnome_print_gsave( m_gpc
);
893 gs_lgp
->gnome_print_translate( m_gpc
, xx
, yy
);
894 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
895 gs_lgp
->gnome_print_scale( m_gpc
, 1.0, scale
);
900 if (m_brush
.GetStyle () != wxTRANSPARENT
)
904 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
905 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
906 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
907 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
909 gs_lgp
->gnome_print_fill( m_gpc
);
912 if (m_pen
.GetStyle () != wxTRANSPARENT
)
916 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
917 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
919 gs_lgp
->gnome_print_stroke( m_gpc
);
922 gs_lgp
->gnome_print_grestore( m_gpc
);
924 CalcBoundingBox( x
, y
);
925 CalcBoundingBox( x
+w
, y
+h
);
928 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
932 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
934 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
941 for ( i
=0; i
<n
; i
++ )
942 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
944 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
946 for (i
= 1; i
< n
; i
++)
947 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
949 gs_lgp
->gnome_print_stroke ( m_gpc
);
952 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
956 if (m_brush
.GetStyle () != wxTRANSPARENT
)
960 int x
= points
[0].x
+ xoffset
;
961 int y
= points
[0].y
+ yoffset
;
962 CalcBoundingBox( x
, y
);
963 gs_lgp
->gnome_print_newpath( m_gpc
);
964 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
966 for (i
= 1; i
< n
; i
++)
968 int x
= points
[i
].x
+ xoffset
;
969 int y
= points
[i
].y
+ yoffset
;
970 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
971 CalcBoundingBox( x
, y
);
973 gs_lgp
->gnome_print_closepath( m_gpc
);
974 gs_lgp
->gnome_print_fill( m_gpc
);
977 if (m_pen
.GetStyle () != wxTRANSPARENT
)
981 int x
= points
[0].x
+ xoffset
;
982 int y
= points
[0].y
+ yoffset
;
983 gs_lgp
->gnome_print_newpath( m_gpc
);
984 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
986 for (i
= 1; i
< n
; i
++)
988 int x
= points
[i
].x
+ xoffset
;
989 int y
= points
[i
].y
+ yoffset
;
990 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
991 CalcBoundingBox( x
, y
);
993 gs_lgp
->gnome_print_closepath( m_gpc
);
994 gs_lgp
->gnome_print_stroke( m_gpc
);
998 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1000 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1003 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1005 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1007 SetBrush( m_brush
);
1009 gs_lgp
->gnome_print_newpath( m_gpc
);
1010 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1011 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1012 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1013 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1014 gs_lgp
->gnome_print_closepath( m_gpc
);
1015 gs_lgp
->gnome_print_fill( m_gpc
);
1017 CalcBoundingBox( x
, y
);
1018 CalcBoundingBox( x
+ width
, y
+ height
);
1021 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1025 gs_lgp
->gnome_print_newpath( m_gpc
);
1026 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1027 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1028 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1029 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1030 gs_lgp
->gnome_print_closepath( m_gpc
);
1031 gs_lgp
->gnome_print_stroke( m_gpc
);
1033 CalcBoundingBox( x
, y
);
1034 CalcBoundingBox( x
+ width
, y
+ height
);
1038 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1040 wxCoord rad
= (wxCoord
) radius
;
1042 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1045 gs_lgp
->gnome_print_newpath(m_gpc
);
1046 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1047 gs_lgp
->gnome_print_curveto(m_gpc
,
1048 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1049 XLOG2DEV(x
),YLOG2DEV(y
),
1050 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1051 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1052 gs_lgp
->gnome_print_curveto(m_gpc
,
1053 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1054 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1055 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1056 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1057 gs_lgp
->gnome_print_curveto(m_gpc
,
1058 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1059 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1060 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1061 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1062 gs_lgp
->gnome_print_curveto(m_gpc
,
1063 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1064 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1065 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1066 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
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
)
1077 gs_lgp
->gnome_print_newpath(m_gpc
);
1078 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1079 gs_lgp
->gnome_print_curveto(m_gpc
,
1080 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1081 XLOG2DEV(x
),YLOG2DEV(y
),
1082 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1083 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1084 gs_lgp
->gnome_print_curveto(m_gpc
,
1085 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1086 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1087 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1088 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1089 gs_lgp
->gnome_print_curveto(m_gpc
,
1090 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1091 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1092 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1093 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1094 gs_lgp
->gnome_print_curveto(m_gpc
,
1095 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1096 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1097 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1098 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1099 gs_lgp
->gnome_print_closepath(m_gpc
);
1100 gs_lgp
->gnome_print_stroke(m_gpc
);
1102 CalcBoundingBox(x
,y
);
1103 CalcBoundingBox(x
+width
,y
+height
);
1107 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1109 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1111 SetBrush( m_brush
);
1113 gs_lgp
->gnome_print_newpath( m_gpc
);
1114 gs_lgp
->gnome_print_moveto( m_gpc
,
1115 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1117 // start with top half
1118 gs_lgp
->gnome_print_curveto( m_gpc
,
1119 XLOG2DEV(x
), YLOG2DEV(y
),
1120 XLOG2DEV(x
+width
), YLOG2DEV(y
),
1121 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
1123 gs_lgp
->gnome_print_curveto( m_gpc
,
1124 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
1125 XLOG2DEV(x
), YLOG2DEV(y
+height
),
1126 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1128 gs_lgp
->gnome_print_closepath( m_gpc
);
1129 gs_lgp
->gnome_print_fill( m_gpc
);
1131 CalcBoundingBox( x
, y
);
1132 CalcBoundingBox( x
+ width
, y
+ height
);
1135 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1139 gs_lgp
->gnome_print_newpath( m_gpc
);
1140 gs_lgp
->gnome_print_moveto( m_gpc
,
1141 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1143 // start with top half
1144 gs_lgp
->gnome_print_curveto( m_gpc
,
1145 XLOG2DEV(x
), YLOG2DEV(y
),
1146 XLOG2DEV(x
+width
), YLOG2DEV(y
),
1147 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
/2) );
1149 gs_lgp
->gnome_print_curveto( m_gpc
,
1150 XLOG2DEV(x
+width
), YLOG2DEV(y
+height
),
1151 XLOG2DEV(x
), YLOG2DEV(y
+height
),
1152 XLOG2DEV(x
), YLOG2DEV(y
+height
/2) );
1154 gs_lgp
->gnome_print_closepath( m_gpc
);
1155 gs_lgp
->gnome_print_stroke( m_gpc
);
1157 CalcBoundingBox( x
, y
);
1158 CalcBoundingBox( x
+ width
, y
+ height
);
1162 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1166 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1169 wxList::compatibility_iterator node
= points
->GetFirst();
1170 p
= (wxPoint
*)node
->GetData();
1174 node
= node
->GetNext();
1175 p
= (wxPoint
*)node
->GetData();
1179 (double)(x1
+ c
) / 2;
1181 (double)(y1
+ d
) / 2;
1183 gs_lgp
->gnome_print_newpath( m_gpc
);
1184 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1185 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1187 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1188 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1190 node
= node
->GetNext();
1193 q
= (wxPoint
*)node
->GetData();
1201 x3
= (double)(x2
+ c
) / 2;
1202 y3
= (double)(y2
+ d
) / 2;
1204 gs_lgp
->gnome_print_curveto(m_gpc
,
1205 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1206 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1207 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1209 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1210 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1212 node
= node
->GetNext();
1215 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1217 gs_lgp
->gnome_print_stroke( m_gpc
);
1220 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1221 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1222 wxCoord xsrcMask
, wxCoord ysrcMask
)
1227 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1229 DoDrawBitmap( icon
, x
, y
, true );
1232 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1234 if (!bitmap
.Ok()) return;
1236 if (bitmap
.HasPixbuf())
1238 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1239 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1240 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1241 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1242 int height
= gdk_pixbuf_get_height( pixbuf
);
1243 int width
= gdk_pixbuf_get_width( pixbuf
);
1245 gs_lgp
->gnome_print_gsave( m_gpc
);
1247 matrix
[0] = XLOG2DEVREL(width
);
1250 matrix
[3] = YLOG2DEVREL(height
);
1251 matrix
[4] = XLOG2DEV(x
);
1252 matrix
[5] = YLOG2DEV(y
+height
);
1253 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1254 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1256 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1258 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1259 gs_lgp
->gnome_print_grestore( m_gpc
);
1263 wxImage image
= bitmap
.ConvertToImage();
1265 if (!image
.Ok()) return;
1267 gs_lgp
->gnome_print_gsave( m_gpc
);
1269 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1272 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1273 matrix
[4] = XLOG2DEV(x
);
1274 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1275 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1276 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1277 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1278 gs_lgp
->gnome_print_grestore( m_gpc
);
1282 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1284 DoDrawRotatedText( text
, x
, y
, 0.0 );
1287 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1292 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1295 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1297 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1300 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1303 size_t datalen
= strlen((const char*)data
);
1304 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1308 PangoAttrList
*attrs
= pango_attr_list_new();
1309 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1311 a
->end_index
= datalen
;
1312 pango_attr_list_insert(attrs
, a
);
1313 pango_layout_set_attributes(m_layout
, attrs
);
1314 pango_attr_list_unref(attrs
);
1317 if (m_textForegroundColour
.Ok())
1319 unsigned char red
= m_textForegroundColour
.Red();
1320 unsigned char blue
= m_textForegroundColour
.Blue();
1321 unsigned char green
= m_textForegroundColour
.Green();
1323 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1325 double redPS
= (double)(red
) / 255.0;
1326 double bluePS
= (double)(blue
) / 255.0;
1327 double greenPS
= (double)(green
) / 255.0;
1329 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1332 m_currentBlue
= blue
;
1333 m_currentGreen
= green
;
1339 if (fabs(m_scaleY
- 1.0) > 0.00001)
1341 // If there is a user or actually any scale applied to
1342 // the device context, scale the font.
1344 // scale font description
1345 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1346 double size
= oldSize
;
1347 size
= size
* m_scaleY
;
1348 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1350 // actually apply scaled font
1351 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1353 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1355 if ( m_backgroundMode
== wxSOLID
)
1357 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1358 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1359 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1363 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1364 if (fabs(angle
) > 0.00001)
1366 gs_lgp
->gnome_print_gsave( m_gpc
);
1367 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1368 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1369 gs_lgp
->gnome_print_grestore( m_gpc
);
1373 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1376 // reset unscaled size
1377 pango_font_description_set_size( m_fontdesc
, oldSize
);
1379 // actually apply unscaled font
1380 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1384 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1386 if ( m_backgroundMode
== wxSOLID
)
1388 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1389 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1390 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1394 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1395 if (fabs(angle
) > 0.00001)
1397 gs_lgp
->gnome_print_gsave( m_gpc
);
1398 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1399 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1400 gs_lgp
->gnome_print_grestore( m_gpc
);
1404 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1410 // undo underline attributes setting:
1411 pango_layout_set_attributes(m_layout
, NULL
);
1414 CalcBoundingBox (x
+ w
, y
+ h
);
1417 void wxGnomePrintDC::Clear()
1421 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1428 pango_font_description_free( m_fontdesc
);
1430 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1432 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1436 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1438 if (!pen
.Ok()) return;
1442 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1444 static const double dotted
[] = {2.0, 5.0};
1445 static const double short_dashed
[] = {4.0, 4.0};
1446 static const double wxCoord_dashed
[] = {4.0, 8.0};
1447 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1449 switch (m_pen
.GetStyle())
1451 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1452 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1453 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1454 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1457 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1461 unsigned char red
= m_pen
.GetColour().Red();
1462 unsigned char blue
= m_pen
.GetColour().Blue();
1463 unsigned char green
= m_pen
.GetColour().Green();
1465 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1467 double redPS
= (double)(red
) / 255.0;
1468 double bluePS
= (double)(blue
) / 255.0;
1469 double greenPS
= (double)(green
) / 255.0;
1471 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1474 m_currentBlue
= blue
;
1475 m_currentGreen
= green
;
1479 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1481 if (!brush
.Ok()) return;
1486 unsigned char red
= m_brush
.GetColour().Red();
1487 unsigned char blue
= m_brush
.GetColour().Blue();
1488 unsigned char green
= m_brush
.GetColour().Green();
1492 // Anything not white is black
1493 if (! (red
== (unsigned char) 255 &&
1494 blue
== (unsigned char) 255 &&
1495 green
== (unsigned char) 255) )
1497 red
= (unsigned char) 0;
1498 green
= (unsigned char) 0;
1499 blue
= (unsigned char) 0;
1504 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1506 double redPS
= (double)(red
) / 255.0;
1507 double bluePS
= (double)(blue
) / 255.0;
1508 double greenPS
= (double)(green
) / 255.0;
1510 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1513 m_currentBlue
= blue
;
1514 m_currentGreen
= green
;
1518 void wxGnomePrintDC::SetLogicalFunction( int function
)
1522 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1526 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1530 void wxGnomePrintDC::DestroyClippingRegion()
1534 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1536 SetDeviceOrigin( 0,0 );
1541 void wxGnomePrintDC::EndDoc()
1543 gs_lgp
->gnome_print_end_doc( m_gpc
);
1546 void wxGnomePrintDC::StartPage()
1548 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1551 void wxGnomePrintDC::EndPage()
1553 gs_lgp
->gnome_print_showpage( m_gpc
);
1556 wxCoord
wxGnomePrintDC::GetCharHeight() const
1558 pango_layout_set_text( m_layout
, "H", 1 );
1561 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1566 wxCoord
wxGnomePrintDC::GetCharWidth() const
1568 pango_layout_set_text( m_layout
, "H", 1 );
1571 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1576 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1578 wxCoord
*externalLeading
,
1579 wxFont
*theFont
) const
1587 if ( externalLeading
)
1588 *externalLeading
= 0;
1590 if (string
.IsEmpty())
1595 // Set new font description
1597 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1599 // Set layout's text
1601 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1602 const char *dataUTF8
= (const char *)data
;
1604 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1607 if (width
) (*width
) = 0;
1608 if (height
) (*height
) = 0;
1611 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1612 const char *dataUTF8
= (const char *)data
;
1617 // hardly ideal, but what else can we do if conversion failed?
1621 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1624 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1627 *width
= (wxCoord
)(w
/ m_scaleX
);
1629 *height
= (wxCoord
)(h
/ m_scaleY
);
1632 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1633 int baseline
= pango_layout_iter_get_baseline(iter
);
1634 pango_layout_iter_free(iter
);
1635 *descent
= h
- PANGO_PIXELS(baseline
);
1638 // Reset old font description
1640 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1643 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1645 wxGnomePrintNativeData
*native
=
1646 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1648 // Query page size. This seems to omit the margins
1649 // right now, although it shouldn't
1651 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1654 *width
= (int) (pw
+ 0.5);
1656 *height
= (int) (ph
+ 0.5);
1659 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1661 wxGnomePrintNativeData
*native
=
1662 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1664 // This code assumes values in Pts.
1667 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1671 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1672 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1673 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1674 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1677 *width
= (int) (pw
+ 0.5);
1679 *height
= (int) (ph
+ 0.5);
1682 wxSize
wxGnomePrintDC::GetPPI() const
1684 return wxSize(72,72);
1687 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1689 m_signX
= (xLeftRight
? 1 : -1);
1690 m_signY
= (yBottomUp
? 1 : -1);
1692 ComputeScaleAndOrigin();
1695 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1701 wxDC::SetDeviceOrigin( x
, h
-y
);
1704 void wxGnomePrintDC::SetResolution(int ppi
)
1708 int wxGnomePrintDC::GetResolution()
1714 class wxGnomePrintModule
: public wxModule
1717 wxGnomePrintModule() {}
1722 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1725 bool wxGnomePrintModule::OnInit()
1727 gs_lgp
= new wxGnomePrintLibrary
;
1729 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1733 void wxGnomePrintModule::OnExit()
1738 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1741 // wxUSE_LIBGNOMEPRINT