Further attempts to implement Clear() for the GTK control

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61118 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2009-06-18 17:42:06 +00:00
parent 03a187ccae
commit 8a56837211

View File

@ -601,9 +601,8 @@ wxgtk_tree_model_iter_next (GtkTreeModel *tree_model,
{
GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
//if (wxtree_model->stamp != iter->stamp)
// wxPrintf( "crash\n" );
// TODO: remove this code
// This happens when clearing the view by calling .._set_model( NULL );
if (iter->stamp == 0) return FALSE;
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
@ -639,7 +638,7 @@ wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), 0);
g_return_val_if_fail ( !iter || wxtree_model->stamp == iter->stamp, 0);
return wxtree_model->internal->iter_n_children( iter );
@ -1489,16 +1488,9 @@ bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsig
bool wxGtkDataViewModelNotifier::Cleared()
{
gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), NULL );
// this will create a new GTK model
m_owner->GtkGetInternal()->Cleared();
SetGtkModel( m_owner->GtkGetInternal()->GetGtkModel() );
gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), GTK_TREE_MODEL(m_wxgtk_model) );
return false;
return true;
}
// ---------------------------------------------------------
@ -3320,17 +3312,16 @@ wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest *WXUNUSED(drag_dest),
bool wxDataViewCtrlInternal::Cleared()
{
GtkWidget* tree_widget = GetOwner()->GtkGetTreeView();
gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget), NULL );
gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget), GTK_TREE_MODEL(m_gtk_model) );
if (m_root)
{
delete m_root;
InitTree();
}
// Create new GTK model
g_object_unref( m_gtk_model );
m_gtk_model = wxgtk_tree_model_new();
m_gtk_model->internal = this;
return true;
}
@ -3503,11 +3494,17 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
int n = ( (wxUIntPtr) iter->user_data ) -1;
if (n == -1)
{
iter->user_data = NULL;
return FALSE;
}
if (n >= (int) wx_model->GetCount())
if (n >= (int) wx_model->GetCount()-1)
{
iter->user_data = NULL;
return FALSE;
}
// user_data is just the index +1 (+2 because we need the next)
iter->user_data = (gpointer) (n+2);
}
@ -3515,14 +3512,19 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
{
wxGtkTreeModelNode *parent = FindParentNode( iter );
if( parent == NULL )
{
iter->user_data = NULL;
return FALSE;
}
int pos = parent->GetChildren().Index( iter->user_data );
if (pos == (int) parent->GetChildCount()-1)
{
iter->user_data = NULL;
return FALSE;
}
iter->stamp = m_gtk_model->stamp;
iter->user_data = parent->GetChildren().Item( pos+1 );
}
@ -3544,6 +3546,14 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *
}
else
{
if (iter == NULL)
{
if (m_root->GetChildCount() == 0) return FALSE;
iter->stamp = m_gtk_model->stamp;
iter->user_data = (gpointer) m_root->GetChildren().Item( 0 );
return TRUE;
}
wxDataViewItem item( (void*) parent->user_data );
if (!m_wx_model->IsContainer( item ))
@ -3572,13 +3582,16 @@ gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
if (iter == NULL)
return (gint) wx_model->GetCount();
return (wx_model->GetCount() > 0);
// this is a list, nodes have no children
return FALSE;
}
else
{
if (iter == NULL)
return (m_root->GetChildCount() > 0);
wxDataViewItem item( (void*) iter->user_data );
bool is_container = m_wx_model->IsContainer( item );
@ -3623,8 +3636,6 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
BuildBranch( parent_node );
// wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
return parent_node->GetChildCount();
}
}
@ -3665,8 +3676,6 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
BuildBranch( parent_node );
// wxPrintf( "iter_nth_child %d\n", n );
iter->stamp = m_gtk_model->stamp;
iter->user_data = parent_node->GetChildren().Item( n );
@ -4015,8 +4024,6 @@ gtk_dataview_motion_notify_callback( GtkWidget *WXUNUSED(widget),
GtkTreeIter iter;
dv->GtkGetInternal()->get_iter( &iter, path );
// wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
gtk_tree_path_free( path );
}
}