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;
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 );
}
}
- 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();
}
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);
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;
{
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 );
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;
{
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 );
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 );