]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktreeselection.c
Seal priv pointer in GtkPrintUnixDialog.
[~andy/gtk] / gtk / gtktreeselection.c
index 9edac52715124804a62977dc47ce9311654617e8..e52ef90959f31453dca97ff79e09f88387064179 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
+#include <string.h>
 #include "gtktreeselection.h"
 #include "gtktreeprivate.h"
 #include "gtkrbtree.h"
 #include "gtkmarshalers.h"
-
-static void gtk_tree_selection_init              (GtkTreeSelection      *selection);
-static void gtk_tree_selection_class_init        (GtkTreeSelectionClass *class);
+#include "gtkintl.h"
+#include "gtkalias.h"
 
 static void gtk_tree_selection_finalize          (GObject               *object);
 static gint gtk_tree_selection_real_select_all   (GtkTreeSelection      *selection);
@@ -39,36 +40,9 @@ enum
   LAST_SIGNAL
 };
 
-static GObjectClass *parent_class = NULL;
 static guint tree_selection_signals [LAST_SIGNAL] = { 0 };
 
-GType
-gtk_tree_selection_get_type (void)
-{
-  static GType selection_type = 0;
-
-  if (!selection_type)
-    {
-      static const GTypeInfo selection_info =
-      {
-        sizeof (GtkTreeSelectionClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-        (GClassInitFunc) gtk_tree_selection_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-        sizeof (GtkTreeSelection),
-       0,              /* n_preallocs */
-        (GInstanceInitFunc) gtk_tree_selection_init
-      };
-
-      selection_type =
-       g_type_register_static (G_TYPE_OBJECT, "GtkTreeSelection",
-                               &selection_info, 0);
-    }
-
-  return selection_type;
-}
+G_DEFINE_TYPE (GtkTreeSelection, gtk_tree_selection, G_TYPE_OBJECT)
 
 static void
 gtk_tree_selection_class_init (GtkTreeSelectionClass *class)
@@ -76,13 +50,12 @@ gtk_tree_selection_class_init (GtkTreeSelectionClass *class)
   GObjectClass *object_class;
 
   object_class = (GObjectClass*) class;
-  parent_class = g_type_class_peek_parent (class);
 
   object_class->finalize = gtk_tree_selection_finalize;
   class->changed = NULL;
 
   tree_selection_signals[CHANGED] =
-    g_signal_new ("changed",
+    g_signal_new (I_("changed"),
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GtkTreeSelectionClass, changed),
@@ -104,14 +77,14 @@ gtk_tree_selection_finalize (GObject *object)
 
   if (selection->destroy)
     {
-      GtkDestroyNotify d = selection->destroy;
+      GDestroyNotify d = selection->destroy;
 
       selection->destroy = NULL;
       d (selection->user_data);
     }
 
   /* chain parent_class' handler */
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_tree_selection_parent_class)->finalize (object);
 }
 
 /**
@@ -241,7 +214,7 @@ gtk_tree_selection_set_mode (GtkTreeSelection *selection,
                                                  node,
                                                  tree,
                                                  anchor_path,
-                                                 0,
+                                                  0,
                                                  FALSE);
       if (anchor_path)
        gtk_tree_path_free (anchor_path);
@@ -283,14 +256,14 @@ void
 gtk_tree_selection_set_select_function (GtkTreeSelection     *selection,
                                        GtkTreeSelectionFunc  func,
                                        gpointer              data,
-                                       GtkDestroyNotify      destroy)
+                                       GDestroyNotify        destroy)
 {
   g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
   g_return_if_fail (func != NULL);
 
   if (selection->destroy)
     {
-      GtkDestroyNotify d = selection->destroy;
+      GDestroyNotify d = selection->destroy;
 
       selection->destroy = NULL;
       d (selection->user_data);
@@ -301,6 +274,24 @@ gtk_tree_selection_set_select_function (GtkTreeSelection     *selection,
   selection->destroy = destroy;
 }
 
+/**
+ * gtk_tree_selection_get_select_function:
+ * @selection: A #GtkTreeSelection.
+ *
+ * Returns the current selection function.
+ *
+ * Return value: The function.
+ *
+ * Since: GSEAL-branch
+ **/
+GtkTreeSelectionFunc
+gtk_tree_selection_get_select_function (GtkTreeSelection *selection)
+{
+  g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
+
+  return selection->user_func;
+}
+
 /**
  * gtk_tree_selection_get_user_data:
  * @selection: A #GtkTreeSelection.
@@ -361,7 +352,10 @@ gtk_tree_selection_get_selected (GtkTreeSelection  *selection,
   g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
   g_return_val_if_fail (selection->type != GTK_SELECTION_MULTIPLE, FALSE);
   g_return_val_if_fail (selection->tree_view != NULL, FALSE);
-  g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
+
+  /* Clear the iter */
+  if (iter)
+    memset (iter, 0, sizeof (GtkTreeIter));
 
   if (model)
     *model = selection->tree_view->priv->model;
