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 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1167 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1168 wxCoord xsrcMask
, wxCoord ysrcMask
)
1173 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1175 DoDrawBitmap( icon
, x
, y
, true );
1178 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1180 if (!bitmap
.Ok()) return;
1182 if (bitmap
.HasPixbuf())
1184 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1185 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1186 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1187 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1188 int height
= gdk_pixbuf_get_height( pixbuf
);
1189 int width
= gdk_pixbuf_get_width( pixbuf
);
1191 gs_lgp
->gnome_print_gsave( m_gpc
);
1193 matrix
[0] = XLOG2DEVREL(width
);
1196 matrix
[3] = YLOG2DEVREL(height
);
1197 matrix
[4] = XLOG2DEV(x
);
1198 matrix
[5] = YLOG2DEV(y
+height
);
1199 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1200 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1202 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1204 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1205 gs_lgp
->gnome_print_grestore( m_gpc
);
1209 wxImage image
= bitmap
.ConvertToImage();
1211 if (!image
.Ok()) return;
1213 gs_lgp
->gnome_print_gsave( m_gpc
);
1215 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1218 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1219 matrix
[4] = XLOG2DEV(x
);
1220 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1221 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1222 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1223 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1224 gs_lgp
->gnome_print_grestore( m_gpc
);
1228 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1230 DoDrawRotatedText( text
, x
, y
, 0.0 );
1233 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1238 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1241 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1243 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1246 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1249 size_t datalen
= strlen((const char*)data
);
1250 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1254 PangoAttrList
*attrs
= pango_attr_list_new();
1255 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1257 a
->end_index
= datalen
;
1258 pango_attr_list_insert(attrs
, a
);
1259 pango_layout_set_attributes(m_layout
, attrs
);
1260 pango_attr_list_unref(attrs
);
1263 if (m_textForegroundColour
.Ok())
1265 unsigned char red
= m_textForegroundColour
.Red();
1266 unsigned char blue
= m_textForegroundColour
.Blue();
1267 unsigned char green
= m_textForegroundColour
.Green();
1269 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1271 double redPS
= (double)(red
) / 255.0;
1272 double bluePS
= (double)(blue
) / 255.0;
1273 double greenPS
= (double)(green
) / 255.0;
1275 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1278 m_currentBlue
= blue
;
1279 m_currentGreen
= green
;
1285 if (fabs(m_scaleY
- 1.0) > 0.00001)
1287 // If there is a user or actually any scale applied to
1288 // the device context, scale the font.
1290 // scale font description
1291 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1292 double size
= oldSize
;
1293 size
= size
* m_scaleY
;
1294 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1296 // actually apply scaled font
1297 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1299 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1301 if ( m_backgroundMode
== wxSOLID
)
1303 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1304 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1305 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1309 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1310 if (fabs(angle
) > 0.00001)
1312 gs_lgp
->gnome_print_gsave( m_gpc
);
1313 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1314 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1315 gs_lgp
->gnome_print_grestore( m_gpc
);
1319 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1322 // reset unscaled size
1323 pango_font_description_set_size( m_fontdesc
, oldSize
);
1325 // actually apply unscaled font
1326 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1330 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1332 if ( m_backgroundMode
== wxSOLID
)
1334 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1335 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1336 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1340 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1341 if (fabs(angle
) > 0.00001)
1343 gs_lgp
->gnome_print_gsave( m_gpc
);
1344 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1345 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1346 gs_lgp
->gnome_print_grestore( m_gpc
);
1350 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1356 // undo underline attributes setting:
1357 pango_layout_set_attributes(m_layout
, NULL
);
1360 CalcBoundingBox (x
+ w
, y
+ h
);
1363 void wxGnomePrintDC::Clear()
1367 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1374 pango_font_description_free( m_fontdesc
);
1376 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1378 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1382 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1384 if (!pen
.Ok()) return;
1388 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1390 static const double dotted
[] = {2.0, 5.0};
1391 static const double short_dashed
[] = {4.0, 4.0};
1392 static const double wxCoord_dashed
[] = {4.0, 8.0};
1393 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1395 switch (m_pen
.GetStyle())
1397 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1398 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1399 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1400 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1403 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1407 unsigned char red
= m_pen
.GetColour().Red();
1408 unsigned char blue
= m_pen
.GetColour().Blue();
1409 unsigned char green
= m_pen
.GetColour().Green();
1411 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1413 double redPS
= (double)(red
) / 255.0;
1414 double bluePS
= (double)(blue
) / 255.0;
1415 double greenPS
= (double)(green
) / 255.0;
1417 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1420 m_currentBlue
= blue
;
1421 m_currentGreen
= green
;
1425 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1427 if (!brush
.Ok()) return;
1432 unsigned char red
= m_brush
.GetColour().Red();
1433 unsigned char blue
= m_brush
.GetColour().Blue();
1434 unsigned char green
= m_brush
.GetColour().Green();
1438 // Anything not white is black
1439 if (! (red
== (unsigned char) 255 &&
1440 blue
== (unsigned char) 255 &&
1441 green
== (unsigned char) 255) )
1443 red
= (unsigned char) 0;
1444 green
= (unsigned char) 0;
1445 blue
= (unsigned char) 0;
1450 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1452 double redPS
= (double)(red
) / 255.0;
1453 double bluePS
= (double)(blue
) / 255.0;
1454 double greenPS
= (double)(green
) / 255.0;
1456 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1459 m_currentBlue
= blue
;
1460 m_currentGreen
= green
;
1464 void wxGnomePrintDC::SetLogicalFunction( int function
)
1468 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1472 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1476 void wxGnomePrintDC::DestroyClippingRegion()
1480 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1482 SetDeviceOrigin( 0,0 );
1487 void wxGnomePrintDC::EndDoc()
1489 gs_lgp
->gnome_print_end_doc( m_gpc
);
1492 void wxGnomePrintDC::StartPage()
1494 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1497 void wxGnomePrintDC::EndPage()
1499 gs_lgp
->gnome_print_showpage( m_gpc
);
1502 wxCoord
wxGnomePrintDC::GetCharHeight() const
1504 pango_layout_set_text( m_layout
, "H", 1 );
1507 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1512 wxCoord
wxGnomePrintDC::GetCharWidth() const
1514 pango_layout_set_text( m_layout
, "H", 1 );
1517 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1522 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1524 wxCoord
*externalLeading
,
1525 wxFont
*theFont
) const
1533 if ( externalLeading
)
1534 *externalLeading
= 0;
1536 if (string
.IsEmpty())
1541 // Set new font description
1543 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1545 // Set layout's text
1547 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1548 const char *dataUTF8
= (const char *)data
;
1550 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1553 if (width
) (*width
) = 0;
1554 if (height
) (*height
) = 0;
1557 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1558 const char *dataUTF8
= (const char *)data
;
1563 // hardly ideal, but what else can we do if conversion failed?
1567 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1570 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1573 *width
= (wxCoord
)(w
/ m_scaleX
);
1575 *height
= (wxCoord
)(h
/ m_scaleY
);
1578 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1579 int baseline
= pango_layout_iter_get_baseline(iter
);
1580 pango_layout_iter_free(iter
);
1581 *descent
= h
- PANGO_PIXELS(baseline
);
1584 // Reset old font description
1586 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1589 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1591 wxGnomePrintNativeData
*native
=
1592 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1594 // Query page size. This seems to omit the margins
1595 // right now, although it shouldn't
1597 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1600 *width
= (int) (pw
+ 0.5);
1602 *height
= (int) (ph
+ 0.5);
1605 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1607 wxGnomePrintNativeData
*native
=
1608 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1610 // This code assumes values in Pts.
1613 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1617 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1618 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1619 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1620 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1623 *width
= (int) (pw
+ 0.5);
1625 *height
= (int) (ph
+ 0.5);
1628 wxSize
wxGnomePrintDC::GetPPI() const
1630 return wxSize(72,72);
1633 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1635 m_signX
= (xLeftRight
? 1 : -1);
1636 m_signY
= (yBottomUp
? 1 : -1);
1638 ComputeScaleAndOrigin();
1641 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1647 wxDC::SetDeviceOrigin( x
, h
-y
);
1650 void wxGnomePrintDC::SetResolution(int ppi
)
1654 int wxGnomePrintDC::GetResolution()
1660 class wxGnomePrintModule
: public wxModule
1663 wxGnomePrintModule() {}
1668 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1671 bool wxGnomePrintModule::OnInit()
1673 gs_lgp
= new wxGnomePrintLibrary
;
1675 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1679 void wxGnomePrintModule::OnExit()
1684 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1687 // wxUSE_LIBGNOMEPRINT