1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gnome/gprint.cpp
3 // Author: Robert Roebling
4 // Purpose: Implement GNOME printing support
7 // Copyright: Robert Roebling
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 #include "wx/gtk/gnome/gprint.h"
20 #if wxUSE_LIBGNOMEPRINT
24 #include "wx/dcmemory.h"
28 #include "wx/module.h"
31 #include "wx/fontutil.h"
32 #include "wx/gtk/private.h"
33 #include "wx/dynlib.h"
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
;
45 #include "wx/html/forcelnk.h"
46 FORCE_LINK_ME(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
)
176 wxGnomePrintLibrary::wxGnomePrintLibrary()
178 m_gnome_print_lib
= NULL
;
179 m_gnome_printui_lib
= NULL
;
183 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
184 m_ok
= m_gnome_print_lib
->IsLoaded();
187 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
188 m_ok
= m_gnome_printui_lib
->IsLoaded();
194 wxGnomePrintLibrary::~wxGnomePrintLibrary()
196 if (m_gnome_print_lib
)
197 delete m_gnome_print_lib
;
198 if (m_gnome_printui_lib
)
199 delete m_gnome_printui_lib
;
202 bool wxGnomePrintLibrary::IsOk()
207 void wxGnomePrintLibrary::InitializeMethods()
212 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
213 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
214 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
215 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_arcto
, success
)
217 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
218 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
221 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
222 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
225 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
228 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
230 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_translate
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
233 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
237 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
240 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
242 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
243 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
244 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
245 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
246 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
248 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
249 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
251 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
252 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
253 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
255 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
256 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
257 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
258 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
259 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
260 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
262 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
264 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
269 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
271 //----------------------------------------------------------------------------
272 // wxGnomePrintNativeData
273 //----------------------------------------------------------------------------
275 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
277 wxGnomePrintNativeData::wxGnomePrintNativeData()
279 m_config
= gs_lgp
->gnome_print_config_default();
280 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
283 wxGnomePrintNativeData::~wxGnomePrintNativeData()
285 g_object_unref (m_config
);
288 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
294 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
300 //----------------------------------------------------------------------------
301 // wxGnomePrintFactory
302 //----------------------------------------------------------------------------
304 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
306 return new wxGnomePrinter( data
);
309 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
310 wxPrintout
*printout
,
311 wxPrintDialogData
*data
)
313 return new wxGnomePrintPreview( preview
, printout
, data
);
316 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
317 wxPrintout
*printout
,
320 return new wxGnomePrintPreview( preview
, printout
, data
);
323 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
324 wxPrintDialogData
*data
)
326 return new wxGnomePrintDialog( parent
, data
);
329 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
332 return new wxGnomePrintDialog( parent
, data
);
335 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
336 wxPageSetupDialogData
* data
)
338 // The native page setup dialog is broken. It
339 // miscalculates newly entered values for the
340 // margins if you have not chose "points" but
341 // e.g. centimerters.
342 // This has been fixed in GNOME CVS (maybe
343 // fixed in libgnomeprintui 2.8.1)
345 return new wxGnomePageSetupDialog( parent
, data
);
348 bool wxGnomePrintFactory::HasPrintSetupDialog()
353 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
358 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
360 return new wxGnomePrintDC(data
);
363 bool wxGnomePrintFactory::HasOwnPrintToFile()
368 bool wxGnomePrintFactory::HasPrinterLine()
373 wxString
wxGnomePrintFactory::CreatePrinterLine()
376 return wxEmptyString
;
379 bool wxGnomePrintFactory::HasStatusLine()
385 wxString
wxGnomePrintFactory::CreateStatusLine()
388 return wxEmptyString
;
391 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
393 return new wxGnomePrintNativeData
;
396 //----------------------------------------------------------------------------
397 // wxGnomePrintSetupDialog
398 //----------------------------------------------------------------------------
400 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
402 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
403 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
404 wxPoint(0, 0), wxSize(600, 600),
405 wxDEFAULT_DIALOG_STYLE
|
409 m_printDialogData
= *data
;
414 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
415 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
416 wxPoint(0, 0), wxSize(600, 600),
417 wxDEFAULT_DIALOG_STYLE
|
421 m_printDialogData
= *data
;
426 void wxGnomePrintDialog::Init()
428 wxPrintData data
= m_printDialogData
.GetPrintData();
430 wxGnomePrintNativeData
*native
=
431 (wxGnomePrintNativeData
*) data
.GetNativeData();
433 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
435 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
438 if (m_printDialogData
.GetEnableSelection())
439 flag
|= GNOME_PRINT_RANGE_SELECTION
;
440 if (m_printDialogData
.GetEnablePageNumbers())
441 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
443 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
445 m_printDialogData
.GetMinPage(),
446 m_printDialogData
.GetMaxPage(),
451 wxGnomePrintDialog::~wxGnomePrintDialog()
456 int wxGnomePrintDialog::ShowModal()
458 // Transfer data from m_printDalogData to dialog here
460 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
462 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
464 gtk_widget_destroy(m_widget
);
471 gboolean collate
= false;
472 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
473 m_printDialogData
.SetNoCopies( copies
);
474 m_printDialogData
.SetCollate( collate
);
476 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
478 case GNOME_PRINT_RANGE_SELECTION
:
479 m_printDialogData
.SetSelection( true );
481 case GNOME_PRINT_RANGE_ALL
:
482 m_printDialogData
.SetAllPages( true );
483 m_printDialogData
.SetFromPage( 0 );
484 m_printDialogData
.SetToPage( 9999 );
486 case GNOME_PRINT_RANGE_RANGE
:
489 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
490 m_printDialogData
.SetFromPage( start
);
491 m_printDialogData
.SetToPage( end
);
495 gtk_widget_destroy(m_widget
);
498 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
504 wxDC
*wxGnomePrintDialog::GetPrintDC()
510 bool wxGnomePrintDialog::Validate()
515 bool wxGnomePrintDialog::TransferDataToWindow()
520 bool wxGnomePrintDialog::TransferDataFromWindow()
525 //----------------------------------------------------------------------------
526 // wxGnomePageSetupDialog
527 //----------------------------------------------------------------------------
529 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
531 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
532 wxPageSetupDialogData
* data
)
535 m_pageDialogData
= *data
;
537 wxGnomePrintNativeData
*native
=
538 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
540 // This is required as the page setup dialog
541 // calculates wrong values otherwise.
542 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
543 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
544 (const guchar
*) "Pts" );
546 m_widget
= gtk_dialog_new();
548 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
550 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
551 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
552 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
553 gtk_widget_show (main
);
555 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
557 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
559 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
560 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
561 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
564 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
568 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
572 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
574 return m_pageDialogData
;
577 int wxGnomePageSetupDialog::ShowModal()
579 wxGnomePrintNativeData
*native
=
580 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
581 GnomePrintConfig
*config
= native
->GetPrintConfig();
583 // Transfer data from m_pageDialogData to native dialog
585 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
587 if (ret
== GTK_RESPONSE_OK
)
589 // Transfer data back to m_pageDialogData
591 // I don't know how querying the last parameter works
592 // I cannot test it as the dialog is currently broken
593 // anyways (it only works for points).
594 double ml
,mr
,mt
,mb
,pw
,ph
;
595 gs_lgp
->gnome_print_config_get_length (config
,
596 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
597 gs_lgp
->gnome_print_config_get_length (config
,
598 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
599 gs_lgp
->gnome_print_config_get_length (config
,
600 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
601 gs_lgp
->gnome_print_config_get_length (config
,
602 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
603 gs_lgp
->gnome_print_config_get_length (config
,
604 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
605 gs_lgp
->gnome_print_config_get_length (config
,
606 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
608 // This probably assumes that the user entered the
609 // values in Pts. Since that is the only the dialog
610 // works right now, we need to fix this later.
611 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
612 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
613 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
614 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
615 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
616 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
617 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
618 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
620 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
621 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
623 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
626 wxPrintf( wxT("paper %d %d, top margin %d\n"),
627 m_pageDialogData
.GetPaperSize().x
,
628 m_pageDialogData
.GetPaperSize().y
,
629 m_pageDialogData
.GetMarginTopLeft().x
);
639 gtk_widget_destroy( m_widget
);
645 bool wxGnomePageSetupDialog::Validate()
650 bool wxGnomePageSetupDialog::TransferDataToWindow()
655 bool wxGnomePageSetupDialog::TransferDataFromWindow()
660 //----------------------------------------------------------------------------
662 //----------------------------------------------------------------------------
664 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
666 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
667 wxPrinterBase( data
)
670 m_native_preview
= false;
673 wxGnomePrinter::~wxGnomePrinter()
677 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
681 sm_lastError
= wxPRINTER_ERROR
;
685 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
686 wxGnomePrintNativeData
*native
=
687 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
689 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
690 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
692 // The GnomePrintJob is temporarily stored in the
693 // native print data as the native print dialog
694 // needs to access it.
695 native
->SetPrintJob( job
);
698 printout
->SetIsPreview(false);
700 if (m_printDialogData
.GetMinPage() < 1)
701 m_printDialogData
.SetMinPage(1);
702 if (m_printDialogData
.GetMaxPage() < 1)
703 m_printDialogData
.SetMaxPage(9999);
707 dc
= PrintDialog( parent
);
709 dc
= new wxGnomePrintDC( this );
711 if (m_native_preview
)
712 printout
->SetIsPreview(true);
716 gs_lgp
->gnome_print_job_close( job
);
717 g_object_unref (job
);
718 sm_lastError
= wxPRINTER_ERROR
;
722 wxSize ScreenPixels
= wxGetDisplaySize();
723 wxSize ScreenMM
= wxGetDisplaySizeMM();
725 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
726 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
727 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
728 wxGnomePrintDC::GetResolution() );
734 printout
->SetPageSizePixels((int)w
, (int)h
);
735 dc
->GetSizeMM(&w
, &h
);
736 printout
->SetPageSizeMM((int)w
, (int)h
);
738 printout
->OnPreparePrinting();
740 // Get some parameters from the printout, if defined
741 int fromPage
, toPage
;
742 int minPage
, maxPage
;
743 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
747 gs_lgp
->gnome_print_job_close( job
);
748 g_object_unref (job
);
749 sm_lastError
= wxPRINTER_ERROR
;
753 printout
->OnBeginPrinting();
755 int minPageNum
= minPage
, maxPageNum
= maxPage
;
757 if ( !m_printDialogData
.GetAllPages() )
759 minPageNum
= m_printDialogData
.GetFromPage();
760 maxPageNum
= m_printDialogData
.GetToPage();
766 copyCount
<= m_printDialogData
.GetNoCopies();
769 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
771 wxLogError(_("Could not start printing."));
772 sm_lastError
= wxPRINTER_ERROR
;
777 for ( pn
= minPageNum
;
778 pn
<= maxPageNum
&& printout
->HasPage(pn
);
782 printout
->OnPrintPage(pn
);
786 printout
->OnEndDocument();
787 printout
->OnEndPrinting();
790 gs_lgp
->gnome_print_job_close( job
);
791 if (m_native_preview
)
793 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
794 GtkWidget
*preview
= gs_lgp
->gnome_print_job_preview_new
797 (const guchar
*)title
.data()
799 gtk_widget_show(preview
);
803 gs_lgp
->gnome_print_job_print( job
);
806 g_object_unref (job
);
809 return (sm_lastError
== wxPRINTER_NO_ERROR
);
812 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
814 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
815 int ret
= dialog
.ShowModal();
816 if (ret
== wxID_CANCEL
)
818 sm_lastError
= wxPRINTER_CANCELLED
;
822 m_native_preview
= ret
== wxID_PREVIEW
;
824 m_printDialogData
= dialog
.GetPrintDialogData();
825 return new wxGnomePrintDC( this );
828 bool wxGnomePrinter::Setup( wxWindow
*parent
)
833 //-----------------------------------------------------------------------------
835 //-----------------------------------------------------------------------------
837 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
839 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
843 m_gpc
= printer
->GetPrintContext();
844 m_job
= NULL
; // only used and destroyed when created with wxPrintData
846 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
847 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
853 m_signX
= 1; // default x-axis left to right
854 m_signY
= -1; // default y-axis bottom up -> top down
857 wxGnomePrintDC::wxGnomePrintDC( const wxPrintData
& data
)
862 wxGnomePrintNativeData
*native
=
863 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
865 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
866 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
867 m_job
= job
; // only used and destroyed when created with wxPrintData
869 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
870 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
876 m_signX
= 1; // default x-axis left to right
877 m_signY
= -1; // default y-axis bottom up -> top down
880 wxGnomePrintDC::~wxGnomePrintDC()
883 g_object_unref (m_job
);
886 bool wxGnomePrintDC::IsOk() const
891 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
896 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
901 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
903 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
907 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
908 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
909 gs_lgp
->gnome_print_stroke ( m_gpc
);
911 CalcBoundingBox( x1
, y1
);
912 CalcBoundingBox( x2
, y2
);
915 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
919 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
923 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
924 double alpha1
, alpha2
;
925 if (x1
== x2
&& y1
== y2
)
933 alpha1
= alpha2
= 0.0;
937 alpha1
= (x1
- xc
== 0) ?
938 (y1
- yc
< 0) ? 90.0 : -90.0 :
939 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
940 alpha2
= (x2
- xc
== 0) ?
941 (y2
- yc
< 0) ? 90.0 : -90.0 :
942 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
944 while (alpha1
<= 0) alpha1
+= 360;
945 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
946 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
947 while (alpha2
> 360) alpha2
-= 360;
950 if (m_brush
.GetStyle() != wxTRANSPARENT
)
953 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
954 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
956 gs_lgp
->gnome_print_fill( m_gpc
);
959 if (m_pen
.GetStyle() != wxTRANSPARENT
)
962 gs_lgp
->gnome_print_newpath( m_gpc
);
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 );
965 gs_lgp
->gnome_print_closepath( m_gpc
);
967 gs_lgp
->gnome_print_stroke( m_gpc
);
970 CalcBoundingBox (x1
, y1
);
971 CalcBoundingBox (x2
, y2
);
972 CalcBoundingBox (xc
, yc
);
975 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
980 int xx
= XLOG2DEV(x
);
981 int yy
= YLOG2DEV(y
);
983 gs_lgp
->gnome_print_gsave( m_gpc
);
985 gs_lgp
->gnome_print_translate( m_gpc
, xx
, yy
);
986 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
987 gs_lgp
->gnome_print_scale( m_gpc
, 1.0, scale
);
992 if (m_brush
.GetStyle () != wxTRANSPARENT
)
996 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
997 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
998 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
999 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1001 gs_lgp
->gnome_print_fill( m_gpc
);
1004 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1008 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
1009 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1011 gs_lgp
->gnome_print_stroke( m_gpc
);
1014 gs_lgp
->gnome_print_grestore( m_gpc
);
1016 CalcBoundingBox( x
, y
);
1017 CalcBoundingBox( x
+w
, y
+h
);
1020 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1024 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1026 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1033 for ( i
=0; i
<n
; i
++ )
1034 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1036 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1038 for (i
= 1; i
< n
; i
++)
1039 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1041 gs_lgp
->gnome_print_stroke ( m_gpc
);
1044 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1048 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1050 SetBrush( m_brush
);
1052 int x
= points
[0].x
+ xoffset
;
1053 int y
= points
[0].y
+ yoffset
;
1054 CalcBoundingBox( x
, y
);
1055 gs_lgp
->gnome_print_newpath( m_gpc
);
1056 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1058 for (i
= 1; i
< n
; i
++)
1060 int x
= points
[i
].x
+ xoffset
;
1061 int y
= points
[i
].y
+ yoffset
;
1062 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1063 CalcBoundingBox( x
, y
);
1065 gs_lgp
->gnome_print_closepath( m_gpc
);
1066 gs_lgp
->gnome_print_fill( m_gpc
);
1069 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1073 int x
= points
[0].x
+ xoffset
;
1074 int y
= points
[0].y
+ yoffset
;
1075 gs_lgp
->gnome_print_newpath( m_gpc
);
1076 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1078 for (i
= 1; i
< n
; i
++)
1080 int x
= points
[i
].x
+ xoffset
;
1081 int y
= points
[i
].y
+ yoffset
;
1082 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1083 CalcBoundingBox( x
, y
);
1085 gs_lgp
->gnome_print_closepath( m_gpc
);
1086 gs_lgp
->gnome_print_stroke( m_gpc
);
1090 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1092 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1095 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1097 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1099 SetBrush( m_brush
);
1101 gs_lgp
->gnome_print_newpath( m_gpc
);
1102 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1103 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1104 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1105 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1106 gs_lgp
->gnome_print_closepath( m_gpc
);
1107 gs_lgp
->gnome_print_fill( m_gpc
);
1109 CalcBoundingBox( x
, y
);
1110 CalcBoundingBox( x
+ width
, y
+ height
);
1113 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1117 gs_lgp
->gnome_print_newpath( m_gpc
);
1118 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1119 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1120 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1121 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1122 gs_lgp
->gnome_print_closepath( m_gpc
);
1123 gs_lgp
->gnome_print_stroke( m_gpc
);
1125 CalcBoundingBox( x
, y
);
1126 CalcBoundingBox( x
+ width
, y
+ height
);
1130 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1132 wxCoord rad
= (wxCoord
) radius
;
1134 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1137 gs_lgp
->gnome_print_newpath(m_gpc
);
1138 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1139 gs_lgp
->gnome_print_curveto(m_gpc
,
1140 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1141 XLOG2DEV(x
),YLOG2DEV(y
),
1142 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1143 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1144 gs_lgp
->gnome_print_curveto(m_gpc
,
1145 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1146 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1147 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1148 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1149 gs_lgp
->gnome_print_curveto(m_gpc
,
1150 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1151 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1152 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1153 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1154 gs_lgp
->gnome_print_curveto(m_gpc
,
1155 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1156 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1157 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1158 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1159 gs_lgp
->gnome_print_closepath(m_gpc
);
1160 gs_lgp
->gnome_print_fill(m_gpc
);
1162 CalcBoundingBox(x
,y
);
1163 CalcBoundingBox(x
+width
,y
+height
);
1166 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1169 gs_lgp
->gnome_print_newpath(m_gpc
);
1170 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1171 gs_lgp
->gnome_print_curveto(m_gpc
,
1172 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1173 XLOG2DEV(x
),YLOG2DEV(y
),
1174 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1175 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1176 gs_lgp
->gnome_print_curveto(m_gpc
,
1177 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1178 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1179 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1180 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1181 gs_lgp
->gnome_print_curveto(m_gpc
,
1182 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1183 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1184 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1185 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1186 gs_lgp
->gnome_print_curveto(m_gpc
,
1187 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1188 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1189 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1190 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1191 gs_lgp
->gnome_print_closepath(m_gpc
);
1192 gs_lgp
->gnome_print_stroke(m_gpc
);
1194 CalcBoundingBox(x
,y
);
1195 CalcBoundingBox(x
+width
,y
+height
);
1199 void wxGnomePrintDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1200 wxCoord width
, wxCoord height
)
1202 double r
= 4 * (sqrt (2) - 1) / 3;
1203 double halfW
= 0.5 * width
,
1204 halfH
= 0.5 * height
,
1207 wxCoord halfWI
= (wxCoord
) halfW
,
1208 halfHI
= (wxCoord
) halfH
;
1210 gs_lgp
->gnome_print_newpath( m_gpc
);
1212 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1213 gs_lgp
->gnome_print_moveto( m_gpc
,
1214 XLOG2DEV(x
+ width
),
1215 YLOG2DEV(y
+ halfHI
) );
1216 gs_lgp
->gnome_print_curveto( m_gpc
,
1217 XLOG2DEV(x
+ width
),
1218 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1219 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1220 YLOG2DEV(y
+ height
),
1221 XLOG2DEV(x
+ halfWI
),
1222 YLOG2DEV(y
+ height
) );
1223 gs_lgp
->gnome_print_curveto( m_gpc
,
1224 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1225 YLOG2DEV(y
+ height
),
1227 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1228 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1229 gs_lgp
->gnome_print_curveto( m_gpc
,
1231 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1232 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1234 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1235 gs_lgp
->gnome_print_curveto( m_gpc
,
1236 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1238 XLOG2DEV(x
+ width
),
1239 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1240 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1242 gs_lgp
->gnome_print_closepath(m_gpc
);
1245 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1247 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1249 SetBrush( m_brush
);
1250 makeEllipticalPath( x
, y
, width
, height
);
1251 gs_lgp
->gnome_print_fill( m_gpc
);
1252 CalcBoundingBox( x
, y
);
1253 CalcBoundingBox( x
+ width
, y
+ height
);
1256 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1259 makeEllipticalPath( x
, y
, width
, height
);
1260 gs_lgp
->gnome_print_stroke( m_gpc
);
1261 CalcBoundingBox( x
, y
);
1262 CalcBoundingBox( x
+ width
, y
+ height
);
1267 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1271 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1274 wxList::compatibility_iterator node
= points
->GetFirst();
1275 p
= (wxPoint
*)node
->GetData();
1279 node
= node
->GetNext();
1280 p
= (wxPoint
*)node
->GetData();
1284 (double)(x1
+ c
) / 2;
1286 (double)(y1
+ d
) / 2;
1288 gs_lgp
->gnome_print_newpath( m_gpc
);
1289 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1290 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1292 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1293 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1295 node
= node
->GetNext();
1298 q
= (wxPoint
*)node
->GetData();
1306 x3
= (double)(x2
+ c
) / 2;
1307 y3
= (double)(y2
+ d
) / 2;
1309 gs_lgp
->gnome_print_curveto(m_gpc
,
1310 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1311 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1312 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1314 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1315 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1317 node
= node
->GetNext();
1320 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1322 gs_lgp
->gnome_print_stroke( m_gpc
);
1324 #endif // wxUSE_SPLINES
1326 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1327 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1328 wxCoord xsrcMask
, wxCoord ysrcMask
)
1330 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1332 // blit into a bitmap
1333 wxBitmap
bitmap( width
, height
);
1335 memDC
.SelectObject(bitmap
);
1336 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1337 memDC
.SelectObject(wxNullBitmap
);
1339 // draw bitmap. scaling and positioning is done there
1340 DrawBitmap( bitmap
, xdest
, ydest
);
1345 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1347 DoDrawBitmap( icon
, x
, y
, true );
1350 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1352 if (!bitmap
.Ok()) return;
1354 if (bitmap
.HasPixbuf())
1356 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1357 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1358 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1359 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1360 int height
= gdk_pixbuf_get_height( pixbuf
);
1361 int width
= gdk_pixbuf_get_width( pixbuf
);
1363 gs_lgp
->gnome_print_gsave( m_gpc
);
1365 matrix
[0] = XLOG2DEVREL(width
);
1368 matrix
[3] = YLOG2DEVREL(height
);
1369 matrix
[4] = XLOG2DEV(x
);
1370 matrix
[5] = YLOG2DEV(y
+height
);
1371 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1372 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1374 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1376 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1377 gs_lgp
->gnome_print_grestore( m_gpc
);
1381 wxImage image
= bitmap
.ConvertToImage();
1383 if (!image
.Ok()) return;
1385 gs_lgp
->gnome_print_gsave( m_gpc
);
1387 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1390 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1391 matrix
[4] = XLOG2DEV(x
);
1392 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1393 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1394 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1395 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1396 gs_lgp
->gnome_print_grestore( m_gpc
);
1400 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1402 DoDrawRotatedText( text
, x
, y
, 0.0 );
1405 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1410 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1413 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1415 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1418 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1421 size_t datalen
= strlen((const char*)data
);
1422 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1426 PangoAttrList
*attrs
= pango_attr_list_new();
1427 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1429 a
->end_index
= datalen
;
1430 pango_attr_list_insert(attrs
, a
);
1431 pango_layout_set_attributes(m_layout
, attrs
);
1432 pango_attr_list_unref(attrs
);
1435 if (m_textForegroundColour
.Ok())
1437 unsigned char red
= m_textForegroundColour
.Red();
1438 unsigned char blue
= m_textForegroundColour
.Blue();
1439 unsigned char green
= m_textForegroundColour
.Green();
1441 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1443 double redPS
= (double)(red
) / 255.0;
1444 double bluePS
= (double)(blue
) / 255.0;
1445 double greenPS
= (double)(green
) / 255.0;
1447 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1450 m_currentBlue
= blue
;
1451 m_currentGreen
= green
;
1457 if (fabs(m_scaleY
- 1.0) > 0.00001)
1459 // If there is a user or actually any scale applied to
1460 // the device context, scale the font.
1462 // scale font description
1463 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1464 double size
= oldSize
;
1465 size
= size
* m_scaleY
;
1466 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1468 // actually apply scaled font
1469 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1471 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1473 if ( m_backgroundMode
== wxSOLID
)
1475 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1476 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1477 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1481 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1482 if (fabs(angle
) > 0.00001)
1484 gs_lgp
->gnome_print_gsave( m_gpc
);
1485 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1486 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1487 gs_lgp
->gnome_print_grestore( m_gpc
);
1491 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1494 // reset unscaled size
1495 pango_font_description_set_size( m_fontdesc
, oldSize
);
1497 // actually apply unscaled font
1498 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1502 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1504 if ( m_backgroundMode
== wxSOLID
)
1506 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1507 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1508 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1512 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1513 if (fabs(angle
) > 0.00001)
1515 gs_lgp
->gnome_print_gsave( m_gpc
);
1516 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1517 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1518 gs_lgp
->gnome_print_grestore( m_gpc
);
1522 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1528 // undo underline attributes setting:
1529 pango_layout_set_attributes(m_layout
, NULL
);
1532 CalcBoundingBox (x
+ w
, y
+ h
);
1535 void wxGnomePrintDC::Clear()
1539 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1546 pango_font_description_free( m_fontdesc
);
1548 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1550 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1554 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1556 if (!pen
.Ok()) return;
1560 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1562 static const double dotted
[] = {2.0, 5.0};
1563 static const double short_dashed
[] = {4.0, 4.0};
1564 static const double wxCoord_dashed
[] = {4.0, 8.0};
1565 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1567 switch (m_pen
.GetStyle())
1569 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1570 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1571 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1572 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1575 // It may be noted that libgnomeprint between at least
1576 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1577 // and then leak the memory since it doesn't set the
1578 // internal flag "privatedash" to 0.
1580 int num
= m_pen
.GetDashes (&wx_dashes
);
1581 gdouble
*g_dashes
= g_new( gdouble
, num
);
1583 for (i
= 0; i
< num
; ++i
)
1584 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1585 gs_lgp
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1591 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1595 unsigned char red
= m_pen
.GetColour().Red();
1596 unsigned char blue
= m_pen
.GetColour().Blue();
1597 unsigned char green
= m_pen
.GetColour().Green();
1599 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1601 double redPS
= (double)(red
) / 255.0;
1602 double bluePS
= (double)(blue
) / 255.0;
1603 double greenPS
= (double)(green
) / 255.0;
1605 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1608 m_currentBlue
= blue
;
1609 m_currentGreen
= green
;
1613 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1615 if (!brush
.Ok()) return;
1620 unsigned char red
= m_brush
.GetColour().Red();
1621 unsigned char blue
= m_brush
.GetColour().Blue();
1622 unsigned char green
= m_brush
.GetColour().Green();
1626 // Anything not white is black
1627 if (! (red
== (unsigned char) 255 &&
1628 blue
== (unsigned char) 255 &&
1629 green
== (unsigned char) 255) )
1631 red
= (unsigned char) 0;
1632 green
= (unsigned char) 0;
1633 blue
= (unsigned char) 0;
1638 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1640 double redPS
= (double)(red
) / 255.0;
1641 double bluePS
= (double)(blue
) / 255.0;
1642 double greenPS
= (double)(green
) / 255.0;
1644 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1647 m_currentBlue
= blue
;
1648 m_currentGreen
= green
;
1652 void wxGnomePrintDC::SetLogicalFunction( int function
)
1656 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1660 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1664 void wxGnomePrintDC::DestroyClippingRegion()
1668 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1670 SetDeviceOrigin( 0,0 );
1675 void wxGnomePrintDC::EndDoc()
1677 gs_lgp
->gnome_print_end_doc( m_gpc
);
1680 void wxGnomePrintDC::StartPage()
1682 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1685 void wxGnomePrintDC::EndPage()
1687 gs_lgp
->gnome_print_showpage( m_gpc
);
1690 wxCoord
wxGnomePrintDC::GetCharHeight() const
1692 pango_layout_set_text( m_layout
, "H", 1 );
1695 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1700 wxCoord
wxGnomePrintDC::GetCharWidth() const
1702 pango_layout_set_text( m_layout
, "H", 1 );
1705 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1710 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1712 wxCoord
*externalLeading
,
1713 wxFont
*theFont
) const
1721 if ( externalLeading
)
1722 *externalLeading
= 0;
1729 // Set new font description
1731 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1733 // Set layout's text
1735 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1736 const char *dataUTF8
= (const char *)data
;
1738 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1741 if (width
) (*width
) = 0;
1742 if (height
) (*height
) = 0;
1745 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1746 const char *dataUTF8
= (const char *)data
;
1751 // hardly ideal, but what else can we do if conversion failed?
1755 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1758 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1761 *width
= (wxCoord
)(w
/ m_scaleX
);
1763 *height
= (wxCoord
)(h
/ m_scaleY
);
1766 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1767 int baseline
= pango_layout_iter_get_baseline(iter
);
1768 pango_layout_iter_free(iter
);
1769 *descent
= h
- PANGO_PIXELS(baseline
);
1772 // Reset old font description
1774 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1777 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1779 wxGnomePrintNativeData
*native
=
1780 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1782 // Query page size. This seems to omit the margins
1783 // right now, although it shouldn't
1785 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1788 *width
= (int) (pw
+ 0.5);
1790 *height
= (int) (ph
+ 0.5);
1793 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1795 wxGnomePrintNativeData
*native
=
1796 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1798 // This code assumes values in Pts.
1801 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1805 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1806 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1807 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1808 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1811 *width
= (int) (pw
+ 0.5);
1813 *height
= (int) (ph
+ 0.5);
1816 wxSize
wxGnomePrintDC::GetPPI() const
1818 return wxSize(72,72);
1821 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1823 m_signX
= (xLeftRight
? 1 : -1);
1824 m_signY
= (yBottomUp
? 1 : -1);
1826 ComputeScaleAndOrigin();
1829 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1835 wxDC::SetDeviceOrigin( x
, h
-y
);
1838 void wxGnomePrintDC::SetResolution(int ppi
)
1842 int wxGnomePrintDC::GetResolution()
1848 class wxGnomePrintModule
: public wxModule
1851 wxGnomePrintModule() {}
1856 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1859 bool wxGnomePrintModule::OnInit()
1861 gs_lgp
= new wxGnomePrintLibrary
;
1863 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1867 void wxGnomePrintModule::OnExit()
1872 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1874 // ----------------------------------------------------------------------------
1876 // ----------------------------------------------------------------------------
1878 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
1880 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
1881 wxPrintout
* WXUNUSED(printoutForPrinting
))
1886 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1887 wxPrintout
*printoutForPrinting
,
1888 wxPrintDialogData
*data
)
1889 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1891 Init(printout
, printoutForPrinting
);
1894 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1895 wxPrintout
*printoutForPrinting
,
1897 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1899 Init(printout
, printoutForPrinting
);
1902 wxGnomePrintPreview::~wxGnomePrintPreview()
1906 bool wxGnomePrintPreview::Print(bool interactive
)
1908 if (!m_printPrintout
)
1911 wxPrinter
printer(& m_printDialogData
);
1912 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
1915 void wxGnomePrintPreview::DetermineScaling()
1917 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
1918 if (paperType
== wxPAPER_NONE
)
1919 paperType
= wxPAPER_NONE
;
1921 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1923 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1927 wxSize ScreenPixels
= wxGetDisplaySize();
1928 wxSize ScreenMM
= wxGetDisplaySizeMM();
1930 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
1931 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
1932 m_previewPrintout
->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
1934 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
1936 // TODO: get better resolution information from wxGnomePrintDC, if possible.
1938 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGnomePrintDC::GetResolution() / 72.0);
1939 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGnomePrintDC::GetResolution() / 72.0);
1940 wxSize
sizeTenthsMM(paper
->GetSize());
1941 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
1943 // If in landscape mode, we need to swap the width and height.
1944 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
1946 m_pageWidth
= sizeDevUnits
.y
;
1947 m_pageHeight
= sizeDevUnits
.x
;
1948 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
1949 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
1953 m_pageWidth
= sizeDevUnits
.x
;
1954 m_pageHeight
= sizeDevUnits
.y
;
1955 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
1956 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
1959 // At 100%, the page should look about page-size on the screen.
1960 m_previewScale
= (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
1965 // wxUSE_LIBGNOMEPRINT