#include "wx/calctrl.h"
#include "wx/popupwin.h"
#include "wx/icon.h"
+#include "wx/list.h"
+#include "wx/listimpl.cpp"
#include "wx/gtk/private.h"
// wxDataViewCtrlInternal
//-----------------------------------------------------------------------------
+WX_DECLARE_LIST(wxDataViewItem, ItemList);
+WX_DEFINE_LIST(ItemList);
+
class wxDataViewCtrlInternal
{
public:
GtkWxTreeModel* GetGtkModel() { return m_gtk_model; }
bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
- bool ItemDeleted( const wxDataViewItem &item );
+ bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
bool ItemChanged( const wxDataViewItem &item );
bool ValueChanged( const wxDataViewItem &item, unsigned int col );
bool Cleared();
~wxGtkDataViewModelNotifier();
virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
- virtual bool ItemDeleted( const wxDataViewItem &item );
+ virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
virtual bool ItemChanged( const wxDataViewItem &item );
virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
virtual bool Cleared();
return true;
}
-bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &item )
+bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
{
GtkTreeIter iter;
iter.stamp = m_wxgtk_model->stamp;
GTK_TREE_MODEL(m_wxgtk_model), path );
gtk_tree_path_free (path);
- m_owner->GtkGetInternal()->ItemDeleted( item );
+ m_owner->GtkGetInternal()->ItemDeleted( parent, item );
return true;
}
return true;
}
-bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &item )
+bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
{
- wxGtkTreeModelNode *parent = FindParentNode( item );
- parent->DeleteChild( item.GetID() );
+ wxGtkTreeModelNode *parent_node = FindNode( parent );
+ parent_node->DeleteChild( item.GetID() );
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, m_owner->GetId() );
event.SetEventObject( m_owner );
g_model = m_wx_model;
wxGtkTreeModelNode *parent = FindParentNode( iter );
+ if( parent == NULL )
+ return FALSE;
+
unsigned int pos = parent->GetChildren().Index( iter->user_data );
if (pos == parent->GetChildCount()-1)
}
static wxGtkTreeModelNode*
-wxDataViewCtrlInternal_FindNode( wxGtkTreeModelNode *node, const wxDataViewItem &item )
+wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
{
- if (!node) return NULL;
+ if( model == NULL )
+ return NULL;
- size_t count = node->GetNodesCount();
- size_t i;
- for (i = 0; i < count; i++)
+ ItemList list;
+ list.DeleteContents( true );
+ wxDataViewItem it( item );
+ while( it.IsOk() )
{
- wxGtkTreeModelNode *child = node->GetNodes().Item( i );
- if (child->GetItem().GetID() == item.GetID())
- {
- // wxPrintf( "leave findnode at %d\n", i );
- return child;
- }
-
- wxGtkTreeModelNode *node2 = wxDataViewCtrlInternal_FindNode( child, item );
- if (node2)
+ wxDataViewItem * pItem = new wxDataViewItem( it );
+ list.Insert( pItem );
+ it = model->GetParent( it );
+ }
+
+ wxGtkTreeModelNode * node = treeNode;
+ for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
+ {
+ if( node && node->GetNodes().GetCount() != 0 )
{
- // wxPrintf( "branch findnode at %d\n", i );
- return node2;
+ int len = node->GetNodes().GetCount();
+ wxGtkTreeModelNodes nodes = node->GetNodes();
+ int j = 0;
+ for( ; j < len; j ++)
+ {
+ if( nodes[j]->GetItem() == *(n->GetData()))
+ {
+ node = nodes[j];
+ break;
+ }
+ }
+
+ if( j == len )
+ {
+ return NULL;
+ }
}
+ else
+ return NULL;
}
-
- return NULL;
+ return node;
+
}
wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
if (!item.IsOk())
return m_root;
- wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_root, item );
+ wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
if (!result)
{
if (!item.IsOk())
return m_root;
- wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_root, item );
+ wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
if (!result)
{
}
static wxGtkTreeModelNode*
-wxDataViewCtrlInternal_FindParentNode( wxGtkTreeModelNode *node, const wxDataViewItem &item )
+wxDataViewCtrlInternal_FindParentNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
{
- size_t child_count = node->GetChildCount();
- void *id = item.GetID();
- const wxGtkTreeModelChildren &children = node->GetChildren();
- size_t pos;
- for (pos = 0; pos < child_count; pos++)
+ if( model == NULL )
+ return NULL;
+
+ ItemList list;
+ list.DeleteContents( true );
+ if( !item.IsOk() )
+ return NULL;
+
+ wxDataViewItem it( model->GetParent( item ) );
+ while( it.IsOk() )
{
- if (children.Item( pos ) == id)
- return node;
+ wxDataViewItem * pItem = new wxDataViewItem( it );
+ list.Insert( pItem );
+ it = model->GetParent( it );
}
- size_t node_count = node->GetNodesCount();
- for (pos = 0; pos < node_count; pos++)
+ wxGtkTreeModelNode * node = treeNode;
+ for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
{
- wxGtkTreeModelNode *child = node->GetNodes().Item( pos );
-
- wxGtkTreeModelNode *node2 = wxDataViewCtrlInternal_FindParentNode( child, item );
- if (node2)
+ if( node && node->GetNodes().GetCount() != 0 )
{
- // wxPrintf( "branch findnode at %d\n", i );
- return node2;
+ int len = node->GetNodes().GetCount();
+ wxGtkTreeModelNodes nodes = node->GetNodes();
+ int j = 0;
+ for( ; j < len; j ++)
+ {
+ if( nodes[j]->GetItem() == *(n->GetData()))
+ {
+ node = nodes[j];
+ break;
+ }
+ }
+
+ if( j == len )
+ {
+ return NULL;
+ }
}
+ else
+ return NULL;
+ }
+ //Examine whether the node is item's parent node
+ int len = node->GetChildCount();
+ for( int i = 0; i < len ; i ++ )
+ {
+ if( node->GetChildren().Item( i ) == item.GetID() )
+ return node;
}
-
return NULL;
}
if (!item.IsOk())
return NULL;
- return wxDataViewCtrlInternal_FindParentNode( m_root, item );
+ return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
}
wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item )
if (!item.IsOk())
return NULL;
- return wxDataViewCtrlInternal_FindParentNode( m_root, item );
+ return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
}
//-----------------------------------------------------------------------------
GtkAllocation *alloc,
wxDataViewCtrl *win )
{
-
- wxWindowList::Node *node = win->GetChildren().GetFirst();
+ wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
while (node)
{
wxWindow *child = node->GetData();