X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/effd54b05efc46c21a7915f39c4e0418cf4c5612..dc834029a3eb341d9c9c5bebb4ce7b60560eeacb:/src/gtk/dataview.cpp diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 0e0bfce9a1..e9ad3b983d 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -26,6 +26,8 @@ #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" @@ -53,6 +55,9 @@ typedef struct _GtkWxTreeModel GtkWxTreeModel; // wxDataViewCtrlInternal //----------------------------------------------------------------------------- +WX_DECLARE_LIST(wxDataViewItem, ItemList); +WX_DEFINE_LIST(ItemList); + class wxDataViewCtrlInternal { public: @@ -74,7 +79,7 @@ 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(); @@ -1017,7 +1022,7 @@ public: ~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(); @@ -1064,7 +1069,7 @@ bool wxGtkDataViewModelNotifier::ItemAdded( const wxDataViewItem &parent, const 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; @@ -1076,7 +1081,7 @@ bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &item ) 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; } @@ -2291,10 +2296,10 @@ bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDa 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 ); @@ -2432,6 +2437,9 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter ) 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) @@ -2534,30 +2542,48 @@ gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *ch } 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 ) @@ -2569,7 +2595,7 @@ 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) { @@ -2586,7 +2612,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item 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) { @@ -2599,31 +2625,56 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item } 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; } @@ -2636,7 +2687,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( GtkTreeIter *iter ) 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 ) @@ -2644,7 +2695,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem if (!item.IsOk()) return NULL; - return wxDataViewCtrlInternal_FindParentNode( m_root, item ); + return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item ); } //----------------------------------------------------------------------------- @@ -2702,8 +2753,7 @@ void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation *alloc, wxDataViewCtrl *win ) { - - wxWindowList::Node *node = win->GetChildren().GetFirst(); + wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); while (node) { wxWindow *child = node->GetData();