git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47589
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
const wxDataViewItem &item, unsigned int col ) = 0;
// define hierachy
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;
virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const = 0;
virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const = 0;
int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
{
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 );
{
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();
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
+
+ // "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())
+ MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
return node->IsContainer();
}
return node->IsContainer();
}
virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const
{
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
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);
return wxDataViewItem(0);
+ MyMusicModelNode *parent = node->GetParent();
int pos = parent->GetChildren().Index( node );
int pos = parent->GetChildren().Index( node );
+
+ // Something went wrong
if (pos == wxNOT_FOUND)
return wxDataViewItem(0);
if (pos == wxNOT_FOUND)
return wxDataViewItem(0);
if (pos == parent->GetChildCount()-1)
return wxDataViewItem(0);
if (pos == parent->GetChildCount()-1)
return wxDataViewItem(0);
int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
{
// sort branches before leaves
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)
- if (item2_has_children && !item1_has_children)
+ if (item2_is_container && !item1_is_container)
return -1;
wxVariant value1,value2;
return -1;
wxVariant value1,value2;
{
wxDataViewItem item( (void*) parent->user_data );
{
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 );
return FALSE;
wxGtkTreeModelNode *parent_node = FindNode( parent );
gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
{
wxDataViewItem item( (void*) iter->user_data );
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 );
{
wxDataViewItem item( (void*) iter->user_data );
{
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 );
return 0;
wxGtkTreeModelNode *parent_node = FindNode( iter );
if (parent) id = (void*) parent->user_data;
wxDataViewItem item( id );
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 );
return FALSE;
wxGtkTreeModelNode *parent_node = FindNode( parent );