]>
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) | |
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_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 | ||
62265c2c | 121 | // renderer properties: |
6eec70b9 VZ |
122 | virtual void SetMode( wxDataViewCellMode mode ) = 0; |
123 | virtual wxDataViewCellMode GetMode() const = 0; | |
124 | ||
125 | // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but | |
126 | // rather an "int"; that's because for rendering cells it's allowed | |
127 | // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM) | |
128 | virtual void SetAlignment( int align ) = 0; | |
129 | virtual int GetAlignment() const = 0; | |
130 | ||
131 | // enable or disable (if called with wxELLIPSIZE_NONE) replacing parts of | |
132 | // the item text (hence this only makes sense for renderers showing | |
133 | // text...) with ellipsis in order to make it fit the column width | |
134 | virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE) = 0; | |
135 | void DisableEllipsize() { EnableEllipsize(wxELLIPSIZE_NONE); } | |
136 | ||
137 | virtual wxEllipsizeMode GetEllipsizeMode() const = 0; | |
138 | ||
139 | // in-place editing | |
140 | virtual bool HasEditorCtrl() const | |
141 | { return false; } | |
142 | virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), | |
143 | wxRect WXUNUSED(labelRect), | |
144 | const wxVariant& WXUNUSED(value)) | |
145 | { return NULL; } | |
146 | virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor), | |
147 | wxVariant& WXUNUSED(value)) | |
148 | { return false; } | |
149 | ||
150 | virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect ); | |
151 | virtual void CancelEditing(); | |
152 | virtual bool FinishEditing(); | |
153 | ||
154 | wxControl *GetEditorCtrl() { return m_editorCtrl; } | |
155 | ||
156 | protected: | |
157 | wxString m_variantType; | |
158 | wxDataViewColumn *m_owner; | |
159 | wxWeakRef<wxControl> m_editorCtrl; | |
160 | wxDataViewItem m_item; // for m_editorCtrl | |
161 | ||
162 | // internal utility: | |
163 | const wxDataViewCtrl* GetView() const; | |
164 | ||
165 | protected: | |
166 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase) | |
167 | }; | |
168 | ||
169 | // include the real wxDataViewRenderer declaration for the native ports | |
170 | #ifdef wxHAS_GENERIC_DATAVIEWCTRL | |
171 | // in the generic implementation there is no real wxDataViewRenderer, all | |
172 | // renderers are custom so it's the same as wxDataViewCustomRenderer and | |
173 | // wxDataViewCustomRendererBase derives from wxDataViewRendererBase directly | |
174 | // | |
175 | // this is a rather ugly hack but unfortunately it just doesn't seem to be | |
176 | // possible to have the same class hierarchy in all ports and avoid | |
177 | // duplicating the entire wxDataViewCustomRendererBase in the generic | |
178 | // wxDataViewRenderer class (well, we could use a mix-in but this would | |
179 | // make classes hierarchy non linear and arguably even more complex) | |
180 | #define wxDataViewCustomRendererRealBase wxDataViewRendererBase | |
181 | #else | |
182 | #if defined(__WXGTK20__) | |
183 | #include "wx/gtk/dvrenderer.h" | |
184 | #elif defined(__WXMAC__) | |
185 | #include "wx/osx/dvrenderer.h" | |
186 | #else | |
187 | #error "unknown native wxDataViewCtrl implementation" | |
188 | #endif | |
189 | #define wxDataViewCustomRendererRealBase wxDataViewRenderer | |
190 | #endif | |
191 | ||
192 | // ---------------------------------------------------------------------------- | |
193 | // wxDataViewCustomRendererBase | |
194 | // ---------------------------------------------------------------------------- | |
195 | ||
196 | class WXDLLIMPEXP_ADV wxDataViewCustomRendererBase | |
197 | : public wxDataViewCustomRendererRealBase | |
198 | { | |
199 | public: | |
200 | // Constructor must specify the usual renderer parameters which we simply | |
201 | // pass to the base class | |
202 | wxDataViewCustomRendererBase(const wxString& varianttype = "string", | |
203 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
204 | int align = wxDVR_DEFAULT_ALIGNMENT) | |
205 | : wxDataViewCustomRendererRealBase(varianttype, mode, align) | |
206 | { | |
207 | } | |
208 | ||
209 | ||
62265c2c VZ |
210 | // Render the item using the current value (returned by GetValue()). |
211 | virtual bool Render(wxRect cell, wxDC *dc, int state) = 0; | |
212 | ||
213 | // Return the size of the item appropriate to its current value. | |
214 | virtual wxSize GetSize() const = 0; | |
215 | ||
6eec70b9 VZ |
216 | // Define virtual function which are called when the item is activated |
217 | // (double-clicked or Enter is pressed on it), clicked or the user starts | |
218 | // to drag it: by default they all simply return false indicating that the | |
219 | // events are not handled | |
220 | ||
221 | virtual bool Activate(wxRect WXUNUSED(cell), | |
222 | wxDataViewModel *WXUNUSED(model), | |
223 | const wxDataViewItem & WXUNUSED(item), | |
224 | unsigned int WXUNUSED(col)) | |
225 | { return false; } | |
226 | ||
227 | virtual bool LeftClick(wxPoint WXUNUSED(cursor), | |
228 | wxRect WXUNUSED(cell), | |
229 | wxDataViewModel *WXUNUSED(model), | |
230 | const wxDataViewItem & WXUNUSED(item), | |
231 | unsigned int WXUNUSED(col) ) | |
232 | { return false; } | |
233 | ||
234 | virtual bool StartDrag(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 | ||
62265c2c VZ |
242 | // Helper which can be used by Render() implementation in the derived |
243 | // classes: it will draw the text in the same manner as the standard | |
244 | // renderers do. | |
245 | virtual void RenderText(const wxString& text, | |
246 | int xoffset, | |
247 | wxRect cell, | |
248 | wxDC *dc, | |
249 | int state); | |
250 | ||
251 | ||
252 | // Override the base class virtual method to simply store the attribute so | |
253 | // that it can be accessed using GetAttr() from Render() if needed. | |
254 | virtual void SetAttr(const wxDataViewItemAttr& attr) { m_attr = attr; } | |
255 | const wxDataViewItemAttr& GetAttr() const { return m_attr; } | |
256 | ||
257 | ||
258 | // Implementation only from now on | |
259 | ||
260 | // Retrieve the DC to use for drawing. This is implemented in derived | |
261 | // platform-specific classes. | |
262 | virtual wxDC *GetDC() = 0; | |
263 | ||
264 | // Prepare DC to use attributes and call Render(). | |
265 | void WXCallRender(wxRect rect, wxDC *dc, int state); | |
266 | ||
6eec70b9 | 267 | private: |
62265c2c VZ |
268 | wxDataViewItemAttr m_attr; |
269 | ||
6eec70b9 VZ |
270 | wxDECLARE_NO_COPY_CLASS(wxDataViewCustomRendererBase); |
271 | }; | |
272 | ||
273 | // include the declaration of all the other renderers to get the real | |
274 | // wxDataViewCustomRenderer from which we need to inherit below | |
275 | #ifdef wxHAS_GENERIC_DATAVIEWCTRL | |
276 | // because of the different renderer classes hierarchy in the generic | |
277 | // version, as explained above, we can include the header defining | |
278 | // wxDataViewRenderer only here and not before wxDataViewCustomRendererBase | |
279 | // declaration as for the native ports | |
280 | #include "wx/generic/dvrenderer.h" | |
281 | #include "wx/generic/dvrenderers.h" | |
282 | #elif defined(__WXGTK20__) | |
283 | #include "wx/gtk/dvrenderers.h" | |
284 | #elif defined(__WXMAC__) | |
285 | #include "wx/osx/dvrenderers.h" | |
286 | #else | |
287 | #error "unknown native wxDataViewCtrl implementation" | |
288 | #endif | |
289 | ||
290 | // ---------------------------------------------------------------------------- | |
291 | // wxDataViewSpinRenderer | |
292 | // ---------------------------------------------------------------------------- | |
293 | ||
294 | class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer | |
295 | { | |
296 | public: | |
297 | wxDataViewSpinRenderer( int min, int max, | |
298 | wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, | |
299 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
300 | virtual bool HasEditorCtrl() const { return true; } | |
301 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); | |
302 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
303 | virtual bool Render( wxRect rect, wxDC *dc, int state ); | |
304 | virtual wxSize GetSize() const; | |
305 | virtual bool SetValue( const wxVariant &value ); | |
306 | virtual bool GetValue( wxVariant &value ) const; | |
307 | ||
308 | private: | |
309 | long m_data; | |
310 | long m_min,m_max; | |
311 | }; | |
312 | ||
313 | #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__) | |
314 | ||
315 | // ---------------------------------------------------------------------------- | |
316 | // wxDataViewChoiceRenderer | |
317 | // ---------------------------------------------------------------------------- | |
318 | ||
319 | class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer | |
320 | { | |
321 | public: | |
322 | wxDataViewChoiceRenderer( const wxArrayString &choices, | |
323 | wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, | |
324 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
325 | virtual bool HasEditorCtrl() const { return true; } | |
326 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); | |
327 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
328 | virtual bool Render( wxRect rect, wxDC *dc, int state ); | |
329 | virtual wxSize GetSize() const; | |
330 | virtual bool SetValue( const wxVariant &value ); | |
331 | virtual bool GetValue( wxVariant &value ) const; | |
332 | ||
333 | private: | |
334 | wxArrayString m_choices; | |
335 | wxString m_data; | |
336 | }; | |
337 | ||
338 | #endif // generic or Carbon versions | |
339 | ||
340 | // this class is obsolete, its functionality was merged in | |
341 | // wxDataViewTextRenderer itself now, don't use it any more | |
342 | #define wxDataViewTextRendererAttr wxDataViewTextRenderer | |
343 | ||
344 | #endif // _WX_DVRENDERERS_H_ | |
345 |