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 struct GTKRenderParams
;
122 // store GTK render call parameters for possible later use
123 void GTKSetRenderParams(GTKRenderParams
* renderParams
)
125 m_renderParams
= renderParams
;
128 // we may or not support attributes, as we don't know it, return true to
129 // make it possible to use them
130 virtual bool GtkSupportsAttrs() const { return true; }
132 virtual bool GtkSetAttr(const wxDataViewItemAttr
& attr
)
135 return !attr
.IsDefault();
138 virtual GtkCellRendererText
*GtkGetTextRenderer() const;
141 bool Init(wxDataViewCellMode mode
, int align
);
144 // Called from GtkGetTextRenderer() to really create the renderer if
146 void GtkInitTextRenderer();
150 GtkCellRendererText
*m_text_renderer
;
152 // parameters of the original render() call stored so that we could pass
153 // them forward to m_text_renderer if our RenderText() is called
154 GTKRenderParams
* m_renderParams
;
156 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer
)
159 // ---------------------------------------------------------
160 // wxDataViewProgressRenderer
161 // ---------------------------------------------------------
163 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer
: public wxDataViewCustomRenderer
166 wxDataViewProgressRenderer( const wxString
&label
= wxEmptyString
,
167 const wxString
&varianttype
= "long",
168 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
169 int align
= wxDVR_DEFAULT_ALIGNMENT
);
170 virtual ~wxDataViewProgressRenderer();
172 bool SetValue( const wxVariant
&value
);
173 bool GetValue( wxVariant
&value
) const;
175 virtual bool Render( wxRect cell
, wxDC
*dc
, int state
);
176 virtual wxSize
GetSize() const;
185 // Flag used to indicate that we need to set the label because we were
186 // unable to do it in the ctor (see comments there).
187 bool m_needsToSetLabel
;
188 #endif // !wxUSE_UNICODE
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer
)
194 // ---------------------------------------------------------
195 // wxDataViewIconTextRenderer
196 // ---------------------------------------------------------
198 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer
: public wxDataViewTextRenderer
201 wxDataViewIconTextRenderer( const wxString
&varianttype
= "wxDataViewIconText",
202 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
203 int align
= wxDVR_DEFAULT_ALIGNMENT
);
204 virtual ~wxDataViewIconTextRenderer();
206 bool SetValue( const wxVariant
&value
);
207 bool GetValue( wxVariant
&value
) const;
209 virtual void GtkPackIntoColumn(GtkTreeViewColumn
*column
);
212 virtual void GtkOnCellChanged(const wxVariant
& value
,
213 const wxDataViewItem
& item
,
217 wxDataViewIconText m_value
;
219 // we use the base class m_renderer for the text and this one for the icon
220 GtkCellRenderer
*m_rendererIcon
;
222 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer
)
225 // -------------------------------------
226 // wxDataViewChoiceRenderer
227 // -------------------------------------
229 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer
: public wxDataViewCustomRenderer
232 wxDataViewChoiceRenderer(const wxArrayString
&choices
,
233 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
234 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
235 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
236 virtual wxSize
GetSize() const;
237 virtual bool SetValue( const wxVariant
&value
);
238 virtual bool GetValue( wxVariant
&value
) const;
240 void SetAlignment( int align
);
242 wxString
GetChoice(size_t index
) const { return m_choices
[index
]; }
243 const wxArrayString
& GetChoices() const { return m_choices
; }
246 wxArrayString m_choices
;
250 // ----------------------------------------------------------------------------
251 // wxDataViewChoiceByIndexRenderer
252 // ----------------------------------------------------------------------------
254 class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer
: public wxDataViewChoiceRenderer
257 wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
258 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
259 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
261 virtual bool SetValue( const wxVariant
&value
);
262 virtual bool GetValue( wxVariant
&value
) const;
265 virtual void GtkOnTextEdited(const char *itempath
, const wxString
& str
);
270 #endif // _WX_GTK_DVRENDERERS_H_