]>
Commit | Line | Data |
---|---|---|
6eec70b9 VZ |
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) | |
b1153ed6 | 6 | // RCS-ID: $Id$ |
6eec70b9 VZ |
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 | ||
70884c6f VZ |
15 | typedef struct _GdkRectangle GdkRectangle; |
16 | ||
6eec70b9 VZ |
17 | // --------------------------------------------------------- |
18 | // wxDataViewTextRenderer | |
19 | // --------------------------------------------------------- | |
20 | ||
21 | class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer | |
22 | { | |
23 | public: | |
24 | wxDataViewTextRenderer( const wxString &varianttype = "string", | |
25 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
26 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
27 | ||
28 | virtual bool SetValue( const wxVariant &value ) | |
29 | { | |
30 | return SetTextValue(value); | |
31 | } | |
32 | ||
33 | virtual bool GetValue( wxVariant &value ) const | |
34 | { | |
35 | wxString str; | |
36 | if ( !GetTextValue(str) ) | |
37 | return false; | |
38 | ||
39 | value = str; | |
40 | ||
41 | return true; | |
42 | } | |
43 | ||
44 | virtual void SetAlignment( int align ); | |
45 | ||
c2a738e3 | 46 | virtual bool GtkSupportsAttrs() const { return true; } |
c80cde00 | 47 | virtual bool GtkSetAttr(const wxDataViewItemAttr& attr); |
c2a738e3 | 48 | |
17cbc244 VZ |
49 | virtual GtkCellRendererText *GtkGetTextRenderer() const; |
50 | ||
6eec70b9 VZ |
51 | protected: |
52 | // implementation of Set/GetValue() | |
53 | bool SetTextValue(const wxString& str); | |
54 | bool GetTextValue(wxString& str) const; | |
55 | ||
56 | ||
57 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer) | |
58 | }; | |
59 | ||
60 | // --------------------------------------------------------- | |
61 | // wxDataViewBitmapRenderer | |
62 | // --------------------------------------------------------- | |
63 | ||
64 | class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer | |
65 | { | |
66 | public: | |
67 | wxDataViewBitmapRenderer( const wxString &varianttype = "wxBitmap", | |
68 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
69 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
70 | ||
71 | bool SetValue( const wxVariant &value ); | |
72 | bool GetValue( wxVariant &value ) const; | |
73 | ||
74 | protected: | |
75 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer) | |
76 | }; | |
77 | ||
78 | // --------------------------------------------------------- | |
79 | // wxDataViewToggleRenderer | |
80 | // --------------------------------------------------------- | |
81 | ||
82 | class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer | |
83 | { | |
84 | public: | |
85 | wxDataViewToggleRenderer( const wxString &varianttype = "bool", | |
86 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
87 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
88 | ||
89 | bool SetValue( const wxVariant &value ); | |
90 | bool GetValue( wxVariant &value ) const; | |
91 | ||
92 | protected: | |
93 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer) | |
94 | }; | |
95 | ||
96 | // --------------------------------------------------------- | |
97 | // wxDataViewCustomRenderer | |
98 | // --------------------------------------------------------- | |
99 | ||
100 | class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase | |
101 | { | |
102 | public: | |
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(); | |
108 | ||
109 | ||
6eec70b9 VZ |
110 | // Create DC on request |
111 | virtual wxDC *GetDC(); | |
112 | ||
62265c2c VZ |
113 | // override the base class function to use GTK text cell renderer |
114 | virtual void RenderText(const wxString& text, | |
115 | int xoffset, | |
116 | wxRect cell, | |
117 | wxDC *dc, | |
118 | int state); | |
6eec70b9 | 119 | |
2a454ffd VZ |
120 | // store GTK render call parameters for possible later use |
121 | void GTKStashRenderParams(GdkWindow *window, | |
122 | GtkWidget *widget, | |
123 | GdkRectangle *background_area, | |
124 | GdkRectangle *expose_area, | |
125 | int flags) | |
126 | { | |
127 | m_renderParams.window = window; | |
128 | m_renderParams.widget = widget; | |
129 | m_renderParams.background_area = background_area; | |
130 | m_renderParams.expose_area = expose_area; | |
131 | m_renderParams.flags = flags; | |
132 | } | |
6eec70b9 | 133 | |
c80cde00 VZ |
134 | // we may or not support attributes, as we don't know it, return true to |
135 | // make it possible to use them | |
136 | virtual bool GtkSupportsAttrs() const { return true; } | |
137 | ||
138 | virtual bool GtkSetAttr(const wxDataViewItemAttr& attr) | |
139 | { | |
140 | SetAttr(attr); | |
141 | return !attr.IsDefault(); | |
142 | } | |
143 | ||
17cbc244 VZ |
144 | virtual GtkCellRendererText *GtkGetTextRenderer() const; |
145 | ||
2a454ffd | 146 | protected: |
6eec70b9 VZ |
147 | bool Init(wxDataViewCellMode mode, int align); |
148 | ||
149 | private: | |
3e81bbbf VZ |
150 | // Called from GtkGetTextRenderer() to really create the renderer if |
151 | // necessary. | |
152 | void GtkInitTextRenderer(); | |
153 | ||
6eec70b9 VZ |
154 | wxDC *m_dc; |
155 | ||
c80cde00 | 156 | GtkCellRendererText *m_text_renderer; |
6eec70b9 | 157 | |
2a454ffd VZ |
158 | // parameters of the original render() call stored so that we could pass |
159 | // them forward to m_text_renderer if our RenderText() is called | |
160 | struct GTKRenderParams | |
161 | { | |
162 | GdkWindow *window; | |
163 | GtkWidget *widget; | |
164 | GdkRectangle *background_area; | |
165 | GdkRectangle *expose_area; | |
166 | int flags; | |
167 | } m_renderParams; | |
168 | ||
6eec70b9 VZ |
169 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer) |
170 | }; | |
171 | ||
172 | // --------------------------------------------------------- | |
173 | // wxDataViewProgressRenderer | |
174 | // --------------------------------------------------------- | |
175 | ||
176 | class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer | |
177 | { | |
178 | public: | |
179 | wxDataViewProgressRenderer( const wxString &label = wxEmptyString, | |
180 | const wxString &varianttype = "long", | |
181 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
182 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
183 | virtual ~wxDataViewProgressRenderer(); | |
184 | ||
185 | bool SetValue( const wxVariant &value ); | |
186 | bool GetValue( wxVariant &value ) const; | |
187 | ||
188 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
189 | virtual wxSize GetSize() const; | |
190 | ||
191 | private: | |
fdd67a6a VZ |
192 | void GTKSetLabel(); |
193 | ||
6eec70b9 VZ |
194 | wxString m_label; |
195 | int m_value; | |
196 | ||
fdd67a6a VZ |
197 | #if !wxUSE_UNICODE |
198 | // Flag used to indicate that we need to set the label because we were | |
199 | // unable to do it in the ctor (see comments there). | |
200 | bool m_needsToSetLabel; | |
201 | #endif // !wxUSE_UNICODE | |
202 | ||
6eec70b9 VZ |
203 | protected: |
204 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer) | |
205 | }; | |
206 | ||
207 | // --------------------------------------------------------- | |
208 | // wxDataViewIconTextRenderer | |
209 | // --------------------------------------------------------- | |
210 | ||
211 | class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer | |
212 | { | |
213 | public: | |
214 | wxDataViewIconTextRenderer( const wxString &varianttype = "wxDataViewIconText", | |
215 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
216 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
217 | virtual ~wxDataViewIconTextRenderer(); | |
218 | ||
219 | bool SetValue( const wxVariant &value ); | |
220 | bool GetValue( wxVariant &value ) const; | |
221 | ||
222 | virtual void GtkPackIntoColumn(GtkTreeViewColumn *column); | |
223 | ||
224 | protected: | |
225 | virtual void GtkOnCellChanged(const wxVariant& value, | |
226 | const wxDataViewItem& item, | |
227 | unsigned col); | |
228 | ||
229 | private: | |
230 | wxDataViewIconText m_value; | |
231 | ||
232 | // we use the base class m_renderer for the text and this one for the icon | |
233 | GtkCellRenderer *m_rendererIcon; | |
234 | ||
235 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer) | |
236 | }; | |
237 | ||
238 | // --------------------------------------------------------- | |
239 | // wxDataViewDateRenderer | |
240 | // --------------------------------------------------------- | |
241 | ||
242 | class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer | |
243 | { | |
244 | public: | |
245 | wxDataViewDateRenderer( const wxString &varianttype = "datetime", | |
246 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, | |
247 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
248 | ||
249 | bool SetValue( const wxVariant &value ); | |
250 | bool GetValue( wxVariant &value ) const; | |
251 | ||
252 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
253 | virtual wxSize GetSize() const; | |
b586d4c7 | 254 | virtual bool Activate( const wxRect& cell, |
6eec70b9 VZ |
255 | wxDataViewModel *model, |
256 | const wxDataViewItem &item, | |
257 | unsigned int col ); | |
258 | ||
259 | private: | |
260 | wxDateTime m_date; | |
261 | ||
262 | protected: | |
263 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer) | |
264 | }; | |
265 | ||
266 | // ------------------------------------- | |
267 | // wxDataViewChoiceRenderer | |
268 | // ------------------------------------- | |
269 | ||
270 | class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer | |
271 | { | |
272 | public: | |
273 | wxDataViewChoiceRenderer(const wxArrayString &choices, | |
274 | wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, | |
275 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
276 | virtual bool Render( wxRect rect, wxDC *dc, int state ); | |
277 | virtual wxSize GetSize() const; | |
278 | virtual bool SetValue( const wxVariant &value ); | |
279 | virtual bool GetValue( wxVariant &value ) const; | |
280 | ||
281 | void SetAlignment( int align ); | |
282 | ||
f4fcd648 RR |
283 | wxString GetChoice(size_t index) const { return m_choices[index]; } |
284 | const wxArrayString& GetChoices() const { return m_choices; } | |
285 | ||
6eec70b9 VZ |
286 | private: |
287 | wxArrayString m_choices; | |
288 | wxString m_data; | |
289 | }; | |
290 | ||
65887bd0 RR |
291 | // ---------------------------------------------------------------------------- |
292 | // wxDataViewChoiceByIndexRenderer | |
293 | // ---------------------------------------------------------------------------- | |
294 | ||
295 | class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer: public wxDataViewChoiceRenderer | |
296 | { | |
297 | public: | |
298 | wxDataViewChoiceByIndexRenderer( const wxArrayString &choices, | |
299 | wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, | |
300 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
ce00f59b | 301 | |
65887bd0 RR |
302 | virtual bool SetValue( const wxVariant &value ); |
303 | virtual bool GetValue( wxVariant &value ) const; | |
ce00f59b | 304 | |
65887bd0 RR |
305 | private: |
306 | virtual void GtkOnTextEdited(const gchar *itempath, const wxString& str); | |
307 | }; | |
308 | ||
309 | ||
310 | ||
6eec70b9 VZ |
311 | #endif // _WX_GTK_DVRENDERERS_H_ |
312 |