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