1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Robert Roebling
4 // Purpose: GNOME printing support
6 // Copyright: Robert Roebling
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
13 #if defined(__GNUG__) && !defined(__APPLE__)
14 #pragma interface "gprint.h"
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 GnomePrintJob
* GetPrintJob() { return m_job
; }
53 GnomePrintConfig
*m_config
;
57 DECLARE_DYNAMIC_CLASS(wxGnomePrintNativeData
)
60 //----------------------------------------------------------------------------
61 // wxGnomePrintFactory
62 //----------------------------------------------------------------------------
64 class wxGnomePrintFactory
: public wxPrintFactory
67 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
69 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
70 wxPrintout
*printout
= NULL
,
71 wxPrintDialogData
*data
= NULL
);
72 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
76 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
77 wxPrintDialogData
*data
= NULL
);
78 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
81 virtual bool HasPrintSetupDialog();
82 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
83 virtual bool HasOwnPrintToFile();
84 virtual bool HasPrinterLine();
85 virtual wxString
CreatePrinterLine();
86 virtual bool HasStatusLine();
87 virtual wxString
CreateStatusLine();
89 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
92 //----------------------------------------------------------------------------
93 // wxGnomePrintSetupDialog
94 //----------------------------------------------------------------------------
96 class wxGnomePrintSetupDialog
: public wxDialog
99 wxGnomePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
100 ~wxGnomePrintSetupDialog();
102 virtual int ShowModal();
104 virtual bool Validate();
105 virtual bool TransferDataToWindow();
106 virtual bool TransferDataFromWindow();
109 // Implement some base class methods to do nothing to avoid asserts and
110 // GTK warnings, since this is not a real wxDialog.
111 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
112 int WXUNUSED(width
), int WXUNUSED(height
),
113 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
114 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
115 int WXUNUSED(width
), int WXUNUSED(height
)) {}
117 DECLARE_DYNAMIC_CLASS(wxGnomePrintSetupDialog
)
120 //----------------------------------------------------------------------------
122 //----------------------------------------------------------------------------
124 class wxGnomePrinter
: public wxPrinterBase
127 wxGnomePrinter(wxPrintDialogData
*data
= NULL
);
128 virtual ~wxGnomePrinter();
130 virtual bool Print(wxWindow
*parent
,
131 wxPrintout
*printout
,
133 virtual wxDC
* PrintDialog(wxWindow
*parent
);
134 virtual bool Setup(wxWindow
*parent
);
136 GnomePrintContext
*GetPrintContext() { return m_gpc
; }
139 GnomePrintContext
*m_gpc
;
142 DECLARE_DYNAMIC_CLASS(wxGnomePrinter
)
143 DECLARE_NO_COPY_CLASS(wxGnomePrinter
)
146 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
150 class wxGnomePrintDC
: public wxDC
153 wxGnomePrintDC( wxGnomePrinter
*printer
);
158 virtual void BeginDrawing() {}
159 virtual void EndDrawing() {}
161 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
162 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
163 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
164 void DoCrossHair(wxCoord x
, wxCoord y
);
165 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
166 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
167 void DoDrawPoint(wxCoord x
, wxCoord y
);
168 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
169 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
170 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
171 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
172 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
173 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
174 void DoDrawSpline(wxList
*points
);
176 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
177 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
178 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
179 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
180 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
181 bool CanDrawBitmap() const { return true; }
183 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
184 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
186 void SetFont( const wxFont
& font
);
187 void SetPen( const wxPen
& pen
);
188 void SetBrush( const wxBrush
& brush
);
189 void SetLogicalFunction( int function
);
190 void SetBackground( const wxBrush
& brush
);
192 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
193 void DestroyClippingRegion();
194 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
196 bool StartDoc(const wxString
& message
);
201 wxCoord
GetCharHeight() const;
202 wxCoord
GetCharWidth() const;
203 bool CanGetTextExtent() const { return true; }
204 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
205 wxCoord
*descent
= (wxCoord
*) NULL
,
206 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
207 wxFont
*theFont
= (wxFont
*) NULL
) const;
209 void DoGetSize(int* width
, int* height
) const;
210 void DoGetSizeMM(int *width
, int *height
) const;
211 wxSize
GetPPI() const;
212 void SetAxisOrientation( bool xLeftRight
, bool yBottomUp
);
213 void SetDeviceOrigin( wxCoord x
, wxCoord y
);
215 virtual int GetDepth() const { return 24; }
217 void SetBackgroundMode(int WXUNUSED(mode
)) { }
218 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
220 wxPrintData
& GetPrintData() { return m_printData
; }
221 void SetPrintData(const wxPrintData
& data
) { m_printData
= data
; }
223 static void SetResolution(int ppi
);
224 static int GetResolution();
227 static float ms_PSScaleFactor
;
230 PangoContext
*m_context
;
231 PangoLayout
*m_layout
;
232 PangoFontDescription
*m_fontdesc
;
234 unsigned char m_currentRed
;
235 unsigned char m_currentGreen
;
236 unsigned char m_currentBlue
;
237 wxPrintData m_printData
;
239 wxGnomePrinter
*m_printer
;
240 GnomePrintContext
*m_gpc
;
243 wxCoord
XDEV2LOG(wxCoord x
) const
245 wxCoord new_x
= x
- m_deviceOriginX
;
247 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
249 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
251 wxCoord
XDEV2LOGREL(wxCoord x
) const
254 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
256 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
258 wxCoord
YDEV2LOG(wxCoord y
) const
260 wxCoord new_y
= y
- m_deviceOriginY
;
262 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
264 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
266 wxCoord
YDEV2LOGREL(wxCoord y
) const
269 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
271 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
273 wxCoord
XLOG2DEV(wxCoord x
) const
275 wxCoord new_x
= x
- m_logicalOriginX
;
277 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
279 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
281 wxCoord
XLOG2DEVREL(wxCoord x
) const
284 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
286 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
288 wxCoord
YLOG2DEV(wxCoord y
) const
290 wxCoord new_y
= y
- m_logicalOriginY
;
292 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
294 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
296 wxCoord
YLOG2DEVREL(wxCoord y
) const
299 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
301 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
304 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC
)
305 DECLARE_NO_COPY_CLASS(wxGnomePrintDC
)
309 // wxUSE_LIBGNOMEPRINT