Re: GtkTree*



On Wed, 15 Aug 2001, Tim Janik wrote:

> setting up a static model for a treeview, then adding columns, then doing
> gtk_tree_selection_select_path (tsel, path); doesn't result in a selection
> because gtk_tree_view_setup_model() aborts on tree_view->priv->columns == NULL.
> i guess you should setup tree_view->priv->tree as soon as the first column is
> added (and you have a model). (though, i'm not sure why you can't setup the
> rbtree right when you have a model and no columns yet).

investigating this further showed that gtk_tree_view_setup_model() and
gtk_tree_view_set_model() don't sanely maintain tree_view<->model relationship
state (e.g. gtk_tree_view_setup_model() could setup the signal handlers,
but not update GTK_TREE_VIEW_MODEL_SETUP, no handling at destruction time etc.).

appended is a patch that i intend to commit soon, it fixes the above selection
probelm and also gets rid of tree_view signal handlers connected to the model
being executed after the tree_view got destroyed.

---
ciaoTJ

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2175
diff -u -p -u -r1.2175 ChangeLog
--- ChangeLog	2001/08/15 09:24:14	1.2175
+++ ChangeLog	2001/08/15 10:40:41
@@ -1,3 +1,13 @@
+Wed Aug 15 12:36:55 2001  Tim Janik  <timj gtk org>
+
+	* gtk/gtktreeview.c (gtk_tree_view_set_model): move all model setup
+	code into this place. get rid of GTK_TREE_VIEW_MODEL_SETUP usage.
+	(gtk_tree_view_set_property): don't cast possible NULL objects.
+	(gtk_tree_view_destroy): reset the model to NULL.
+
+	* gtk/gtktreeselection.c (gtk_tree_selection_finalize): chain
+	parent_class handler.
+
 2001-08-15  Matthias Clasen  <matthiasc waldgeist poet de>
 
 	* docs/debugging.txt: Add a warning about --enable-debug=no,
