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 wxDCImpl
* CreatePrinterDCImpl( wxPrinterDC
*owner
, 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
;
176 DECLARE_DYNAMIC_CLASS(wxGtkPrinter
)
177 DECLARE_NO_COPY_CLASS(wxGtkPrinter
)
180 //----------------------------------------------------------------------------
181 // wxGtkPrintNativeData
182 //----------------------------------------------------------------------------
184 class WXDLLIMPEXP_CORE wxGtkPrintNativeData
: public wxPrintNativeDataBase
187 wxGtkPrintNativeData();
188 virtual ~wxGtkPrintNativeData();
190 virtual bool TransferTo( wxPrintData
&data
);
191 virtual bool TransferFrom( const wxPrintData
&data
);
193 virtual bool Ok() const { return IsOk(); }
194 virtual bool IsOk() const { return true; }
196 GtkPrintSettings
* GetPrintConfig() { return m_config
; }
197 void SetPrintConfig( GtkPrintSettings
* config
);
199 void SetPrintJob( GtkPrintOperation
*job
) { m_job
= job
; }
200 GtkPrintOperation
* GetPrintJob() { return m_job
; }
202 GtkPrintContext
*GetPrintContext() { return m_context
; }
203 void SetPrintContext(GtkPrintContext
*context
) {m_context
= context
; }
206 GtkPageSetup
* GetPageSetupFromSettings(GtkPrintSettings
* settings
);
207 void SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
);
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;
232 bool CanDrawBitmap() const { return true; }
234 void SetFont( const wxFont
& font
);
235 void SetPen( const wxPen
& pen
);
236 void SetBrush( const wxBrush
& brush
);
237 void SetLogicalFunction( int function
);
238 void SetBackground( const wxBrush
& brush
);
239 void DestroyClippingRegion();
240 bool StartDoc(const wxString
& message
);
244 wxCoord
GetCharHeight() const;
245 wxCoord
GetCharWidth() const;
246 bool CanGetTextExtent() const { return true; }
247 wxSize
GetPPI() const;
248 virtual int GetDepth() const { return 24; }
249 void SetBackgroundMode(int mode
);
250 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
251 void SetResolution(int ppi
);
253 // overriden for wxPrinterDC Impl
254 virtual int GetResolution() const;
255 virtual wxRect
GetPaperRect() const;
258 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
259 void DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
);
260 void DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
= wxEAST
);
261 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
262 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
263 void DoCrossHair(wxCoord x
, wxCoord y
);
264 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
265 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
266 void DoDrawPoint(wxCoord x
, wxCoord y
);
267 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
268 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
269 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
270 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
271 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
272 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
274 void DoDrawSpline(const wxPointList
*points
);
276 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
277 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
278 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
279 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
280 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
281 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
282 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
283 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
284 void DoSetDeviceClippingRegion( const wxRegion
&WXUNUSED(clip
) )
286 wxFAIL_MSG( "not implemented" );
288 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
289 wxCoord
*descent
= (wxCoord
*) NULL
,
290 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
291 const wxFont
*theFont
= (wxFont
*) NULL
) const;
292 void DoGetSize(int* width
, int* height
) const;
293 void DoGetSizeMM(int *width
, int *height
) const;
295 wxPrintData
& GetPrintData() { return m_printData
; }
296 void SetPrintData(const wxPrintData
& data
);
299 wxPrintData m_printData
;
300 PangoContext
*m_context
;
301 PangoLayout
*m_layout
;
302 PangoFontDescription
*m_fontdesc
;
305 unsigned char m_currentRed
;
306 unsigned char m_currentGreen
;
307 unsigned char m_currentBlue
;
308 unsigned char m_currentAlpha
;
310 GtkPrintContext
*m_gpc
;
315 DECLARE_DYNAMIC_CLASS(wxGtkPrinterDCImpl
)
316 DECLARE_NO_COPY_CLASS(wxGtkPrinterDCImpl
)
319 // ----------------------------------------------------------------------------
320 // wxGtkPrintPreview: programmer creates an object of this class to preview a
322 // ----------------------------------------------------------------------------
324 class WXDLLIMPEXP_CORE wxGtkPrintPreview
: public wxPrintPreviewBase
327 wxGtkPrintPreview(wxPrintout
*printout
,
328 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
329 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
330 wxGtkPrintPreview(wxPrintout
*printout
,
331 wxPrintout
*printoutForPrinting
,
334 virtual ~wxGtkPrintPreview();
336 virtual bool Print(bool interactive
);
337 virtual void DetermineScaling();
340 void Init(wxPrintout
*printout
,
341 wxPrintout
*printoutForPrinting
,
344 // resolution to use in DPI
347 DECLARE_CLASS(wxGtkPrintPreview
)
350 #endif // wxUSE_GTKPRINT
352 #endif // _WX_GTK_PRINT_H_