* Boston, MA 02111-1307, USA.
*/
-#include <config.h>
+#include "config.h"
#include <string.h>
#include "gtktreeselection.h"
#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),
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);
}
/**
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);
selection->destroy = destroy;
}
+/**
+ * gtk_tree_selection_get_select_function:
+ * @selection: A #GtkTreeSelection.
+ *
+ * Returns the current selection function.
+ *
+ * Return value: The function.
+ *
+ * Since: 2.14
+ **/
+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.
/**
* gtk_tree_selection_get_selected:
* @selection: A #GtkTreeSelection.
- * @model: A pointer to set to the #GtkTreeModel, or NULL.
- * @iter: The #GtkTreeIter, or NULL.
+ * @model: (out) (allow-none): A pointer to set to the #GtkTreeModel, or NULL.
+ * @iter: (allow-none): The #GtkTreeIter, or NULL.
*
* Sets @iter to the currently selected node if @selection is set to
* #GTK_SELECTION_SINGLE or #GTK_SELECTION_BROWSE. @iter may be NULL if you
/**
* gtk_tree_selection_get_selected_rows:
* @selection: A #GtkTreeSelection.
- * @model: A pointer to set to the #GtkTreeModel, or NULL.
+ * @model: (allow-none): A pointer to set to the #GtkTreeModel, or NULL.
*
* Creates a list of path of all selected rows. Additionally, if you are
* planning on modifying the model after calling this function, you may
* 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_foreach (list, (GFunc) gtk_tree_path_free, NULL);
* g_list_free (list);
- * </programlisting></informalexample>
+ * ]|
*
- * Return value: A #GList containing a #GtkTreePath for each selected row.
+ * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
*
* Since: 2.2
**/
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
g_return_val_if_fail (selection->tree_view != 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)
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;
+ gulong inserted_id, deleted_id, reordered_id, changed_id;
gboolean stop = FALSE;
g_return_if_fail (GTK_IS_TREE_SELECTION (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 ();
{
if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
{
- gtk_tree_model_get_iter (selection->tree_view->priv->model,
- &iter, path);
- (* func) (selection->tree_view->priv->model, path, &iter, data);
+ gtk_tree_model_get_iter (model, &iter, path);
+ (* func) (model, path, &iter, data);
}
if (stop)
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 (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;