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/itemid.h"
25 #include "wx/weakref.h"
26 #include "wx/vector.h"
27 #include "wx/dataobj.h"
28 #include "wx/withimages.h"
30 class WXDLLIMPEXP_FWD_CORE wxImageList
;
32 #if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
33 // #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
34 #define wxHAS_GENERIC_DATAVIEWCTRL
37 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
38 // this symbol doesn't follow the convention for wxUSE_XXX symbols which
39 // are normally always defined as either 0 or 1, so its use is deprecated
40 // and it only exists for backwards compatibility, don't use it any more
41 // and use wxHAS_GENERIC_DATAVIEWCTRL instead
42 #define wxUSE_GENERICDATAVIEWCTRL
45 // ----------------------------------------------------------------------------
46 // wxDataViewCtrl globals
47 // ----------------------------------------------------------------------------
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 // Make it a class and not a typedef to allow forward declaring it.
83 class wxDataViewItem
: public wxItemId
<void*>
86 wxDataViewItem() : wxItemId
<void*>() { }
87 wxEXPLICIT
wxDataViewItem(void* pItem
) : wxItemId
<void*>(pItem
) { }
90 WX_DEFINE_ARRAY(wxDataViewItem
, wxDataViewItemArray
);
92 // ---------------------------------------------------------
93 // wxDataViewModelNotifier
94 // ---------------------------------------------------------
96 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
99 wxDataViewModelNotifier() { m_owner
= NULL
; }
100 virtual ~wxDataViewModelNotifier() { m_owner
= NULL
; }
102 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
103 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
104 virtual bool ItemChanged( const wxDataViewItem
&item
) = 0;
105 virtual bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
106 virtual bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
107 virtual bool ItemsChanged( const wxDataViewItemArray
&items
);
108 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
) = 0;
109 virtual bool Cleared() = 0;
111 // some platforms, such as GTK+, may need a two step procedure for ::Reset()
112 virtual bool BeforeReset() { return true; }
113 virtual bool AfterReset() { return Cleared(); }
115 virtual void Resort() = 0;
117 void SetOwner( wxDataViewModel
*owner
) { m_owner
= owner
; }
118 wxDataViewModel
*GetOwner() const { return m_owner
; }
121 wxDataViewModel
*m_owner
;
126 // ----------------------------------------------------------------------------
127 // wxDataViewItemAttr: a structure containing the visual attributes of an item
128 // ----------------------------------------------------------------------------
130 // TODO: this should be renamed to wxItemAttr or something general like this
132 class WXDLLIMPEXP_ADV wxDataViewItemAttr
143 void SetColour(const wxColour
& colour
) { m_colour
= colour
; }
144 void SetBold( bool set
) { m_bold
= set
; }
145 void SetItalic( bool set
) { m_italic
= set
; }
148 bool HasColour() const { return m_colour
.IsOk(); }
149 const wxColour
& GetColour() const { return m_colour
; }
151 bool HasFont() const { return m_bold
|| m_italic
; }
152 bool GetBold() const { return m_bold
; }
153 bool GetItalic() const { return m_italic
; }
155 bool IsDefault() const { return !(HasColour() || HasFont()); }
157 // Return the font based on the given one with this attribute applied to it.
158 wxFont
GetEffectiveFont(const wxFont
& font
) const;
167 // ---------------------------------------------------------
169 // ---------------------------------------------------------
171 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier
, wxDataViewModelNotifiers
,
172 class WXDLLIMPEXP_ADV
);
174 class WXDLLIMPEXP_ADV wxDataViewModel
: public wxRefCounter
179 virtual unsigned int GetColumnCount() const = 0;
181 // return type as reported by wxVariant
182 virtual wxString
GetColumnType( unsigned int col
) const = 0;
184 // get value into a wxVariant
185 virtual void GetValue( wxVariant
&variant
,
186 const wxDataViewItem
&item
, unsigned int col
) const = 0;
188 // return true if the given item has a value to display in the given
189 // column: this is always true except for container items which by default
190 // only show their label in the first column (but see HasContainerColumns())
191 bool HasValue(const wxDataViewItem
& item
, unsigned col
) const
193 return col
== 0 || !IsContainer(item
) || HasContainerColumns(item
);
196 // usually ValueChanged() should be called after changing the value in the
197 // model to update the control, ChangeValue() does it on its own while
198 // SetValue() does not -- so while you will override SetValue(), you should
199 // be usually calling ChangeValue()
200 virtual bool SetValue(const wxVariant
&variant
,
201 const wxDataViewItem
&item
,
202 unsigned int col
) = 0;
204 bool ChangeValue(const wxVariant
& variant
,
205 const wxDataViewItem
& item
,
208 return SetValue(variant
, item
, col
) && ValueChanged(item
, col
);
211 // Get text attribute, return false of default attributes should be used
212 virtual bool GetAttr(const wxDataViewItem
&WXUNUSED(item
),
213 unsigned int WXUNUSED(col
),
214 wxDataViewItemAttr
&WXUNUSED(attr
)) const
219 // Override this if you want to disable specific items
220 virtual bool IsEnabled(const wxDataViewItem
&WXUNUSED(item
),
221 unsigned int WXUNUSED(col
)) const
227 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const = 0;
228 virtual bool IsContainer( const wxDataViewItem
&item
) const = 0;
229 // Is the container just a header or an item with all columns
230 virtual bool HasContainerColumns(const wxDataViewItem
& WXUNUSED(item
)) const
232 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const = 0;
234 // delegated notifiers
235 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
236 bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
237 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
238 bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
239 bool ItemChanged( const wxDataViewItem
&item
);
240 bool ItemsChanged( const wxDataViewItemArray
&items
);
241 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
244 // some platforms, such as GTK+, may need a two step procedure for ::Reset()
250 virtual void Resort();
252 void AddNotifier( wxDataViewModelNotifier
*notifier
);
253 void RemoveNotifier( wxDataViewModelNotifier
*notifier
);
255 // default compare function
256 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
257 unsigned int column
, bool ascending
) const;
258 virtual bool HasDefaultCompare() const { return false; }
261 virtual bool IsListModel() const { return false; }
262 virtual bool IsVirtualListModel() const { return false; }
265 // the user should not delete this class directly: he should use DecRef() instead!
266 virtual ~wxDataViewModel() { }
268 wxDataViewModelNotifiers m_notifiers
;
271 // ----------------------------------------------------------------------------
272 // wxDataViewListModel: a model of a list, i.e. flat data structure without any
273 // branches/containers, used as base class by wxDataViewIndexListModel and
274 // wxDataViewVirtualListModel
275 // ----------------------------------------------------------------------------
277 class WXDLLIMPEXP_ADV wxDataViewListModel
: public wxDataViewModel
280 // derived classes should override these methods instead of
281 // {Get,Set}Value() and GetAttr() inherited from the base class
283 virtual void GetValueByRow(wxVariant
&variant
,
284 unsigned row
, unsigned col
) const = 0;
286 virtual bool SetValueByRow(const wxVariant
&variant
,
287 unsigned row
, unsigned col
) = 0;
290 GetAttrByRow(unsigned WXUNUSED(row
), unsigned WXUNUSED(col
),
291 wxDataViewItemAttr
&WXUNUSED(attr
)) const
296 virtual bool IsEnabledByRow(unsigned int WXUNUSED(row
),
297 unsigned int WXUNUSED(col
)) const
303 // helper methods provided by list models only
304 virtual unsigned GetRow( const wxDataViewItem
&item
) const = 0;
306 // returns the number of rows
307 virtual unsigned int GetCount() const = 0;
309 // implement some base class pure virtual directly
310 virtual wxDataViewItem
311 GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
313 // items never have valid parent in this model
314 return wxDataViewItem();
317 virtual bool IsContainer( const wxDataViewItem
&item
) const
319 // only the invisible (and invalid) root item has children
323 // and implement some others by forwarding them to our own ones
324 virtual void GetValue( wxVariant
&variant
,
325 const wxDataViewItem
&item
, unsigned int col
) const
327 GetValueByRow(variant
, GetRow(item
), col
);
330 virtual bool SetValue( const wxVariant
&variant
,
331 const wxDataViewItem
&item
, unsigned int col
)
333 return SetValueByRow( variant
, GetRow(item
), col
);
336 virtual bool GetAttr(const wxDataViewItem
&item
, unsigned int col
,
337 wxDataViewItemAttr
&attr
) const
339 return GetAttrByRow( GetRow(item
), col
, attr
);
342 virtual bool IsEnabled(const wxDataViewItem
&item
, unsigned int col
) const
344 return IsEnabledByRow( GetRow(item
), col
);
348 virtual bool IsListModel() const { return true; }
351 // ---------------------------------------------------------
352 // wxDataViewIndexListModel
353 // ---------------------------------------------------------
355 class WXDLLIMPEXP_ADV wxDataViewIndexListModel
: public wxDataViewListModel
358 wxDataViewIndexListModel( unsigned int initial_size
= 0 );
361 void RowInserted( unsigned int before
);
363 void RowDeleted( unsigned int row
);
364 void RowsDeleted( const wxArrayInt
&rows
);
365 void RowChanged( unsigned int row
);
366 void RowValueChanged( unsigned int row
, unsigned int col
);
367 void Reset( unsigned int new_size
);
369 // convert to/from row/wxDataViewItem
371 virtual unsigned GetRow( const wxDataViewItem
&item
) const;
372 wxDataViewItem
GetItem( unsigned int row
) const;
374 // compare based on index
376 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
377 unsigned int column
, bool ascending
) const;
378 virtual bool HasDefaultCompare() const;
380 // implement base methods
381 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
383 unsigned int GetCount() const { return m_hash
.GetCount(); }
386 wxDataViewItemArray m_hash
;
387 unsigned int m_nextFreeID
;
391 // ---------------------------------------------------------
392 // wxDataViewVirtualListModel
393 // ---------------------------------------------------------
396 // better than nothing
397 typedef wxDataViewIndexListModel wxDataViewVirtualListModel
;
400 class WXDLLIMPEXP_ADV wxDataViewVirtualListModel
: public wxDataViewListModel
403 wxDataViewVirtualListModel( unsigned int initial_size
= 0 );
406 void RowInserted( unsigned int before
);
408 void RowDeleted( unsigned int row
);
409 void RowsDeleted( const wxArrayInt
&rows
);
410 void RowChanged( unsigned int row
);
411 void RowValueChanged( unsigned int row
, unsigned int col
);
412 void Reset( unsigned int new_size
);
414 // convert to/from row/wxDataViewItem
416 virtual unsigned GetRow( const wxDataViewItem
&item
) const;
417 wxDataViewItem
GetItem( unsigned int row
) const;
419 // compare based on index
421 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
422 unsigned int column
, bool ascending
) const;
423 virtual bool HasDefaultCompare() const;
425 // implement base methods
426 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
428 unsigned int GetCount() const { return m_size
; }
431 virtual bool IsVirtualListModel() const { return true; }
439 // ----------------------------------------------------------------------------
440 // wxDataViewRenderer and related classes
441 // ----------------------------------------------------------------------------
443 #include "wx/dvrenderers.h"
445 // ---------------------------------------------------------
446 // wxDataViewColumnBase
447 // ---------------------------------------------------------
449 // for compatibility only, do not use
450 enum wxDataViewColumnFlags
452 wxDATAVIEW_COL_RESIZABLE
= wxCOL_RESIZABLE
,
453 wxDATAVIEW_COL_SORTABLE
= wxCOL_SORTABLE
,
454 wxDATAVIEW_COL_REORDERABLE
= wxCOL_REORDERABLE
,
455 wxDATAVIEW_COL_HIDDEN
= wxCOL_HIDDEN
458 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxSettableHeaderColumn
461 // ctor for the text columns: takes ownership of renderer
462 wxDataViewColumnBase(wxDataViewRenderer
*renderer
,
463 unsigned int model_column
)
465 Init(renderer
, model_column
);
468 // ctor for the bitmap columns
469 wxDataViewColumnBase(const wxBitmap
& bitmap
,
470 wxDataViewRenderer
*renderer
,
471 unsigned int model_column
)
474 Init(renderer
, model_column
);
477 virtual ~wxDataViewColumnBase();
480 virtual void SetOwner( wxDataViewCtrl
*owner
)
484 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column
); }
485 wxDataViewCtrl
*GetOwner() const { return m_owner
; }
486 wxDataViewRenderer
* GetRenderer() const { return m_renderer
; }
488 // implement some of base class pure virtuals (the rest is port-dependent
489 // and done differently in generic and native versions)
490 virtual void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
491 virtual wxBitmap
GetBitmap() const { return m_bitmap
; }
494 wxDataViewRenderer
*m_renderer
;
497 wxDataViewCtrl
*m_owner
;
500 // common part of all ctors
501 void Init(wxDataViewRenderer
*renderer
, unsigned int model_column
);
504 // ---------------------------------------------------------
505 // wxDataViewCtrlBase
506 // ---------------------------------------------------------
508 #define wxDV_SINGLE 0x0000 // for convenience
509 #define wxDV_MULTIPLE 0x0001 // can select multiple items
511 #define wxDV_NO_HEADER 0x0002 // column titles not visible
512 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
513 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
515 #define wxDV_ROW_LINES 0x0010 // alternating colour in rows
516 #define wxDV_VARIABLE_LINE_HEIGHT 0x0020 // variable line height
518 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
521 wxDataViewCtrlBase();
522 virtual ~wxDataViewCtrlBase();
527 virtual bool AssociateModel( wxDataViewModel
*model
);
528 wxDataViewModel
* GetModel();
529 const wxDataViewModel
* GetModel() const;
535 wxDataViewColumn
*PrependTextColumn( const wxString
&label
, unsigned int model_column
,
536 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
537 wxAlignment align
= wxALIGN_NOT
,
538 int flags
= wxDATAVIEW_COL_RESIZABLE
);
539 wxDataViewColumn
*PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
540 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
541 wxAlignment align
= wxALIGN_NOT
,
542 int flags
= wxDATAVIEW_COL_RESIZABLE
);
543 wxDataViewColumn
*PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
544 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
545 wxAlignment align
= wxALIGN_CENTER
,
546 int flags
= wxDATAVIEW_COL_RESIZABLE
);
547 wxDataViewColumn
*PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
548 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
549 wxAlignment align
= wxALIGN_CENTER
,
550 int flags
= wxDATAVIEW_COL_RESIZABLE
);
551 wxDataViewColumn
*PrependDateColumn( const wxString
&label
, unsigned int model_column
,
552 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
553 wxAlignment align
= wxALIGN_NOT
,
554 int flags
= wxDATAVIEW_COL_RESIZABLE
);
555 wxDataViewColumn
*PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
556 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
557 wxAlignment align
= wxALIGN_CENTER
,
558 int flags
= wxDATAVIEW_COL_RESIZABLE
);
559 wxDataViewColumn
*PrependTextColumn( const wxBitmap
&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
*PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
564 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
565 wxAlignment align
= wxALIGN_NOT
,
566 int flags
= wxDATAVIEW_COL_RESIZABLE
);
567 wxDataViewColumn
*PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
568 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
569 wxAlignment align
= wxALIGN_CENTER
,
570 int flags
= wxDATAVIEW_COL_RESIZABLE
);
571 wxDataViewColumn
*PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
572 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
573 wxAlignment align
= wxALIGN_CENTER
,
574 int flags
= wxDATAVIEW_COL_RESIZABLE
);
575 wxDataViewColumn
*PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
576 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
577 wxAlignment align
= wxALIGN_NOT
,
578 int flags
= wxDATAVIEW_COL_RESIZABLE
);
579 wxDataViewColumn
*PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
580 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
581 wxAlignment align
= wxALIGN_CENTER
,
582 int flags
= wxDATAVIEW_COL_RESIZABLE
);
584 wxDataViewColumn
*AppendTextColumn( const wxString
&label
, unsigned int model_column
,
585 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
586 wxAlignment align
= wxALIGN_NOT
,
587 int flags
= wxDATAVIEW_COL_RESIZABLE
);
588 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
589 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
590 wxAlignment align
= wxALIGN_NOT
,
591 int flags
= wxDATAVIEW_COL_RESIZABLE
);
592 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
593 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
594 wxAlignment align
= wxALIGN_CENTER
,
595 int flags
= wxDATAVIEW_COL_RESIZABLE
);
596 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
597 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
598 wxAlignment align
= wxALIGN_CENTER
,
599 int flags
= wxDATAVIEW_COL_RESIZABLE
);
600 wxDataViewColumn
*AppendDateColumn( const wxString
&label
, unsigned int model_column
,
601 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
602 wxAlignment align
= wxALIGN_NOT
,
603 int flags
= wxDATAVIEW_COL_RESIZABLE
);
604 wxDataViewColumn
*AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
605 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
606 wxAlignment align
= wxALIGN_CENTER
,
607 int flags
= wxDATAVIEW_COL_RESIZABLE
);
608 wxDataViewColumn
*AppendTextColumn( const wxBitmap
&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
*AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
613 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
614 wxAlignment align
= wxALIGN_NOT
,
615 int flags
= wxDATAVIEW_COL_RESIZABLE
);
616 wxDataViewColumn
*AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
617 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
618 wxAlignment align
= wxALIGN_CENTER
,
619 int flags
= wxDATAVIEW_COL_RESIZABLE
);
620 wxDataViewColumn
*AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
621 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
622 wxAlignment align
= wxALIGN_CENTER
,
623 int flags
= wxDATAVIEW_COL_RESIZABLE
);
624 wxDataViewColumn
*AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
625 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
626 wxAlignment align
= wxALIGN_NOT
,
627 int flags
= wxDATAVIEW_COL_RESIZABLE
);
628 wxDataViewColumn
*AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
629 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
630 wxAlignment align
= wxALIGN_CENTER
,
631 int flags
= wxDATAVIEW_COL_RESIZABLE
);
633 virtual bool PrependColumn( wxDataViewColumn
*col
);
634 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
635 virtual bool AppendColumn( wxDataViewColumn
*col
);
637 virtual unsigned int GetColumnCount() const = 0;
638 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const = 0;
639 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const = 0;
641 virtual bool DeleteColumn( wxDataViewColumn
*column
) = 0;
642 virtual bool ClearColumns() = 0;
644 void SetExpanderColumn( wxDataViewColumn
*col
)
645 { m_expander_column
= col
; DoSetExpanderColumn(); }
646 wxDataViewColumn
*GetExpanderColumn() const
647 { return m_expander_column
; }
649 virtual wxDataViewColumn
*GetSortingColumn() const = 0;
655 void SetIndent( int indent
)
656 { m_indent
= indent
; DoSetIndent(); }
657 int GetIndent() const
660 // Current item is the one used by the keyboard navigation, it is the same
661 // as the (unique) selected item in single selection mode so these
662 // functions are mostly useful for controls with wxDV_MULTIPLE style.
663 wxDataViewItem
GetCurrentItem() const;
664 void SetCurrentItem(const wxDataViewItem
& item
);
666 virtual wxDataViewItem
GetSelection() const = 0;
667 virtual int GetSelections( wxDataViewItemArray
& sel
) const = 0;
668 virtual void SetSelections( const wxDataViewItemArray
& sel
) = 0;
669 virtual void Select( const wxDataViewItem
& item
) = 0;
670 virtual void Unselect( const wxDataViewItem
& item
) = 0;
671 virtual bool IsSelected( const wxDataViewItem
& item
) const = 0;
673 virtual void SelectAll() = 0;
674 virtual void UnselectAll() = 0;
676 virtual void Expand( const wxDataViewItem
& item
) = 0;
677 virtual void ExpandAncestors( const wxDataViewItem
& item
);
678 virtual void Collapse( const wxDataViewItem
& item
) = 0;
679 virtual bool IsExpanded( const wxDataViewItem
& item
) const = 0;
681 virtual void EnsureVisible( const wxDataViewItem
& item
,
682 const wxDataViewColumn
*column
= NULL
) = 0;
683 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
&item
, wxDataViewColumn
* &column
) const = 0;
684 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const = 0;
686 virtual bool SetRowHeight( int WXUNUSED(rowHeight
) ) { return false; }
688 virtual void StartEditor( const wxDataViewItem
& WXUNUSED(item
),
689 unsigned int WXUNUSED(column
) )
692 #if wxUSE_DRAG_AND_DROP
693 virtual bool EnableDragSource(const wxDataFormat
& WXUNUSED(format
))
695 virtual bool EnableDropTarget(const wxDataFormat
& WXUNUSED(format
))
697 #endif // wxUSE_DRAG_AND_DROP
699 // define control visual attributes
700 // --------------------------------
702 virtual wxVisualAttributes
GetDefaultAttributes() const
704 return GetClassDefaultAttributes(GetWindowVariant());
707 static wxVisualAttributes
708 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
)
710 return wxControl::GetCompositeControlsDefaultAttributes(variant
);
714 virtual void DoSetExpanderColumn() = 0 ;
715 virtual void DoSetIndent() = 0;
718 // Implementation of the public Set/GetCurrentItem() methods which are only
719 // called in multi selection case (for single selection controls their
720 // implementation is trivial and is done in the base class itself).
721 virtual wxDataViewItem
DoGetCurrentItem() const = 0;
722 virtual void DoSetCurrentItem(const wxDataViewItem
& item
) = 0;
724 wxDataViewModel
*m_model
;
725 wxDataViewColumn
*m_expander_column
;
729 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
732 // ----------------------------------------------------------------------------
733 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
734 // ----------------------------------------------------------------------------
736 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
739 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
740 : wxNotifyEvent(commandType
, winid
),
744 m_value(wxNullVariant
),
749 m_editCancelled(false)
750 #if wxUSE_DRAG_AND_DROP
751 , m_dataObject(NULL
),
757 wxDataViewEvent(const wxDataViewEvent
& event
)
758 : wxNotifyEvent(event
),
759 m_item(event
.m_item
),
761 m_model(event
.m_model
),
762 m_value(event
.m_value
),
763 m_column(event
.m_column
),
765 m_cacheFrom(event
.m_cacheFrom
),
766 m_cacheTo(event
.m_cacheTo
),
767 m_editCancelled(event
.m_editCancelled
)
768 #if wxUSE_DRAG_AND_DROP
769 , m_dataObject(event
.m_dataObject
),
770 m_dataFormat(event
.m_dataFormat
),
771 m_dataBuffer(event
.m_dataBuffer
),
772 m_dataSize(event
.m_dataSize
)
776 wxDataViewItem
GetItem() const { return m_item
; }
777 void SetItem( const wxDataViewItem
&item
) { m_item
= item
; }
779 int GetColumn() const { return m_col
; }
780 void SetColumn( int col
) { m_col
= col
; }
782 wxDataViewModel
* GetModel() const { return m_model
; }
783 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
785 const wxVariant
&GetValue() const { return m_value
; }
786 void SetValue( const wxVariant
&value
) { m_value
= value
; }
788 // for wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE only
789 bool IsEditCancelled() const { return m_editCancelled
; }
790 void SetEditCanceled(bool editCancelled
) { m_editCancelled
= editCancelled
; }
792 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
793 void SetDataViewColumn( wxDataViewColumn
*col
) { m_column
= col
; }
794 wxDataViewColumn
*GetDataViewColumn() const { return m_column
; }
796 // for wxEVT_DATAVIEW_CONTEXT_MENU only
797 wxPoint
GetPosition() const { return m_pos
; }
798 void SetPosition( int x
, int y
) { m_pos
.x
= x
; m_pos
.y
= y
; }
800 // For wxEVT_COMMAND_DATAVIEW_CACHE_HINT
801 int GetCacheFrom() const { return m_cacheFrom
; }
802 int GetCacheTo() const { return m_cacheTo
; }
803 void SetCache(int from
, int to
) { m_cacheFrom
= from
; m_cacheTo
= to
; }
806 #if wxUSE_DRAG_AND_DROP
807 // For drag operations
808 void SetDataObject( wxDataObject
*obj
) { m_dataObject
= obj
; }
809 wxDataObject
*GetDataObject() const { return m_dataObject
; }
811 // For drop operations
812 void SetDataFormat( const wxDataFormat
&format
) { m_dataFormat
= format
; }
813 wxDataFormat
GetDataFormat() const { return m_dataFormat
; }
814 void SetDataSize( size_t size
) { m_dataSize
= size
; }
815 size_t GetDataSize() const { return m_dataSize
; }
816 void SetDataBuffer( void* buf
) { m_dataBuffer
= buf
;}
817 void *GetDataBuffer() const { return m_dataBuffer
; }
818 #endif // wxUSE_DRAG_AND_DROP
820 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
823 wxDataViewItem m_item
;
825 wxDataViewModel
*m_model
;
827 wxDataViewColumn
*m_column
;
831 bool m_editCancelled
;
833 #if wxUSE_DRAG_AND_DROP
834 wxDataObject
*m_dataObject
;
836 wxDataFormat m_dataFormat
;
839 #endif // wxUSE_DRAG_AND_DROP
842 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
845 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
847 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
848 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
849 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
850 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
851 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
852 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
853 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
854 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
855 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
857 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
859 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
860 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
861 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
862 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
864 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
866 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
867 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
868 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
870 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
872 #define wxDataViewEventHandler(func) \
873 wxEVENT_HANDLER_CAST(wxDataViewEventFunction, func)
875 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
876 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
878 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
880 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
881 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
882 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
883 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
884 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
885 #define EVT_DATAVIEW_ITEM_START_EDITING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_START_EDITING, id, fn)
886 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
887 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
888 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
890 #define EVT_DATAVIEW_ITEM_CONTEXT_MENU(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_CONTEXT_MENU, id, fn)
892 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
893 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
894 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
895 #define EVT_DATAVIEW_COLUMN_REORDERED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_REORDERED, id, fn)
896 #define EVT_DATAVIEW_CACHE_HINT(id, fn) wx__DECLARE_DATAVIEWEVT(CACHE_HINT, id, fn)
898 #define EVT_DATAVIEW_ITEM_BEGIN_DRAG(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_BEGIN_DRAG, id, fn)
899 #define EVT_DATAVIEW_ITEM_DROP_POSSIBLE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP_POSSIBLE, id, fn)
900 #define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn)
902 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
903 #include "wx/generic/dataview.h"
904 #elif defined(__WXGTK20__)
905 #include "wx/gtk/dataview.h"
906 #elif defined(__WXMAC__)
907 #include "wx/osx/dataview.h"
909 #error "unknown native wxDataViewCtrl implementation"
912 //-----------------------------------------------------------------------------
913 // wxDataViewListStore
914 //-----------------------------------------------------------------------------
916 class WXDLLIMPEXP_ADV wxDataViewListStoreLine
919 wxDataViewListStoreLine( wxClientData
*data
= NULL
)
923 virtual ~wxDataViewListStoreLine()
928 void SetData( wxClientData
*data
)
929 { if (m_data
) delete m_data
; m_data
= data
; }
930 wxClientData
*GetData() const
933 wxVector
<wxVariant
> m_values
;
936 wxClientData
*m_data
;
940 class WXDLLIMPEXP_ADV wxDataViewListStore
: public wxDataViewIndexListModel
943 wxDataViewListStore();
944 ~wxDataViewListStore();
946 void PrependColumn( const wxString
&varianttype
);
947 void InsertColumn( unsigned int pos
, const wxString
&varianttype
);
948 void AppendColumn( const wxString
&varianttype
);
950 void AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
);
951 void PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
);
952 void InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
);
953 void DeleteItem( unsigned int pos
);
954 void DeleteAllItems();
956 // override base virtuals
958 virtual unsigned int GetColumnCount() const;
960 virtual wxString
GetColumnType( unsigned int col
) const;
962 virtual void GetValueByRow( wxVariant
&value
,
963 unsigned int row
, unsigned int col
) const;
965 virtual bool SetValueByRow( const wxVariant
&value
,
966 unsigned int row
, unsigned int col
);
970 wxVector
<wxDataViewListStoreLine
*> m_data
;
971 wxArrayString m_cols
;
974 //-----------------------------------------------------------------------------
976 class WXDLLIMPEXP_ADV wxDataViewListCtrl
: public wxDataViewCtrl
979 wxDataViewListCtrl();
980 wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
981 const wxPoint
& pos
= wxDefaultPosition
,
982 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_ROW_LINES
,
983 const wxValidator
& validator
= wxDefaultValidator
);
984 ~wxDataViewListCtrl();
986 bool Create( wxWindow
*parent
, wxWindowID id
,
987 const wxPoint
& pos
= wxDefaultPosition
,
988 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_ROW_LINES
,
989 const wxValidator
& validator
= wxDefaultValidator
);
991 wxDataViewListStore
*GetStore()
992 { return (wxDataViewListStore
*) GetModel(); }
993 const wxDataViewListStore
*GetStore() const
994 { return (const wxDataViewListStore
*) GetModel(); }
996 int ItemToRow(const wxDataViewItem
&item
) const
997 { return item
.IsOk() ? (int)GetStore()->GetRow(item
) : wxNOT_FOUND
; }
998 wxDataViewItem
RowToItem(int row
) const
999 { return row
== wxNOT_FOUND
? wxDataViewItem() : GetStore()->GetItem(row
); }
1001 int GetSelectedRow() const
1002 { return ItemToRow(GetSelection()); }
1003 void SelectRow(unsigned row
)
1004 { Select(RowToItem(row
)); }
1005 void UnselectRow(unsigned row
)
1006 { Unselect(RowToItem(row
)); }
1007 bool IsRowSelected(unsigned row
) const
1008 { return IsSelected(RowToItem(row
)); }
1010 bool AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
);
1011 bool PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
);
1012 bool InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
);
1014 // overridden from base class
1015 virtual bool PrependColumn( wxDataViewColumn
*col
);
1016 virtual bool InsertColumn( unsigned int pos
, wxDataViewColumn
*col
);
1017 virtual bool AppendColumn( wxDataViewColumn
*col
);
1019 wxDataViewColumn
*AppendTextColumn( const wxString
&label
,
1020 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
1021 int width
= -1, wxAlignment align
= wxALIGN_LEFT
, int flags
= wxDATAVIEW_COL_RESIZABLE
);
1022 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
,
1023 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
,
1024 int width
= -1, wxAlignment align
= wxALIGN_LEFT
, int flags
= wxDATAVIEW_COL_RESIZABLE
);
1025 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
,
1026 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
1027 int width
= -1, wxAlignment align
= wxALIGN_LEFT
, int flags
= wxDATAVIEW_COL_RESIZABLE
);
1028 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
,
1029 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
1030 int width
= -1, wxAlignment align
= wxALIGN_LEFT
, int flags
= wxDATAVIEW_COL_RESIZABLE
);
1032 void AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
)
1033 { GetStore()->AppendItem( values
, data
); }
1034 void PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
)
1035 { GetStore()->PrependItem( values
, data
); }
1036 void InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
, wxClientData
*data
= NULL
)
1037 { GetStore()->InsertItem( row
, values
, data
); }
1038 void DeleteItem( unsigned row
)
1039 { GetStore()->DeleteItem( row
); }
1040 void DeleteAllItems()
1041 { GetStore()->DeleteAllItems(); }
1043 void SetValue( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1044 { GetStore()->SetValueByRow( value
, row
, col
);
1045 GetStore()->RowValueChanged( row
, col
); }
1046 void GetValue( wxVariant
&value
, unsigned int row
, unsigned int col
)
1047 { GetStore()->GetValueByRow( value
, row
, col
); }
1049 void SetTextValue( const wxString
&value
, unsigned int row
, unsigned int col
)
1050 { GetStore()->SetValueByRow( value
, row
, col
);
1051 GetStore()->RowValueChanged( row
, col
); }
1052 wxString
GetTextValue( unsigned int row
, unsigned int col
) const
1053 { wxVariant value
; GetStore()->GetValueByRow( value
, row
, col
); return value
.GetString(); }
1055 void SetToggleValue( bool value
, unsigned int row
, unsigned int col
)
1056 { GetStore()->SetValueByRow( value
, row
, col
);
1057 GetStore()->RowValueChanged( row
, col
); }
1058 bool GetToggleValue( unsigned int row
, unsigned int col
) const
1059 { wxVariant value
; GetStore()->GetValueByRow( value
, row
, col
); return value
.GetBool(); }
1061 void OnSize( wxSizeEvent
&event
);
1064 DECLARE_EVENT_TABLE()
1065 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl
)
1068 //-----------------------------------------------------------------------------
1069 // wxDataViewTreeStore
1070 //-----------------------------------------------------------------------------
1072 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
1075 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode
*parent
,
1076 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
1077 virtual ~wxDataViewTreeStoreNode();
1079 void SetText( const wxString
&text
)
1081 wxString
GetText() const
1083 void SetIcon( const wxIcon
&icon
)
1085 const wxIcon
&GetIcon() const
1087 void SetData( wxClientData
*data
)
1088 { if (m_data
) delete m_data
; m_data
= data
; }
1089 wxClientData
*GetData() const
1092 wxDataViewItem
GetItem() const
1093 { return wxDataViewItem( (void*) this ); }
1095 virtual bool IsContainer()
1098 wxDataViewTreeStoreNode
*GetParent()
1099 { return m_parent
; }
1102 wxDataViewTreeStoreNode
*m_parent
;
1105 wxClientData
*m_data
;
1108 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode
, wxDataViewTreeStoreNodeList
,
1109 class WXDLLIMPEXP_ADV
);
1111 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode
: public wxDataViewTreeStoreNode
1114 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode
*parent
,
1115 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
1116 wxClientData
*data
= NULL
);
1117 virtual ~wxDataViewTreeStoreContainerNode();
1119 const wxDataViewTreeStoreNodeList
&GetChildren() const
1120 { return m_children
; }
1121 wxDataViewTreeStoreNodeList
&GetChildren()
1122 { return m_children
; }
1124 void SetExpandedIcon( const wxIcon
&icon
)
1125 { m_iconExpanded
= icon
; }
1126 const wxIcon
&GetExpandedIcon() const
1127 { return m_iconExpanded
; }
1129 void SetExpanded( bool expanded
= true )
1130 { m_isExpanded
= expanded
; }
1131 bool IsExpanded() const
1132 { return m_isExpanded
; }
1134 virtual bool IsContainer()
1138 wxDataViewTreeStoreNodeList m_children
;
1139 wxIcon m_iconExpanded
;
1143 //-----------------------------------------------------------------------------
1145 class WXDLLIMPEXP_ADV wxDataViewTreeStore
: public wxDataViewModel
1148 wxDataViewTreeStore();
1149 ~wxDataViewTreeStore();
1151 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
1152 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
1153 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
1154 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
1155 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1156 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
1158 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
1159 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
1160 wxClientData
*data
= NULL
);
1161 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
1162 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
1163 wxClientData
*data
= NULL
);
1164 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1165 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
1166 wxClientData
*data
= NULL
);
1168 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const;
1169 int GetChildCount( const wxDataViewItem
& parent
) const;
1171 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
1172 wxString
GetItemText( const wxDataViewItem
& item
) const;
1173 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
1174 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const;
1175 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
1176 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const;
1177 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
);
1178 wxClientData
*GetItemData( const wxDataViewItem
& item
) const;
1180 void DeleteItem( const wxDataViewItem
& item
);
1181 void DeleteChildren( const wxDataViewItem
& item
);
1182 void DeleteAllItems();
1184 // implement base methods
1186 virtual void GetValue( wxVariant
&variant
,
1187 const wxDataViewItem
&item
, unsigned int col
) const;
1188 virtual bool SetValue( const wxVariant
&variant
,
1189 const wxDataViewItem
&item
, unsigned int col
);
1190 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
1191 virtual bool IsContainer( const wxDataViewItem
&item
) const;
1192 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
1194 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1195 unsigned int column
, bool ascending
) const;
1197 virtual bool HasDefaultCompare() const
1199 virtual unsigned int GetColumnCount() const
1201 virtual wxString
GetColumnType( unsigned int WXUNUSED(col
) ) const
1202 { return wxT("wxDataViewIconText"); }
1204 wxDataViewTreeStoreNode
*FindNode( const wxDataViewItem
&item
) const;
1205 wxDataViewTreeStoreContainerNode
*FindContainerNode( const wxDataViewItem
&item
) const;
1206 wxDataViewTreeStoreNode
*GetRoot() const { return m_root
; }
1209 wxDataViewTreeStoreNode
*m_root
;
1212 //-----------------------------------------------------------------------------
1214 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl
: public wxDataViewCtrl
,
1218 wxDataViewTreeCtrl() { }
1219 wxDataViewTreeCtrl(wxWindow
*parent
,
1221 const wxPoint
& pos
= wxDefaultPosition
,
1222 const wxSize
& size
= wxDefaultSize
,
1223 long style
= wxDV_NO_HEADER
| wxDV_ROW_LINES
,
1224 const wxValidator
& validator
= wxDefaultValidator
)
1226 Create(parent
, id
, pos
, size
, style
, validator
);
1229 bool Create(wxWindow
*parent
,
1231 const wxPoint
& pos
= wxDefaultPosition
,
1232 const wxSize
& size
= wxDefaultSize
,
1233 long style
= wxDV_NO_HEADER
| wxDV_ROW_LINES
,
1234 const wxValidator
& validator
= wxDefaultValidator
);
1236 wxDataViewTreeStore
*GetStore()
1237 { return (wxDataViewTreeStore
*) GetModel(); }
1238 const wxDataViewTreeStore
*GetStore() const
1239 { return (const wxDataViewTreeStore
*) GetModel(); }
1241 bool IsContainer( const wxDataViewItem
& item
) const
1242 { return GetStore()->IsContainer(item
); }
1244 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
1245 const wxString
&text
, int icon
= NO_IMAGE
, wxClientData
*data
= NULL
);
1246 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
1247 const wxString
&text
, int icon
= NO_IMAGE
, wxClientData
*data
= NULL
);
1248 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1249 const wxString
&text
, int icon
= NO_IMAGE
, wxClientData
*data
= NULL
);
1251 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
1252 const wxString
&text
, int icon
= NO_IMAGE
, int expanded
= NO_IMAGE
,
1253 wxClientData
*data
= NULL
);
1254 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
1255 const wxString
&text
, int icon
= NO_IMAGE
, int expanded
= NO_IMAGE
,
1256 wxClientData
*data
= NULL
);
1257 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1258 const wxString
&text
, int icon
= NO_IMAGE
, int expanded
= NO_IMAGE
,
1259 wxClientData
*data
= NULL
);
1261 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1262 { return GetStore()->GetNthChild(parent
, pos
); }
1263 int GetChildCount( const wxDataViewItem
& parent
) const
1264 { return GetStore()->GetChildCount(parent
); }
1266 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
1267 wxString
GetItemText( const wxDataViewItem
& item
) const
1268 { return GetStore()->GetItemText(item
); }
1269 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
1270 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const
1271 { return GetStore()->GetItemIcon(item
); }
1272 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
1273 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const
1274 { return GetStore()->GetItemExpandedIcon(item
); }
1275 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1276 { GetStore()->SetItemData(item
,data
); }
1277 wxClientData
*GetItemData( const wxDataViewItem
& item
) const
1278 { return GetStore()->GetItemData(item
); }
1280 void DeleteItem( const wxDataViewItem
& item
);
1281 void DeleteChildren( const wxDataViewItem
& item
);
1282 void DeleteAllItems();
1284 void OnExpanded( wxDataViewEvent
&event
);
1285 void OnCollapsed( wxDataViewEvent
&event
);
1286 void OnSize( wxSizeEvent
&event
);
1289 DECLARE_EVENT_TABLE()
1290 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl
)
1293 #endif // wxUSE_DATAVIEWCTRL
1296 // _WX_DATAVIEW_H_BASE_