1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Robert Roebling
4 // Purpose: GNOME printing support
6 // Copyright: Robert Roebling
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
13 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 // Include wxWindows' headers
23 #if wxUSE_LIBGNOMEPRINT
26 #include "wx/prntbase.h"
27 #include "wx/printdlg.h"
29 typedef struct _GnomePrintJob GnomePrintJob
;
30 typedef struct _GnomePrintContext GnomePrintContext
;
31 typedef struct _GnomePrintConfig GnomePrintConfig
;
33 //----------------------------------------------------------------------------
34 // wxGnomePrintNativeData
35 //----------------------------------------------------------------------------
37 class wxGnomePrintNativeData
: public wxPrintNativeDataBase
40 wxGnomePrintNativeData();
41 virtual ~wxGnomePrintNativeData();
43 virtual bool TransferTo( wxPrintData
&data
);
44 virtual bool TransferFrom( const wxPrintData
&data
);
46 virtual bool Ok() const { return true; }
48 GnomePrintConfig
* GetPrintConfig() { return m_config
; }
49 void SetPrintJob( GnomePrintJob
*job
) { m_job
= job
; }
50 GnomePrintJob
* GetPrintJob() { return m_job
; }
54 GnomePrintConfig
*m_config
;
58 DECLARE_DYNAMIC_CLASS(wxGnomePrintNativeData
)
61 //----------------------------------------------------------------------------
62 // wxGnomePrintFactory
63 //----------------------------------------------------------------------------
65 class wxGnomePrintFactory
: public wxPrintFactory
68 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
70 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
71 wxPrintout
*printout
= NULL
,
72 wxPrintDialogData
*data
= NULL
);
73 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
77 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
78 wxPrintDialogData
*data
= NULL
);
79 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
82 virtual wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
83 wxPageSetupDialogData
* data
= NULL
);
85 virtual bool HasPrintSetupDialog();
86 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
87 virtual bool HasOwnPrintToFile();
88 virtual bool HasPrinterLine();
89 virtual wxString
CreatePrinterLine();
90 virtual bool HasStatusLine();
91 virtual wxString
CreateStatusLine();
93 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
96 //----------------------------------------------------------------------------
98 //----------------------------------------------------------------------------
100 class wxGnomePrintDialog
: public wxPrintDialogBase
103 wxGnomePrintDialog( wxWindow
*parent
,
104 wxPrintDialogData
* data
= NULL
);
105 wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
* data
);
106 ~wxGnomePrintDialog();
108 wxPrintData
& GetPrintData()
109 { return m_printDialogData
.GetPrintData(); }
110 wxPrintDialogData
& GetPrintDialogData()
111 { return m_printDialogData
; }
115 virtual int ShowModal();
117 virtual bool Validate();
118 virtual bool TransferDataToWindow();
119 virtual bool TransferDataFromWindow();
122 // Implement some base class methods to do nothing to avoid asserts and
123 // GTK warnings, since this is not a real wxDialog.
124 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
125 int WXUNUSED(width
), int WXUNUSED(height
),
126 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
127 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
128 int WXUNUSED(width
), int WXUNUSED(height
)) {}
131 wxPrintDialogData m_printDialogData
;
134 DECLARE_DYNAMIC_CLASS(wxGnomePrintDialog
)
137 //----------------------------------------------------------------------------
138 // wxGnomePageSetupDialog
139 //----------------------------------------------------------------------------
141 class wxGnomePageSetupDialog
: public wxPageSetupDialogBase
144 wxGnomePageSetupDialog( wxWindow
*parent
,
145 wxPageSetupDialogData
* data
= NULL
);
146 ~wxGnomePageSetupDialog();
148 virtual wxPageSetupDialogData
& GetPageSetupDialogData();
150 virtual int ShowModal();
152 virtual bool Validate();
153 virtual bool TransferDataToWindow();
154 virtual bool TransferDataFromWindow();
157 // Implement some base class methods to do nothing to avoid asserts and
158 // GTK warnings, since this is not a real wxDialog.
159 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
160 int WXUNUSED(width
), int WXUNUSED(height
),
161 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
162 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
163 int WXUNUSED(width
), int WXUNUSED(height
)) {}
165 wxPageSetupDialogData m_pageDialogData
;
168 DECLARE_DYNAMIC_CLASS(wxGnomePageSetupDialog
)
171 //----------------------------------------------------------------------------
173 //----------------------------------------------------------------------------
175 class wxGnomePrinter
: public wxPrinterBase
178 wxGnomePrinter(wxPrintDialogData
*data
= NULL
);
179 virtual ~wxGnomePrinter();
181 virtual bool Print(wxWindow
*parent
,
182 wxPrintout
*printout
,
184 virtual wxDC
* PrintDialog(wxWindow
*parent
);
185 virtual bool Setup(wxWindow
*parent
);
187 GnomePrintContext
*GetPrintContext() { return m_gpc
; }
190 GnomePrintContext
*m_gpc
;
191 bool m_native_preview
;
194 DECLARE_DYNAMIC_CLASS(wxGnomePrinter
)
195 DECLARE_NO_COPY_CLASS(wxGnomePrinter
)
198 //-----------------------------------------------------------------------------
200 //-----------------------------------------------------------------------------
202 class wxGnomePrintDC
: public wxDC
205 wxGnomePrintDC( wxGnomePrinter
*printer
);
210 virtual void BeginDrawing() {}
211 virtual void EndDrawing() {}
213 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
214 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
215 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
216 void DoCrossHair(wxCoord x
, wxCoord y
);
217 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
218 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
219 void DoDrawPoint(wxCoord x
, wxCoord y
);
220 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
221 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
222 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
223 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
224 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
225 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
226 void DoDrawSpline(wxList
*points
);
228 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
229 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
230 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
231 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
232 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
233 bool CanDrawBitmap() const { return true; }
235 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
236 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
238 void SetFont( const wxFont
& font
);
239 void SetPen( const wxPen
& pen
);
240 void SetBrush( const wxBrush
& brush
);
241 void SetLogicalFunction( int function
);
242 void SetBackground( const wxBrush
& brush
);
244 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
245 void DestroyClippingRegion();
246 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
248 bool StartDoc(const wxString
& message
);
253 wxCoord
GetCharHeight() const;
254 wxCoord
GetCharWidth() const;
255 bool CanGetTextExtent() const { return true; }
256 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
257 wxCoord
*descent
= (wxCoord
*) NULL
,
258 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
259 wxFont
*theFont
= (wxFont
*) NULL
) const;
261 void DoGetSize(int* width
, int* height
) const;
262 void DoGetSizeMM(int *width
, int *height
) const;
263 wxSize
GetPPI() const;
264 void SetAxisOrientation( bool xLeftRight
, bool yBottomUp
);
265 void SetDeviceOrigin( wxCoord x
, wxCoord y
);
267 virtual int GetDepth() const { return 24; }
269 void SetBackgroundMode(int WXUNUSED(mode
)) { }
270 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
272 wxPrintData
& GetPrintData() { return m_printData
; }
273 void SetPrintData(const wxPrintData
& data
) { m_printData
= data
; }
275 static void SetResolution(int ppi
);
276 static int GetResolution();
279 static float ms_PSScaleFactor
;
282 PangoContext
*m_context
;
283 PangoLayout
*m_layout
;
284 PangoFontDescription
*m_fontdesc
;
286 unsigned char m_currentRed
;
287 unsigned char m_currentGreen
;
288 unsigned char m_currentBlue
;
289 wxPrintData m_printData
;
291 wxGnomePrinter
*m_printer
;
292 GnomePrintContext
*m_gpc
;
295 wxCoord
XDEV2LOG(wxCoord x
) const
297 wxCoord new_x
= x
- m_deviceOriginX
;
299 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
301 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
303 wxCoord
XDEV2LOGREL(wxCoord x
) const
306 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
308 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
310 wxCoord
YDEV2LOG(wxCoord y
) const
312 wxCoord new_y
= y
- m_deviceOriginY
;
314 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
316 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
318 wxCoord
YDEV2LOGREL(wxCoord y
) const
321 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
323 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
325 wxCoord
XLOG2DEV(wxCoord x
) const
327 wxCoord new_x
= x
- m_logicalOriginX
;
329 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
331 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
333 wxCoord
XLOG2DEVREL(wxCoord x
) const
336 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
338 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
340 wxCoord
YLOG2DEV(wxCoord y
) const
342 wxCoord new_y
= y
- m_logicalOriginY
;
344 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
346 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
348 wxCoord
YLOG2DEVREL(wxCoord y
) const
351 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
353 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
356 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC
)
357 DECLARE_NO_COPY_CLASS(wxGnomePrintDC
)
361 // wxUSE_LIBGNOMEPRINT