#include "gtktreeprivate.h"
#include "gtkrbtree.h"
#include "gtkmarshalers.h"
+#include "gtkintl.h"
#include "gtkalias.h"
-static void gtk_tree_selection_init (GtkTreeSelection *selection);
-static void gtk_tree_selection_class_init (GtkTreeSelectionClass *class);
-
static void gtk_tree_selection_finalize (GObject *object);
static gint gtk_tree_selection_real_select_all (GtkTreeSelection *selection);
static gint gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection);
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)
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),
}
/* chain parent_class' handler */
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_tree_selection_parent_class)->finalize (object);
}
/**
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);
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,
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);
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 */
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);
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");
}
/**
g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
}
-static gboolean
-tree_column_is_sensitive (GtkTreeViewColumn *column,
- GtkTreeModel *model,
- GtkTreeIter *iter)
-{
- GList *cells, *list;
- gboolean sensitive;
- gboolean visible;
-
- gtk_tree_view_column_cell_set_cell_data (column, model,
- iter, FALSE, FALSE);
-
- cells = gtk_tree_view_column_get_cell_renderers (column);
-
- list = cells;
- while (list)
- {
- g_object_get (list->data,
- "sensitive", &sensitive,
- "visible", &visible,
- NULL);
-
- if (visible && sensitive)
- break;
-
- list = list->next;
- }
- g_list_free (cells);
-
- return sensitive;
-}
-
-static gboolean
-row_is_selectable (GtkTreeSelection *selection,
- GtkRBNode *node,
- GtkTreePath *path)
+gboolean
+_gtk_tree_selection_row_is_selectable (GtkTreeSelection *selection,
+ GtkRBNode *node,
+ GtkTreePath *path)
{
- GList *list;
GtkTreeIter iter;
gboolean sensitive = FALSE;
return FALSE;
}
- for (list = selection->tree_view->priv->columns; list && !sensitive; list = list->next)
- {
- GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
-
- if (!column->visible)
- continue;
-
- sensitive = tree_column_is_sensitive (column, selection->tree_view->priv->model, &iter);
- }
-
- if (!sensitive)
- 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),
{
/* We only want to select the new node if we can unselect the old one,
* and we can select the new one. */
- dirty = row_is_selectable (selection, node, path);
+ 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
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!
GtkRBNode *node,
gboolean select)
{
- gboolean selected = FALSE;
+ gboolean toggle = FALSE;
GtkTreePath *path = NULL;
select = !! select;
if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
{
path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
- selected = row_is_selectable (selection, node, path);
+ 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;