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
;
155 DECLARE_DYNAMIC_CLASS(wxGnomePrinter
)
156 DECLARE_NO_COPY_CLASS(wxGnomePrinter
)
159 //-----------------------------------------------------------------------------
161 //-----------------------------------------------------------------------------
163 class wxGnomePrintDC
: public wxDC
166 wxGnomePrintDC( wxGnomePrinter
*printer
);
171 virtual void BeginDrawing() {}
172 virtual void EndDrawing() {}
174 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
175 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
176 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
177 void DoCrossHair(wxCoord x
, wxCoord y
);
178 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
179 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
180 void DoDrawPoint(wxCoord x
, wxCoord y
);
181 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
182 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
183 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
184 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
185 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
186 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
187 void DoDrawSpline(wxList
*points
);
189 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
190 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
191 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
192 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
193 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
194 bool CanDrawBitmap() const { return true; }
196 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
197 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
199 void SetFont( const wxFont
& font
);
200 void SetPen( const wxPen
& pen
);
201 void SetBrush( const wxBrush
& brush
);
202 void SetLogicalFunction( int function
);
203 void SetBackground( const wxBrush
& brush
);
205 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
206 void DestroyClippingRegion();
207 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
209 bool StartDoc(const wxString
& message
);
214 wxCoord
GetCharHeight() const;
215 wxCoord
GetCharWidth() const;
216 bool CanGetTextExtent() const { return true; }
217 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
218 wxCoord
*descent
= (wxCoord
*) NULL
,
219 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
220 wxFont
*theFont
= (wxFont
*) NULL
) const;
222 void DoGetSize(int* width
, int* height
) const;
223 void DoGetSizeMM(int *width
, int *height
) const;
224 wxSize
GetPPI() const;
225 void SetAxisOrientation( bool xLeftRight
, bool yBottomUp
);
226 void SetDeviceOrigin( wxCoord x
, wxCoord y
);
228 virtual int GetDepth() const { return 24; }
230 void SetBackgroundMode(int WXUNUSED(mode
)) { }
231 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
233 wxPrintData
& GetPrintData() { return m_printData
; }
234 void SetPrintData(const wxPrintData
& data
) { m_printData
= data
; }
236 static void SetResolution(int ppi
);
237 static int GetResolution();
240 static float ms_PSScaleFactor
;
243 PangoContext
*m_context
;
244 PangoLayout
*m_layout
;
245 PangoFontDescription
*m_fontdesc
;
247 unsigned char m_currentRed
;
248 unsigned char m_currentGreen
;
249 unsigned char m_currentBlue
;
250 wxPrintData m_printData
;
252 wxGnomePrinter
*m_printer
;
253 GnomePrintContext
*m_gpc
;
256 wxCoord
XDEV2LOG(wxCoord x
) const
258 wxCoord new_x
= x
- m_deviceOriginX
;
260 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
262 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
264 wxCoord
XDEV2LOGREL(wxCoord x
) const
267 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
269 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
271 wxCoord
YDEV2LOG(wxCoord y
) const
273 wxCoord new_y
= y
- m_deviceOriginY
;
275 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
277 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
279 wxCoord
YDEV2LOGREL(wxCoord y
) const
282 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
284 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
286 wxCoord
XLOG2DEV(wxCoord x
) const
288 wxCoord new_x
= x
- m_logicalOriginX
;
290 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
292 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
294 wxCoord
XLOG2DEVREL(wxCoord x
) const
297 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
299 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
301 wxCoord
YLOG2DEV(wxCoord y
) const
303 wxCoord new_y
= y
- m_logicalOriginY
;
305 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
307 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
309 wxCoord
YLOG2DEVREL(wxCoord y
) const
312 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
314 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
317 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC
)
318 DECLARE_NO_COPY_CLASS(wxGnomePrintDC
)
322 // wxUSE_LIBGNOMEPRINT