Add support for custom attributes to wxGTK wxDataViewCustomRenderer.
[wxWidgets.git] / include / wx / gtk / dvrenderers.h
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 // RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
7 // Copyright: (c) 2006 Robert Roebling
8 // (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GTK_DVRENDERERS_H_
13 #define _WX_GTK_DVRENDERERS_H_
14
15 typedef struct _GdkRectangle GdkRectangle;
16 typedef struct _GtkCellRendererText GtkCellRendererText;
17
18 // ---------------------------------------------------------
19 // wxDataViewTextRenderer
20 // ---------------------------------------------------------
21
22 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
23 {
24 public:
25 wxDataViewTextRenderer( const wxString &varianttype = "string",
26 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
27 int align = wxDVR_DEFAULT_ALIGNMENT );
28
29 virtual bool SetValue( const wxVariant &value )
30 {
31 return SetTextValue(value);
32 }
33
34 virtual bool GetValue( wxVariant &value ) const
35 {
36 wxString str;
37 if ( !GetTextValue(str) )
38 return false;
39
40 value = str;
41
42 return true;
43 }
44
45 virtual void SetAlignment( int align );
46
47 virtual bool GtkSupportsAttrs() const { return true; }
48 virtual bool GtkSetAttr(const wxDataViewItemAttr& attr);
49
50 protected:
51 // implementation of Set/GetValue()
52 bool SetTextValue(const wxString& str);
53 bool GetTextValue(wxString& str) const;
54
55
56 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
57 };
58
59 // ---------------------------------------------------------
60 // wxDataViewBitmapRenderer
61 // ---------------------------------------------------------
62
63 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
64 {
65 public:
66 wxDataViewBitmapRenderer( const wxString &varianttype = "wxBitmap",
67 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
68 int align = wxDVR_DEFAULT_ALIGNMENT );
69
70 bool SetValue( const wxVariant &value );
71 bool GetValue( wxVariant &value ) const;
72
73 protected:
74 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
75 };
76
77 // ---------------------------------------------------------
78 // wxDataViewToggleRenderer
79 // ---------------------------------------------------------
80
81 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
82 {
83 public:
84 wxDataViewToggleRenderer( const wxString &varianttype = "bool",
85 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
86 int align = wxDVR_DEFAULT_ALIGNMENT );
87
88 bool SetValue( const wxVariant &value );
89 bool GetValue( wxVariant &value ) const;
90
91 protected:
92 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
93 };
94
95 // ---------------------------------------------------------
96 // wxDataViewCustomRenderer
97 // ---------------------------------------------------------
98
99 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase
100 {
101 public:
102 wxDataViewCustomRenderer( const wxString &varianttype = "string",
103 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
104 int align = wxDVR_DEFAULT_ALIGNMENT,
105 bool no_init = false );
106 virtual ~wxDataViewCustomRenderer();
107
108
109 // Create DC on request
110 virtual wxDC *GetDC();
111
112 // override the base class function to use GTK text cell renderer
113 virtual void RenderText(const wxString& text,
114 int xoffset,
115 wxRect cell,
116 wxDC *dc,
117 int state);
118
119 // store GTK render call parameters for possible later use
120 void GTKStashRenderParams(GdkWindow *window,
121 GtkWidget *widget,
122 GdkRectangle *background_area,
123 GdkRectangle *expose_area,
124 int flags)
125 {
126 m_renderParams.window = window;
127 m_renderParams.widget = widget;
128 m_renderParams.background_area = background_area;
129 m_renderParams.expose_area = expose_area;
130 m_renderParams.flags = flags;
131 }
132
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; }
136
137 virtual bool GtkSetAttr(const wxDataViewItemAttr& attr)
138 {
139 SetAttr(attr);
140 return !attr.IsDefault();
141 }
142
143 protected:
144 bool Init(wxDataViewCellMode mode, int align);
145
146 private:
147 wxDC *m_dc;
148
149 GtkCellRendererText *m_text_renderer;
150
151 // parameters of the original render() call stored so that we could pass
152 // them forward to m_text_renderer if our RenderText() is called
153 struct GTKRenderParams
154 {
155 GdkWindow *window;
156 GtkWidget *widget;
157 GdkRectangle *background_area;
158 GdkRectangle *expose_area;
159 int flags;
160 } m_renderParams;
161
162 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
163 };
164
165 // ---------------------------------------------------------
166 // wxDataViewProgressRenderer
167 // ---------------------------------------------------------
168
169 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
170 {
171 public:
172 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
173 const wxString &varianttype = "long",
174 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
175 int align = wxDVR_DEFAULT_ALIGNMENT );
176 virtual ~wxDataViewProgressRenderer();
177
178 bool SetValue( const wxVariant &value );
179 bool GetValue( wxVariant &value ) const;
180
181 virtual bool Render( wxRect cell, wxDC *dc, int state );
182 virtual wxSize GetSize() const;
183
184 private:
185 wxString m_label;
186 int m_value;
187
188 protected:
189 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
190 };
191
192 // ---------------------------------------------------------
193 // wxDataViewIconTextRenderer
194 // ---------------------------------------------------------
195
196 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
197 {
198 public:
199 wxDataViewIconTextRenderer( const wxString &varianttype = "wxDataViewIconText",
200 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
201 int align = wxDVR_DEFAULT_ALIGNMENT );
202 virtual ~wxDataViewIconTextRenderer();
203
204 bool SetValue( const wxVariant &value );
205 bool GetValue( wxVariant &value ) const;
206
207 virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
208
209 protected:
210 virtual void GtkOnCellChanged(const wxVariant& value,
211 const wxDataViewItem& item,
212 unsigned col);
213
214 private:
215 wxDataViewIconText m_value;
216
217 // we use the base class m_renderer for the text and this one for the icon
218 GtkCellRenderer *m_rendererIcon;
219
220 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
221 };
222
223 // ---------------------------------------------------------
224 // wxDataViewDateRenderer
225 // ---------------------------------------------------------
226
227 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
228 {
229 public:
230 wxDataViewDateRenderer( const wxString &varianttype = "datetime",
231 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
232 int align = wxDVR_DEFAULT_ALIGNMENT );
233
234 bool SetValue( const wxVariant &value );
235 bool GetValue( wxVariant &value ) const;
236
237 virtual bool Render( wxRect cell, wxDC *dc, int state );
238 virtual wxSize GetSize() const;
239 virtual bool Activate( wxRect cell,
240 wxDataViewModel *model,
241 const wxDataViewItem &item,
242 unsigned int col );
243
244 private:
245 wxDateTime m_date;
246
247 protected:
248 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
249 };
250
251 // -------------------------------------
252 // wxDataViewChoiceRenderer
253 // -------------------------------------
254
255 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
256 {
257 public:
258 wxDataViewChoiceRenderer(const wxArrayString &choices,
259 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
260 int alignment = wxDVR_DEFAULT_ALIGNMENT );
261 virtual bool Render( wxRect rect, wxDC *dc, int state );
262 virtual wxSize GetSize() const;
263 virtual bool SetValue( const wxVariant &value );
264 virtual bool GetValue( wxVariant &value ) const;
265
266 void SetAlignment( int align );
267
268 private:
269 wxArrayString m_choices;
270 wxString m_data;
271 };
272
273 #endif // _WX_GTK_DVRENDERERS_H_
274