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 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 //----------------------------------------------------------------------------
94 //----------------------------------------------------------------------------
96 class wxGnomePrintDialog
: public wxPrintDialogBase
99 wxGnomePrintDialog( wxWindow
*parent
,
100 wxPrintDialogData
* data
= (wxPrintDialogData
*)NULL
);
101 wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
* data
);
102 ~wxGnomePrintDialog();
104 wxPrintData
& GetPrintData()
105 { return m_printDialogData
.GetPrintData(); }
106 wxPrintDialogData
& GetPrintDialogData()
107 { return m_printDialogData
; }
111 virtual int ShowModal();
113 virtual bool Validate();
114 virtual bool TransferDataToWindow();
115 virtual bool TransferDataFromWindow();
118 // Implement some base class methods to do nothing to avoid asserts and
119 // GTK warnings, since this is not a real wxDialog.
120 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
121 int WXUNUSED(width
), int WXUNUSED(height
),
122 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
123 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
124 int WXUNUSED(width
), int WXUNUSED(height
)) {}
127 wxPrintDialogData m_printDialogData
;
130 DECLARE_DYNAMIC_CLASS(wxGnomePrintDialog
)
133 //----------------------------------------------------------------------------
135 //----------------------------------------------------------------------------
137 class wxGnomePrinter
: public wxPrinterBase
140 wxGnomePrinter(wxPrintDialogData
*data
= NULL
);
141 virtual ~wxGnomePrinter();
143 virtual bool Print(wxWindow
*parent
,
144 wxPrintout
*printout
,
146 virtual wxDC
* PrintDialog(wxWindow
*parent
);
147 virtual bool Setup(wxWindow
*parent
);
149 GnomePrintContext
*GetPrintContext() { return m_gpc
; }
152 GnomePrintContext
*m_gpc
;
153 bool m_native_preview
;
156 DECLARE_DYNAMIC_CLASS(wxGnomePrinter
)
157 DECLARE_NO_COPY_CLASS(wxGnomePrinter
)
160 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
164 class wxGnomePrintDC
: public wxDC
167 wxGnomePrintDC( wxGnomePrinter
*printer
);
172 virtual void BeginDrawing() {}
173 virtual void EndDrawing() {}
175 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
176 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
177 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
178 void DoCrossHair(wxCoord x
, wxCoord y
);
179 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
180 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
181 void DoDrawPoint(wxCoord x
, wxCoord y
);
182 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
183 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
184 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
185 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
186 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
187 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
188 void DoDrawSpline(wxList
*points
);
190 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
191 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
192 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
193 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
194 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
195 bool CanDrawBitmap() const { return true; }
197 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
198 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
200 void SetFont( const wxFont
& font
);
201 void SetPen( const wxPen
& pen
);
202 void SetBrush( const wxBrush
& brush
);
203 void SetLogicalFunction( int function
);
204 void SetBackground( const wxBrush
& brush
);
206 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
207 void DestroyClippingRegion();
208 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
210 bool StartDoc(const wxString
& message
);
215 wxCoord
GetCharHeight() const;
216 wxCoord
GetCharWidth() const;
217 bool CanGetTextExtent() const { return true; }
218 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
219 wxCoord
*descent
= (wxCoord
*) NULL
,
220 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
221 wxFont
*theFont
= (wxFont
*) NULL
) const;
223 void DoGetSize(int* width
, int* height
) const;
224 void DoGetSizeMM(int *width
, int *height
) const;
225 wxSize
GetPPI() const;
226 void SetAxisOrientation( bool xLeftRight
, bool yBottomUp
);
227 void SetDeviceOrigin( wxCoord x
, wxCoord y
);
229 virtual int GetDepth() const { return 24; }
231 void SetBackgroundMode(int WXUNUSED(mode
)) { }
232 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
234 wxPrintData
& GetPrintData() { return m_printData
; }
235 void SetPrintData(const wxPrintData
& data
) { m_printData
= data
; }
237 static void SetResolution(int ppi
);
238 static int GetResolution();
241 static float ms_PSScaleFactor
;
244 PangoContext
*m_context
;
245 PangoLayout
*m_layout
;
246 PangoFontDescription
*m_fontdesc
;
248 unsigned char m_currentRed
;
249 unsigned char m_currentGreen
;
250 unsigned char m_currentBlue
;
251 wxPrintData m_printData
;
253 wxGnomePrinter
*m_printer
;
254 GnomePrintContext
*m_gpc
;
257 wxCoord
XDEV2LOG(wxCoord x
) const
259 wxCoord new_x
= x
- m_deviceOriginX
;
261 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
263 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
265 wxCoord
XDEV2LOGREL(wxCoord x
) const
268 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
270 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
272 wxCoord
YDEV2LOG(wxCoord y
) const
274 wxCoord new_y
= y
- m_deviceOriginY
;
276 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
278 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
280 wxCoord
YDEV2LOGREL(wxCoord y
) const
283 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
285 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
287 wxCoord
XLOG2DEV(wxCoord x
) const
289 wxCoord new_x
= x
- m_logicalOriginX
;
291 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
293 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
295 wxCoord
XLOG2DEVREL(wxCoord x
) const
298 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
300 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
302 wxCoord
YLOG2DEV(wxCoord y
) const
304 wxCoord new_y
= y
- m_logicalOriginY
;
306 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
308 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
310 wxCoord
YLOG2DEVREL(wxCoord y
) const
313 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
315 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
318 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC
)
319 DECLARE_NO_COPY_CLASS(wxGnomePrintDC
)
323 // wxUSE_LIBGNOMEPRINT