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)
7 // Copyright: (c) 2006 Robert Roebling
8 // (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GTK_DVRENDERERS_H_
13 #define _WX_GTK_DVRENDERERS_H_
15 typedef struct _GdkRectangle GdkRectangle
;
17 // ---------------------------------------------------------
18 // wxDataViewTextRenderer
19 // ---------------------------------------------------------
21 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
24 wxDataViewTextRenderer( const wxString
&varianttype
= "string",
25 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
26 int align
= wxDVR_DEFAULT_ALIGNMENT
);
28 virtual bool SetValue( const wxVariant
&value
)
30 return SetTextValue(value
);
33 virtual bool GetValue( wxVariant
&value
) const
36 if ( !GetTextValue(str
) )
44 virtual void SetAlignment( int align
);
46 virtual bool GtkSupportsAttrs() const { return true; }
47 virtual bool GtkSetAttr(const wxDataViewItemAttr
& attr
);
49 virtual GtkCellRendererText
*GtkGetTextRenderer() const;
52 // implementation of Set/GetValue()
53 bool SetTextValue(const wxString
& str
);
54 bool GetTextValue(wxString
& str
) const;
57 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
60 // ---------------------------------------------------------
61 // wxDataViewBitmapRenderer
62 // ---------------------------------------------------------
64 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
67 wxDataViewBitmapRenderer( const wxString
&varianttype
= "wxBitmap",
68 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
69 int align
= wxDVR_DEFAULT_ALIGNMENT
);
71 bool SetValue( const wxVariant
&value
);
72 bool GetValue( wxVariant
&value
) const;
75 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
78 // ---------------------------------------------------------
79 // wxDataViewToggleRenderer
80 // ---------------------------------------------------------
82 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
85 wxDataViewToggleRenderer( const wxString
&varianttype
= "bool",
86 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
87 int align
= wxDVR_DEFAULT_ALIGNMENT
);
89 bool SetValue( const wxVariant
&value
);
90 bool GetValue( wxVariant
&value
) const;
93 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
96 // ---------------------------------------------------------
97 // wxDataViewCustomRenderer
98 // ---------------------------------------------------------
100 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewCustomRendererBase
103 wxDataViewCustomRenderer( const wxString
&varianttype
= "string",
104 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
105 int align
= wxDVR_DEFAULT_ALIGNMENT
,
106 bool no_init
= false );
107 virtual ~wxDataViewCustomRenderer();
110 // Create DC on request
111 virtual wxDC
*GetDC();
113 // override the base class function to use GTK text cell renderer
114 virtual void RenderText(const wxString
& text
,
120 // store GTK render call parameters for possible later use
121 void GTKStashRenderParams(GdkWindow
*window
,
123 GdkRectangle
*background_area
,
124 GdkRectangle
*expose_area
,
127 m_renderParams
.window
= window
;
128 m_renderParams
.widget
= widget
;
129 m_renderParams
.background_area
= background_area
;
130 m_renderParams
.expose_area
= expose_area
;
131 m_renderParams
.flags
= flags
;
134 // we may or not support attributes, as we don't know it, return true to
135 // make it possible to use them
136 virtual bool GtkSupportsAttrs() const { return true; }
138 virtual bool GtkSetAttr(const wxDataViewItemAttr
& attr
)
141 return !attr
.IsDefault();
144 virtual GtkCellRendererText
*GtkGetTextRenderer() const;
147 bool Init(wxDataViewCellMode mode
, int align
);
150 // Called from GtkGetTextRenderer() to really create the renderer if
152 void GtkInitTextRenderer();
156 GtkCellRendererText
*m_text_renderer
;
158 // parameters of the original render() call stored so that we could pass
159 // them forward to m_text_renderer if our RenderText() is called
160 struct GTKRenderParams
164 GdkRectangle
*background_area
;
165 GdkRectangle
*expose_area
;
169 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
172 // ---------------------------------------------------------
173 // wxDataViewProgressRenderer
174 // ---------------------------------------------------------
176 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
179 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
180 const wxString
&varianttype
= "long",
181 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
182 int align
= wxDVR_DEFAULT_ALIGNMENT
);
183 virtual ~wxDataViewProgressRenderer();
185 bool SetValue( const wxVariant
&value
);
186 bool GetValue( wxVariant
&value
) const;
188 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
189 virtual wxSize
GetSize() const;
198 // Flag used to indicate that we need to set the label because we were
199 // unable to do it in the ctor (see comments there).
200 bool m_needsToSetLabel
;
201 #endif // !wxUSE_UNICODE
204 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
207 // ---------------------------------------------------------
208 // wxDataViewIconTextRenderer
209 // ---------------------------------------------------------
211 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewTextRenderer
214 wxDataViewIconTextRenderer( const wxString
&varianttype
= "wxDataViewIconText",
215 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
216 int align
= wxDVR_DEFAULT_ALIGNMENT
);
217 virtual ~wxDataViewIconTextRenderer();
219 bool SetValue( const wxVariant
&value
);
220 bool GetValue( wxVariant
&value
) const;
222 virtual void GtkPackIntoColumn(GtkTreeViewColumn
*column
);
225 virtual void GtkOnCellChanged(const wxVariant
& value
,
226 const wxDataViewItem
& item
,
230 wxDataViewIconText m_value
;
232 // we use the base class m_renderer for the text and this one for the icon
233 GtkCellRenderer
*m_rendererIcon
;
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
238 // -------------------------------------
239 // wxDataViewChoiceRenderer
240 // -------------------------------------
242 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewCustomRenderer
245 wxDataViewChoiceRenderer(const wxArrayString
&choices
,
246 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
247 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
248 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
249 virtual wxSize
GetSize() const;
250 virtual bool SetValue( const wxVariant
&value
);
251 virtual bool GetValue( wxVariant
&value
) const;
253 void SetAlignment( int align
);
255 wxString
GetChoice(size_t index
) const { return m_choices
[index
]; }
256 const wxArrayString
& GetChoices() const { return m_choices
; }
259 wxArrayString m_choices
;
263 // ----------------------------------------------------------------------------
264 // wxDataViewChoiceByIndexRenderer
265 // ----------------------------------------------------------------------------
267 class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer
: public wxDataViewChoiceRenderer
270 wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
271 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
272 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
274 virtual bool SetValue( const wxVariant
&value
);
275 virtual bool GetValue( wxVariant
&value
) const;
278 virtual void GtkOnTextEdited(const char *itempath
, const wxString
& str
);
283 #endif // _WX_GTK_DVRENDERERS_H_