1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/print.h
3 // Author: Anthony Bretaudeau
4 // Purpose: GTK printing support
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"
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 wxDCImpl
* CreatePrinterDCImpl( wxPrinterDC
*owner
, 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
;
174 DECLARE_DYNAMIC_CLASS(wxGtkPrinter
)
175 wxDECLARE_NO_COPY_CLASS(wxGtkPrinter
);
178 //----------------------------------------------------------------------------
179 // wxGtkPrintNativeData
180 //----------------------------------------------------------------------------
182 class WXDLLIMPEXP_CORE wxGtkPrintNativeData
: public wxPrintNativeDataBase
185 wxGtkPrintNativeData();
186 virtual ~wxGtkPrintNativeData();
188 virtual bool TransferTo( wxPrintData
&data
);
189 virtual bool TransferFrom( const wxPrintData
&data
);
191 virtual bool Ok() const { return IsOk(); }
192 virtual bool IsOk() const { return true; }
194 GtkPrintSettings
* GetPrintConfig() { return m_config
; }
195 void SetPrintConfig( GtkPrintSettings
* config
);
197 GtkPrintOperation
* GetPrintJob() { return m_job
; }
198 void SetPrintJob(GtkPrintOperation
*job
) { m_job
= job
; }
200 GtkPrintContext
*GetPrintContext() { return m_context
; }
201 void SetPrintContext(GtkPrintContext
*context
) {m_context
= context
; }
204 GtkPageSetup
* GetPageSetupFromSettings(GtkPrintSettings
* settings
);
205 void SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
);
208 // NB: m_config is created and owned by us, but the other objects are not
209 // and their accessors don't change their ref count.
210 GtkPrintSettings
*m_config
;
211 GtkPrintOperation
*m_job
;
212 GtkPrintContext
*m_context
;
214 DECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData
)
217 //-----------------------------------------------------------------------------
219 //-----------------------------------------------------------------------------
221 class WXDLLIMPEXP_CORE wxGtkPrinterDCImpl
: public wxDCImpl
224 wxGtkPrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& data
);
225 virtual ~wxGtkPrinterDCImpl();
227 bool Ok() const { return IsOk(); }
230 virtual void* GetCairoContext() const;
231 virtual void* GetHandle() const;
233 bool CanDrawBitmap() const { return true; }
235 void SetFont( const wxFont
& font
);
236 void SetPen( const wxPen
& pen
);
237 void SetBrush( const wxBrush
& brush
);
238 void SetLogicalFunction( wxRasterOperationMode function
);
239 void SetBackground( const wxBrush
& brush
);
240 void DestroyClippingRegion();
241 bool StartDoc(const wxString
& message
);
245 wxCoord
GetCharHeight() const;
246 wxCoord
GetCharWidth() const;
247 bool CanGetTextExtent() const { return true; }
248 wxSize
GetPPI() const;
249 virtual int GetDepth() const { return 24; }
250 void SetBackgroundMode(int mode
);
251 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
252 void SetResolution(int ppi
);
254 // overridden for wxPrinterDC Impl
255 virtual int GetResolution() const;
256 virtual wxRect
GetPaperRect() const;
259 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
,
260 wxFloodFillStyle style
=wxFLOOD_SURFACE
);
261 void DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
);
262 void DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
= wxEAST
);
263 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
264 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
265 void DoCrossHair(wxCoord x
, wxCoord y
);
266 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
267 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
268 void DoDrawPoint(wxCoord x
, wxCoord y
);
269 void DoDrawLines(int n
, const wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
270 void DoDrawPolygon(int n
, const wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, wxPolygonFillMode fillStyle
=wxODDEVEN_RULE
);
271 void DoDrawPolyPolygon(int n
, const int count
[], const wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, wxPolygonFillMode fillStyle
=wxODDEVEN_RULE
);
272 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
273 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
274 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
276 void DoDrawSpline(const wxPointList
*points
);
278 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
279 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
280 wxRasterOperationMode rop
= wxCOPY
, bool useMask
= false,
281 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
282 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
283 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
284 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
285 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
286 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
287 void DoSetDeviceClippingRegion( const wxRegion
&WXUNUSED(clip
) )
289 wxFAIL_MSG( "not implemented" );
291 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
292 wxCoord
*descent
= NULL
,
293 wxCoord
*externalLeading
= NULL
,
294 const wxFont
*theFont
= 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
);
302 wxPrintData m_printData
;
303 PangoContext
*m_context
;
304 PangoLayout
*m_layout
;
305 PangoFontDescription
*m_fontdesc
;
308 unsigned char m_currentRed
;
309 unsigned char m_currentGreen
;
310 unsigned char m_currentBlue
;
311 unsigned char m_currentAlpha
;
313 GtkPrintContext
*m_gpc
;
318 DECLARE_DYNAMIC_CLASS(wxGtkPrinterDCImpl
)
319 wxDECLARE_NO_COPY_CLASS(wxGtkPrinterDCImpl
);
322 // ----------------------------------------------------------------------------
323 // wxGtkPrintPreview: programmer creates an object of this class to preview a
325 // ----------------------------------------------------------------------------
327 class WXDLLIMPEXP_CORE wxGtkPrintPreview
: public wxPrintPreviewBase
330 wxGtkPrintPreview(wxPrintout
*printout
,
331 wxPrintout
*printoutForPrinting
= NULL
,
332 wxPrintDialogData
*data
= NULL
);
333 wxGtkPrintPreview(wxPrintout
*printout
,
334 wxPrintout
*printoutForPrinting
,
337 virtual ~wxGtkPrintPreview();
339 virtual bool Print(bool interactive
);
340 virtual void DetermineScaling();
343 void Init(wxPrintout
*printout
,
344 wxPrintout
*printoutForPrinting
,
347 // resolution to use in DPI
350 DECLARE_CLASS(wxGtkPrintPreview
)
353 #endif // wxUSE_GTKPRINT
355 #endif // _WX_GTK_PRINT_H_