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 wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
82 wxPageSetupDialogData
* data
= NULL
);
84 virtual bool HasPrintSetupDialog();
85 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
86 virtual bool HasOwnPrintToFile();
87 virtual bool HasPrinterLine();
88 virtual wxString
CreatePrinterLine();
89 virtual bool HasStatusLine();
90 virtual wxString
CreateStatusLine();
92 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
95 //----------------------------------------------------------------------------
97 //----------------------------------------------------------------------------
99 class wxGnomePrintDialog
: public wxPrintDialogBase
102 wxGnomePrintDialog( wxWindow
*parent
,
103 wxPrintDialogData
* data
= NULL
);
104 wxGnomePrintDialog( wxWindow
*parent
, wxPrintData
* data
);
105 ~wxGnomePrintDialog();
107 wxPrintData
& GetPrintData()
108 { return m_printDialogData
.GetPrintData(); }
109 wxPrintDialogData
& GetPrintDialogData()
110 { return m_printDialogData
; }
114 virtual int ShowModal();
116 virtual bool Validate();
117 virtual bool TransferDataToWindow();
118 virtual bool TransferDataFromWindow();
121 // Implement some base class methods to do nothing to avoid asserts and
122 // GTK warnings, since this is not a real wxDialog.
123 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
124 int WXUNUSED(width
), int WXUNUSED(height
),
125 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
126 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
127 int WXUNUSED(width
), int WXUNUSED(height
)) {}
130 wxPrintDialogData m_printDialogData
;
133 DECLARE_DYNAMIC_CLASS(wxGnomePrintDialog
)
136 //----------------------------------------------------------------------------
137 // wxGnomePageSetupDialog
138 //----------------------------------------------------------------------------
140 class wxGnomePageSetupDialog
: public wxPageSetupDialogBase
143 wxGnomePageSetupDialog( wxWindow
*parent
,
144 wxPageSetupDialogData
* data
= NULL
);
145 ~wxGnomePageSetupDialog();
147 virtual wxPageSetupDialogData
& GetPageSetupDialogData();
149 virtual int ShowModal();
151 virtual bool Validate();
152 virtual bool TransferDataToWindow();
153 virtual bool TransferDataFromWindow();
156 // Implement some base class methods to do nothing to avoid asserts and
157 // GTK warnings, since this is not a real wxDialog.
158 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
159 int WXUNUSED(width
), int WXUNUSED(height
),
160 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
161 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
162 int WXUNUSED(width
), int WXUNUSED(height
)) {}
164 wxPageSetupDialogData m_pageDialogData
;
167 DECLARE_DYNAMIC_CLASS(wxGnomePageSetupDialog
)
170 //----------------------------------------------------------------------------
172 //----------------------------------------------------------------------------
174 class wxGnomePrinter
: public wxPrinterBase
177 wxGnomePrinter(wxPrintDialogData
*data
= NULL
);
178 virtual ~wxGnomePrinter();
180 virtual bool Print(wxWindow
*parent
,
181 wxPrintout
*printout
,
183 virtual wxDC
* PrintDialog(wxWindow
*parent
);
184 virtual bool Setup(wxWindow
*parent
);
186 GnomePrintContext
*GetPrintContext() { return m_gpc
; }
189 GnomePrintContext
*m_gpc
;
190 bool m_native_preview
;
193 DECLARE_DYNAMIC_CLASS(wxGnomePrinter
)
194 DECLARE_NO_COPY_CLASS(wxGnomePrinter
)
197 //-----------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
201 class wxGnomePrintDC
: public wxDC
204 wxGnomePrintDC( wxGnomePrinter
*printer
);
209 virtual void BeginDrawing() {}
210 virtual void EndDrawing() {}
212 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
213 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
214 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
215 void DoCrossHair(wxCoord x
, wxCoord y
);
216 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
217 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
218 void DoDrawPoint(wxCoord x
, wxCoord y
);
219 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
220 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
221 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
222 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
223 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
224 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
225 void DoDrawSpline(wxList
*points
);
227 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
228 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
229 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
230 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
231 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
232 bool CanDrawBitmap() const { return true; }
234 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
235 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
237 void SetFont( const wxFont
& font
);
238 void SetPen( const wxPen
& pen
);
239 void SetBrush( const wxBrush
& brush
);
240 void SetLogicalFunction( int function
);
241 void SetBackground( const wxBrush
& brush
);
243 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
244 void DestroyClippingRegion();
245 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
247 bool StartDoc(const wxString
& message
);
252 wxCoord
GetCharHeight() const;
253 wxCoord
GetCharWidth() const;
254 bool CanGetTextExtent() const { return true; }
255 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
256 wxCoord
*descent
= (wxCoord
*) NULL
,
257 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
258 wxFont
*theFont
= (wxFont
*) NULL
) const;
260 void DoGetSize(int* width
, int* height
) const;
261 void DoGetSizeMM(int *width
, int *height
) const;
262 wxSize
GetPPI() const;
263 void SetAxisOrientation( bool xLeftRight
, bool yBottomUp
);
264 void SetDeviceOrigin( wxCoord x
, wxCoord y
);
266 virtual int GetDepth() const { return 24; }
268 void SetBackgroundMode(int WXUNUSED(mode
)) { }
269 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
271 wxPrintData
& GetPrintData() { return m_printData
; }
272 void SetPrintData(const wxPrintData
& data
) { m_printData
= data
; }
274 static void SetResolution(int ppi
);
275 static int GetResolution();
278 static float ms_PSScaleFactor
;
281 PangoContext
*m_context
;
282 PangoLayout
*m_layout
;
283 PangoFontDescription
*m_fontdesc
;
285 unsigned char m_currentRed
;
286 unsigned char m_currentGreen
;
287 unsigned char m_currentBlue
;
288 wxPrintData m_printData
;
290 wxGnomePrinter
*m_printer
;
291 GnomePrintContext
*m_gpc
;
294 wxCoord
XDEV2LOG(wxCoord x
) const
296 wxCoord new_x
= x
- m_deviceOriginX
;
298 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
300 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
302 wxCoord
XDEV2LOGREL(wxCoord x
) const
305 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
307 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
309 wxCoord
YDEV2LOG(wxCoord y
) const
311 wxCoord new_y
= y
- m_deviceOriginY
;
313 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
315 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
317 wxCoord
YDEV2LOGREL(wxCoord y
) const
320 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
322 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
324 wxCoord
XLOG2DEV(wxCoord x
) const
326 wxCoord new_x
= x
- m_logicalOriginX
;
328 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
330 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
332 wxCoord
XLOG2DEVREL(wxCoord x
) const
335 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
337 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
339 wxCoord
YLOG2DEV(wxCoord y
) const
341 wxCoord new_y
= y
- m_logicalOriginY
;
343 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
345 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
347 wxCoord
YLOG2DEVREL(wxCoord y
) const
350 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
352 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
355 DECLARE_DYNAMIC_CLASS(wxGnomePrintDC
)
356 DECLARE_NO_COPY_CLASS(wxGnomePrintDC
)
360 // wxUSE_LIBGNOMEPRINT