1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gnome/gprint.cpp
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME printing support
7 // Copyright: Robert Roebling
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_LIBGNOMEPRINT
20 #include "wx/gtk/gnome/gprint.h"
24 #include "wx/dcmemory.h"
28 #include "wx/module.h"
31 #include "wx/fontutil.h"
32 #include "wx/gtk/private.h"
33 #include "wx/dynlib.h"
36 #include <libgnomeprint/gnome-print.h>
37 #include <libgnomeprint/gnome-print-pango.h>
38 #include <libgnomeprint/gnome-print-config.h>
39 #include <libgnomeprintui/gnome-print-dialog.h>
40 #include <libgnomeprintui/gnome-print-job-preview.h>
41 #include <libgnomeprintui/gnome-print-paper-selector.h>
43 static const double RAD2DEG
= 180.0 / M_PI
;
46 wxFORCE_LINK_THIS_MODULE(gnome_print
)
48 //----------------------------------------------------------------------------
49 // wxGnomePrintLibrary
50 //----------------------------------------------------------------------------
52 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
53 typedef rettype (* name ## Type) args ; \
54 name ## Type pfn_ ## name; \
56 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
58 #define wxDL_METHOD_LOAD( lib, name, success ) \
59 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
62 class wxGnomePrintLibrary
65 wxGnomePrintLibrary();
66 ~wxGnomePrintLibrary();
69 void InitializeMethods();
73 wxDynamicLibrary
*m_gnome_print_lib
;
74 wxDynamicLibrary
*m_gnome_printui_lib
;
77 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
78 (GnomePrintContext
*pc
), (pc
), 0 )
79 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
80 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
81 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
82 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
83 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
84 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
85 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
86 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
87 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
88 (GnomePrintContext
*pc
), (pc
), 0 )
89 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
90 (GnomePrintContext
*pc
), (pc
), 0 )
91 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
92 (GnomePrintContext
*pc
), (pc
), 0 )
93 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
94 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
95 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
96 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
97 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
98 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
100 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
101 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
102 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
103 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
105 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
106 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
107 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
108 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
109 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
110 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
111 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
112 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
114 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
115 (GnomePrintContext
*pc
), (pc
), 0 )
116 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
117 (GnomePrintContext
*pc
), (pc
), 0 )
119 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
120 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
121 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
122 (GnomePrintContext
*pc
), (pc
), 0 )
123 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
124 (GnomePrintContext
*pc
), (pc
), 0 )
126 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
127 (GnomePrintContext
*gpc
), (gpc
), NULL
)
128 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
129 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
131 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
132 (GnomePrintConfig
*config
), (config
), NULL
)
133 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
134 (GnomePrintJob
*job
), (job
), NULL
)
135 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
136 (GnomePrintJob
*job
), (job
), 0 )
137 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
138 (GnomePrintJob
*job
), (job
), 0 )
139 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
140 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
142 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
143 (const guchar
*abbreviation
), (abbreviation
), NULL
)
144 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
145 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
147 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
149 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
150 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
151 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
152 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
154 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
155 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
156 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
157 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
158 const guchar
*currentlabel
, const guchar
*rangelabel
),
159 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
160 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
161 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
162 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
163 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
164 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
165 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
166 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
167 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
169 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
170 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
172 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
173 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
175 DECLARE_NO_COPY_CLASS(wxGnomePrintLibrary
)
178 wxGnomePrintLibrary::wxGnomePrintLibrary()
180 m_gnome_print_lib
= NULL
;
181 m_gnome_printui_lib
= NULL
;
185 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
186 m_ok
= m_gnome_print_lib
->IsLoaded();
189 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
190 m_ok
= m_gnome_printui_lib
->IsLoaded();
196 wxGnomePrintLibrary::~wxGnomePrintLibrary()
198 if (m_gnome_print_lib
)
199 delete m_gnome_print_lib
;
200 if (m_gnome_printui_lib
)
201 delete m_gnome_printui_lib
;
204 bool wxGnomePrintLibrary::IsOk()
209 void wxGnomePrintLibrary::InitializeMethods()
214 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
215 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
217 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
218 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_arcto
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
221 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
222 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
223 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
230 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
231 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_translate
, success
)
234 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
237 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
238 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
241 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
242 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
244 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
245 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
246 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
247 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
248 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
250 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
251 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
253 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
254 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
255 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
257 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
258 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
259 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
260 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
261 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
262 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
264 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
266 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
271 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
273 //----------------------------------------------------------------------------
274 // wxGnomePrintNativeData
275 //----------------------------------------------------------------------------
277 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
279 wxGnomePrintNativeData::wxGnomePrintNativeData()
281 m_config
= gs_lgp
->gnome_print_config_default();
282 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
285 wxGnomePrintNativeData::~wxGnomePrintNativeData()
287 g_object_unref (m_config
);
290 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
296 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
302 //----------------------------------------------------------------------------
303 // wxGnomePrintFactory
304 //----------------------------------------------------------------------------
306 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
308 return new wxGnomePrinter( data
);
311 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
312 wxPrintout
*printout
,
313 wxPrintDialogData
*data
)
315 return new wxGnomePrintPreview( preview
, printout
, data
);
318 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
319 wxPrintout
*printout
,
322 return new wxGnomePrintPreview( preview
, printout
, data
);
325 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
326 wxPrintDialogData
*data
)
328 return new wxGnomePrintDialog( parent
, data
);
331 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
334 return new wxGnomePrintDialog( parent
, data
);
337 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
338 wxPageSetupDialogData
* data
)
340 // The native page setup dialog is broken. It
341 // miscalculates newly entered values for the
342 // margins if you have not chose "points" but
343 // e.g. centimerters.
344 // This has been fixed in GNOME CVS (maybe
345 // fixed in libgnomeprintui 2.8.1)
347 return new wxGnomePageSetupDialog( parent
, data
);
350 bool wxGnomePrintFactory::HasPrintSetupDialog()
355 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
360 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
362 return new wxGnomePrintDC(data
);
365 bool wxGnomePrintFactory::HasOwnPrintToFile()
370 bool wxGnomePrintFactory::HasPrinterLine()
375 wxString
wxGnomePrintFactory::CreatePrinterLine()
378 return wxEmptyString
;
381 bool wxGnomePrintFactory::HasStatusLine()
387 wxString
wxGnomePrintFactory::CreateStatusLine()
390 return wxEmptyString
;
393 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
395 return new wxGnomePrintNativeData
;
398 //----------------------------------------------------------------------------
399 // wxGnomePrintSetupDialog
400 //----------------------------------------------------------------------------
402 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
404 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
405 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
406 wxPoint(0, 0), wxSize(600, 600),
407 wxDEFAULT_DIALOG_STYLE
|
411 m_printDialogData
= *data
;
416 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
417 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
418 wxPoint(0, 0), wxSize(600, 600),
419 wxDEFAULT_DIALOG_STYLE
|
423 m_printDialogData
= *data
;
428 void wxGnomePrintDialog::Init()
430 wxPrintData data
= m_printDialogData
.GetPrintData();
432 wxGnomePrintNativeData
*native
=
433 (wxGnomePrintNativeData
*) data
.GetNativeData();
435 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
437 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
440 if (m_printDialogData
.GetEnableSelection())
441 flag
|= GNOME_PRINT_RANGE_SELECTION
;
442 if (m_printDialogData
.GetEnablePageNumbers())
443 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
445 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
447 m_printDialogData
.GetMinPage(),
448 m_printDialogData
.GetMaxPage(),
453 wxGnomePrintDialog::~wxGnomePrintDialog()
458 int wxGnomePrintDialog::ShowModal()
460 // Transfer data from m_printDalogData to dialog here
462 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
464 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
466 gtk_widget_destroy(m_widget
);
473 gboolean collate
= false;
474 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
475 m_printDialogData
.SetNoCopies( copies
);
476 m_printDialogData
.SetCollate( collate
);
478 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
480 case GNOME_PRINT_RANGE_SELECTION
:
481 m_printDialogData
.SetSelection( true );
483 case GNOME_PRINT_RANGE_ALL
:
484 m_printDialogData
.SetAllPages( true );
485 m_printDialogData
.SetFromPage( 0 );
486 m_printDialogData
.SetToPage( 9999 );
488 case GNOME_PRINT_RANGE_RANGE
:
491 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
492 m_printDialogData
.SetFromPage( start
);
493 m_printDialogData
.SetToPage( end
);
497 gtk_widget_destroy(m_widget
);
500 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
506 wxDC
*wxGnomePrintDialog::GetPrintDC()
512 bool wxGnomePrintDialog::Validate()
517 bool wxGnomePrintDialog::TransferDataToWindow()
522 bool wxGnomePrintDialog::TransferDataFromWindow()
527 //----------------------------------------------------------------------------
528 // wxGnomePageSetupDialog
529 //----------------------------------------------------------------------------
531 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
533 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
534 wxPageSetupDialogData
* data
)
537 m_pageDialogData
= *data
;
539 wxGnomePrintNativeData
*native
=
540 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
542 // This is required as the page setup dialog
543 // calculates wrong values otherwise.
544 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
545 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
546 (const guchar
*) "Pts" );
548 m_widget
= gtk_dialog_new();
550 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
552 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
553 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
554 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
555 gtk_widget_show (main
);
557 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
559 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
561 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
562 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
563 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
566 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
570 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
574 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
576 return m_pageDialogData
;
579 int wxGnomePageSetupDialog::ShowModal()
581 wxGnomePrintNativeData
*native
=
582 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
583 GnomePrintConfig
*config
= native
->GetPrintConfig();
585 // Transfer data from m_pageDialogData to native dialog
587 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
589 if (ret
== GTK_RESPONSE_OK
)
591 // Transfer data back to m_pageDialogData
593 // I don't know how querying the last parameter works
594 // I cannot test it as the dialog is currently broken
595 // anyways (it only works for points).
596 double ml
,mr
,mt
,mb
,pw
,ph
;
597 gs_lgp
->gnome_print_config_get_length (config
,
598 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
599 gs_lgp
->gnome_print_config_get_length (config
,
600 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
601 gs_lgp
->gnome_print_config_get_length (config
,
602 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
603 gs_lgp
->gnome_print_config_get_length (config
,
604 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
605 gs_lgp
->gnome_print_config_get_length (config
,
606 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
607 gs_lgp
->gnome_print_config_get_length (config
,
608 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
610 // This probably assumes that the user entered the
611 // values in Pts. Since that is the only the dialog
612 // works right now, we need to fix this later.
613 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
614 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
615 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
616 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
617 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
618 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
619 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
620 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
622 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
623 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
625 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
628 wxPrintf( wxT("paper %d %d, top margin %d\n"),
629 m_pageDialogData
.GetPaperSize().x
,
630 m_pageDialogData
.GetPaperSize().y
,
631 m_pageDialogData
.GetMarginTopLeft().x
);
641 gtk_widget_destroy( m_widget
);
647 bool wxGnomePageSetupDialog::Validate()
652 bool wxGnomePageSetupDialog::TransferDataToWindow()
657 bool wxGnomePageSetupDialog::TransferDataFromWindow()
662 //----------------------------------------------------------------------------
664 //----------------------------------------------------------------------------
666 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
668 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
669 wxPrinterBase( data
)
672 m_native_preview
= false;
675 wxGnomePrinter::~wxGnomePrinter()
679 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
683 sm_lastError
= wxPRINTER_ERROR
;
687 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
688 wxGnomePrintNativeData
*native
=
689 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
691 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
692 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
694 // The GnomePrintJob is temporarily stored in the
695 // native print data as the native print dialog
696 // needs to access it.
697 native
->SetPrintJob( job
);
700 printout
->SetIsPreview(false);
702 if (m_printDialogData
.GetMinPage() < 1)
703 m_printDialogData
.SetMinPage(1);
704 if (m_printDialogData
.GetMaxPage() < 1)
705 m_printDialogData
.SetMaxPage(9999);
709 dc
= PrintDialog( parent
);
711 dc
= new wxGnomePrintDC( this );
713 if (m_native_preview
)
714 printout
->SetIsPreview(true);
718 gs_lgp
->gnome_print_job_close( job
);
719 g_object_unref (job
);
720 if (sm_lastError
!= wxPRINTER_CANCELLED
)
721 sm_lastError
= wxPRINTER_ERROR
;
725 wxSize ScreenPixels
= wxGetDisplaySize();
726 wxSize ScreenMM
= wxGetDisplaySizeMM();
728 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
729 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
730 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
731 wxGnomePrintDC::GetResolution() );
737 printout
->SetPageSizePixels((int)w
, (int)h
);
738 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
740 dc
->GetSizeMM(&mw
, &mh
);
741 printout
->SetPageSizeMM((int)mw
, (int)mh
);
742 printout
->OnPreparePrinting();
744 // Get some parameters from the printout, if defined
745 int fromPage
, toPage
;
746 int minPage
, maxPage
;
747 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
751 gs_lgp
->gnome_print_job_close( job
);
752 g_object_unref (job
);
753 sm_lastError
= wxPRINTER_ERROR
;
757 printout
->OnBeginPrinting();
759 int minPageNum
= minPage
, maxPageNum
= maxPage
;
761 if ( !m_printDialogData
.GetAllPages() )
763 minPageNum
= m_printDialogData
.GetFromPage();
764 maxPageNum
= m_printDialogData
.GetToPage();
770 copyCount
<= m_printDialogData
.GetNoCopies();
773 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
775 wxLogError(_("Could not start printing."));
776 sm_lastError
= wxPRINTER_ERROR
;
781 for ( pn
= minPageNum
;
782 pn
<= maxPageNum
&& printout
->HasPage(pn
);
786 printout
->OnPrintPage(pn
);
790 printout
->OnEndDocument();
791 printout
->OnEndPrinting();
794 gs_lgp
->gnome_print_job_close( job
);
795 if (m_native_preview
)
797 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
798 GtkWidget
*preview
= gs_lgp
->gnome_print_job_preview_new
801 (const guchar
*)title
.data()
803 gtk_widget_show(preview
);
807 gs_lgp
->gnome_print_job_print( job
);
810 g_object_unref (job
);
813 return (sm_lastError
== wxPRINTER_NO_ERROR
);
816 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
818 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
819 int ret
= dialog
.ShowModal();
820 if (ret
== wxID_CANCEL
)
822 sm_lastError
= wxPRINTER_CANCELLED
;
826 m_native_preview
= ret
== wxID_PREVIEW
;
828 m_printDialogData
= dialog
.GetPrintDialogData();
829 return new wxGnomePrintDC( this );
832 bool wxGnomePrinter::Setup( wxWindow
*parent
)
837 //-----------------------------------------------------------------------------
839 //-----------------------------------------------------------------------------
841 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
843 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
847 m_gpc
= printer
->GetPrintContext();
848 m_job
= NULL
; // only used and destroyed when created with wxPrintData
850 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
851 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
858 m_signX
= 1; // default x-axis left to right
859 m_signY
= -1; // default y-axis bottom up -> top down
861 GetSize( NULL
, &m_deviceOffsetY
);
864 wxGnomePrintDC::wxGnomePrintDC( const wxPrintData
& data
)
869 wxGnomePrintNativeData
*native
=
870 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
872 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
873 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
874 m_job
= job
; // only used and destroyed when created with wxPrintData
876 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
877 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
884 m_signX
= 1; // default x-axis left to right
885 m_signY
= -1; // default y-axis bottom up -> top down
887 GetSize( NULL
, &m_deviceOffsetY
);
890 wxGnomePrintDC::~wxGnomePrintDC()
893 g_object_unref (m_job
);
896 bool wxGnomePrintDC::IsOk() const
901 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
906 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
911 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
913 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
917 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
918 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
919 gs_lgp
->gnome_print_stroke ( m_gpc
);
921 CalcBoundingBox( x1
, y1
);
922 CalcBoundingBox( x2
, y2
);
925 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
929 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
933 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
934 double alpha1
, alpha2
;
935 if (x1
== x2
&& y1
== y2
)
943 alpha1
= alpha2
= 0.0;
947 alpha1
= (x1
- xc
== 0) ?
948 (y1
- yc
< 0) ? 90.0 : -90.0 :
949 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
950 alpha2
= (x2
- xc
== 0) ?
951 (y2
- yc
< 0) ? 90.0 : -90.0 :
952 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
954 while (alpha1
<= 0) alpha1
+= 360;
955 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
956 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
957 while (alpha2
> 360) alpha2
-= 360;
960 if (m_brush
.GetStyle() != wxTRANSPARENT
)
963 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
964 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
966 gs_lgp
->gnome_print_fill( m_gpc
);
969 if (m_pen
.GetStyle() != wxTRANSPARENT
)
972 gs_lgp
->gnome_print_newpath( m_gpc
);
973 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
974 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
975 gs_lgp
->gnome_print_closepath( m_gpc
);
977 gs_lgp
->gnome_print_stroke( m_gpc
);
980 CalcBoundingBox (x1
, y1
);
981 CalcBoundingBox (x2
, y2
);
982 CalcBoundingBox (xc
, yc
);
985 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
990 int xx
= XLOG2DEV(x
);
991 int yy
= YLOG2DEV(y
);
993 gs_lgp
->gnome_print_gsave( m_gpc
);
995 gs_lgp
->gnome_print_translate( m_gpc
, xx
, yy
);
996 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
997 gs_lgp
->gnome_print_scale( m_gpc
, 1.0, scale
);
1002 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1004 SetBrush( m_brush
);
1006 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1007 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
1008 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1009 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1011 gs_lgp
->gnome_print_fill( m_gpc
);
1014 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1018 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
1019 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1021 gs_lgp
->gnome_print_stroke( m_gpc
);
1024 gs_lgp
->gnome_print_grestore( m_gpc
);
1026 CalcBoundingBox( x
, y
);
1027 CalcBoundingBox( x
+w
, y
+h
);
1030 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1034 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1036 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1043 for ( i
=0; i
<n
; i
++ )
1044 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1046 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1048 for (i
= 1; i
< n
; i
++)
1049 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1051 gs_lgp
->gnome_print_stroke ( m_gpc
);
1054 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1058 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1060 SetBrush( m_brush
);
1062 int x
= points
[0].x
+ xoffset
;
1063 int y
= points
[0].y
+ yoffset
;
1064 CalcBoundingBox( x
, y
);
1065 gs_lgp
->gnome_print_newpath( m_gpc
);
1066 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1068 for (i
= 1; i
< n
; i
++)
1070 int x
= points
[i
].x
+ xoffset
;
1071 int y
= points
[i
].y
+ yoffset
;
1072 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1073 CalcBoundingBox( x
, y
);
1075 gs_lgp
->gnome_print_closepath( m_gpc
);
1076 gs_lgp
->gnome_print_fill( m_gpc
);
1079 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1083 int x
= points
[0].x
+ xoffset
;
1084 int y
= points
[0].y
+ yoffset
;
1085 gs_lgp
->gnome_print_newpath( m_gpc
);
1086 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1088 for (i
= 1; i
< n
; i
++)
1090 int x
= points
[i
].x
+ xoffset
;
1091 int y
= points
[i
].y
+ yoffset
;
1092 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1093 CalcBoundingBox( x
, y
);
1095 gs_lgp
->gnome_print_closepath( m_gpc
);
1096 gs_lgp
->gnome_print_stroke( m_gpc
);
1100 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1102 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1105 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1107 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1109 SetBrush( m_brush
);
1111 gs_lgp
->gnome_print_newpath( m_gpc
);
1112 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1113 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1114 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1115 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1116 gs_lgp
->gnome_print_closepath( m_gpc
);
1117 gs_lgp
->gnome_print_fill( m_gpc
);
1119 CalcBoundingBox( x
, y
);
1120 CalcBoundingBox( x
+ width
, y
+ height
);
1123 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1127 gs_lgp
->gnome_print_newpath( m_gpc
);
1128 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1129 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1130 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1131 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1132 gs_lgp
->gnome_print_closepath( m_gpc
);
1133 gs_lgp
->gnome_print_stroke( m_gpc
);
1135 CalcBoundingBox( x
, y
);
1136 CalcBoundingBox( x
+ width
, y
+ height
);
1140 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1142 wxCoord rad
= (wxCoord
) radius
;
1144 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1147 gs_lgp
->gnome_print_newpath(m_gpc
);
1148 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1149 gs_lgp
->gnome_print_curveto(m_gpc
,
1150 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1151 XLOG2DEV(x
),YLOG2DEV(y
),
1152 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1153 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1154 gs_lgp
->gnome_print_curveto(m_gpc
,
1155 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1156 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1157 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1158 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1159 gs_lgp
->gnome_print_curveto(m_gpc
,
1160 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1161 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1162 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1163 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1164 gs_lgp
->gnome_print_curveto(m_gpc
,
1165 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1166 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1167 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1168 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1169 gs_lgp
->gnome_print_closepath(m_gpc
);
1170 gs_lgp
->gnome_print_fill(m_gpc
);
1172 CalcBoundingBox(x
,y
);
1173 CalcBoundingBox(x
+width
,y
+height
);
1176 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1179 gs_lgp
->gnome_print_newpath(m_gpc
);
1180 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1181 gs_lgp
->gnome_print_curveto(m_gpc
,
1182 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1183 XLOG2DEV(x
),YLOG2DEV(y
),
1184 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1185 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1186 gs_lgp
->gnome_print_curveto(m_gpc
,
1187 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1188 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1189 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1190 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1191 gs_lgp
->gnome_print_curveto(m_gpc
,
1192 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1193 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1194 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1195 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1196 gs_lgp
->gnome_print_curveto(m_gpc
,
1197 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1198 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1199 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1200 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1201 gs_lgp
->gnome_print_closepath(m_gpc
);
1202 gs_lgp
->gnome_print_stroke(m_gpc
);
1204 CalcBoundingBox(x
,y
);
1205 CalcBoundingBox(x
+width
,y
+height
);
1209 void wxGnomePrintDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1210 wxCoord width
, wxCoord height
)
1212 double r
= 4 * (sqrt (2) - 1) / 3;
1213 double halfW
= 0.5 * width
,
1214 halfH
= 0.5 * height
,
1217 wxCoord halfWI
= (wxCoord
) halfW
,
1218 halfHI
= (wxCoord
) halfH
;
1220 gs_lgp
->gnome_print_newpath( m_gpc
);
1222 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1223 gs_lgp
->gnome_print_moveto( m_gpc
,
1224 XLOG2DEV(x
+ width
),
1225 YLOG2DEV(y
+ halfHI
) );
1226 gs_lgp
->gnome_print_curveto( m_gpc
,
1227 XLOG2DEV(x
+ width
),
1228 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1229 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1230 YLOG2DEV(y
+ height
),
1231 XLOG2DEV(x
+ halfWI
),
1232 YLOG2DEV(y
+ height
) );
1233 gs_lgp
->gnome_print_curveto( m_gpc
,
1234 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1235 YLOG2DEV(y
+ height
),
1237 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1238 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1239 gs_lgp
->gnome_print_curveto( m_gpc
,
1241 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1242 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1244 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1245 gs_lgp
->gnome_print_curveto( m_gpc
,
1246 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1248 XLOG2DEV(x
+ width
),
1249 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1250 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1252 gs_lgp
->gnome_print_closepath(m_gpc
);
1255 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1257 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1259 SetBrush( m_brush
);
1260 makeEllipticalPath( x
, y
, width
, height
);
1261 gs_lgp
->gnome_print_fill( m_gpc
);
1262 CalcBoundingBox( x
, y
);
1263 CalcBoundingBox( x
+ width
, y
+ height
);
1266 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1269 makeEllipticalPath( x
, y
, width
, height
);
1270 gs_lgp
->gnome_print_stroke( m_gpc
);
1271 CalcBoundingBox( x
, y
);
1272 CalcBoundingBox( x
+ width
, y
+ height
);
1277 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1281 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1284 wxList::compatibility_iterator node
= points
->GetFirst();
1285 p
= (wxPoint
*)node
->GetData();
1289 node
= node
->GetNext();
1290 p
= (wxPoint
*)node
->GetData();
1294 (double)(x1
+ c
) / 2;
1296 (double)(y1
+ d
) / 2;
1298 gs_lgp
->gnome_print_newpath( m_gpc
);
1299 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1300 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1302 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1303 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1305 node
= node
->GetNext();
1308 q
= (wxPoint
*)node
->GetData();
1316 x3
= (double)(x2
+ c
) / 2;
1317 y3
= (double)(y2
+ d
) / 2;
1319 gs_lgp
->gnome_print_curveto(m_gpc
,
1320 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1321 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1322 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1324 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1325 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1327 node
= node
->GetNext();
1330 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1332 gs_lgp
->gnome_print_stroke( m_gpc
);
1334 #endif // wxUSE_SPLINES
1336 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1337 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1338 wxCoord xsrcMask
, wxCoord ysrcMask
)
1340 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1342 // blit into a bitmap
1343 wxBitmap
bitmap( width
, height
);
1345 memDC
.SelectObject(bitmap
);
1346 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1347 memDC
.SelectObject(wxNullBitmap
);
1349 // draw bitmap. scaling and positioning is done there
1350 DrawBitmap( bitmap
, xdest
, ydest
);
1355 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1357 DoDrawBitmap( icon
, x
, y
, true );
1360 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1362 if (!bitmap
.Ok()) return;
1364 if (bitmap
.HasPixbuf())
1366 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1367 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1368 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1369 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1370 int height
= gdk_pixbuf_get_height( pixbuf
);
1371 int width
= gdk_pixbuf_get_width( pixbuf
);
1373 gs_lgp
->gnome_print_gsave( m_gpc
);
1375 matrix
[0] = XLOG2DEVREL(width
);
1378 matrix
[3] = YLOG2DEVREL(height
);
1379 matrix
[4] = XLOG2DEV(x
);
1380 matrix
[5] = YLOG2DEV(y
+height
);
1381 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1382 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1384 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1386 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1387 gs_lgp
->gnome_print_grestore( m_gpc
);
1391 wxImage image
= bitmap
.ConvertToImage();
1393 if (!image
.Ok()) return;
1395 gs_lgp
->gnome_print_gsave( m_gpc
);
1397 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1400 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1401 matrix
[4] = XLOG2DEV(x
);
1402 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1403 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1404 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1405 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1406 gs_lgp
->gnome_print_grestore( m_gpc
);
1410 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1412 DoDrawRotatedText( text
, x
, y
, 0.0 );
1415 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1420 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1423 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1425 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1428 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1431 size_t datalen
= strlen((const char*)data
);
1432 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1436 PangoAttrList
*attrs
= pango_attr_list_new();
1437 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1439 a
->end_index
= datalen
;
1440 pango_attr_list_insert(attrs
, a
);
1441 pango_layout_set_attributes(m_layout
, attrs
);
1442 pango_attr_list_unref(attrs
);
1445 if (m_textForegroundColour
.Ok())
1447 unsigned char red
= m_textForegroundColour
.Red();
1448 unsigned char blue
= m_textForegroundColour
.Blue();
1449 unsigned char green
= m_textForegroundColour
.Green();
1451 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1453 double redPS
= (double)(red
) / 255.0;
1454 double bluePS
= (double)(blue
) / 255.0;
1455 double greenPS
= (double)(green
) / 255.0;
1457 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1460 m_currentBlue
= blue
;
1461 m_currentGreen
= green
;
1467 if (fabs(m_scaleY
- 1.0) > 0.00001)
1469 // If there is a user or actually any scale applied to
1470 // the device context, scale the font.
1472 // scale font description
1473 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1474 double size
= oldSize
;
1475 size
= size
* m_scaleY
;
1476 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1478 // actually apply scaled font
1479 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1481 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1483 if ( m_backgroundMode
== wxSOLID
)
1485 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1486 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1487 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1491 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1492 if (fabs(angle
) > 0.00001)
1494 gs_lgp
->gnome_print_gsave( m_gpc
);
1495 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1496 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1497 gs_lgp
->gnome_print_grestore( m_gpc
);
1501 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1504 // reset unscaled size
1505 pango_font_description_set_size( m_fontdesc
, oldSize
);
1507 // actually apply unscaled font
1508 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1512 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1514 if ( m_backgroundMode
== wxSOLID
)
1516 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1517 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1518 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1522 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1523 if (fabs(angle
) > 0.00001)
1525 gs_lgp
->gnome_print_gsave( m_gpc
);
1526 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1527 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1528 gs_lgp
->gnome_print_grestore( m_gpc
);
1532 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1538 // undo underline attributes setting:
1539 pango_layout_set_attributes(m_layout
, NULL
);
1542 CalcBoundingBox (x
+ w
, y
+ h
);
1545 void wxGnomePrintDC::Clear()
1549 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1556 pango_font_description_free( m_fontdesc
);
1558 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1560 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1564 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1566 if (!pen
.Ok()) return;
1570 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1572 static const double dotted
[] = {2.0, 5.0};
1573 static const double short_dashed
[] = {4.0, 4.0};
1574 static const double wxCoord_dashed
[] = {4.0, 8.0};
1575 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1577 switch (m_pen
.GetStyle())
1579 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1580 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1581 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1582 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1585 // It may be noted that libgnomeprint between at least
1586 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1587 // and then leak the memory since it doesn't set the
1588 // internal flag "privatedash" to 0.
1590 int num
= m_pen
.GetDashes (&wx_dashes
);
1591 gdouble
*g_dashes
= g_new( gdouble
, num
);
1593 for (i
= 0; i
< num
; ++i
)
1594 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1595 gs_lgp
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1601 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1605 unsigned char red
= m_pen
.GetColour().Red();
1606 unsigned char blue
= m_pen
.GetColour().Blue();
1607 unsigned char green
= m_pen
.GetColour().Green();
1609 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1611 double redPS
= (double)(red
) / 255.0;
1612 double bluePS
= (double)(blue
) / 255.0;
1613 double greenPS
= (double)(green
) / 255.0;
1615 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1618 m_currentBlue
= blue
;
1619 m_currentGreen
= green
;
1623 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1625 if (!brush
.Ok()) return;
1630 unsigned char red
= m_brush
.GetColour().Red();
1631 unsigned char blue
= m_brush
.GetColour().Blue();
1632 unsigned char green
= m_brush
.GetColour().Green();
1636 // Anything not white is black
1637 if (! (red
== (unsigned char) 255 &&
1638 blue
== (unsigned char) 255 &&
1639 green
== (unsigned char) 255) )
1641 red
= (unsigned char) 0;
1642 green
= (unsigned char) 0;
1643 blue
= (unsigned char) 0;
1648 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1650 double redPS
= (double)(red
) / 255.0;
1651 double bluePS
= (double)(blue
) / 255.0;
1652 double greenPS
= (double)(green
) / 255.0;
1654 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1657 m_currentBlue
= blue
;
1658 m_currentGreen
= green
;
1662 void wxGnomePrintDC::SetLogicalFunction( int function
)
1666 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1670 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1674 void wxGnomePrintDC::DestroyClippingRegion()
1678 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1683 void wxGnomePrintDC::EndDoc()
1685 gs_lgp
->gnome_print_end_doc( m_gpc
);
1688 void wxGnomePrintDC::StartPage()
1690 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1693 void wxGnomePrintDC::EndPage()
1695 gs_lgp
->gnome_print_showpage( m_gpc
);
1698 wxCoord
wxGnomePrintDC::GetCharHeight() const
1700 pango_layout_set_text( m_layout
, "H", 1 );
1703 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1708 wxCoord
wxGnomePrintDC::GetCharWidth() const
1710 pango_layout_set_text( m_layout
, "H", 1 );
1713 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1718 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1720 wxCoord
*externalLeading
,
1721 const wxFont
*theFont
) const
1729 if ( externalLeading
)
1730 *externalLeading
= 0;
1737 // Set new font description
1739 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1741 // Set layout's text
1743 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1744 const char *dataUTF8
= (const char *)data
;
1746 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1749 if (width
) (*width
) = 0;
1750 if (height
) (*height
) = 0;
1753 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1754 const char *dataUTF8
= (const char *)data
;
1759 // hardly ideal, but what else can we do if conversion failed?
1763 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1766 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1769 *width
= (wxCoord
)(w
/ m_scaleX
);
1771 *height
= (wxCoord
)(h
/ m_scaleY
);
1774 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1775 int baseline
= pango_layout_iter_get_baseline(iter
);
1776 pango_layout_iter_free(iter
);
1777 *descent
= h
- PANGO_PIXELS(baseline
);
1780 // Reset old font description
1782 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1785 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1787 wxGnomePrintNativeData
*native
=
1788 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1790 // Query page size. This seems to omit the margins
1792 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1795 *width
= (int) (pw
+ 0.5);
1797 *height
= (int) (ph
+ 0.5);
1800 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1802 wxGnomePrintNativeData
*native
=
1803 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1805 // This code assumes values in Pts.
1808 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1812 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1813 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1814 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1815 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1818 *width
= (int) (pw
+ 0.5);
1820 *height
= (int) (ph
+ 0.5);
1823 wxSize
wxGnomePrintDC::GetPPI() const
1825 return wxSize(72,72);
1828 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1830 m_signX
= (xLeftRight
? 1 : -1);
1831 m_signY
= (yBottomUp
? 1 : -1);
1833 ComputeScaleAndOrigin();
1836 void wxGnomePrintDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1838 wxDC::SetLogicalOrigin( x
, y
);
1841 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1843 wxDC::SetDeviceOrigin( x
, y
);
1846 void wxGnomePrintDC::SetResolution(int ppi
)
1850 int wxGnomePrintDC::GetResolution()
1856 class wxGnomePrintModule
: public wxModule
1859 wxGnomePrintModule() {}
1864 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1867 bool wxGnomePrintModule::OnInit()
1869 gs_lgp
= new wxGnomePrintLibrary
;
1871 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1875 void wxGnomePrintModule::OnExit()
1880 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1882 // ----------------------------------------------------------------------------
1884 // ----------------------------------------------------------------------------
1886 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
1888 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
1889 wxPrintout
* WXUNUSED(printoutForPrinting
))
1894 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1895 wxPrintout
*printoutForPrinting
,
1896 wxPrintDialogData
*data
)
1897 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1899 Init(printout
, printoutForPrinting
);
1902 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1903 wxPrintout
*printoutForPrinting
,
1905 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1907 Init(printout
, printoutForPrinting
);
1910 wxGnomePrintPreview::~wxGnomePrintPreview()
1914 bool wxGnomePrintPreview::Print(bool interactive
)
1916 if (!m_printPrintout
)
1919 wxPrinter
printer(& m_printDialogData
);
1920 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
1923 void wxGnomePrintPreview::DetermineScaling()
1925 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
1926 if (paperType
== wxPAPER_NONE
)
1927 paperType
= wxPAPER_NONE
;
1929 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1931 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1935 wxSize ScreenPixels
= wxGetDisplaySize();
1936 wxSize ScreenMM
= wxGetDisplaySizeMM();
1938 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
1939 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
1940 m_previewPrintout
->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
1942 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
1944 // TODO: get better resolution information from wxGnomePrintDC, if possible.
1946 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGnomePrintDC::GetResolution() / 72.0);
1947 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGnomePrintDC::GetResolution() / 72.0);
1948 wxSize
sizeTenthsMM(paper
->GetSize());
1949 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
1951 // If in landscape mode, we need to swap the width and height.
1952 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
1954 m_pageWidth
= sizeDevUnits
.y
;
1955 m_pageHeight
= sizeDevUnits
.x
;
1956 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
1960 m_pageWidth
= sizeDevUnits
.x
;
1961 m_pageHeight
= sizeDevUnits
.y
;
1962 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
1964 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
1965 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
1967 // At 100%, the page should look about page-size on the screen.
1968 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
1969 m_previewScaleY
= m_previewScaleX
;
1974 // wxUSE_LIBGNOMEPRINT