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"
35 #include <libgnomeprint/gnome-print.h>
36 #include <libgnomeprint/gnome-print-pango.h>
37 #include <libgnomeprint/gnome-print-config.h>
38 #include <libgnomeprintui/gnome-print-dialog.h>
39 #include <libgnomeprintui/gnome-print-job-preview.h>
40 #include <libgnomeprintui/gnome-print-paper-selector.h>
42 static const double RAD2DEG
= 180.0 / M_PI
;
44 #include "wx/html/forcelnk.h"
45 FORCE_LINK_ME(gnome_print
)
47 //----------------------------------------------------------------------------
48 // wxGnomePrintLibrary
49 //----------------------------------------------------------------------------
51 #define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \
52 typedef rettype (* name ## Type) args ; \
53 name ## Type pfn_ ## name; \
55 { if (m_ok) return pfn_ ## name shortargs ; return defret; }
57 #define wxDL_METHOD_LOAD( lib, name, success ) \
58 pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \
61 class wxGnomePrintLibrary
64 wxGnomePrintLibrary();
65 ~wxGnomePrintLibrary();
68 void InitializeMethods();
72 wxDynamicLibrary
*m_gnome_print_lib
;
73 wxDynamicLibrary
*m_gnome_printui_lib
;
76 wxDL_METHOD_DEFINE( gint
, gnome_print_newpath
,
77 (GnomePrintContext
*pc
), (pc
), 0 )
78 wxDL_METHOD_DEFINE( gint
, gnome_print_moveto
,
79 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
80 wxDL_METHOD_DEFINE( gint
, gnome_print_lineto
,
81 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
82 wxDL_METHOD_DEFINE( gint
, gnome_print_arcto
,
83 (GnomePrintContext
*pc
, gdouble x
, gdouble y
, gdouble radius
, gdouble angle1
, gdouble angle2
, gint direction
), (pc
, x
, y
, radius
, angle1
, angle2
, direction
), 0 )
84 wxDL_METHOD_DEFINE( gint
, gnome_print_curveto
,
85 (GnomePrintContext
*pc
, gdouble x1
, gdouble y1
, gdouble x2
, gdouble y2
, gdouble x3
, gdouble y3
), (pc
, x1
, y1
, x2
, y2
, x3
, y3
), 0 )
86 wxDL_METHOD_DEFINE( gint
, gnome_print_closepath
,
87 (GnomePrintContext
*pc
), (pc
), 0 )
88 wxDL_METHOD_DEFINE( gint
, gnome_print_stroke
,
89 (GnomePrintContext
*pc
), (pc
), 0 )
90 wxDL_METHOD_DEFINE( gint
, gnome_print_fill
,
91 (GnomePrintContext
*pc
), (pc
), 0 )
92 wxDL_METHOD_DEFINE( gint
, gnome_print_setrgbcolor
,
93 (GnomePrintContext
*pc
, gdouble r
, gdouble g
, gdouble b
), (pc
, r
, g
, b
), 0 )
94 wxDL_METHOD_DEFINE( gint
, gnome_print_setlinewidth
,
95 (GnomePrintContext
*pc
, gdouble width
), (pc
, width
), 0 )
96 wxDL_METHOD_DEFINE( gint
, gnome_print_setdash
,
97 (GnomePrintContext
*pc
, gint n_values
, const gdouble
*values
, gdouble offset
), (pc
, n_values
, values
, offset
), 0 )
99 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbimage
,
100 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
101 wxDL_METHOD_DEFINE( gint
, gnome_print_rgbaimage
,
102 (GnomePrintContext
*pc
, const guchar
*data
, gint width
, gint height
, gint rowstride
), (pc
, data
, width
, height
, rowstride
), 0 )
104 wxDL_METHOD_DEFINE( gint
, gnome_print_concat
,
105 (GnomePrintContext
*pc
, const gdouble
*matrix
), (pc
, matrix
), 0 )
106 wxDL_METHOD_DEFINE( gint
, gnome_print_scale
,
107 (GnomePrintContext
*pc
, gdouble sx
, gdouble sy
), (pc
, sx
, sy
), 0 )
108 wxDL_METHOD_DEFINE( gint
, gnome_print_rotate
,
109 (GnomePrintContext
*pc
, gdouble theta
), (pc
, theta
), 0 )
110 wxDL_METHOD_DEFINE( gint
, gnome_print_translate
,
111 (GnomePrintContext
*pc
, gdouble x
, gdouble y
), (pc
, x
, y
), 0 )
113 wxDL_METHOD_DEFINE( gint
, gnome_print_gsave
,
114 (GnomePrintContext
*pc
), (pc
), 0 )
115 wxDL_METHOD_DEFINE( gint
, gnome_print_grestore
,
116 (GnomePrintContext
*pc
), (pc
), 0 )
118 wxDL_METHOD_DEFINE( gint
, gnome_print_beginpage
,
119 (GnomePrintContext
*pc
, const guchar
* name
), (pc
, name
), 0 )
120 wxDL_METHOD_DEFINE( gint
, gnome_print_showpage
,
121 (GnomePrintContext
*pc
), (pc
), 0 )
122 wxDL_METHOD_DEFINE( gint
, gnome_print_end_doc
,
123 (GnomePrintContext
*pc
), (pc
), 0 )
125 wxDL_METHOD_DEFINE( PangoLayout
*, gnome_print_pango_create_layout
,
126 (GnomePrintContext
*gpc
), (gpc
), NULL
)
127 wxDL_METHOD_DEFINE( void, gnome_print_pango_layout
,
128 (GnomePrintContext
*gpc
, PangoLayout
*layout
), (gpc
, layout
), /**/ )
130 wxDL_METHOD_DEFINE( GnomePrintJob
*, gnome_print_job_new
,
131 (GnomePrintConfig
*config
), (config
), NULL
)
132 wxDL_METHOD_DEFINE( GnomePrintContext
*, gnome_print_job_get_context
,
133 (GnomePrintJob
*job
), (job
), NULL
)
134 wxDL_METHOD_DEFINE( gint
, gnome_print_job_close
,
135 (GnomePrintJob
*job
), (job
), 0 )
136 wxDL_METHOD_DEFINE( gint
, gnome_print_job_print
,
137 (GnomePrintJob
*job
), (job
), 0 )
138 wxDL_METHOD_DEFINE( gboolean
, gnome_print_job_get_page_size
,
139 (GnomePrintJob
*job
, gdouble
*width
, gdouble
*height
), (job
, width
, height
), 0 )
141 wxDL_METHOD_DEFINE( GnomePrintUnit
*, gnome_print_unit_get_by_abbreviation
,
142 (const guchar
*abbreviation
), (abbreviation
), NULL
)
143 wxDL_METHOD_DEFINE( gboolean
, gnome_print_convert_distance
,
144 (gdouble
*distance
, const GnomePrintUnit
*from
, const GnomePrintUnit
*to
), (distance
, from
, to
), false )
146 wxDL_METHOD_DEFINE( GnomePrintConfig
*, gnome_print_config_default
,
148 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_set
,
149 (GnomePrintConfig
*config
, const guchar
*key
, const guchar
*value
), (config
, key
, value
), false )
150 wxDL_METHOD_DEFINE( gboolean
, gnome_print_config_get_length
,
151 (GnomePrintConfig
*config
, const guchar
*key
, gdouble
*val
, const GnomePrintUnit
**unit
), (config
, key
, val
, unit
), false )
153 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_dialog_new
,
154 (GnomePrintJob
*gpj
, const guchar
*title
, gint flags
), (gpj
, title
, flags
), NULL
)
155 wxDL_METHOD_DEFINE( void, gnome_print_dialog_construct_range_page
,
156 (GnomePrintDialog
*gpd
, gint flags
, gint start
, gint end
,
157 const guchar
*currentlabel
, const guchar
*rangelabel
),
158 (gpd
, flags
, start
, end
, currentlabel
, rangelabel
), /**/ )
159 wxDL_METHOD_DEFINE( void, gnome_print_dialog_get_copies
,
160 (GnomePrintDialog
*gpd
, gint
*copies
, gboolean
*collate
), (gpd
, copies
, collate
), /**/ )
161 wxDL_METHOD_DEFINE( void, gnome_print_dialog_set_copies
,
162 (GnomePrintDialog
*gpd
, gint copies
, gint collate
), (gpd
, copies
, collate
), /**/ )
163 wxDL_METHOD_DEFINE( GnomePrintRangeType
, gnome_print_dialog_get_range
,
164 (GnomePrintDialog
*gpd
), (gpd
), GNOME_PRINT_RANGETYPE_NONE
)
165 wxDL_METHOD_DEFINE( int, gnome_print_dialog_get_range_page
,
166 (GnomePrintDialog
*gpd
, gint
*start
, gint
*end
), (gpd
, start
, end
), 0 )
168 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_paper_selector_new_with_flags
,
169 (GnomePrintConfig
*config
, gint flags
), (config
, flags
), NULL
)
171 wxDL_METHOD_DEFINE( GtkWidget
*, gnome_print_job_preview_new
,
172 (GnomePrintJob
*gpm
, const guchar
*title
), (gpm
, title
), NULL
)
175 wxGnomePrintLibrary::wxGnomePrintLibrary()
177 m_gnome_print_lib
= NULL
;
178 m_gnome_printui_lib
= NULL
;
182 m_gnome_print_lib
= new wxDynamicLibrary( wxT("libgnomeprint-2-2.so.0") );
183 m_ok
= m_gnome_print_lib
->IsLoaded();
186 m_gnome_printui_lib
= new wxDynamicLibrary( wxT("libgnomeprintui-2-2.so.0") );
187 m_ok
= m_gnome_printui_lib
->IsLoaded();
193 wxGnomePrintLibrary::~wxGnomePrintLibrary()
195 if (m_gnome_print_lib
)
196 delete m_gnome_print_lib
;
197 if (m_gnome_printui_lib
)
198 delete m_gnome_printui_lib
;
201 bool wxGnomePrintLibrary::IsOk()
206 void wxGnomePrintLibrary::InitializeMethods()
211 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_newpath
, success
)
212 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_moveto
, success
)
213 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_lineto
, success
)
214 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_curveto
, success
)
215 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_arcto
, success
)
216 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_closepath
, success
)
217 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_stroke
, success
)
218 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_fill
, success
)
219 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setrgbcolor
, success
)
220 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setlinewidth
, success
)
221 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_setdash
, success
)
223 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbimage
, success
)
224 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rgbaimage
, success
)
226 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_concat
, success
)
227 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_scale
, success
)
228 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_rotate
, success
)
229 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_translate
, success
)
231 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_gsave
, success
)
232 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_grestore
, success
)
234 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_beginpage
, success
)
235 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_showpage
, success
)
236 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_end_doc
, success
)
238 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_create_layout
, success
)
239 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_pango_layout
, success
)
241 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_new
, success
)
242 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_context
, success
)
243 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_close
, success
)
244 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_print
, success
)
245 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_job_get_page_size
, success
)
247 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_unit_get_by_abbreviation
, success
)
248 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_convert_distance
, success
)
250 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_default
, success
)
251 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_set
, success
)
252 wxDL_METHOD_LOAD( m_gnome_print_lib
, gnome_print_config_get_length
, success
)
254 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_new
, success
)
255 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_construct_range_page
, success
)
256 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_copies
, success
)
257 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_set_copies
, success
)
258 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range
, success
)
259 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_dialog_get_range_page
, success
)
261 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_paper_selector_new_with_flags
, success
)
263 wxDL_METHOD_LOAD( m_gnome_printui_lib
, gnome_print_job_preview_new
, success
)
268 static wxGnomePrintLibrary
* gs_lgp
= NULL
;
270 //----------------------------------------------------------------------------
271 // wxGnomePrintNativeData
272 //----------------------------------------------------------------------------
274 IMPLEMENT_CLASS(wxGnomePrintNativeData
, wxPrintNativeDataBase
)
276 wxGnomePrintNativeData::wxGnomePrintNativeData()
278 m_config
= gs_lgp
->gnome_print_config_default();
279 m_job
= gs_lgp
->gnome_print_job_new( m_config
);
282 wxGnomePrintNativeData::~wxGnomePrintNativeData()
284 g_object_unref (m_config
);
287 bool wxGnomePrintNativeData::TransferTo( wxPrintData
&data
)
293 bool wxGnomePrintNativeData::TransferFrom( const wxPrintData
&data
)
299 //----------------------------------------------------------------------------
300 // wxGnomePrintFactory
301 //----------------------------------------------------------------------------
303 wxPrinterBase
* wxGnomePrintFactory::CreatePrinter( wxPrintDialogData
*data
)
305 return new wxGnomePrinter( data
);
308 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
309 wxPrintout
*printout
,
310 wxPrintDialogData
*data
)
312 return new wxGnomePrintPreview( preview
, printout
, data
);
315 wxPrintPreviewBase
*wxGnomePrintFactory::CreatePrintPreview( wxPrintout
*preview
,
316 wxPrintout
*printout
,
319 return new wxGnomePrintPreview( preview
, printout
, data
);
322 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
323 wxPrintDialogData
*data
)
325 return new wxGnomePrintDialog( parent
, data
);
328 wxPrintDialogBase
*wxGnomePrintFactory::CreatePrintDialog( wxWindow
*parent
,
331 return new wxGnomePrintDialog( parent
, data
);
334 wxPageSetupDialogBase
*wxGnomePrintFactory::CreatePageSetupDialog( wxWindow
*parent
,
335 wxPageSetupDialogData
* data
)
337 // The native page setup dialog is broken. It
338 // miscalculates newly entered values for the
339 // margins if you have not chose "points" but
340 // e.g. centimerters.
341 // This has been fixed in GNOME CVS (maybe
342 // fixed in libgnomeprintui 2.8.1)
344 return new wxGnomePageSetupDialog( parent
, data
);
347 bool wxGnomePrintFactory::HasPrintSetupDialog()
352 wxDialog
*wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
)
357 wxDC
* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData
& data
)
359 return new wxGnomePrintDC(data
);
362 bool wxGnomePrintFactory::HasOwnPrintToFile()
367 bool wxGnomePrintFactory::HasPrinterLine()
372 wxString
wxGnomePrintFactory::CreatePrinterLine()
375 return wxEmptyString
;
378 bool wxGnomePrintFactory::HasStatusLine()
384 wxString
wxGnomePrintFactory::CreateStatusLine()
387 return wxEmptyString
;
390 wxPrintNativeDataBase
*wxGnomePrintFactory::CreatePrintNativeData()
392 return new wxGnomePrintNativeData
;
395 //----------------------------------------------------------------------------
396 // wxGnomePrintSetupDialog
397 //----------------------------------------------------------------------------
399 IMPLEMENT_CLASS(wxGnomePrintDialog
, wxPrintDialogBase
)
401 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintDialogData
*data
)
402 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
403 wxPoint(0, 0), wxSize(600, 600),
404 wxDEFAULT_DIALOG_STYLE
|
408 m_printDialogData
= *data
;
413 wxGnomePrintDialog::wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
*data
)
414 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
415 wxPoint(0, 0), wxSize(600, 600),
416 wxDEFAULT_DIALOG_STYLE
|
420 m_printDialogData
= *data
;
425 void wxGnomePrintDialog::Init()
427 wxPrintData data
= m_printDialogData
.GetPrintData();
429 wxGnomePrintNativeData
*native
=
430 (wxGnomePrintNativeData
*) data
.GetNativeData();
432 m_widget
= gs_lgp
->gnome_print_dialog_new( native
->GetPrintJob(),
434 GNOME_PRINT_DIALOG_RANGE
|GNOME_PRINT_DIALOG_COPIES
);
437 if (m_printDialogData
.GetEnableSelection())
438 flag
|= GNOME_PRINT_RANGE_SELECTION
;
439 if (m_printDialogData
.GetEnablePageNumbers())
440 flag
|= GNOME_PRINT_RANGE_ALL
|GNOME_PRINT_RANGE_RANGE
;
442 gs_lgp
->gnome_print_dialog_construct_range_page( (GnomePrintDialog
*) m_widget
,
444 m_printDialogData
.GetMinPage(),
445 m_printDialogData
.GetMaxPage(),
450 wxGnomePrintDialog::~wxGnomePrintDialog()
455 int wxGnomePrintDialog::ShowModal()
457 // Transfer data from m_printDalogData to dialog here
459 int response
= gtk_dialog_run (GTK_DIALOG (m_widget
));
461 if (response
== GNOME_PRINT_DIALOG_RESPONSE_CANCEL
)
463 gtk_widget_destroy(m_widget
);
470 gboolean collate
= false;
471 gs_lgp
->gnome_print_dialog_get_copies( (GnomePrintDialog
*) m_widget
, &copies
, &collate
);
472 m_printDialogData
.SetNoCopies( copies
);
473 m_printDialogData
.SetCollate( collate
);
475 switch (gs_lgp
->gnome_print_dialog_get_range( (GnomePrintDialog
*) m_widget
))
477 case GNOME_PRINT_RANGE_SELECTION
:
478 m_printDialogData
.SetSelection( true );
480 case GNOME_PRINT_RANGE_ALL
:
481 m_printDialogData
.SetAllPages( true );
482 m_printDialogData
.SetFromPage( 0 );
483 m_printDialogData
.SetToPage( 9999 );
485 case GNOME_PRINT_RANGE_RANGE
:
488 gs_lgp
->gnome_print_dialog_get_range_page( (GnomePrintDialog
*) m_widget
, &start
, &end
);
489 m_printDialogData
.SetFromPage( start
);
490 m_printDialogData
.SetToPage( end
);
494 gtk_widget_destroy(m_widget
);
497 if (response
== GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
)
503 wxDC
*wxGnomePrintDialog::GetPrintDC()
509 bool wxGnomePrintDialog::Validate()
514 bool wxGnomePrintDialog::TransferDataToWindow()
519 bool wxGnomePrintDialog::TransferDataFromWindow()
524 //----------------------------------------------------------------------------
525 // wxGnomePageSetupDialog
526 //----------------------------------------------------------------------------
528 IMPLEMENT_CLASS(wxGnomePageSetupDialog
, wxPageSetupDialogBase
)
530 wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow
*parent
,
531 wxPageSetupDialogData
* data
)
534 m_pageDialogData
= *data
;
536 wxGnomePrintNativeData
*native
=
537 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
539 // This is required as the page setup dialog
540 // calculates wrong values otherwise.
541 gs_lgp
->gnome_print_config_set( native
->GetPrintConfig(),
542 (const guchar
*) GNOME_PRINT_KEY_PREFERED_UNIT
,
543 (const guchar
*) "Pts" );
545 m_widget
= gtk_dialog_new();
547 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( _("Page setup") ) );
549 GtkWidget
*main
= gs_lgp
->gnome_paper_selector_new_with_flags( native
->GetPrintConfig(),
550 GNOME_PAPER_SELECTOR_MARGINS
|GNOME_PAPER_SELECTOR_FEED_ORIENTATION
);
551 gtk_container_set_border_width (GTK_CONTAINER (main
), 8);
552 gtk_widget_show (main
);
554 gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget
)->vbox
), main
);
556 gtk_dialog_set_has_separator (GTK_DIALOG (m_widget
), TRUE
);
558 gtk_dialog_add_buttons (GTK_DIALOG (m_widget
),
559 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
560 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
563 gtk_dialog_set_default_response (GTK_DIALOG (m_widget
),
567 wxGnomePageSetupDialog::~wxGnomePageSetupDialog()
571 wxPageSetupDialogData
& wxGnomePageSetupDialog::GetPageSetupDialogData()
573 return m_pageDialogData
;
576 int wxGnomePageSetupDialog::ShowModal()
578 wxGnomePrintNativeData
*native
=
579 (wxGnomePrintNativeData
*) m_pageDialogData
.GetPrintData().GetNativeData();
580 GnomePrintConfig
*config
= native
->GetPrintConfig();
582 // Transfer data from m_pageDialogData to native dialog
584 int ret
= gtk_dialog_run( GTK_DIALOG(m_widget
) );
586 if (ret
== GTK_RESPONSE_OK
)
588 // Transfer data back to m_pageDialogData
590 // I don't know how querying the last parameter works
591 // I cannot test it as the dialog is currently broken
592 // anyways (it only works for points).
593 double ml
,mr
,mt
,mb
,pw
,ph
;
594 gs_lgp
->gnome_print_config_get_length (config
,
595 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT
, &ml
, NULL
);
596 gs_lgp
->gnome_print_config_get_length (config
,
597 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT
, &mr
, NULL
);
598 gs_lgp
->gnome_print_config_get_length (config
,
599 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP
, &mt
, NULL
);
600 gs_lgp
->gnome_print_config_get_length (config
,
601 (const guchar
*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM
, &mb
, NULL
);
602 gs_lgp
->gnome_print_config_get_length (config
,
603 (const guchar
*) GNOME_PRINT_KEY_PAPER_WIDTH
, &pw
, NULL
);
604 gs_lgp
->gnome_print_config_get_length (config
,
605 (const guchar
*) GNOME_PRINT_KEY_PAPER_HEIGHT
, &ph
, NULL
);
607 // This probably assumes that the user entered the
608 // values in Pts. Since that is the only the dialog
609 // works right now, we need to fix this later.
610 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
611 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
612 gs_lgp
->gnome_print_convert_distance( &ml
, pts_unit
, mm_unit
);
613 gs_lgp
->gnome_print_convert_distance( &mr
, pts_unit
, mm_unit
);
614 gs_lgp
->gnome_print_convert_distance( &mt
, pts_unit
, mm_unit
);
615 gs_lgp
->gnome_print_convert_distance( &mb
, pts_unit
, mm_unit
);
616 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
617 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
619 m_pageDialogData
.SetMarginTopLeft( wxPoint( (int)(ml
+0.5), (int)(mt
+0.5)) );
620 m_pageDialogData
.SetMarginBottomRight( wxPoint( (int)(mr
+0.5), (int)(mb
+0.5)) );
622 m_pageDialogData
.SetPaperSize( wxSize( (int)(pw
+0.5), (int)(ph
+0.5) ) );
625 wxPrintf( wxT("paper %d %d, top margin %d\n"),
626 m_pageDialogData
.GetPaperSize().x
,
627 m_pageDialogData
.GetPaperSize().y
,
628 m_pageDialogData
.GetMarginTopLeft().x
);
638 gtk_widget_destroy( m_widget
);
644 bool wxGnomePageSetupDialog::Validate()
649 bool wxGnomePageSetupDialog::TransferDataToWindow()
654 bool wxGnomePageSetupDialog::TransferDataFromWindow()
659 //----------------------------------------------------------------------------
661 //----------------------------------------------------------------------------
663 IMPLEMENT_CLASS(wxGnomePrinter
, wxPrinterBase
)
665 wxGnomePrinter::wxGnomePrinter( wxPrintDialogData
*data
) :
666 wxPrinterBase( data
)
669 m_native_preview
= false;
672 wxGnomePrinter::~wxGnomePrinter()
676 bool wxGnomePrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
680 sm_lastError
= wxPRINTER_ERROR
;
684 wxPrintData printdata
= GetPrintDialogData().GetPrintData();
685 wxGnomePrintNativeData
*native
=
686 (wxGnomePrintNativeData
*) printdata
.GetNativeData();
688 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
689 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
691 // The GnomePrintJob is temporarily stored in the
692 // native print data as the native print dialog
693 // needs to access it.
694 native
->SetPrintJob( job
);
697 printout
->SetIsPreview(false);
699 if (m_printDialogData
.GetMinPage() < 1)
700 m_printDialogData
.SetMinPage(1);
701 if (m_printDialogData
.GetMaxPage() < 1)
702 m_printDialogData
.SetMaxPage(9999);
706 dc
= PrintDialog( parent
);
708 dc
= new wxGnomePrintDC( this );
710 if (m_native_preview
)
711 printout
->SetIsPreview(true);
715 gs_lgp
->gnome_print_job_close( job
);
716 g_object_unref (job
);
717 sm_lastError
= wxPRINTER_ERROR
;
721 wxSize ScreenPixels
= wxGetDisplaySize();
722 wxSize ScreenMM
= wxGetDisplaySizeMM();
724 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
725 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
726 printout
->SetPPIPrinter( wxGnomePrintDC::GetResolution(),
727 wxGnomePrintDC::GetResolution() );
733 printout
->SetPageSizePixels((int)w
, (int)h
);
734 dc
->GetSizeMM(&w
, &h
);
735 printout
->SetPageSizeMM((int)w
, (int)h
);
737 printout
->OnPreparePrinting();
739 // Get some parameters from the printout, if defined
740 int fromPage
, toPage
;
741 int minPage
, maxPage
;
742 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
746 gs_lgp
->gnome_print_job_close( job
);
747 g_object_unref (job
);
748 sm_lastError
= wxPRINTER_ERROR
;
752 printout
->OnBeginPrinting();
754 int minPageNum
= minPage
, maxPageNum
= maxPage
;
756 if ( !m_printDialogData
.GetAllPages() )
758 minPageNum
= m_printDialogData
.GetFromPage();
759 maxPageNum
= m_printDialogData
.GetToPage();
765 copyCount
<= m_printDialogData
.GetNoCopies();
768 if (!printout
->OnBeginDocument(minPageNum
, maxPageNum
))
770 wxLogError(_("Could not start printing."));
771 sm_lastError
= wxPRINTER_ERROR
;
776 for ( pn
= minPageNum
;
777 pn
<= maxPageNum
&& printout
->HasPage(pn
);
781 printout
->OnPrintPage(pn
);
785 printout
->OnEndDocument();
786 printout
->OnEndPrinting();
789 gs_lgp
->gnome_print_job_close( job
);
790 if (m_native_preview
)
792 const wxCharBuffer
title(wxGTK_CONV_SYS(_("Print preview")));
793 GtkWidget
*preview
= gs_lgp
->gnome_print_job_preview_new
796 (const guchar
*)title
.data()
798 gtk_widget_show(preview
);
802 gs_lgp
->gnome_print_job_print( job
);
805 g_object_unref (job
);
808 return (sm_lastError
== wxPRINTER_NO_ERROR
);
811 wxDC
* wxGnomePrinter::PrintDialog( wxWindow
*parent
)
813 wxGnomePrintDialog
dialog( parent
, &m_printDialogData
);
814 int ret
= dialog
.ShowModal();
815 if (ret
== wxID_CANCEL
)
817 sm_lastError
= wxPRINTER_CANCELLED
;
821 m_native_preview
= ret
== wxID_PREVIEW
;
823 m_printDialogData
= dialog
.GetPrintDialogData();
824 return new wxGnomePrintDC( this );
827 bool wxGnomePrinter::Setup( wxWindow
*parent
)
832 //-----------------------------------------------------------------------------
834 //-----------------------------------------------------------------------------
836 IMPLEMENT_CLASS(wxGnomePrintDC
, wxDC
)
838 wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter
*printer
)
842 m_gpc
= printer
->GetPrintContext();
843 m_job
= NULL
; // only used and destroyed when created with wxPrintData
845 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
846 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
852 m_signX
= 1; // default x-axis left to right
853 m_signY
= -1; // default y-axis bottom up -> top down
856 wxGnomePrintDC::wxGnomePrintDC( const wxPrintData
& data
)
861 wxGnomePrintNativeData
*native
=
862 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
864 GnomePrintJob
*job
= gs_lgp
->gnome_print_job_new( native
->GetPrintConfig() );
865 m_gpc
= gs_lgp
->gnome_print_job_get_context (job
);
866 m_job
= job
; // only used and destroyed when created with wxPrintData
868 m_layout
= gs_lgp
->gnome_print_pango_create_layout( m_gpc
);
869 m_fontdesc
= pango_font_description_from_string( "Sans 12" );
875 m_signX
= 1; // default x-axis left to right
876 m_signY
= -1; // default y-axis bottom up -> top down
879 wxGnomePrintDC::~wxGnomePrintDC()
882 g_object_unref (job
);
885 bool wxGnomePrintDC::IsOk() const
890 bool wxGnomePrintDC::DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
)
895 bool wxGnomePrintDC::DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const
900 void wxGnomePrintDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
902 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
906 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(x1
), YLOG2DEV(y1
) );
907 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(x2
), YLOG2DEV(y2
) );
908 gs_lgp
->gnome_print_stroke ( m_gpc
);
910 CalcBoundingBox( x1
, y1
);
911 CalcBoundingBox( x2
, y2
);
914 void wxGnomePrintDC::DoCrossHair(wxCoord x
, wxCoord y
)
918 void wxGnomePrintDC::DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
)
922 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
923 double alpha1
, alpha2
;
924 if (x1
== x2
&& y1
== y2
)
932 alpha1
= alpha2
= 0.0;
936 alpha1
= (x1
- xc
== 0) ?
937 (y1
- yc
< 0) ? 90.0 : -90.0 :
938 -atan2(double(y1
-yc
), double(x1
-xc
)) * RAD2DEG
;
939 alpha2
= (x2
- xc
== 0) ?
940 (y2
- yc
< 0) ? 90.0 : -90.0 :
941 -atan2(double(y2
-yc
), double(x2
-xc
)) * RAD2DEG
;
943 while (alpha1
<= 0) alpha1
+= 360;
944 while (alpha2
<= 0) alpha2
+= 360; // adjust angles to be between
945 while (alpha1
> 360) alpha1
-= 360; // 0 and 360 degree
946 while (alpha2
> 360) alpha2
-= 360;
949 if (m_brush
.GetStyle() != wxTRANSPARENT
)
952 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
953 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
955 gs_lgp
->gnome_print_fill( m_gpc
);
958 if (m_pen
.GetStyle() != wxTRANSPARENT
)
961 gs_lgp
->gnome_print_newpath( m_gpc
);
962 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
) );
963 gs_lgp
->gnome_print_arcto( m_gpc
, XLOG2DEV(xc
), YLOG2DEV(yc
), XLOG2DEVREL((int)radius
), alpha1
, alpha2
, 0 );
964 gs_lgp
->gnome_print_closepath( m_gpc
);
966 gs_lgp
->gnome_print_stroke( m_gpc
);
969 CalcBoundingBox (x1
, y1
);
970 CalcBoundingBox (x2
, y2
);
971 CalcBoundingBox (xc
, yc
);
974 void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
979 int xx
= XLOG2DEV(x
);
980 int yy
= YLOG2DEV(y
);
982 gs_lgp
->gnome_print_gsave( m_gpc
);
984 gs_lgp
->gnome_print_translate( m_gpc
, xx
, yy
);
985 double scale
= (double)YLOG2DEVREL(h
) / (double) XLOG2DEVREL(w
);
986 gs_lgp
->gnome_print_scale( m_gpc
, 1.0, scale
);
991 if (m_brush
.GetStyle () != wxTRANSPARENT
)
995 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
996 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
997 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
998 gs_lgp
->gnome_print_moveto ( m_gpc
, xx
, yy
);
1000 gs_lgp
->gnome_print_fill( m_gpc
);
1003 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1007 gs_lgp
->gnome_print_arcto( m_gpc
, xx
, yy
,
1008 XLOG2DEVREL(w
)/2, sa
, ea
, 0 );
1010 gs_lgp
->gnome_print_stroke( m_gpc
);
1013 gs_lgp
->gnome_print_grestore( m_gpc
);
1015 CalcBoundingBox( x
, y
);
1016 CalcBoundingBox( x
+w
, y
+h
);
1019 void wxGnomePrintDC::DoDrawPoint(wxCoord x
, wxCoord y
)
1023 void wxGnomePrintDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
1025 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
1032 for ( i
=0; i
<n
; i
++ )
1033 CalcBoundingBox( points
[i
].x
+xoffset
, points
[i
].y
+yoffset
);
1035 gs_lgp
->gnome_print_moveto ( m_gpc
, XLOG2DEV(points
[0].x
+xoffset
), YLOG2DEV(points
[0].y
+yoffset
) );
1037 for (i
= 1; i
< n
; i
++)
1038 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV(points
[i
].x
+xoffset
), YLOG2DEV(points
[i
].y
+yoffset
) );
1040 gs_lgp
->gnome_print_stroke ( m_gpc
);
1043 void wxGnomePrintDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1047 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1049 SetBrush( m_brush
);
1051 int x
= points
[0].x
+ xoffset
;
1052 int y
= points
[0].y
+ yoffset
;
1053 CalcBoundingBox( x
, y
);
1054 gs_lgp
->gnome_print_newpath( m_gpc
);
1055 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1057 for (i
= 1; i
< n
; i
++)
1059 int x
= points
[i
].x
+ xoffset
;
1060 int y
= points
[i
].y
+ yoffset
;
1061 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1062 CalcBoundingBox( x
, y
);
1064 gs_lgp
->gnome_print_closepath( m_gpc
);
1065 gs_lgp
->gnome_print_fill( m_gpc
);
1068 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1072 int x
= points
[0].x
+ xoffset
;
1073 int y
= points
[0].y
+ yoffset
;
1074 gs_lgp
->gnome_print_newpath( m_gpc
);
1075 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1077 for (i
= 1; i
< n
; i
++)
1079 int x
= points
[i
].x
+ xoffset
;
1080 int y
= points
[i
].y
+ yoffset
;
1081 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1082 CalcBoundingBox( x
, y
);
1084 gs_lgp
->gnome_print_closepath( m_gpc
);
1085 gs_lgp
->gnome_print_stroke( m_gpc
);
1089 void wxGnomePrintDC::DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
1091 wxDC::DoDrawPolyPolygon( n
, count
, points
, xoffset
, yoffset
, fillStyle
);
1094 void wxGnomePrintDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1096 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1098 SetBrush( m_brush
);
1100 gs_lgp
->gnome_print_newpath( m_gpc
);
1101 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1102 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1103 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1104 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1105 gs_lgp
->gnome_print_closepath( m_gpc
);
1106 gs_lgp
->gnome_print_fill( m_gpc
);
1108 CalcBoundingBox( x
, y
);
1109 CalcBoundingBox( x
+ width
, y
+ height
);
1112 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1116 gs_lgp
->gnome_print_newpath( m_gpc
);
1117 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
) );
1118 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
) );
1119 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
+ width
), YLOG2DEV(y
+ height
) );
1120 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV(x
), YLOG2DEV(y
+ height
) );
1121 gs_lgp
->gnome_print_closepath( m_gpc
);
1122 gs_lgp
->gnome_print_stroke( m_gpc
);
1124 CalcBoundingBox( x
, y
);
1125 CalcBoundingBox( x
+ width
, y
+ height
);
1129 void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
1131 wxCoord rad
= (wxCoord
) radius
;
1133 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1136 gs_lgp
->gnome_print_newpath(m_gpc
);
1137 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1138 gs_lgp
->gnome_print_curveto(m_gpc
,
1139 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1140 XLOG2DEV(x
),YLOG2DEV(y
),
1141 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1142 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1143 gs_lgp
->gnome_print_curveto(m_gpc
,
1144 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1145 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1146 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1147 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1148 gs_lgp
->gnome_print_curveto(m_gpc
,
1149 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1150 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1151 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1152 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1153 gs_lgp
->gnome_print_curveto(m_gpc
,
1154 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1155 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1156 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1157 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1158 gs_lgp
->gnome_print_closepath(m_gpc
);
1159 gs_lgp
->gnome_print_fill(m_gpc
);
1161 CalcBoundingBox(x
,y
);
1162 CalcBoundingBox(x
+width
,y
+height
);
1165 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1168 gs_lgp
->gnome_print_newpath(m_gpc
);
1169 gs_lgp
->gnome_print_moveto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1170 gs_lgp
->gnome_print_curveto(m_gpc
,
1171 XLOG2DEV(x
+ rad
),YLOG2DEV(y
),
1172 XLOG2DEV(x
),YLOG2DEV(y
),
1173 XLOG2DEV(x
),YLOG2DEV(y
+ rad
));
1174 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
));
1175 gs_lgp
->gnome_print_curveto(m_gpc
,
1176 XLOG2DEV(x
),YLOG2DEV(y
+ height
- rad
),
1177 XLOG2DEV(x
),YLOG2DEV(y
+ height
),
1178 XLOG2DEV(x
+ rad
),YLOG2DEV(y
+ height
));
1179 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
));
1180 gs_lgp
->gnome_print_curveto(m_gpc
,
1181 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
+ height
),
1182 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
),
1183 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ height
- rad
));
1184 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
));
1185 gs_lgp
->gnome_print_curveto(m_gpc
,
1186 XLOG2DEV(x
+ width
),YLOG2DEV(y
+ rad
),
1187 XLOG2DEV(x
+ width
),YLOG2DEV(y
),
1188 XLOG2DEV(x
+ width
- rad
),YLOG2DEV(y
));
1189 gs_lgp
->gnome_print_lineto(m_gpc
,XLOG2DEV(x
+ rad
),YLOG2DEV(y
));
1190 gs_lgp
->gnome_print_closepath(m_gpc
);
1191 gs_lgp
->gnome_print_stroke(m_gpc
);
1193 CalcBoundingBox(x
,y
);
1194 CalcBoundingBox(x
+width
,y
+height
);
1198 void wxGnomePrintDC::makeEllipticalPath(wxCoord x
, wxCoord y
,
1199 wxCoord width
, wxCoord height
)
1201 double r
= 4 * (sqrt (2) - 1) / 3;
1202 double halfW
= 0.5 * width
,
1203 halfH
= 0.5 * height
,
1206 wxCoord halfWI
= (wxCoord
) halfW
,
1207 halfHI
= (wxCoord
) halfH
;
1209 gs_lgp
->gnome_print_newpath( m_gpc
);
1211 // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
1212 gs_lgp
->gnome_print_moveto( m_gpc
,
1213 XLOG2DEV(x
+ width
),
1214 YLOG2DEV(y
+ halfHI
) );
1215 gs_lgp
->gnome_print_curveto( m_gpc
,
1216 XLOG2DEV(x
+ width
),
1217 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1218 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1219 YLOG2DEV(y
+ height
),
1220 XLOG2DEV(x
+ halfWI
),
1221 YLOG2DEV(y
+ height
) );
1222 gs_lgp
->gnome_print_curveto( m_gpc
,
1223 XLOG2DEV(x
+ (wxCoord
) rint(halfW
- halfWR
)),
1224 YLOG2DEV(y
+ height
),
1226 YLOG2DEV(y
+ (wxCoord
) rint (halfH
+ halfHR
)),
1227 XLOG2DEV(x
), YLOG2DEV(y
+halfHI
) );
1228 gs_lgp
->gnome_print_curveto( m_gpc
,
1230 YLOG2DEV(y
+ (wxCoord
) rint (halfH
- halfHR
)),
1231 XLOG2DEV(x
+ (wxCoord
) rint (halfW
- halfWR
)),
1233 XLOG2DEV(x
+halfWI
), YLOG2DEV(y
) );
1234 gs_lgp
->gnome_print_curveto( m_gpc
,
1235 XLOG2DEV(x
+ (wxCoord
) rint(halfW
+ halfWR
)),
1237 XLOG2DEV(x
+ width
),
1238 YLOG2DEV(y
+ (wxCoord
) rint(halfH
- halfHR
)),
1239 XLOG2DEV(x
+ width
), YLOG2DEV(y
+ halfHI
) );
1241 gs_lgp
->gnome_print_closepath(m_gpc
);
1244 void wxGnomePrintDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1246 if (m_brush
.GetStyle () != wxTRANSPARENT
)
1248 SetBrush( m_brush
);
1249 makeEllipticalPath( x
, y
, width
, height
);
1250 gs_lgp
->gnome_print_fill( m_gpc
);
1251 CalcBoundingBox( x
, y
);
1252 CalcBoundingBox( x
+ width
, y
+ height
);
1255 if (m_pen
.GetStyle () != wxTRANSPARENT
)
1258 makeEllipticalPath( x
, y
, width
, height
);
1259 gs_lgp
->gnome_print_stroke( m_gpc
);
1260 CalcBoundingBox( x
, y
);
1261 CalcBoundingBox( x
+ width
, y
+ height
);
1266 void wxGnomePrintDC::DoDrawSpline(wxList
*points
)
1270 double c
, d
, x1
, y1
, x2
, y2
, x3
, y3
;
1273 wxList::compatibility_iterator node
= points
->GetFirst();
1274 p
= (wxPoint
*)node
->GetData();
1278 node
= node
->GetNext();
1279 p
= (wxPoint
*)node
->GetData();
1283 (double)(x1
+ c
) / 2;
1285 (double)(y1
+ d
) / 2;
1287 gs_lgp
->gnome_print_newpath( m_gpc
);
1288 gs_lgp
->gnome_print_moveto( m_gpc
, XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
) );
1289 gs_lgp
->gnome_print_lineto( m_gpc
, XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1291 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1292 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1294 node
= node
->GetNext();
1297 q
= (wxPoint
*)node
->GetData();
1305 x3
= (double)(x2
+ c
) / 2;
1306 y3
= (double)(y2
+ d
) / 2;
1308 gs_lgp
->gnome_print_curveto(m_gpc
,
1309 XLOG2DEV((wxCoord
)x1
), YLOG2DEV((wxCoord
)y1
),
1310 XLOG2DEV((wxCoord
)x2
), YLOG2DEV((wxCoord
)y2
),
1311 XLOG2DEV((wxCoord
)x3
), YLOG2DEV((wxCoord
)y3
) );
1313 CalcBoundingBox( (wxCoord
)x1
, (wxCoord
)y1
);
1314 CalcBoundingBox( (wxCoord
)x3
, (wxCoord
)y3
);
1316 node
= node
->GetNext();
1319 gs_lgp
->gnome_print_lineto ( m_gpc
, XLOG2DEV((wxCoord
)c
), YLOG2DEV((wxCoord
)d
) );
1321 gs_lgp
->gnome_print_stroke( m_gpc
);
1323 #endif // wxUSE_SPLINES
1325 bool wxGnomePrintDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1326 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
, bool useMask
,
1327 wxCoord xsrcMask
, wxCoord ysrcMask
)
1329 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1331 // blit into a bitmap
1332 wxBitmap
bitmap( width
, height
);
1334 memDC
.SelectObject(bitmap
);
1335 memDC
.Blit(0, 0, width
, height
, source
, xsrc
, ysrc
, rop
); /* TODO: Blit transparently? */
1336 memDC
.SelectObject(wxNullBitmap
);
1338 // draw bitmap. scaling and positioning is done there
1339 DrawBitmap( bitmap
, xdest
, ydest
);
1344 void wxGnomePrintDC::DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1346 DoDrawBitmap( icon
, x
, y
, true );
1349 void wxGnomePrintDC::DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
)
1351 if (!bitmap
.Ok()) return;
1353 if (bitmap
.HasPixbuf())
1355 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1356 guchar
*raw_image
= gdk_pixbuf_get_pixels( pixbuf
);
1357 bool has_alpha
= gdk_pixbuf_get_has_alpha( pixbuf
);
1358 int rowstride
= gdk_pixbuf_get_rowstride( pixbuf
);
1359 int height
= gdk_pixbuf_get_height( pixbuf
);
1360 int width
= gdk_pixbuf_get_width( pixbuf
);
1362 gs_lgp
->gnome_print_gsave( m_gpc
);
1364 matrix
[0] = XLOG2DEVREL(width
);
1367 matrix
[3] = YLOG2DEVREL(height
);
1368 matrix
[4] = XLOG2DEV(x
);
1369 matrix
[5] = YLOG2DEV(y
+height
);
1370 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1371 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1373 gs_lgp
->gnome_print_rgbaimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1375 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*)raw_image
, width
, height
, rowstride
);
1376 gs_lgp
->gnome_print_grestore( m_gpc
);
1380 wxImage image
= bitmap
.ConvertToImage();
1382 if (!image
.Ok()) return;
1384 gs_lgp
->gnome_print_gsave( m_gpc
);
1386 matrix
[0] = XLOG2DEVREL(image
.GetWidth());
1389 matrix
[3] = YLOG2DEVREL(image
.GetHeight());
1390 matrix
[4] = XLOG2DEV(x
);
1391 matrix
[5] = YLOG2DEV(y
+image
.GetHeight());
1392 gs_lgp
->gnome_print_concat( m_gpc
, matrix
);
1393 gs_lgp
->gnome_print_moveto( m_gpc
, 0, 0 );
1394 gs_lgp
->gnome_print_rgbimage( m_gpc
, (guchar
*) image
.GetData(), image
.GetWidth(), image
.GetHeight(), image
.GetWidth()*3 );
1395 gs_lgp
->gnome_print_grestore( m_gpc
);
1399 void wxGnomePrintDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
1401 DoDrawRotatedText( text
, x
, y
, 0.0 );
1404 void wxGnomePrintDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
)
1409 bool underlined
= m_font
.Ok() && m_font
.GetUnderlined();
1412 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1414 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( text
);
1417 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1420 size_t datalen
= strlen((const char*)data
);
1421 pango_layout_set_text( m_layout
, (const char*) data
, datalen
);
1425 PangoAttrList
*attrs
= pango_attr_list_new();
1426 PangoAttribute
*a
= pango_attr_underline_new(PANGO_UNDERLINE_SINGLE
);
1428 a
->end_index
= datalen
;
1429 pango_attr_list_insert(attrs
, a
);
1430 pango_layout_set_attributes(m_layout
, attrs
);
1431 pango_attr_list_unref(attrs
);
1434 if (m_textForegroundColour
.Ok())
1436 unsigned char red
= m_textForegroundColour
.Red();
1437 unsigned char blue
= m_textForegroundColour
.Blue();
1438 unsigned char green
= m_textForegroundColour
.Green();
1440 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1442 double redPS
= (double)(red
) / 255.0;
1443 double bluePS
= (double)(blue
) / 255.0;
1444 double greenPS
= (double)(green
) / 255.0;
1446 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1449 m_currentBlue
= blue
;
1450 m_currentGreen
= green
;
1456 if (fabs(m_scaleY
- 1.0) > 0.00001)
1458 // If there is a user or actually any scale applied to
1459 // the device context, scale the font.
1461 // scale font description
1462 gint oldSize
= pango_font_description_get_size( m_fontdesc
);
1463 double size
= oldSize
;
1464 size
= size
* m_scaleY
;
1465 pango_font_description_set_size( m_fontdesc
, (gint
)size
);
1467 // actually apply scaled font
1468 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1470 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1472 if ( m_backgroundMode
== wxSOLID
)
1474 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1475 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1476 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1480 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1481 if (fabs(angle
) > 0.00001)
1483 gs_lgp
->gnome_print_gsave( m_gpc
);
1484 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1485 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1486 gs_lgp
->gnome_print_grestore( m_gpc
);
1490 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1493 // reset unscaled size
1494 pango_font_description_set_size( m_fontdesc
, oldSize
);
1496 // actually apply unscaled font
1497 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1501 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1503 if ( m_backgroundMode
== wxSOLID
)
1505 gdk_gc_set_foreground(m_textGC
, m_textBackgroundColour
.GetColor());
1506 gdk_draw_rectangle(m_window
, m_textGC
, TRUE
, x
, y
, w
, h
);
1507 gdk_gc_set_foreground(m_textGC
, m_textForegroundColour
.GetColor());
1511 gs_lgp
->gnome_print_moveto (m_gpc
, x
, y
);
1512 if (fabs(angle
) > 0.00001)
1514 gs_lgp
->gnome_print_gsave( m_gpc
);
1515 gs_lgp
->gnome_print_rotate( m_gpc
, angle
);
1516 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1517 gs_lgp
->gnome_print_grestore( m_gpc
);
1521 gs_lgp
->gnome_print_pango_layout( m_gpc
, m_layout
);
1527 // undo underline attributes setting:
1528 pango_layout_set_attributes(m_layout
, NULL
);
1531 CalcBoundingBox (x
+ w
, y
+ h
);
1534 void wxGnomePrintDC::Clear()
1538 void wxGnomePrintDC::SetFont( const wxFont
& font
)
1545 pango_font_description_free( m_fontdesc
);
1547 m_fontdesc
= pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
1549 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1553 void wxGnomePrintDC::SetPen( const wxPen
& pen
)
1555 if (!pen
.Ok()) return;
1559 gs_lgp
->gnome_print_setlinewidth( m_gpc
, XLOG2DEVREL( 1000 * m_pen
.GetWidth() ) / 1000.0f
);
1561 static const double dotted
[] = {2.0, 5.0};
1562 static const double short_dashed
[] = {4.0, 4.0};
1563 static const double wxCoord_dashed
[] = {4.0, 8.0};
1564 static const double dotted_dashed
[] = {6.0, 6.0, 2.0, 6.0};
1566 switch (m_pen
.GetStyle())
1568 case wxDOT
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, dotted
, 0 ); break;
1569 case wxSHORT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, short_dashed
, 0 ); break;
1570 case wxLONG_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 2, wxCoord_dashed
, 0 ); break;
1571 case wxDOT_DASH
: gs_lgp
->gnome_print_setdash( m_gpc
, 4, dotted_dashed
, 0 ); break;
1574 // It may be noted that libgnomeprint between at least
1575 // versions 2.8.0 and 2.12.1 makes a copy of the dashes
1576 // and then leak the memory since it doesn't set the
1577 // internal flag "privatedash" to 0.
1579 int num
= m_pen
.GetDashes (&wx_dashes
);
1580 gdouble
*g_dashes
= g_new( gdouble
, num
);
1582 for (i
= 0; i
< num
; ++i
)
1583 g_dashes
[i
] = (gdouble
) wx_dashes
[i
];
1584 gs_lgp
-> gnome_print_setdash( m_gpc
, num
, g_dashes
, 0);
1590 default: gs_lgp
->gnome_print_setdash( m_gpc
, 0, NULL
, 0 ); break;
1594 unsigned char red
= m_pen
.GetColour().Red();
1595 unsigned char blue
= m_pen
.GetColour().Blue();
1596 unsigned char green
= m_pen
.GetColour().Green();
1598 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1600 double redPS
= (double)(red
) / 255.0;
1601 double bluePS
= (double)(blue
) / 255.0;
1602 double greenPS
= (double)(green
) / 255.0;
1604 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1607 m_currentBlue
= blue
;
1608 m_currentGreen
= green
;
1612 void wxGnomePrintDC::SetBrush( const wxBrush
& brush
)
1614 if (!brush
.Ok()) return;
1619 unsigned char red
= m_brush
.GetColour().Red();
1620 unsigned char blue
= m_brush
.GetColour().Blue();
1621 unsigned char green
= m_brush
.GetColour().Green();
1625 // Anything not white is black
1626 if (! (red
== (unsigned char) 255 &&
1627 blue
== (unsigned char) 255 &&
1628 green
== (unsigned char) 255) )
1630 red
= (unsigned char) 0;
1631 green
= (unsigned char) 0;
1632 blue
= (unsigned char) 0;
1637 if (!(red
== m_currentRed
&& green
== m_currentGreen
&& blue
== m_currentBlue
))
1639 double redPS
= (double)(red
) / 255.0;
1640 double bluePS
= (double)(blue
) / 255.0;
1641 double greenPS
= (double)(green
) / 255.0;
1643 gs_lgp
->gnome_print_setrgbcolor( m_gpc
, redPS
, greenPS
, bluePS
);
1646 m_currentBlue
= blue
;
1647 m_currentGreen
= green
;
1651 void wxGnomePrintDC::SetLogicalFunction( int function
)
1655 void wxGnomePrintDC::SetBackground( const wxBrush
& brush
)
1659 void wxGnomePrintDC::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1663 void wxGnomePrintDC::DestroyClippingRegion()
1667 bool wxGnomePrintDC::StartDoc(const wxString
& message
)
1669 SetDeviceOrigin( 0,0 );
1674 void wxGnomePrintDC::EndDoc()
1676 gs_lgp
->gnome_print_end_doc( m_gpc
);
1679 void wxGnomePrintDC::StartPage()
1681 gs_lgp
->gnome_print_beginpage( m_gpc
, (const guchar
*) "page" );
1684 void wxGnomePrintDC::EndPage()
1686 gs_lgp
->gnome_print_showpage( m_gpc
);
1689 wxCoord
wxGnomePrintDC::GetCharHeight() const
1691 pango_layout_set_text( m_layout
, "H", 1 );
1694 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1699 wxCoord
wxGnomePrintDC::GetCharWidth() const
1701 pango_layout_set_text( m_layout
, "H", 1 );
1704 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1709 void wxGnomePrintDC::DoGetTextExtent(const wxString
& string
, wxCoord
*width
, wxCoord
*height
,
1711 wxCoord
*externalLeading
,
1712 wxFont
*theFont
) const
1720 if ( externalLeading
)
1721 *externalLeading
= 0;
1728 // Set new font description
1730 pango_layout_set_font_description( m_layout
, theFont
->GetNativeFontInfo()->description
);
1732 // Set layout's text
1734 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1735 const char *dataUTF8
= (const char *)data
;
1737 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
1740 if (width
) (*width
) = 0;
1741 if (height
) (*height
) = 0;
1744 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
1745 const char *dataUTF8
= (const char *)data
;
1750 // hardly ideal, but what else can we do if conversion failed?
1754 pango_layout_set_text( m_layout
, dataUTF8
, strlen(dataUTF8
) );
1757 pango_layout_get_pixel_size( m_layout
, &w
, &h
);
1760 *width
= (wxCoord
)(w
/ m_scaleX
);
1762 *height
= (wxCoord
)(h
/ m_scaleY
);
1765 PangoLayoutIter
*iter
= pango_layout_get_iter(m_layout
);
1766 int baseline
= pango_layout_iter_get_baseline(iter
);
1767 pango_layout_iter_free(iter
);
1768 *descent
= h
- PANGO_PIXELS(baseline
);
1771 // Reset old font description
1773 pango_layout_set_font_description( m_layout
, m_fontdesc
);
1776 void wxGnomePrintDC::DoGetSize(int* width
, int* height
) const
1778 wxGnomePrintNativeData
*native
=
1779 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1781 // Query page size. This seems to omit the margins
1782 // right now, although it shouldn't
1784 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1787 *width
= (int) (pw
+ 0.5);
1789 *height
= (int) (ph
+ 0.5);
1792 void wxGnomePrintDC::DoGetSizeMM(int *width
, int *height
) const
1794 wxGnomePrintNativeData
*native
=
1795 (wxGnomePrintNativeData
*) m_printData
.GetNativeData();
1797 // This code assumes values in Pts.
1800 gs_lgp
->gnome_print_job_get_page_size( native
->GetPrintJob(), &pw
, &ph
);
1804 const GnomePrintUnit
*mm_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "mm" );
1805 const GnomePrintUnit
*pts_unit
= gs_lgp
->gnome_print_unit_get_by_abbreviation( (const guchar
*) "Pts" );
1806 gs_lgp
->gnome_print_convert_distance( &pw
, pts_unit
, mm_unit
);
1807 gs_lgp
->gnome_print_convert_distance( &ph
, pts_unit
, mm_unit
);
1810 *width
= (int) (pw
+ 0.5);
1812 *height
= (int) (ph
+ 0.5);
1815 wxSize
wxGnomePrintDC::GetPPI() const
1817 return wxSize(72,72);
1820 void wxGnomePrintDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1822 m_signX
= (xLeftRight
? 1 : -1);
1823 m_signY
= (yBottomUp
? 1 : -1);
1825 ComputeScaleAndOrigin();
1828 void wxGnomePrintDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1834 wxDC::SetDeviceOrigin( x
, h
-y
);
1837 void wxGnomePrintDC::SetResolution(int ppi
)
1841 int wxGnomePrintDC::GetResolution()
1847 class wxGnomePrintModule
: public wxModule
1850 wxGnomePrintModule() {}
1855 DECLARE_DYNAMIC_CLASS(wxGnomePrintModule
)
1858 bool wxGnomePrintModule::OnInit()
1860 gs_lgp
= new wxGnomePrintLibrary
;
1862 wxPrintFactory::SetPrintFactory( new wxGnomePrintFactory
);
1866 void wxGnomePrintModule::OnExit()
1871 IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule
, wxModule
)
1873 // ----------------------------------------------------------------------------
1875 // ----------------------------------------------------------------------------
1877 IMPLEMENT_CLASS(wxGnomePrintPreview
, wxPrintPreviewBase
)
1879 void wxGnomePrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
1880 wxPrintout
* WXUNUSED(printoutForPrinting
))
1885 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1886 wxPrintout
*printoutForPrinting
,
1887 wxPrintDialogData
*data
)
1888 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1890 Init(printout
, printoutForPrinting
);
1893 wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout
*printout
,
1894 wxPrintout
*printoutForPrinting
,
1896 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
1898 Init(printout
, printoutForPrinting
);
1901 wxGnomePrintPreview::~wxGnomePrintPreview()
1905 bool wxGnomePrintPreview::Print(bool interactive
)
1907 if (!m_printPrintout
)
1910 wxPrinter
printer(& m_printDialogData
);
1911 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
1914 void wxGnomePrintPreview::DetermineScaling()
1916 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
1917 if (paperType
== wxPAPER_NONE
)
1918 paperType
= wxPAPER_NONE
;
1920 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
1922 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
1926 wxSize ScreenPixels
= wxGetDisplaySize();
1927 wxSize ScreenMM
= wxGetDisplaySizeMM();
1929 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
1930 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
1931 m_previewPrintout
->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
1933 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
1935 // TODO: get better resolution information from wxGnomePrintDC, if possible.
1937 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxGnomePrintDC::GetResolution() / 72.0);
1938 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxGnomePrintDC::GetResolution() / 72.0);
1939 wxSize
sizeTenthsMM(paper
->GetSize());
1940 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
1942 // If in landscape mode, we need to swap the width and height.
1943 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
1945 m_pageWidth
= sizeDevUnits
.y
;
1946 m_pageHeight
= sizeDevUnits
.x
;
1947 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
1948 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
1952 m_pageWidth
= sizeDevUnits
.x
;
1953 m_pageHeight
= sizeDevUnits
.y
;
1954 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
1955 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
1958 // At 100%, the page should look about page-size on the screen.
1959 m_previewScale
= (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
1964 // wxUSE_LIBGNOMEPRINT