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