]>
Commit | Line | Data |
---|---|---|
6eec70b9 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/dvrenderers.h | |
3 | // Purpose: Declare all wxDataViewCtrl classes | |
4 | // Author: Robert Roebling, Vadim Zeitlin | |
5 | // Created: 2009-11-08 (extracted from wx/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_DVRENDERERS_H_ | |
13 | #define _WX_DVRENDERERS_H_ | |
14 | ||
15 | /* | |
16 | Note about the structure of various headers: they're organized in a more | |
17 | complicated way than usual because of the various dependencies which are | |
18 | different for different ports. In any case the only public header, i.e. the | |
19 | one which can be included directly is wx/dataview.h. It, in turn, includes | |
20 | this one to define all the renderer classes. | |
21 | ||
22 | We define the base wxDataViewRendererBase class first and then include a | |
23 | port-dependent wx/xxx/dvrenderer.h which defines wxDataViewRenderer itself. | |
24 | After this we can define wxDataViewRendererCustomBase (and maybe in the | |
25 | future base classes for other renderers if the need arises, i.e. if there | |
26 | is any non-trivial code or API which it makes sense to keep in common code) | |
27 | and include wx/xxx/dvrenderers.h (notice the plural) which defines all the | |
28 | rest of the renderer classes. | |
29 | */ | |
30 | ||
31 | class WXDLLIMPEXP_FWD_ADV wxDataViewCustomRenderer; | |
32 | ||
33 | // ---------------------------------------------------------------------------- | |
34 | // wxDataViewIconText: helper class used by wxDataViewIconTextRenderer | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | class WXDLLIMPEXP_ADV wxDataViewIconText : public wxObject | |
38 | { | |
39 | public: | |
40 | wxDataViewIconText( const wxString &text = wxEmptyString, | |
41 | const wxIcon& icon = wxNullIcon ) | |
42 | : m_text(text), | |
43 | m_icon(icon) | |
44 | { } | |
45 | ||
46 | wxDataViewIconText( const wxDataViewIconText &other ) | |
47 | : wxObject(), | |
48 | m_text(other.m_text), | |
49 | m_icon(other.m_icon) | |
50 | { } | |
51 | ||
52 | void SetText( const wxString &text ) { m_text = text; } | |
53 | wxString GetText() const { return m_text; } | |
54 | void SetIcon( const wxIcon &icon ) { m_icon = icon; } | |
55 | const wxIcon &GetIcon() const { return m_icon; } | |
56 | ||
57 | private: | |
58 | wxString m_text; | |
59 | wxIcon m_icon; | |
60 | ||
61 | DECLARE_DYNAMIC_CLASS(wxDataViewIconText) | |
62 | }; | |
63 | ||
64 | inline | |
65 | bool operator==(const wxDataViewIconText& left, const wxDataViewIconText& right) | |
66 | { | |
67 | return left.GetText() == right.GetText() && | |
68 | left.GetIcon().IsSameAs(right.GetIcon()); | |
69 | } | |
70 | ||
71 | inline | |
72 | bool operator!=(const wxDataViewIconText& left, const wxDataViewIconText& right) | |
73 | { | |
74 | return !(left == right); | |
75 | } | |
76 | ||
77 | DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV) | |
78 | ||
79 | // ---------------------------------------------------------------------------- | |
80 | // wxDataViewRendererBase | |
81 | // ---------------------------------------------------------------------------- | |
82 | ||
83 | enum wxDataViewCellMode | |
84 | { | |
85 | wxDATAVIEW_CELL_INERT, | |
86 | wxDATAVIEW_CELL_ACTIVATABLE, | |
87 | wxDATAVIEW_CELL_EDITABLE | |
88 | }; | |
89 | ||
90 | enum wxDataViewCellRenderState | |
91 | { | |
92 | wxDATAVIEW_CELL_SELECTED = 1, | |
93 | wxDATAVIEW_CELL_PRELIT = 2, | |
94 | wxDATAVIEW_CELL_INSENSITIVE = 4, | |
95 | wxDATAVIEW_CELL_FOCUSED = 8 | |
96 | }; | |
97 | ||
98 | class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject | |
99 | { | |
100 | public: | |
101 | wxDataViewRendererBase( const wxString &varianttype, | |
102 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
103 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
104 | virtual ~wxDataViewRendererBase(); | |
105 | ||
106 | virtual bool Validate( wxVariant& WXUNUSED(value) ) | |
107 | { return true; } | |
108 | ||
109 | void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; } | |
110 | wxDataViewColumn* GetOwner() const { return m_owner; } | |
111 | ||
62265c2c VZ |
112 | // renderer value and attributes: SetValue() and SetAttr() are called |
113 | // before a cell is rendered using this renderer | |
114 | virtual bool SetValue(const wxVariant& value) = 0; | |
115 | virtual bool GetValue(wxVariant& value) const = 0; | |
6eec70b9 | 116 | |
62265c2c | 117 | virtual void SetAttr(const wxDataViewItemAttr& WXUNUSED(attr)) { } |
6eec70b9 VZ |
118 | |
119 | wxString GetVariantType() const { return m_variantType; } | |
120 | ||
f0ccd2cb VS |
121 | // helper that calls SetValue and SetAttr: |
122 | void PrepareForItem(const wxDataViewModel *model, | |
123 | const wxDataViewItem& item, unsigned column); | |
124 | ||
62265c2c | 125 | // renderer properties: |
6eec70b9 VZ |
126 | virtual void SetMode( wxDataViewCellMode mode ) = 0; |
127 | virtual wxDataViewCellMode GetMode() const = 0; | |
128 | ||
129 | // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but | |
130 | // rather an "int"; that's because for rendering cells it's allowed | |
131 | // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM) | |
132 | virtual void SetAlignment( int align ) = 0; | |
133 | virtual int GetAlignment() const = 0; | |
134 | ||
135 | // enable or disable (if called with wxELLIPSIZE_NONE) replacing parts of | |
136 | // the item text (hence this only makes sense for renderers showing | |
137 | // text...) with ellipsis in order to make it fit the column width | |
138 | virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE) = 0; | |
139 | void DisableEllipsize() { EnableEllipsize(wxELLIPSIZE_NONE); } | |
140 | ||
141 | virtual wxEllipsizeMode GetEllipsizeMode() const = 0; | |
142 | ||
143 | // in-place editing | |
144 | virtual bool HasEditorCtrl() const | |
145 | { return false; } | |
146 | virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), | |
147 | wxRect WXUNUSED(labelRect), | |
148 | const wxVariant& WXUNUSED(value)) | |
149 | { return NULL; } | |
150 | virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor), | |
151 | wxVariant& WXUNUSED(value)) | |
152 | { return false; } | |
153 | ||
154 | virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect ); | |
155 | virtual void CancelEditing(); | |
156 | virtual bool FinishEditing(); | |
157 | ||
158 | wxControl *GetEditorCtrl() { return m_editorCtrl; } | |
159 | ||
160 | protected: | |
66c02e6e VZ |
161 | // Called from {Cancel,Finish}Editing() to cleanup m_editorCtrl |
162 | void DestroyEditControl(); | |
163 | ||
6eec70b9 VZ |
164 | wxString m_variantType; |
165 | wxDataViewColumn *m_owner; | |
166 | wxWeakRef<wxControl> m_editorCtrl; | |
167 | wxDataViewItem m_item; // for m_editorCtrl | |
168 | ||
169 | // internal utility: | |
170 | const wxDataViewCtrl* GetView() const; | |
171 | ||
172 | protected: | |
173 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase) | |
174 | }; | |
175 | ||
176 | // include the real wxDataViewRenderer declaration for the native ports | |
177 | #ifdef wxHAS_GENERIC_DATAVIEWCTRL | |
178 | // in the generic implementation there is no real wxDataViewRenderer, all | |
179 | // renderers are custom so it's the same as wxDataViewCustomRenderer and | |
180 | // wxDataViewCustomRendererBase derives from wxDataViewRendererBase directly | |
181 | // | |
182 | // this is a rather ugly hack but unfortunately it just doesn't seem to be | |
183 | // possible to have the same class hierarchy in all ports and avoid | |
184 | // duplicating the entire wxDataViewCustomRendererBase in the generic | |
185 | // wxDataViewRenderer class (well, we could use a mix-in but this would | |
186 | // make classes hierarchy non linear and arguably even more complex) | |
187 | #define wxDataViewCustomRendererRealBase wxDataViewRendererBase | |
188 | #else | |
189 | #if defined(__WXGTK20__) | |
190 | #include "wx/gtk/dvrenderer.h" | |
191 | #elif defined(__WXMAC__) | |
192 | #include "wx/osx/dvrenderer.h" | |
193 | #else | |
194 | #error "unknown native wxDataViewCtrl implementation" | |
195 | #endif | |
196 | #define wxDataViewCustomRendererRealBase wxDataViewRenderer | |
197 | #endif | |
198 | ||
199 | // ---------------------------------------------------------------------------- | |
200 | // wxDataViewCustomRendererBase | |
201 | // ---------------------------------------------------------------------------- | |
202 | ||
203 | class WXDLLIMPEXP_ADV wxDataViewCustomRendererBase | |
204 | : public wxDataViewCustomRendererRealBase | |
205 | { | |
206 | public: | |
207 | // Constructor must specify the usual renderer parameters which we simply | |
208 | // pass to the base class | |
209 | wxDataViewCustomRendererBase(const wxString& varianttype = "string", | |
210 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
211 | int align = wxDVR_DEFAULT_ALIGNMENT) | |
212 | : wxDataViewCustomRendererRealBase(varianttype, mode, align) | |
213 | { | |
214 | } | |
215 | ||
216 | ||
62265c2c VZ |
217 | // Render the item using the current value (returned by GetValue()). |
218 | virtual bool Render(wxRect cell, wxDC *dc, int state) = 0; | |
219 | ||
220 | // Return the size of the item appropriate to its current value. | |
221 | virtual wxSize GetSize() const = 0; | |
222 | ||
6eec70b9 VZ |
223 | // Define virtual function which are called when the item is activated |
224 | // (double-clicked or Enter is pressed on it), clicked or the user starts | |
225 | // to drag it: by default they all simply return false indicating that the | |
226 | // events are not handled | |
227 | ||
228 | virtual bool Activate(wxRect WXUNUSED(cell), | |
229 | wxDataViewModel *WXUNUSED(model), | |
230 | const wxDataViewItem & WXUNUSED(item), | |
231 | unsigned int WXUNUSED(col)) | |
232 | { return false; } | |
233 | ||
234 | virtual bool LeftClick(wxPoint WXUNUSED(cursor), | |
235 | wxRect WXUNUSED(cell), | |
236 | wxDataViewModel *WXUNUSED(model), | |
237 | const wxDataViewItem & WXUNUSED(item), | |
238 | unsigned int WXUNUSED(col) ) | |
239 | { return false; } | |
240 | ||
241 | virtual bool StartDrag(wxPoint WXUNUSED(cursor), | |
242 | wxRect WXUNUSED(cell), | |
243 | wxDataViewModel *WXUNUSED(model), | |
244 | const wxDataViewItem & WXUNUSED(item), | |
245 | unsigned int WXUNUSED(col) ) | |
246 | { return false; } | |
247 | ||
248 | ||
62265c2c VZ |
249 | // Helper which can be used by Render() implementation in the derived |
250 | // classes: it will draw the text in the same manner as the standard | |
251 | // renderers do. | |
252 | virtual void RenderText(const wxString& text, | |
253 | int xoffset, | |
254 | wxRect cell, | |
255 | wxDC *dc, | |
256 | int state); | |
257 | ||
258 | ||
259 | // Override the base class virtual method to simply store the attribute so | |
260 | // that it can be accessed using GetAttr() from Render() if needed. | |
261 | virtual void SetAttr(const wxDataViewItemAttr& attr) { m_attr = attr; } | |
262 | const wxDataViewItemAttr& GetAttr() const { return m_attr; } | |
263 | ||
264 | ||
265 | // Implementation only from now on | |
266 | ||
267 | // Retrieve the DC to use for drawing. This is implemented in derived | |
268 | // platform-specific classes. | |
269 | virtual wxDC *GetDC() = 0; | |
270 | ||
271 | // Prepare DC to use attributes and call Render(). | |
272 | void WXCallRender(wxRect rect, wxDC *dc, int state); | |
273 | ||
86755098 VS |
274 | protected: |
275 | // helper for GetSize() implementations, respects attributes | |
276 | wxSize GetTextExtent(const wxString& str) const; | |
277 | ||
6eec70b9 | 278 | private: |
62265c2c VZ |
279 | wxDataViewItemAttr m_attr; |
280 | ||
6eec70b9 VZ |
281 | wxDECLARE_NO_COPY_CLASS(wxDataViewCustomRendererBase); |
282 | }; | |
283 | ||
284 | // include the declaration of all the other renderers to get the real | |
285 | // wxDataViewCustomRenderer from which we need to inherit below | |
286 | #ifdef wxHAS_GENERIC_DATAVIEWCTRL | |
287 | // because of the different renderer classes hierarchy in the generic | |
288 | // version, as explained above, we can include the header defining | |
289 | // wxDataViewRenderer only here and not before wxDataViewCustomRendererBase | |
290 | // declaration as for the native ports | |
291 | #include "wx/generic/dvrenderer.h" | |
292 | #include "wx/generic/dvrenderers.h" | |
293 | #elif defined(__WXGTK20__) | |
294 | #include "wx/gtk/dvrenderers.h" | |
295 | #elif defined(__WXMAC__) | |
296 | #include "wx/osx/dvrenderers.h" | |
297 | #else | |
298 | #error "unknown native wxDataViewCtrl implementation" | |
299 | #endif | |
300 | ||
301 | // ---------------------------------------------------------------------------- | |
302 | // wxDataViewSpinRenderer | |
303 | // ---------------------------------------------------------------------------- | |
304 | ||
305 | class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer | |
306 | { | |
307 | public: | |
308 | wxDataViewSpinRenderer( int min, int max, | |
309 | wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, | |
310 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
311 | virtual bool HasEditorCtrl() const { return true; } | |
312 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); | |
313 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
314 | virtual bool Render( wxRect rect, wxDC *dc, int state ); | |
315 | virtual wxSize GetSize() const; | |
316 | virtual bool SetValue( const wxVariant &value ); | |
317 | virtual bool GetValue( wxVariant &value ) const; | |
318 | ||
319 | private: | |
320 | long m_data; | |
321 | long m_min,m_max; | |
322 | }; | |
323 | ||
324 | #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__) | |
325 | ||
326 | // ---------------------------------------------------------------------------- | |
327 | // wxDataViewChoiceRenderer | |
328 | // ---------------------------------------------------------------------------- | |
329 | ||
330 | class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer | |
331 | { | |
332 | public: | |
333 | wxDataViewChoiceRenderer( const wxArrayString &choices, | |
334 | wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, | |
335 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
336 | virtual bool HasEditorCtrl() const { return true; } | |
337 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); | |
338 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
339 | virtual bool Render( wxRect rect, wxDC *dc, int state ); | |
340 | virtual wxSize GetSize() const; | |
341 | virtual bool SetValue( const wxVariant &value ); | |
342 | virtual bool GetValue( wxVariant &value ) const; | |
343 | ||
6bb6cc1e RR |
344 | wxString GetChoice(size_t index) const { return m_choices[index]; } |
345 | const wxArrayString& GetChoices() const { return m_choices; } | |
346 | ||
6eec70b9 VZ |
347 | private: |
348 | wxArrayString m_choices; | |
349 | wxString m_data; | |
350 | }; | |
351 | ||
79a53c39 | 352 | // ---------------------------------------------------------------------------- |
65887bd0 | 353 | // wxDataViewChoiceByIndexRenderer |
79a53c39 RR |
354 | // ---------------------------------------------------------------------------- |
355 | ||
65887bd0 | 356 | class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer: public wxDataViewChoiceRenderer |
79a53c39 RR |
357 | { |
358 | public: | |
65887bd0 | 359 | wxDataViewChoiceByIndexRenderer( const wxArrayString &choices, |
79a53c39 | 360 | wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, |
65887bd0 | 361 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); |
ce00f59b | 362 | |
65887bd0 RR |
363 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); |
364 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
ce00f59b | 365 | |
65887bd0 RR |
366 | virtual bool SetValue( const wxVariant &value ); |
367 | virtual bool GetValue( wxVariant &value ) const; | |
79a53c39 RR |
368 | }; |
369 | ||
370 | ||
65887bd0 RR |
371 | #endif // generic or Carbon versions |
372 | ||
6eec70b9 VZ |
373 | // this class is obsolete, its functionality was merged in |
374 | // wxDataViewTextRenderer itself now, don't use it any more | |
375 | #define wxDataViewTextRendererAttr wxDataViewTextRenderer | |
376 | ||
377 | #endif // _WX_DVRENDERERS_H_ | |
378 |