1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/dvrenderers.h
3 // Purpose: All GTK wxDataViewCtrl renderer classes
4 // Author: Robert Roebling, Vadim Zeitlin
5 // Created: 2009-11-07 (extracted from wx/gtk/dataview.h)
6 // Copyright: (c) 2006 Robert Roebling
7 // (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GTK_DVRENDERERS_H_
12 #define _WX_GTK_DVRENDERERS_H_
15 typedef struct _cairo_rectangle_int cairo_rectangle_int_t
;
16 typedef cairo_rectangle_int_t GdkRectangle
;
18 typedef struct _GdkRectangle GdkRectangle
;
21 // ---------------------------------------------------------
22 // wxDataViewTextRenderer
23 // ---------------------------------------------------------
25 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
28 wxDataViewTextRenderer( const wxString
&varianttype
= "string",
29 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
30 int align
= wxDVR_DEFAULT_ALIGNMENT
);
32 virtual bool SetValue( const wxVariant
&value
)
34 return SetTextValue(value
);
37 virtual bool GetValue( wxVariant
&value
) const
40 if ( !GetTextValue(str
) )
48 virtual void SetAlignment( int align
);
50 virtual bool GtkSupportsAttrs() const { return true; }
51 virtual bool GtkSetAttr(const wxDataViewItemAttr
& attr
);
53 virtual GtkCellRendererText
*GtkGetTextRenderer() const;
56 // implementation of Set/GetValue()
57 bool SetTextValue(const wxString
& str
);
58 bool GetTextValue(wxString
& str
) const;
61 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
64 // ---------------------------------------------------------
65 // wxDataViewBitmapRenderer
66 // ---------------------------------------------------------
68 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
71 wxDataViewBitmapRenderer( const wxString
&varianttype
= "wxBitmap",
72 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
73 int align
= wxDVR_DEFAULT_ALIGNMENT
);
75 bool SetValue( const wxVariant
&value
);
76 bool GetValue( wxVariant
&value
) const;
79 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
82 // ---------------------------------------------------------
83 // wxDataViewToggleRenderer
84 // ---------------------------------------------------------
86 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
89 wxDataViewToggleRenderer( const wxString
&varianttype
= "bool",
90 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
91 int align
= wxDVR_DEFAULT_ALIGNMENT
);
93 bool SetValue( const wxVariant
&value
);
94 bool GetValue( wxVariant
&value
) const;
97 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
100 // ---------------------------------------------------------
101 // wxDataViewCustomRenderer
102 // ---------------------------------------------------------
104 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewCustomRendererBase
107 wxDataViewCustomRenderer( const wxString
&varianttype
= "string",
108 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
109 int align
= wxDVR_DEFAULT_ALIGNMENT
,
110 bool no_init
= false );
111 virtual ~wxDataViewCustomRenderer();
114 // Create DC on request
115 virtual wxDC
*GetDC();
117 // override the base class function to use GTK text cell renderer
118 virtual void RenderText(const wxString
& text
,
124 struct GTKRenderParams
;
126 // store GTK render call parameters for possible later use
127 void GTKSetRenderParams(GTKRenderParams
* renderParams
)
129 m_renderParams
= renderParams
;
132 // we may or not support attributes, as we don't know it, return true to
133 // make it possible to use them
134 virtual bool GtkSupportsAttrs() const { return true; }
136 virtual bool GtkSetAttr(const wxDataViewItemAttr
& attr
)
139 return !attr
.IsDefault();
142 virtual GtkCellRendererText
*GtkGetTextRenderer() const;
145 bool Init(wxDataViewCellMode mode
, int align
);
147 // Called from GtkGetTextRenderer() to really create the renderer if
149 void GtkInitTextRenderer();
153 GtkCellRendererText
*m_text_renderer
;
155 // parameters of the original render() call stored so that we could pass
156 // them forward to m_text_renderer if our RenderText() is called
157 GTKRenderParams
* m_renderParams
;
159 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
162 // ---------------------------------------------------------
163 // wxDataViewProgressRenderer
164 // ---------------------------------------------------------
166 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
169 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
170 const wxString
&varianttype
= "long",
171 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
172 int align
= wxDVR_DEFAULT_ALIGNMENT
);
173 virtual ~wxDataViewProgressRenderer();
175 bool SetValue( const wxVariant
&value
);
176 bool GetValue( wxVariant
&value
) const;
178 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
179 virtual wxSize
GetSize() const;
188 // Flag used to indicate that we need to set the label because we were
189 // unable to do it in the ctor (see comments there).
190 bool m_needsToSetLabel
;
191 #endif // !wxUSE_UNICODE
194 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
197 // ---------------------------------------------------------
198 // wxDataViewIconTextRenderer
199 // ---------------------------------------------------------
201 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewTextRenderer
204 wxDataViewIconTextRenderer( const wxString
&varianttype
= "wxDataViewIconText",
205 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
206 int align
= wxDVR_DEFAULT_ALIGNMENT
);
207 virtual ~wxDataViewIconTextRenderer();
209 bool SetValue( const wxVariant
&value
);
210 bool GetValue( wxVariant
&value
) const;
212 virtual void GtkPackIntoColumn(GtkTreeViewColumn
*column
);
215 virtual void GtkOnCellChanged(const wxVariant
& value
,
216 const wxDataViewItem
& item
,
220 wxDataViewIconText m_value
;
222 // we use the base class m_renderer for the text and this one for the icon
223 GtkCellRenderer
*m_rendererIcon
;
225 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
228 // -------------------------------------
229 // wxDataViewChoiceRenderer
230 // -------------------------------------
232 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewCustomRenderer
235 wxDataViewChoiceRenderer(const wxArrayString
&choices
,
236 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
237 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
238 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
239 virtual wxSize
GetSize() const;
240 virtual bool SetValue( const wxVariant
&value
);
241 virtual bool GetValue( wxVariant
&value
) const;
243 void SetAlignment( int align
);
245 wxString
GetChoice(size_t index
) const { return m_choices
[index
]; }
246 const wxArrayString
& GetChoices() const { return m_choices
; }
249 wxArrayString m_choices
;
253 // ----------------------------------------------------------------------------
254 // wxDataViewChoiceByIndexRenderer
255 // ----------------------------------------------------------------------------
257 class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer
: public wxDataViewChoiceRenderer
260 wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
261 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
262 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
264 virtual bool SetValue( const wxVariant
&value
);
265 virtual bool GetValue( wxVariant
&value
) const;
268 virtual void GtkOnTextEdited(const char *itempath
, const wxString
& str
);
273 #endif // _WX_GTK_DVRENDERERS_H_