X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0ae51f62deaca848621da88e73d634ecace40054..169dc97542bcf418ad8244bdba45014e2337d9a6:/src/gtk/dataview.cpp diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 040ddc6e61..15855368b1 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -540,7 +540,7 @@ wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model, else { gtype = G_TYPE_STRING; - // wxFAIL_MSG( _T("non-string columns not supported yet") ); + // wxFAIL_MSG( wxT("non-string columns not supported yet") ); } return gtype; @@ -591,7 +591,7 @@ wxgtk_tree_model_get_value (GtkTreeModel *tree_model, } else { - wxFAIL_MSG( _T("non-string columns not supported yet") ); + wxFAIL_MSG( wxT("non-string columns not supported yet") ); } } @@ -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 ); @@ -854,7 +853,7 @@ typedef struct _GtkWxCellRendererTextClass GtkWxCellRendererTextClass; struct _GtkWxCellRendererText { GtkCellRendererText parent; - + wxDataViewRenderer *wx_renderer; }; @@ -970,7 +969,7 @@ static GtkCellEditable *gtk_wx_cell_renderer_text_start_editing( event.SetColumn( wx_renderer->GetOwner()->GetModelColumn() ); event.SetItem( item ); dv->HandleWindowEvent( event ); - + if (event.IsAllowed()) return GTK_CELL_RENDERER_CLASS(text_cell_parent_class)-> start_editing( gtk_renderer, gdk_event, widget, path, background_area, cell_area, flags ); @@ -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; } // --------------------------------------------------------- @@ -1570,8 +1562,8 @@ void wxDataViewRenderer::GtkInitHandlers() if (!gtk_check_version(2,6,0)) { g_signal_connect (GTK_CELL_RENDERER(m_renderer), "editing_started", - G_CALLBACK (wxgtk_renderer_editing_started), - this); + G_CALLBACK (wxgtk_renderer_editing_started), + this); } } @@ -2580,9 +2572,11 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column), wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() ); if (value.GetType() != cell->GetVariantType()) + { wxLogError( wxT("Wrong type, required: %s but: %s"), value.GetType().c_str(), cell->GetVariantType().c_str() ); + } cell->SetValue( value ); @@ -3031,10 +3025,10 @@ void wxGtkTreeModelNode::Resort() // Sort the ptrs gs_internal = m_internal; ptrs.Sort( &wxGtkTreeModelChildPtrCmp ); - + wxGtkTreeModelChildren temp; void** base_ptr = &(m_children[0]); - // Transfer positions to new_order array and + // Transfer positions to new_order array and // IDs to temp for (i = 0; i < child_count; i++) { @@ -3074,13 +3068,13 @@ void wxGtkTreeModelNode::Resort() #if 0 // Too slow - + wxGtkTreeModelChildren temp; WX_APPEND_ARRAY( temp, m_children ); gs_internal = m_internal; m_children.Sort( &wxGtkTreeModelChildCmp ); - + unsigned int pos; for (pos = 0; pos < child_count; pos++) { @@ -3103,7 +3097,7 @@ void wxGtkTreeModelNode::Resort() gtk_tree_path_free (path); delete [] new_order; - + unsigned int pos; for (pos = 0; pos < node_count; pos++) { @@ -3320,17 +3314,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; } @@ -3407,13 +3400,14 @@ GtkTreeModelFlags wxDataViewCtrlInternal::get_flags() gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path ) { + if (m_wx_model->IsVirtualListModel()) { - wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0]; - if (i >= wx_model->GetLastIndex() + 1) + if (i >= wx_model->GetCount()) return FALSE; iter->stamp = m_gtk_model->stamp; @@ -3496,16 +3490,22 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter ) { if (m_wx_model->IsVirtualListModel()) { - wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; // user_data is just the index +1 int n = ( (wxUIntPtr) iter->user_data ) -1; if (n == -1) + { + iter->user_data = NULL; return FALSE; + } - if (n >= (int) wx_model->GetLastIndex()) + 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); @@ -3514,14 +3514,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 ); } @@ -3537,12 +3542,20 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter * return FALSE; iter->stamp = m_gtk_model->stamp; - iter->user_data = (gpointer) 0; + iter->user_data = (gpointer) 1; return TRUE; } 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 )) @@ -3568,11 +3581,19 @@ gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter ) { if (m_wx_model->IsVirtualListModel()) { + wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; + + if (iter == NULL) + 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 ); @@ -3594,10 +3615,10 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter ) { if (m_wx_model->IsVirtualListModel()) { - wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; if (iter == NULL) - return (gint) wx_model->GetLastIndex() + 1; + return (gint) wx_model->GetCount(); return 0; } @@ -3617,8 +3638,6 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter ) BuildBranch( parent_node ); - // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() ); - return parent_node->GetChildCount(); } } @@ -3627,7 +3646,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter { if (m_wx_model->IsVirtualListModel()) { - wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; if (parent) return FALSE; @@ -3635,12 +3654,12 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter if (n < 0) return FALSE; - if (n >= (gint) wx_model->GetLastIndex() + 1) + if (n >= (gint) wx_model->GetCount()) return FALSE; iter->stamp = m_gtk_model->stamp; // user_data is just the index +1 - iter->user_data = (gpointer) (n-1); + iter->user_data = (gpointer) (n+1); return TRUE; } @@ -3659,8 +3678,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 ); @@ -4009,8 +4026,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 ); } }