Index: gtk/gtktreeselection.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeselection.c,v
retrieving revision 1.28
diff -u -p -u -r1.28 gtktreeselection.c
--- gtk/gtktreeselection.c	2001/08/13 17:23:41	1.28
+++ gtk/gtktreeselection.c	2001/08/15 10:40:43
@@ -99,6 +99,9 @@ gtk_tree_selection_finalize (GObject *ob
 {
   if (GTK_TREE_SELECTION (object)->destroy)
     (* GTK_TREE_SELECTION (object)->destroy) (GTK_TREE_SELECTION (object)->user_data);
+
+  /* chain parent_class' handler */
+  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 /**
Index: gtk/gtktreeview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeview.c,v
retrieving revision 1.116
diff -u -p -u -r1.116 gtktreeview.c
--- gtk/gtktreeview.c	2001/07/31 19:55:02	1.116
+++ gtk/gtktreeview.c	2001/08/15 10:40:50
@@ -853,13 +853,13 @@ gtk_tree_view_set_property (GObject     
   switch (prop_id)
     {
     case PROP_MODEL:
-      gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (g_value_get_object (value)));
+      gtk_tree_view_set_model (tree_view, g_value_get_object (value));
       break;
     case PROP_HADJUSTMENT:
-      gtk_tree_view_set_hadjustment (tree_view, GTK_ADJUSTMENT (g_value_get_object (value)));
+      gtk_tree_view_set_hadjustment (tree_view, g_value_get_object (value));
       break;
     case PROP_VADJUSTMENT:
-      gtk_tree_view_set_vadjustment (tree_view, GTK_ADJUSTMENT (g_value_get_object (value)));
+      gtk_tree_view_set_vadjustment (tree_view, g_value_get_object (value));
       break;
     case PROP_HEADERS_VISIBLE:
       gtk_tree_view_set_headers_visible (tree_view, g_value_get_boolean (value));
@@ -868,7 +868,7 @@ gtk_tree_view_set_property (GObject     
       gtk_tree_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
       break;
     case PROP_EXPANDER_COLUMN:
-      gtk_tree_view_set_expander_column (tree_view, GTK_TREE_VIEW_COLUMN (g_value_get_object (value)));
+      gtk_tree_view_set_expander_column (tree_view, g_value_get_object (value));
       break;
     case PROP_REORDERABLE:
       gtk_tree_view_set_reorderable (tree_view, g_value_get_boolean (value));
@@ -939,9 +939,10 @@ gtk_tree_view_finalize (GObject *object)
 static void
 gtk_tree_view_destroy (GtkObject *object)
 {
-  GtkTreeView *tree_view = (GtkTreeView *) object;
+  GtkTreeView *tree_view = GTK_TREE_VIEW (object);
   GList *list;
 
+  gtk_tree_view_set_model (tree_view, NULL);
 
   if (tree_view->priv->tree != NULL)
     {
@@ -1273,7 +1274,7 @@ gtk_tree_view_size_request_buttons (GtkT
 
   tree_view->priv->header_height = 1;
 
-  if (GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_MODEL_SETUP))
+  if (tree_view->priv->model)
     {
       for (list = tree_view->priv->columns; list; list = list->next)
         {
@@ -4701,53 +4702,6 @@ gtk_tree_view_get_arrow_xrange (GtkTreeV
     }
 }
 
-static void
-gtk_tree_view_setup_model (GtkTreeView *tree_view)
-{
-  GtkTreePath *path;
-  GtkTreeIter iter;
-
-  tree_view->priv->tree = NULL;
-
-  g_signal_connect (tree_view->priv->model,
-                    "range_changed",
-                    (GCallback) gtk_tree_view_range_changed,
-                    tree_view);
-  g_signal_connect (tree_view->priv->model,
-                    "inserted",
-                    (GCallback) gtk_tree_view_inserted,
-                    tree_view);
-  g_signal_connect (tree_view->priv->model,
-                    "has_child_toggled",
-                    (GCallback) gtk_tree_view_has_child_toggled,
-                    tree_view);
-  g_signal_connect (tree_view->priv->model,
-                    "deleted",
-                    (GCallback) gtk_tree_view_deleted,
-                    tree_view);
-  g_signal_connect (tree_view->priv->model,
-                    "reordered",
-                    (GCallback) gtk_tree_view_reordered,
-                    tree_view);
-
-  if (tree_view->priv->columns == NULL)
-    return;
-
-  path = gtk_tree_path_new_root ();
-
-  if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, path))
-    {
-      tree_view->priv->tree = _gtk_rbtree_new ();
-      gtk_tree_view_build_tree (tree_view, tree_view->priv->tree, &iter, 1, FALSE, GTK_WIDGET_REALIZED (tree_view));
-    }
-
-  gtk_tree_path_free (path);
-
-  /*  FIXME: do I need to do this? gtk_tree_view_create_buttons (tree_view); */
-
-  GTK_TREE_VIEW_SET_FLAG (tree_view, GTK_TREE_VIEW_MODEL_SETUP);
-}
-
 static gint
 gtk_tree_view_insert_iter_height (GtkTreeView *tree_view,
 				  GtkRBTree   *tree,
@@ -5012,10 +4966,6 @@ gtk_tree_view_check_dirty (GtkTreeView *
   GtkTreeViewColumn *column;
   GtkTreeIter iter;
 
-  if (!GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_MODEL_SETUP) &&
-      tree_view->priv->model)
-    gtk_tree_view_setup_model (tree_view);
-
   for (list = tree_view->priv->columns; list; list = list->next)
     {
       column = list->data;
@@ -6159,59 +6109,74 @@ gtk_tree_view_set_model (GtkTreeView  *t
 
   if (model == tree_view->priv->model)
     return;
-
-  if (model != NULL)
-    g_object_ref (model);
 
-  if (tree_view->priv->model != NULL)
+  if (tree_view->priv->model)
     {
-      if (GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_MODEL_SETUP))
+      g_signal_handlers_disconnect_by_func (G_OBJECT (tree_view->priv->model),
+					    gtk_tree_view_range_changed, tree_view);
+      g_signal_handlers_disconnect_by_func (G_OBJECT (tree_view->priv->model),
+					    gtk_tree_view_inserted, tree_view);
+      g_signal_handlers_disconnect_by_func (G_OBJECT (tree_view->priv->model),
+					    gtk_tree_view_has_child_toggled, tree_view);
+      g_signal_handlers_disconnect_by_func (G_OBJECT (tree_view->priv->model),
+					    gtk_tree_view_deleted, tree_view);
+      g_signal_handlers_disconnect_by_func (G_OBJECT (tree_view->priv->model),
+					    gtk_tree_view_reordered, tree_view);
+      if (tree_view->priv->tree)
 	{
-	  g_signal_handlers_disconnect_matched (G_OBJECT (tree_view->priv->model),
-						G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
-						0, 0, NULL,
-						gtk_tree_view_range_changed, tree_view);
-	  g_signal_handlers_disconnect_matched (G_OBJECT (tree_view->priv->model),
-						G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
-						0, 0, NULL,
-						gtk_tree_view_inserted, tree_view);
-	  g_signal_handlers_disconnect_matched (G_OBJECT (tree_view->priv->model),
-						G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
-						0, 0, NULL,
-						gtk_tree_view_has_child_toggled, tree_view);
-	  g_signal_handlers_disconnect_matched (G_OBJECT (tree_view->priv->model),
-						G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
-						0, 0, NULL,
-						gtk_tree_view_deleted, tree_view);
-	  g_signal_handlers_disconnect_matched (G_OBJECT (tree_view->priv->model),
-						G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
-						0, 0, NULL,
-						gtk_tree_view_reordered, tree_view);
-	  if (tree_view->priv->tree)
-	    _gtk_rbtree_free (tree_view->priv->tree);
+	  _gtk_rbtree_free (tree_view->priv->tree);
+	  tree_view->priv->tree = NULL;
 	}
-
       if (tree_view->priv->drag_dest_row)
-        gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
-
-      GTK_TREE_VIEW_UNSET_FLAG (tree_view, GTK_TREE_VIEW_MODEL_SETUP);
+	{
+	  gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
+	  tree_view->priv->drag_dest_row = NULL;
+	}
       g_object_unref (tree_view->priv->model);
     }
 
   tree_view->priv->model = model;
 
-  if (model == NULL)
-    {
-      tree_view->priv->tree = NULL;
-      if (GTK_WIDGET_REALIZED (tree_view))
-	_gtk_tree_view_update_size (tree_view);
-    }
-  else if (GTK_WIDGET_REALIZED (tree_view))
+  if (tree_view->priv->model)
     {
-      gtk_tree_view_setup_model (tree_view);
-      _gtk_tree_view_update_size (tree_view);
+      GtkTreePath *path;
+      GtkTreeIter iter;
+
+      g_object_ref (tree_view->priv->model);
+      g_signal_connect (tree_view->priv->model,
+			"range_changed",
+			G_CALLBACK (gtk_tree_view_range_changed),
+			tree_view);
+      g_signal_connect (tree_view->priv->model,
+			"inserted",
+			G_CALLBACK (gtk_tree_view_inserted),
+			tree_view);
+      g_signal_connect (tree_view->priv->model,
+			"has_child_toggled",
+			G_CALLBACK (gtk_tree_view_has_child_toggled),
+			tree_view);
+      g_signal_connect (tree_view->priv->model,
+			"deleted",
+			G_CALLBACK (gtk_tree_view_deleted),
+			tree_view);
+      g_signal_connect (tree_view->priv->model,
+			"reordered",
+			G_CALLBACK (gtk_tree_view_reordered),
+			tree_view);
+
+      path = gtk_tree_path_new_root ();
+      if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, path))
+	{
+	  tree_view->priv->tree = _gtk_rbtree_new ();
+	  gtk_tree_view_build_tree (tree_view, tree_view->priv->tree, &iter, 1, FALSE, GTK_WIDGET_REALIZED (tree_view));
+	}
+      gtk_tree_path_free (path);
+
+      /*  FIXME: do I need to do this? gtk_tree_view_create_buttons (tree_view); */
     }
 
+  if (GTK_WIDGET_REALIZED (tree_view))
+    _gtk_tree_view_update_size (tree_view);
   g_object_notify (G_OBJECT (tree_view), "model");
 }
 





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]