1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataViewCtrl base classes
4 // Author: Robert Roebling
5 // Modified by: Bo Yang
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DATAVIEW_H_BASE_
13 #define _WX_DATAVIEW_H_BASE_
17 #if wxUSE_DATAVIEWCTRL
19 #include "wx/textctrl.h"
20 #include "wx/headercol.h"
21 #include "wx/variant.h"
22 #include "wx/dynarray.h"
24 #include "wx/weakref.h"
25 #include "wx/vector.h"
26 #include "wx/dataobj.h"
27 #include "wx/withimages.h"
29 class WXDLLIMPEXP_FWD_CORE wxImageList
;
31 #if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
32 // #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
33 #define wxHAS_GENERIC_DATAVIEWCTRL
36 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
37 // this symbol doesn't follow the convention for wxUSE_XXX symbols which
38 // are normally always defined as either 0 or 1, so its use is deprecated
39 // and it only exists for backwards compatibility, don't use it any more
40 // and use wxHAS_GENERIC_DATAVIEWCTRL instead
41 #define wxUSE_GENERICDATAVIEWCTRL
44 // ----------------------------------------------------------------------------
45 // wxDataViewCtrl globals
46 // ----------------------------------------------------------------------------
48 class WXDLLIMPEXP_FWD_ADV wxDataViewItem
;
49 class WXDLLIMPEXP_FWD_ADV wxDataViewModel
;
50 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
51 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn
;
52 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer
;
53 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier
;
55 extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr
[];
57 // ----------------------------------------------------------------------------
58 // wxDataViewCtrl flags
59 // ----------------------------------------------------------------------------
61 // size of a wxDataViewRenderer without contents:
62 #define wxDVC_DEFAULT_RENDERER_SIZE 20
64 // the default width of new (text) columns:
65 #define wxDVC_DEFAULT_WIDTH 80
67 // the default width of new toggle columns:
68 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
70 // the default minimal width of the columns:
71 #define wxDVC_DEFAULT_MINWIDTH 30
73 // The default alignment of wxDataViewRenderers is to take
74 // the alignment from the column it owns.
75 #define wxDVR_DEFAULT_ALIGNMENT -1
78 // ---------------------------------------------------------
80 // ---------------------------------------------------------
82 class WXDLLIMPEXP_ADV wxDataViewItem
85 wxDataViewItem() : m_id(NULL
) {}
86 wxDataViewItem(const wxDataViewItem
&item
) : m_id(item
.m_id
) {}
88 wxEXPLICIT
wxDataViewItem(void* id
) : m_id(id
) {}
90 bool IsOk() const { return m_id
!= NULL
; }
91 void* GetID() const { return m_id
; }
92 operator const void* () const { return m_id
; }
99 bool operator==(const wxDataViewItem
& left
, const wxDataViewItem
& right
)
101 return left
.GetID() == right
.GetID();
105 bool operator!=(const wxDataViewItem
& left
, const wxDataViewItem
& right
)
107 return !(left
== right
);
110 WX_DEFINE_ARRAY(wxDataViewItem
, wxDataViewItemArray
);
112 // ---------------------------------------------------------
113 // wxDataViewModelNotifier
114 // ---------------------------------------------------------
116 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
119 wxDataViewModelNotifier() { m_owner
= NULL
; }
120 virtual ~wxDataViewModelNotifier() { m_owner
= NULL
; }
122 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
123 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
124 virtual bool ItemChanged( const wxDataViewItem
&item
) = 0;
125 virtual bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
126 virtual bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
127 virtual bool ItemsChanged( const wxDataViewItemArray
&items
);
128 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
) = 0;
129 virtual bool Cleared() = 0;
131 // some platforms, such as GTK+, may need a two step procedure for ::Reset()
132 virtual bool BeforeReset() { return true; }
133 virtual bool AfterReset() { return Cleared(); }
135 virtual void Resort() = 0;
137 void SetOwner( wxDataViewModel
*owner
) { m_owner
= owner
; }
138 wxDataViewModel
*GetOwner() const { return m_owner
; }
141 wxDataViewModel
*m_owner
;
146 // ----------------------------------------------------------------------------
147 // wxDataViewItemAttr: a structure containing the visual attributes of an item
148 // ----------------------------------------------------------------------------
150 // TODO: this should be renamed to wxItemAttr or something general like this
152 class WXDLLIMPEXP_ADV wxDataViewItemAttr
163 void SetColour(const wxColour
& colour
) { m_colour
= colour
; }
164 void SetBold( bool set
) { m_bold
= set
; }
165 void SetItalic( bool set
) { m_italic
= set
; }
168 bool HasColour() const { return m_colour
.IsOk(); }
169 const wxColour
& GetColour() const { return m_colour
; }
171 bool HasFont() const { return m_bold
|| m_italic
; }
172 bool GetBold() const { return m_bold
; }
173 bool GetItalic() const { return m_italic
; }
175 bool IsDefault() const { return !(HasColour() || HasFont()); }
177 // Return the font based on the given one with this attribute applied to it.
178 wxFont
GetEffectiveFont(const wxFont
& font
) const;
187 // ---------------------------------------------------------
189 // ---------------------------------------------------------
191 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier
, wxDataViewModelNotifiers
,
192 class WXDLLIMPEXP_ADV
);
194 class WXDLLIMPEXP_ADV wxDataViewModel
: public wxRefCounter
199 virtual unsigned int GetColumnCount() const = 0;
201 // return type as reported by wxVariant
202 virtual wxString
GetColumnType( unsigned int col
) const = 0;
204 // get value into a wxVariant
205 virtual void GetValue( wxVariant
&variant
,
206 const wxDataViewItem
&item
, unsigned int col
) const = 0;
208 // return true if the given item has a value to display in the given
209 // column: this is always true except for container items which by default
210 // only show their label in the first column (but see HasContainerColumns())
211 bool HasValue(const wxDataViewItem
& item
, unsigned col
) const
213 return col
== 0 || !IsContainer(item
) || HasContainerColumns(item
);
216 // usually ValueChanged() should be called after changing the value in the
217 // model to update the control, ChangeValue() does it on its own while
218 // SetValue() does not -- so while you will override SetValue(), you should
219 // be usually calling ChangeValue()
220 virtual bool SetValue(const wxVariant
&variant
,
221 const wxDataViewItem
&item
,
222 unsigned int col
) = 0;
224 bool ChangeValue(const wxVariant
& variant
,
225 const wxDataViewItem
& item
,
228 return SetValue(variant
, item
, col
) && ValueChanged(item
, col
);
231 // Get text attribute, return false of default attributes should be used
232 virtual bool GetAttr(const wxDataViewItem
&WXUNUSED(item
),
233 unsigned int WXUNUSED(col
),
234 wxDataViewItemAttr
&WXUNUSED(attr
)) const
239 // Override this if you want to disable specific items
240 virtual bool IsEnabled(const wxDataViewItem
&WXUNUSED(item
),
241 unsigned int WXUNUSED(col
)) const
247 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const = 0;
248 virtual bool IsContainer( const wxDataViewItem
&item
) const = 0;
249 // Is the container just a header or an item with all columns
250 virtual bool HasContainerColumns(const wxDataViewItem
& WXUNUSED(item
)) const
252 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const = 0;
254 // delegated notifiers
255 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
256 bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
257 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
258 bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
259 bool ItemChanged( const wxDataViewItem
&item
);
260 bool ItemsChanged( const wxDataViewItemArray
&items
);
261 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
264 // some platforms, such as GTK+, may need a two step procedure for ::Reset()
270 virtual void Resort();
272 void AddNotifier( wxDataViewModelNotifier
*notifier
);
273 void RemoveNotifier( wxDataViewModelNotifier
*notifier
);
275 // default compare function
276 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
277 unsigned int column
, bool ascending
) const;
278 virtual bool HasDefaultCompare() const { return false; }
281 virtual bool IsListModel() const { return false; }
282 virtual bool IsVirtualListModel() const { return false; }
285 // the user should not delete this class directly: he should use DecRef() instead!
286 virtual ~wxDataViewModel() { }
288 wxDataViewModelNotifiers m_notifiers
;
291 // ----------------------------------------------------------------------------
292 // wxDataViewListModel: a model of a list, i.e. flat data structure without any
293 // branches/containers, used as base class by wxDataViewIndexListModel and
294 // wxDataViewVirtualListModel
295 // ----------------------------------------------------------------------------
297 class WXDLLIMPEXP_ADV wxDataViewListModel
: public wxDataViewModel
300 // derived classes should override these methods instead of
301 // {Get,Set}Value() and GetAttr() inherited from the base class
303 virtual void GetValueByRow(wxVariant
&variant
,
304 unsigned row
, unsigned col
) const = 0;
306 virtual bool SetValueByRow(const wxVariant
&variant
,
307 unsigned row
, unsigned col
) = 0;
310 GetAttrByRow(unsigned WXUNUSED(row
), unsigned WXUNUSED(col
),
311 wxDataViewItemAttr
&WXUNUSED(attr
)) const
316 virtual bool IsEnabledByRow(unsigned int WXUNUSED(row
),
317 unsigned int WXUNUSED(col
)) const
323 // helper methods provided by list models only
324 virtual unsigned GetRow( const wxDataViewItem
&item
) const = 0;
326 // returns the number of rows
327 virtual unsigned int GetCount() const = 0;
329 // implement some base class pure virtual directly
330 virtual wxDataViewItem
331 GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
333 // items never have valid parent in this model
334 return wxDataViewItem();
337 virtual bool IsContainer( const wxDataViewItem
&item
) const
339 // only the invisible (and invalid) root item has children
343 // and implement some others by forwarding them to our own ones
344 virtual void GetValue( wxVariant
&variant
,
345 const wxDataViewItem
&item
, unsigned int col
) const
347 GetValueByRow(variant
, GetRow(item
), col
);
350 virtual bool SetValue( const wxVariant
&variant
,
351 const wxDataViewItem
&item
, unsigned int col
)
353 return SetValueByRow( variant
, GetRow(item
), col
);
356 virtual bool GetAttr(const wxDataViewItem
&item
, unsigned int col
,
357 wxDataViewItemAttr
&attr
) const
359 return GetAttrByRow( GetRow(item
), col
, attr
);
362 virtual bool IsEnabled(const wxDataViewItem
&item
, unsigned int col
) const
364 return IsEnabledByRow( GetRow(item
), col
);
368 virtual bool IsListModel() const { return true; }
371 // ---------------------------------------------------------
372 // wxDataViewIndexListModel
373 // ---------------------------------------------------------
375 class WXDLLIMPEXP_ADV wxDataViewIndexListModel
: public wxDataViewListModel
378 wxDataViewIndexListModel( unsigned int initial_size
= 0 );
381 void RowInserted( unsigned int before
);
383 void RowDeleted( unsigned int row
);
384 void RowsDeleted( const wxArrayInt
&rows
);
385 void RowChanged( unsigned int row
);
386 void RowValueChanged( unsigned int row
, unsigned int col
);
387 void Reset( unsigned int new_size
);
389 // convert to/from row/wxDataViewItem
391 virtual unsigned GetRow( const wxDataViewItem
&item
) const;
392 wxDataViewItem
GetItem( unsigned int row
) const;
394 // compare based on index
396 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
397 unsigned int column
, bool ascending
) const;
398 virtual bool HasDefaultCompare() const;
400 // implement base methods
401 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
403 unsigned int GetCount() const { return m_hash
.GetCount(); }
406 wxDataViewItemArray m_hash
;
407 unsigned int m_nextFreeID
;
411 // ---------------------------------------------------------
412 // wxDataViewVirtualListModel
413 // ---------------------------------------------------------
416 // better than nothing
417 typedef wxDataViewIndexListModel wxDataViewVirtualListModel
;
420 class WXDLLIMPEXP_ADV wxDataViewVirtualListModel
: public wxDataViewListModel
423 wxDataViewVirtualListModel( unsigned int initial_size
= 0 );
426 void RowInserted( unsigned int before
);
428 void RowDeleted( unsigned int row
);
429 void RowsDeleted( const wxArrayInt
&rows
);
430 void RowChanged( unsigned int row
);
431 void RowValueChanged( unsigned int row
, unsigned int col
);
432 void Reset( unsigned int new_size
);
434 // convert to/from row/wxDataViewItem
436 virtual unsigned GetRow( const wxDataViewItem
&item
) const;
437 wxDataViewItem
GetItem( unsigned int row
) const;
439 // compare based on index
441 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
442 unsigned int column
, bool ascending
) const;
443 virtual bool HasDefaultCompare() const;
445 // implement base methods
446 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
448 unsigned int GetCount() const { return m_size
; }
451 virtual bool IsVirtualListModel() const { return true; }
459 // ----------------------------------------------------------------------------
460 // wxDataViewRenderer and related classes
461 // ----------------------------------------------------------------------------
463 #include "wx/dvrenderers.h"
465 // ---------------------------------------------------------
466 // wxDataViewColumnBase
467 // ---------------------------------------------------------
469 // for compatibility only, do not use
470 enum wxDataViewColumnFlags
472 wxDATAVIEW_COL_RESIZABLE
= wxCOL_RESIZABLE
,
473 wxDATAVIEW_COL_SORTABLE
= wxCOL_SORTABLE
,
474 wxDATAVIEW_COL_REORDERABLE
= wxCOL_REORDERABLE
,
475 wxDATAVIEW_COL_HIDDEN
= wxCOL_HIDDEN
478 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxSettableHeaderColumn
481 // ctor for the text columns: takes ownership of renderer
482 wxDataViewColumnBase(wxDataViewRenderer
*renderer
,
483 unsigned int model_column
)
485 Init(renderer
, model_column
);
488 // ctor for the bitmap columns
489 wxDataViewColumnBase(const wxBitmap
& bitmap
,
490 wxDataViewRenderer
*renderer
,
491 unsigned int model_column
)
494 Init(renderer
, model_column
);
497 virtual ~wxDataViewColumnBase();
500 virtual void SetOwner( wxDataViewCtrl
*owner
)
504 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column
); }
505 wxDataViewCtrl
*GetOwner() const { return m_owner
; }
506 wxDataViewRenderer
* GetRenderer() const { return m_renderer
; }
508 // implement some of base class pure virtuals (the rest is port-dependent
509 // and done differently in generic and native versions)
510 virtual void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
511 virtual wxBitmap
GetBitmap() const { return m_bitmap
; }
514 wxDataViewRenderer
*m_renderer
;
517 wxDataViewCtrl
*m_owner
;
520 // common part of all ctors
521 void Init(wxDataViewRenderer
*renderer
, unsigned int model_column
);
524 // ---------------------------------------------------------
525 // wxDataViewCtrlBase
526 // ---------------------------------------------------------
528 #define wxDV_SINGLE 0x0000 // for convenience
529 #define wxDV_MULTIPLE 0x0001 // can select multiple items
531 #define wxDV_NO_HEADER 0x0002 // column titles not visible
532 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
533 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
535 #define wxDV_ROW_LINES 0x0010 // alternating colour in rows
536 #define wxDV_VARIABLE_LINE_HEIGHT 0x0020 // variable line height
538 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
541 wxDataViewCtrlBase();
542 virtual ~wxDataViewCtrlBase();
547 virtual bool AssociateModel( wxDataViewModel
*model
);
548 wxDataViewModel
* GetModel();
549 const wxDataViewModel
* GetModel() const;
555 wxDataViewColumn
*PrependTextColumn( const wxString
&label
, unsigned int model_column
,
556 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
557 wxAlignment align
= wxALIGN_NOT
,
558 int flags
= wxDATAVIEW_COL_RESIZABLE
);
559 wxDataViewColumn
*PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
560 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
561 wxAlignment align
= wxALIGN_NOT
,
562 int flags
= wxDATAVIEW_COL_RESIZABLE
);
563 wxDataViewColumn
*PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
564 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
565 wxAlignment align
= wxALIGN_CENTER
,
566 int flags
= wxDATAVIEW_COL_RESIZABLE
);
567 wxDataViewColumn
*PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
568 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
569 wxAlignment align
= wxALIGN_CENTER
,
570 int flags
= wxDATAVIEW_COL_RESIZABLE
);
571 wxDataViewColumn
*PrependDateColumn( const wxString
&label
, unsigned int model_column
,
572 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
573 wxAlignment align
= wxALIGN_NOT
,
574 int flags
= wxDATAVIEW_COL_RESIZABLE
);
575 wxDataViewColumn
*PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
576 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
577 wxAlignment align
= wxALIGN_CENTER
,
578 int flags
= wxDATAVIEW_COL_RESIZABLE
);
579 wxDataViewColumn
*PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
580 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
581 wxAlignment align
= wxALIGN_NOT
,
582 int flags
= wxDATAVIEW_COL_RESIZABLE
);
583 wxDataViewColumn
*PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
584 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
585 wxAlignment align
= wxALIGN_NOT
,
586 int flags
= wxDATAVIEW_COL_RESIZABLE
);
587 wxDataViewColumn
*PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
588 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
589 wxAlignment align
= wxALIGN_CENTER
,
590 int flags
= wxDATAVIEW_COL_RESIZABLE
);
591 wxDataViewColumn
*PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
592 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
593 wxAlignment align
= wxALIGN_CENTER
,
594 int flags
= wxDATAVIEW_COL_RESIZABLE
);
595 wxDataViewColumn
*PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
596 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
597 wxAlignment align
= wxALIGN_NOT
,
598 int flags
= wxDATAVIEW_COL_RESIZABLE
);
599 wxDataViewColumn
*PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
600 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
601 wxAlignment align
= wxALIGN_CENTER
,
602 int flags
= wxDATAVIEW_COL_RESIZABLE
);
604 wxDataViewColumn
*AppendTextColumn( const wxString
&label
, unsigned int model_column
,
605 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
606 wxAlignment align
= wxALIGN_NOT
,
607 int flags
= wxDATAVIEW_COL_RESIZABLE
);
608 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
609 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
610 wxAlignment align
= wxALIGN_NOT
,
611 int flags
= wxDATAVIEW_COL_RESIZABLE
);
612 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
613 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
614 wxAlignment align
= wxALIGN_CENTER
,
615 int flags
= wxDATAVIEW_COL_RESIZABLE
);
616 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
617 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
618 wxAlignment align
= wxALIGN_CENTER
,
619 int flags
= wxDATAVIEW_COL_RESIZABLE
);
620 wxDataViewColumn
*AppendDateColumn( const wxString
&label
, unsigned int model_column
,
621 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
622 wxAlignment align
= wxALIGN_NOT
,
623 int flags
= wxDATAVIEW_COL_RESIZABLE
);
624 wxDataViewColumn
*AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
625 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
626 wxAlignment align
= wxALIGN_CENTER
,
627 int flags
= wxDATAVIEW_COL_RESIZABLE
);
628 wxDataViewColumn
*AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
629 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
630 wxAlignment align
= wxALIGN_NOT
,
631 int flags
= wxDATAVIEW_COL_RESIZABLE
);
632 wxDataViewColumn
*AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
633 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
634 wxAlignment align
= wxALIGN_NOT
,
635 int flags
= wxDATAVIEW_COL_RESIZABLE
);
636 wxDataViewColumn
*AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
637 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
638 wxAlignment align
= wxALIGN_CENTER
,
639 int flags
= wxDATAVIEW_COL_RESIZABLE
);
640 wxDataViewColumn
*AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
641 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
642 wxAlignment align
= wxALIGN_CENTER
,
643 int flags
= wxDATAVIEW_COL_RESIZABLE
);
644 wxDataViewColumn
*AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
645 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
646 wxAlignment align
= wxALIGN_NOT
,
647 int flags
= wxDATAVIEW_COL_RESIZABLE
);
648 wxDataViewColumn
*AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
649 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
650 wxAlignment align
= wxALIGN_CENTER
,
651 int flags
= wxDATAVIEW_COL_RESIZABLE
);
653 virtual bool PrependColumn( wxDataViewColumn
*col
);
654 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
655 virtual bool AppendColumn( wxDataViewColumn
*col
);
657 virtual unsigned int GetColumnCount() const = 0;
658 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const = 0;
659 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const = 0;
661 virtual bool DeleteColumn( wxDataViewColumn
*column
) = 0;
662 virtual bool ClearColumns() = 0;
664 void SetExpanderColumn( wxDataViewColumn
*col
)
665 { m_expander_column
= col
; DoSetExpanderColumn(); }
666 wxDataViewColumn
*GetExpanderColumn() const
667 { return m_expander_column
; }
669 virtual wxDataViewColumn
*GetSortingColumn() const = 0;
675 void SetIndent( int indent
)
676 { m_indent
= indent
; DoSetIndent(); }
677 int GetIndent() const
680 // Current item is the one used by the keyboard navigation, it is the same
681 // as the (unique) selected item in single selection mode so these
682 // functions are mostly useful for controls with wxDV_MULTIPLE style.
683 wxDataViewItem
GetCurrentItem() const;
684 void SetCurrentItem(const wxDataViewItem
& item
);
686 virtual wxDataViewItem
GetSelection() const = 0;
687 virtual int GetSelections( wxDataViewItemArray
& sel
) const = 0;
688 virtual void SetSelections( const wxDataViewItemArray
& sel
) = 0;
689 virtual void Select( const wxDataViewItem
& item
) = 0;
690 virtual void Unselect( const wxDataViewItem
& item
) = 0;
691 virtual bool IsSelected( const wxDataViewItem
& item
) const = 0;
693 virtual void SelectAll() = 0;
694 virtual void UnselectAll() = 0;
696 virtual void Expand( const wxDataViewItem
& item
) = 0;
697 virtual void ExpandAncestors( const wxDataViewItem
& item
);
698 virtual void Collapse( const wxDataViewItem
& item
) = 0;
699 virtual bool IsExpanded( const wxDataViewItem
& item
) const = 0;
701 virtual void EnsureVisible( const wxDataViewItem
& item
,
702 const wxDataViewColumn
*column
= NULL
) = 0;
703 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
&item
, wxDataViewColumn
* &column
) const = 0;
704 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const = 0;
706 virtual bool SetRowHeight( int WXUNUSED(rowHeight
) ) { return false; }
708 virtual void StartEditor( const wxDataViewItem
& WXUNUSED(item
),
709 unsigned int WXUNUSED(column
) )
712 #if wxUSE_DRAG_AND_DROP
713 virtual bool EnableDragSource(const wxDataFormat
& WXUNUSED(format
))
715 virtual bool EnableDropTarget(const wxDataFormat
& WXUNUSED(format
))
717 #endif // wxUSE_DRAG_AND_DROP
719 // define control visual attributes
720 // --------------------------------
722 virtual wxVisualAttributes
GetDefaultAttributes() const
724 return GetClassDefaultAttributes(GetWindowVariant());
727 static wxVisualAttributes
728 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
)
730 return wxControl::GetCompositeControlsDefaultAttributes(variant
);
734 virtual void DoSetExpanderColumn() = 0 ;
735 virtual void DoSetIndent() = 0;
738 // Implementation of the public Set/GetCurrentItem() methods which are only
739 // called in multi selection case (for single selection controls their
740 // implementation is trivial and is done in the base class itself).
741 virtual wxDataViewItem
DoGetCurrentItem() const = 0;
742 virtual void DoSetCurrentItem(const wxDataViewItem
& item
) = 0;
744 wxDataViewModel
*m_model
;
745 wxDataViewColumn
*m_expander_column
;
749 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
752 // ----------------------------------------------------------------------------
753 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
754 // ----------------------------------------------------------------------------
756 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
759 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
760 : wxNotifyEvent(commandType
, winid
),
764 m_value(wxNullVariant
),
769 m_editCancelled(false)
770 #if wxUSE_DRAG_AND_DROP
771 , m_dataObject(NULL
),
777 wxDataViewEvent(const wxDataViewEvent
& event
)
778 : wxNotifyEvent(event
),
779 m_item(event
.m_item
),
781 m_model(event
.m_model
),
782 m_value(event
.m_value
),
783 m_column(event
.m_column
),
785 m_cacheFrom(event
.m_cacheFrom
),
786 m_cacheTo(event
.m_cacheTo
),
787 m_editCancelled(event
.m_editCancelled
)
788 #if wxUSE_DRAG_AND_DROP
789 , m_dataObject(event
.m_dataObject
),
790 m_dataFormat(event
.m_dataFormat
),
791 m_dataBuffer(event
.m_dataBuffer
),
792 m_dataSize(event
.m_dataSize
)
796 wxDataViewItem
GetItem() const { return m_item
; }
797 void SetItem( const wxDataViewItem
&item
) { m_item
= item
; }
799 int GetColumn() const { return m_col
; }
800 void SetColumn( int col
) { m_col
= col
; }
802 wxDataViewModel
* GetModel() const { return m_model
; }
803 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
805 const wxVariant
&GetValue() const { return m_value
; }
806 void SetValue( const wxVariant
&value
) { m_value
= value
; }
808 // for wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE only
809 bool IsEditCancelled() const { return m_editCancelled
; }
810 void SetEditCanceled(bool editCancelled
) { m_editCancelled
= editCancelled
; }
812 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
813 void SetDataViewColumn( wxDataViewColumn
*col
) { m_column
= col
; }
814 wxDataViewColumn
*GetDataViewColumn() const { return m_column
; }
816 // for wxEVT_DATAVIEW_CONTEXT_MENU only
817 wxPoint
GetPosition() const { return m_pos
; }
818 void SetPosition( int x
, int y
) { m_pos
.x
= x
; m_pos
.y
= y
; }
820 // For wxEVT_COMMAND_DATAVIEW_CACHE_HINT
821 int GetCacheFrom() const { return m_cacheFrom
; }
822 int GetCacheTo() const { return m_cacheTo
; }
823 void SetCache(int from
, int to
) { m_cacheFrom
= from
; m_cacheTo
= to
; }
826 #if wxUSE_DRAG_AND_DROP
827 // For drag operations
828 void SetDataObject( wxDataObject
*obj
) { m_dataObject
= obj
; }
829 wxDataObject
*GetDataObject() const { return m_dataObject
; }
831 // For drop operations
832 void SetDataFormat( const wxDataFormat
&format
) { m_dataFormat
= format
; }
833 wxDataFormat
GetDataFormat() const { return m_dataFormat
; }
834 void SetDataSize( size_t size
) { m_dataSize
= size
; }
835 size_t GetDataSize() const { return m_dataSize
; }
836 void SetDataBuffer( void* buf
) { m_dataBuffer
= buf
;}
837 void *GetDataBuffer() const { return m_dataBuffer
; }
838 #endif // wxUSE_DRAG_AND_DROP
840 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
843 wxDataViewItem m_item
;
845 wxDataViewModel
*m_model
;
847 wxDataViewColumn
*m_column
;
851 bool m_editCancelled
;
853 #if wxUSE_DRAG_AND_DROP
854 wxDataObject
*m_dataObject
;
856 wxDataFormat m_dataFormat
;
859 #endif // wxUSE_DRAG_AND_DROP
862 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
865 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
867 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
868 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
869 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
870 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
871 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
872 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
873 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
874 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
875 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
877 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
879 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
880 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
881 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
882 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
884 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
886 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
887 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
888 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
890 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
892 #define wxDataViewEventHandler(func) \
893 wxEVENT_HANDLER_CAST(wxDataViewEventFunction, func)
895 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
896 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
898 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
900 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
901 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
902 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
903 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
904 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
905 #define EVT_DATAVIEW_ITEM_START_EDITING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_START_EDITING, id, fn)
906 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
907 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
908 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
910 #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn)
912 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
913 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
914 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
915 #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn)
916 #define EVT_DATAVIEW_CACHE_HINT(id, fn) wx__DECLARE_DATAVIEWEVT(CACHE_HINT, id, fn)
918 #define EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_BEGIN_DRAG, id, fn)
919 #define EVT_DATAVIEW_ITEM_DROP_POSSIBLE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP_POSSIBLE, id, fn)
920 #define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn)
922 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
923 #include "wx/generic/dataview.h"
924 #elif defined(__WXGTK20__)
925 #include "wx/gtk/dataview.h"
926 #elif defined(__WXMAC__)
927 #include "wx/osx/dataview.h"
929 #error "unknown native wxDataViewCtrl implementation"
932 //-----------------------------------------------------------------------------
933 // wxDataViewListStore
934 //-----------------------------------------------------------------------------
936 class WXDLLIMPEXP_ADV wxDataViewListStoreLine
939 wxDataViewListStoreLine( wxClientData
*data
= NULL
)
943 virtual ~wxDataViewListStoreLine()
948 void SetData( wxClientData
*data
)
949 { if (m_data
) delete m_data
; m_data
= data
; }
950 wxClientData
*GetData() const
953 wxVector
<wxVariant
> m_values
;
956 wxClientData
*m_data
;
960 class WXDLLIMPEXP_ADV wxDataViewListStore
: public wxDataViewIndexListModel
963 wxDataViewListStore();
964 ~wxDataViewListStore();
966 void PrependColumn( const wxString
&varianttype
);
967 void InsertColumn( unsigned int pos
, const wxString
&varianttype
);
968 void AppendColumn( const wxString
&varianttype
);
970 void AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
);
971 void PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
);
972 void InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
);
973 void DeleteItem( unsigned int pos
);
974 void DeleteAllItems();
976 // override base virtuals
978 virtual unsigned int GetColumnCount() const;
980 virtual wxString
GetColumnType( unsigned int col
) const;
982 virtual void GetValueByRow( wxVariant
&value
,
983 unsigned int row
, unsigned int col
) const;
985 virtual bool SetValueByRow( const wxVariant
&value
,
986 unsigned int row
, unsigned int col
);
990 wxVector
<wxDataViewListStoreLine
*> m_data
;
991 wxArrayString m_cols
;
994 //-----------------------------------------------------------------------------
996 class WXDLLIMPEXP_ADV wxDataViewListCtrl
: public wxDataViewCtrl
999 wxDataViewListCtrl();
1000 wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1001 const wxPoint
& pos
= wxDefaultPosition
,
1002 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_ROW_LINES
,
1003 const wxValidator
& validator
= wxDefaultValidator
);
1004 ~wxDataViewListCtrl();
1006 bool Create( wxWindow
*parent
, wxWindowID id
,
1007 const wxPoint
& pos
= wxDefaultPosition
,
1008 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_ROW_LINES
,
1009 const wxValidator
& validator
= wxDefaultValidator
);
1011 wxDataViewListStore
*GetStore()
1012 { return (wxDataViewListStore
*) GetModel(); }
1013 const wxDataViewListStore
*GetStore() const
1014 { return (const wxDataViewListStore
*) GetModel(); }
1016 int ItemToRow(const wxDataViewItem
&item
) const
1017 { return item
.IsOk() ? (int)GetStore()->GetRow(item
) : wxNOT_FOUND
; }
1018 wxDataViewItem
RowToItem(int row
) const
1019 { return row
== wxNOT_FOUND
? wxDataViewItem() : GetStore()->GetItem(row
); }
1021 int GetSelectedRow() const
1022 { return ItemToRow(GetSelection()); }
1023 void SelectRow(unsigned row
)
1024 { Select(RowToItem(row
)); }
1025 void UnselectRow(unsigned row
)
1026 { Unselect(RowToItem(row
)); }
1027 bool IsRowSelected(unsigned row
) const
1028 { return IsSelected(RowToItem(row
)); }
1030 bool AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
);
1031 bool PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
);
1032 bool InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
);
1034 // overridden from base class
1035 virtual bool PrependColumn( wxDataViewColumn
*col
);
1036 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
1037 virtual bool AppendColumn( wxDataViewColumn
*col
);
1039 wxDataViewColumn
*AppendTextColumn( const wxString
&label
,
1040 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
1041 int width
= -1, wxAlignment align
= wxALIGN_LEFT
, int flags
= wxDATAVIEW_COL_RESIZABLE
);
1042 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
,
1043 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
1044 int width
= -1, wxAlignment align
= wxALIGN_LEFT
, int flags
= wxDATAVIEW_COL_RESIZABLE
);
1045 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
,
1046 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
1047 int width
= -1, wxAlignment align
= wxALIGN_LEFT
, int flags
= wxDATAVIEW_COL_RESIZABLE
);
1048 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
,
1049 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
1050 int width
= -1, wxAlignment align
= wxALIGN_LEFT
, int flags
= wxDATAVIEW_COL_RESIZABLE
);
1052 void AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
)
1053 { GetStore()->AppendItem( values
, data
); }
1054 void PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
)
1055 { GetStore()->PrependItem( values
, data
); }
1056 void InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
)
1057 { GetStore()->InsertItem( row
, values
, data
); }
1058 void DeleteItem( unsigned row
)
1059 { GetStore()->DeleteItem( row
); }
1060 void DeleteAllItems()
1061 { GetStore()->DeleteAllItems(); }
1063 void SetValue( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1064 { GetStore()->SetValueByRow( value
, row
, col
);
1065 GetStore()->RowValueChanged( row
, col
); }
1066 void GetValue( wxVariant
&value
, unsigned int row
, unsigned int col
)
1067 { GetStore()->GetValueByRow( value
, row
, col
); }
1069 void SetTextValue( const wxString
&value
, unsigned int row
, unsigned int col
)
1070 { GetStore()->SetValueByRow( value
, row
, col
);
1071 GetStore()->RowValueChanged( row
, col
); }
1072 wxString
GetTextValue( unsigned int row
, unsigned int col
) const
1073 { wxVariant value
; GetStore()->GetValueByRow( value
, row
, col
); return value
.GetString(); }
1075 void SetToggleValue( bool value
, unsigned int row
, unsigned int col
)
1076 { GetStore()->SetValueByRow( value
, row
, col
);
1077 GetStore()->RowValueChanged( row
, col
); }
1078 bool GetToggleValue( unsigned int row
, unsigned int col
) const
1079 { wxVariant value
; GetStore()->GetValueByRow( value
, row
, col
); return value
.GetBool(); }
1081 void OnSize( wxSizeEvent
&event
);
1084 DECLARE_EVENT_TABLE()
1085 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl
)
1088 //-----------------------------------------------------------------------------
1089 // wxDataViewTreeStore
1090 //-----------------------------------------------------------------------------
1092 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
1095 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode
*parent
,
1096 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
1097 virtual ~wxDataViewTreeStoreNode();
1099 void SetText( const wxString
&text
)
1101 wxString
GetText() const
1103 void SetIcon( const wxIcon
&icon
)
1105 const wxIcon
&GetIcon() const
1107 void SetData( wxClientData
*data
)
1108 { if (m_data
) delete m_data
; m_data
= data
; }
1109 wxClientData
*GetData() const
1112 wxDataViewItem
GetItem() const
1113 { return wxDataViewItem( (void*) this ); }
1115 virtual bool IsContainer()
1118 wxDataViewTreeStoreNode
*GetParent()
1119 { return m_parent
; }
1122 wxDataViewTreeStoreNode
*m_parent
;
1125 wxClientData
*m_data
;
1128 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode
, wxDataViewTreeStoreNodeList
,
1129 class WXDLLIMPEXP_ADV
);
1131 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode
: public wxDataViewTreeStoreNode
1134 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode
*parent
,
1135 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
1136 wxClientData
*data
= NULL
);
1137 virtual ~wxDataViewTreeStoreContainerNode();
1139 const wxDataViewTreeStoreNodeList
&GetChildren() const
1140 { return m_children
; }
1141 wxDataViewTreeStoreNodeList
&GetChildren()
1142 { return m_children
; }
1144 void SetExpandedIcon( const wxIcon
&icon
)
1145 { m_iconExpanded
= icon
; }
1146 const wxIcon
&GetExpandedIcon() const
1147 { return m_iconExpanded
; }
1149 void SetExpanded( bool expanded
= true )
1150 { m_isExpanded
= expanded
; }
1151 bool IsExpanded() const
1152 { return m_isExpanded
; }
1154 virtual bool IsContainer()
1158 wxDataViewTreeStoreNodeList m_children
;
1159 wxIcon m_iconExpanded
;
1163 //-----------------------------------------------------------------------------
1165 class WXDLLIMPEXP_ADV wxDataViewTreeStore
: public wxDataViewModel
1168 wxDataViewTreeStore();
1169 ~wxDataViewTreeStore();
1171 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
1172 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
1173 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
1174 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
1175 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1176 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
1178 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
1179 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
1180 wxClientData
*data
= NULL
);
1181 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
1182 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
1183 wxClientData
*data
= NULL
);
1184 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1185 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
1186 wxClientData
*data
= NULL
);
1188 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const;
1189 int GetChildCount( const wxDataViewItem
& parent
) const;
1191 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
1192 wxString
GetItemText( const wxDataViewItem
& item
) const;
1193 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
1194 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const;
1195 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
1196 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const;
1197 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
);
1198 wxClientData
*GetItemData( const wxDataViewItem
& item
) const;
1200 void DeleteItem( const wxDataViewItem
& item
);
1201 void DeleteChildren( const wxDataViewItem
& item
);
1202 void DeleteAllItems();
1204 // implement base methods
1206 virtual void GetValue( wxVariant
&variant
,
1207 const wxDataViewItem
&item
, unsigned int col
) const;
1208 virtual bool SetValue( const wxVariant
&variant
,
1209 const wxDataViewItem
&item
, unsigned int col
);
1210 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
1211 virtual bool IsContainer( const wxDataViewItem
&item
) const;
1212 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
1214 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1215 unsigned int column
, bool ascending
) const;
1217 virtual bool HasDefaultCompare() const
1219 virtual unsigned int GetColumnCount() const
1221 virtual wxString
GetColumnType( unsigned int WXUNUSED(col
) ) const
1222 { return wxT("wxDataViewIconText"); }
1224 wxDataViewTreeStoreNode
*FindNode( const wxDataViewItem
&item
) const;
1225 wxDataViewTreeStoreContainerNode
*FindContainerNode( const wxDataViewItem
&item
) const;
1226 wxDataViewTreeStoreNode
*GetRoot() const { return m_root
; }
1229 wxDataViewTreeStoreNode
*m_root
;
1232 //-----------------------------------------------------------------------------
1234 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl
: public wxDataViewCtrl
,
1238 wxDataViewTreeCtrl() { }
1239 wxDataViewTreeCtrl(wxWindow
*parent
,
1241 const wxPoint
& pos
= wxDefaultPosition
,
1242 const wxSize
& size
= wxDefaultSize
,
1243 long style
= wxDV_NO_HEADER
| wxDV_ROW_LINES
,
1244 const wxValidator
& validator
= wxDefaultValidator
)
1246 Create(parent
, id
, pos
, size
, style
, validator
);
1249 bool Create(wxWindow
*parent
,
1251 const wxPoint
& pos
= wxDefaultPosition
,
1252 const wxSize
& size
= wxDefaultSize
,
1253 long style
= wxDV_NO_HEADER
| wxDV_ROW_LINES
,
1254 const wxValidator
& validator
= wxDefaultValidator
);
1256 wxDataViewTreeStore
*GetStore()
1257 { return (wxDataViewTreeStore
*) GetModel(); }
1258 const wxDataViewTreeStore
*GetStore() const
1259 { return (const wxDataViewTreeStore
*) GetModel(); }
1261 bool IsContainer( const wxDataViewItem
& item
) const
1262 { return GetStore()->IsContainer(item
); }
1264 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
1265 const wxString
&text
, int icon
= NO_IMAGE
, wxClientData
*data
= NULL
);
1266 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
1267 const wxString
&text
, int icon
= NO_IMAGE
, wxClientData
*data
= NULL
);
1268 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1269 const wxString
&text
, int icon
= NO_IMAGE
, wxClientData
*data
= NULL
);
1271 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
1272 const wxString
&text
, int icon
= NO_IMAGE
, int expanded
= NO_IMAGE
,
1273 wxClientData
*data
= NULL
);
1274 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
1275 const wxString
&text
, int icon
= NO_IMAGE
, int expanded
= NO_IMAGE
,
1276 wxClientData
*data
= NULL
);
1277 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1278 const wxString
&text
, int icon
= NO_IMAGE
, int expanded
= NO_IMAGE
,
1279 wxClientData
*data
= NULL
);
1281 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1282 { return GetStore()->GetNthChild(parent
, pos
); }
1283 int GetChildCount( const wxDataViewItem
& parent
) const
1284 { return GetStore()->GetChildCount(parent
); }
1286 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
1287 wxString
GetItemText( const wxDataViewItem
& item
) const
1288 { return GetStore()->GetItemText(item
); }
1289 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
1290 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const
1291 { return GetStore()->GetItemIcon(item
); }
1292 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
1293 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const
1294 { return GetStore()->GetItemExpandedIcon(item
); }
1295 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1296 { GetStore()->SetItemData(item
,data
); }
1297 wxClientData
*GetItemData( const wxDataViewItem
& item
) const
1298 { return GetStore()->GetItemData(item
); }
1300 void DeleteItem( const wxDataViewItem
& item
);
1301 void DeleteChildren( const wxDataViewItem
& item
);
1302 void DeleteAllItems();
1304 void OnExpanded( wxDataViewEvent
&event
);
1305 void OnCollapsed( wxDataViewEvent
&event
);
1306 void OnSize( wxSizeEvent
&event
);
1309 DECLARE_EVENT_TABLE()
1310 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl
)
1313 #endif // wxUSE_DATAVIEWCTRL
1316 // _WX_DATAVIEW_H_BASE_