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) Anthony Bretaudeau
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"
25 typedef struct _GtkPrintOperation GtkPrintOperation
;
26 typedef struct _GtkPrintContext GtkPrintContext
;
27 typedef struct _GtkPrintSettings GtkPrintSettings
;
28 typedef struct _GtkPageSetup GtkPageSetup
;
30 typedef struct _cairo cairo_t
;
32 //----------------------------------------------------------------------------
34 //----------------------------------------------------------------------------
36 class wxGtkPrintFactory
: public wxPrintFactory
39 virtual wxPrinterBase
*CreatePrinter( wxPrintDialogData
*data
);
41 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
42 wxPrintout
*printout
= NULL
,
43 wxPrintDialogData
*data
= NULL
);
44 virtual wxPrintPreviewBase
*CreatePrintPreview( wxPrintout
*preview
,
48 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
49 wxPrintDialogData
*data
= NULL
);
50 virtual wxPrintDialogBase
*CreatePrintDialog( wxWindow
*parent
,
53 virtual wxPageSetupDialogBase
*CreatePageSetupDialog( wxWindow
*parent
,
54 wxPageSetupDialogData
* data
= NULL
);
56 virtual wxDC
* CreatePrinterDC( const wxPrintData
& data
);
58 virtual bool HasPrintSetupDialog();
59 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
60 virtual bool HasOwnPrintToFile();
61 virtual bool HasPrinterLine();
62 virtual wxString
CreatePrinterLine();
63 virtual bool HasStatusLine();
64 virtual wxString
CreateStatusLine();
66 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
69 //----------------------------------------------------------------------------
71 //----------------------------------------------------------------------------
73 class WXDLLIMPEXP_CORE wxGtkPrintDialog
: public wxPrintDialogBase
76 wxGtkPrintDialog( wxWindow
*parent
,
77 wxPrintDialogData
* data
= NULL
);
78 wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
* data
);
79 virtual ~wxGtkPrintDialog();
81 wxPrintData
& GetPrintData()
82 { return m_printDialogData
.GetPrintData(); }
83 wxPrintDialogData
& GetPrintDialogData()
84 { return m_printDialogData
; }
86 wxDC
*GetPrintDC() { return m_dc
; }
87 void SetPrintDC(wxDC
* printDC
) { m_dc
= printDC
; }
89 virtual int ShowModal();
91 virtual bool Validate() { return true; }
92 virtual bool TransferDataToWindow() { return true; }
93 virtual bool TransferDataFromWindow() { return true; }
95 void SetShowDialog(bool show
) { m_showDialog
= show
; }
96 bool GetShowDialog() { return m_showDialog
; }
99 // Implement some base class methods to do nothing to avoid asserts and
100 // GTK warnings, since this is not a real wxDialog.
101 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
102 int WXUNUSED(width
), int WXUNUSED(height
),
103 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
104 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
105 int WXUNUSED(width
), int WXUNUSED(height
)) {}
108 wxPrintDialogData m_printDialogData
;
113 DECLARE_DYNAMIC_CLASS(wxGtkPrintDialog
)
116 //----------------------------------------------------------------------------
117 // wxGtkPageSetupDialog
118 //----------------------------------------------------------------------------
120 class WXDLLIMPEXP_CORE wxGtkPageSetupDialog
: public wxPageSetupDialogBase
123 wxGtkPageSetupDialog( wxWindow
*parent
,
124 wxPageSetupDialogData
* data
= NULL
);
125 virtual ~wxGtkPageSetupDialog();
127 virtual wxPageSetupDialogData
& GetPageSetupDialogData() { return m_pageDialogData
; }
129 virtual int ShowModal();
131 virtual bool Validate() { return true; }
132 virtual bool TransferDataToWindow() { return true; }
133 virtual bool TransferDataFromWindow() { return true; }
136 // Implement some base class methods to do nothing to avoid asserts and
137 // GTK warnings, since this is not a real wxDialog.
138 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
139 int WXUNUSED(width
), int WXUNUSED(height
),
140 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
141 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
142 int WXUNUSED(width
), int WXUNUSED(height
)) {}
145 wxPageSetupDialogData m_pageDialogData
;
148 DECLARE_DYNAMIC_CLASS(wxGtkPageSetupDialog
)
151 //----------------------------------------------------------------------------
153 //----------------------------------------------------------------------------
155 class WXDLLIMPEXP_CORE wxGtkPrinter
: public wxPrinterBase
158 wxGtkPrinter(wxPrintDialogData
*data
= NULL
);
159 virtual ~wxGtkPrinter();
161 virtual bool Print(wxWindow
*parent
,
162 wxPrintout
*printout
,
164 virtual wxDC
* PrintDialog(wxWindow
*parent
);
165 virtual bool Setup(wxWindow
*parent
);
167 GtkPrintContext
*GetPrintContext() { return m_gpc
; }
168 void SetPrintContext(GtkPrintContext
*context
) {m_gpc
= context
;}
169 void BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
);
170 void DrawPage(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
, int page_nr
);
173 GtkPrintContext
*m_gpc
;
177 DECLARE_DYNAMIC_CLASS(wxGtkPrinter
)
178 DECLARE_NO_COPY_CLASS(wxGtkPrinter
)
181 //----------------------------------------------------------------------------
182 // wxGtkPrintNativeData
183 //----------------------------------------------------------------------------
185 class WXDLLIMPEXP_CORE wxGtkPrintNativeData
: public wxPrintNativeDataBase
188 wxGtkPrintNativeData();
189 virtual ~wxGtkPrintNativeData();
191 virtual bool TransferTo( wxPrintData
&data
);
192 virtual bool TransferFrom( const wxPrintData
&data
);
194 virtual bool Ok() const { return IsOk(); }
195 virtual bool IsOk() const { return true; }
197 GtkPrintSettings
* GetPrintConfig() { return m_config
; }
198 void SetPrintConfig( GtkPrintSettings
* config
);
200 void SetPrintJob( GtkPrintOperation
*job
) { m_job
= job
; }
201 GtkPrintOperation
* GetPrintJob() { return m_job
; }
203 GtkPrintContext
*GetPrintContext() { return m_context
; }
204 void SetPrintContext(GtkPrintContext
*context
) {m_context
= context
; }
207 GtkPageSetup
* GetPageSetupFromSettings(GtkPrintSettings
* settings
);
208 void SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
);
211 GtkPrintSettings
*m_config
;
212 GtkPrintOperation
*m_job
;
213 GtkPrintContext
*m_context
;
215 DECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData
)
218 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
222 class WXDLLIMPEXP_CORE wxGtkPrintDC
: public wxDC
225 wxGtkPrintDC( const wxPrintData
& data
);
226 virtual ~wxGtkPrintDC();
228 bool Ok() const { return IsOk(); }
231 bool CanDrawBitmap() const { return true; }
233 void SetFont( const wxFont
& font
);
234 void SetPen( const wxPen
& pen
);
235 void SetBrush( const wxBrush
& brush
);
236 void SetLogicalFunction( int function
);
237 void SetBackground( const wxBrush
& brush
);
238 void DestroyClippingRegion();
239 bool StartDoc(const wxString
& message
);
243 wxCoord
GetCharHeight() const;
244 wxCoord
GetCharWidth() const;
245 bool CanGetTextExtent() const { return true; }
246 wxSize
GetPPI() const;
247 void SetLogicalOrigin( wxCoord x
, wxCoord y
);
248 void SetDeviceOrigin( wxCoord x
, wxCoord y
);
249 virtual int GetDepth() const { return 24; }
250 void SetBackgroundMode(int WXUNUSED(mode
));
251 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
252 static void SetResolution(int ppi
);
253 static int GetResolution();
254 void DrawScaledBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
255 bool useMask
= false, int quality
= wxIMAGE_QUALITY_NORMAL
)
256 { DoDrawScaledBitmap( bmp
, x
, y
, w
, h
, useMask
, quality
); }
257 void DrawScaledBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
, const wxSize
& sz
,
258 bool useMask
= false, int quality
= wxIMAGE_QUALITY_NORMAL
)
259 { DoDrawScaledBitmap( bmp
, pt
.x
, pt
.y
, sz
.x
, sz
.y
, useMask
, quality
); }
260 void DrawScaledBitmap(const wxBitmap
&bmp
, const wxRect
& rect
,
261 bool useMask
= false, int quality
= wxIMAGE_QUALITY_NORMAL
)
262 { DoDrawScaledBitmap( bmp
, rect
.x
, rect
.y
, rect
.width
, rect
.height
, useMask
, quality
); }
265 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
266 void DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
);
267 void DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
= wxEAST
);
268 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
269 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
270 void DoCrossHair(wxCoord x
, wxCoord y
);
271 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
272 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
273 void DoDrawPoint(wxCoord x
, wxCoord y
);
274 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
275 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
276 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
277 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
278 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
279 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
281 void DoDrawSpline(wxList
*points
);
282 #endif // wxUSE_SPLINES
283 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
284 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
285 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
286 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
287 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
288 void DoDrawScaledBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
, bool useMask
= false, int quality
= wxIMAGE_QUALITY_NORMAL
);
289 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
290 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
291 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
292 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
293 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
294 wxCoord
*descent
= (wxCoord
*) NULL
,
295 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
296 const wxFont
*theFont
= (wxFont
*) NULL
) const;
297 void DoGetSize(int* width
, int* height
) const;
298 void DoGetSizeMM(int *width
, int *height
) const;
300 wxPrintData
& GetPrintData() { return m_printData
; }
301 void SetPrintData(const wxPrintData
& data
);
303 void ComputeScaleAndOrigin();
306 static float ms_PSScaleFactor
;
308 wxPrintData m_printData
;
309 PangoContext
*m_context
;
310 PangoLayout
*m_layout
;
311 PangoFontDescription
*m_fontdesc
;
314 unsigned char m_currentRed
;
315 unsigned char m_currentGreen
;
316 unsigned char m_currentBlue
;
317 unsigned char m_currentAlpha
;
322 GtkPrintContext
*m_gpc
;
323 static int ms_resolution
;
325 wxCoord
DeviceToLogicalX(wxCoord x
) const
328 if (m_signX
== -1) addValue
= m_deviceOffsetX
- m_deviceOriginX
; // right to left
329 else addValue
= m_deviceOriginX
;// left to right
330 return (wxCoord
) ((double)(x
- addValue
) * m_signX
+ m_logicalOriginX
);
332 wxCoord
DeviceToLogicalXRel(wxCoord x
) const
336 wxCoord
DeviceToLogicalY(wxCoord y
) const
339 if (m_signY
== -1) addValue
= m_deviceOffsetY
- m_deviceOriginY
; // bottom to up
340 else addValue
= m_deviceOriginY
;// up to bottom
341 return (wxCoord
) ((double)(y
- addValue
) * m_signY
+ m_logicalOriginY
);
343 wxCoord
DeviceToLogicalYRel(wxCoord y
) const
347 wxCoord
CairoToLogicalX(double x
) const
350 if (m_signX
== -1) addValue
= m_deviceOffsetX
- m_deviceOriginX
; // right to left
351 else addValue
= m_deviceOriginX
;// left to right
352 return (wxCoord
) MapFromCairo((double)(x
- addValue
) * m_signX
+ m_logicalOriginX
);
354 wxCoord
CairoToLogicalXRel(double x
) const
356 return (wxCoord
) MapFromCairo(x
);
358 wxCoord
CairoToLogicalY(double y
) const
361 if (m_signY
== -1) addValue
= m_deviceOffsetY
- m_deviceOriginY
; // bottom to up
362 else addValue
= m_deviceOriginY
;// up to bottom
363 return (wxCoord
) MapFromCairo((double)(y
- addValue
) * m_signY
+ m_logicalOriginY
);
365 wxCoord
CairoToLogicalYRel(double y
) const
367 return (wxCoord
) MapFromCairo(y
);
369 wxCoord
LogicalToDeviceX(wxCoord x
) const
372 if (m_signX
== -1) addValue
= m_deviceOffsetX
- m_deviceOriginX
; // right to left
373 else addValue
= m_deviceOriginX
;// left to right
374 return (wxCoord
) ((double)(x
- m_logicalOriginX
) * m_signX
+ addValue
);
376 wxCoord
LogicalToDeviceXRel(wxCoord x
) const
380 wxCoord
LogicalToDeviceY(wxCoord y
) const
383 if (m_signY
== -1) addValue
= m_deviceOffsetY
- m_deviceOriginY
; // bottom to up
384 else addValue
= m_deviceOriginY
;// up to bottom
385 return (wxCoord
) ((double)(y
- m_logicalOriginY
) * m_signY
+ addValue
);
387 wxCoord
LogicalToDeviceYRel(wxCoord y
) const
391 double LogicalToCairoX(wxCoord x
) const
394 if (m_signX
== -1) addValue
= m_deviceOffsetX
- m_deviceOriginX
; // right to left
395 else addValue
= m_deviceOriginX
;// left to right
396 return MapToCairo((double)(x
- m_logicalOriginX
) * m_signX
+ addValue
);
398 double LogicalToCairoXRel(wxCoord x
) const
400 return MapToCairo(x
);
402 double LogicalToCairoY(wxCoord y
) const
405 if (m_signY
== -1) addValue
= m_deviceOffsetY
- m_deviceOriginY
; // bottom to up
406 else addValue
= m_deviceOriginY
;// up to bottom
407 return MapToCairo((double)(y
- m_logicalOriginY
) * m_signY
+ addValue
);
409 double LogicalToCairoYRel(wxCoord y
) const
411 return MapToCairo(y
);
413 double MapToCairo(wxCoord coordInt
) const
415 return (double)coordInt
*72.0/(double)ms_resolution
;
417 double MapToCairo(double coordReal
) const
419 return coordReal
*72.0/(double)ms_resolution
;
421 wxCoord
MapFromCairo(wxCoord coordInt
) const
423 return (wxCoord
) ((double)coordInt
*(double)ms_resolution
/72.0);
425 wxCoord
MapFromCairo(double coordReal
) const
427 return (wxCoord
) (coordReal
*(double)ms_resolution
/72.0);
429 DECLARE_DYNAMIC_CLASS(wxGtkPrintDC
)
430 DECLARE_NO_COPY_CLASS(wxGtkPrintDC
)
433 // ----------------------------------------------------------------------------
434 // wxGtkPrintPreview: programmer creates an object of this class to preview a
436 // ----------------------------------------------------------------------------
438 class WXDLLIMPEXP_CORE wxGtkPrintPreview
: public wxPrintPreviewBase
441 wxGtkPrintPreview(wxPrintout
*printout
,
442 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
443 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
444 wxGtkPrintPreview(wxPrintout
*printout
,
445 wxPrintout
*printoutForPrinting
,
448 virtual ~wxGtkPrintPreview();
450 virtual bool Print(bool interactive
);
451 virtual void DetermineScaling();
454 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
456 DECLARE_CLASS(wxGtkPrintPreview
)