1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/datavcmn.cpp
3 // Purpose: wxDataViewCtrl base classes and common parts
4 // Author: Robert Roebling
7 // Copyright: (c) 2006, Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
21 #include "wx/spinctrl.h"
23 #include "wx/weakref.h"
27 #include "wx/settings.h"
33 const wxChar wxDataViewCtrlNameStr
[] = wxT("dataviewCtrl");
36 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
)
38 return (left
.GetID() == right
.GetID() );
42 void wxDataViewItem::Print(const wxString
& text
) const
44 wxPrintf(wxT("item %s: %l\n"), text
.GetData(), (long)m_id
);
48 // ---------------------------------------------------------
49 // wxDataViewModelNotifier
50 // ---------------------------------------------------------
52 #include "wx/listimpl.cpp"
53 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
55 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
57 size_t count
= items
.GetCount();
59 for (i
= 0; i
< count
; i
++)
60 if (!ItemAdded( parent
, items
[i
] )) return false;
65 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
67 size_t count
= items
.GetCount();
69 for (i
= 0; i
< count
; i
++)
70 if (!ItemDeleted( parent
, items
[i
] )) return false;
75 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
77 size_t count
= items
.GetCount();
79 for (i
= 0; i
< count
; i
++)
80 if (!ItemChanged( items
[i
] )) return false;
85 // ---------------------------------------------------------
87 // ---------------------------------------------------------
89 wxDataViewModel::wxDataViewModel()
91 m_notifiers
.DeleteContents( true );
94 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
98 wxDataViewModelNotifiers::iterator iter
;
99 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
101 wxDataViewModelNotifier
* notifier
= *iter
;
102 if (!notifier
->ItemAdded( parent
, item
))
109 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
113 wxDataViewModelNotifiers::iterator iter
;
114 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
116 wxDataViewModelNotifier
* notifier
= *iter
;
117 if (!notifier
->ItemDeleted( parent
, item
))
124 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
128 wxDataViewModelNotifiers::iterator iter
;
129 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
131 wxDataViewModelNotifier
* notifier
= *iter
;
132 if (!notifier
->ItemChanged( item
))
139 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
143 wxDataViewModelNotifiers::iterator iter
;
144 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
146 wxDataViewModelNotifier
* notifier
= *iter
;
147 if (!notifier
->ItemsAdded( parent
, items
))
154 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
158 wxDataViewModelNotifiers::iterator iter
;
159 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
161 wxDataViewModelNotifier
* notifier
= *iter
;
162 if (!notifier
->ItemsDeleted( parent
, items
))
169 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
173 wxDataViewModelNotifiers::iterator iter
;
174 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
176 wxDataViewModelNotifier
* notifier
= *iter
;
177 if (!notifier
->ItemsChanged( items
))
184 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
188 wxDataViewModelNotifiers::iterator iter
;
189 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
191 wxDataViewModelNotifier
* notifier
= *iter
;
192 if (!notifier
->ValueChanged( item
, col
))
199 bool wxDataViewModel::Cleared()
203 wxDataViewModelNotifiers::iterator iter
;
204 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
206 wxDataViewModelNotifier
* notifier
= *iter
;
207 if (!notifier
->Cleared())
214 void wxDataViewModel::Resort()
216 wxDataViewModelNotifiers::iterator iter
;
217 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
219 wxDataViewModelNotifier
* notifier
= *iter
;
224 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
226 m_notifiers
.push_back( notifier
);
227 notifier
->SetOwner( this );
230 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
232 m_notifiers
.DeleteObject( notifier
);
235 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
236 unsigned int column
, bool ascending
)
238 // sort branches before leaves
239 bool item1_is_container
= IsContainer(item1
);
240 bool item2_is_container
= IsContainer(item2
);
242 if (item1_is_container
&& !item2_is_container
)
244 if (item2_is_container
&& !item1_is_container
)
247 wxVariant value1
,value2
;
248 GetValue( value1
, item1
, column
);
249 GetValue( value2
, item2
, column
);
253 wxVariant temp
= value1
;
258 if (value1
.GetType() == wxT("string"))
260 wxString str1
= value1
.GetString();
261 wxString str2
= value2
.GetString();
262 int res
= str1
.Cmp( str2
);
265 if (value1
.GetType() == wxT("long"))
267 long l1
= value1
.GetLong();
268 long l2
= value2
.GetLong();
272 if (value1
.GetType() == wxT("double"))
274 double d1
= value1
.GetDouble();
275 double d2
= value2
.GetDouble();
276 if (d1
< d2
) return 1;
277 if (d1
> d2
) return -1;
279 if (value1
.GetType() == wxT("datetime"))
281 wxDateTime dt1
= value1
.GetDateTime();
282 wxDateTime dt2
= value2
.GetDateTime();
283 if (dt1
.IsEarlierThan(dt2
)) return 1;
284 if (dt2
.IsEarlierThan(dt1
)) return -11;
287 // items must be different
288 unsigned long litem1
= (unsigned long) item1
.GetID();
289 unsigned long litem2
= (unsigned long) item2
.GetID();
292 return litem2
-litem2
;
294 return litem1
-litem2
;
297 // ---------------------------------------------------------
298 // wxDataViewIndexListModel
299 // ---------------------------------------------------------
301 static int my_sort( int *v1
, int *v2
)
307 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
309 // IDs are ordered until an item gets deleted or inserted
312 // build initial index
314 for (i
= 1; i
< initial_size
+1; i
++)
315 m_hash
.Add( (void*) i
);
316 m_lastIndex
= initial_size
+ 1;
319 wxDataViewIndexListModel::~wxDataViewIndexListModel()
323 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
327 // IDs are ordered until an item gets deleted or inserted
330 // build initial index
332 for (i
= 1; i
< new_size
+1; i
++)
333 m_hash
.Add( (void*) i
);
334 m_lastIndex
= new_size
+ 1;
336 wxDataViewModel::Cleared();
339 void wxDataViewIndexListModel::RowPrepended()
343 unsigned int id
= m_lastIndex
++;
344 m_hash
.Insert( (void*) id
, 0 );
345 wxDataViewItem
item( (void*) id
);
346 ItemAdded( wxDataViewItem(0), item
);
349 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
353 unsigned int id
= m_lastIndex
++;
354 m_hash
.Insert( (void*) id
, before
);
355 wxDataViewItem
item( (void*) id
);
356 ItemAdded( wxDataViewItem(0), item
);
359 void wxDataViewIndexListModel::RowAppended()
361 unsigned int id
= m_lastIndex
++;
362 m_hash
.Add( (void*) id
);
363 wxDataViewItem
item( (void*) id
);
364 ItemAdded( wxDataViewItem(0), item
);
367 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
371 wxDataViewItem
item( m_hash
[row
] );
372 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
373 m_hash
.RemoveAt( row
);
376 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
378 wxArrayInt sorted
= rows
;
379 sorted
.Sort( my_sort
);
383 wxDataViewItemArray array
;
385 for (i
= 0; i
< rows
.GetCount(); i
++)
387 wxDataViewItem
item( m_hash
[rows
[i
]] );
390 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
392 for (i
= 0; i
< sorted
.GetCount(); i
++)
393 m_hash
.RemoveAt( sorted
[i
] );
396 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
398 wxDataViewModel::ItemChanged( GetItem(row
) );
401 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
403 wxDataViewModel::ValueChanged( GetItem(row
), col
);
406 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
410 unsigned int pos
= wxPtrToUInt( item
.GetID() );
414 // assert for not found
415 return (unsigned int) m_hash
.Index( item
.GetID() );
418 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
420 wxASSERT( row
< m_hash
.GetCount() );
421 return wxDataViewItem( m_hash
[row
] );
424 bool wxDataViewIndexListModel::HasDefaultCompare() const
429 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
430 const wxDataViewItem
& item2
,
431 unsigned int WXUNUSED(column
),
436 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
437 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
446 return GetRow(item1
) - GetRow(item2
);
448 return GetRow(item2
) - GetRow(item1
);
451 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
452 const wxDataViewItem
&item
, unsigned int col
) const
454 GetValue( variant
, GetRow(item
), col
);
457 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
458 const wxDataViewItem
&item
, unsigned int col
)
460 return SetValue( variant
, GetRow(item
), col
);
463 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
465 return GetAttr( GetRow(item
), col
, attr
);
468 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
470 return wxDataViewItem(0);
473 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
475 // only the invisible root item has children
482 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
489 return m_hash
.GetCount();
492 // ---------------------------------------------------------
493 // wxDataViewVirtualListModel
494 // ---------------------------------------------------------
498 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
500 m_lastIndex
= initial_size
-1;
503 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
507 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
509 m_lastIndex
= new_size
-1;
511 wxDataViewModel::Cleared();
514 void wxDataViewVirtualListModel::RowPrepended()
517 wxDataViewItem
item( (void*) 0 );
518 ItemAdded( wxDataViewItem(0), item
);
521 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
524 wxDataViewItem
item( (void*) before
);
525 ItemAdded( wxDataViewItem(0), item
);
528 void wxDataViewVirtualListModel::RowAppended()
531 wxDataViewItem
item( (void*) m_lastIndex
);
532 ItemAdded( wxDataViewItem(0), item
);
535 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
537 wxDataViewItem
item( (void*) row
);
538 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
542 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
544 wxArrayInt sorted
= rows
;
545 sorted
.Sort( my_sort
);
547 wxDataViewItemArray array
;
549 for (i
= 0; i
< sorted
.GetCount(); i
++)
551 wxDataViewItem
item( (void*) sorted
[i
] );
554 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
556 m_lastIndex
-= rows
.GetCount();
559 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
561 wxDataViewModel::ItemChanged( GetItem(row
) );
564 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
566 wxDataViewModel::ValueChanged( GetItem(row
), col
);
569 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
571 return wxPtrToUInt( item
.GetID() );
574 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
576 return wxDataViewItem( (void*) row
);
579 bool wxDataViewVirtualListModel::HasDefaultCompare() const
584 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
585 const wxDataViewItem
& item2
,
586 unsigned int WXUNUSED(column
),
589 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
590 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
598 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
599 const wxDataViewItem
&item
, unsigned int col
) const
601 GetValue( variant
, GetRow(item
), col
);
604 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
605 const wxDataViewItem
&item
, unsigned int col
)
607 return SetValue( variant
, GetRow(item
), col
);
610 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
612 return GetAttr( GetRow(item
), col
, attr
);
615 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
617 return wxDataViewItem(0);
620 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
622 // only the invisible root item has children
629 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
631 return 0; // should we report an error ?
636 //-----------------------------------------------------------------------------
637 // wxDataViewIconText
638 //-----------------------------------------------------------------------------
640 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
642 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
644 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
646 if (one
.GetText() != two
.GetText()) return false;
647 if (one
.IsSameAs(two
)) return false;
651 // ---------------------------------------------------------
652 // wxDataViewRendererBase
653 // ---------------------------------------------------------
655 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
657 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
658 wxDataViewCellMode
WXUNUSED(mode
),
659 int WXUNUSED(align
) )
661 m_variantType
= varianttype
;
665 wxDataViewRendererBase::~wxDataViewRendererBase()
669 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
671 return wx_const_cast(wxDataViewRendererBase
*, this)->GetOwner()->GetOwner();
674 class wxKillRef
: public wxWindowRef
677 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
678 virtual void OnObjectDestroy()
680 get()->PopEventHandler( true );
685 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
687 m_item
= item
; // remember for later
689 unsigned int col
= GetOwner()->GetModelColumn();
691 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
693 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
694 (void) new wxKillRef( m_editorCtrl
.get() );
696 wxDataViewEditorCtrlEvtHandler
*handler
=
697 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
699 m_editorCtrl
->PushEventHandler( handler
);
701 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
702 handler
->SetFocusOnIdle();
704 m_editorCtrl
->SetFocus();
707 // Now we should send Editing Started event
708 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
709 event
.SetDataViewColumn( GetOwner() );
710 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
711 event
.SetItem( item
);
712 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
717 void wxDataViewRendererBase::CancelEditing()
719 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
721 m_editorCtrl
->Hide();
722 wxPendingDelete
.Append( m_editorCtrl
);
725 bool wxDataViewRendererBase::FinishEditing()
728 GetValueFromEditorCtrl( m_editorCtrl
, value
);
730 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
732 m_editorCtrl
->Hide();
733 wxPendingDelete
.Append( m_editorCtrl
);
735 if (!Validate(value
))
738 unsigned int col
= GetOwner()->GetModelColumn();
739 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
740 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
742 // Now we should send Editing Done event
743 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
744 event
.SetDataViewColumn( GetOwner() );
745 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
746 event
.SetItem( m_item
);
747 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
752 //-----------------------------------------------------------------------------
753 // wxDataViewEditorCtrlEvtHandler
754 //-----------------------------------------------------------------------------
756 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
757 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
758 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
759 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
762 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
763 wxControl
*editorCtrl
,
764 wxDataViewRenderer
*owner
)
767 m_editorCtrl
= editorCtrl
;
772 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
776 m_focusOnIdle
= false;
777 if (wxWindow::FindFocus() != m_editorCtrl
)
778 m_editorCtrl
->SetFocus();
784 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
786 switch ( event
.m_keyCode
)
790 m_owner
->FinishEditing();
795 m_owner
->CancelEditing();
803 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
808 m_owner
->FinishEditing();
814 // ---------------------------------------------------------
815 // wxDataViewColumnBase
816 // ---------------------------------------------------------
818 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
820 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
821 wxDataViewRenderer
*renderer
,
822 unsigned int model_column
,
824 wxAlignment
WXUNUSED(align
),
827 m_renderer
= renderer
;
828 m_model_column
= model_column
;
830 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
832 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
833 // parameters inside the native control!
836 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
837 wxDataViewRenderer
*renderer
,
838 unsigned int model_column
,
840 wxAlignment
WXUNUSED(align
),
841 int WXUNUSED(flags
) )
843 m_renderer
= renderer
;
844 m_model_column
= model_column
;
847 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
850 wxDataViewColumnBase::~wxDataViewColumnBase()
856 int wxDataViewColumnBase::GetFlags() const
861 ret
|= wxDATAVIEW_COL_SORTABLE
;
863 ret
|= wxDATAVIEW_COL_RESIZABLE
;
865 ret
|= wxDATAVIEW_COL_HIDDEN
;
870 void wxDataViewColumnBase::SetFlags(int flags
)
872 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
873 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
874 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
875 SetReorderable((flags
& wxDATAVIEW_COL_REORDERABLE
) != 0);
878 // ---------------------------------------------------------
879 // wxDataViewCtrlBase
880 // ---------------------------------------------------------
882 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
884 wxDataViewCtrlBase::wxDataViewCtrlBase()
887 m_expander_column
= 0;
891 wxDataViewCtrlBase::~wxDataViewCtrlBase()
900 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
904 m_model
->DecRef(); // discard old model, if any
907 // add our own reference to the new model:
917 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
922 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
928 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
929 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
931 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
932 new wxDataViewTextRenderer( wxT("string"), mode
),
933 model_column
, width
, align
, flags
);
939 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
940 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
942 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
943 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
944 model_column
, width
, align
, flags
);
950 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
951 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
954 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
955 new wxDataViewToggleRenderer( wxT("bool"), mode
),
956 model_column
, width
, align
, flags
);
962 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
963 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
965 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
966 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
967 model_column
, width
, align
, flags
);
973 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
974 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
976 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
977 new wxDataViewDateRenderer( wxT("datetime"), mode
),
978 model_column
, width
, align
, flags
);
984 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
985 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
987 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
988 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
989 model_column
, width
, align
, flags
);
995 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
996 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
998 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
999 new wxDataViewTextRenderer( wxT("string"), mode
),
1000 model_column
, width
, align
, flags
);
1001 AppendColumn( ret
);
1006 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1007 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1009 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1010 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1011 model_column
, width
, align
, flags
);
1012 AppendColumn( ret
);
1017 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1018 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1020 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1021 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1022 model_column
, width
, align
, flags
);
1023 AppendColumn( ret
);
1028 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1029 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1031 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1032 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1033 model_column
, width
, align
, flags
);
1034 AppendColumn( ret
);
1039 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1040 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1042 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1043 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1044 model_column
, width
, align
, flags
);
1045 AppendColumn( ret
);
1050 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1051 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1053 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1054 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1055 model_column
, width
, align
, flags
);
1056 AppendColumn( ret
);
1061 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1062 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1064 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1065 new wxDataViewTextRenderer( wxT("string"), mode
),
1066 model_column
, width
, align
, flags
);
1067 PrependColumn( ret
);
1072 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1073 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1075 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1076 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1077 model_column
, width
, align
, flags
);
1078 PrependColumn( ret
);
1083 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1084 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1087 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1088 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1089 model_column
, width
, align
, flags
);
1090 PrependColumn( ret
);
1095 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1096 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1098 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1099 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1100 model_column
, width
, align
, flags
);
1101 PrependColumn( ret
);
1106 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1107 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1109 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1110 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1111 model_column
, width
, align
, flags
);
1112 PrependColumn( ret
);
1117 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1118 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1120 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1121 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1122 model_column
, width
, align
, flags
);
1123 PrependColumn( ret
);
1128 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1129 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1131 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1132 new wxDataViewTextRenderer( wxT("string"), mode
),
1133 model_column
, width
, align
, flags
);
1134 PrependColumn( ret
);
1139 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1140 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1142 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1143 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1144 model_column
, width
, align
, flags
);
1145 PrependColumn( ret
);
1150 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1151 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1153 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1154 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1155 model_column
, width
, align
, flags
);
1156 PrependColumn( ret
);
1161 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1162 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1164 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1165 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1166 model_column
, width
, align
, flags
);
1167 PrependColumn( ret
);
1172 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1173 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1175 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1176 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1177 model_column
, width
, align
, flags
);
1178 PrependColumn( ret
);
1183 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1184 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1186 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1187 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1188 model_column
, width
, align
, flags
);
1189 PrependColumn( ret
);
1194 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1196 col
->SetOwner( (wxDataViewCtrl
*) this );
1201 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1203 col
->SetOwner( (wxDataViewCtrl
*) this );
1207 // ---------------------------------------------------------
1209 // ---------------------------------------------------------
1211 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1213 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1215 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1216 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1217 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1218 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1219 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1220 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1221 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1222 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1224 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
)
1226 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1227 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1228 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1229 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
)
1232 // -------------------------------------
1233 // wxDataViewSpinRenderer
1234 // -------------------------------------
1236 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1237 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1243 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1246 wxSize size
= labelRect
.GetSize();
1248 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1251 str
.Printf( wxT("%d"), (int) l
);
1252 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1253 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
, m_min
, m_max
, l
);
1255 size
= sc
->GetSize();
1256 wxPoint pt
= sc
->GetPosition();
1257 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1263 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1265 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1266 long l
= sc
->GetValue();
1271 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1274 str
.Printf(wxT("%d"), (int) m_data
);
1275 RenderText( str
, 0, rect
, dc
, state
);
1279 wxSize
wxDataViewSpinRenderer::GetSize() const
1281 return wxSize(80,16);
1284 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1286 m_data
= value
.GetLong();
1290 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1296 //-----------------------------------------------------------------------------
1297 // wxDataViewTreeStore
1298 //-----------------------------------------------------------------------------
1300 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1301 wxDataViewTreeStoreNode
*parent
,
1302 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1310 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1316 #include "wx/listimpl.cpp"
1317 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1319 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1320 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1321 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1322 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1324 m_iconExpanded
= expanded
;
1325 m_isExpanded
= false;
1326 m_children
.DeleteContents(true);
1329 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1333 //-----------------------------------------------------------------------------
1335 wxDataViewTreeStore::wxDataViewTreeStore()
1337 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1340 wxDataViewTreeStore::~wxDataViewTreeStore()
1345 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1346 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1348 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1349 if (!parent_node
) return wxDataViewItem(0);
1351 wxDataViewTreeStoreNode
*node
=
1352 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1353 parent_node
->GetChildren().Append( node
);
1356 ItemAdded( parent
, node
->GetItem() );
1358 return node
->GetItem();
1361 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1362 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1364 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1365 if (!parent_node
) return wxDataViewItem(0);
1367 wxDataViewTreeStoreNode
*node
=
1368 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1369 parent_node
->GetChildren().Insert( node
);
1372 ItemAdded( parent
, node
->GetItem() );
1374 return node
->GetItem();
1378 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1379 const wxDataViewItem
& WXUNUSED(previous
),
1380 const wxString
& WXUNUSED(text
),
1381 const wxIcon
& WXUNUSED(icon
),
1382 wxClientData
* WXUNUSED(data
))
1384 return wxDataViewItem(0);
1387 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1388 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1389 wxClientData
*data
)
1391 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1392 if (!parent_node
) return wxDataViewItem(0);
1394 wxDataViewTreeStoreContainerNode
*node
=
1395 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1396 parent_node
->GetChildren().Insert( node
);
1399 ItemAdded( parent
, node
->GetItem() );
1401 return node
->GetItem();
1405 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1406 const wxString
&text
,
1408 const wxIcon
& expanded
,
1409 wxClientData
* data
)
1411 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1412 if (!parent_node
) return wxDataViewItem(0);
1414 wxDataViewTreeStoreContainerNode
*node
=
1415 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1416 parent_node
->GetChildren().Append( node
);
1419 ItemAdded( parent
, node
->GetItem() );
1421 return node
->GetItem();
1425 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1426 const wxDataViewItem
& WXUNUSED(previous
),
1427 const wxString
& WXUNUSED(text
),
1428 const wxIcon
& WXUNUSED(icon
),
1429 const wxIcon
& WXUNUSED(expanded
),
1430 wxClientData
* WXUNUSED(data
))
1432 return wxDataViewItem(0);
1435 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1437 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1438 if (!parent_node
) return wxDataViewItem(0);
1440 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1442 return node
->GetData();
1444 return wxDataViewItem(0);
1447 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1449 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1450 if (!node
) return -1;
1452 if (!node
->IsContainer())
1455 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1456 return (int) container_node
->GetChildren().GetCount();
1459 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1461 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1464 node
->SetText( text
);
1467 ValueChanged( item
, 0 );
1470 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1472 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1473 if (!node
) return wxEmptyString
;
1475 return node
->GetText();
1478 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1480 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1483 node
->SetIcon( icon
);
1486 ValueChanged( item
, 0 );
1489 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1491 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1492 if (!node
) return wxNullIcon
;
1494 return node
->GetIcon();
1497 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1499 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1502 node
->SetExpandedIcon( icon
);
1505 ValueChanged( item
, 0 );
1508 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1510 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1511 if (!node
) return wxNullIcon
;
1513 return node
->GetExpandedIcon();
1516 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1518 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1521 node
->SetData( data
);
1523 // notify control? only sensible when sorting on client data
1524 // ValueChanged( item, 0 );
1527 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1529 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1530 if (!node
) return NULL
;
1532 return node
->GetData();
1535 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1537 if (!item
.IsOk()) return;
1539 wxDataViewItem parent_item
= GetParent( item
);
1541 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1542 if (!parent_node
) return;
1544 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1547 parent_node
->GetChildren().DeleteObject( node
);
1550 ItemDeleted( parent_item
, item
);
1553 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1555 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1558 wxDataViewItemArray array
;
1559 wxDataViewTreeStoreNodeList::iterator iter
;
1560 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1562 wxDataViewTreeStoreNode
* child
= *iter
;
1563 array
.Add( child
->GetItem() );
1566 node
->GetChildren().clear();
1569 ItemsDeleted( item
, array
);
1572 void wxDataViewTreeStore::DeleteAllItems()
1578 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1579 const wxDataViewItem
&item
,
1580 unsigned int WXUNUSED(col
)) const
1582 // if (col != 0) return;
1584 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1587 wxIcon
icon( node
->GetIcon());
1588 if (node
->IsContainer())
1590 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1591 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1592 icon
= container
->GetExpandedIcon();
1595 wxDataViewIconText
data( node
->GetText(), icon
);
1601 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1602 const wxDataViewItem
& item
,
1603 unsigned int WXUNUSED(col
))
1605 // if (col != 0) return false;
1607 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1608 if (!node
) return false;
1610 wxDataViewIconText data
;
1614 node
->SetText( data
.GetText() );
1615 node
->SetIcon( data
.GetIcon() );
1620 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1622 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1623 if (!node
) return wxDataViewItem(0);
1625 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1626 if (!parent
) return wxDataViewItem(0);
1628 if (parent
== m_root
)
1629 return wxDataViewItem(0);
1631 return parent
->GetItem();
1634 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1636 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1637 if (!node
) return false;
1639 return node
->IsContainer();
1642 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1644 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1645 if (!node
) return 0;
1647 wxDataViewTreeStoreNodeList::iterator iter
;
1648 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1650 wxDataViewTreeStoreNode
* child
= *iter
;
1651 children
.Add( child
->GetItem() );
1654 return node
->GetChildren().GetCount();
1657 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1658 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1660 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1661 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1663 if (!node1
|| !node2
)
1666 wxDataViewTreeStoreContainerNode
* parent1
=
1667 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1668 wxDataViewTreeStoreContainerNode
* parent2
=
1669 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1671 if (parent1
!= parent2
)
1673 wxLogError( wxT("Comparing items with different parent.") );
1677 if (node1
->IsContainer() && !!node2
->IsContainer())
1680 if (node2
->IsContainer() && !!node1
->IsContainer())
1683 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1686 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1691 return (wxDataViewTreeStoreNode
*) item
.GetID();
1694 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1697 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1699 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1701 if (!node
->IsContainer())
1704 return (wxDataViewTreeStoreContainerNode
*) node
;
1707 //-----------------------------------------------------------------------------
1708 // wxDataViewTreeCtrl
1709 //-----------------------------------------------------------------------------
1711 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1713 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1714 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1715 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1716 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1719 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1724 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1725 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1728 Create( parent
, id
, pos
, size
, style
, validator
);
1730 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1731 AssociateModel( store
);
1734 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
1737 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1743 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1744 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1746 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1749 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1754 m_imageList
= imagelist
;
1757 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1758 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1760 wxIcon icon
= wxNullIcon
;
1761 if (m_imageList
&& (iconIndex
!= -1))
1762 icon
= m_imageList
->GetIcon( iconIndex
);
1764 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1767 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1768 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1770 wxIcon icon
= wxNullIcon
;
1771 if (m_imageList
&& (iconIndex
!= -1))
1772 icon
= m_imageList
->GetIcon( iconIndex
);
1774 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1777 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1778 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1780 wxIcon icon
= wxNullIcon
;
1781 if (m_imageList
&& (iconIndex
!= -1))
1782 icon
= m_imageList
->GetIcon( iconIndex
);
1784 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1787 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1788 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1790 wxIcon icon
= wxNullIcon
;
1791 if (m_imageList
&& (iconIndex
!= -1))
1792 icon
= m_imageList
->GetIcon( iconIndex
);
1794 wxIcon expanded
= wxNullIcon
;
1795 if (m_imageList
&& (expandedIndex
!= -1))
1796 expanded
= m_imageList
->GetIcon( expandedIndex
);
1798 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1801 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1802 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1804 wxIcon icon
= wxNullIcon
;
1805 if (m_imageList
&& (iconIndex
!= -1))
1806 icon
= m_imageList
->GetIcon( iconIndex
);
1808 wxIcon expanded
= wxNullIcon
;
1809 if (m_imageList
&& (expandedIndex
!= -1))
1810 expanded
= m_imageList
->GetIcon( expandedIndex
);
1812 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1815 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1816 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1818 wxIcon icon
= wxNullIcon
;
1819 if (m_imageList
&& (iconIndex
!= -1))
1820 icon
= m_imageList
->GetIcon( iconIndex
);
1822 wxIcon expanded
= wxNullIcon
;
1823 if (m_imageList
&& (expandedIndex
!= -1))
1824 expanded
= m_imageList
->GetIcon( expandedIndex
);
1826 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1829 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1831 if (m_imageList
) return;
1833 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1834 if (!container
) return;
1836 container
->SetExpanded( true );
1837 GetStore()->ItemChanged( event
.GetItem() );
1840 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1842 if (m_imageList
) return;
1844 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1845 if (!container
) return;
1847 container
->SetExpanded( false );
1848 GetStore()->ItemChanged( event
.GetItem() );
1851 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
1853 #if defined(wxUSE_GENERICDATAVIEWCTRL)
1854 wxSize size
= GetClientSize();
1855 wxDataViewColumn
*col
= GetColumn( 0 );
1857 col
->SetWidth( size
.x
);
1862 #endif // wxUSE_DATAVIEWCTRL