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