gtktreeselection: Move public members to a private structure

This commit is contained in:
Javier Jardón 2010-12-19 05:01:22 +00:00
parent d0b81b2148
commit 66e7915dc4
2 changed files with 212 additions and 120 deletions

View File

@ -60,6 +60,14 @@
* select_row on an already selected row).
*/
struct _GtkTreeSelectionPrivate
{
GtkTreeView *tree_view;
GtkSelectionMode type;
GtkTreeSelectionFunc user_func;
gpointer user_data;
GDestroyNotify destroy;
};
static void gtk_tree_selection_finalize (GObject *object);
static gint gtk_tree_selection_real_select_all (GtkTreeSelection *selection);
@ -106,21 +114,31 @@ gtk_tree_selection_class_init (GtkTreeSelectionClass *class)
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
g_type_class_add_private (class, sizeof (GtkTreeSelectionPrivate));
}
static void
gtk_tree_selection_init (GtkTreeSelection *selection)
{
selection->type = GTK_SELECTION_SINGLE;
GtkTreeSelectionPrivate *priv;
selection->priv = G_TYPE_INSTANCE_GET_PRIVATE (selection,
GTK_TYPE_TREE_SELECTION,
GtkTreeSelectionPrivate);
priv = selection->priv;
priv->type = GTK_SELECTION_SINGLE;
}
static void
gtk_tree_selection_finalize (GObject *object)
{
GtkTreeSelection *selection = GTK_TREE_SELECTION (object);
GtkTreeSelectionPrivate *priv = selection->priv;
if (selection->destroy)
selection->destroy (selection->user_data);
if (priv->destroy)
priv->destroy (priv->user_data);
/* chain parent_class' handler */
G_OBJECT_CLASS (gtk_tree_selection_parent_class)->finalize (object);
@ -178,11 +196,15 @@ void
_gtk_tree_selection_set_tree_view (GtkTreeSelection *selection,
GtkTreeView *tree_view)
{
GtkTreeSelectionPrivate *priv;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
if (tree_view != NULL)
g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
selection->tree_view = tree_view;
priv = selection->priv;
priv->tree_view = tree_view;
}
/**
@ -198,23 +220,26 @@ void
gtk_tree_selection_set_mode (GtkTreeSelection *selection,
GtkSelectionMode type)
{
GtkTreeSelectionPrivate *priv;
GtkTreeSelectionFunc tmp_func;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
if (selection->type == type)
priv = selection->priv;
if (priv->type == type)
return;
if (type == GTK_SELECTION_NONE)
{
/* We do this so that we unconditionally unset all rows
*/
tmp_func = selection->user_func;
selection->user_func = NULL;
tmp_func = priv->user_func;
priv->user_func = NULL;
gtk_tree_selection_unselect_all (selection);
selection->user_func = tmp_func;
priv->user_func = tmp_func;
_gtk_tree_view_set_anchor_path (selection->tree_view, NULL);
_gtk_tree_view_set_anchor_path (priv->tree_view, NULL);
}
else if (type == GTK_SELECTION_SINGLE ||
type == GTK_SELECTION_BROWSE)
@ -224,11 +249,11 @@ gtk_tree_selection_set_mode (GtkTreeSelection *selection,
gint selected = FALSE;
GtkTreePath *anchor_path = NULL;
anchor_path = _gtk_tree_view_get_anchor_path (selection->tree_view);
anchor_path = _gtk_tree_view_get_anchor_path (priv->tree_view);
if (anchor_path)
{
_gtk_tree_view_find_node (selection->tree_view,
_gtk_tree_view_find_node (priv->tree_view,
anchor_path,
&tree,
&node);
@ -239,10 +264,10 @@ gtk_tree_selection_set_mode (GtkTreeSelection *selection,
/* We do this so that we unconditionally unset all rows
*/
tmp_func = selection->user_func;
selection->user_func = NULL;
tmp_func = priv->user_func;
priv->user_func = NULL;
gtk_tree_selection_unselect_all (selection);
selection->user_func = tmp_func;
priv->user_func = tmp_func;
if (node && selected)
_gtk_tree_selection_internal_select_node (selection,
@ -255,7 +280,7 @@ gtk_tree_selection_set_mode (GtkTreeSelection *selection,
gtk_tree_path_free (anchor_path);
}
selection->type = type;
priv->type = type;
}
/**
@ -272,7 +297,7 @@ gtk_tree_selection_get_mode (GtkTreeSelection *selection)
{
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), GTK_SELECTION_SINGLE);
return selection->type;
return selection->priv->type;
}
/**
@ -295,14 +320,18 @@ gtk_tree_selection_set_select_function (GtkTreeSelection *selection,
gpointer data,
GDestroyNotify destroy)
{
GtkTreeSelectionPrivate *priv;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
if (selection->destroy)
selection->destroy (selection->user_data);
priv = selection->priv;
selection->user_func = func;
selection->user_data = data;
selection->destroy = destroy;
if (priv->destroy)
priv->destroy (priv->user_data);
priv->user_func = func;
priv->user_data = data;
priv->destroy = destroy;
}
/**
@ -320,7 +349,7 @@ gtk_tree_selection_get_select_function (GtkTreeSelection *selection)
{
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
return selection->user_func;
return selection->priv->user_func;
}
/**
@ -336,7 +365,7 @@ gtk_tree_selection_get_user_data (GtkTreeSelection *selection)
{
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
return selection->user_data;
return selection->priv->user_data;
}
/**
@ -352,7 +381,7 @@ gtk_tree_selection_get_tree_view (GtkTreeSelection *selection)
{
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
return selection->tree_view;
return selection->priv->tree_view;
}
/**
@ -374,6 +403,7 @@ gtk_tree_selection_get_selected (GtkTreeSelection *selection,
GtkTreeModel **model,
GtkTreeIter *iter)
{
GtkTreeSelectionPrivate *priv;
GtkRBTree *tree;
GtkRBNode *node;
GtkTreePath *anchor_path;
@ -381,24 +411,27 @@ gtk_tree_selection_get_selected (GtkTreeSelection *selection,
gboolean found_node;
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);
priv = selection->priv;
g_return_val_if_fail (priv->type != GTK_SELECTION_MULTIPLE, FALSE);
g_return_val_if_fail (priv->tree_view != NULL, FALSE);
/* Clear the iter */
if (iter)
memset (iter, 0, sizeof (GtkTreeIter));
if (model)
*model = gtk_tree_view_get_model (selection->tree_view);
*model = gtk_tree_view_get_model (priv->tree_view);
anchor_path = _gtk_tree_view_get_anchor_path (selection->tree_view);
anchor_path = _gtk_tree_view_get_anchor_path (priv->tree_view);
if (anchor_path == NULL)
return FALSE;
retval = FALSE;
found_node = !_gtk_tree_view_find_node (selection->tree_view,
found_node = !_gtk_tree_view_find_node (priv->tree_view,
anchor_path,
&tree,
&node);
@ -411,7 +444,7 @@ gtk_tree_selection_get_selected (GtkTreeSelection *selection,
if (iter == NULL)
retval = TRUE;
else
retval = gtk_tree_model_get_iter (gtk_tree_view_get_model (selection->tree_view),
retval = gtk_tree_model_get_iter (gtk_tree_view_get_model (priv->tree_view),
iter,
anchor_path);
}
@ -451,25 +484,29 @@ GList *
gtk_tree_selection_get_selected_rows (GtkTreeSelection *selection,
GtkTreeModel **model)
{
GtkTreeSelectionPrivate *priv;
GList *list = NULL;
GtkRBTree *tree = NULL;
GtkRBNode *node = NULL;
GtkTreePath *path;
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
g_return_val_if_fail (selection->tree_view != NULL, NULL);
priv = selection->priv;
g_return_val_if_fail (priv->tree_view != NULL, NULL);
if (model)
*model = gtk_tree_view_get_model (selection->tree_view);
*model = gtk_tree_view_get_model (priv->tree_view);
tree = _gtk_tree_view_get_rbtree (selection->tree_view);
tree = _gtk_tree_view_get_rbtree (priv->tree_view);
if (tree == NULL || tree->root == NULL)
return NULL;
if (selection->type == GTK_SELECTION_NONE)
if (priv->type == GTK_SELECTION_NONE)
return NULL;
else if (selection->type != GTK_SELECTION_MULTIPLE)
else if (priv->type != GTK_SELECTION_MULTIPLE)
{
GtkTreeIter iter;
@ -477,7 +514,7 @@ gtk_tree_selection_get_selected_rows (GtkTreeSelection *selection,
{
GtkTreePath *path;
path = gtk_tree_model_get_path (gtk_tree_view_get_model (selection->tree_view), &iter);
path = gtk_tree_model_get_path (gtk_tree_view_get_model (priv->tree_view), &iter);
list = g_list_append (list, path);
return list;
@ -574,19 +611,23 @@ gtk_tree_selection_count_selected_rows_helper (GtkRBTree *tree,
gint
gtk_tree_selection_count_selected_rows (GtkTreeSelection *selection)
{
GtkTreeSelectionPrivate *priv;
gint count = 0;
GtkRBTree *tree;
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), 0);
g_return_val_if_fail (selection->tree_view != NULL, 0);
tree = _gtk_tree_view_get_rbtree (selection->tree_view);
priv = selection->priv;
g_return_val_if_fail (priv->tree_view != NULL, 0);
tree = _gtk_tree_view_get_rbtree (priv->tree_view);
if (tree == NULL || tree->root == NULL)
return 0;
if (selection->type == GTK_SELECTION_SINGLE ||
selection->type == GTK_SELECTION_BROWSE)
if (priv->type == GTK_SELECTION_SINGLE ||
priv->type == GTK_SELECTION_BROWSE)
{
if (gtk_tree_selection_get_selected (selection, NULL, NULL))
return 1;
@ -626,6 +667,7 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
GtkTreeSelectionForeachFunc func,
gpointer data)
{
GtkTreeSelectionPrivate *priv;
GtkTreePath *path;
GtkRBTree *tree;
GtkRBNode *node;
@ -636,19 +678,22 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
gboolean stop = FALSE;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
tree = _gtk_tree_view_get_rbtree (selection->tree_view);
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
tree = _gtk_tree_view_get_rbtree (priv->tree_view);
if (func == NULL || tree == NULL || tree->root == NULL)
return;
model = gtk_tree_view_get_model (selection->tree_view);
model = gtk_tree_view_get_model (priv->tree_view);
if (selection->type == GTK_SELECTION_SINGLE ||
selection->type == GTK_SELECTION_BROWSE)
if (priv->type == GTK_SELECTION_SINGLE ||
priv->type == GTK_SELECTION_BROWSE)
{
path = _gtk_tree_view_get_anchor_path (selection->tree_view);
path = _gtk_tree_view_get_anchor_path (priv->tree_view);
if (path)
{
@ -676,7 +721,7 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
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",
changed_id = g_signal_connect_swapped (priv->tree_view, "notify::model",
G_CALLBACK (model_changed),
&stop);
@ -744,7 +789,7 @@ out:
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_signal_handler_disconnect (priv->tree_view, changed_id);
g_object_unref (model);
/* check if we have to spew a scary message */
@ -766,16 +811,20 @@ void
gtk_tree_selection_select_path (GtkTreeSelection *selection,
GtkTreePath *path)
{
GtkTreeSelectionPrivate *priv;
GtkRBNode *node;
GtkRBTree *tree;
gboolean ret;
GtkTreeSelectMode mode = 0;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
g_return_if_fail (path != NULL);
ret = _gtk_tree_view_find_node (selection->tree_view,
ret = _gtk_tree_view_find_node (priv->tree_view,
path,
&tree,
&node);
@ -784,7 +833,7 @@ gtk_tree_selection_select_path (GtkTreeSelection *selection,
ret == TRUE)
return;
if (selection->type == GTK_SELECTION_MULTIPLE)
if (priv->type == GTK_SELECTION_MULTIPLE)
mode = GTK_TREE_SELECT_MODE_TOGGLE;
_gtk_tree_selection_internal_select_node (selection,
@ -806,15 +855,19 @@ void
gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
GtkTreePath *path)
{
GtkTreeSelectionPrivate *priv;
GtkRBNode *node;
GtkRBTree *tree;
gboolean ret;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
g_return_if_fail (path != NULL);
ret = _gtk_tree_view_find_node (selection->tree_view,
ret = _gtk_tree_view_find_node (priv->tree_view,
path,
&tree,
&node);
@ -842,13 +895,17 @@ void
gtk_tree_selection_select_iter (GtkTreeSelection *selection,
GtkTreeIter *iter)
{
GtkTreeSelectionPrivate *priv;
GtkTreePath *path;
GtkTreeModel *model;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
model = gtk_tree_view_get_model (selection->tree_view);
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
model = gtk_tree_view_get_model (priv->tree_view);
g_return_if_fail (model != NULL);
g_return_if_fail (iter != NULL);
@ -873,13 +930,17 @@ void
gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
GtkTreeIter *iter)
{
GtkTreeSelectionPrivate *priv;
GtkTreePath *path;
GtkTreeModel *model;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
model = gtk_tree_view_get_model (selection->tree_view);
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
model = gtk_tree_view_get_model (priv->tree_view);
g_return_if_fail (model != NULL);
g_return_if_fail (iter != NULL);
@ -906,18 +967,22 @@ gboolean
gtk_tree_selection_path_is_selected (GtkTreeSelection *selection,
GtkTreePath *path)
{
GtkTreeSelectionPrivate *priv;
GtkRBNode *node;
GtkRBTree *tree;
gboolean ret;
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);
if (gtk_tree_view_get_model (selection->tree_view) == NULL)
priv = selection->priv;
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (priv->tree_view != NULL, FALSE);
if (gtk_tree_view_get_model (priv->tree_view) == NULL)
return FALSE;
ret = _gtk_tree_view_find_node (selection->tree_view,
ret = _gtk_tree_view_find_node (priv->tree_view,
path,
&tree,
&node);
@ -942,15 +1007,19 @@ gboolean
gtk_tree_selection_iter_is_selected (GtkTreeSelection *selection,
GtkTreeIter *iter)
{
GtkTreeSelectionPrivate *priv;
GtkTreePath *path;
GtkTreeModel *model;
gboolean retval;
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
g_return_val_if_fail (selection->tree_view != NULL, FALSE);
model = gtk_tree_view_get_model (selection->tree_view);
priv = selection->priv;
g_return_val_if_fail (iter != NULL, FALSE);
g_return_val_if_fail (priv->tree_view != NULL, FALSE);
model = gtk_tree_view_get_model (priv->tree_view);
g_return_val_if_fail (model != NULL, FALSE);
path = gtk_tree_model_get_path (model, iter);
@ -996,10 +1065,11 @@ select_all_helper (GtkRBTree *tree,
static gint
gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
{
GtkTreeSelectionPrivate *priv = selection->priv;
struct _TempTuple *tuple;
GtkRBTree *tree;
tree = _gtk_tree_view_get_rbtree (selection->tree_view);
tree = _gtk_tree_view_get_rbtree (priv->tree_view);
if (tree == NULL)
return FALSE;
@ -1032,14 +1102,19 @@ gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
void
gtk_tree_selection_select_all (GtkTreeSelection *selection)
{
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
GtkTreeSelectionPrivate *priv;
if (_gtk_tree_view_get_rbtree (selection->tree_view) == NULL ||
gtk_tree_view_get_model (selection->tree_view) == NULL)
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
if (_gtk_tree_view_get_rbtree (priv->tree_view) == NULL ||
gtk_tree_view_get_model (priv->tree_view) == NULL)
return;
g_return_if_fail (selection->type == GTK_SELECTION_MULTIPLE);
g_return_if_fail (priv->type == GTK_SELECTION_MULTIPLE);
if (gtk_tree_selection_real_select_all (selection))
g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
@ -1067,21 +1142,22 @@ unselect_all_helper (GtkRBTree *tree,
static gboolean
gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
{
GtkTreeSelectionPrivate *priv = selection->priv;
struct _TempTuple *tuple;
if (selection->type == GTK_SELECTION_SINGLE ||
selection->type == GTK_SELECTION_BROWSE)
if (priv->type == GTK_SELECTION_SINGLE ||
priv->type == GTK_SELECTION_BROWSE)
{
GtkRBTree *tree = NULL;
GtkRBNode *node = NULL;
GtkTreePath *anchor_path;
anchor_path = _gtk_tree_view_get_anchor_path (selection->tree_view);
anchor_path = _gtk_tree_view_get_anchor_path (priv->tree_view);
if (anchor_path == NULL)
return FALSE;
_gtk_tree_view_find_node (selection->tree_view,
_gtk_tree_view_find_node (priv->tree_view,
anchor_path,
&tree,
&node);
@ -1095,7 +1171,7 @@ gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
{
if (gtk_tree_selection_real_select_node (selection, tree, node, FALSE))
{
_gtk_tree_view_set_anchor_path (selection->tree_view, NULL);
_gtk_tree_view_set_anchor_path (priv->tree_view, NULL);
return TRUE;
}
}
@ -1109,7 +1185,7 @@ gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
tuple->selection = selection;
tuple->dirty = FALSE;
tree = _gtk_tree_view_get_rbtree (selection->tree_view);
tree = _gtk_tree_view_get_rbtree (priv->tree_view);
_gtk_rbtree_traverse (tree, tree->root,
G_PRE_ORDER,
unselect_all_helper,
@ -1134,11 +1210,16 @@ gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
void
gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
{
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
GtkTreeSelectionPrivate *priv;
if (_gtk_tree_view_get_rbtree (selection->tree_view) == NULL ||
gtk_tree_view_get_model (selection->tree_view) == NULL)
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
if (_gtk_tree_view_get_rbtree (priv->tree_view) == NULL ||
gtk_tree_view_get_model (priv->tree_view) == NULL)
return;
if (gtk_tree_selection_real_unselect_all (selection))
@ -1157,6 +1238,7 @@ gtk_tree_selection_real_modify_range (GtkTreeSelection *selection,
GtkTreePath *start_path,
GtkTreePath *end_path)
{
GtkTreeSelectionPrivate *priv = selection->priv;
GtkRBNode *start_node, *end_node;
GtkRBTree *start_tree, *end_tree;
GtkTreePath *anchor_path = NULL;
@ -1165,18 +1247,18 @@ gtk_tree_selection_real_modify_range (GtkTreeSelection *selection,
switch (gtk_tree_path_compare (start_path, end_path))
{
case 1:
_gtk_tree_view_find_node (selection->tree_view,
_gtk_tree_view_find_node (priv->tree_view,
end_path,
&start_tree,
&start_node);
_gtk_tree_view_find_node (selection->tree_view,
_gtk_tree_view_find_node (priv->tree_view,
start_path,
&end_tree,
&end_node);
anchor_path = start_path;
break;
case 0:
_gtk_tree_view_find_node (selection->tree_view,
_gtk_tree_view_find_node (priv->tree_view,
start_path,
&start_tree,
&start_node);
@ -1185,11 +1267,11 @@ gtk_tree_selection_real_modify_range (GtkTreeSelection *selection,
anchor_path = start_path;
break;
case -1:
_gtk_tree_view_find_node (selection->tree_view,
_gtk_tree_view_find_node (priv->tree_view,
start_path,
&start_tree,
&start_node);
_gtk_tree_view_find_node (selection->tree_view,
_gtk_tree_view_find_node (priv->tree_view,
end_path,
&end_tree,
&end_node);
@ -1201,7 +1283,7 @@ gtk_tree_selection_real_modify_range (GtkTreeSelection *selection,
g_return_val_if_fail (end_node != NULL, FALSE);
if (anchor_path)
_gtk_tree_view_set_anchor_path (selection->tree_view, anchor_path);
_gtk_tree_view_set_anchor_path (priv->tree_view, anchor_path);
do
{
@ -1247,10 +1329,15 @@ gtk_tree_selection_select_range (GtkTreeSelection *selection,
GtkTreePath *start_path,
GtkTreePath *end_path)
{
GtkTreeSelectionPrivate *priv;
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 (gtk_tree_view_get_model (selection->tree_view) != NULL);
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
g_return_if_fail (priv->type == GTK_SELECTION_MULTIPLE);
g_return_if_fail (gtk_tree_view_get_model (priv->tree_view) != NULL);
if (gtk_tree_selection_real_modify_range (selection, RANGE_SELECT, start_path, end_path))
g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
@ -1272,9 +1359,14 @@ gtk_tree_selection_unselect_range (GtkTreeSelection *selection,
GtkTreePath *start_path,
GtkTreePath *end_path)
{
GtkTreeSelectionPrivate *priv;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
g_return_if_fail (gtk_tree_view_get_model (selection->tree_view) != NULL);
priv = selection->priv;
g_return_if_fail (priv->tree_view != NULL);
g_return_if_fail (gtk_tree_view_get_model (priv->tree_view) != NULL);
if (gtk_tree_selection_real_modify_range (selection, RANGE_UNSELECT, start_path, end_path))
g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
@ -1285,15 +1377,16 @@ _gtk_tree_selection_row_is_selectable (GtkTreeSelection *selection,
GtkRBNode *node,
GtkTreePath *path)
{
GtkTreeSelectionPrivate *priv = selection->priv;
GtkTreeIter iter;
GtkTreeModel *model;
GtkTreeViewRowSeparatorFunc separator_func;
gpointer separator_data;
gboolean sensitive = FALSE;
model = gtk_tree_view_get_model (selection->tree_view);
model = gtk_tree_view_get_model (priv->tree_view);
_gtk_tree_view_get_row_separator_func (selection->tree_view,
_gtk_tree_view_get_row_separator_func (priv->tree_view,
&separator_func, &separator_data);
if (!gtk_tree_model_get_iter (model, &iter, path))
@ -1306,10 +1399,10 @@ _gtk_tree_selection_row_is_selectable (GtkTreeSelection *selection,
return FALSE;
}
if (selection->user_func)
return (*selection->user_func) (selection, model, path,
if (priv->user_func)
return (*priv->user_func) (selection, model, path,
GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED),
selection->user_data);
priv->user_data);
else
return TRUE;
}
@ -1331,25 +1424,26 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
GtkTreeSelectMode mode,
gboolean override_browse_mode)
{
GtkTreeSelectionPrivate *priv = selection->priv;
gint flags;
gint dirty = FALSE;
GtkTreePath *anchor_path = NULL;
if (selection->type == GTK_SELECTION_NONE)
if (priv->type == GTK_SELECTION_NONE)
return;
anchor_path = _gtk_tree_view_get_anchor_path (selection->tree_view);
anchor_path = _gtk_tree_view_get_anchor_path (priv->tree_view);
if (selection->type == GTK_SELECTION_SINGLE ||
selection->type == GTK_SELECTION_BROWSE)
if (priv->type == GTK_SELECTION_SINGLE ||
priv->type == GTK_SELECTION_BROWSE)
{
/* just unselect */
if (selection->type == GTK_SELECTION_BROWSE && override_browse_mode)
if (priv->type == GTK_SELECTION_BROWSE && override_browse_mode)
{
dirty = gtk_tree_selection_real_unselect_all (selection);
}
/* Did we try to select the same node again? */
else if (selection->type == GTK_SELECTION_SINGLE &&
else if (priv->type == GTK_SELECTION_SINGLE &&
anchor_path && gtk_tree_path_compare (path, anchor_path) == 0)
{
if ((mode & GTK_TREE_SELECT_MODE_TOGGLE) == GTK_TREE_SELECT_MODE_TOGGLE)
@ -1376,10 +1470,10 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
if (dirty)
{
_gtk_tree_view_set_anchor_path (selection->tree_view, NULL);
_gtk_tree_view_set_anchor_path (priv->tree_view, NULL);
if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
_gtk_tree_view_set_anchor_path (priv->tree_view, path);
}
}
else
@ -1388,17 +1482,17 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
{
dirty = TRUE;
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
_gtk_tree_view_set_anchor_path (priv->tree_view, path);
}
}
}
}
else if (selection->type == GTK_SELECTION_MULTIPLE)
else if (priv->type == GTK_SELECTION_MULTIPLE)
{
if ((mode & GTK_TREE_SELECT_MODE_EXTEND) == GTK_TREE_SELECT_MODE_EXTEND
&& (anchor_path == NULL))
{
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
_gtk_tree_view_set_anchor_path (priv->tree_view, path);
dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
}
@ -1412,7 +1506,7 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
{
flags = node->flags;
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
_gtk_tree_view_set_anchor_path (priv->tree_view, path);
if ((flags & GTK_RBNODE_IS_SELECTED) == GTK_RBNODE_IS_SELECTED)
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
@ -1431,7 +1525,7 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
{
dirty = gtk_tree_selection_real_unselect_all (selection);
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
_gtk_tree_view_set_anchor_path (priv->tree_view, path);
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
}
@ -1460,6 +1554,7 @@ gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
GtkRBNode *node,
gboolean select)
{
GtkTreeSelectionPrivate *priv = selection->priv;
gboolean toggle = FALSE;
GtkTreePath *path = NULL;
@ -1467,7 +1562,7 @@ 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);
path = _gtk_tree_view_find_path (priv->tree_view, tree, node);
toggle = _gtk_tree_selection_row_is_selectable (selection, node, path);
gtk_tree_path_free (path);
}
@ -1476,8 +1571,8 @@ gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
{
node->flags ^= GTK_RBNODE_IS_SELECTED;
_gtk_tree_view_queue_draw_node (selection->tree_view, tree, node, NULL);
_gtk_tree_view_queue_draw_node (priv->tree_view, tree, node, NULL);
return TRUE;
}

View File

@ -36,6 +36,8 @@ G_BEGIN_DECLS
#define GTK_IS_TREE_SELECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TREE_SELECTION))
#define GTK_TREE_SELECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TREE_SELECTION, GtkTreeSelectionClass))
typedef struct _GtkTreeSelectionPrivate GtkTreeSelectionPrivate;
/**
* GtkTreeSelectionFunc:
* @selection: A #GtkTreeSelection
@ -74,15 +76,10 @@ typedef void (* GtkTreeSelectionForeachFunc) (GtkTreeModel *model,
struct _GtkTreeSelection
{
/*< private >*/
GObject parent;
/*< private >*/
GtkTreeView *GSEAL (tree_view);
GtkSelectionMode GSEAL (type);
GtkTreeSelectionFunc GSEAL (user_func);
gpointer GSEAL (user_data);
GDestroyNotify GSEAL (destroy);
GtkTreeSelectionPrivate *priv;
};
struct _GtkTreeSelectionClass