gtk2/gtk/gtktreeselection.c

1569 lines
43 KiB
C
Raw Normal View History

/* gtktreeselection.h
* Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
2012-02-27 13:01:10 +00:00
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
2004-10-28 15:00:05 +00:00
#include <string.h>
#include "gtktreeselection.h"
#include "gtktreeprivate.h"
#include "gtktreerbtreeprivate.h"
#include "gtkmarshalers.h"
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtktypebuiltins.h"
/**
2021-03-02 03:50:53 +00:00
* GtkTreeSelection:
*
* The selection object for GtkTreeView
*
* The `GtkTreeSelection` object is a helper object to manage the selection
* for a `GtkTreeView` widget. The `GtkTreeSelection` object is
* automatically created when a new `GtkTreeView` widget is created, and
* cannot exist independently of this widget. The primary reason the
* `GtkTreeSelection` objects exists is for cleanliness of code and API.
* That is, there is no conceptual reason all these functions could not be
* methods on the `GtkTreeView` widget instead of a separate function.
*
* The `GtkTreeSelection` object is gotten from a `GtkTreeView` by calling
* gtk_tree_view_get_selection(). It can be manipulated to check the
* selection status of the tree, as well as select and deselect individual
* rows. Selection is done completely view side. As a result, multiple
* views of the same model can have completely different selections.
* Additionally, you cannot change the selection of a row on the model that
* is not currently displayed by the view without expanding its parents
* first.
*
* One of the important things to remember when monitoring the selection of
* a view is that the `GtkTreeSelection`::changed signal is mostly a hint.
2012-12-12 02:30:22 +00:00
* That is, it may only emit one signal when a range of rows is selected.
* Additionally, it may on occasion emit a `GtkTreeSelection`::changed signal
* when nothing has happened (mostly as a result of programmers calling
* select_row on an already selected row).
*/
typedef struct _GtkTreeSelectionClass GtkTreeSelectionClass;
struct _GtkTreeSelection
{
GObject parent;
GtkTreeView *tree_view;
GtkSelectionMode type;
GtkTreeSelectionFunc user_func;
gpointer user_data;
GDestroyNotify destroy;
};
struct _GtkTreeSelectionClass
{
GObjectClass parent_class;
void (* changed) (GtkTreeSelection *selection);
};
static void gtk_tree_selection_finalize (GObject *object);
2020-07-24 13:54:49 +00:00
static int gtk_tree_selection_real_select_all (GtkTreeSelection *selection);
static int gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection);
static int gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
GtkTreeRBTree *tree,
GtkTreeRBNode *node,
gboolean select);
static void gtk_tree_selection_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_tree_selection_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
enum
{
PROP_0,
PROP_MODE,
N_PROPERTIES
};
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
enum
{
CHANGED,
LAST_SIGNAL
};
static GParamSpec *properties[N_PROPERTIES];
static guint tree_selection_signals [LAST_SIGNAL] = { 0 };
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;
object_class->finalize = gtk_tree_selection_finalize;
object_class->set_property = gtk_tree_selection_set_property;
object_class->get_property = gtk_tree_selection_get_property;
class->changed = NULL;
doh, this was broken beyond believe. Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org> * gtk/stock-icons/Makefile.am: doh, this was broken beyond believe. * gtk/gtkbox.c: change property types from (u)long to (u)int for ::position and ::padding. * gtk/gtkcontainer.c: make ::border_width an INT property. * gtk/gtkpacker.c: make ::position an INT property. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed): guard against NULL h/v scrollbars, since this is used at construction time. * gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented internal gtk_clist_constructor(). * gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented gtk_ctree_constructor(). * gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property ::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION. * docs/reference/Makefile.am: fun stuff, disabled docs generation again, gtk-scan.c needs to introspec paramspecs, not GtkAgs. * gtk/gtkwidget.[hc]: removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv() and gtk_widget_get(). (gtk_widget_new): use g_object_new_valist(). (gtk_widget_set): use g_object_set_valist(). * gtk/gtkobject.[hc]: removed gtk_object_arg_get_info(), gtk_object_getv(), gtk_object_query_args(), gtk_object_newv(), gtk_object_class_add_signals(), gtk_object_class_user_signal_new(), gtk_object_class_user_signal_newv(), gtk_object_arg_set(), gtk_object_arg_get(), gtk_object_args_collect(), gtk_object_default_construct(), gtk_object_constructed(), GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED(). removed nsignals, signals and n_args members from GtkObjectClass. (gtk_object_new): use g_object_new_valist(). (gtk_object_set): use g_object_set_valist(). (gtk_object_get): use g_object_get_valist(). * gtk/gtkcompat.h: define gtk_object_default_construct(). * gtk/gtktypeutils.c (gtk_type_new): create constructed objects via g_object_new(). * gtk/*.c: removed gtk_object_class_add_signals() from class_init() fucntions, cleaned up method assignments (make sure your structures are setup properly before calling out). removed all GTK_CONSTRUCTED hacks ;)
2000-12-13 01:34:41 +00:00
/* Properties */
/**
* GtkTreeSelection:mode:
*
* Selection mode.
* See gtk_tree_selection_set_mode() for more information on this property.
*/
properties[PROP_MODE] = g_param_spec_enum ("mode", NULL, NULL,
GTK_TYPE_SELECTION_MODE,
GTK_SELECTION_SINGLE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
/* Install all properties */
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
/* Signals */
/**
* GtkTreeSelection::changed:
* @treeselection: the object which received the signal.
*
* Emitted whenever the selection has (possibly) changed. Please note that
* this signal is mostly a hint. It may only be emitted once when a range
* of rows are selected, and it may occasionally be emitted when nothing
* has happened.
*/
tree_selection_signals[CHANGED] =
g_signal_new (I_("changed"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkTreeSelectionClass, changed),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
}
static void
gtk_tree_selection_init (GtkTreeSelection *selection)
{
selection->type = GTK_SELECTION_SINGLE;
}
static void
gtk_tree_selection_finalize (GObject *object)
{
GtkTreeSelection *selection = GTK_TREE_SELECTION (object);
if (selection->destroy)
selection->destroy (selection->user_data);
/* chain parent_class' handler */
2006-05-02 23:56:43 +00:00
G_OBJECT_CLASS (gtk_tree_selection_parent_class)->finalize (object);
}
static void
gtk_tree_selection_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
g_return_if_fail (GTK_IS_TREE_SELECTION (object));
switch (prop_id)
{
case PROP_MODE:
gtk_tree_selection_set_mode (GTK_TREE_SELECTION (object), g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_tree_selection_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
g_return_if_fail (GTK_IS_TREE_SELECTION (object));
switch (prop_id)
{
case PROP_MODE:
g_value_set_enum (value, gtk_tree_selection_get_mode (GTK_TREE_SELECTION (object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
* _gtk_tree_selection_new:
*
* Creates a new `GtkTreeSelection` object. This function should not be invoked,
* as each `GtkTreeView` will create its own `GtkTreeSelection`.
*
* Returns: A newly created `GtkTreeSelection` object.
**/
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
GtkTreeSelection*
_gtk_tree_selection_new (void)
{
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
GtkTreeSelection *selection;
selection = g_object_new (GTK_TYPE_TREE_SELECTION, NULL);
return selection;
}
/**
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
* _gtk_tree_selection_new_with_tree_view:
* @tree_view: The `GtkTreeView`.
*
* Creates a new `GtkTreeSelection` object. This function should not be invoked,
* as each `GtkTreeView` will create its own `GtkTreeSelection`.
*
* Returns: A newly created `GtkTreeSelection` object.
**/
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
GtkTreeSelection*
_gtk_tree_selection_new_with_tree_view (GtkTreeView *tree_view)
{
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
GtkTreeSelection *selection;
g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL);
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
selection = _gtk_tree_selection_new ();
_gtk_tree_selection_set_tree_view (selection, tree_view);
return selection;
}
/**
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
* _gtk_tree_selection_set_tree_view:
* @selection: A `GtkTreeSelection`.
* @tree_view: The `GtkTreeView`.
*
* Sets the `GtkTreeView` of @selection. This function should not be invoked, as
* it is used internally by `GtkTreeView`.
**/
void
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
_gtk_tree_selection_set_tree_view (GtkTreeSelection *selection,
GtkTreeView *tree_view)
{
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;
}
/**
* gtk_tree_selection_set_mode:
* @selection: A `GtkTreeSelection`.
* @type: The selection mode
*
* Sets the selection mode of the @selection. If the previous type was
* %GTK_SELECTION_MULTIPLE, then the anchor is kept selected, if it was
* previously selected.
**/
void
gtk_tree_selection_set_mode (GtkTreeSelection *selection,
GtkSelectionMode type)
{
GtkTreeSelectionFunc tmp_func;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
if (selection->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;
gtk_tree_selection_unselect_all (selection);
selection->user_func = tmp_func;
_gtk_tree_view_set_anchor_path (selection->tree_view, NULL);
}
else if (type == GTK_SELECTION_SINGLE ||
type == GTK_SELECTION_BROWSE)
{
GtkTreeRBTree *tree = NULL;
GtkTreeRBNode *node = NULL;
2020-07-24 13:54:49 +00:00
int selected = FALSE;
GtkTreePath *anchor_path = NULL;
anchor_path = _gtk_tree_view_get_anchor_path (selection->tree_view);
if (anchor_path)
{
_gtk_tree_view_find_node (selection->tree_view,
anchor_path,
&tree,
&node);
if (node && GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
selected = TRUE;
}
/* We do this so that we unconditionally unset all rows
*/
tmp_func = selection->user_func;
selection->user_func = NULL;
gtk_tree_selection_unselect_all (selection);
selection->user_func = tmp_func;
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
if (node && selected)
_gtk_tree_selection_internal_select_node (selection,
node,
tree,
anchor_path,
0,
FALSE);
if (anchor_path)
gtk_tree_path_free (anchor_path);
}
selection->type = type;
g_object_notify_by_pspec (G_OBJECT (selection), properties[PROP_MODE]);
}
/**
* gtk_tree_selection_get_mode:
* @selection: a `GtkTreeSelection`
*
* Gets the selection mode for @selection. See
* gtk_tree_selection_set_mode().
*
* Returns: the current selection mode
**/
GtkSelectionMode
gtk_tree_selection_get_mode (GtkTreeSelection *selection)
{
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), GTK_SELECTION_SINGLE);
return selection->type;
}
/**
* gtk_tree_selection_set_select_function:
* @selection: A `GtkTreeSelection`.
* @func: (nullable): The selection function. May be %NULL
* @data: The selection functions data. May be %NULL
* @destroy: The destroy function for user data. May be %NULL
*
* Sets the selection function.
*
* If set, this function is called before any node is selected or unselected,
* giving some control over which nodes are selected. The select function
* should return %TRUE if the state of the node may be toggled, and %FALSE
* if the state of the node should be left unchanged.
*/
void
gtk_tree_selection_set_select_function (GtkTreeSelection *selection,
GtkTreeSelectionFunc func,
gpointer data,
GDestroyNotify destroy)
{
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
if (selection->destroy)
selection->destroy (selection->user_data);
selection->user_func = func;
selection->user_data = data;
selection->destroy = destroy;
}
/**
2010-09-18 16:42:15 +00:00
* gtk_tree_selection_get_select_function: (skip)
* @selection: A `GtkTreeSelection`.
*
* Returns the current selection function.
*
* Returns: The function.
**/
GtkTreeSelectionFunc
gtk_tree_selection_get_select_function (GtkTreeSelection *selection)
{
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
return selection->user_func;
}
/**
2010-09-18 16:42:15 +00:00
* gtk_tree_selection_get_user_data: (skip)
* @selection: A `GtkTreeSelection`.
*
* Returns the user data for the selection function.
*
* Returns: The user data.
**/
gpointer
gtk_tree_selection_get_user_data (GtkTreeSelection *selection)
{
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
return selection->user_data;
}
/**
* gtk_tree_selection_get_tree_view:
* @selection: A `GtkTreeSelection`
*
* Returns the tree view associated with @selection.
*
* Returns: (transfer none): A `GtkTreeView`
**/
GtkTreeView *
gtk_tree_selection_get_tree_view (GtkTreeSelection *selection)
{
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
return selection->tree_view;
}
/**
* gtk_tree_selection_get_selected:
* @selection: A `GtkTreeSelection`.
* @model: (out) (optional) (transfer none): A pointer to set to the `GtkTreeModel`
* @iter: (out) (optional): The `GtkTreeIter`
*
* 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
* just want to test if @selection has any selected nodes. @model is filled
* with the current model as a convenience. This function will not work if you
* use @selection is %GTK_SELECTION_MULTIPLE.
*
* Returns: TRUE, if there is a selected node.
**/
gboolean
gtk_tree_selection_get_selected (GtkTreeSelection *selection,
GtkTreeModel **model,
GtkTreeIter *iter)
{
GtkTreeRBTree *tree;
GtkTreeRBNode *node;
GtkTreePath *anchor_path;
gboolean retval = FALSE;
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);
/* Clear the iter */
if (iter)
memset (iter, 0, sizeof (GtkTreeIter));
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
if (model)
*model = gtk_tree_view_get_model (selection->tree_view);
anchor_path = _gtk_tree_view_get_anchor_path (selection->tree_view);
if (anchor_path == NULL)
return FALSE;
found_node = !_gtk_tree_view_find_node (selection->tree_view,
anchor_path,
&tree,
&node);
if (found_node && GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
{
/* we only want to return the anchor if it exists in the rbtree and
* is selected.
*/
if (iter == NULL)
retval = TRUE;
else
retval = gtk_tree_model_get_iter (gtk_tree_view_get_model (selection->tree_view),
iter,
anchor_path);
}
else
{
/* We don't want to return the anchor if it isn't actually selected.
*/
retval = FALSE;
}
gtk_tree_path_free (anchor_path);
return retval;
}
/**
* gtk_tree_selection_get_selected_rows:
* @selection: A `GtkTreeSelection`.
* @model: (out) (optional) (transfer none): A pointer to set to the `GtkTreeModel`
*
* 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().
*
* To free the return value, use:
* |[<!-- language="C" -->
2011-12-10 04:26:06 +00:00
* g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
* ]|
*
* Returns: (element-type GtkTreePath) (transfer full): A `GList` containing a `GtkTreePath` for each selected row.
**/
GList *
gtk_tree_selection_get_selected_rows (GtkTreeSelection *selection,
GtkTreeModel **model)
{
GList *list = NULL;
GtkTreeRBTree *tree = NULL;
GtkTreeRBNode *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);
if (model)
*model = gtk_tree_view_get_model (selection->tree_view);
tree = _gtk_tree_view_get_rbtree (selection->tree_view);
if (tree == NULL || tree->root == NULL)
return NULL;
if (selection->type == GTK_SELECTION_NONE)
return NULL;
else if (selection->type != GTK_SELECTION_MULTIPLE)
{
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
{
path = gtk_tree_model_get_path (gtk_tree_view_get_model (selection->tree_view), &iter);
list = g_list_append (list, path);
return list;
}
return NULL;
}
node = gtk_tree_rbtree_first (tree);
path = gtk_tree_path_new_first ();
while (node != NULL)
{
if (GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
list = g_list_prepend (list, gtk_tree_path_copy (path));
if (node->children)
{
tree = node->children;
node = gtk_tree_rbtree_first (tree);
gtk_tree_path_append_index (path, 0);
}
else
{
gboolean done = FALSE;
do
{
node = gtk_tree_rbtree_next (tree, node);
if (node != NULL)
{
done = TRUE;
gtk_tree_path_next (path);
}
else
{
node = tree->parent_node;
tree = tree->parent_tree;
if (!tree)
{
gtk_tree_path_free (path);
goto done;
}
gtk_tree_path_up (path);
}
}
while (!done);
}
}
gtk_tree_path_free (path);
done:
return g_list_reverse (list);
}
static void
gtk_tree_selection_count_selected_rows_helper (GtkTreeRBTree *tree,
GtkTreeRBNode *node,
gpointer data)
{
2020-07-24 13:54:49 +00:00
int *count = (int *)data;
g_return_if_fail (node != NULL);
if (GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
(*count)++;
if (node->children)
gtk_tree_rbtree_traverse (node->children, node->children->root,
G_PRE_ORDER,
gtk_tree_selection_count_selected_rows_helper, data);
}
/**
* gtk_tree_selection_count_selected_rows:
* @selection: A `GtkTreeSelection`.
*
* Returns the number of rows that have been selected in @tree.
*
* Returns: The number of rows selected.
**/
2020-07-24 13:54:49 +00:00
int
gtk_tree_selection_count_selected_rows (GtkTreeSelection *selection)
{
2020-07-24 13:54:49 +00:00
int count = 0;
GtkTreeRBTree *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);
if (tree == NULL || tree->root == NULL)
return 0;
if (selection->type == GTK_SELECTION_SINGLE ||
selection->type == GTK_SELECTION_BROWSE)
{
if (gtk_tree_selection_get_selected (selection, NULL, NULL))
return 1;
else
return 0;
}
gtk_tree_rbtree_traverse (tree, tree->root,
G_PRE_ORDER,
gtk_tree_selection_count_selected_rows_helper,
&count);
return count;
}
2002-10-22 23:05:29 +00:00
/* gtk_tree_selection_selected_foreach helper */
static void
model_changed (gpointer data)
{
gboolean *stop = (gboolean *)data;
*stop = TRUE;
}
/**
* gtk_tree_selection_selected_foreach:
* @selection: A `GtkTreeSelection`.
2010-09-18 16:42:15 +00:00
* @func: (scope call): The function to call for each selected node.
* @data: user data to pass to the function.
*
* Calls a function for each selected node. Note that you cannot modify
* the tree or selection from within this function. As a result,
* gtk_tree_selection_get_selected_rows() might be more useful.
**/
void
gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
GtkTreeSelectionForeachFunc func,
gpointer data)
{
GtkTreePath *path;
GtkTreeRBTree *tree;
GtkTreeRBNode *node;
GtkTreeIter iter;
GtkTreeModel *model;
gulong inserted_id, deleted_id, reordered_id, changed_id;
gboolean stop = FALSE;
2002-10-22 23:05:29 +00:00
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);
if (func == NULL || tree == NULL || tree->root == NULL)
return;
model = gtk_tree_view_get_model (selection->tree_view);
if (selection->type == GTK_SELECTION_SINGLE ||
selection->type == GTK_SELECTION_BROWSE)
{
path = _gtk_tree_view_get_anchor_path (selection->tree_view);
if (path)
{
gtk_tree_model_get_iter (model, &iter, path);
(* func) (model, path, &iter, data);
gtk_tree_path_free (path);
}
return;
}
node = gtk_tree_rbtree_first (tree);
g_object_ref (model);
2002-10-22 23:05:29 +00:00
/* connect to signals to monitor changes in treemodel */
inserted_id = g_signal_connect_swapped (model, "row-inserted",
2002-10-22 23:05:29 +00:00
G_CALLBACK (model_changed),
&stop);
deleted_id = g_signal_connect_swapped (model, "row-deleted",
2002-10-22 23:05:29 +00:00
G_CALLBACK (model_changed),
&stop);
reordered_id = g_signal_connect_swapped (model, "rows-reordered",
2002-10-22 23:05:29 +00:00
G_CALLBACK (model_changed),
&stop);
changed_id = g_signal_connect_swapped (selection->tree_view, "notify::model",
G_CALLBACK (model_changed),
&stop);
2002-10-22 23:05:29 +00:00
/* find the node internally */
path = gtk_tree_path_new_first ();
while (node != NULL)
{
if (GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
{
gtk_tree_model_get_iter (model, &iter, path);
(* func) (model, path, &iter, data);
}
2002-10-22 23:05:29 +00:00
if (stop)
goto out;
if (node->children)
{
tree = node->children;
node = gtk_tree_rbtree_first (tree);
2002-10-22 23:05:29 +00:00
gtk_tree_path_append_index (path, 0);
}
else
{
gboolean done = FALSE;
do
{
node = gtk_tree_rbtree_next (tree, node);
if (node != NULL)
{
done = TRUE;
gtk_tree_path_next (path);
}
else
{
node = tree->parent_node;
tree = tree->parent_tree;
if (tree == NULL)
{
/* we've run out of tree */
/* We're done with this function */
2002-10-22 23:05:29 +00:00
goto out;
}
2002-10-22 23:05:29 +00:00
gtk_tree_path_up (path);
}
}
while (!done);
}
}
2002-10-22 23:05:29 +00:00
out:
if (path)
gtk_tree_path_free (path);
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);
2002-10-22 23:05:29 +00:00
/* 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.");
}
/**
* gtk_tree_selection_select_path:
* @selection: A `GtkTreeSelection`.
* @path: The `GtkTreePath` to be selected.
*
* Select the row at @path.
**/
void
gtk_tree_selection_select_path (GtkTreeSelection *selection,
GtkTreePath *path)
{
GtkTreeRBNode *node;
GtkTreeRBTree *tree;
gboolean ret;
GtkTreeSelectMode mode = 0;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
g_return_if_fail (path != NULL);
ret = _gtk_tree_view_find_node (selection->tree_view,
path,
&tree,
&node);
if (node == NULL || GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED) ||
ret == TRUE)
return;
if (selection->type == GTK_SELECTION_MULTIPLE)
mode = GTK_TREE_SELECT_MODE_TOGGLE;
_gtk_tree_selection_internal_select_node (selection,
node,
tree,
path,
mode,
FALSE);
}
/**
* gtk_tree_selection_unselect_path:
* @selection: A `GtkTreeSelection`.
* @path: The `GtkTreePath` to be unselected.
*
* Unselects the row at @path.
**/
void
gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
GtkTreePath *path)
{
GtkTreeRBNode *node;
GtkTreeRBTree *tree;
gboolean ret;
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
g_return_if_fail (selection->tree_view != NULL);
g_return_if_fail (path != NULL);
ret = _gtk_tree_view_find_node (selection->tree_view,
path,
&tree,
&node);
if (node == NULL || !GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED) ||
ret == TRUE)
return;
_gtk_tree_selection_internal_select_node (selection,
node,
tree,
path,
GTK_TREE_SELECT_MODE_TOGGLE,
TRUE);
}
/**
* gtk_tree_selection_select_iter:
* @selection: A `GtkTreeSelection`.
* @iter: The `GtkTreeIter` to be selected.
*
* Selects the specified iterator.
**/
void
gtk_tree_selection_select_iter (GtkTreeSelection *selection,
GtkTreeIter *iter)
{
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);
g_return_if_fail (model != NULL);
g_return_if_fail (iter != NULL);
path = gtk_tree_model_get_path (model, iter);
if (path == NULL)
return;
gtk_tree_selection_select_path (selection, path);
gtk_tree_path_free (path);
}
/**
* gtk_tree_selection_unselect_iter:
* @selection: A `GtkTreeSelection`.
* @iter: The `GtkTreeIter` to be unselected.
*
* Unselects the specified iterator.
**/
void
gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
GtkTreeIter *iter)
{
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);
g_return_if_fail (model != NULL);
g_return_if_fail (iter != NULL);
path = gtk_tree_model_get_path (model, iter);
if (path == NULL)
return;
gtk_tree_selection_unselect_path (selection, path);
gtk_tree_path_free (path);
}
/**
* gtk_tree_selection_path_is_selected:
* @selection: A `GtkTreeSelection`.
* @path: A `GtkTreePath` to check selection on.
*
* Returns %TRUE if the row pointed to by @path is currently selected. If @path
* does not point to a valid location, %FALSE is returned
*
* Returns: %TRUE if @path is selected.
**/
gboolean
gtk_tree_selection_path_is_selected (GtkTreeSelection *selection,
GtkTreePath *path)
{
GtkTreeRBNode *node;
GtkTreeRBTree *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);
Fix #139290: 2004-07-08 Federico Mena Quintero <federico@ximian.com> Fix #139290: * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_new): Add a GError argument. Do check for errors when getting the GtkFileFolder: get the folder and read the children before actually creating the model. Removed obsolete code that handled roots-changed on the file system. (file_model_node_get_info): Assert that we don't reach the old case to display file system roots. (roots_changed_callback): Removed. * gtk/gtkfilechooserdefault.c (set_list_model): Add a GError argument, and a boolean return value. Return an error if we cannot create the file system model. On error, set a NULL model on the tree. (gtk_file_chooser_default_set_current_folder): Use the error value from set_list_model(). (gtk_file_chooser_default_set_property): Set the show_hidden property only if the browse_files_model exists. (gtk_file_chooser_default_unselect_path): Only operate if the browse_files_model exists. (check_preview_change): Check whether we have the sort_model. (change_folder_and_display_error): Copy the path we get passed before using it. There's a comment in there that explains why we need to copy it; basically, if the passed path belongs to the model, the model may go away in the middle of this function and we'll be left with a dangling pointer. (install_list_model_filter): Assert that the model is not NULL. (set_current_filter): Check whether the model exists. * gtk/gtktreeselection.c (gtk_tree_selection_get_selected): Don't g_return_if_fail if the model is NULL. (gtk_tree_selection_get_selected_rows): Likewise. (gtk_tree_selection_count_selected_rows): Likewise. (gtk_tree_selection_selected_foreach): Likewise. (gtk_tree_selection_path_is_selected): Likewise; rather just return FALSE. (gtk_tree_selection_select_all): Likewise. (gtk_tree_selection_unselect_all): Likewise. (gtk_tree_selection_select_range): Do g_return_if_fail() if the model is NULL. (gtk_tree_selection_unselect_range): Likewise. * gtk/gtkfilesystemunix.c (fill_in_names): Return immediately if g_dir_open() fails: there is no need to set the error ourselves, as g_dir_open() already does it.
2004-07-09 00:53:48 +00:00
if (gtk_tree_view_get_model (selection->tree_view) == NULL)
Fix #139290: 2004-07-08 Federico Mena Quintero <federico@ximian.com> Fix #139290: * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_new): Add a GError argument. Do check for errors when getting the GtkFileFolder: get the folder and read the children before actually creating the model. Removed obsolete code that handled roots-changed on the file system. (file_model_node_get_info): Assert that we don't reach the old case to display file system roots. (roots_changed_callback): Removed. * gtk/gtkfilechooserdefault.c (set_list_model): Add a GError argument, and a boolean return value. Return an error if we cannot create the file system model. On error, set a NULL model on the tree. (gtk_file_chooser_default_set_current_folder): Use the error value from set_list_model(). (gtk_file_chooser_default_set_property): Set the show_hidden property only if the browse_files_model exists. (gtk_file_chooser_default_unselect_path): Only operate if the browse_files_model exists. (check_preview_change): Check whether we have the sort_model. (change_folder_and_display_error): Copy the path we get passed before using it. There's a comment in there that explains why we need to copy it; basically, if the passed path belongs to the model, the model may go away in the middle of this function and we'll be left with a dangling pointer. (install_list_model_filter): Assert that the model is not NULL. (set_current_filter): Check whether the model exists. * gtk/gtktreeselection.c (gtk_tree_selection_get_selected): Don't g_return_if_fail if the model is NULL. (gtk_tree_selection_get_selected_rows): Likewise. (gtk_tree_selection_count_selected_rows): Likewise. (gtk_tree_selection_selected_foreach): Likewise. (gtk_tree_selection_path_is_selected): Likewise; rather just return FALSE. (gtk_tree_selection_select_all): Likewise. (gtk_tree_selection_unselect_all): Likewise. (gtk_tree_selection_select_range): Do g_return_if_fail() if the model is NULL. (gtk_tree_selection_unselect_range): Likewise. * gtk/gtkfilesystemunix.c (fill_in_names): Return immediately if g_dir_open() fails: there is no need to set the error ourselves, as g_dir_open() already does it.
2004-07-09 00:53:48 +00:00
return FALSE;
ret = _gtk_tree_view_find_node (selection->tree_view,
path,
&tree,
&node);
if ((node == NULL) || !GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED) ||
ret == TRUE)
return FALSE;
return TRUE;
}
/**
* gtk_tree_selection_iter_is_selected:
* @selection: A `GtkTreeSelection`
* @iter: A valid `GtkTreeIter`
*
Minor documentation fixes 2002-08-10 Soren Sandmann <sandmann@daimi.au.dk> * docs/reference/gtk/tree_widget.sgml, docs/reference/gtk/tmpl/gtkdialog.sgml, docs/reference/gtk/tmpl/gtkentry.sgml, docs/reference/gtk/tmpl/gtkfilesel.sgml, docs/reference/gtk/tmpl/gtkfontsel.sgml, docs/reference/gtk/tmpl/gtkfontseldlg.sgml, docs/reference/gtk/tmpl/gtktreemodel.sgml, docs/reference/gtk/tmpl/gtkwidget.sgml, gdk/x11/gdkdisplay-x11.c, gtk/gtkbbox.c, gtk/gtkbox.c, gtk/gtkbutton.c, gtk/gtkcellrenderer.c, gtk/gtkcellrendererpixbuf.c, gtk/gtkcellrenderertext.c, gtk/gtkcheckmenuitem.c, gtk/gtkcontainer.c, gtk/gtkcurve.c, gtk/gtkdialog.h, gtk/gtkentry.c, gtk/gtkfilesel.c, gtk/gtkfontsel.c, gtk/gtkframe.c, gtk/gtkhandlebox.c, gtk/gtkiconfactory.c, gtk/gtkimage.c, gtk/gtkinvisible.c, gtk/gtkitemfactory.c, gtk/gtklabel.c, gtk/gtklayout.c, gtk/gtkmenu.c, gtk/gtkprogress.c, gtk/gtkprogressbar.c, gtk/gtkscrolledwindow.c, gtk/gtksizegroup.c, gtk/gtktable.c, gtk/gtktextiter.c, gtk/gtktexttag.c, gtk/gtktexttag.h, gtk/gtktextview.c, gtk/gtktogglebutton.c, gtk/gtktoolbar.c, gtk/gtktreemodel.c, gtk/gtktreeselection.c, gtk/gtktreestore.c, gtk/gtktreeview.c, gtk/gtktreeviewcolumn.c, gtk/gtkviewport.c, gtk/gtkwidget.c, gtk/gtkwidget.h, gtk/gtkwindow.c: Minor documentation fixes (#89254, patch from Brett Nash; #85809, patch from daten@dnetc.org; #76391, patch from Ross Burton; #74559, Manuel Clos; #73569, #72005, Alexey A. Malyshev; #70061, patch from Dennis Bj"orklund; #64566, #63388, #58328, #57499, #81007, #77349, Vitaly Tishkov; #78932, Vitaly Tishkov, patch from Ross Burton; #73306)
2002-08-10 09:55:41 +00:00
* Returns %TRUE if the row at @iter is currently selected.
*
* Returns: %TRUE, if @iter is selected
**/
gboolean
gtk_tree_selection_iter_is_selected (GtkTreeSelection *selection,
GtkTreeIter *iter)
{
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);
g_return_val_if_fail (model != NULL, FALSE);
path = gtk_tree_model_get_path (model, iter);
if (path == NULL)
return FALSE;
retval = gtk_tree_selection_path_is_selected (selection, path);
gtk_tree_path_free (path);
return retval;
}
/* Wish I was in python, right now... */
struct _TempTuple {
GtkTreeSelection *selection;
2020-07-24 13:54:49 +00:00
int dirty;
};
static void
select_all_helper (GtkTreeRBTree *tree,
GtkTreeRBNode *node,
gpointer data)
{
struct _TempTuple *tuple = data;
if (node->children)
gtk_tree_rbtree_traverse (node->children,
node->children->root,
G_PRE_ORDER,
select_all_helper,
data);
if (!GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
{
tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, TRUE) || tuple->dirty;
}
}
/* We have a real_{un,}select_all function that doesn't emit the signal, so we
* can use it in other places without fear of the signal being emitted.
*/
2020-07-24 13:54:49 +00:00
static int
gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
{
struct _TempTuple *tuple;
GtkTreeRBTree *tree;
tree = _gtk_tree_view_get_rbtree (selection->tree_view);
if (tree == NULL)
return FALSE;
/* Mark all nodes selected */
tuple = g_new (struct _TempTuple, 1);
tuple->selection = selection;
tuple->dirty = FALSE;
gtk_tree_rbtree_traverse (tree, tree->root,
G_PRE_ORDER,
select_all_helper,
tuple);
if (tuple->dirty)
{
g_free (tuple);
return TRUE;
}
g_free (tuple);
return FALSE;
}
/**
* gtk_tree_selection_select_all:
* @selection: A `GtkTreeSelection`.
*
* Selects all the nodes. @selection must be set to %GTK_SELECTION_MULTIPLE
* mode.
**/
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);
Fix #139290: 2004-07-08 Federico Mena Quintero <federico@ximian.com> Fix #139290: * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_new): Add a GError argument. Do check for errors when getting the GtkFileFolder: get the folder and read the children before actually creating the model. Removed obsolete code that handled roots-changed on the file system. (file_model_node_get_info): Assert that we don't reach the old case to display file system roots. (roots_changed_callback): Removed. * gtk/gtkfilechooserdefault.c (set_list_model): Add a GError argument, and a boolean return value. Return an error if we cannot create the file system model. On error, set a NULL model on the tree. (gtk_file_chooser_default_set_current_folder): Use the error value from set_list_model(). (gtk_file_chooser_default_set_property): Set the show_hidden property only if the browse_files_model exists. (gtk_file_chooser_default_unselect_path): Only operate if the browse_files_model exists. (check_preview_change): Check whether we have the sort_model. (change_folder_and_display_error): Copy the path we get passed before using it. There's a comment in there that explains why we need to copy it; basically, if the passed path belongs to the model, the model may go away in the middle of this function and we'll be left with a dangling pointer. (install_list_model_filter): Assert that the model is not NULL. (set_current_filter): Check whether the model exists. * gtk/gtktreeselection.c (gtk_tree_selection_get_selected): Don't g_return_if_fail if the model is NULL. (gtk_tree_selection_get_selected_rows): Likewise. (gtk_tree_selection_count_selected_rows): Likewise. (gtk_tree_selection_selected_foreach): Likewise. (gtk_tree_selection_path_is_selected): Likewise; rather just return FALSE. (gtk_tree_selection_select_all): Likewise. (gtk_tree_selection_unselect_all): Likewise. (gtk_tree_selection_select_range): Do g_return_if_fail() if the model is NULL. (gtk_tree_selection_unselect_range): Likewise. * gtk/gtkfilesystemunix.c (fill_in_names): Return immediately if g_dir_open() fails: there is no need to set the error ourselves, as g_dir_open() already does it.
2004-07-09 00:53:48 +00:00
if (_gtk_tree_view_get_rbtree (selection->tree_view) == NULL ||
gtk_tree_view_get_model (selection->tree_view) == NULL)
return;
Fix #139290: 2004-07-08 Federico Mena Quintero <federico@ximian.com> Fix #139290: * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_new): Add a GError argument. Do check for errors when getting the GtkFileFolder: get the folder and read the children before actually creating the model. Removed obsolete code that handled roots-changed on the file system. (file_model_node_get_info): Assert that we don't reach the old case to display file system roots. (roots_changed_callback): Removed. * gtk/gtkfilechooserdefault.c (set_list_model): Add a GError argument, and a boolean return value. Return an error if we cannot create the file system model. On error, set a NULL model on the tree. (gtk_file_chooser_default_set_current_folder): Use the error value from set_list_model(). (gtk_file_chooser_default_set_property): Set the show_hidden property only if the browse_files_model exists. (gtk_file_chooser_default_unselect_path): Only operate if the browse_files_model exists. (check_preview_change): Check whether we have the sort_model. (change_folder_and_display_error): Copy the path we get passed before using it. There's a comment in there that explains why we need to copy it; basically, if the passed path belongs to the model, the model may go away in the middle of this function and we'll be left with a dangling pointer. (install_list_model_filter): Assert that the model is not NULL. (set_current_filter): Check whether the model exists. * gtk/gtktreeselection.c (gtk_tree_selection_get_selected): Don't g_return_if_fail if the model is NULL. (gtk_tree_selection_get_selected_rows): Likewise. (gtk_tree_selection_count_selected_rows): Likewise. (gtk_tree_selection_selected_foreach): Likewise. (gtk_tree_selection_path_is_selected): Likewise; rather just return FALSE. (gtk_tree_selection_select_all): Likewise. (gtk_tree_selection_unselect_all): Likewise. (gtk_tree_selection_select_range): Do g_return_if_fail() if the model is NULL. (gtk_tree_selection_unselect_range): Likewise. * gtk/gtkfilesystemunix.c (fill_in_names): Return immediately if g_dir_open() fails: there is no need to set the error ourselves, as g_dir_open() already does it.
2004-07-09 00:53:48 +00:00
g_return_if_fail (selection->type == GTK_SELECTION_MULTIPLE);
if (gtk_tree_selection_real_select_all (selection))
g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
}
static void
unselect_all_helper (GtkTreeRBTree *tree,
GtkTreeRBNode *node,
gpointer data)
{
struct _TempTuple *tuple = data;
if (node->children)
gtk_tree_rbtree_traverse (node->children,
node->children->root,
G_PRE_ORDER,
unselect_all_helper,
data);
if (GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
{
tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, FALSE) || tuple->dirty;
}
}
static gboolean
gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
{
struct _TempTuple *tuple;
if (selection->type == GTK_SELECTION_SINGLE ||
selection->type == GTK_SELECTION_BROWSE)
{
GtkTreeRBTree *tree = NULL;
GtkTreeRBNode *node = NULL;
GtkTreePath *anchor_path;
anchor_path = _gtk_tree_view_get_anchor_path (selection->tree_view);
if (anchor_path == NULL)
return FALSE;
_gtk_tree_view_find_node (selection->tree_view,
anchor_path,
&tree,
&node);
gtk_tree_path_free (anchor_path);
remove validation idle 2001-02-08 Havoc Pennington <hp@redhat.com> * gtk/gtktextview.c (gtk_text_view_destroy_layout): remove validation idle * demos/gtk-demo/main.c (create_tree): adjust to changes in text cell renderer * demos/pixbuf-demo.c (timeout): remove deprecated gtk_widget_draw * demos/testpixbuf-save.c (main): remove deprecated gtk_drawing_area_size * gtk/gtktreeview.c (gtk_tree_view_size_allocate): allocate buttons even if the model isn't setup. gtk_tree_view_check_dirty() at the start of the allocation. (gtk_tree_view_check_dirty): handle column->button == NULL, handle unsetup or NULL model. * gtk/gtkstyle.c (gtk_default_draw_flat_box): drawing for the even/odd/sorted cells in the tree view. * gtk/gtktreeselection.c (gtk_tree_selection_real_unselect_all): bugfixes * gtk/gtktreeview.c: assorted bugfixy stuff. Draw the row backgrounds with draw_flat_box using different detail for even/odd rows. * gtk/gtkrbtree.c, gtkrbtree.h: Keep track of the parity of each row, so we can draw the alternating colors thing * gtk/gtktexttag.c (gtk_text_tag_set_property): if we change a property from a synonym property, notify for the synonym. Also, nuke the background_gdk_set and foreground_gdk_set synonyms (gtk_text_tag_get_property): Always return the font, even if all its fields aren't set * gtk/gtkcellrenderertext.h (struct _GtkCellRendererText): don't store the attr list; it leaves us with no way to change attributes in _render according to the render flags, and no way to implement get_property. Instead store all the specific text attributes. Separate whether an attribute is enabled from its value. Sync all properties with GtkTextTag, make them all consistent, etc. * gtk/gtkcellrenderer.h: Add a flag GTK_CELL_RENDERER_SORTED so renderers can highlight the sort row/column * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_get_property): use accessor functions to get values; this has the side effect of showing up which accessor functions were missing. Added those. * gtk/gtktreeviewcolumn.h: Replace set_justification with set_alignment, to be consistent with GtkLabel, GtkMisc * gtk/gtktreeviewcolumn.c: Added code to display sort indicator arrow. * gtk/Makefile.am (gtk_public_h_sources): add gtktreesortable.h * gtk/gtktreesortable.h: updates in here
2001-02-08 23:36:53 +00:00
if (tree == NULL)
return FALSE;
if (GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
{
if (gtk_tree_selection_real_select_node (selection, tree, node, FALSE))
{
_gtk_tree_view_set_anchor_path (selection->tree_view, NULL);
return TRUE;
}
}
return FALSE;
}
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
else
{
GtkTreeRBTree *tree;
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
tuple = g_new (struct _TempTuple, 1);
tuple->selection = selection;
tuple->dirty = FALSE;
tree = _gtk_tree_view_get_rbtree (selection->tree_view);
gtk_tree_rbtree_traverse (tree, tree->root,
G_PRE_ORDER,
unselect_all_helper,
tuple);
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
if (tuple->dirty)
{
g_free (tuple);
return TRUE;
}
g_free (tuple);
Adapt to GtkTreeSelection changes 2001-01-01 Havoc Pennington <hp@redhat.com> * gtk/gtktreeview.c: Adapt to GtkTreeSelection changes * gtk/gtktreeselection.c (_gtk_tree_selection_set_tree_view): don't fill in tree_view->priv->selection, kind of an unexpected side effect * gtk/gtkcellrenderertext.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderer.c: Remove definition of _ and include gtkintl.h (gtk_cell_renderer_get_property): remove calls to g_value_init * gtk/gtkcellrendererpixbuf.c: Remove definition of _ and include gtkintl.h * gtk/gtkcellrenderertextpixbuf.c: Remove definition of _ macro and include gtkintl.h (gtk_cell_renderer_text_pixbuf_class_init): remove spaces from property names * gtk/gtktreeselection.c (_gtk_tree_selection_new): rename, return GtkTreeSelection (_gtk_tree_selection_new_from_with_view): rename, return GtkTreeSelection (_gtk_tree_selection_set_tree_view): rename with uscore (gtk_tree_selection_get_selected): fill in the "model" out param first, so it gets filled in even if we return at the top of the function (gtk_tree_selection_real_select_all): add a comment and an else{} to clarify this a bit (gtk_tree_selection_real_unselect_all): add the same else{} * gtk/gtktreeselection.h: Rename new, new_with_tree_view, and set_tree_view to have underscore prefixes, move them to the private header, fix return type of new_with_tree_view (struct _GtkTreeSelection): mark struct fields private * gtk/gtktreemodel.c (gtk_tree_model_get_flags): return GtkTreeModelFlags, not a guint (gtk_tree_path_prev): return gboolean not gint (gtk_tree_path_up): return gboolean not gint * gtk/gtktreemodel.h (struct _GtkTreeModelIface): make get_flags return GtkTreeModelFlags, not a guint * gtk/gtktreemodelsort.c (gtk_tree_model_sort_finalize): check that child model is non-null before unrefing it (g_value_int_compare_func): make this a qsort compare func, not a boolean predicate * gtk/gtktreemodelsort.h: rename gtk_tree_model_set_sort_column, (add -umn to the end), and mark it unimplemented (gtk_tree_model_sort_resort): remove, this wasn't implemented, and I don't see what it's for - doesn't the model always sort itself? (gtk_tree_model_sort_set_compare): this had the wrong signature * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_attributes): Fix the docs to say that it destructively replaces existing attributes (previously said that it added attributes). (gtk_tree_view_column_set_visible): canonicalize bool before equality testing. Also, check for realization before hiding/showing the tree_column->window; if this window could exist before realization, then it's busted and needs fixing, we can't create GDK resources pre-realization. Also, remove superfluous queue_resize(), since set_size() does that for us. (gtk_tree_view_column_set_col_type): check realization before using tree_column->window * gtk/gtktreedatalist.c: fix filename in copyright notice
2001-01-01 19:01:54 +00:00
return FALSE;
}
}
/**
* gtk_tree_selection_unselect_all:
* @selection: A `GtkTreeSelection`.
*
* Unselects all the nodes.
**/
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);
Fix #139290: 2004-07-08 Federico Mena Quintero <federico@ximian.com> Fix #139290: * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_new): Add a GError argument. Do check for errors when getting the GtkFileFolder: get the folder and read the children before actually creating the model. Removed obsolete code that handled roots-changed on the file system. (file_model_node_get_info): Assert that we don't reach the old case to display file system roots. (roots_changed_callback): Removed. * gtk/gtkfilechooserdefault.c (set_list_model): Add a GError argument, and a boolean return value. Return an error if we cannot create the file system model. On error, set a NULL model on the tree. (gtk_file_chooser_default_set_current_folder): Use the error value from set_list_model(). (gtk_file_chooser_default_set_property): Set the show_hidden property only if the browse_files_model exists. (gtk_file_chooser_default_unselect_path): Only operate if the browse_files_model exists. (check_preview_change): Check whether we have the sort_model. (change_folder_and_display_error): Copy the path we get passed before using it. There's a comment in there that explains why we need to copy it; basically, if the passed path belongs to the model, the model may go away in the middle of this function and we'll be left with a dangling pointer. (install_list_model_filter): Assert that the model is not NULL. (set_current_filter): Check whether the model exists. * gtk/gtktreeselection.c (gtk_tree_selection_get_selected): Don't g_return_if_fail if the model is NULL. (gtk_tree_selection_get_selected_rows): Likewise. (gtk_tree_selection_count_selected_rows): Likewise. (gtk_tree_selection_selected_foreach): Likewise. (gtk_tree_selection_path_is_selected): Likewise; rather just return FALSE. (gtk_tree_selection_select_all): Likewise. (gtk_tree_selection_unselect_all): Likewise. (gtk_tree_selection_select_range): Do g_return_if_fail() if the model is NULL. (gtk_tree_selection_unselect_range): Likewise. * gtk/gtkfilesystemunix.c (fill_in_names): Return immediately if g_dir_open() fails: there is no need to set the error ourselves, as g_dir_open() already does it.
2004-07-09 00:53:48 +00:00
if (_gtk_tree_view_get_rbtree (selection->tree_view) == NULL ||
gtk_tree_view_get_model (selection->tree_view) == NULL)
return;
if (gtk_tree_selection_real_unselect_all (selection))
g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
}
enum
{
RANGE_SELECT,
RANGE_UNSELECT
};
2020-07-24 13:54:49 +00:00
static int
gtk_tree_selection_real_modify_range (GtkTreeSelection *selection,
2020-07-24 13:54:49 +00:00
int mode,
GtkTreePath *start_path,
GtkTreePath *end_path)
{
GtkTreeRBNode *start_node = NULL, *end_node = NULL;
GtkTreeRBTree *start_tree, *end_tree;
GtkTreePath *anchor_path = NULL;
gboolean dirty = FALSE;
switch (gtk_tree_path_compare (start_path, end_path))
{
case 1:
_gtk_tree_view_find_node (selection->tree_view,
end_path,
&start_tree,
&start_node);
_gtk_tree_view_find_node (selection->tree_view,
start_path,
&end_tree,
&end_node);
anchor_path = start_path;
break;
case 0:
_gtk_tree_view_find_node (selection->tree_view,
start_path,
&start_tree,
&start_node);
end_tree = start_tree;
end_node = start_node;
anchor_path = start_path;
break;
case -1:
_gtk_tree_view_find_node (selection->tree_view,
start_path,
&start_tree,
&start_node);
_gtk_tree_view_find_node (selection->tree_view,
end_path,
&end_tree,
&end_node);
anchor_path = start_path;
break;
default:
g_assert_not_reached ();
break;
}
/* Invalid start or end node? */
if (start_node == NULL || end_node == NULL)
return dirty;
if (anchor_path)
_gtk_tree_view_set_anchor_path (selection->tree_view, anchor_path);
do
{
dirty |= gtk_tree_selection_real_select_node (selection, start_tree, start_node, (mode == RANGE_SELECT)?TRUE:FALSE);
if (start_node == end_node)
break;
if (start_node->children)
{
start_tree = start_node->children;
start_node = gtk_tree_rbtree_first (start_tree);
}
else
{
gtk_tree_rbtree_next_full (start_tree, start_node, &start_tree, &start_node);
if (start_tree == NULL)
{
/* we just ran out of tree. That means someone passed in bogus values.
*/
return dirty;
}
}
}
while (TRUE);
return dirty;
}
/**
* gtk_tree_selection_select_range:
* @selection: A `GtkTreeSelection`.
* @start_path: The initial node of the range.
* @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,
GtkTreePath *start_path,
GtkTreePath *end_path)
{
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);
if (gtk_tree_selection_real_modify_range (selection, RANGE_SELECT, start_path, end_path))
g_signal_emit (selection, tree_selection_signals[CHANGED], 0);
}
/**
* gtk_tree_selection_unselect_range:
* @selection: A `GtkTreeSelection`.
* @start_path: The initial node of the range.
* @end_path: The initial node of the range.
*
* Unselects a range of nodes, determined by @start_path and @end_path
* inclusive.
**/
void
gtk_tree_selection_unselect_range (GtkTreeSelection *selection,
GtkTreePath *start_path,
GtkTreePath *end_path)
{
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);
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,
GtkTreeRBNode *node,
GtkTreePath *path)
{
Support separators in combo boxes and more generally in tree views 2004-07-07 Matthias Clasen <mclasen@redhat.com> Support separators in combo boxes and more generally in tree views (#135873): * gtk/gtkcombobox.h: * gtk/gtkcombobox.c (gtk_combo_box_get_row_separator_column): * gtk/gtkcombobox.c (gtk_combo_box_set_row_separator_column): Add a ::row-separator-column property with getter and setter, which can indicate a boolean model column to determine which rows are separators. * gtk/gtkcombobox.c: Display separator rows as separator menu items in menu mode, and by using the new treeview separator functionality in list mode. * gtk/gtktreeview.h: * gtk/gtktreeview.c (gtk_tree_view_get_row_separator_func): * gtk/gtktreeview.c (gtk_tree_view_set_row_separator_func): Add a callback to determine whether a row is a separator. * gtk/gtktreeview.c (gtk_tree_view_bin_expose): * gtk/gtktreeview.c (gtk_tree_view_create_row_drag_icon): * gtk/gtktreeview.c (validate_row): Use the new callback to determine whether a row is a separator, and draw it as a separator then. Since separators should take up less vertical space than regular rows, this requires removing the redundant MAX(...,expander_size) calls which appear in many places. Instead, the MAX() is now only done in validate_row(), and only if the row is not a separator. To catch possible side effects of this intrusive change, I have left EXPANDER_MAX() calls in place of the MAX() calls which will emit a warning if something breaks. They should be removed before 2.6. * gtk/gtktreeselection.c (row_is_selectable): Don't let separator rows be selected. * tests/testcombo.c (create_blaat): Add a separator column.
2004-07-07 15:15:35 +00:00
GtkTreeIter iter;
GtkTreeModel *model;
GtkTreeViewRowSeparatorFunc separator_func;
gpointer separator_data;
Support separators in combo boxes and more generally in tree views 2004-07-07 Matthias Clasen <mclasen@redhat.com> Support separators in combo boxes and more generally in tree views (#135873): * gtk/gtkcombobox.h: * gtk/gtkcombobox.c (gtk_combo_box_get_row_separator_column): * gtk/gtkcombobox.c (gtk_combo_box_set_row_separator_column): Add a ::row-separator-column property with getter and setter, which can indicate a boolean model column to determine which rows are separators. * gtk/gtkcombobox.c: Display separator rows as separator menu items in menu mode, and by using the new treeview separator functionality in list mode. * gtk/gtktreeview.h: * gtk/gtktreeview.c (gtk_tree_view_get_row_separator_func): * gtk/gtktreeview.c (gtk_tree_view_set_row_separator_func): Add a callback to determine whether a row is a separator. * gtk/gtktreeview.c (gtk_tree_view_bin_expose): * gtk/gtktreeview.c (gtk_tree_view_create_row_drag_icon): * gtk/gtktreeview.c (validate_row): Use the new callback to determine whether a row is a separator, and draw it as a separator then. Since separators should take up less vertical space than regular rows, this requires removing the redundant MAX(...,expander_size) calls which appear in many places. Instead, the MAX() is now only done in validate_row(), and only if the row is not a separator. To catch possible side effects of this intrusive change, I have left EXPANDER_MAX() calls in place of the MAX() calls which will emit a warning if something breaks. They should be removed before 2.6. * gtk/gtktreeselection.c (row_is_selectable): Don't let separator rows be selected. * tests/testcombo.c (create_blaat): Add a separator column.
2004-07-07 15:15:35 +00:00
gboolean sensitive = FALSE;
model = gtk_tree_view_get_model (selection->tree_view);
_gtk_tree_view_get_row_separator_func (selection->tree_view,
&separator_func, &separator_data);
if (!gtk_tree_model_get_iter (model, &iter, path))
Support separators in combo boxes and more generally in tree views 2004-07-07 Matthias Clasen <mclasen@redhat.com> Support separators in combo boxes and more generally in tree views (#135873): * gtk/gtkcombobox.h: * gtk/gtkcombobox.c (gtk_combo_box_get_row_separator_column): * gtk/gtkcombobox.c (gtk_combo_box_set_row_separator_column): Add a ::row-separator-column property with getter and setter, which can indicate a boolean model column to determine which rows are separators. * gtk/gtkcombobox.c: Display separator rows as separator menu items in menu mode, and by using the new treeview separator functionality in list mode. * gtk/gtktreeview.h: * gtk/gtktreeview.c (gtk_tree_view_get_row_separator_func): * gtk/gtktreeview.c (gtk_tree_view_set_row_separator_func): Add a callback to determine whether a row is a separator. * gtk/gtktreeview.c (gtk_tree_view_bin_expose): * gtk/gtktreeview.c (gtk_tree_view_create_row_drag_icon): * gtk/gtktreeview.c (validate_row): Use the new callback to determine whether a row is a separator, and draw it as a separator then. Since separators should take up less vertical space than regular rows, this requires removing the redundant MAX(...,expander_size) calls which appear in many places. Instead, the MAX() is now only done in validate_row(), and only if the row is not a separator. To catch possible side effects of this intrusive change, I have left EXPANDER_MAX() calls in place of the MAX() calls which will emit a warning if something breaks. They should be removed before 2.6. * gtk/gtktreeselection.c (row_is_selectable): Don't let separator rows be selected. * tests/testcombo.c (create_blaat): Add a separator column.
2004-07-07 15:15:35 +00:00
sensitive = TRUE;
if (!sensitive && separator_func)
Support separators in combo boxes and more generally in tree views 2004-07-07 Matthias Clasen <mclasen@redhat.com> Support separators in combo boxes and more generally in tree views (#135873): * gtk/gtkcombobox.h: * gtk/gtkcombobox.c (gtk_combo_box_get_row_separator_column): * gtk/gtkcombobox.c (gtk_combo_box_set_row_separator_column): Add a ::row-separator-column property with getter and setter, which can indicate a boolean model column to determine which rows are separators. * gtk/gtkcombobox.c: Display separator rows as separator menu items in menu mode, and by using the new treeview separator functionality in list mode. * gtk/gtktreeview.h: * gtk/gtktreeview.c (gtk_tree_view_get_row_separator_func): * gtk/gtktreeview.c (gtk_tree_view_set_row_separator_func): Add a callback to determine whether a row is a separator. * gtk/gtktreeview.c (gtk_tree_view_bin_expose): * gtk/gtktreeview.c (gtk_tree_view_create_row_drag_icon): * gtk/gtktreeview.c (validate_row): Use the new callback to determine whether a row is a separator, and draw it as a separator then. Since separators should take up less vertical space than regular rows, this requires removing the redundant MAX(...,expander_size) calls which appear in many places. Instead, the MAX() is now only done in validate_row(), and only if the row is not a separator. To catch possible side effects of this intrusive change, I have left EXPANDER_MAX() calls in place of the MAX() calls which will emit a warning if something breaks. They should be removed before 2.6. * gtk/gtktreeselection.c (row_is_selectable): Don't let separator rows be selected. * tests/testcombo.c (create_blaat): Add a separator column.
2004-07-07 15:15:35 +00:00
{
/* never allow separators to be selected */
if ((* separator_func) (model, &iter, separator_data))
Support separators in combo boxes and more generally in tree views 2004-07-07 Matthias Clasen <mclasen@redhat.com> Support separators in combo boxes and more generally in tree views (#135873): * gtk/gtkcombobox.h: * gtk/gtkcombobox.c (gtk_combo_box_get_row_separator_column): * gtk/gtkcombobox.c (gtk_combo_box_set_row_separator_column): Add a ::row-separator-column property with getter and setter, which can indicate a boolean model column to determine which rows are separators. * gtk/gtkcombobox.c: Display separator rows as separator menu items in menu mode, and by using the new treeview separator functionality in list mode. * gtk/gtktreeview.h: * gtk/gtktreeview.c (gtk_tree_view_get_row_separator_func): * gtk/gtktreeview.c (gtk_tree_view_set_row_separator_func): Add a callback to determine whether a row is a separator. * gtk/gtktreeview.c (gtk_tree_view_bin_expose): * gtk/gtktreeview.c (gtk_tree_view_create_row_drag_icon): * gtk/gtktreeview.c (validate_row): Use the new callback to determine whether a row is a separator, and draw it as a separator then. Since separators should take up less vertical space than regular rows, this requires removing the redundant MAX(...,expander_size) calls which appear in many places. Instead, the MAX() is now only done in validate_row(), and only if the row is not a separator. To catch possible side effects of this intrusive change, I have left EXPANDER_MAX() calls in place of the MAX() calls which will emit a warning if something breaks. They should be removed before 2.6. * gtk/gtktreeselection.c (row_is_selectable): Don't let separator rows be selected. * tests/testcombo.c (create_blaat): Add a separator column.
2004-07-07 15:15:35 +00:00
return FALSE;
}
if (selection->user_func)
return (*selection->user_func) (selection, model, path,
GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED),
selection->user_data);
else
return TRUE;
}
/* Called internally by gtktreeview.c It handles actually selecting the tree.
*/
2002-04-20 23:57:41 +00:00
/*
* docs about the override_browse_mode, we set this flag when we want to
* unset select the node and override the select browse mode behaviour (that is
* 'one node should *always* be selected').
*/
void
_gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
GtkTreeRBNode *node,
GtkTreeRBTree *tree,
GtkTreePath *path,
GtkTreeSelectMode mode,
gboolean override_browse_mode)
{
2020-07-24 13:54:49 +00:00
int flags;
int dirty = FALSE;
GtkTreePath *anchor_path = NULL;
if (selection->type == GTK_SELECTION_NONE)
return;
anchor_path = _gtk_tree_view_get_anchor_path (selection->tree_view);
if (selection->type == GTK_SELECTION_SINGLE ||
selection->type == GTK_SELECTION_BROWSE)
{
/* just unselect */
if (selection->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 &&
anchor_path && gtk_tree_path_compare (path, anchor_path) == 0)
{
if ((mode & GTK_TREE_SELECT_MODE_TOGGLE) == GTK_TREE_SELECT_MODE_TOGGLE)
{
dirty = gtk_tree_selection_real_unselect_all (selection);
}
}
else
{
if (anchor_path)
{
/* We only want to select the new node if we can unselect the old one,
* and we can select the new one. */
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
*/
if (dirty)
dirty = gtk_tree_selection_real_unselect_all (selection);
/* if dirty is TRUE at this point, we successfully unselected the
* old one, and can then select the new one */
if (dirty)
{
_gtk_tree_view_set_anchor_path (selection->tree_view, NULL);
if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
}
}
else
{
if (gtk_tree_selection_real_select_node (selection, tree, node, TRUE))
{
dirty = TRUE;
2002-10-22 23:05:29 +00:00
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
}
}
}
}
else if (selection->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);
dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
}
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 ((mode & GTK_TREE_SELECT_MODE_TOGGLE) == GTK_TREE_SELECT_MODE_TOGGLE)
{
flags = node->flags;
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
if ((flags & GTK_TREE_RBNODE_IS_SELECTED) == GTK_TREE_RBNODE_IS_SELECTED)
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
else
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
}
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,
RANGE_SELECT,
anchor_path,
path);
}
else
{
dirty = gtk_tree_selection_real_unselect_all (selection);
_gtk_tree_view_set_anchor_path (selection->tree_view, path);
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
}
}
if (anchor_path)
gtk_tree_path_free (anchor_path);
if (dirty)
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!
*/
2020-07-24 13:54:49 +00:00
static int
gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
GtkTreeRBTree *tree,
GtkTreeRBNode *node,
gboolean select)
{
gboolean toggle = FALSE;
GtkTreePath *path = NULL;
g_return_val_if_fail (node != NULL, FALSE);
select = !! select;
if (GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED) != select)
{
path = _gtk_tree_path_new_from_rbtree (tree, node);
toggle = _gtk_tree_selection_row_is_selectable (selection, node, path);
gtk_tree_path_free (path);
}
if (toggle)
{
if (!GTK_TREE_RBNODE_FLAG_SET (node, GTK_TREE_RBNODE_IS_SELECTED))
{
GTK_TREE_RBNODE_SET_FLAG (node, GTK_TREE_RBNODE_IS_SELECTED);
}
else
{
GTK_TREE_RBNODE_UNSET_FLAG (node, GTK_TREE_RBNODE_IS_SELECTED);
}
gtk_widget_queue_draw (GTK_WIDGET (selection->tree_view));
return TRUE;
}
return FALSE;
}