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