Avoid setting attributes in GTK wxDataViewRenderer if not supported.
[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 // ---------------------------------------------------------
16 // wxDataViewTextRenderer
17 // ---------------------------------------------------------
18
19 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
20 {
21 public:
22 wxDataViewTextRenderer( const wxString &varianttype = "string",
23 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
24 int align = wxDVR_DEFAULT_ALIGNMENT );
25
26 virtual bool SetValue( const wxVariant &value )
27 {
28 return SetTextValue(value);
29 }
30
31 virtual bool GetValue( wxVariant &value ) const
32 {
33 wxString str;
34 if ( !GetTextValue(str) )
35 return false;
36
37 value = str;
38
39 return true;
40 }
41
42 virtual void SetAlignment( int align );
43
44 virtual bool GtkSupportsAttrs() const { return true; }
45
46 protected:
47 // implementation of Set/GetValue()
48 bool SetTextValue(const wxString& str);
49 bool GetTextValue(wxString& str) const;
50
51
52 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
53 };
54
55 // ---------------------------------------------------------
56 // wxDataViewBitmapRenderer
57 // ---------------------------------------------------------
58
59 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
60 {
61 public:
62 wxDataViewBitmapRenderer( const wxString &varianttype = "wxBitmap",
63 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
64 int align = wxDVR_DEFAULT_ALIGNMENT );
65
66 bool SetValue( const wxVariant &value );
67 bool GetValue( wxVariant &value ) const;
68
69 protected:
70 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
71 };
72
73 // ---------------------------------------------------------
74 // wxDataViewToggleRenderer
75 // ---------------------------------------------------------
76
77 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
78 {
79 public:
80 wxDataViewToggleRenderer( const wxString &varianttype = "bool",
81 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
82 int align = wxDVR_DEFAULT_ALIGNMENT );
83
84 bool SetValue( const wxVariant &value );
85 bool GetValue( wxVariant &value ) const;
86
87 protected:
88 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
89 };
90
91 // ---------------------------------------------------------
92 // wxDataViewCustomRenderer
93 // ---------------------------------------------------------
94
95 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase
96 {
97 public:
98 wxDataViewCustomRenderer( const wxString &varianttype = "string",
99 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
100 int align = wxDVR_DEFAULT_ALIGNMENT,
101 bool no_init = false );
102 virtual ~wxDataViewCustomRenderer();
103
104
105 // Create DC on request
106 virtual wxDC *GetDC();
107
108 // override the base class function to use GTK text cell renderer
109 virtual void RenderText(const wxString& text,
110 int xoffset,
111 wxRect cell,
112 wxDC *dc,
113 int state);
114
115 protected:
116
117 bool Init(wxDataViewCellMode mode, int align);
118
119 private:
120 wxDC *m_dc;
121
122 public:
123 // Internal, temporary for RenderText.
124 GtkCellRenderer *m_text_renderer;
125 GdkWindow *window;
126 GtkWidget *widget;
127 void *background_area;
128 void *cell_area;
129 void *expose_area;
130 int flags;
131
132 protected:
133 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
134 };
135
136 // ---------------------------------------------------------
137 // wxDataViewProgressRenderer
138 // ---------------------------------------------------------
139
140 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
141 {
142 public:
143 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
144 const wxString &varianttype = "long",
145 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
146 int align = wxDVR_DEFAULT_ALIGNMENT );
147 virtual ~wxDataViewProgressRenderer();
148
149 bool SetValue( const wxVariant &value );
150 bool GetValue( wxVariant &value ) const;
151
152 virtual bool Render( wxRect cell, wxDC *dc, int state );
153 virtual wxSize GetSize() const;
154
155 private:
156 wxString m_label;
157 int m_value;
158
159 protected:
160 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
161 };
162
163 // ---------------------------------------------------------
164 // wxDataViewIconTextRenderer
165 // ---------------------------------------------------------
166
167 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
168 {
169 public:
170 wxDataViewIconTextRenderer( const wxString &varianttype = "wxDataViewIconText",
171 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
172 int align = wxDVR_DEFAULT_ALIGNMENT );
173 virtual ~wxDataViewIconTextRenderer();
174
175 bool SetValue( const wxVariant &value );
176 bool GetValue( wxVariant &value ) const;
177
178 virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
179
180 protected:
181 virtual void GtkOnCellChanged(const wxVariant& value,
182 const wxDataViewItem& item,
183 unsigned col);
184
185 private:
186 wxDataViewIconText m_value;
187
188 // we use the base class m_renderer for the text and this one for the icon
189 GtkCellRenderer *m_rendererIcon;
190
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
192 };
193
194 // ---------------------------------------------------------
195 // wxDataViewDateRenderer
196 // ---------------------------------------------------------
197
198 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
199 {
200 public:
201 wxDataViewDateRenderer( const wxString &varianttype = "datetime",
202 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
203 int align = wxDVR_DEFAULT_ALIGNMENT );
204
205 bool SetValue( const wxVariant &value );
206 bool GetValue( wxVariant &value ) const;
207
208 virtual bool Render( wxRect cell, wxDC *dc, int state );
209 virtual wxSize GetSize() const;
210 virtual bool Activate( wxRect cell,
211 wxDataViewModel *model,
212 const wxDataViewItem &item,
213 unsigned int col );
214
215 private:
216 wxDateTime m_date;
217
218 protected:
219 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
220 };
221
222 // -------------------------------------
223 // wxDataViewChoiceRenderer
224 // -------------------------------------
225
226 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
227 {
228 public:
229 wxDataViewChoiceRenderer(const wxArrayString &choices,
230 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
231 int alignment = wxDVR_DEFAULT_ALIGNMENT );
232 virtual bool Render( wxRect rect, wxDC *dc, int state );
233 virtual wxSize GetSize() const;
234 virtual bool SetValue( const wxVariant &value );
235 virtual bool GetValue( wxVariant &value ) const;
236
237 void SetAlignment( int align );
238
239 private:
240 wxArrayString m_choices;
241 wxString m_data;
242 };
243
244 #endif // _WX_GTK_DVRENDERERS_H_
245