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
);
57 virtual wxImplDC
* CreatePrinterImplDC( wxPrinterDC
*owner
, const wxPrintData
& data
);
59 virtual wxDC
* CreatePrinterDC( const wxPrintData
& data
);
62 virtual bool HasPrintSetupDialog();
63 virtual wxDialog
*CreatePrintSetupDialog( wxWindow
*parent
, wxPrintData
*data
);
64 virtual bool HasOwnPrintToFile();
65 virtual bool HasPrinterLine();
66 virtual wxString
CreatePrinterLine();
67 virtual bool HasStatusLine();
68 virtual wxString
CreateStatusLine();
70 virtual wxPrintNativeDataBase
*CreatePrintNativeData();
73 //----------------------------------------------------------------------------
75 //----------------------------------------------------------------------------
77 class WXDLLIMPEXP_CORE wxGtkPrintDialog
: public wxPrintDialogBase
80 wxGtkPrintDialog( wxWindow
*parent
,
81 wxPrintDialogData
* data
= NULL
);
82 wxGtkPrintDialog( wxWindow
*parent
, wxPrintData
* data
);
83 virtual ~wxGtkPrintDialog();
85 wxPrintData
& GetPrintData()
86 { return m_printDialogData
.GetPrintData(); }
87 wxPrintDialogData
& GetPrintDialogData()
88 { return m_printDialogData
; }
90 wxDC
*GetPrintDC() { return m_dc
; }
91 void SetPrintDC(wxDC
* printDC
) { m_dc
= printDC
; }
93 virtual int ShowModal();
95 virtual bool Validate() { return true; }
96 virtual bool TransferDataToWindow() { return true; }
97 virtual bool TransferDataFromWindow() { return true; }
99 void SetShowDialog(bool show
) { m_showDialog
= show
; }
100 bool GetShowDialog() { return m_showDialog
; }
103 // Implement some base class methods to do nothing to avoid asserts and
104 // GTK warnings, since this is not a real wxDialog.
105 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
106 int WXUNUSED(width
), int WXUNUSED(height
),
107 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
108 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
109 int WXUNUSED(width
), int WXUNUSED(height
)) {}
112 wxPrintDialogData m_printDialogData
;
117 DECLARE_DYNAMIC_CLASS(wxGtkPrintDialog
)
120 //----------------------------------------------------------------------------
121 // wxGtkPageSetupDialog
122 //----------------------------------------------------------------------------
124 class WXDLLIMPEXP_CORE wxGtkPageSetupDialog
: public wxPageSetupDialogBase
127 wxGtkPageSetupDialog( wxWindow
*parent
,
128 wxPageSetupDialogData
* data
= NULL
);
129 virtual ~wxGtkPageSetupDialog();
131 virtual wxPageSetupDialogData
& GetPageSetupDialogData() { return m_pageDialogData
; }
133 virtual int ShowModal();
135 virtual bool Validate() { return true; }
136 virtual bool TransferDataToWindow() { return true; }
137 virtual bool TransferDataFromWindow() { return true; }
140 // Implement some base class methods to do nothing to avoid asserts and
141 // GTK warnings, since this is not a real wxDialog.
142 virtual void DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
143 int WXUNUSED(width
), int WXUNUSED(height
),
144 int WXUNUSED(sizeFlags
) = wxSIZE_AUTO
) {}
145 virtual void DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
),
146 int WXUNUSED(width
), int WXUNUSED(height
)) {}
149 wxPageSetupDialogData m_pageDialogData
;
152 DECLARE_DYNAMIC_CLASS(wxGtkPageSetupDialog
)
155 //----------------------------------------------------------------------------
157 //----------------------------------------------------------------------------
159 class WXDLLIMPEXP_CORE wxGtkPrinter
: public wxPrinterBase
162 wxGtkPrinter(wxPrintDialogData
*data
= NULL
);
163 virtual ~wxGtkPrinter();
165 virtual bool Print(wxWindow
*parent
,
166 wxPrintout
*printout
,
168 virtual wxDC
* PrintDialog(wxWindow
*parent
);
169 virtual bool Setup(wxWindow
*parent
);
171 GtkPrintContext
*GetPrintContext() { return m_gpc
; }
172 void SetPrintContext(GtkPrintContext
*context
) {m_gpc
= context
;}
173 void BeginPrint(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
);
174 void DrawPage(wxPrintout
*printout
, GtkPrintOperation
*operation
, GtkPrintContext
*context
, int page_nr
);
177 GtkPrintContext
*m_gpc
;
180 DECLARE_DYNAMIC_CLASS(wxGtkPrinter
)
181 DECLARE_NO_COPY_CLASS(wxGtkPrinter
)
184 //----------------------------------------------------------------------------
185 // wxGtkPrintNativeData
186 //----------------------------------------------------------------------------
188 class WXDLLIMPEXP_CORE wxGtkPrintNativeData
: public wxPrintNativeDataBase
191 wxGtkPrintNativeData();
192 virtual ~wxGtkPrintNativeData();
194 virtual bool TransferTo( wxPrintData
&data
);
195 virtual bool TransferFrom( const wxPrintData
&data
);
197 virtual bool Ok() const { return IsOk(); }
198 virtual bool IsOk() const { return true; }
200 GtkPrintSettings
* GetPrintConfig() { return m_config
; }
201 void SetPrintConfig( GtkPrintSettings
* config
);
203 void SetPrintJob( GtkPrintOperation
*job
) { m_job
= job
; }
204 GtkPrintOperation
* GetPrintJob() { return m_job
; }
206 GtkPrintContext
*GetPrintContext() { return m_context
; }
207 void SetPrintContext(GtkPrintContext
*context
) {m_context
= context
; }
210 GtkPageSetup
* GetPageSetupFromSettings(GtkPrintSettings
* settings
);
211 void SetPageSetupToSettings(GtkPrintSettings
* settings
, GtkPageSetup
* page_setup
);
214 GtkPrintSettings
*m_config
;
215 GtkPrintOperation
*m_job
;
216 GtkPrintContext
*m_context
;
218 DECLARE_DYNAMIC_CLASS(wxGtkPrintNativeData
)
221 //-----------------------------------------------------------------------------
223 //-----------------------------------------------------------------------------
226 class WXDLLIMPEXP_CORE wxGtkPrinterImplDC
: public wxImplDC
228 #define wxGtkPrinterImplDC wxGtkPrinterDC
229 class WXDLLIMPEXP_CORE wxGtkPrinterDC
: public wxDC
234 wxGtkPrinterImplDC( wxPrinterDC
*owner
, const wxPrintData
& data
);
236 wxGtkPrinterDC( const wxPrintData
& data
);
238 virtual ~wxGtkPrinterImplDC();
240 bool Ok() const { return IsOk(); }
243 bool CanDrawBitmap() const { return true; }
245 void SetFont( const wxFont
& font
);
246 void SetPen( const wxPen
& pen
);
247 void SetBrush( const wxBrush
& brush
);
248 void SetLogicalFunction( int function
);
249 void SetBackground( const wxBrush
& brush
);
250 void DestroyClippingRegion();
251 bool StartDoc(const wxString
& message
);
255 wxCoord
GetCharHeight() const;
256 wxCoord
GetCharWidth() const;
257 bool CanGetTextExtent() const { return true; }
258 wxSize
GetPPI() const;
259 virtual int GetDepth() const { return 24; }
260 void SetBackgroundMode(int mode
);
261 void SetPalette(const wxPalette
& WXUNUSED(palette
)) { }
262 void SetResolution(int ppi
);
264 // overriden for wxPrinterDC Impl
265 virtual int GetResolution();
266 virtual wxRect
GetPaperRect();
269 bool DoFloodFill(wxCoord x1
, wxCoord y1
, const wxColour
&col
, int style
=wxFLOOD_SURFACE
);
270 void DoGradientFillConcentric(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, const wxPoint
& circleCenter
);
271 void DoGradientFillLinear(const wxRect
& rect
, const wxColour
& initialColour
, const wxColour
& destColour
, wxDirection nDirection
= wxEAST
);
272 bool DoGetPixel(wxCoord x1
, wxCoord y1
, wxColour
*col
) const;
273 void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
274 void DoCrossHair(wxCoord x
, wxCoord y
);
275 void DoDrawArc(wxCoord x1
,wxCoord y1
,wxCoord x2
,wxCoord y2
,wxCoord xc
,wxCoord yc
);
276 void DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
);
277 void DoDrawPoint(wxCoord x
, wxCoord y
);
278 void DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0);
279 void DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
280 void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[], wxCoord xoffset
= 0, wxCoord yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
281 void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
282 void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
= 20.0);
283 void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
285 void DoDrawSpline(const wxPointList
*points
);
287 bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
288 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int rop
= wxCOPY
, bool useMask
= false,
289 wxCoord xsrcMask
= wxDefaultCoord
, wxCoord ysrcMask
= wxDefaultCoord
);
290 void DoDrawIcon( const wxIcon
& icon
, wxCoord x
, wxCoord y
);
291 void DoDrawBitmap( const wxBitmap
& bitmap
, wxCoord x
, wxCoord y
, bool useMask
= false );
292 void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
293 void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
, double angle
);
294 void DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
295 void DoSetClippingRegionAsRegion( const wxRegion
&WXUNUSED(clip
) ) { }
296 void DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
297 wxCoord
*descent
= (wxCoord
*) NULL
,
298 wxCoord
*externalLeading
= (wxCoord
*) NULL
,
299 const wxFont
*theFont
= (wxFont
*) NULL
) const;
300 void DoGetSize(int* width
, int* height
) const;
301 void DoGetSizeMM(int *width
, int *height
) const;
303 wxPrintData
& GetPrintData() { return m_printData
; }
304 void SetPrintData(const wxPrintData
& data
);
307 wxPrintData m_printData
;
308 PangoContext
*m_context
;
309 PangoLayout
*m_layout
;
310 PangoFontDescription
*m_fontdesc
;
313 unsigned char m_currentRed
;
314 unsigned char m_currentGreen
;
315 unsigned char m_currentBlue
;
316 unsigned char m_currentAlpha
;
318 GtkPrintContext
*m_gpc
;
323 DECLARE_DYNAMIC_CLASS(wxGtkPrinterImplDC
)
324 DECLARE_NO_COPY_CLASS(wxGtkPrinterImplDC
)
327 // ----------------------------------------------------------------------------
328 // wxGtkPrintPreview: programmer creates an object of this class to preview a
330 // ----------------------------------------------------------------------------
332 class WXDLLIMPEXP_CORE wxGtkPrintPreview
: public wxPrintPreviewBase
335 wxGtkPrintPreview(wxPrintout
*printout
,
336 wxPrintout
*printoutForPrinting
= (wxPrintout
*) NULL
,
337 wxPrintDialogData
*data
= (wxPrintDialogData
*) NULL
);
338 wxGtkPrintPreview(wxPrintout
*printout
,
339 wxPrintout
*printoutForPrinting
,
342 virtual ~wxGtkPrintPreview();
344 virtual bool Print(bool interactive
);
345 virtual void DetermineScaling();
348 void Init(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
);
350 DECLARE_CLASS(wxGtkPrintPreview
)