From ed903e42421d76ac96e0e48724c66afc611a740a Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 20 Jul 2007 09:01:52 +0000 Subject: [PATCH] Renamed HasChildren() to IsContainer(), added GetParent() to wxDataViewModel git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataview.h | 3 ++- samples/dataview/dataview.cpp | 32 +++++++++++++++++++++++++++----- src/common/datavcmn.cpp | 8 ++++---- src/gtk/dataview.cpp | 8 ++++---- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index bb0077fefc..281141dafb 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -104,7 +104,8 @@ public: const wxDataViewItem &item, unsigned int col ) = 0; // define hierachy - virtual bool HasChildren( const wxDataViewItem &item ) const = 0; + virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0; + virtual bool IsContainer( const wxDataViewItem &item ) const = 0; virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const = 0; virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const = 0; diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 95f6177814..bd55943730 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -171,7 +171,7 @@ public: int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 ) { - if (HasChildren(item1) && HasChildren(item2)) + if (IsContainer(item1) && IsContainer(item2)) { wxVariant value1,value2; GetValue( value1, item1, 0 ); @@ -230,12 +230,29 @@ public: } } - virtual bool HasChildren( const wxDataViewItem &item ) const + virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const { + // the invisble root node has no parent + if (!item.IsOk()) + return wxDataViewItem(0); + MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); - if (!node) + + // "MyMusic" also has no parent + if (node == m_root) + return wxDataViewItem(0); + + return wxDataViewItem( (void*) node->GetParent() ); + } + + virtual bool IsContainer( const wxDataViewItem &item ) const + { + // the invisble root node can have children (in + // our model always "MyMusic") + if (!item.IsOk()) return true; + MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); return node->IsContainer(); } @@ -261,14 +278,19 @@ public: virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const { MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); - MyMusicModelNode *parent = node->GetParent(); - if (!parent) + + // "MyMusic" has no siblings in our model + if (node == m_root) return wxDataViewItem(0); + MyMusicModelNode *parent = node->GetParent(); int pos = parent->GetChildren().Index( node ); + + // Something went wrong if (pos == wxNOT_FOUND) return wxDataViewItem(0); + // No more children if (pos == parent->GetChildCount()-1) return wxDataViewItem(0); diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index acbc8da36a..29c12266a8 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -148,12 +148,12 @@ void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier ) int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 ) { // sort branches before leaves - bool item1_has_children = HasChildren(item1); - bool item2_has_children = HasChildren(item2); + bool item1_is_container = IsContainer(item1); + bool item2_is_container = IsContainer(item2); - if (item1_has_children && !item2_has_children) + if (item1_is_container && !item2_is_container) return 1; - if (item2_has_children && !item1_has_children) + if (item2_is_container && !item1_is_container) return -1; wxVariant value1,value2; diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 50618e6eba..3aaedef4f2 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -2307,7 +2307,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter * { wxDataViewItem item( (void*) parent->user_data ); - if (!m_wx_model->HasChildren( item )) + if (!m_wx_model->IsContainer( item )) return FALSE; wxGtkTreeModelNode *parent_node = FindNode( parent ); @@ -2327,7 +2327,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter * gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter ) { wxDataViewItem item( (void*) iter->user_data ); - bool res = m_wx_model->HasChildren( item ); + bool res = m_wx_model->IsContainer( item ); if (!res) return FALSE; @@ -2342,7 +2342,7 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter ) { wxDataViewItem item( (void*) iter->user_data ); - if (!m_wx_model->HasChildren( item )) + if (!m_wx_model->IsContainer( item )) return 0; wxGtkTreeModelNode *parent_node = FindNode( iter ); @@ -2359,7 +2359,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter if (parent) id = (void*) parent->user_data; wxDataViewItem item( id ); - if (!m_wx_model->HasChildren( item )) + if (!m_wx_model->IsContainer( item )) return FALSE; wxGtkTreeModelNode *parent_node = FindNode( parent );