1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Robert Roebling
4 // Purpose: GNOME printing support
6 // Copyright: Robert Roebling
7 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma interface "gprint.h"
16 // Include wxWindows' headers
23 #include "wx/prntbase.h"
24 #include "wx/printdlg.h"
26 typedef struct _GnomePrintJob GnomePrintJob
;
27 typedef struct _GnomePrintContext GnomePrintContext
;
28 typedef struct _GnomePrintConfig GnomePrintConfig
;
30 //----------------------------------------------------------------------------
31 // wxGnomePrintNativeData
32 //----------------------------------------------------------------------------
34 class wxGnomePrintNativeData
: public wxPrintNativeDataBase
37 wxGnomePrintNativeData();
38 virtual ~wxGnomePrintNativeData();
40 virtual bool TransferTo( wxPrintData
&data
);
41 virtual bool TransferFrom( const wxPrintData
&data
);
43 virtual bool Ok() const { return true; }
45 GnomePrintConfig
* GetPrintConfig() { return m_config
; }
46 GnomePrintJob
* GetPrintJob() { return m_job
; }
50 GnomePrintConfig
*m_config
;
54 DECLARE_DYNAMIC_CLASS(wxGnomePrintNativeData
)
57 //----------------------------------------------------------------------------
58 // wxGnomePrintFactory
59 //----------------------------------------------------------------------------
61 class wxGnomePrintFactory
: public wxPrintFactory
64 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
66 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
67 wxPrintout
*printout
= NULL
,
68 wxPrintDialogData
*data
= NULL
);
69 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
73 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
74 wxPrintDialogData
*data
= NULL
);
75 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
78 virtual bool HasPrintSetupDialog();
79 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
80 virtual bool HasOwnPrintToFile();
81 virtual bool HasPrinterLine();
82 virtual wxString
CreatePrinterLine();
83 virtual bool HasStatusLine();
84 virtual wxString
CreateStatusLine();
86 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
89 //----------------------------------------------------------------------------
90 // wxGnomePrintSetupDialog
91 //----------------------------------------------------------------------------
93 class wxGnomePrintSetupDialog
: public wxDialog
96 wxGnomePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
97 ~wxGnomePrintSetupDialog();
99 virtual int ShowModal();
101 virtual bool Validate();
102 virtual bool TransferDataToWindow();
103 virtual bool TransferDataFromWindow();
106 // Implement some base class methods to do nothing to avoid asserts and
107 // GTK warnings, since this is not a real wxDialog.
108 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
109 int WXUNUSED(width
), int WXUNUSED(height
),
110 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
111 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
112 int WXUNUSED(width
), int WXUNUSED(height
)) {}
114 DECLARE_DYNAMIC_CLASS(wxGnomePrintSetupDialog
)
117 //----------------------------------------------------------------------------
119 //----------------------------------------------------------------------------
121 class wxGnomePrinter
: public wxPrinterBase
124 wxGnomePrinter(wxPrintDialogData
*data
= NULL
);
125 virtual ~wxGnomePrinter();
127 virtual bool Print(wxWindow
*parent
,
128 wxPrintout
*printout
,
130 virtual wxDC
* PrintDialog(wxWindow
*parent
);
131 virtual bool Setup(wxWindow
*parent
);
133 GnomePrintContext
*GetPrintContext() { return m_gpc
; }
136 GnomePrintContext
*m_gpc
;
139 DECLARE_DYNAMIC_CLASS(wxGnomePrinter
)
140 DECLARE_NO_COPY_CLASS(wxGnomePrinter
)
143 //-----------------------------------------------------------------------------
145 //-----------------------------------------------------------------------------
147 class wxGnomePrintDC
: public wxDC
150 wxGnomePrintDC( wxGnomePrinter
*printer
);
155 virtual void BeginDrawing() {}
156 virtual void EndDrawing() {}
158 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
159 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
160 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
161 void DoCrossHair(wxCoord x
, wxCoord y
);
162 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
163 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
164 void DoDrawPoint(wxCoord x
, wxCoord y
);
165 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
166 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
167 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
168 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
169 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
170 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
171 void DoDrawSpline(wxList
*points
);
173 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
174 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
175 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
176 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
177 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
178 bool CanDrawBitmap() const { return true; }
180 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
181 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
183 void SetFont( const wxFont
& font
);
184 void SetPen( const wxPen
& pen
);
185 void SetBrush( const wxBrush
& brush
);
186 void SetLogicalFunction( int function
);
187 void SetBackground( const wxBrush
& brush
);
189 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
190 void DestroyClippingRegion();
191 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
193 bool StartDoc(const wxString
& message
);
198 wxCoord
GetCharHeight() const;
199 wxCoord
GetCharWidth() const;
200 bool CanGetTextExtent() const { return true; }
201 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
202 wxCoord
*descent
= (wxCoord
*) NULL
,
203 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
204 wxFont
*theFont
= (wxFont
*) NULL
) const;
206 void DoGetSize(int* width
, int* height
) const;
207 void DoGetSizeMM(int *width
, int *height
) const;
208 wxSize
GetPPI() const;
209 void SetAxisOrientation( bool xLeftRight
, bool yBottomUp
);
210 void SetDeviceOrigin( wxCoord x
, wxCoord y
);
212 virtual int GetDepth() const { return 24; }
214 void SetBackgroundMode(int WXUNUSED(mode
)) { }
215 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
217 wxPrintData
& GetPrintData() { return m_printData
; }
218 void SetPrintData(const wxPrintData
& data
) { m_printData
= data
; }
220 static void SetResolution(int ppi
);
221 static int GetResolution();
224 static float ms_PSScaleFactor
;
227 PangoContext
*m_context
;
228 PangoLayout
*m_layout
;
229 PangoFontDescription
*m_fontdesc
;
231 unsigned char m_currentRed
;
232 unsigned char m_currentGreen
;
233 unsigned char m_currentBlue
;
234 wxPrintData m_printData
;
236 wxGnomePrinter
*m_printer
;
237 GnomePrintContext
*m_gpc
;
240 wxCoord
XDEV2LOG(wxCoord x
) const
242 wxCoord new_x
= x
- m_deviceOriginX
;
244 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
246 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
248 wxCoord
XDEV2LOGREL(wxCoord x
) const
251 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
253 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
255 wxCoord
YDEV2LOG(wxCoord y
) const
257 wxCoord new_y
= y
- m_deviceOriginY
;
259 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
261 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
263 wxCoord
YDEV2LOGREL(wxCoord y
) const
266 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
268 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
270 wxCoord
XLOG2DEV(wxCoord x
) const
272 wxCoord new_x
= x
- m_logicalOriginX
;
274 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
276 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
278 wxCoord
XLOG2DEVREL(wxCoord x
) const
281 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
283 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
285 wxCoord
YLOG2DEV(wxCoord y
) const
287 wxCoord new_y
= y
- m_logicalOriginY
;
289 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
291 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
293 wxCoord
YLOG2DEVREL(wxCoord y
) const
296 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
298 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
301 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC
)
302 DECLARE_NO_COPY_CLASS(wxGnomePrintDC
)