1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.h
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
6 // RCS-ID: $Id: print.h,v 1 2007-08-25 05:44:44 PC Exp $
7 // Copyright: (c) 2007 wxWidgets development team
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GTK_PRINT_H_
12 #define _WX_GTK_PRINT_H_
19 #include "wx/printdlg.h"
20 #include "wx/prntbase.h"
23 typedef struct _GtkPrintOperation GtkPrintOperation
;
24 typedef struct _GtkPrintContext GtkPrintContext
;
25 typedef struct _GtkPrintSettings GtkPrintSettings
;
26 typedef struct _GtkPageSetup GtkPageSetup
;
28 typedef struct _cairo cairo_t
;
30 //----------------------------------------------------------------------------
32 //----------------------------------------------------------------------------
34 class wxGtkPrintFactory
: public wxPrintFactory
37 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
39 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
40 wxPrintout
*printout
= NULL
,
41 wxPrintDialogData
*data
= NULL
);
42 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
46 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
47 wxPrintDialogData
*data
= NULL
);
48 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
51 virtual wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
52 wxPageSetupDialogData
* data
= NULL
);
54 virtual wxDC
* CreatePrinterDC( const wxPrintData
& data
);
56 virtual bool HasPrintSetupDialog();
57 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
58 virtual bool HasOwnPrintToFile();
59 virtual bool HasPrinterLine();
60 virtual wxString
CreatePrinterLine();
61 virtual bool HasStatusLine();
62 virtual wxString
CreateStatusLine();
64 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
67 //----------------------------------------------------------------------------
69 //----------------------------------------------------------------------------
71 class WXDLLIMPEXP_CORE wxGtkPrintDialog
: public wxPrintDialogBase
74 wxGtkPrintDialog( wxWindow
*parent
,
75 wxPrintDialogData
* data
= NULL
);
76 wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
* data
);
77 virtual ~wxGtkPrintDialog();
79 wxPrintData
& GetPrintData()
80 { return m_printDialogData
.GetPrintData(); }
81 wxPrintDialogData
& GetPrintDialogData()
82 { return m_printDialogData
; }
84 wxDC
*GetPrintDC() { return m_dc
; }
85 void SetPrintDC(wxDC
* printDC
) { m_dc
= printDC
; }
87 virtual int ShowModal();
89 virtual bool Validate() { return true; }
90 virtual bool TransferDataToWindow() { return true; }
91 virtual bool TransferDataFromWindow() { return true; }
93 void SetShowDialog(bool show
) { m_showDialog
= show
; }
94 bool GetShowDialog() { return m_showDialog
; }
97 // Implement some base class methods to do nothing to avoid asserts and
98 // GTK warnings, since this is not a real wxDialog.
99 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
100 int WXUNUSED(width
), int WXUNUSED(height
),
101 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
102 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
103 int WXUNUSED(width
), int WXUNUSED(height
)) {}
106 wxPrintDialogData m_printDialogData
;
111 DECLARE_DYNAMIC_CLASS(wxGtkPrintDialog
)
114 //----------------------------------------------------------------------------
115 // wxGtkPageSetupDialog
116 //----------------------------------------------------------------------------
118 class WXDLLIMPEXP_CORE wxGtkPageSetupDialog
: public wxPageSetupDialogBase
121 wxGtkPageSetupDialog( wxWindow
*parent
,
122 wxPageSetupDialogData
* data
= NULL
);
123 virtual ~wxGtkPageSetupDialog();
125 virtual wxPageSetupDialogData
& GetPageSetupDialogData() { return m_pageDialogData
; }
127 virtual int ShowModal();
129 virtual bool Validate() { return true; }
130 virtual bool TransferDataToWindow() { return true; }
131 virtual bool TransferDataFromWindow() { return true; }
134 // Implement some base class methods to do nothing to avoid asserts and
135 // GTK warnings, since this is not a real wxDialog.
136 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
137 int WXUNUSED(width
), int WXUNUSED(height
),
138 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
139 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
140 int WXUNUSED(width
), int WXUNUSED(height
)) {}
143 wxPageSetupDialogData m_pageDialogData
;
146 DECLARE_DYNAMIC_CLASS(wxGtkPageSetupDialog
)
149 //----------------------------------------------------------------------------
151 //----------------------------------------------------------------------------
153 class WXDLLIMPEXP_CORE wxGtkPrinter
: public wxPrinterBase
156 wxGtkPrinter(wxPrintDialogData
*data
= NULL
);
157 virtual ~wxGtkPrinter();
159 virtual bool Print(wxWindow
*parent
,
160 wxPrintout
*printout
,
162 virtual wxDC
* PrintDialog(wxWindow
*parent
);
163 virtual bool Setup(wxWindow
*parent
);
165 GtkPrintContext
*GetPrintContext() { return m_gpc
; }
166 void SetPrintContext(GtkPrintContext
*context
) {m_gpc
= context
;}
167 void BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
);
168 void DrawPage(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
, int page_nr
);
171 GtkPrintContext
*m_gpc
;
175 DECLARE_DYNAMIC_CLASS(wxGtkPrinter
)
176 DECLARE_NO_COPY_CLASS(wxGtkPrinter
)
179 //----------------------------------------------------------------------------
180 // wxGtkPrintNativeData
181 //----------------------------------------------------------------------------
183 class WXDLLIMPEXP_CORE wxGtkPrintNativeData
: public wxPrintNativeDataBase
186 wxGtkPrintNativeData();
187 virtual ~wxGtkPrintNativeData();
189 virtual bool TransferTo( wxPrintData
&data
);
190 virtual bool TransferFrom( const wxPrintData
&data
);
192 virtual bool Ok() const { return IsOk(); }
193 virtual bool IsOk() const { return true; }
195 GtkPrintSettings
* GetPrintConfig() { return m_config
; }
196 void SetPrintConfig( GtkPrintSettings
* config
);
198 void SetPrintJob( GtkPrintOperation
*job
) { m_job
= job
; }
199 GtkPrintOperation
* GetPrintJob() { return m_job
; }
201 GtkPrintContext
*GetPrintContext() { return m_context
; }
202 void SetPrintContext(GtkPrintContext
*context
) {m_context
= context
; }
205 GtkPageSetup
* GetPageSetupFromSettings(GtkPrintSettings
* settings
);
206 void SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
);
209 GtkPrintSettings
*m_config
;
210 GtkPrintOperation
*m_job
;
211 GtkPrintContext
*m_context
;
213 DECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData
)
216 //-----------------------------------------------------------------------------
218 //-----------------------------------------------------------------------------
220 class WXDLLIMPEXP_CORE wxGtkPrintDC
: public wxDC
223 wxGtkPrintDC( const wxPrintData
& data
);
224 virtual ~wxGtkPrintDC();
226 bool Ok() const { return IsOk(); }
229 bool CanDrawBitmap() const { return true; }
231 void SetFont( const wxFont
& font
);
232 void SetPen( const wxPen
& pen
);
233 void SetBrush( const wxBrush
& brush
);
234 void SetLogicalFunction( int function
);
235 void SetBackground( const wxBrush
& brush
);
236 void DestroyClippingRegion();
237 bool StartDoc(const wxString
& message
);
241 wxCoord
GetCharHeight() const;
242 wxCoord
GetCharWidth() const;
243 bool CanGetTextExtent() const { return true; }
244 wxSize
GetPPI() const;
245 void SetLogicalOrigin( wxCoord x
, wxCoord y
);
246 void SetDeviceOrigin( wxCoord x
, wxCoord y
);
247 virtual int GetDepth() const { return 24; }
248 void SetBackgroundMode(int WXUNUSED(mode
));
249 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
250 static void SetResolution(int ppi
);
251 static int GetResolution();
252 void DrawScaledBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
253 bool useMask
= false, int quality
= wxIMAGE_QUALITY_NORMAL
)
254 { DoDrawScaledBitmap( bmp
, x
, y
, w
, h
, useMask
, quality
); }
255 void DrawScaledBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
, const wxSize
& sz
,
256 bool useMask
= false, int quality
= wxIMAGE_QUALITY_NORMAL
)
257 { DoDrawScaledBitmap( bmp
, pt
.x
, pt
.y
, sz
.x
, sz
.y
, useMask
, quality
); }
258 void DrawScaledBitmap(const wxBitmap
&bmp
, const wxRect
& rect
,
259 bool useMask
= false, int quality
= wxIMAGE_QUALITY_NORMAL
)
260 { DoDrawScaledBitmap( bmp
, rect
.x
, rect
.y
, rect
.width
, rect
.height
, useMask
, quality
); }
263 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
264 void DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
);
265 void DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
= wxEAST
);
266 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
267 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
268 void DoCrossHair(wxCoord x
, wxCoord y
);
269 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
270 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
271 void DoDrawPoint(wxCoord x
, wxCoord y
);
272 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
273 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
274 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
275 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
276 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
277 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
279 void DoDrawSpline(wxList
*points
);
280 #endif // wxUSE_SPLINES
281 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
282 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
283 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
284 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
285 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
286 void DoDrawScaledBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
, bool useMask
= false, int quality
= wxIMAGE_QUALITY_NORMAL
);
287 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
288 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
289 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
290 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
291 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
292 wxCoord
*descent
= (wxCoord
*) NULL
,
293 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
294 const wxFont
*theFont
= (wxFont
*) NULL
) const;
295 void DoGetSize(int* width
, int* height
) const;
296 void DoGetSizeMM(int *width
, int *height
) const;
298 wxPrintData
& GetPrintData() { return m_printData
; }
299 void SetPrintData(const wxPrintData
& data
);
301 void ComputeScaleAndOrigin();
304 static float ms_PSScaleFactor
;
306 wxPrintData m_printData
;
307 PangoContext
*m_context
;
308 PangoLayout
*m_layout
;
309 PangoFontDescription
*m_fontdesc
;
312 unsigned char m_currentRed
;
313 unsigned char m_currentGreen
;
314 unsigned char m_currentBlue
;
315 unsigned char m_currentAlpha
;
320 GtkPrintContext
*m_gpc
;
321 static int ms_resolution
;
323 wxCoord
DeviceToLogicalX(wxCoord x
) const
326 if (m_signX
== -1) addValue
= m_deviceOffsetX
- m_deviceOriginX
; // right to left
327 else addValue
= m_deviceOriginX
;// left to right
328 return (wxCoord
) ((double)(x
- addValue
) * m_signX
+ m_logicalOriginX
);
330 wxCoord
DeviceToLogicalXRel(wxCoord x
) const
334 wxCoord
DeviceToLogicalY(wxCoord y
) const
337 if (m_signY
== -1) addValue
= m_deviceOffsetY
- m_deviceOriginY
; // bottom to up
338 else addValue
= m_deviceOriginY
;// up to bottom
339 return (wxCoord
) ((double)(y
- addValue
) * m_signY
+ m_logicalOriginY
);
341 wxCoord
DeviceToLogicalYRel(wxCoord y
) const
345 wxCoord
LogicalToDeviceX(wxCoord x
) const
348 if (m_signX
== -1) addValue
= m_deviceOffsetX
- m_deviceOriginX
; // right to left
349 else addValue
= m_deviceOriginX
;// left to right
350 return (wxCoord
) ((double)(x
- m_logicalOriginX
) * m_signX
+ addValue
);
352 wxCoord
LogicalToDeviceXRel(wxCoord x
) const
356 wxCoord
LogicalToDeviceY(wxCoord y
) const
359 if (m_signY
== -1) addValue
= m_deviceOffsetY
- m_deviceOriginY
; // bottom to up
360 else addValue
= m_deviceOriginY
;// up to bottom
361 return (wxCoord
) ((double)(y
- m_logicalOriginY
) * m_signY
+ addValue
);
363 wxCoord
LogicalToDeviceYRel(wxCoord y
) const
368 DECLARE_DYNAMIC_CLASS(wxGtkPrintDC
)
369 DECLARE_NO_COPY_CLASS(wxGtkPrintDC
)
372 // ----------------------------------------------------------------------------
373 // wxGtkPrintPreview: programmer creates an object of this class to preview a
375 // ----------------------------------------------------------------------------
377 class WXDLLIMPEXP_CORE wxGtkPrintPreview
: public wxPrintPreviewBase
380 wxGtkPrintPreview(wxPrintout
*printout
,
381 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
382 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
383 wxGtkPrintPreview(wxPrintout
*printout
,
384 wxPrintout
*printoutForPrinting
,
387 virtual ~wxGtkPrintPreview();
389 virtual bool Print(bool interactive
);
390 virtual void DetermineScaling();
393 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
395 DECLARE_CLASS(wxGtkPrintPreview
)