@@ -413,13 +407,13 @@ gtk_tree_selection_get_selected (GtkTreeSelection  *selection,
  * Creates a list of path of all selected rows. Additionally, if you are
  * planning on modifying the model after calling this function, you may
  * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
- * To do this, you can use gtk_tree_row_reference_new_proxy().
+ * To do this, you can use gtk_tree_row_reference_new().
  *
  * To free the return value, use:
- * <informalexample><programlisting>
+ * |[
  * g_list_foreach (list, gtk_tree_path_free, NULL);
  * g_list_free (list);
- * </programlisting></informalexample>
+ * ]|
  *
  * Return value: A #GList containing a #GtkTreePath for each selected row.
  *
@@ -436,15 +430,14 @@ gtk_tree_selection_get_selected_rows (GtkTreeSelection   *selection,
 
   g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
   g_return_val_if_fail (selection->tree_view != NULL, NULL);
-  g_return_val_if_fail (selection->tree_view->priv->model != NULL, NULL);
+
+  if (model)
+    *model = selection->tree_view->priv->model;
 
   if (selection->tree_view->priv->tree == NULL ||
       selection->tree_view->priv->tree->root == NULL)
     return NULL;
 
-  if (model)
-    *model = selection->tree_view->priv->model;
-
   if (selection->type == GTK_SELECTION_NONE)
     return NULL;
   else if (selection->type != GTK_SELECTION_MULTIPLE)
@@ -474,7 +467,7 @@ gtk_tree_selection_get_selected_rows (GtkTreeSelection   *selection,
   do
     {
       if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
-       list = g_list_append (list, gtk_tree_path_copy (path));
+       list = g_list_prepend (list, gtk_tree_path_copy (path));
 
       if (node->children)
         {
@@ -506,7 +499,8 @@ gtk_tree_selection_get_selected_rows (GtkTreeSelection   *selection,
                  if (!tree)
                    {
                      gtk_tree_path_free (path);
-                     return list;
+
+                     goto done; 
                    }
 
                  gtk_tree_path_up (path);
@@ -519,7 +513,8 @@ gtk_tree_selection_get_selected_rows (GtkTreeSelection   *selection,
 
   gtk_tree_path_free (path);
 
-  return list;
+ done:
+  return g_list_reverse (list);
 }
 
 static void
@@ -552,12 +547,9 @@ gint
 gtk_tree_selection_count_selected_rows (GtkTreeSelection *selection)
 {
   gint count = 0;
-  GtkRBTree *tree;
-  GtkRBNode *node;
 
   g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), 0);
   g_return_val_if_fail (selection->tree_view != NULL, 0);
-  g_return_val_if_fail (selection->tree_view->priv->model != NULL, 0);
 
   if (selection->tree_view->priv->tree == NULL ||
       selection->tree_view->priv->tree->root == NULL)
@@ -572,9 +564,6 @@ gtk_tree_selection_count_selected_rows (GtkTreeSelection *selection)
        return 0;
     }
 
-  tree = selection->tree_view->priv->tree;
-  node = selection->tree_view->priv->tree->root;
-
   _gtk_rbtree_traverse (selection->tree_view->priv->tree,
                         selection->tree_view->priv->tree->root,
                        G_PRE_ORDER,
@@ -612,13 +601,13 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection            *selection,
   GtkRBTree *tree;
   GtkRBNode *node;
   GtkTreeIter iter;
+  GtkTreeModel *model;
 
-  guint inserted_id, deleted_id, reordered_id;
-  gboolean stop = FALSE, has_next = TRUE, has_parent = TRUE;
+  gulong inserted_id, deleted_id, reordered_id, changed_id;
+  gboolean stop = FALSE;
 
   g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
   g_return_if_fail (selection->tree_view != NULL);
-  g_return_if_fail (selection->tree_view->priv->model != NULL);
 
   if (func == NULL ||
       selection->tree_view->priv->tree == NULL ||
@@ -644,75 +633,64 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection            *selection,
   while (node->left != tree->nil)
     node = node->left;
 
+  model = selection->tree_view->priv->model;
+  g_object_ref (model);
+
   /* connect to signals to monitor changes in treemodel */
-  inserted_id = g_signal_connect_swapped (selection->tree_view->priv->model,
-                                          "row_inserted",
+  inserted_id = g_signal_connect_swapped (model, "row_inserted",
                                          G_CALLBACK (model_changed),
                                          &stop);
-  deleted_id = g_signal_connect_swapped (selection->tree_view->priv->model,
-                                         "row_deleted",
+  deleted_id = g_signal_connect_swapped (model, "row_deleted",
                                         G_CALLBACK (model_changed),
                                         &stop);
-  reordered_id = g_signal_connect_swapped (selection->tree_view->priv->model,
-                                           "rows_reordered",
+  reordered_id = g_signal_connect_swapped (model, "rows_reordered",
                                           G_CALLBACK (model_changed),
                                           &stop);
+  changed_id = g_signal_connect_swapped (selection->tree_view, "notify::model",
+                                        G_CALLBACK (model_changed), 
+                                        &stop);
 
   /* find the node internally */
   path = gtk_tree_path_new_first ();
-  gtk_tree_model_get_iter (selection->tree_view->priv->model,
-                          &iter, path);
 
   do
     {
       if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
-       (* func) (selection->tree_view->priv->model, path, &iter, data);
+        {
+          gtk_tree_model_get_iter (model, &iter, path);
+         (* func) (model, path, &iter, data);
+        }
 
       if (stop)
        goto out;
 
       if (node->children)
        {
-         gboolean has_child;
-         GtkTreeIter tmp;
-
          tree = node->children;
          node = tree->root;
+
          while (node->left != tree->nil)
            node = node->left;
-         tmp = iter;
-         has_child = gtk_tree_model_iter_children (selection->tree_view->priv->model, &iter, &tmp);
-         gtk_tree_path_append_index (path, 0);
 
-         /* we do the sanity check at the bottom of this function */
-         if (!has_child)
-           goto out;
+         gtk_tree_path_append_index (path, 0);
        }
       else
        {
          gboolean done = FALSE;
+
          do
            {
              node = _gtk_rbtree_next (tree, node);
              if (node != NULL)
                {
-                 gboolean has_next;
-
-                 has_next = gtk_tree_model_iter_next (selection->tree_view->priv->model, &iter);
                  done = TRUE;
                  gtk_tree_path_next (path);
-
-                 /* we do the sanity check at the bottom of this function */
-                 if (!has_next)
-                   goto out;
                }
              else
                {
-                 gboolean has_parent;
-                 GtkTreeIter tmp_iter = iter;
-
                  node = tree->parent_node;
                  tree = tree->parent_tree;
+
                  if (tree == NULL)
                    {
                      /* we've run out of tree */
@@ -721,12 +699,7 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection            *selection,
                      goto out;
                    }
 
-                 has_parent = gtk_tree_model_iter_parent (selection->tree_view->priv->model, &iter, &tmp_iter);
                  gtk_tree_path_up (path);
-
-                 /* we do the sanity check at the bottom of this function */
-                 if (!has_parent)
-                   goto out;
                }
            }
          while (!done);
@@ -738,24 +711,18 @@ out:
   if (path)
     gtk_tree_path_free (path);
 
-  g_signal_handler_disconnect (selection->tree_view->priv->model,
-                               inserted_id);
-  g_signal_handler_disconnect (selection->tree_view->priv->model,
-                               deleted_id);
-  g_signal_handler_disconnect (selection->tree_view->priv->model,
-                               reordered_id);
+  g_signal_handler_disconnect (model, inserted_id);
+  g_signal_handler_disconnect (model, deleted_id);
+  g_signal_handler_disconnect (model, reordered_id);
+  g_signal_handler_disconnect (selection->tree_view, changed_id);
+  g_object_unref (model);
 
   /* check if we have to spew a scary message */
-  if (!has_next)
-    TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
-  if (!has_parent)
-    TREE_VIEW_INTERNAL_ASSERT_VOID (has_parent);
   if (stop)
-    g_warning
-      ("The model has been modified from within gtk_tree_selection_selected_foreach.\n"
-       "This function is for observing the selections of the tree only.  If\n"
-       "you are trying to get all selected items from the tree, try using\n"
-       "gtk_tree_selection_get_selected_rows instead.\n");
+    g_warning ("The model has been modified from within gtk_tree_selection_selected_foreach.\n"
+              "This function is for observing the selections of the tree only.  If\n"
+              "you are trying to get all selected items from the tree, try using\n"
+              "gtk_tree_selection_get_selected_rows instead.\n");
 }
 
 /**
@@ -771,8 +738,8 @@ gtk_tree_selection_select_path (GtkTreeSelection *selection,
 {
   GtkRBNode *node;
   GtkRBTree *tree;
-  GdkModifierType state = 0;
   gboolean ret;
+  GtkTreeSelectMode mode = 0;
 
   g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
   g_return_if_fail (selection->tree_view != NULL);
@@ -788,13 +755,13 @@ gtk_tree_selection_select_path (GtkTreeSelection *selection,
     return;
 
   if (selection->type == GTK_SELECTION_MULTIPLE)
-    state = GDK_CONTROL_MASK;
+    mode = GTK_TREE_SELECT_MODE_TOGGLE;
 
   _gtk_tree_selection_internal_select_node (selection,
                                            node,
                                            tree,
                                            path,
-                                           state,
+                                            mode,
                                            FALSE);
 }
 
@@ -830,7 +797,7 @@ gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
                                            node,
                                            tree,
                                            path,
-                                           GDK_CONTROL_MASK,
+                                            GTK_TREE_SELECT_MODE_TOGGLE,
                                            TRUE);
 }
 
@@ -912,7 +879,9 @@ gtk_tree_selection_path_is_selected (GtkTreeSelection *selection,
   g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
   g_return_val_if_fail (path != NULL, FALSE);
   g_return_val_if_fail (selection->tree_view != NULL, FALSE);
-  g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
+
+  if (selection->tree_view->priv->model == NULL)
+    return FALSE;
 
   ret = _gtk_tree_view_find_node (selection->tree_view,
                                  path,
@@ -1018,7 +987,7 @@ gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
  * gtk_tree_selection_select_all:
  * @selection: A #GtkTreeSelection.
  *
- * Selects all the nodes.  @selection is must be set to #GTK_SELECTION_MULTIPLE
+ * Selects all the nodes. @selection must be set to #GTK_SELECTION_MULTIPLE
  * mode.
  **/
 void
@@ -1026,8 +995,10 @@ gtk_tree_selection_select_all (GtkTreeSelection *selection)
 {
   g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
   g_return_if_fail (selection->tree_view != NULL);
-  if (selection->tree_view->priv->tree == NULL)
+
+  if (selection->tree_view->priv->tree == NULL || selection->tree_view->priv->model == NULL)
     return;
+
   g_return_if_fail (selection->type == GTK_SELECTION_MULTIPLE);
 
   if (gtk_tree_selection_real_select_all (selection))
@@ -1127,12 +1098,10 @@ gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
 {
   g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
   g_return_if_fail (selection->tree_view != NULL);
-  if (selection->tree_view->priv->tree == NULL)
+
+  if (selection->tree_view->priv->tree == NULL || selection->tree_view->priv->model == NULL)
     return;
   
-  if (selection->tree_view->priv->tree == NULL)
-    return;
-
   if (gtk_tree_selection_real_unselect_all (selection))
     g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
 }
@@ -1240,6 +1209,7 @@ gtk_tree_selection_real_modify_range (GtkTreeSelection *selection,
  * @end_path: The final node of the range.
  *
  * Selects a range of nodes, determined by @start_path and @end_path inclusive.
+ * @selection must be set to #GTK_SELECTION_MULTIPLE mode. 
  **/
 void
 gtk_tree_selection_select_range (GtkTreeSelection *selection,
@@ -1248,6 +1218,8 @@ gtk_tree_selection_select_range (GtkTreeSelection *selection,
 {
   g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
   g_return_if_fail (selection->tree_view != NULL);
+  g_return_if_fail (selection->type == GTK_SELECTION_MULTIPLE);
+  g_return_if_fail (selection->tree_view->priv->model != NULL);
 
   if (gtk_tree_selection_real_modify_range (selection, RANGE_SELECT, start_path, end_path))
     g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
@@ -1271,11 +1243,41 @@ gtk_tree_selection_unselect_range (GtkTreeSelection *selection,
 {
   g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
   g_return_if_fail (selection->tree_view != NULL);
+  g_return_if_fail (selection->tree_view->priv->model != NULL);
 
   if (gtk_tree_selection_real_modify_range (selection, RANGE_UNSELECT, start_path, end_path))
     g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
 }
 
+gboolean
+_gtk_tree_selection_row_is_selectable (GtkTreeSelection *selection,
+                                      GtkRBNode        *node,
+                                      GtkTreePath      *path)
+{
+  GtkTreeIter iter;
+  gboolean sensitive = FALSE;
+
+  if (!gtk_tree_model_get_iter (selection->tree_view->priv->model, &iter, path))
+    sensitive = TRUE;
+
+  if (!sensitive && selection->tree_view->priv->row_separator_func)
+    {
+      /* never allow separators to be selected */
+      if ((* selection->tree_view->priv->row_separator_func) (selection->tree_view->priv->model,
+                                                             &iter,
+                                                             selection->tree_view->priv->row_separator_data))
+       return FALSE;
+    }
+
+  if (selection->user_func)
+    return (*selection->user_func) (selection, selection->tree_view->priv->model, path,
+                                   GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED),
+                                   selection->user_data);
+  else
+    return TRUE;
+}
+
+
 /* Called internally by gtktreeview.c It handles actually selecting the tree.
  */
 
@@ -1289,7 +1291,7 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
                                          GtkRBNode        *node,
                                          GtkRBTree        *tree,
                                          GtkTreePath      *path,
-                                         GdkModifierType   state,
+                                          GtkTreeSelectMode mode,
                                          gboolean          override_browse_mode)
 {
   gint flags;
@@ -1314,7 +1316,7 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
       else if (selection->type == GTK_SELECTION_SINGLE &&
               anchor_path && gtk_tree_path_compare (path, anchor_path) == 0)
        {
-         if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
+         if ((mode & GTK_TREE_SELECT_MODE_TOGGLE) == GTK_TREE_SELECT_MODE_TOGGLE)
            {
              dirty = gtk_tree_selection_real_unselect_all (selection);
            }
@@ -1325,17 +1327,7 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
            {
              /* We only want to select the new node if we can unselect the old one,
               * and we can select the new one. */
-             if (selection->user_func)
-               {
-                 if ((*selection->user_func) (selection, selection->tree_view->priv->model, path,
-                                              GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED),
-                                              selection->user_data))
-                   dirty = TRUE;
-               }
-             else
-               {
-                 dirty = TRUE;
-               }
+             dirty = _gtk_tree_selection_row_is_selectable (selection, node, path);
 
              /* if dirty is FALSE, we weren't able to select the new one, otherwise, we try to
               * unselect the new one
@@ -1376,7 +1368,8 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
     }
   else if (selection->type == GTK_SELECTION_MULTIPLE)
     {
-      if (((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) && (anchor_path == NULL))
+      if ((mode & GTK_TREE_SELECT_MODE_EXTEND) == GTK_TREE_SELECT_MODE_EXTEND
+          && (anchor_path == NULL))
        {
          if (selection->tree_view->priv->anchor)
            gtk_tree_row_reference_free (selection->tree_view->priv->anchor);
@@ -1385,13 +1378,13 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
            gtk_tree_row_reference_new_proxy (G_OBJECT (selection->tree_view), selection->tree_view->priv->model, path);
          dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
        }
-      else if ((state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) == (GDK_SHIFT_MASK|GDK_CONTROL_MASK))
+      else if ((mode & (GTK_TREE_SELECT_MODE_EXTEND | GTK_TREE_SELECT_MODE_TOGGLE)) == (GTK_TREE_SELECT_MODE_EXTEND | GTK_TREE_SELECT_MODE_TOGGLE))
        {
          gtk_tree_selection_select_range (selection,
                                           anchor_path,
                                           path);
        }
-      else if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
+      else if ((mode & GTK_TREE_SELECT_MODE_TOGGLE) == GTK_TREE_SELECT_MODE_TOGGLE)
        {
          flags = node->flags;
          if (selection->tree_view->priv->anchor)
@@ -1405,7 +1398,7 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
          else
            dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
        }
-      else if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
+      else if ((mode & GTK_TREE_SELECT_MODE_EXTEND) == GTK_TREE_SELECT_MODE_EXTEND)
        {
          dirty = gtk_tree_selection_real_unselect_all (selection);
          dirty |= gtk_tree_selection_real_modify_range (selection,
@@ -1431,7 +1424,14 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
     gtk_tree_path_free (anchor_path);
 
   if (dirty)
-    g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
+    g_signal_emit (selection, tree_selection_signals[CHANGED], 0);  
+}
+
+
+void 
+_gtk_tree_selection_emit_changed (GtkTreeSelection *selection)
+{
+  g_signal_emit (selection, tree_selection_signals[CHANGED], 0);  
 }
 
 /* NOTE: Any {un,}selection ever done _MUST_ be done through this function!
@@ -1443,7 +1443,7 @@ gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
                                     GtkRBNode        *node,
                                     gboolean          select)
 {
-  gboolean selected = FALSE;
+  gboolean toggle = FALSE;
   GtkTreePath *path = NULL;
 
   select = !! select;
@@ -1451,19 +1451,11 @@ gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
   if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
     {
       path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
-      if (selection->user_func)
-       {
-         if ((*selection->user_func) (selection, selection->tree_view->priv->model, path,
-                                       GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED),
-                                       selection->user_data))
-           selected = TRUE;
-       }
-      else
-       selected = TRUE;
+      toggle = _gtk_tree_selection_row_is_selectable (selection, node, path);
       gtk_tree_path_free (path);
     }
 
-  if (selected == TRUE)
+  if (toggle)
     {
       node->flags ^= GTK_RBNODE_IS_SELECTED;
 
@@ -1475,3 +1467,5 @@ gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
   return FALSE;
 }
 
+#define __GTK_TREE_SELECTION_C__
+#include "gtkaliasdef.c"