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 );
686 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
688 m_item
= item
; // remember for later
690 unsigned int col
= GetOwner()->GetModelColumn();
692 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
694 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
695 (void) new wxKillRef( m_editorCtrl
.get() );
697 wxDataViewEditorCtrlEvtHandler
*handler
=
698 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
700 m_editorCtrl
->PushEventHandler( handler
);
702 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
703 handler
->SetFocusOnIdle();
705 m_editorCtrl
->SetFocus();
708 // Now we should send Editing Started event
709 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
710 event
.SetDataViewColumn( GetOwner() );
711 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
712 event
.SetItem( item
);
713 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
718 void wxDataViewRendererBase::CancelEditing()
720 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
722 m_editorCtrl
->Hide();
723 wxPendingDelete
.Append( m_editorCtrl
);
726 bool wxDataViewRendererBase::FinishEditing()
729 GetValueFromEditorCtrl( m_editorCtrl
, value
);
731 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
733 m_editorCtrl
->Hide();
734 wxPendingDelete
.Append( m_editorCtrl
);
736 if (!Validate(value
))
739 unsigned int col
= GetOwner()->GetModelColumn();
740 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
741 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
743 // Now we should send Editing Done event
744 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
745 event
.SetDataViewColumn( GetOwner() );
746 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
747 event
.SetItem( m_item
);
748 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
753 //-----------------------------------------------------------------------------
754 // wxDataViewEditorCtrlEvtHandler
755 //-----------------------------------------------------------------------------
757 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
758 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
759 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
760 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
763 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
764 wxControl
*editorCtrl
,
765 wxDataViewRenderer
*owner
)
768 m_editorCtrl
= editorCtrl
;
773 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
777 m_focusOnIdle
= false;
778 if (wxWindow::FindFocus() != m_editorCtrl
)
779 m_editorCtrl
->SetFocus();
785 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
787 switch ( event
.m_keyCode
)
791 m_owner
->FinishEditing();
796 m_owner
->CancelEditing();
804 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
809 m_owner
->FinishEditing();
815 // ---------------------------------------------------------
816 // wxDataViewColumnBase
817 // ---------------------------------------------------------
819 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
821 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
822 wxDataViewRenderer
*renderer
,
823 unsigned int model_column
,
825 wxAlignment
WXUNUSED(align
),
828 m_renderer
= renderer
;
829 m_model_column
= model_column
;
831 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
833 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
834 // parameters inside the native control!
837 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
838 wxDataViewRenderer
*renderer
,
839 unsigned int model_column
,
841 wxAlignment
WXUNUSED(align
),
842 int WXUNUSED(flags
) )
844 m_renderer
= renderer
;
845 m_model_column
= model_column
;
848 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
851 wxDataViewColumnBase::~wxDataViewColumnBase()
857 int wxDataViewColumnBase::GetFlags() const
862 ret
|= wxDATAVIEW_COL_SORTABLE
;
864 ret
|= wxDATAVIEW_COL_RESIZABLE
;
866 ret
|= wxDATAVIEW_COL_HIDDEN
;
871 void wxDataViewColumnBase::SetFlags(int flags
)
873 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
874 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
875 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
876 SetReorderable((flags
& wxDATAVIEW_COL_REORDERABLE
) != 0);
879 // ---------------------------------------------------------
880 // wxDataViewCtrlBase
881 // ---------------------------------------------------------
883 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
885 wxDataViewCtrlBase::wxDataViewCtrlBase()
888 m_expander_column
= 0;
892 wxDataViewCtrlBase::~wxDataViewCtrlBase()
901 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
905 m_model
->DecRef(); // discard old model, if any
908 // add our own reference to the new model:
918 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
923 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
929 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
930 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
932 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
933 new wxDataViewTextRenderer( wxT("string"), mode
),
934 model_column
, width
, align
, flags
);
940 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
941 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
943 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
944 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
945 model_column
, width
, align
, flags
);
951 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
952 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
955 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
956 new wxDataViewToggleRenderer( wxT("bool"), mode
),
957 model_column
, width
, align
, flags
);
963 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
964 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
966 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
967 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
968 model_column
, width
, align
, flags
);
974 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
975 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
977 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
978 new wxDataViewDateRenderer( wxT("datetime"), mode
),
979 model_column
, width
, align
, flags
);
985 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
986 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
988 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
989 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
990 model_column
, width
, align
, flags
);
996 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
997 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
999 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1000 new wxDataViewTextRenderer( wxT("string"), mode
),
1001 model_column
, width
, align
, flags
);
1002 AppendColumn( ret
);
1007 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1008 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1010 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1011 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1012 model_column
, width
, align
, flags
);
1013 AppendColumn( ret
);
1018 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1019 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1021 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1022 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1023 model_column
, width
, align
, flags
);
1024 AppendColumn( ret
);
1029 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1030 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1032 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1033 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1034 model_column
, width
, align
, flags
);
1035 AppendColumn( ret
);
1040 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1041 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1043 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1044 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1045 model_column
, width
, align
, flags
);
1046 AppendColumn( ret
);
1051 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1052 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1054 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1055 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1056 model_column
, width
, align
, flags
);
1057 AppendColumn( ret
);
1062 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1063 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1065 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1066 new wxDataViewTextRenderer( wxT("string"), mode
),
1067 model_column
, width
, align
, flags
);
1068 PrependColumn( ret
);
1073 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1074 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1076 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1077 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1078 model_column
, width
, align
, flags
);
1079 PrependColumn( ret
);
1084 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1085 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1088 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1089 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1090 model_column
, width
, align
, flags
);
1091 PrependColumn( ret
);
1096 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1097 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1099 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1100 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1101 model_column
, width
, align
, flags
);
1102 PrependColumn( ret
);
1107 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1108 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1110 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1111 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1112 model_column
, width
, align
, flags
);
1113 PrependColumn( ret
);
1118 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1119 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1121 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1122 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1123 model_column
, width
, align
, flags
);
1124 PrependColumn( ret
);
1129 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1130 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1132 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1133 new wxDataViewTextRenderer( wxT("string"), mode
),
1134 model_column
, width
, align
, flags
);
1135 PrependColumn( ret
);
1140 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1141 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1143 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1144 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1145 model_column
, width
, align
, flags
);
1146 PrependColumn( ret
);
1151 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1152 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1154 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1155 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1156 model_column
, width
, align
, flags
);
1157 PrependColumn( ret
);
1162 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1163 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1165 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1166 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1167 model_column
, width
, align
, flags
);
1168 PrependColumn( ret
);
1173 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1174 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1176 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1177 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1178 model_column
, width
, align
, flags
);
1179 PrependColumn( ret
);
1184 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1185 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1187 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1188 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1189 model_column
, width
, align
, flags
);
1190 PrependColumn( ret
);
1195 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1197 col
->SetOwner( (wxDataViewCtrl
*) this );
1202 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1204 col
->SetOwner( (wxDataViewCtrl
*) this );
1209 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1211 col
->SetOwner( (wxDataViewCtrl
*) this );
1215 // ---------------------------------------------------------
1217 // ---------------------------------------------------------
1219 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1221 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1223 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1224 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1225 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1226 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1227 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1228 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1229 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1230 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1232 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
)
1234 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1235 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1236 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1237 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
)
1240 // -------------------------------------
1241 // wxDataViewSpinRenderer
1242 // -------------------------------------
1244 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1245 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1251 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1254 wxSize size
= labelRect
.GetSize();
1256 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1259 str
.Printf( wxT("%d"), (int) l
);
1260 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1261 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
, m_min
, m_max
, l
);
1263 size
= sc
->GetSize();
1264 wxPoint pt
= sc
->GetPosition();
1265 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1271 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1273 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1274 long l
= sc
->GetValue();
1279 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1282 str
.Printf(wxT("%d"), (int) m_data
);
1283 RenderText( str
, 0, rect
, dc
, state
);
1287 wxSize
wxDataViewSpinRenderer::GetSize() const
1289 return wxSize(80,16);
1292 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1294 m_data
= value
.GetLong();
1298 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1304 //-----------------------------------------------------------------------------
1305 // wxDataViewTreeStore
1306 //-----------------------------------------------------------------------------
1308 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1309 wxDataViewTreeStoreNode
*parent
,
1310 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1318 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1324 #include "wx/listimpl.cpp"
1325 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1327 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1328 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1329 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1330 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1332 m_iconExpanded
= expanded
;
1333 m_isExpanded
= false;
1334 m_children
.DeleteContents(true);
1337 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1341 //-----------------------------------------------------------------------------
1343 wxDataViewTreeStore::wxDataViewTreeStore()
1345 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1348 wxDataViewTreeStore::~wxDataViewTreeStore()
1353 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1354 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1356 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1357 if (!parent_node
) return wxDataViewItem(0);
1359 wxDataViewTreeStoreNode
*node
=
1360 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1361 parent_node
->GetChildren().Append( node
);
1364 ItemAdded( parent
, node
->GetItem() );
1366 return node
->GetItem();
1369 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1370 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1372 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1373 if (!parent_node
) return wxDataViewItem(0);
1375 wxDataViewTreeStoreNode
*node
=
1376 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1377 parent_node
->GetChildren().Insert( node
);
1380 ItemAdded( parent
, node
->GetItem() );
1382 return node
->GetItem();
1386 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1387 const wxDataViewItem
& WXUNUSED(previous
),
1388 const wxString
& WXUNUSED(text
),
1389 const wxIcon
& WXUNUSED(icon
),
1390 wxClientData
* WXUNUSED(data
))
1392 return wxDataViewItem(0);
1395 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1396 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1397 wxClientData
*data
)
1399 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1400 if (!parent_node
) return wxDataViewItem(0);
1402 wxDataViewTreeStoreContainerNode
*node
=
1403 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1404 parent_node
->GetChildren().Insert( node
);
1407 ItemAdded( parent
, node
->GetItem() );
1409 return node
->GetItem();
1413 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1414 const wxString
&text
,
1416 const wxIcon
& expanded
,
1417 wxClientData
* data
)
1419 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1420 if (!parent_node
) return wxDataViewItem(0);
1422 wxDataViewTreeStoreContainerNode
*node
=
1423 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1424 parent_node
->GetChildren().Append( node
);
1427 ItemAdded( parent
, node
->GetItem() );
1429 return node
->GetItem();
1433 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1434 const wxDataViewItem
& WXUNUSED(previous
),
1435 const wxString
& WXUNUSED(text
),
1436 const wxIcon
& WXUNUSED(icon
),
1437 const wxIcon
& WXUNUSED(expanded
),
1438 wxClientData
* WXUNUSED(data
))
1440 return wxDataViewItem(0);
1443 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1445 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1446 if (!parent_node
) return wxDataViewItem(0);
1448 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1450 return node
->GetData();
1452 return wxDataViewItem(0);
1455 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1457 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1458 if (!node
) return -1;
1460 if (!node
->IsContainer())
1463 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1464 return (int) container_node
->GetChildren().GetCount();
1467 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1469 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1472 node
->SetText( text
);
1475 ValueChanged( item
, 0 );
1478 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1480 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1481 if (!node
) return wxEmptyString
;
1483 return node
->GetText();
1486 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1488 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1491 node
->SetIcon( icon
);
1494 ValueChanged( item
, 0 );
1497 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1499 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1500 if (!node
) return wxNullIcon
;
1502 return node
->GetIcon();
1505 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1507 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1510 node
->SetExpandedIcon( icon
);
1513 ValueChanged( item
, 0 );
1516 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1518 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1519 if (!node
) return wxNullIcon
;
1521 return node
->GetExpandedIcon();
1524 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1526 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1529 node
->SetData( data
);
1531 // notify control? only sensible when sorting on client data
1532 // ValueChanged( item, 0 );
1535 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1537 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1538 if (!node
) return NULL
;
1540 return node
->GetData();
1543 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1545 if (!item
.IsOk()) return;
1547 wxDataViewItem parent_item
= GetParent( item
);
1549 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1550 if (!parent_node
) return;
1552 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1555 parent_node
->GetChildren().DeleteObject( node
);
1558 ItemDeleted( parent_item
, item
);
1561 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1563 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1566 wxDataViewItemArray array
;
1567 wxDataViewTreeStoreNodeList::iterator iter
;
1568 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1570 wxDataViewTreeStoreNode
* child
= *iter
;
1571 array
.Add( child
->GetItem() );
1574 node
->GetChildren().clear();
1577 ItemsDeleted( item
, array
);
1580 void wxDataViewTreeStore::DeleteAllItems()
1586 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1587 const wxDataViewItem
&item
,
1588 unsigned int WXUNUSED(col
)) const
1590 // if (col != 0) return;
1592 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1595 wxIcon
icon( node
->GetIcon());
1596 if (node
->IsContainer())
1598 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1599 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1600 icon
= container
->GetExpandedIcon();
1603 wxDataViewIconText
data( node
->GetText(), icon
);
1609 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1610 const wxDataViewItem
& item
,
1611 unsigned int WXUNUSED(col
))
1613 // if (col != 0) return false;
1615 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1616 if (!node
) return false;
1618 wxDataViewIconText data
;
1622 node
->SetText( data
.GetText() );
1623 node
->SetIcon( data
.GetIcon() );
1628 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1630 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1631 if (!node
) return wxDataViewItem(0);
1633 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1634 if (!parent
) return wxDataViewItem(0);
1636 if (parent
== m_root
)
1637 return wxDataViewItem(0);
1639 return parent
->GetItem();
1642 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1644 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1645 if (!node
) return false;
1647 return node
->IsContainer();
1650 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1652 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1653 if (!node
) return 0;
1655 wxDataViewTreeStoreNodeList::iterator iter
;
1656 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1658 wxDataViewTreeStoreNode
* child
= *iter
;
1659 children
.Add( child
->GetItem() );
1662 return node
->GetChildren().GetCount();
1665 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1666 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1668 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1669 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1671 if (!node1
|| !node2
)
1674 wxDataViewTreeStoreContainerNode
* parent1
=
1675 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1676 wxDataViewTreeStoreContainerNode
* parent2
=
1677 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1679 if (parent1
!= parent2
)
1681 wxLogError( wxT("Comparing items with different parent.") );
1685 if (node1
->IsContainer() && !!node2
->IsContainer())
1688 if (node2
->IsContainer() && !!node1
->IsContainer())
1691 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1694 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1699 return (wxDataViewTreeStoreNode
*) item
.GetID();
1702 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1705 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1707 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1709 if (!node
->IsContainer())
1712 return (wxDataViewTreeStoreContainerNode
*) node
;
1715 //-----------------------------------------------------------------------------
1716 // wxDataViewTreeCtrl
1717 //-----------------------------------------------------------------------------
1719 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1721 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1722 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1723 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1724 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1727 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1732 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1733 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1736 Create( parent
, id
, pos
, size
, style
, validator
);
1738 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1739 AssociateModel( store
);
1742 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
1745 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1751 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1752 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1754 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1757 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1762 m_imageList
= imagelist
;
1765 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1766 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1768 wxIcon icon
= wxNullIcon
;
1769 if (m_imageList
&& (iconIndex
!= -1))
1770 icon
= m_imageList
->GetIcon( iconIndex
);
1772 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1775 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1776 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1778 wxIcon icon
= wxNullIcon
;
1779 if (m_imageList
&& (iconIndex
!= -1))
1780 icon
= m_imageList
->GetIcon( iconIndex
);
1782 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1785 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1786 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1788 wxIcon icon
= wxNullIcon
;
1789 if (m_imageList
&& (iconIndex
!= -1))
1790 icon
= m_imageList
->GetIcon( iconIndex
);
1792 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1795 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1796 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1798 wxIcon icon
= wxNullIcon
;
1799 if (m_imageList
&& (iconIndex
!= -1))
1800 icon
= m_imageList
->GetIcon( iconIndex
);
1802 wxIcon expanded
= wxNullIcon
;
1803 if (m_imageList
&& (expandedIndex
!= -1))
1804 expanded
= m_imageList
->GetIcon( expandedIndex
);
1806 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1809 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1810 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1812 wxIcon icon
= wxNullIcon
;
1813 if (m_imageList
&& (iconIndex
!= -1))
1814 icon
= m_imageList
->GetIcon( iconIndex
);
1816 wxIcon expanded
= wxNullIcon
;
1817 if (m_imageList
&& (expandedIndex
!= -1))
1818 expanded
= m_imageList
->GetIcon( expandedIndex
);
1820 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1823 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1824 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1826 wxIcon icon
= wxNullIcon
;
1827 if (m_imageList
&& (iconIndex
!= -1))
1828 icon
= m_imageList
->GetIcon( iconIndex
);
1830 wxIcon expanded
= wxNullIcon
;
1831 if (m_imageList
&& (expandedIndex
!= -1))
1832 expanded
= m_imageList
->GetIcon( expandedIndex
);
1834 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1837 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1839 if (m_imageList
) return;
1841 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1842 if (!container
) return;
1844 container
->SetExpanded( true );
1845 GetStore()->ItemChanged( event
.GetItem() );
1848 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1850 if (m_imageList
) return;
1852 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1853 if (!container
) return;
1855 container
->SetExpanded( false );
1856 GetStore()->ItemChanged( event
.GetItem() );
1859 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
1861 #if defined(wxUSE_GENERICDATAVIEWCTRL)
1862 wxSize size
= GetClientSize();
1863 wxDataViewColumn
*col
= GetColumn( 0 );
1865 col
->SetWidth( size
.x
);
1870 #endif // wxUSE_DATAVIEWCTRL