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_
16 typedef struct _cairo_rectangle_int cairo_rectangle_int_t
;
17 typedef cairo_rectangle_int_t GdkRectangle
;
19 typedef struct _GdkRectangle GdkRectangle
;
22 // ---------------------------------------------------------
23 // wxDataViewTextRenderer
24 // ---------------------------------------------------------
26 class WXDLLIMPEXP_ADV wxDataViewTextRenderer
: public wxDataViewRenderer
29 wxDataViewTextRenderer( const wxString
&varianttype
= "string",
30 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
31 int align
= wxDVR_DEFAULT_ALIGNMENT
);
33 virtual bool SetValue( const wxVariant
&value
)
35 return SetTextValue(value
);
38 virtual bool GetValue( wxVariant
&value
) const
41 if ( !GetTextValue(str
) )
49 virtual void SetAlignment( int align
);
51 virtual bool GtkSupportsAttrs() const { return true; }
52 virtual bool GtkSetAttr(const wxDataViewItemAttr
& attr
);
54 virtual GtkCellRendererText
*GtkGetTextRenderer() const;
57 // implementation of Set/GetValue()
58 bool SetTextValue(const wxString
& str
);
59 bool GetTextValue(wxString
& str
) const;
62 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer
)
65 // ---------------------------------------------------------
66 // wxDataViewBitmapRenderer
67 // ---------------------------------------------------------
69 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer
: public wxDataViewRenderer
72 wxDataViewBitmapRenderer( const wxString
&varianttype
= "wxBitmap",
73 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
74 int align
= wxDVR_DEFAULT_ALIGNMENT
);
76 bool SetValue( const wxVariant
&value
);
77 bool GetValue( wxVariant
&value
) const;
80 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer
)
83 // ---------------------------------------------------------
84 // wxDataViewToggleRenderer
85 // ---------------------------------------------------------
87 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer
: public wxDataViewRenderer
90 wxDataViewToggleRenderer( const wxString
&varianttype
= "bool",
91 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
92 int align
= wxDVR_DEFAULT_ALIGNMENT
);
94 bool SetValue( const wxVariant
&value
);
95 bool GetValue( wxVariant
&value
) const;
98 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer
)
101 // ---------------------------------------------------------
102 // wxDataViewCustomRenderer
103 // ---------------------------------------------------------
105 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer
: public wxDataViewCustomRendererBase
108 wxDataViewCustomRenderer( const wxString
&varianttype
= "string",
109 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
110 int align
= wxDVR_DEFAULT_ALIGNMENT
,
111 bool no_init
= false );
112 virtual ~wxDataViewCustomRenderer();
115 // Create DC on request
116 virtual wxDC
*GetDC();
118 // override the base class function to use GTK text cell renderer
119 virtual void RenderText(const wxString
& text
,
125 struct GTKRenderParams
;
127 // store GTK render call parameters for possible later use
128 void GTKSetRenderParams(GTKRenderParams
* renderParams
)
130 m_renderParams
= renderParams
;
133 // we may or not support attributes, as we don't know it, return true to
134 // make it possible to use them
135 virtual bool GtkSupportsAttrs() const { return true; }
137 virtual bool GtkSetAttr(const wxDataViewItemAttr
& attr
)
140 return !attr
.IsDefault();
143 virtual GtkCellRendererText
*GtkGetTextRenderer() const;
146 bool Init(wxDataViewCellMode mode
, int align
);
149 // Called from GtkGetTextRenderer() to really create the renderer if
151 void GtkInitTextRenderer();
155 GtkCellRendererText
*m_text_renderer
;
157 // parameters of the original render() call stored so that we could pass
158 // them forward to m_text_renderer if our RenderText() is called
159 GTKRenderParams
* m_renderParams
;
161 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
164 // ---------------------------------------------------------
165 // wxDataViewProgressRenderer
166 // ---------------------------------------------------------
168 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
171 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
172 const wxString
&varianttype
= "long",
173 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
174 int align
= wxDVR_DEFAULT_ALIGNMENT
);
175 virtual ~wxDataViewProgressRenderer();
177 bool SetValue( const wxVariant
&value
);
178 bool GetValue( wxVariant
&value
) const;
180 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
181 virtual wxSize
GetSize() const;
190 // Flag used to indicate that we need to set the label because we were
191 // unable to do it in the ctor (see comments there).
192 bool m_needsToSetLabel
;
193 #endif // !wxUSE_UNICODE
196 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
199 // ---------------------------------------------------------
200 // wxDataViewIconTextRenderer
201 // ---------------------------------------------------------
203 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewTextRenderer
206 wxDataViewIconTextRenderer( const wxString
&varianttype
= "wxDataViewIconText",
207 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
208 int align
= wxDVR_DEFAULT_ALIGNMENT
);
209 virtual ~wxDataViewIconTextRenderer();
211 bool SetValue( const wxVariant
&value
);
212 bool GetValue( wxVariant
&value
) const;
214 virtual void GtkPackIntoColumn(GtkTreeViewColumn
*column
);
217 virtual void GtkOnCellChanged(const wxVariant
& value
,
218 const wxDataViewItem
& item
,
222 wxDataViewIconText m_value
;
224 // we use the base class m_renderer for the text and this one for the icon
225 GtkCellRenderer
*m_rendererIcon
;
227 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
230 // -------------------------------------
231 // wxDataViewChoiceRenderer
232 // -------------------------------------
234 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewCustomRenderer
237 wxDataViewChoiceRenderer(const wxArrayString
&choices
,
238 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
239 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
240 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
241 virtual wxSize
GetSize() const;
242 virtual bool SetValue( const wxVariant
&value
);
243 virtual bool GetValue( wxVariant
&value
) const;
245 void SetAlignment( int align
);
247 wxString
GetChoice(size_t index
) const { return m_choices
[index
]; }
248 const wxArrayString
& GetChoices() const { return m_choices
; }
251 wxArrayString m_choices
;
255 // ----------------------------------------------------------------------------
256 // wxDataViewChoiceByIndexRenderer
257 // ----------------------------------------------------------------------------
259 class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer
: public wxDataViewChoiceRenderer
262 wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
263 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
264 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
266 virtual bool SetValue( const wxVariant
&value
);
267 virtual bool GetValue( wxVariant
&value
) const;
270 virtual void GtkOnTextEdited(const char *itempath
, const wxString
& str
);
275 #endif // _WX_GTK_DVRENDERERS_H_