2000-10-05 01:04:57 +00:00
|
|
|
/* 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
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
#include "gtktreeprivate.h"
|
|
|
|
#include "gtkrbtree.h"
|
|
|
|
#include "gtksignal.h"
|
|
|
|
|
2000-10-06 00:06:00 +00:00
|
|
|
static void gtk_tree_selection_init (GtkTreeSelection *selection);
|
|
|
|
static void gtk_tree_selection_class_init (GtkTreeSelectionClass *class);
|
|
|
|
static gint gtk_tree_selection_real_select_all (GtkTreeSelection *selection);
|
|
|
|
static gint gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection);
|
|
|
|
static gint gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
|
|
|
|
GtkRBTree *tree,
|
|
|
|
GtkRBNode *node,
|
|
|
|
gboolean select);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
enum {
|
2000-10-06 00:06:00 +00:00
|
|
|
SELECTION_CHANGED,
|
2000-10-05 01:04:57 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkObjectClass *parent_class = NULL;
|
|
|
|
static guint tree_selection_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
GtkType
|
|
|
|
gtk_tree_selection_get_type (void)
|
|
|
|
{
|
|
|
|
static GtkType selection_type = 0;
|
|
|
|
|
|
|
|
if (!selection_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo selection_info =
|
|
|
|
{
|
|
|
|
sizeof (GtkTreeSelectionClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gtk_tree_selection_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GtkTreeSelection),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gtk_tree_selection_init
|
|
|
|
};
|
|
|
|
|
urg, removed implementation of gtk_marshal_VOID__INT_INT_INT_INT. if
Wed Oct 25 20:47:41 2000 Tim Janik <timj@gtk.org>
* gtk/gdk-pixbuf-loader.c (gdk_pixbuf_loader_class_init): urg, removed
implementation of gtk_marshal_VOID__INT_INT_INT_INT. if people do that,
couldn't they at least give it a non-standard name?
* gtk/gtktextlayout.c: arg! yet another implementation of
gtk_marshal_VOID__INT_INT_INT_INT(), is this a conspiracy?
* gtk/gtktextbuffer.c: gotcha! captured a vagabonding
gtk_marshal_VOID__INT_POINTER_INT() implementation, braught it back
home. now i know this _is_ a conspiracy.
* gtk/gtkwidget.c (gtk_widget_class_init): marshaller fixups for
::state-changed.
* gtk/gtkaccelgroup.c (gtk_accel_group_create_remove):
(gtk_accel_group_create_add): marshaller signature fixups.
* gtk/gtklistitem.c (gtk_list_item_class_init): signal creation fixups,
pass in GTK_TYPE_SCROLL_TYPE instead of GTK_TYPE_ENUM.
* gtk/gtkobject.[hc]: removed GTK_CONNECTED flag, it's not valid
anymore.
Tue Oct 24 23:59:21 2000 Tim Janik <timj@gtk.org>
* docs/reference/Makefile.am: disabled SUBDIRS for the moment, since
due to the signal system changes, it wouldn't build currently. to
be fixed soon.
* docs/Changes-2.0.txt: GtkSignal/GSignal updates.
* gtk/gtkwidget.c: ::direction_changed takes an enum as argument,
so it needs gtk_marshal_VOID__ENUM() instead of
gtk_marshal_NONE__UINT().
* gdk/gdk*.c: adapted type registration functions.
* gtk/gtkbindings.c:
* gtk/gtkaccelgroup.c: operate on GSignalQuery, GtkSignalQuery is
gone.
* gtk/gtkenums.h: define GtkSignalRunType in terms of GSignalType.
* gtk/gtkobject.c:
(gtk_object_destroy):
(gtk_object_shutdown): fixed recursion guards. basically we have to
catch the case where any of GObject.shutdown() or gtk_object_destroy()
is called during ::destroy, and avoid recursion there.
* gtk/gtktypeutils.c:
* gtk/maketypes.awk: awk-script hackup to provide gtk_type_init() with
boxed_copy/boxed_free. this needs a more general solution based on a
publically installed code-generator utility.
* gtk/gtktypeutils.[hc]: compat aliased GTK_TYPE_BOXED to G_TYPE_BOXED,
glib's gobject has support for that now.
define GtkSignalMarshaller in terms of GSignalCMarshaller.
Mon Oct 23 09:36:42 2000 Tim Janik <timj@gtk.org>
* gtk/gtksignal.[hc]:
* gtk/gtkmarshal.[hc]:
* gtk/Makefile.am: generate marshallers with glib-genmarshal and don't
compile gtkmarshal.c on its own anymore, just include it in gtksignal.c.
removed #include <gtkmarshal.h>s all over the place, gtksignal.h takes
care of that.
* *.c: marshaller name fixups.
* gtk/gtkmarshal.list: added a comment briefing the format.
Sun Oct 22 23:14:39 2000 Tim Janik <timj@gtk.org>
* gtk/gtksignal.[hc]: nuked old implementation. we mostly have
compatibility macros here now. more specifically, most of
the API is preserved (yes, _most_, nonwithstanding the
following exceptions listed, the API is stil lHUGE ;)
things that got removed completely:
GtkSignalQuery, gtk_signal_query(), gtk_signal_n_emissions(),
gtk_signal_n_emissions_by_name(), gtk_signal_handlers_destroy(),
gtk_signal_set_funcs(), gtk_signal_handler_pending_by_id(),
gtk_signal_add_emission_hook(), gtk_signal_add_emission_hook_full(),
gtk_signal_remove_emission_hook().
non-functional functions variants:
gtk_signal_add_emission_hook(), gtk_signal_remove_emission_hook().
the GtkCallbackMarshal argument to gtk_signal_connect_full() is
not supported anymore.
(gtk_signal_compat_matched): new internal function to aid
implementation of the compatibility macros, it provides
functionality to block/unblock/disconnect handlers based
on func/data.
* gtk/gtkenums.h: define GtkSignalRunType in terms of GSignalType,
* *.c: adaptions to new type registration API signatures.
Fri Oct 20 15:26:33 2000 Tim Janik <timj@gtk.org>
* gtk/gtktypeutils.[hc]: removed G_TYPE_GTK_POINTER cludge.
2000-10-25 22:34:14 +00:00
|
|
|
selection_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkTreeSelection", &selection_info, 0);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return selection_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_selection_class_init (GtkTreeSelectionClass *class)
|
|
|
|
{
|
|
|
|
GtkObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = (GtkObjectClass*) class;
|
|
|
|
parent_class = g_type_class_peek_parent (class);
|
|
|
|
|
2000-10-06 00:06:00 +00:00
|
|
|
tree_selection_signals[SELECTION_CHANGED] =
|
|
|
|
gtk_signal_new ("selection_changed",
|
2000-10-05 01:04:57 +00:00
|
|
|
GTK_RUN_FIRST,
|
|
|
|
GTK_CLASS_TYPE (object_class),
|
2000-10-06 00:06:00 +00:00
|
|
|
GTK_SIGNAL_OFFSET (GtkTreeSelectionClass, selection_changed),
|
urg, removed implementation of gtk_marshal_VOID__INT_INT_INT_INT. if
Wed Oct 25 20:47:41 2000 Tim Janik <timj@gtk.org>
* gtk/gdk-pixbuf-loader.c (gdk_pixbuf_loader_class_init): urg, removed
implementation of gtk_marshal_VOID__INT_INT_INT_INT. if people do that,
couldn't they at least give it a non-standard name?
* gtk/gtktextlayout.c: arg! yet another implementation of
gtk_marshal_VOID__INT_INT_INT_INT(), is this a conspiracy?
* gtk/gtktextbuffer.c: gotcha! captured a vagabonding
gtk_marshal_VOID__INT_POINTER_INT() implementation, braught it back
home. now i know this _is_ a conspiracy.
* gtk/gtkwidget.c (gtk_widget_class_init): marshaller fixups for
::state-changed.
* gtk/gtkaccelgroup.c (gtk_accel_group_create_remove):
(gtk_accel_group_create_add): marshaller signature fixups.
* gtk/gtklistitem.c (gtk_list_item_class_init): signal creation fixups,
pass in GTK_TYPE_SCROLL_TYPE instead of GTK_TYPE_ENUM.
* gtk/gtkobject.[hc]: removed GTK_CONNECTED flag, it's not valid
anymore.
Tue Oct 24 23:59:21 2000 Tim Janik <timj@gtk.org>
* docs/reference/Makefile.am: disabled SUBDIRS for the moment, since
due to the signal system changes, it wouldn't build currently. to
be fixed soon.
* docs/Changes-2.0.txt: GtkSignal/GSignal updates.
* gtk/gtkwidget.c: ::direction_changed takes an enum as argument,
so it needs gtk_marshal_VOID__ENUM() instead of
gtk_marshal_NONE__UINT().
* gdk/gdk*.c: adapted type registration functions.
* gtk/gtkbindings.c:
* gtk/gtkaccelgroup.c: operate on GSignalQuery, GtkSignalQuery is
gone.
* gtk/gtkenums.h: define GtkSignalRunType in terms of GSignalType.
* gtk/gtkobject.c:
(gtk_object_destroy):
(gtk_object_shutdown): fixed recursion guards. basically we have to
catch the case where any of GObject.shutdown() or gtk_object_destroy()
is called during ::destroy, and avoid recursion there.
* gtk/gtktypeutils.c:
* gtk/maketypes.awk: awk-script hackup to provide gtk_type_init() with
boxed_copy/boxed_free. this needs a more general solution based on a
publically installed code-generator utility.
* gtk/gtktypeutils.[hc]: compat aliased GTK_TYPE_BOXED to G_TYPE_BOXED,
glib's gobject has support for that now.
define GtkSignalMarshaller in terms of GSignalCMarshaller.
Mon Oct 23 09:36:42 2000 Tim Janik <timj@gtk.org>
* gtk/gtksignal.[hc]:
* gtk/gtkmarshal.[hc]:
* gtk/Makefile.am: generate marshallers with glib-genmarshal and don't
compile gtkmarshal.c on its own anymore, just include it in gtksignal.c.
removed #include <gtkmarshal.h>s all over the place, gtksignal.h takes
care of that.
* *.c: marshaller name fixups.
* gtk/gtkmarshal.list: added a comment briefing the format.
Sun Oct 22 23:14:39 2000 Tim Janik <timj@gtk.org>
* gtk/gtksignal.[hc]: nuked old implementation. we mostly have
compatibility macros here now. more specifically, most of
the API is preserved (yes, _most_, nonwithstanding the
following exceptions listed, the API is stil lHUGE ;)
things that got removed completely:
GtkSignalQuery, gtk_signal_query(), gtk_signal_n_emissions(),
gtk_signal_n_emissions_by_name(), gtk_signal_handlers_destroy(),
gtk_signal_set_funcs(), gtk_signal_handler_pending_by_id(),
gtk_signal_add_emission_hook(), gtk_signal_add_emission_hook_full(),
gtk_signal_remove_emission_hook().
non-functional functions variants:
gtk_signal_add_emission_hook(), gtk_signal_remove_emission_hook().
the GtkCallbackMarshal argument to gtk_signal_connect_full() is
not supported anymore.
(gtk_signal_compat_matched): new internal function to aid
implementation of the compatibility macros, it provides
functionality to block/unblock/disconnect handlers based
on func/data.
* gtk/gtkenums.h: define GtkSignalRunType in terms of GSignalType,
* *.c: adaptions to new type registration API signatures.
Fri Oct 20 15:26:33 2000 Tim Janik <timj@gtk.org>
* gtk/gtktypeutils.[hc]: removed G_TYPE_GTK_POINTER cludge.
2000-10-25 22:34:14 +00:00
|
|
|
gtk_marshal_VOID__VOID,
|
2000-10-06 00:06:00 +00:00
|
|
|
GTK_TYPE_NONE, 0);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
gtk_object_class_add_signals (object_class, tree_selection_signals, LAST_SIGNAL);
|
|
|
|
|
2000-10-06 00:06:00 +00:00
|
|
|
class->selection_changed = NULL;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_selection_init (GtkTreeSelection *selection)
|
|
|
|
{
|
2000-10-06 00:06:00 +00:00
|
|
|
selection->type = GTK_TREE_SELECTION_SINGLE;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkTreeSelection object. This function should not be invoked,
|
|
|
|
* as each #GtkTreeView will create it's own #GtkTreeSelection.
|
|
|
|
*
|
|
|
|
* Return value: A newly created #GtkTreeSelection object.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
GtkObject *
|
|
|
|
gtk_tree_selection_new (void)
|
|
|
|
{
|
|
|
|
GtkObject *selection;
|
|
|
|
|
|
|
|
selection = GTK_OBJECT (gtk_type_new (GTK_TYPE_TREE_SELECTION));
|
|
|
|
|
|
|
|
return selection;
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03: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 it's own #GtkTreeSelection.
|
|
|
|
*
|
|
|
|
* Return value: A newly created #GtkTreeSelection object.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
GtkObject *
|
|
|
|
gtk_tree_selection_new_with_tree_view (GtkTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkObject *selection;
|
|
|
|
|
|
|
|
g_return_val_if_fail (tree_view != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL);
|
|
|
|
|
|
|
|
selection = gtk_tree_selection_new ();
|
|
|
|
gtk_tree_selection_set_tree_view (GTK_TREE_SELECTION (selection), tree_view);
|
|
|
|
|
|
|
|
return selection;
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03: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.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
gtk_tree_selection_set_tree_view (GtkTreeSelection *selection,
|
|
|
|
GtkTreeView *tree_view)
|
|
|
|
{
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
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;
|
|
|
|
tree_view->priv->selection = selection;
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_set_type:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
|
|
|
* @type: The selection type.
|
|
|
|
*
|
|
|
|
* Sets the selection type of the @selection. If the previous type was
|
|
|
|
* #GTK_TREE_SELECTION_MULTI and @type is #GTK_TREE_SELECTION_SINGLE, then
|
|
|
|
* the anchor is kept selected, if it was previously selected.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
gtk_tree_selection_set_type (GtkTreeSelection *selection,
|
|
|
|
GtkTreeSelectionType type)
|
|
|
|
{
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
|
|
|
|
if (selection->type == type)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (type == GTK_TREE_SELECTION_SINGLE)
|
|
|
|
{
|
|
|
|
GtkRBTree *tree = NULL;
|
|
|
|
GtkRBNode *node = NULL;
|
|
|
|
gint selected = FALSE;
|
|
|
|
|
|
|
|
if (selection->tree_view->priv->anchor)
|
|
|
|
{
|
|
|
|
_gtk_tree_view_find_node (selection->tree_view,
|
|
|
|
selection->tree_view->priv->anchor,
|
|
|
|
&tree,
|
|
|
|
&node);
|
|
|
|
|
|
|
|
if (node && GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
|
|
|
|
selected = TRUE;
|
|
|
|
}
|
2000-10-16 07:03:54 +00:00
|
|
|
/* FIXME: if user_func is set, then it needs to unconditionally unselect
|
|
|
|
* all.
|
|
|
|
*/
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_selection_unselect_all (selection);
|
|
|
|
if (node && selected)
|
|
|
|
GTK_RBNODE_SET_FLAG (node, GTK_RBNODE_IS_SELECTED);
|
|
|
|
}
|
|
|
|
selection->type = type;
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_set_select_function:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
|
|
|
* @func: The selection function.
|
|
|
|
* @data: The selection function's data.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
gtk_tree_selection_set_select_function (GtkTreeSelection *selection,
|
|
|
|
GtkTreeSelectionFunc func,
|
2000-10-16 07:03:54 +00:00
|
|
|
gpointer data)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
|
|
|
selection->user_func = func;
|
|
|
|
selection->user_data = data;
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_get_user_data:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
|
|
|
*
|
|
|
|
* Returns the user data for the selection function.
|
|
|
|
*
|
|
|
|
* Return value: The user data.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
gpointer
|
|
|
|
gtk_tree_selection_get_user_data (GtkTreeSelection *selection)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), NULL);
|
|
|
|
|
|
|
|
return selection->user_data;
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_get_selected:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
2000-10-30 23:21:38 +00:00
|
|
|
* @iter: The #GtkTreeIter, or NULL.
|
2000-10-16 07:03:54 +00:00
|
|
|
*
|
2000-10-26 00:36:47 +00:00
|
|
|
* Sets @iter to the currently selected node if @selection is set to
|
|
|
|
* #GTK_TREE_SELECTION_SINGLE. Otherwise, it uses the anchor. @iter may be
|
|
|
|
* NULL if you just want to test if @selection has any selected nodes.
|
2000-10-16 07:03:54 +00:00
|
|
|
*
|
2000-10-30 23:21:38 +00:00
|
|
|
* Return value: TRUE, if there is a selected node.
|
2000-10-16 07:03:54 +00:00
|
|
|
**/
|
2000-10-26 00:36:47 +00:00
|
|
|
gboolean
|
|
|
|
gtk_tree_selection_get_selected (GtkTreeSelection *selection,
|
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkRBTree *tree;
|
|
|
|
GtkRBNode *node;
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_val_if_fail (selection != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (selection->tree_view->priv->anchor == NULL)
|
2000-10-26 00:36:47 +00:00
|
|
|
return FALSE;
|
|
|
|
else if (iter == NULL)
|
|
|
|
return TRUE;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_val_if_fail (selection->tree_view != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (selection->tree_view->priv->model != NULL, FALSE);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (!_gtk_tree_view_find_node (selection->tree_view,
|
|
|
|
selection->tree_view->priv->anchor,
|
|
|
|
&tree,
|
|
|
|
&node) &&
|
|
|
|
! GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
|
|
|
|
/* We don't want to return the anchor if it isn't actually selected.
|
|
|
|
*/
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
return gtk_tree_model_get_iter (selection->tree_view->priv->model,
|
|
|
|
iter,
|
|
|
|
selection->tree_view->priv->anchor);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_selected_foreach:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
|
|
|
* @func: The function to call for each selected node.
|
|
|
|
* @data: user data to pass to the function.
|
|
|
|
*
|
|
|
|
* Calls a function for each selected node.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
|
|
|
|
GtkTreeSelectionForeachFunc func,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkRBTree *tree;
|
|
|
|
GtkRBNode *node;
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter iter;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (selection->tree_view != NULL);
|
|
|
|
g_return_if_fail (selection->tree_view->priv->model != NULL);
|
|
|
|
|
|
|
|
if (func == NULL ||
|
|
|
|
selection->tree_view->priv->tree == NULL ||
|
|
|
|
selection->tree_view->priv->tree->root == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tree = selection->tree_view->priv->tree;
|
|
|
|
node = selection->tree_view->priv->tree->root;
|
|
|
|
|
|
|
|
while (node->left != tree->nil)
|
|
|
|
node = node->left;
|
|
|
|
|
|
|
|
/* find the node internally */
|
|
|
|
path = gtk_tree_path_new_root ();
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_model_get_iter (selection->tree_view->priv->model,
|
|
|
|
&iter, path);
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
|
2000-10-26 00:36:47 +00:00
|
|
|
(* func) (selection->tree_view->priv->model, &iter, data);
|
2000-10-05 01:04:57 +00:00
|
|
|
if (node->children)
|
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
gboolean has_child;
|
|
|
|
GtkTreeIter tmp;
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
tree = node->children;
|
|
|
|
node = tree->root;
|
|
|
|
while (node->left != tree->nil)
|
|
|
|
node = node->left;
|
2000-10-26 00:36:47 +00:00
|
|
|
tmp = iter;
|
|
|
|
has_child = gtk_tree_model_iter_children (selection->tree_view->priv->model, &iter, &tmp);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
/* Sanity Check! */
|
2000-10-26 00:36:47 +00:00
|
|
|
TREE_VIEW_INTERNAL_ASSERT_VOID (has_child);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gboolean done = FALSE;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
node = _gtk_rbtree_next (tree, node);
|
|
|
|
if (node != NULL)
|
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
gboolean has_next;
|
|
|
|
|
|
|
|
has_next = gtk_tree_model_iter_next (selection->tree_view->priv->model, &iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
done = TRUE;
|
|
|
|
|
|
|
|
/* Sanity Check! */
|
2000-10-26 00:36:47 +00:00
|
|
|
TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
gboolean has_parent;
|
|
|
|
GtkTreeIter tmp_iter = iter;
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
node = tree->parent_node;
|
|
|
|
tree = tree->parent_tree;
|
|
|
|
if (tree == NULL)
|
|
|
|
/* we've run out of tree */
|
|
|
|
/* We're done with this function */
|
|
|
|
return;
|
2000-10-26 00:36:47 +00:00
|
|
|
has_parent = gtk_tree_model_iter_parent (selection->tree_view->priv->model, &iter, &tmp_iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
2000-10-26 00:36:47 +00:00
|
|
|
TREE_VIEW_INTERNAL_ASSERT_VOID (has_parent);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_select_path:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
|
|
|
* @path: The #GtkTreePath to be selected.
|
|
|
|
*
|
|
|
|
* Select the row at @path.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
gtk_tree_selection_select_path (GtkTreeSelection *selection,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
GtkRBNode *node;
|
|
|
|
GtkRBTree *tree;
|
|
|
|
GdkModifierType state = 0;
|
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (selection->tree_view != NULL);
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
|
|
|
_gtk_tree_view_find_node (selection->tree_view,
|
|
|
|
path,
|
|
|
|
&tree,
|
|
|
|
&node);
|
|
|
|
|
|
|
|
if (node == NULL || GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selection->type == GTK_TREE_SELECTION_MULTI)
|
|
|
|
state = GDK_CONTROL_MASK;
|
|
|
|
|
|
|
|
_gtk_tree_selection_internal_select_node (selection,
|
|
|
|
node,
|
|
|
|
tree,
|
|
|
|
path,
|
|
|
|
state);
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_unselect_path:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
|
|
|
* @path: The #GtkTreePath to be unselected.
|
|
|
|
*
|
|
|
|
* Unselects the row at @path.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
gtk_tree_selection_unselect_path (GtkTreeSelection *selection,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
GtkRBNode *node;
|
|
|
|
GtkRBTree *tree;
|
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (selection->tree_view != NULL);
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
|
|
|
_gtk_tree_view_find_node (selection->tree_view,
|
|
|
|
path,
|
|
|
|
&tree,
|
|
|
|
&node);
|
|
|
|
|
|
|
|
if (node == NULL || !GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
_gtk_tree_selection_internal_select_node (selection,
|
|
|
|
node,
|
|
|
|
tree,
|
|
|
|
path,
|
|
|
|
GDK_CONTROL_MASK);
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
2000-10-26 00:36:47 +00:00
|
|
|
* gtk_tree_selection_select_iter:
|
2000-10-16 07:03:54 +00:00
|
|
|
* @selection: A #GtkTreeSelection.
|
2000-10-26 00:36:47 +00:00
|
|
|
* @iter: The #GtkTreeIter to be selected.
|
2000-10-16 07:03:54 +00:00
|
|
|
*
|
2000-10-26 00:36:47 +00:00
|
|
|
* Selects the specified iterator.
|
2000-10-16 07:03:54 +00:00
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_selection_select_iter (GtkTreeSelection *selection,
|
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (selection->tree_view != NULL);
|
|
|
|
g_return_if_fail (selection->tree_view->priv->model != NULL);
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_if_fail (iter == NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (selection->tree_view->priv->model,
|
2000-10-26 00:36:47 +00:00
|
|
|
iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_selection_select_path (selection, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
2000-10-26 00:36:47 +00:00
|
|
|
* gtk_tree_selection_unselect_iter:
|
2000-10-16 07:03:54 +00:00
|
|
|
* @selection: A #GtkTreeSelection.
|
2000-10-26 00:36:47 +00:00
|
|
|
* @iter: The #GtkTreeIter to be unselected.
|
2000-10-16 07:03:54 +00:00
|
|
|
*
|
2000-10-26 00:36:47 +00:00
|
|
|
* Unselects the specified iterator.
|
2000-10-16 07:03:54 +00:00
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,
|
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (selection->tree_view != NULL);
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_if_fail (selection->tree_view->priv->model != NULL);
|
|
|
|
g_return_if_fail (iter == NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (selection->tree_view->priv->model,
|
2000-10-26 00:36:47 +00:00
|
|
|
iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_selection_select_path (selection, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wish I was in python, right now... */
|
|
|
|
struct _TempTuple {
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
gint dirty;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_all_helper (GtkRBTree *tree,
|
|
|
|
GtkRBNode *node,
|
Fix GtkTreeNode *node ->GtkTreeNode node issue.
2000-10-15 <jrb@redhat.com>
* gtk/gtktreeview.c, gtk/gtktreeview.h, gtk/gtktreestore.h,
gtk/gtktreestore.c, gtk/gtkliststore.h, gtk/gtkliststore.c,
gtk/gtkmodelsimple.c, gtk/gtkmodelsimple.h, gtk/gtktreedatalist.c,
gtk/gtktreemodel.h, gtk/gtktreeselection.c,
gtk/gtktreeselection.h: Fix GtkTreeNode *node ->GtkTreeNode node
issue.
2000-10-15 17:46:23 +00:00
|
|
|
gpointer data)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
struct _TempTuple *tuple = data;
|
|
|
|
|
|
|
|
if (node->children)
|
|
|
|
_gtk_rbtree_traverse (node->children,
|
|
|
|
node->children->root,
|
|
|
|
G_PRE_ORDER,
|
|
|
|
select_all_helper,
|
|
|
|
data);
|
|
|
|
if (!GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
|
|
|
|
{
|
2000-10-06 00:06:00 +00:00
|
|
|
tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, TRUE) || tuple->dirty;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-06 00:06:00 +00:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
gtk_tree_selection_real_select_all (GtkTreeSelection *selection)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
struct _TempTuple *tuple;
|
2000-10-06 00:06:00 +00:00
|
|
|
if (selection->tree_view->priv->tree == NULL)
|
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (selection->type == GTK_TREE_SELECTION_SINGLE)
|
|
|
|
{
|
2000-10-06 00:06:00 +00:00
|
|
|
GtkRBTree *tree;
|
2000-10-05 01:04:57 +00:00
|
|
|
GtkRBNode *node;
|
2000-10-06 00:06:00 +00:00
|
|
|
gint dirty;
|
|
|
|
|
|
|
|
dirty = gtk_tree_selection_real_unselect_all (selection);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-06 00:06:00 +00:00
|
|
|
tree = selection->tree_view->priv->tree;
|
|
|
|
node = tree->root;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
while (node->right != selection->tree_view->priv->tree->nil)
|
|
|
|
node = node->right;
|
|
|
|
|
|
|
|
if (node->children)
|
|
|
|
{
|
|
|
|
tree = node->children;
|
|
|
|
node = tree->root;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
} while (TRUE);
|
|
|
|
|
|
|
|
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
|
|
|
|
|
|
|
|
return dirty;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tuple = g_new (struct _TempTuple, 1);
|
|
|
|
tuple->selection = selection;
|
|
|
|
tuple->dirty = FALSE;
|
|
|
|
|
|
|
|
_gtk_rbtree_traverse (selection->tree_view->priv->tree,
|
|
|
|
selection->tree_view->priv->tree->root,
|
|
|
|
G_PRE_ORDER,
|
|
|
|
select_all_helper,
|
|
|
|
tuple);
|
|
|
|
if (tuple->dirty)
|
2000-10-06 00:06:00 +00:00
|
|
|
{
|
|
|
|
g_free (tuple);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
g_free (tuple);
|
2000-10-06 00:06:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_select_all:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
|
|
|
*
|
|
|
|
* Selects all the nodes. If the type of @selection is
|
|
|
|
* #GTK_TREE_SELECTION_SINGLE, then the last row is selected.
|
|
|
|
**/
|
2000-10-06 00:06:00 +00:00
|
|
|
void
|
|
|
|
gtk_tree_selection_select_all (GtkTreeSelection *selection)
|
|
|
|
{
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (selection->tree_view != NULL);
|
|
|
|
g_return_if_fail (selection->tree_view->priv->tree != NULL);
|
|
|
|
|
|
|
|
if (gtk_tree_selection_real_select_all (selection))
|
|
|
|
gtk_signal_emit (GTK_OBJECT (selection), tree_selection_signals[SELECTION_CHANGED]);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unselect_all_helper (GtkRBTree *tree,
|
|
|
|
GtkRBNode *node,
|
Fix GtkTreeNode *node ->GtkTreeNode node issue.
2000-10-15 <jrb@redhat.com>
* gtk/gtktreeview.c, gtk/gtktreeview.h, gtk/gtktreestore.h,
gtk/gtktreestore.c, gtk/gtkliststore.h, gtk/gtkliststore.c,
gtk/gtkmodelsimple.c, gtk/gtkmodelsimple.h, gtk/gtktreedatalist.c,
gtk/gtktreemodel.h, gtk/gtktreeselection.c,
gtk/gtktreeselection.h: Fix GtkTreeNode *node ->GtkTreeNode node
issue.
2000-10-15 17:46:23 +00:00
|
|
|
gpointer data)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
struct _TempTuple *tuple = data;
|
|
|
|
|
|
|
|
if (node->children)
|
|
|
|
_gtk_rbtree_traverse (node->children,
|
|
|
|
node->children->root,
|
|
|
|
G_PRE_ORDER,
|
|
|
|
unselect_all_helper,
|
|
|
|
data);
|
|
|
|
if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
|
|
|
|
{
|
2000-10-06 00:06:00 +00:00
|
|
|
tuple->dirty = gtk_tree_selection_real_select_node (tuple->selection, tree, node, FALSE) || tuple->dirty;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-06 00:06:00 +00:00
|
|
|
static gint
|
|
|
|
gtk_tree_selection_real_unselect_all (GtkTreeSelection *selection)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
struct _TempTuple *tuple;
|
|
|
|
|
|
|
|
if (selection->type == GTK_TREE_SELECTION_SINGLE)
|
|
|
|
{
|
|
|
|
GtkRBTree *tree = NULL;
|
|
|
|
GtkRBNode *node = NULL;
|
|
|
|
if (selection->tree_view->priv->anchor == NULL)
|
2000-10-06 00:06:00 +00:00
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
_gtk_tree_view_find_node (selection->tree_view,
|
|
|
|
selection->tree_view->priv->anchor,
|
|
|
|
&tree,
|
|
|
|
&node);
|
|
|
|
if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
|
2000-10-06 00:06:00 +00:00
|
|
|
{
|
|
|
|
gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tuple = g_new (struct _TempTuple, 1);
|
|
|
|
tuple->selection = selection;
|
|
|
|
tuple->dirty = FALSE;
|
|
|
|
|
|
|
|
_gtk_rbtree_traverse (selection->tree_view->priv->tree,
|
|
|
|
selection->tree_view->priv->tree->root,
|
|
|
|
G_PRE_ORDER,
|
|
|
|
unselect_all_helper,
|
|
|
|
tuple);
|
2000-10-06 00:06:00 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
if (tuple->dirty)
|
2000-10-06 00:06:00 +00:00
|
|
|
{
|
|
|
|
g_free (tuple);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
g_free (tuple);
|
2000-10-06 00:06:00 +00:00
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_selection_unselect_all:
|
|
|
|
* @selection: A #GtkTreeSelection.
|
|
|
|
*
|
|
|
|
* Unselects all the nodes.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
2000-10-06 00:06:00 +00:00
|
|
|
gtk_tree_selection_unselect_all (GtkTreeSelection *selection)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (selection->tree_view != NULL);
|
2000-10-06 00:06:00 +00:00
|
|
|
g_return_if_fail (selection->tree_view->priv->tree != NULL);
|
|
|
|
if (selection->tree_view->priv->tree == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gtk_tree_selection_real_unselect_all (selection))
|
|
|
|
gtk_signal_emit (GTK_OBJECT (selection), tree_selection_signals[SELECTION_CHANGED]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_tree_selection_real_select_range (GtkTreeSelection *selection,
|
|
|
|
GtkTreePath *start_path,
|
|
|
|
GtkTreePath *end_path)
|
|
|
|
{
|
|
|
|
GtkRBNode *start_node, *end_node;
|
|
|
|
GtkRBTree *start_tree, *end_tree;
|
|
|
|
gboolean dirty = FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-10-06 00:06:00 +00:00
|
|
|
g_return_val_if_fail (start_node != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (end_node != NULL, FALSE);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2000-10-06 00:06:00 +00:00
|
|
|
if (GTK_RBNODE_FLAG_SET (start_node, GTK_RBNODE_IS_SELECTED))
|
|
|
|
{
|
|
|
|
dirty = gtk_tree_selection_real_select_node (selection, start_tree, start_node, FALSE);
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (start_node == end_node)
|
2000-10-06 00:06:00 +00:00
|
|
|
break;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (start_node->children)
|
|
|
|
{
|
|
|
|
start_tree = start_node->children;
|
|
|
|
start_node = start_tree->root;
|
|
|
|
while (start_node->left != start_tree->nil)
|
|
|
|
start_node = start_node->left;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gboolean done = FALSE;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
start_node = _gtk_rbtree_next (start_tree, start_node);
|
|
|
|
if (start_node != NULL)
|
|
|
|
{
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start_node = start_tree->parent_node;
|
|
|
|
start_tree = start_tree->parent_tree;
|
|
|
|
if (start_tree == NULL)
|
|
|
|
/* we've run out of tree */
|
|
|
|
/* This means we never found end node!! */
|
2000-10-06 00:06:00 +00:00
|
|
|
break;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (TRUE);
|
2000-10-06 00:06:00 +00:00
|
|
|
|
|
|
|
return dirty;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-16 07:03:54 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
**/
|
2000-10-06 00:06:00 +00:00
|
|
|
void
|
|
|
|
gtk_tree_selection_select_range (GtkTreeSelection *selection,
|
|
|
|
GtkTreePath *start_path,
|
|
|
|
GtkTreePath *end_path)
|
|
|
|
{
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
|
|
|
|
g_return_if_fail (selection->tree_view != NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-06 00:06:00 +00:00
|
|
|
if (gtk_tree_selection_real_select_range (selection, start_path, end_path))
|
|
|
|
gtk_signal_emit (GTK_OBJECT (selection), tree_selection_signals[SELECTION_CHANGED]);
|
|
|
|
}
|
|
|
|
/* Called internally by gtktreeview.c It handles actually selecting the tree.
|
|
|
|
* This should almost certainly ever be called by anywhere else.
|
|
|
|
*/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
_gtk_tree_selection_internal_select_node (GtkTreeSelection *selection,
|
|
|
|
GtkRBNode *node,
|
|
|
|
GtkRBTree *tree,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GdkModifierType state)
|
|
|
|
{
|
|
|
|
gint flags;
|
2000-10-06 00:06:00 +00:00
|
|
|
gint dirty = FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) && (selection->tree_view->priv->anchor == NULL))
|
|
|
|
{
|
|
|
|
selection->tree_view->priv->anchor = gtk_tree_path_copy (path);
|
2000-10-06 00:06:00 +00:00
|
|
|
dirty = gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
else if ((state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) == (GDK_SHIFT_MASK|GDK_CONTROL_MASK))
|
|
|
|
{
|
|
|
|
gtk_tree_selection_select_range (selection,
|
|
|
|
selection->tree_view->priv->anchor,
|
|
|
|
path);
|
|
|
|
}
|
|
|
|
else if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
flags = node->flags;
|
|
|
|
if (selection->type == GTK_TREE_SELECTION_SINGLE)
|
2000-10-06 00:06:00 +00:00
|
|
|
dirty = gtk_tree_selection_real_unselect_all (selection);
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
if (selection->tree_view->priv->anchor)
|
|
|
|
gtk_tree_path_free (selection->tree_view->priv->anchor);
|
|
|
|
selection->tree_view->priv->anchor = gtk_tree_path_copy (path);
|
2000-10-06 00:06:00 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
if ((flags & GTK_RBNODE_IS_SELECTED) == GTK_RBNODE_IS_SELECTED)
|
2000-10-06 00:06:00 +00:00
|
|
|
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, FALSE);
|
2000-10-05 01:04:57 +00:00
|
|
|
else
|
2000-10-06 00:06:00 +00:00
|
|
|
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
else if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
|
|
|
|
{
|
2000-10-06 00:06:00 +00:00
|
|
|
dirty = gtk_tree_selection_real_unselect_all (selection);
|
|
|
|
dirty |= gtk_tree_selection_real_select_range (selection,
|
|
|
|
selection->tree_view->priv->anchor,
|
|
|
|
path);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-06 00:06:00 +00:00
|
|
|
dirty = gtk_tree_selection_real_unselect_all (selection);
|
2000-10-05 01:04:57 +00:00
|
|
|
if (selection->tree_view->priv->anchor)
|
|
|
|
gtk_tree_path_free (selection->tree_view->priv->anchor);
|
|
|
|
selection->tree_view->priv->anchor = gtk_tree_path_copy (path);
|
2000-10-06 00:06:00 +00:00
|
|
|
dirty |= gtk_tree_selection_real_select_node (selection, tree, node, TRUE);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
2000-10-06 00:06:00 +00:00
|
|
|
|
|
|
|
if (dirty)
|
|
|
|
gtk_signal_emit (GTK_OBJECT (selection), tree_selection_signals[SELECTION_CHANGED]);
|
|
|
|
}
|
|
|
|
|
2000-10-13 00:34:38 +00:00
|
|
|
/* NOTE: Any {un,}selection ever done _MUST_ be done through this function!
|
|
|
|
*/
|
2000-10-16 07:03:54 +00:00
|
|
|
|
|
|
|
/* FIXME: user_func can screw up GTK_TREE_SELECTION_SINGLE. If it prevents
|
|
|
|
* unselection of a node, it can keep more then one node selected.
|
|
|
|
*/
|
2000-10-06 00:06:00 +00:00
|
|
|
static gint
|
|
|
|
gtk_tree_selection_real_select_node (GtkTreeSelection *selection,
|
|
|
|
GtkRBTree *tree,
|
|
|
|
GtkRBNode *node,
|
|
|
|
gboolean select)
|
|
|
|
{
|
|
|
|
gboolean selected = FALSE;
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
|
|
|
if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
|
|
|
|
{
|
|
|
|
path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
|
|
|
|
if (selection->user_func)
|
|
|
|
{
|
|
|
|
if ((*selection->user_func) (selection, selection->tree_view->priv->model, path, selection->user_data))
|
|
|
|
selected = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
selected = TRUE;
|
|
|
|
}
|
|
|
|
if (selected == TRUE)
|
|
|
|
{
|
|
|
|
node->flags ^= GTK_RBNODE_IS_SELECTED;
|
|
|
|
|
|
|
|
/* FIXME: just draw the one node*/
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (selection->tree_view));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|