Add wxDataViewListModel base class for list models.
[wxWidgets.git] / include / wx / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dataview.h
3 // Purpose: wxDataViewCtrl base classes
4 // Author: Robert Roebling
5 // Modified by: Bo Yang
6 // Created: 08.01.06
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DATAVIEW_H_BASE_
13 #define _WX_DATAVIEW_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_DATAVIEWCTRL
18
19 #include "wx/textctrl.h"
20 #include "wx/headercol.h"
21 #include "wx/variant.h"
22 #include "wx/dynarray.h"
23 #include "wx/icon.h"
24 #include "wx/weakref.h"
25 #include "wx/vector.h"
26 #include "wx/dataobj.h"
27
28 class WXDLLIMPEXP_FWD_CORE wxImageList;
29
30 #if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
31 // #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
32 #define wxHAS_GENERIC_DATAVIEWCTRL
33 #endif
34
35 // ----------------------------------------------------------------------------
36 // wxDataViewCtrl globals
37 // ----------------------------------------------------------------------------
38
39 class WXDLLIMPEXP_FWD_ADV wxDataViewItem;
40 class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
41 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
42 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
43 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer;
44 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
45
46 extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[];
47
48 // ----------------------------------------------------------------------------
49 // wxDataViewCtrl flags
50 // ----------------------------------------------------------------------------
51
52 // size of a wxDataViewRenderer without contents:
53 #define wxDVC_DEFAULT_RENDERER_SIZE 20
54
55 // the default width of new (text) columns:
56 #define wxDVC_DEFAULT_WIDTH 80
57
58 // the default width of new toggle columns:
59 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
60
61 // the default minimal width of the columns:
62 #define wxDVC_DEFAULT_MINWIDTH 30
63
64 // The default alignment of wxDataViewRenderers is to take
65 // the alignment from the column it owns.
66 #define wxDVR_DEFAULT_ALIGNMENT -1
67
68
69 // ---------------------------------------------------------
70 // wxDataViewItem
71 // ---------------------------------------------------------
72
73 class WXDLLIMPEXP_ADV wxDataViewItem
74 {
75 public:
76 wxDataViewItem( void* id = NULL )
77 { m_id = id; }
78 wxDataViewItem( const wxDataViewItem &item )
79 { m_id = item.m_id; }
80 bool IsOk() const { return m_id != NULL; }
81 void* GetID() const { return m_id; }
82 operator const void* () const { return m_id; }
83
84 private:
85 void* m_id;
86 };
87
88 inline
89 bool operator==(const wxDataViewItem& left, const wxDataViewItem& right)
90 {
91 return left.GetID() == right.GetID();
92 }
93
94 inline
95 bool operator!=(const wxDataViewItem& left, const wxDataViewItem& right)
96 {
97 return !(left == right);
98 }
99
100 WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray);
101
102 // ---------------------------------------------------------
103 // wxDataViewModelNotifier
104 // ---------------------------------------------------------
105
106 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
107 {
108 public:
109 wxDataViewModelNotifier() { m_owner = NULL; }
110 virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
111
112 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
113 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
114 virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
115 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
116 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
117 virtual bool ItemsChanged( const wxDataViewItemArray &items );
118 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
119 virtual bool Cleared() = 0;
120
121 virtual void Resort() = 0;
122
123 void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
124 wxDataViewModel *GetOwner() const { return m_owner; }
125
126 private:
127 wxDataViewModel *m_owner;
128 };
129
130
131
132 // ----------------------------------------------------------------------------
133 // wxDataViewItemAttr: a structure containing the visual attributes of an item
134 // ----------------------------------------------------------------------------
135
136 // TODO: this should be renamed to wxItemAttr or something general like this
137
138 class WXDLLIMPEXP_ADV wxDataViewItemAttr
139 {
140 public:
141 // ctors
142 wxDataViewItemAttr()
143 {
144 m_bold = false;
145 m_italic = false;
146 }
147
148 // setters
149 void SetColour(const wxColour& colour) { m_colour = colour; }
150 void SetBold( bool set ) { m_bold = set; }
151 void SetItalic( bool set ) { m_italic = set; }
152
153 // accessors
154 bool HasColour() const { return m_colour.Ok(); }
155 const wxColour& GetColour() const { return m_colour; }
156
157 bool HasFont() const { return m_bold || m_italic; }
158 bool GetBold() const { return m_bold; }
159 bool GetItalic() const { return m_italic; }
160
161 private:
162 wxColour m_colour;
163 bool m_bold;
164 bool m_italic;
165 };
166
167
168 // ---------------------------------------------------------
169 // wxDataViewModel
170 // ---------------------------------------------------------
171
172 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers,
173 class WXDLLIMPEXP_ADV);
174
175 class WXDLLIMPEXP_ADV wxDataViewModel: public wxRefCounter
176 {
177 public:
178 wxDataViewModel();
179
180 virtual unsigned int GetColumnCount() const = 0;
181
182 // return type as reported by wxVariant
183 virtual wxString GetColumnType( unsigned int col ) const = 0;
184
185 // get value into a wxVariant
186 virtual void GetValue( wxVariant &variant,
187 const wxDataViewItem &item, unsigned int col ) const = 0;
188
189 // return true if the given item has a value to display in the given
190 // column: this is always true except for container items which by default
191 // only show their label in the first column (but see HasContainerColumns())
192 bool HasValue(const wxDataViewItem& item, unsigned col) const
193 {
194 return col == 0 || !IsContainer(item) || HasContainerColumns(item);
195 }
196
197 // usually ValueChanged() should be called after changing the value in the
198 // model to update the control, ChangeValue() does it on its own while
199 // SetValue() does not -- so while you will override SetValue(), you should
200 // be usually calling ChangeValue()
201 virtual bool SetValue(const wxVariant &variant,
202 const wxDataViewItem &item,
203 unsigned int col) = 0;
204
205 bool ChangeValue(const wxVariant& variant,
206 const wxDataViewItem& item,
207 unsigned int col)
208 {
209 return SetValue(variant, item, col) && ValueChanged(item, col);
210 }
211
212 // Get text attribute, return false of default attributes should be used
213 virtual bool GetAttr( const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
214 { return false; }
215
216 // define hierachy
217 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
218 virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
219 // Is the container just a header or an item with all columns
220 virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const
221 { return false; }
222 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0;
223
224 // delegated notifiers
225 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
226 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
227 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
228 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
229 virtual bool ItemChanged( const wxDataViewItem &item );
230 virtual bool ItemsChanged( const wxDataViewItemArray &items );
231 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
232 virtual bool Cleared();
233
234 // delegatd action
235 virtual void Resort();
236
237 void AddNotifier( wxDataViewModelNotifier *notifier );
238 void RemoveNotifier( wxDataViewModelNotifier *notifier );
239
240 // default compare function
241 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
242 unsigned int column, bool ascending ) const;
243 virtual bool HasDefaultCompare() const { return false; }
244
245 // internal
246 virtual bool IsVirtualListModel() const { return false; }
247
248 protected:
249 // the user should not delete this class directly: he should use DecRef() instead!
250 virtual ~wxDataViewModel() { }
251
252 wxDataViewModelNotifiers m_notifiers;
253 };
254
255 // ----------------------------------------------------------------------------
256 // wxDataViewListModel: a model of a list, i.e. flat data structure without any
257 // branches/containers, used as base class by wxDataViewIndexListModel and
258 // wxDataViewVirtualListModel
259 // ----------------------------------------------------------------------------
260
261 class WXDLLIMPEXP_ADV wxDataViewListModel : public wxDataViewModel
262 {
263 public:
264 // derived classes should override these methods instead of
265 // {Get,Set}Value() and GetAttr() inherited from the base class
266
267 virtual void GetValueByRow(wxVariant &variant,
268 unsigned row, unsigned col) const = 0;
269
270 virtual bool SetValueByRow(const wxVariant &variant,
271 unsigned row, unsigned col) = 0;
272
273 virtual bool
274 GetAttrByRow(unsigned WXUNUSED(row), unsigned WXUNUSED(col),
275 wxDataViewItemAttr &WXUNUSED(attr))
276 {
277 return false;
278 }
279
280
281 // helper methods provided by list models only
282 virtual unsigned GetRow( const wxDataViewItem &item ) const = 0;
283
284
285 // implement some base class pure virtual directly
286 virtual wxDataViewItem
287 GetParent( const wxDataViewItem & WXUNUSED(item) ) const
288 {
289 // items never have valid parent in this model
290 return wxDataViewItem();
291 }
292
293 virtual bool IsContainer( const wxDataViewItem &item ) const
294 {
295 // only the invisible (and invalid) root item has children
296 return !item.IsOk();
297 }
298
299 // and implement some others by forwarding them to our own ones
300 virtual void GetValue( wxVariant &variant,
301 const wxDataViewItem &item, unsigned int col ) const
302 {
303 GetValueByRow(variant, GetRow(item), col);
304 }
305
306 virtual bool SetValue( const wxVariant &variant,
307 const wxDataViewItem &item, unsigned int col )
308 {
309 return SetValueByRow( variant, GetRow(item), col );
310 }
311
312 virtual bool GetAttr(const wxDataViewItem &item, unsigned int col,
313 wxDataViewItemAttr &attr)
314 {
315 return GetAttrByRow( GetRow(item), col, attr );
316 }
317 };
318
319 // ---------------------------------------------------------
320 // wxDataViewIndexListModel
321 // ---------------------------------------------------------
322
323 class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewListModel
324 {
325 public:
326 wxDataViewIndexListModel( unsigned int initial_size = 0 );
327
328 void RowPrepended();
329 void RowInserted( unsigned int before );
330 void RowAppended();
331 void RowDeleted( unsigned int row );
332 void RowsDeleted( const wxArrayInt &rows );
333 void RowChanged( unsigned int row );
334 void RowValueChanged( unsigned int row, unsigned int col );
335 void Reset( unsigned int new_size );
336
337 // convert to/from row/wxDataViewItem
338
339 virtual unsigned GetRow( const wxDataViewItem &item ) const;
340 wxDataViewItem GetItem( unsigned int row ) const;
341
342 // compare based on index
343
344 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
345 unsigned int column, bool ascending ) const;
346 virtual bool HasDefaultCompare() const;
347
348 // implement base methods
349 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
350
351 // internal
352 unsigned int GetCount() const { return m_hash.GetCount(); }
353
354 private:
355 wxDataViewItemArray m_hash;
356 unsigned int m_nextFreeID;
357 bool m_ordered;
358 };
359
360 // ---------------------------------------------------------
361 // wxDataViewVirtualListModel
362 // ---------------------------------------------------------
363
364 #ifdef __WXMAC__
365 // better than nothing
366 typedef wxDataViewIndexListModel wxDataViewVirtualListModel;
367 #else
368
369 class WXDLLIMPEXP_ADV wxDataViewVirtualListModel: public wxDataViewListModel
370 {
371 public:
372 wxDataViewVirtualListModel( unsigned int initial_size = 0 );
373
374 void RowPrepended();
375 void RowInserted( unsigned int before );
376 void RowAppended();
377 void RowDeleted( unsigned int row );
378 void RowsDeleted( const wxArrayInt &rows );
379 void RowChanged( unsigned int row );
380 void RowValueChanged( unsigned int row, unsigned int col );
381 void Reset( unsigned int new_size );
382
383 // convert to/from row/wxDataViewItem
384
385 virtual unsigned GetRow( const wxDataViewItem &item ) const;
386 wxDataViewItem GetItem( unsigned int row ) const;
387
388 // compare based on index
389
390 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
391 unsigned int column, bool ascending ) const;
392 virtual bool HasDefaultCompare() const;
393
394 // implement base methods
395 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
396
397 // internal
398 virtual bool IsVirtualListModel() const { return true; }
399 unsigned int GetCount() const { return m_size; }
400
401 private:
402 unsigned int m_size;
403 bool m_ordered;
404 };
405 #endif
406
407 //-----------------------------------------------------------------------------
408 // wxDataViewEditorCtrlEvtHandler
409 //-----------------------------------------------------------------------------
410
411 class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
412 {
413 public:
414 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
415
416 void AcceptChangesAndFinish();
417 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
418
419 protected:
420 void OnChar( wxKeyEvent &event );
421 void OnTextEnter( wxCommandEvent &event );
422 void OnKillFocus( wxFocusEvent &event );
423 void OnIdle( wxIdleEvent &event );
424
425 private:
426 wxDataViewRenderer *m_owner;
427 wxControl *m_editorCtrl;
428 bool m_finished;
429 bool m_focusOnIdle;
430
431 private:
432 DECLARE_EVENT_TABLE()
433 };
434
435 // ---------------------------------------------------------
436 // wxDataViewRendererBase
437 // ---------------------------------------------------------
438
439 enum wxDataViewCellMode
440 {
441 wxDATAVIEW_CELL_INERT,
442 wxDATAVIEW_CELL_ACTIVATABLE,
443 wxDATAVIEW_CELL_EDITABLE
444 };
445
446 enum wxDataViewCellRenderState
447 {
448 wxDATAVIEW_CELL_SELECTED = 1,
449 wxDATAVIEW_CELL_PRELIT = 2,
450 wxDATAVIEW_CELL_INSENSITIVE = 4,
451 wxDATAVIEW_CELL_FOCUSED = 8
452 };
453
454 class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
455 {
456 public:
457 wxDataViewRendererBase( const wxString &varianttype,
458 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
459 int alignment = wxDVR_DEFAULT_ALIGNMENT );
460 virtual ~wxDataViewRendererBase();
461
462 virtual bool Validate( wxVariant& WXUNUSED(value) )
463 { return true; }
464
465 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
466 wxDataViewColumn* GetOwner() const { return m_owner; }
467
468 // renderer properties:
469
470 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
471 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
472
473 wxString GetVariantType() const { return m_variantType; }
474
475 virtual void SetMode( wxDataViewCellMode mode ) = 0;
476 virtual wxDataViewCellMode GetMode() const = 0;
477
478 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
479 // rather an "int"; that's because for rendering cells it's allowed
480 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
481 virtual void SetAlignment( int align ) = 0;
482 virtual int GetAlignment() const = 0;
483
484 // enable or disable (if called with wxELLIPSIZE_NONE) replacing parts of
485 // the item text (hence this only makes sense for renderers showing
486 // text...) with ellipsis in order to make it fit the column width
487 virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE) = 0;
488 void DisableEllipsize() { EnableEllipsize(wxELLIPSIZE_NONE); }
489
490 virtual wxEllipsizeMode GetEllipsizeMode() const = 0;
491
492 // in-place editing
493 virtual bool HasEditorCtrl() const
494 { return false; }
495 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
496 wxRect WXUNUSED(labelRect),
497 const wxVariant& WXUNUSED(value))
498 { return NULL; }
499 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
500 wxVariant& WXUNUSED(value))
501 { return false; }
502
503 virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
504 virtual void CancelEditing();
505 virtual bool FinishEditing();
506
507 wxControl *GetEditorCtrl() { return m_editorCtrl; }
508
509 protected:
510 wxString m_variantType;
511 wxDataViewColumn *m_owner;
512 wxWeakRef<wxControl> m_editorCtrl;
513 wxDataViewItem m_item; // for m_editorCtrl
514
515 // internal utility:
516 const wxDataViewCtrl* GetView() const;
517
518 protected:
519 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
520 };
521
522 //-----------------------------------------------------------------------------
523 // wxDataViewIconText
524 //-----------------------------------------------------------------------------
525
526 class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject
527 {
528 public:
529 wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
530 : m_text(text), m_icon(icon)
531 { }
532 wxDataViewIconText( const wxDataViewIconText &other )
533 : wxObject()
534 { m_icon = other.m_icon; m_text = other.m_text; }
535
536 void SetText( const wxString &text ) { m_text = text; }
537 wxString GetText() const { return m_text; }
538 void SetIcon( const wxIcon &icon ) { m_icon = icon; }
539 const wxIcon &GetIcon() const { return m_icon; }
540
541 private:
542 wxString m_text;
543 wxIcon m_icon;
544
545 private:
546 DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
547 };
548
549 inline
550 bool operator==(const wxDataViewIconText& left, const wxDataViewIconText& right)
551 {
552 return left.GetText() == right.GetText() &&
553 left.GetIcon().IsSameAs(right.GetIcon());
554 }
555
556 inline
557 bool operator!=(const wxDataViewIconText& left, const wxDataViewIconText& right)
558 {
559 return !(left == right);
560 }
561
562 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
563
564 // ---------------------------------------------------------
565 // wxDataViewColumnBase
566 // ---------------------------------------------------------
567
568 // for compatibility only, do not use
569 enum wxDataViewColumnFlags
570 {
571 wxDATAVIEW_COL_RESIZABLE = wxCOL_RESIZABLE,
572 wxDATAVIEW_COL_SORTABLE = wxCOL_SORTABLE,
573 wxDATAVIEW_COL_REORDERABLE = wxCOL_REORDERABLE,
574 wxDATAVIEW_COL_HIDDEN = wxCOL_HIDDEN
575 };
576
577 class WXDLLIMPEXP_ADV wxDataViewColumnBase : public wxSettableHeaderColumn
578 {
579 public:
580 // ctor for the text columns: takes ownership of renderer
581 wxDataViewColumnBase(wxDataViewRenderer *renderer,
582 unsigned int model_column)
583 {
584 Init(renderer, model_column);
585 }
586
587 // ctor for the bitmap columns
588 wxDataViewColumnBase(const wxBitmap& bitmap,
589 wxDataViewRenderer *renderer,
590 unsigned int model_column)
591 : m_bitmap(bitmap)
592 {
593 Init(renderer, model_column);
594 }
595
596 virtual ~wxDataViewColumnBase();
597
598 // setters:
599 virtual void SetOwner( wxDataViewCtrl *owner )
600 { m_owner = owner; }
601
602 // getters:
603 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); }
604 wxDataViewCtrl *GetOwner() const { return m_owner; }
605 wxDataViewRenderer* GetRenderer() const { return m_renderer; }
606
607 // implement some of base class pure virtuals (the rest is port-dependent
608 // and done differently in generic and native versions)
609 virtual void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
610 virtual wxBitmap GetBitmap() const { return m_bitmap; }
611
612 protected:
613 wxDataViewRenderer *m_renderer;
614 int m_model_column;
615 wxBitmap m_bitmap;
616 wxDataViewCtrl *m_owner;
617
618 private:
619 // common part of all ctors
620 void Init(wxDataViewRenderer *renderer, unsigned int model_column);
621 };
622
623 // ---------------------------------------------------------
624 // wxDataViewCtrlBase
625 // ---------------------------------------------------------
626
627 #define wxDV_SINGLE 0x0000 // for convenience
628 #define wxDV_MULTIPLE 0x0001 // can select multiple items
629
630 #define wxDV_NO_HEADER 0x0002 // column titles not visible
631 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
632 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
633
634 #define wxDV_ROW_LINES 0x0010 // alternating colour in rows
635 #define wxDV_VARIABLE_LINE_HEIGHT 0x0020 // variable line height
636
637 class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
638 {
639 public:
640 wxDataViewCtrlBase();
641 virtual ~wxDataViewCtrlBase();
642
643 // model
644 // -----
645
646 virtual bool AssociateModel( wxDataViewModel *model );
647 wxDataViewModel* GetModel();
648 const wxDataViewModel* GetModel() const;
649
650
651 // column management
652 // -----------------
653
654 wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column,
655 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
656 wxAlignment align = wxALIGN_NOT,
657 int flags = wxDATAVIEW_COL_RESIZABLE );
658 wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column,
659 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
660 wxAlignment align = wxALIGN_NOT,
661 int flags = wxDATAVIEW_COL_RESIZABLE );
662 wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column,
663 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
664 wxAlignment align = wxALIGN_CENTER,
665 int flags = wxDATAVIEW_COL_RESIZABLE );
666 wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column,
667 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
668 wxAlignment align = wxALIGN_CENTER,
669 int flags = wxDATAVIEW_COL_RESIZABLE );
670 wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column,
671 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
672 wxAlignment align = wxALIGN_NOT,
673 int flags = wxDATAVIEW_COL_RESIZABLE );
674 wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column,
675 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
676 wxAlignment align = wxALIGN_CENTER,
677 int flags = wxDATAVIEW_COL_RESIZABLE );
678 wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column,
679 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
680 wxAlignment align = wxALIGN_NOT,
681 int flags = wxDATAVIEW_COL_RESIZABLE );
682 wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
683 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
684 wxAlignment align = wxALIGN_NOT,
685 int flags = wxDATAVIEW_COL_RESIZABLE );
686 wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
687 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
688 wxAlignment align = wxALIGN_CENTER,
689 int flags = wxDATAVIEW_COL_RESIZABLE );
690 wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
691 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
692 wxAlignment align = wxALIGN_CENTER,
693 int flags = wxDATAVIEW_COL_RESIZABLE );
694 wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column,
695 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
696 wxAlignment align = wxALIGN_NOT,
697 int flags = wxDATAVIEW_COL_RESIZABLE );
698 wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
699 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
700 wxAlignment align = wxALIGN_CENTER,
701 int flags = wxDATAVIEW_COL_RESIZABLE );
702
703 wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
704 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
705 wxAlignment align = wxALIGN_NOT,
706 int flags = wxDATAVIEW_COL_RESIZABLE );
707 wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column,
708 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
709 wxAlignment align = wxALIGN_NOT,
710 int flags = wxDATAVIEW_COL_RESIZABLE );
711 wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column,
712 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
713 wxAlignment align = wxALIGN_CENTER,
714 int flags = wxDATAVIEW_COL_RESIZABLE );
715 wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column,
716 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
717 wxAlignment align = wxALIGN_CENTER,
718 int flags = wxDATAVIEW_COL_RESIZABLE );
719 wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column,
720 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
721 wxAlignment align = wxALIGN_NOT,
722 int flags = wxDATAVIEW_COL_RESIZABLE );
723 wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column,
724 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
725 wxAlignment align = wxALIGN_CENTER,
726 int flags = wxDATAVIEW_COL_RESIZABLE );
727 wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
728 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
729 wxAlignment align = wxALIGN_NOT,
730 int flags = wxDATAVIEW_COL_RESIZABLE );
731 wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
732 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
733 wxAlignment align = wxALIGN_NOT,
734 int flags = wxDATAVIEW_COL_RESIZABLE );
735 wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
736 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
737 wxAlignment align = wxALIGN_CENTER,
738 int flags = wxDATAVIEW_COL_RESIZABLE );
739 wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
740 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
741 wxAlignment align = wxALIGN_CENTER,
742 int flags = wxDATAVIEW_COL_RESIZABLE );
743 wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column,
744 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
745 wxAlignment align = wxALIGN_NOT,
746 int flags = wxDATAVIEW_COL_RESIZABLE );
747 wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
748 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
749 wxAlignment align = wxALIGN_CENTER,
750 int flags = wxDATAVIEW_COL_RESIZABLE );
751
752 virtual bool PrependColumn( wxDataViewColumn *col );
753 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
754 virtual bool AppendColumn( wxDataViewColumn *col );
755
756 virtual unsigned int GetColumnCount() const = 0;
757 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0;
758 virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0;
759
760 virtual bool DeleteColumn( wxDataViewColumn *column ) = 0;
761 virtual bool ClearColumns() = 0;
762
763 void SetExpanderColumn( wxDataViewColumn *col )
764 { m_expander_column = col ; DoSetExpanderColumn(); }
765 wxDataViewColumn *GetExpanderColumn() const
766 { return m_expander_column; }
767
768 virtual wxDataViewColumn *GetSortingColumn() const = 0;
769
770
771 // items management
772 // ----------------
773
774 void SetIndent( int indent )
775 { m_indent = indent ; DoSetIndent(); }
776 int GetIndent() const
777 { return m_indent; }
778
779 virtual wxDataViewItem GetSelection() const = 0;
780 virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
781 virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
782 virtual void Select( const wxDataViewItem & item ) = 0;
783 virtual void Unselect( const wxDataViewItem & item ) = 0;
784 virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
785
786 virtual void SelectAll() = 0;
787 virtual void UnselectAll() = 0;
788
789 virtual void Expand( const wxDataViewItem & item ) = 0;
790 virtual void ExpandAncestors( const wxDataViewItem & item );
791 virtual void Collapse( const wxDataViewItem & item ) = 0;
792 virtual bool IsExpanded( const wxDataViewItem & item ) const = 0;
793
794 virtual void EnsureVisible( const wxDataViewItem & item,
795 const wxDataViewColumn *column = NULL ) = 0;
796 virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
797 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
798
799 #if wxUSE_DRAG_AND_DROP
800 virtual bool EnableDragSource(const wxDataFormat& WXUNUSED(format))
801 { return false; }
802 virtual bool EnableDropTarget(const wxDataFormat& WXUNUSED(format))
803 { return false; }
804 #endif // wxUSE_DRAG_AND_DROP
805
806 // define control visual attributes
807 // --------------------------------
808
809 virtual wxVisualAttributes GetDefaultAttributes() const
810 {
811 return GetClassDefaultAttributes(GetWindowVariant());
812 }
813
814 static wxVisualAttributes
815 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL)
816 {
817 return wxControl::GetCompositeControlsDefaultAttributes(variant);
818 }
819
820 protected:
821 virtual void DoSetExpanderColumn() = 0 ;
822 virtual void DoSetIndent() = 0;
823
824 private:
825 wxDataViewModel *m_model;
826 wxDataViewColumn *m_expander_column;
827 int m_indent ;
828
829 protected:
830 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
831 };
832
833 // ----------------------------------------------------------------------------
834 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
835 // ----------------------------------------------------------------------------
836
837 class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
838 {
839 public:
840 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
841 : wxNotifyEvent(commandType, winid),
842 m_item(0),
843 m_col(-1),
844 m_model(NULL),
845 m_value(wxNullVariant),
846 m_column(NULL),
847 m_pos(-1,-1),
848 m_cacheFrom(0),
849 m_cacheTo(0)
850 #if wxUSE_DRAG_AND_DROP
851 , m_dataObject(NULL),
852 m_dataBuffer(NULL),
853 m_dataSize(0)
854 #endif
855 { }
856
857 wxDataViewEvent(const wxDataViewEvent& event)
858 : wxNotifyEvent(event),
859 m_item(event.m_item),
860 m_col(event.m_col),
861 m_model(event.m_model),
862 m_value(event.m_value),
863 m_column(event.m_column),
864 m_pos(m_pos),
865 m_cacheFrom(event.m_cacheFrom),
866 m_cacheTo(event.m_cacheTo)
867 #if wxUSE_DRAG_AND_DROP
868 , m_dataObject(event.m_dataObject),
869 m_dataFormat(event.m_dataFormat),
870 m_dataBuffer(event.m_dataBuffer),
871 m_dataSize(event.m_dataSize)
872 #endif
873 { }
874
875 wxDataViewItem GetItem() const { return m_item; }
876 void SetItem( const wxDataViewItem &item ) { m_item = item; }
877
878 int GetColumn() const { return m_col; }
879 void SetColumn( int col ) { m_col = col; }
880
881 wxDataViewModel* GetModel() const { return m_model; }
882 void SetModel( wxDataViewModel *model ) { m_model = model; }
883
884 const wxVariant &GetValue() const { return m_value; }
885 void SetValue( const wxVariant &value ) { m_value = value; }
886
887 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
888 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
889 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
890
891 // for wxEVT_DATAVIEW_CONTEXT_MENU only
892 wxPoint GetPosition() const { return m_pos; }
893 void SetPosition( int x, int y ) { m_pos.x = x; m_pos.y = y; }
894
895 // For wxEVT_COMMAND_DATAVIEW_CACHE_HINT
896 int GetCacheFrom() const { return m_cacheFrom; }
897 int GetCacheTo() const { return m_cacheTo; }
898 void SetCache(int from, int to) { m_cacheFrom = from; m_cacheTo = to; }
899
900
901 #if wxUSE_DRAG_AND_DROP
902 // For drag operations
903 void SetDataObject( wxDataObject *obj ) { m_dataObject = obj; }
904 wxDataObject *GetDataObject() const { return m_dataObject; }
905
906 // For drop operations
907 void SetDataFormat( const wxDataFormat &format ) { m_dataFormat = format; }
908 wxDataFormat GetDataFormat() const { return m_dataFormat; }
909 void SetDataSize( size_t size ) { m_dataSize = size; }
910 size_t GetDataSize() const { return m_dataSize; }
911 void SetDataBuffer( void* buf ) { m_dataBuffer = buf;}
912 void *GetDataBuffer() const { return m_dataBuffer; }
913 #endif // wxUSE_DRAG_AND_DROP
914
915 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
916
917 protected:
918 wxDataViewItem m_item;
919 int m_col;
920 wxDataViewModel *m_model;
921 wxVariant m_value;
922 wxDataViewColumn *m_column;
923 wxPoint m_pos;
924 int m_cacheFrom;
925 int m_cacheTo;
926
927 #if wxUSE_DRAG_AND_DROP
928 wxDataObject *m_dataObject;
929
930 wxDataFormat m_dataFormat;
931 void* m_dataBuffer;
932 size_t m_dataSize;
933 #endif // wxUSE_DRAG_AND_DROP
934
935 private:
936 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
937 };
938
939 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent );
940
941 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent );
942 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent );
943 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent );
944 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent );
945 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent );
946 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent );
947 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent );
948 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent );
949 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent );
950
951 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent );
952
953 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent );
954 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent );
955 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent );
956 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent );
957
958 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_CACHE_HINT, wxDataViewEvent );
959
960 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent );
961 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent );
962 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent );
963
964 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
965
966 #define wxDataViewEventHandler(func) \
967 wxEVENT_HANDLER_CAST(wxDataViewEventFunction, func)
968
969 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
970 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
971
972 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
973
974 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
975 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
976 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
977 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
978 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
979 #define EVT_DATAVIEW_ITEM_START_EDITING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_START_EDITING, id, fn)
980 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
981 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
982 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
983
984 #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn)
985
986 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
987 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
988 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
989 #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn)
990 #define EVT_DATAVIEW_CACHE_HINT(id, fn) wx__DECLARE_DATAVIEWEVT(CACHE_HINT, id, fn)
991
992 #define EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_BEGIN_DRAG, id, fn)
993 #define EVT_DATAVIEW_ITEM_DROP_POSSIBLE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP_POSSIBLE, id, fn)
994 #define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn)
995
996 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
997 // this symbol doesn't follow the convention for wxUSE_XXX symbols which
998 // are normally always defined as either 0 or 1, so its use is deprecated
999 // and it only exists for backwards compatibility, don't use it any more
1000 // and use wxHAS_GENERIC_DATAVIEWCTRL instead
1001 #define wxUSE_GENERICDATAVIEWCTRL
1002
1003 #include "wx/generic/dataview.h"
1004 #elif defined(__WXGTK20__)
1005 #include "wx/gtk/dataview.h"
1006 #elif defined(__WXMAC__)
1007 #include "wx/osx/dataview.h"
1008 #else
1009 #error "unknown native wxDataViewCtrl implementation"
1010 #endif
1011
1012 // -------------------------------------
1013 // wxDataViewSpinRenderer
1014 // -------------------------------------
1015
1016 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer
1017 {
1018 public:
1019 wxDataViewSpinRenderer( int min, int max,
1020 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
1021 int alignment = wxDVR_DEFAULT_ALIGNMENT );
1022 virtual bool HasEditorCtrl() const { return true; }
1023 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
1024 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
1025 virtual bool Render( wxRect rect, wxDC *dc, int state );
1026 virtual wxSize GetSize() const;
1027 virtual bool SetValue( const wxVariant &value );
1028 virtual bool GetValue( wxVariant &value ) const;
1029
1030 private:
1031 long m_data;
1032 long m_min,m_max;
1033 };
1034
1035 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1036
1037 // -------------------------------------
1038 // wxDataViewChoiceRenderer
1039 // -------------------------------------
1040
1041 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
1042 {
1043 public:
1044 wxDataViewChoiceRenderer( const wxArrayString &choices,
1045 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
1046 int alignment = wxDVR_DEFAULT_ALIGNMENT );
1047 virtual bool HasEditorCtrl() const { return true; }
1048 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
1049 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
1050 virtual bool Render( wxRect rect, wxDC *dc, int state );
1051 virtual wxSize GetSize() const;
1052 virtual bool SetValue( const wxVariant &value );
1053 virtual bool GetValue( wxVariant &value ) const;
1054
1055 private:
1056 wxArrayString m_choices;
1057 wxString m_data;
1058 };
1059
1060 #endif
1061
1062 // this class is obsolete, its functionality was merged in
1063 // wxDataViewTextRenderer itself now, don't use it any more
1064 #define wxDataViewTextRendererAttr wxDataViewTextRenderer
1065
1066 //-----------------------------------------------------------------------------
1067 // wxDataViewListStore
1068 //-----------------------------------------------------------------------------
1069
1070 class WXDLLIMPEXP_ADV wxDataViewListStoreLine
1071 {
1072 public:
1073 wxDataViewListStoreLine( wxClientData *data = NULL )
1074 {
1075 m_data = data;
1076 }
1077 virtual ~wxDataViewListStoreLine()
1078 {
1079 delete m_data;
1080 }
1081
1082 void SetData( wxClientData *data )
1083 { if (m_data) delete m_data; m_data = data; }
1084 wxClientData *GetData() const
1085 { return m_data; }
1086
1087 wxVector<wxVariant> m_values;
1088
1089 private:
1090 wxClientData *m_data;
1091 };
1092
1093
1094 class WXDLLIMPEXP_ADV wxDataViewListStore: public wxDataViewIndexListModel
1095 {
1096 public:
1097 wxDataViewListStore();
1098 ~wxDataViewListStore();
1099
1100 void PrependColumn( const wxString &varianttype );
1101 void InsertColumn( unsigned int pos, const wxString &varianttype );
1102 void AppendColumn( const wxString &varianttype );
1103
1104 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
1105 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
1106 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL );
1107 void DeleteItem( unsigned int pos );
1108 void DeleteAllItems();
1109
1110 // override base virtuals
1111
1112 virtual unsigned int GetColumnCount() const;
1113
1114 virtual wxString GetColumnType( unsigned int col ) const;
1115
1116 virtual void GetValueByRow( wxVariant &value,
1117 unsigned int row, unsigned int col ) const;
1118
1119 virtual bool SetValueByRow( const wxVariant &value,
1120 unsigned int row, unsigned int col );
1121
1122
1123 public:
1124 wxVector<wxDataViewListStoreLine*> m_data;
1125 wxArrayString m_cols;
1126 };
1127
1128 //-----------------------------------------------------------------------------
1129
1130 class WXDLLIMPEXP_ADV wxDataViewListCtrl: public wxDataViewCtrl
1131 {
1132 public:
1133 wxDataViewListCtrl();
1134 wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
1135 const wxPoint& pos = wxDefaultPosition,
1136 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
1137 const wxValidator& validator = wxDefaultValidator );
1138 ~wxDataViewListCtrl();
1139
1140 bool Create( wxWindow *parent, wxWindowID id,
1141 const wxPoint& pos = wxDefaultPosition,
1142 const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
1143 const wxValidator& validator = wxDefaultValidator );
1144
1145 wxDataViewListStore *GetStore()
1146 { return (wxDataViewListStore*) GetModel(); }
1147 const wxDataViewListStore *GetStore() const
1148 { return (const wxDataViewListStore*) GetModel(); }
1149
1150 bool AppendColumn( wxDataViewColumn *column, const wxString &varianttype );
1151 bool PrependColumn( wxDataViewColumn *column, const wxString &varianttype );
1152 bool InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype );
1153
1154 // overridden from base class
1155 virtual bool PrependColumn( wxDataViewColumn *col );
1156 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
1157 virtual bool AppendColumn( wxDataViewColumn *col );
1158
1159 wxDataViewColumn *AppendTextColumn( const wxString &label,
1160 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1161 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1162 wxDataViewColumn *AppendToggleColumn( const wxString &label,
1163 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
1164 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1165 wxDataViewColumn *AppendProgressColumn( const wxString &label,
1166 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1167 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1168 wxDataViewColumn *AppendIconTextColumn( const wxString &label,
1169 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
1170 int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
1171
1172 void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
1173 { GetStore()->AppendItem( values, data ); }
1174 void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
1175 { GetStore()->PrependItem( values, data ); }
1176 void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL )
1177 { GetStore()->InsertItem( row, values, data ); }
1178 void DeleteItem( unsigned row )
1179 { GetStore()->DeleteItem( row ); }
1180 void DeleteAllItems()
1181 { GetStore()->DeleteAllItems(); }
1182
1183 void SetValue( const wxVariant &value, unsigned int row, unsigned int col )
1184 { GetStore()->SetValueByRow( value, row, col );
1185 GetStore()->RowValueChanged( row, col); }
1186 void GetValue( wxVariant &value, unsigned int row, unsigned int col )
1187 { GetStore()->GetValueByRow( value, row, col ); }
1188
1189 void SetTextValue( const wxString &value, unsigned int row, unsigned int col )
1190 { GetStore()->SetValueByRow( value, row, col );
1191 GetStore()->RowValueChanged( row, col); }
1192 wxString GetTextValue( unsigned int row, unsigned int col ) const
1193 { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetString(); }
1194
1195 void SetToggleValue( bool value, unsigned int row, unsigned int col )
1196 { GetStore()->SetValueByRow( value, row, col );
1197 GetStore()->RowValueChanged( row, col); }
1198 bool GetToggleValue( unsigned int row, unsigned int col ) const
1199 { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); }
1200
1201 void OnSize( wxSizeEvent &event );
1202
1203 private:
1204 DECLARE_EVENT_TABLE()
1205 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl)
1206 };
1207
1208 //-----------------------------------------------------------------------------
1209 // wxDataViewTreeStore
1210 //-----------------------------------------------------------------------------
1211
1212 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
1213 {
1214 public:
1215 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent,
1216 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1217 virtual ~wxDataViewTreeStoreNode();
1218
1219 void SetText( const wxString &text )
1220 { m_text = text; }
1221 wxString GetText() const
1222 { return m_text; }
1223 void SetIcon( const wxIcon &icon )
1224 { m_icon = icon; }
1225 const wxIcon &GetIcon() const
1226 { return m_icon; }
1227 void SetData( wxClientData *data )
1228 { if (m_data) delete m_data; m_data = data; }
1229 wxClientData *GetData() const
1230 { return m_data; }
1231
1232 wxDataViewItem GetItem() const
1233 { return wxDataViewItem( (void*) this ); }
1234
1235 virtual bool IsContainer()
1236 { return false; }
1237
1238 wxDataViewTreeStoreNode *GetParent()
1239 { return m_parent; }
1240
1241 private:
1242 wxDataViewTreeStoreNode *m_parent;
1243 wxString m_text;
1244 wxIcon m_icon;
1245 wxClientData *m_data;
1246 };
1247
1248 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList,
1249 class WXDLLIMPEXP_ADV);
1250
1251 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode
1252 {
1253 public:
1254 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent,
1255 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1256 wxClientData *data = NULL );
1257 virtual ~wxDataViewTreeStoreContainerNode();
1258
1259 const wxDataViewTreeStoreNodeList &GetChildren() const
1260 { return m_children; }
1261 wxDataViewTreeStoreNodeList &GetChildren()
1262 { return m_children; }
1263
1264 void SetExpandedIcon( const wxIcon &icon )
1265 { m_iconExpanded = icon; }
1266 const wxIcon &GetExpandedIcon() const
1267 { return m_iconExpanded; }
1268
1269 void SetExpanded( bool expanded = true )
1270 { m_isExpanded = expanded; }
1271 bool IsExpanded() const
1272 { return m_isExpanded; }
1273
1274 virtual bool IsContainer()
1275 { return true; }
1276
1277 private:
1278 wxDataViewTreeStoreNodeList m_children;
1279 wxIcon m_iconExpanded;
1280 bool m_isExpanded;
1281 };
1282
1283 //-----------------------------------------------------------------------------
1284
1285 class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel
1286 {
1287 public:
1288 wxDataViewTreeStore();
1289 ~wxDataViewTreeStore();
1290
1291 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1292 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1293 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1294 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1295 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1296 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
1297
1298 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1299 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1300 wxClientData *data = NULL );
1301 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1302 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1303 wxClientData *data = NULL );
1304 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1305 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
1306 wxClientData *data = NULL );
1307
1308 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const;
1309 int GetChildCount( const wxDataViewItem& parent ) const;
1310
1311 void SetItemText( const wxDataViewItem& item, const wxString &text );
1312 wxString GetItemText( const wxDataViewItem& item ) const;
1313 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
1314 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const;
1315 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
1316 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const;
1317 void SetItemData( const wxDataViewItem& item, wxClientData *data );
1318 wxClientData *GetItemData( const wxDataViewItem& item ) const;
1319
1320 void DeleteItem( const wxDataViewItem& item );
1321 void DeleteChildren( const wxDataViewItem& item );
1322 void DeleteAllItems();
1323
1324 // implement base methods
1325
1326 virtual void GetValue( wxVariant &variant,
1327 const wxDataViewItem &item, unsigned int col ) const;
1328 virtual bool SetValue( const wxVariant &variant,
1329 const wxDataViewItem &item, unsigned int col );
1330 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
1331 virtual bool IsContainer( const wxDataViewItem &item ) const;
1332 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
1333
1334 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
1335 unsigned int column, bool ascending ) const;
1336
1337 virtual bool HasDefaultCompare() const
1338 { return true; }
1339 virtual unsigned int GetColumnCount() const
1340 { return 1; };
1341 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
1342 { return wxT("wxDataViewIconText"); }
1343
1344 wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const;
1345 wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const;
1346 wxDataViewTreeStoreNode *GetRoot() const { return m_root; }
1347
1348 public:
1349 wxDataViewTreeStoreNode *m_root;
1350 };
1351
1352 //-----------------------------------------------------------------------------
1353
1354 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
1355 {
1356 public:
1357 wxDataViewTreeCtrl() { Init(); }
1358 wxDataViewTreeCtrl(wxWindow *parent,
1359 wxWindowID id,
1360 const wxPoint& pos = wxDefaultPosition,
1361 const wxSize& size = wxDefaultSize,
1362 long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1363 const wxValidator& validator = wxDefaultValidator)
1364 {
1365 Init();
1366
1367 Create(parent, id, pos, size, style, validator);
1368 }
1369
1370 virtual ~wxDataViewTreeCtrl();
1371
1372 bool Create(wxWindow *parent,
1373 wxWindowID id,
1374 const wxPoint& pos = wxDefaultPosition,
1375 const wxSize& size = wxDefaultSize,
1376 long style = wxDV_NO_HEADER | wxDV_ROW_LINES,
1377 const wxValidator& validator = wxDefaultValidator);
1378
1379 wxDataViewTreeStore *GetStore()
1380 { return (wxDataViewTreeStore*) GetModel(); }
1381 const wxDataViewTreeStore *GetStore() const
1382 { return (const wxDataViewTreeStore*) GetModel(); }
1383
1384 void SetImageList( wxImageList *imagelist );
1385 wxImageList* GetImageList() { return m_imageList; }
1386
1387 wxDataViewItem AppendItem( const wxDataViewItem& parent,
1388 const wxString &text, int icon = -1, wxClientData *data = NULL );
1389 wxDataViewItem PrependItem( const wxDataViewItem& parent,
1390 const wxString &text, int icon = -1, wxClientData *data = NULL );
1391 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1392 const wxString &text, int icon = -1, wxClientData *data = NULL );
1393
1394 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
1395 const wxString &text, int icon = -1, int expanded = -1,
1396 wxClientData *data = NULL );
1397 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
1398 const wxString &text, int icon = -1, int expanded = -1,
1399 wxClientData *data = NULL );
1400 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1401 const wxString &text, int icon = -1, int expanded = -1,
1402 wxClientData *data = NULL );
1403
1404 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1405 { return GetStore()->GetNthChild(parent, pos); }
1406 int GetChildCount( const wxDataViewItem& parent ) const
1407 { return GetStore()->GetChildCount(parent); }
1408
1409 void SetItemText( const wxDataViewItem& item, const wxString &text );
1410 wxString GetItemText( const wxDataViewItem& item ) const
1411 { return GetStore()->GetItemText(item); }
1412 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
1413 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const
1414 { return GetStore()->GetItemIcon(item); }
1415 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
1416 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const
1417 { return GetStore()->GetItemExpandedIcon(item); }
1418 void SetItemData( const wxDataViewItem& item, wxClientData *data )
1419 { GetStore()->SetItemData(item,data); }
1420 wxClientData *GetItemData( const wxDataViewItem& item ) const
1421 { return GetStore()->GetItemData(item); }
1422
1423 void DeleteItem( const wxDataViewItem& item );
1424 void DeleteChildren( const wxDataViewItem& item );
1425 void DeleteAllItems();
1426
1427 void OnExpanded( wxDataViewEvent &event );
1428 void OnCollapsed( wxDataViewEvent &event );
1429 void OnSize( wxSizeEvent &event );
1430
1431 private:
1432 void Init()
1433 {
1434 m_imageList = NULL;
1435 }
1436
1437 wxImageList *m_imageList;
1438
1439 private:
1440 DECLARE_EVENT_TABLE()
1441 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl)
1442 };
1443
1444 #endif // wxUSE_DATAVIEWCTRL
1445
1446 #endif
1447 // _WX_DATAVIEW_H_BASE_