2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
1997-11-24 22:37:52 +00:00
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1997-11-24 22:37:52 +00:00
|
|
|
|
* 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
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
1997-11-24 22:37:52 +00:00
|
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-24 22:37:52 +00:00
|
|
|
|
*/
|
1999-02-24 07:37:18 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:37:18 +00:00
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2010-10-19 00:01:31 +00:00
|
|
|
|
|
|
|
|
|
#include "gtkradiobutton.h"
|
|
|
|
|
|
2018-03-17 09:30:10 +00:00
|
|
|
|
#include "gtkwidgetprivate.h"
|
2015-10-30 04:27:13 +00:00
|
|
|
|
#include "gtkcheckbuttonprivate.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
|
#include "gtklabel.h"
|
2004-02-26 18:58:26 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2002-10-13 23:56:31 +00:00
|
|
|
|
#include "gtkintl.h"
|
2011-06-28 03:24:22 +00:00
|
|
|
|
#include "a11y/gtkradiobuttonaccessible.h"
|
2015-10-30 04:27:13 +00:00
|
|
|
|
#include "gtkstylecontextprivate.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2010-05-19 22:40:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtkradiobutton
|
|
|
|
|
* @Short_description: A choice from multiple check buttons
|
|
|
|
|
* @Title: GtkRadioButton
|
|
|
|
|
* @See_also: #GtkComboBox
|
|
|
|
|
*
|
|
|
|
|
* A single radio button performs the same basic function as a #GtkCheckButton,
|
|
|
|
|
* as its position in the object hierarchy reflects. It is only when multiple
|
|
|
|
|
* radio buttons are grouped together that they become a different user
|
|
|
|
|
* interface component in their own right.
|
|
|
|
|
*
|
|
|
|
|
* Every radio button is a member of some group of radio buttons. When one is
|
|
|
|
|
* selected, all other radio buttons in the same group are deselected. A
|
|
|
|
|
* #GtkRadioButton is one way of giving the user a choice from many options.
|
|
|
|
|
*
|
|
|
|
|
* Radio button widgets are created with gtk_radio_button_new(), passing %NULL
|
|
|
|
|
* as the argument if this is the first radio button in a group. In subsequent
|
|
|
|
|
* calls, the group you wish to add this button to should be passed as an
|
|
|
|
|
* argument. Optionally, gtk_radio_button_new_with_label() can be used if you
|
|
|
|
|
* want a text label on the radio button.
|
|
|
|
|
*
|
|
|
|
|
* Alternatively, when adding widgets to an existing group of radio buttons,
|
|
|
|
|
* use gtk_radio_button_new_from_widget() with a #GtkRadioButton that already
|
|
|
|
|
* has a group assigned to it. The convenience function
|
|
|
|
|
* gtk_radio_button_new_with_label_from_widget() is also provided.
|
|
|
|
|
*
|
|
|
|
|
* To retrieve the group a #GtkRadioButton is assigned to, use
|
|
|
|
|
* gtk_radio_button_get_group().
|
|
|
|
|
*
|
|
|
|
|
* To remove a #GtkRadioButton from one group and make it part of a new one,
|
|
|
|
|
* use gtk_radio_button_set_group().
|
|
|
|
|
*
|
|
|
|
|
* The group list does not need to be freed, as each #GtkRadioButton will remove
|
|
|
|
|
* itself and its list item when it is destroyed.
|
|
|
|
|
*
|
2015-10-30 04:27:13 +00:00
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
2015-11-03 15:17:41 +00:00
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
|
* radiobutton
|
2015-12-16 15:55:52 +00:00
|
|
|
|
* ├── radio
|
|
|
|
|
* ╰── <child>
|
2015-11-03 15:17:41 +00:00
|
|
|
|
* ]|
|
|
|
|
|
*
|
2017-01-27 11:02:47 +00:00
|
|
|
|
* A GtkRadioButton with indicator (see gtk_check_button_set_draw_indicator())) has a
|
2015-10-30 04:27:13 +00:00
|
|
|
|
* main CSS node with name radiobutton and a subnode with name radio.
|
|
|
|
|
*
|
2015-11-03 15:17:41 +00:00
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
|
* button.radio
|
2015-12-16 15:55:52 +00:00
|
|
|
|
* ├── radio
|
|
|
|
|
* ╰── <child>
|
2015-11-03 15:17:41 +00:00
|
|
|
|
* ]|
|
|
|
|
|
*
|
2015-10-30 04:27:13 +00:00
|
|
|
|
* A GtkRadioButton without indicator changes the name of its main node
|
|
|
|
|
* to button and adds a .radio style class to it. The subnode is invisible
|
|
|
|
|
* in this case.
|
|
|
|
|
*
|
2014-02-04 21:57:57 +00:00
|
|
|
|
* ## How to create a group of two radio buttons.
|
|
|
|
|
*
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* void create_radio_buttons (void) {
|
|
|
|
|
*
|
|
|
|
|
* GtkWidget *window, *radio1, *radio2, *box, *entry;
|
2020-02-14 19:55:36 +00:00
|
|
|
|
* window = gtk_window_new ();
|
2012-08-20 10:02:37 +00:00
|
|
|
|
* box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
|
|
|
|
* gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Create a radio button with a GtkEntry widget
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* radio1 = gtk_radio_button_new (NULL);
|
2014-02-09 22:24:06 +00:00
|
|
|
|
* entry = gtk_entry_new ();
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* gtk_container_add (GTK_CONTAINER (radio1), entry);
|
|
|
|
|
*
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Create a radio button with a label
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1),
|
2014-02-07 18:42:09 +00:00
|
|
|
|
* "I’m the second radio button.");
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Pack them into a box, then show all the widgets
|
2018-12-26 07:20:34 +00:00
|
|
|
|
* gtk_container_add (GTK_CONTAINER (box), radio1);
|
|
|
|
|
* gtk_container_add (GTK_CONTAINER (box), radio2);
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* gtk_container_add (GTK_CONTAINER (window), box);
|
2017-01-19 09:02:04 +00:00
|
|
|
|
* gtk_widget_show (window);
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* return;
|
|
|
|
|
* }
|
2014-01-27 17:12:55 +00:00
|
|
|
|
* ]|
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*
|
|
|
|
|
* When an unselected button in the group is clicked the clicked button
|
|
|
|
|
* receives the #GtkToggleButton::toggled signal, as does the previously
|
|
|
|
|
* selected button.
|
|
|
|
|
* Inside the #GtkToggleButton::toggled handler, gtk_toggle_button_get_active()
|
|
|
|
|
* can be used to determine if the button has been selected or deselected.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-05-27 04:10:48 +00:00
|
|
|
|
typedef struct _GtkRadioButtonClass GtkRadioButtonClass;
|
|
|
|
|
|
|
|
|
|
struct _GtkRadioButton
|
|
|
|
|
{
|
|
|
|
|
GtkCheckButton parent_instance;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GtkRadioButtonClass
|
|
|
|
|
{
|
|
|
|
|
GtkCheckButtonClass parent_class;
|
|
|
|
|
|
|
|
|
|
void (*group_changed) (GtkRadioButton *radio_button);
|
|
|
|
|
};
|
2010-05-19 22:40:58 +00:00
|
|
|
|
|
2018-06-18 10:33:37 +00:00
|
|
|
|
typedef struct
|
2010-07-07 23:04:11 +00:00
|
|
|
|
{
|
|
|
|
|
GSList *group;
|
2018-06-18 10:33:37 +00:00
|
|
|
|
} GtkRadioButtonPrivate;
|
2010-07-07 23:04:11 +00:00
|
|
|
|
|
1998-06-24 06:25:14 +00:00
|
|
|
|
enum {
|
2002-10-13 23:56:31 +00:00
|
|
|
|
PROP_0,
|
2015-09-06 14:46:00 +00:00
|
|
|
|
PROP_GROUP,
|
|
|
|
|
LAST_PROP
|
1998-06-24 06:25:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-08-20 14:51:53 +00:00
|
|
|
|
enum {
|
|
|
|
|
GROUP_CHANGED,
|
|
|
|
|
N_SIGNALS
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-06 14:46:00 +00:00
|
|
|
|
static GParamSpec *radio_button_props[LAST_PROP] = { NULL, };
|
2018-08-20 14:51:53 +00:00
|
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2010-09-18 23:55:42 +00:00
|
|
|
|
static void gtk_radio_button_destroy (GtkWidget *widget);
|
2001-10-16 21:02:24 +00:00
|
|
|
|
static gboolean gtk_radio_button_focus (GtkWidget *widget,
|
|
|
|
|
GtkDirectionType direction);
|
|
|
|
|
static void gtk_radio_button_clicked (GtkButton *button);
|
2002-10-13 23:56:31 +00:00
|
|
|
|
static void gtk_radio_button_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
static void gtk_radio_button_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkRadioButton, gtk_radio_button, GTK_TYPE_CHECK_BUTTON)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_radio_button_class_init (GtkRadioButtonClass *class)
|
|
|
|
|
{
|
2002-10-13 23:56:31 +00:00
|
|
|
|
GObjectClass *gobject_class;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
GtkButtonClass *button_class;
|
2001-10-16 21:02:24 +00:00
|
|
|
|
GtkWidgetClass *widget_class;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2002-10-13 23:56:31 +00:00
|
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
2001-10-16 21:02:24 +00:00
|
|
|
|
widget_class = (GtkWidgetClass*) class;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
button_class = (GtkButtonClass*) class;
|
|
|
|
|
|
2002-10-13 23:56:31 +00:00
|
|
|
|
gobject_class->set_property = gtk_radio_button_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_radio_button_get_property;
|
1998-06-24 06:25:14 +00:00
|
|
|
|
|
2010-05-19 22:40:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkRadioButton:group:
|
|
|
|
|
*
|
|
|
|
|
* Sets a new group for a radio button.
|
|
|
|
|
*/
|
2015-09-06 14:46:00 +00:00
|
|
|
|
radio_button_props[PROP_GROUP] =
|
|
|
|
|
g_param_spec_object ("group",
|
|
|
|
|
P_("Group"),
|
|
|
|
|
P_("The radio button whose group this widget belongs to."),
|
|
|
|
|
GTK_TYPE_RADIO_BUTTON,
|
|
|
|
|
GTK_PARAM_WRITABLE);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class, LAST_PROP, radio_button_props);
|
|
|
|
|
|
2010-09-18 23:55:42 +00:00
|
|
|
|
widget_class->destroy = gtk_radio_button_destroy;
|
2001-10-16 21:02:24 +00:00
|
|
|
|
widget_class->focus = gtk_radio_button_focus;
|
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
|
button_class->clicked = gtk_radio_button_clicked;
|
|
|
|
|
|
2004-02-26 18:58:26 +00:00
|
|
|
|
class->group_changed = NULL;
|
|
|
|
|
|
|
|
|
|
/**
|
2005-04-03 07:11:09 +00:00
|
|
|
|
* GtkRadioButton::group-changed:
|
2011-01-18 09:12:38 +00:00
|
|
|
|
* @button: the object which received the signal
|
2004-02-26 18:58:26 +00:00
|
|
|
|
*
|
|
|
|
|
* Emitted when the group of radio buttons that a radio button belongs
|
|
|
|
|
* to changes. This is emitted when a radio button switches from
|
|
|
|
|
* being alone to being part of a group of 2 or more buttons, or
|
2007-06-03 04:56:00 +00:00
|
|
|
|
* vice-versa, and when a button is moved from one group of 2 or
|
2004-02-26 18:58:26 +00:00
|
|
|
|
* more buttons to a different one, but not when the composition
|
|
|
|
|
* of the group that a button belongs to changes.
|
|
|
|
|
*/
|
2018-08-20 14:51:53 +00:00
|
|
|
|
signals[GROUP_CHANGED] = g_signal_new (I_("group-changed"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkRadioButtonClass, group_changed),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
G_TYPE_NONE, 0);
|
2010-07-07 23:04:11 +00:00
|
|
|
|
|
2011-06-28 03:24:22 +00:00
|
|
|
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_RADIO_BUTTON_ACCESSIBLE);
|
2017-11-18 03:49:57 +00:00
|
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("radiobutton"));
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-21 01:50:07 +00:00
|
|
|
|
gtk_radio_button_init (GtkRadioButton *self)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
2020-01-21 01:50:07 +00:00
|
|
|
|
GtkRadioButtonPrivate *priv = gtk_radio_button_get_instance_private (self);
|
|
|
|
|
GtkWidget *widget = GTK_WIDGET (self);
|
2015-10-30 04:27:13 +00:00
|
|
|
|
GtkCssNode *css_node;
|
2010-07-07 23:04:11 +00:00
|
|
|
|
|
2020-01-21 01:50:07 +00:00
|
|
|
|
gtk_widget_set_receives_default (widget, FALSE);
|
1999-01-22 08:12:00 +00:00
|
|
|
|
|
2020-01-21 01:50:07 +00:00
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self), TRUE);
|
1999-01-22 08:12:00 +00:00
|
|
|
|
|
2020-01-21 01:50:07 +00:00
|
|
|
|
priv->group = g_slist_prepend (NULL, self);
|
2015-10-30 04:27:13 +00:00
|
|
|
|
|
2020-01-21 01:50:07 +00:00
|
|
|
|
css_node = gtk_widget_get_css_node (widget);
|
2020-01-23 23:43:26 +00:00
|
|
|
|
gtk_css_node_set_name (css_node, g_quark_from_static_string ("radiobutton"));
|
2020-01-21 01:50:07 +00:00
|
|
|
|
css_node = gtk_check_button_get_indicator_node (GTK_CHECK_BUTTON (self));
|
2020-01-23 23:43:26 +00:00
|
|
|
|
gtk_css_node_set_name (css_node, g_quark_from_static_string ("radio"));
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-24 06:25:14 +00:00
|
|
|
|
static void
|
2002-10-13 23:56:31 +00:00
|
|
|
|
gtk_radio_button_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
1998-06-24 06:25:14 +00:00
|
|
|
|
{
|
new function gtk_container_child_arg_set, similar to
Wed Jun 24 14:14:32 1998 Tim Janik <timj@gtk.org>
* gtk/gtkcontainer.c: new function gtk_container_child_arg_set, similar
to gtk_container_child_arg_setv, but takes a variable argument list.
new function gtk_container_get_child_arg_type, which is needed by
gtk_object_collect_args.
* gtk/gtkobject.c: changed prototype for gtk_object_collect_args, to
take a function pointer to figure the argument type.
adapted callers to pass gtk_object_get_arg_type.
* gtk/gtkwidget.c: adapted gtk_object_collect_args callers to pass
gtk_object_get_arg_type..
* gtk/gtkpacker.h:
* gtk/gtkpacker.c:
(gtk_packer_reorder_child): new function to change the packing order
of a child.
(gtk_packer_size_request):
(gtk_packer_size_allocate): take container->border_width into acount.
* gtk/gtkpacker.c: implemented widget arguments:
"GtkPacker::spacing", "GtkPacker::border_width", "GtkPacker::pad_x",
"GtkPacker::pad_y", "GtkPacker::ipad_x", "GtkPacker::ipad_y".
implemented child arguments:
"GtkPacker::side", "GtkPacker::anchor", "GtkPacker::expand",
"GtkPacker::fill_x", "GtkPacker::fill_y", "GtkPacker::use_default",
"GtkPacker::border_width", "GtkPacker::pad_x", "GtkPacker::pad_y",
"GtkPacker::ipad_x", "GtkPacker::ipad_y", "GtkPacker::position".
* gtk/gtkmisc.c (gtk_misc_set_arg): for padding args, set the padding,
not the alignment.
* gtk/gtkeventbox.h:
* gtk/gtkeventbox.c: GtkType and macro fixups.
* gtk/testgtk.c (entry_toggle_sensitive): new function to toggle
sensitivity of an entry.
* gtk/gtkstyle.c (gtk_style_new): support normal grey as default color
for insensitive base.
* gtk/gtkentry.c (gtk_entry_realize): set the window backgrounds
widget state dependent.
(gtk_entry_style_set): likewise.
(gtk_entry_state_changed): set background color on state changes.
(gtk_entry_draw_text): for non selected text, use state dependent
colors.
* gtk/gtktogglebutton.c: support for widget arguments
"GtkToggleButton::active" and "GtkToggleButton::draw_indicator".
1998-06-24 12:22:23 +00:00
|
|
|
|
GtkRadioButton *radio_button;
|
|
|
|
|
|
|
|
|
|
radio_button = GTK_RADIO_BUTTON (object);
|
|
|
|
|
|
2002-10-13 23:56:31 +00:00
|
|
|
|
switch (prop_id)
|
1998-06-24 06:25:14 +00:00
|
|
|
|
{
|
|
|
|
|
GSList *slist;
|
2007-02-28 16:16:54 +00:00
|
|
|
|
GtkRadioButton *button;
|
1998-06-24 06:25:14 +00:00
|
|
|
|
|
2002-10-13 23:56:31 +00:00
|
|
|
|
case PROP_GROUP:
|
2007-06-04 14:37:17 +00:00
|
|
|
|
button = g_value_get_object (value);
|
2007-02-28 16:16:54 +00:00
|
|
|
|
|
|
|
|
|
if (button)
|
|
|
|
|
slist = gtk_radio_button_get_group (button);
|
1998-06-24 06:25:14 +00:00
|
|
|
|
else
|
|
|
|
|
slist = NULL;
|
|
|
|
|
gtk_radio_button_set_group (radio_button, slist);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-13 23:56:31 +00:00
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
1998-06-24 06:25:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2002-10-13 23:56:31 +00:00
|
|
|
|
gtk_radio_button_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
1998-06-24 06:25:14 +00:00
|
|
|
|
{
|
2002-10-13 23:56:31 +00:00
|
|
|
|
switch (prop_id)
|
1998-06-24 06:25:14 +00:00
|
|
|
|
{
|
|
|
|
|
default:
|
2002-10-13 23:56:31 +00:00
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
1998-06-24 06:25:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 22:40:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_radio_button_set_group:
|
|
|
|
|
* @radio_button: a #GtkRadioButton.
|
2013-12-06 22:53:41 +00:00
|
|
|
|
* @group: (element-type GtkRadioButton) (allow-none): an existing radio
|
|
|
|
|
* button group, such as one returned from gtk_radio_button_get_group(), or %NULL.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* Sets a #GtkRadioButton’s group. It should be noted that this does not change
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* the layout of your interface in any way, so if you are changing the group,
|
|
|
|
|
* it is likely you will need to re-arrange the user interface to reflect these
|
|
|
|
|
* changes.
|
|
|
|
|
*/
|
1998-03-18 21:11:04 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_radio_button_set_group (GtkRadioButton *radio_button,
|
1999-01-22 08:12:00 +00:00
|
|
|
|
GSList *group)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
2018-06-18 10:33:37 +00:00
|
|
|
|
GtkRadioButtonPrivate *priv = gtk_radio_button_get_instance_private (radio_button);
|
2004-02-26 18:58:26 +00:00
|
|
|
|
GtkWidget *old_group_singleton = NULL;
|
|
|
|
|
GtkWidget *new_group_singleton = NULL;
|
2010-07-07 23:04:11 +00:00
|
|
|
|
|
1998-04-18 20:33:35 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_RADIO_BUTTON (radio_button));
|
2014-10-03 03:37:38 +00:00
|
|
|
|
|
|
|
|
|
if (g_slist_find (group, radio_button))
|
|
|
|
|
return;
|
1999-01-22 08:12:00 +00:00
|
|
|
|
|
2010-07-07 23:04:11 +00:00
|
|
|
|
if (priv->group)
|
1998-03-18 21:11:04 +00:00
|
|
|
|
{
|
1998-04-18 20:33:35 +00:00
|
|
|
|
GSList *slist;
|
2004-02-26 18:58:26 +00:00
|
|
|
|
|
2010-07-07 23:04:11 +00:00
|
|
|
|
priv->group = g_slist_remove (priv->group, radio_button);
|
|
|
|
|
|
|
|
|
|
if (priv->group && !priv->group->next)
|
|
|
|
|
old_group_singleton = g_object_ref (priv->group->data);
|
|
|
|
|
|
|
|
|
|
for (slist = priv->group; slist; slist = slist->next)
|
2018-06-18 10:33:37 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRadioButton *tmp_button = slist->data;
|
|
|
|
|
GtkRadioButtonPrivate *tmp_priv = gtk_radio_button_get_instance_private (tmp_button);
|
2010-07-07 23:04:11 +00:00
|
|
|
|
|
2018-06-18 10:33:37 +00:00
|
|
|
|
tmp_priv->group = priv->group;
|
|
|
|
|
}
|
1998-03-18 21:11:04 +00:00
|
|
|
|
}
|
1998-04-18 20:33:35 +00:00
|
|
|
|
|
2004-02-26 18:58:26 +00:00
|
|
|
|
if (group && !group->next)
|
|
|
|
|
new_group_singleton = g_object_ref (group->data);
|
2010-07-07 23:04:11 +00:00
|
|
|
|
|
|
|
|
|
priv->group = g_slist_prepend (group, radio_button);
|
|
|
|
|
|
1998-04-18 20:33:35 +00:00
|
|
|
|
if (group)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
1998-04-18 20:33:35 +00:00
|
|
|
|
GSList *slist;
|
|
|
|
|
|
|
|
|
|
for (slist = group; slist; slist = slist->next)
|
2018-06-18 10:33:37 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRadioButton *tmp_button = slist->data;
|
|
|
|
|
GtkRadioButtonPrivate *tmp_priv = gtk_radio_button_get_instance_private (tmp_button);
|
2010-07-07 23:04:11 +00:00
|
|
|
|
|
2018-06-18 10:33:37 +00:00
|
|
|
|
tmp_priv->group = priv->group;
|
|
|
|
|
}
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
1999-01-22 08:12:00 +00:00
|
|
|
|
|
2004-02-26 18:58:26 +00:00
|
|
|
|
g_object_ref (radio_button);
|
|
|
|
|
|
2015-09-06 14:46:00 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (radio_button), radio_button_props[PROP_GROUP]);
|
2018-08-20 14:51:53 +00:00
|
|
|
|
g_signal_emit (radio_button, signals[GROUP_CHANGED], 0);
|
2004-02-26 18:58:26 +00:00
|
|
|
|
if (old_group_singleton)
|
|
|
|
|
{
|
2018-08-20 14:51:53 +00:00
|
|
|
|
g_signal_emit (old_group_singleton, signals[GROUP_CHANGED], 0);
|
2004-02-26 18:58:26 +00:00
|
|
|
|
g_object_unref (old_group_singleton);
|
|
|
|
|
}
|
|
|
|
|
if (new_group_singleton)
|
|
|
|
|
{
|
2018-08-20 14:51:53 +00:00
|
|
|
|
g_signal_emit (new_group_singleton, signals[GROUP_CHANGED], 0);
|
2004-02-26 18:58:26 +00:00
|
|
|
|
g_object_unref (new_group_singleton);
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-22 08:12:00 +00:00
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), group == NULL);
|
2004-02-26 18:58:26 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (radio_button);
|
1998-03-18 21:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 02:55:03 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_radio_button_join_group:
|
|
|
|
|
* @radio_button: the #GtkRadioButton object
|
|
|
|
|
* @group_source: (allow-none): a radio button object whos group we are
|
|
|
|
|
* joining, or %NULL to remove the radio button from its group
|
|
|
|
|
*
|
|
|
|
|
* Joins a #GtkRadioButton object to the group of another #GtkRadioButton object
|
|
|
|
|
*
|
|
|
|
|
* Use this in language bindings instead of the gtk_radio_button_get_group()
|
|
|
|
|
* and gtk_radio_button_set_group() methods
|
|
|
|
|
*
|
|
|
|
|
* A common way to set up a group of radio buttons is the following:
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2010-09-07 02:55:03 +00:00
|
|
|
|
* GtkRadioButton *radio_button;
|
|
|
|
|
* GtkRadioButton *last_button;
|
|
|
|
|
*
|
2018-01-03 16:10:21 +00:00
|
|
|
|
* while (some_condition)
|
2010-09-07 02:55:03 +00:00
|
|
|
|
* {
|
2019-09-28 06:38:41 +00:00
|
|
|
|
* radio_button = GTK_RADIO_BUTTON (gtk_radio_button_new (NULL));
|
2010-09-07 02:55:03 +00:00
|
|
|
|
*
|
|
|
|
|
* gtk_radio_button_join_group (radio_button, last_button);
|
|
|
|
|
* last_button = radio_button;
|
|
|
|
|
* }
|
|
|
|
|
* ]|
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_radio_button_join_group (GtkRadioButton *radio_button,
|
|
|
|
|
GtkRadioButton *group_source)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_RADIO_BUTTON (radio_button));
|
|
|
|
|
g_return_if_fail (group_source == NULL || GTK_IS_RADIO_BUTTON (group_source));
|
|
|
|
|
|
|
|
|
|
if (group_source)
|
|
|
|
|
{
|
|
|
|
|
GSList *group;
|
|
|
|
|
group = gtk_radio_button_get_group (group_source);
|
|
|
|
|
|
|
|
|
|
if (!group)
|
|
|
|
|
{
|
|
|
|
|
/* if we are not already part of a group we need to set up a new one
|
|
|
|
|
and then get the newly created group */
|
|
|
|
|
gtk_radio_button_set_group (group_source, NULL);
|
|
|
|
|
group = gtk_radio_button_get_group (group_source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_radio_button_set_group (radio_button, group);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gtk_radio_button_set_group (radio_button, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 22:40:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_radio_button_new:
|
2011-01-20 09:37:17 +00:00
|
|
|
|
* @group: (element-type GtkRadioButton) (allow-none): an existing
|
|
|
|
|
* radio button group, or %NULL if you are creating a new group.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkRadioButton. To be of any practical value, a widget should
|
|
|
|
|
* then be packed into the radio button.
|
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* Returns: a new radio button
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*/
|
1998-03-18 21:11:04 +00:00
|
|
|
|
GtkWidget*
|
|
|
|
|
gtk_radio_button_new (GSList *group)
|
|
|
|
|
{
|
|
|
|
|
GtkRadioButton *radio_button;
|
|
|
|
|
|
2002-10-13 23:56:31 +00:00
|
|
|
|
radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON, NULL);
|
1998-03-18 21:11:04 +00:00
|
|
|
|
|
1999-01-22 08:12:00 +00:00
|
|
|
|
if (group)
|
|
|
|
|
gtk_radio_button_set_group (radio_button, group);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
|
|
return GTK_WIDGET (radio_button);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 22:40:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_radio_button_new_with_label:
|
2011-01-20 09:37:17 +00:00
|
|
|
|
* @group: (element-type GtkRadioButton) (allow-none): an existing
|
|
|
|
|
* radio button group, or %NULL if you are creating a new group.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* @label: the text label to display next to the radio button.
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkRadioButton with a text label.
|
|
|
|
|
*
|
2011-01-18 09:01:17 +00:00
|
|
|
|
* Returns: a new radio button.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
|
GtkWidget*
|
|
|
|
|
gtk_radio_button_new_with_label (GSList *group,
|
|
|
|
|
const gchar *label)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *radio_button;
|
|
|
|
|
|
2001-08-28 05:05:53 +00:00
|
|
|
|
radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON, "label", label, NULL) ;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2001-08-27 01:05:07 +00:00
|
|
|
|
if (group)
|
2001-08-29 02:20:02 +00:00
|
|
|
|
gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_button), group);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
|
|
return radio_button;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-05 18:22:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_radio_button_new_with_mnemonic:
|
2011-01-20 09:37:17 +00:00
|
|
|
|
* @group: (element-type GtkRadioButton) (allow-none): the radio button
|
2013-12-06 22:53:41 +00:00
|
|
|
|
* group, or %NULL
|
2001-06-05 18:22:30 +00:00
|
|
|
|
* @label: the text of the button, with an underscore in front of the
|
|
|
|
|
* mnemonic character
|
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* Creates a new #GtkRadioButton containing a label, adding it to the same
|
|
|
|
|
* group as @group. The label will be created using
|
|
|
|
|
* gtk_label_new_with_mnemonic(), so underscores in @label indicate the
|
Mass fixing of trivial doc bugs. (#63544, #57007, #64141, #63472, #57108,
* gtk/gtkiconfactory.c, gtk/gtktextbuffer.c, gtk/gtktreemodel.c,
gtk/gtkwindow.c, gtk/gtknotebook.c, gtk/gtkradiobutton.c,
gtk/gtktextiter.c, gtk/gtkdialog.c: Mass fixing of trivial doc bugs.
(#63544, #57007, #64141, #63472, #57108, #60818, #61562)
* gtk/tmpl/gtkaccellabel.sgml, gtk/tmpl/gtkcombo.sgml,
gtk/tmpl/gtkentry.sgml, gtk/tmpl/gtkhscrollbar.sgml,
gtk/tmpl/gtkvscrollbar.sgml, gtk/tmpl/gtktoolbar.sgml,
gtk/tmpl/gtkdialog.sgml, gtk/tmpl/gtkstatusbar.sgml:
Mass fixing of trivial doc bugs. (#55579, #56760, #58769, #55918,
#64154, #60422, #54697)
2001-11-10 22:06:44 +00:00
|
|
|
|
* mnemonic for the button.
|
2010-09-21 04:18:11 +00:00
|
|
|
|
*
|
2011-01-18 09:01:17 +00:00
|
|
|
|
* Returns: a new #GtkRadioButton
|
2010-09-21 04:18:11 +00:00
|
|
|
|
*/
|
2001-06-05 18:22:30 +00:00
|
|
|
|
GtkWidget*
|
|
|
|
|
gtk_radio_button_new_with_mnemonic (GSList *group,
|
|
|
|
|
const gchar *label)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *radio_button;
|
|
|
|
|
|
2005-03-26 05:49:15 +00:00
|
|
|
|
radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON,
|
|
|
|
|
"label", label,
|
|
|
|
|
"use-underline", TRUE,
|
|
|
|
|
NULL);
|
2001-06-05 18:22:30 +00:00
|
|
|
|
|
2001-08-27 01:05:07 +00:00
|
|
|
|
if (group)
|
2001-08-29 02:20:02 +00:00
|
|
|
|
gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_button), group);
|
2001-06-05 18:22:30 +00:00
|
|
|
|
|
|
|
|
|
return radio_button;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 22:40:58 +00:00
|
|
|
|
/**
|
2011-10-15 17:18:52 +00:00
|
|
|
|
* gtk_radio_button_new_from_widget: (constructor)
|
2010-11-19 09:19:32 +00:00
|
|
|
|
* @radio_group_member: (allow-none): an existing #GtkRadioButton.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* Creates a new #GtkRadioButton, adding it to the same group as
|
|
|
|
|
* @radio_group_member. As with gtk_radio_button_new(), a widget
|
|
|
|
|
* should be packed into the radio button.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*
|
2011-01-18 09:14:33 +00:00
|
|
|
|
* Returns: (transfer none): a new radio button.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
|
GtkWidget*
|
2007-06-27 11:28:55 +00:00
|
|
|
|
gtk_radio_button_new_from_widget (GtkRadioButton *radio_group_member)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
|
|
|
|
GSList *l = NULL;
|
2007-06-27 11:28:55 +00:00
|
|
|
|
if (radio_group_member)
|
|
|
|
|
l = gtk_radio_button_get_group (radio_group_member);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
return gtk_radio_button_new (l);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 22:40:58 +00:00
|
|
|
|
/**
|
2011-02-02 14:11:06 +00:00
|
|
|
|
* gtk_radio_button_new_with_label_from_widget: (constructor)
|
2010-11-19 09:19:32 +00:00
|
|
|
|
* @radio_group_member: (allow-none): widget to get radio group from or %NULL
|
2010-05-19 22:40:58 +00:00
|
|
|
|
* @label: a text string to display next to the radio button.
|
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* Creates a new #GtkRadioButton with a text label, adding it to
|
|
|
|
|
* the same group as @radio_group_member.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* Returns: (transfer none): a new radio button.
|
2010-05-19 22:40:58 +00:00
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
|
GtkWidget*
|
2007-06-27 11:28:55 +00:00
|
|
|
|
gtk_radio_button_new_with_label_from_widget (GtkRadioButton *radio_group_member,
|
1997-11-24 22:37:52 +00:00
|
|
|
|
const gchar *label)
|
|
|
|
|
{
|
|
|
|
|
GSList *l = NULL;
|
2007-06-27 11:28:55 +00:00
|
|
|
|
if (radio_group_member)
|
|
|
|
|
l = gtk_radio_button_get_group (radio_group_member);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
return gtk_radio_button_new_with_label (l, label);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-05 18:22:30 +00:00
|
|
|
|
/**
|
2011-02-02 14:11:06 +00:00
|
|
|
|
* gtk_radio_button_new_with_mnemonic_from_widget: (constructor)
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @radio_group_member: (allow-none): widget to get radio group from or %NULL
|
2001-06-05 18:22:30 +00:00
|
|
|
|
* @label: the text of the button, with an underscore in front of the
|
|
|
|
|
* mnemonic character
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkRadioButton containing a label. The label
|
|
|
|
|
* will be created using gtk_label_new_with_mnemonic(), so underscores
|
|
|
|
|
* in @label indicate the mnemonic for the button.
|
2010-09-21 04:18:11 +00:00
|
|
|
|
*
|
2011-01-18 09:14:33 +00:00
|
|
|
|
* Returns: (transfer none): a new #GtkRadioButton
|
2001-06-05 18:22:30 +00:00
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
2007-06-27 11:28:55 +00:00
|
|
|
|
gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *radio_group_member,
|
2001-06-05 18:22:30 +00:00
|
|
|
|
const gchar *label)
|
|
|
|
|
{
|
|
|
|
|
GSList *l = NULL;
|
2007-06-27 11:28:55 +00:00
|
|
|
|
if (radio_group_member)
|
|
|
|
|
l = gtk_radio_button_get_group (radio_group_member);
|
2001-06-05 18:22:30 +00:00
|
|
|
|
return gtk_radio_button_new_with_mnemonic (l, label);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-10 10:23:40 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_radio_button_get_group:
|
|
|
|
|
* @radio_button: a #GtkRadioButton.
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the group assigned to a radio button.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (element-type GtkRadioButton) (transfer none): a linked list
|
2009-12-10 10:23:40 +00:00
|
|
|
|
* containing all the radio buttons in the same group
|
|
|
|
|
* as @radio_button. The returned list is owned by the radio button
|
|
|
|
|
* and must not be modified or freed.
|
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
|
GSList*
|
2001-06-24 15:34:48 +00:00
|
|
|
|
gtk_radio_button_get_group (GtkRadioButton *radio_button)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
2018-06-18 10:33:37 +00:00
|
|
|
|
GtkRadioButtonPrivate *priv = gtk_radio_button_get_instance_private (radio_button);
|
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_RADIO_BUTTON (radio_button), NULL);
|
|
|
|
|
|
2018-06-18 10:33:37 +00:00
|
|
|
|
return priv->group;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-09-18 23:55:42 +00:00
|
|
|
|
gtk_radio_button_destroy (GtkWidget *widget)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
2004-02-26 18:58:26 +00:00
|
|
|
|
GtkWidget *old_group_singleton = NULL;
|
2010-09-18 23:55:42 +00:00
|
|
|
|
GtkRadioButton *radio_button = GTK_RADIO_BUTTON (widget);
|
2018-06-18 10:33:37 +00:00
|
|
|
|
GtkRadioButtonPrivate *priv = gtk_radio_button_get_instance_private (radio_button);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
GSList *tmp_list;
|
2004-02-26 18:58:26 +00:00
|
|
|
|
gboolean was_in_group;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2010-07-07 23:04:11 +00:00
|
|
|
|
was_in_group = priv->group && priv->group->next;
|
|
|
|
|
|
|
|
|
|
priv->group = g_slist_remove (priv->group, radio_button);
|
|
|
|
|
if (priv->group && !priv->group->next)
|
|
|
|
|
old_group_singleton = priv->group->data;
|
2004-02-26 18:58:26 +00:00
|
|
|
|
|
2010-07-07 23:04:11 +00:00
|
|
|
|
tmp_list = priv->group;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
|
|
while (tmp_list)
|
|
|
|
|
{
|
2018-06-18 10:33:37 +00:00
|
|
|
|
GtkRadioButton *tmp_button = tmp_list->data;
|
|
|
|
|
GtkRadioButtonPrivate *tmp_priv = gtk_radio_button_get_instance_private (tmp_button);
|
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
|
tmp_list = tmp_list->next;
|
|
|
|
|
|
2018-06-18 10:33:37 +00:00
|
|
|
|
tmp_priv->group = priv->group;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-21 15:23:14 +00:00
|
|
|
|
/* this button is no longer in the group */
|
2010-07-07 23:04:11 +00:00
|
|
|
|
priv->group = NULL;
|
2004-02-26 18:58:26 +00:00
|
|
|
|
|
|
|
|
|
if (old_group_singleton)
|
2018-08-20 14:51:53 +00:00
|
|
|
|
g_signal_emit (old_group_singleton, signals[GROUP_CHANGED], 0);
|
2004-02-26 18:58:26 +00:00
|
|
|
|
if (was_in_group)
|
2018-08-20 14:51:53 +00:00
|
|
|
|
g_signal_emit (radio_button, signals[GROUP_CHANGED], 0);
|
2008-08-07 14:12:32 +00:00
|
|
|
|
|
2010-09-18 23:55:42 +00:00
|
|
|
|
GTK_WIDGET_CLASS (gtk_radio_button_parent_class)->destroy (widget);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-16 21:02:24 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_radio_button_focus (GtkWidget *widget,
|
|
|
|
|
GtkDirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
GtkRadioButton *radio_button = GTK_RADIO_BUTTON (widget);
|
2018-06-18 10:33:37 +00:00
|
|
|
|
GtkRadioButtonPrivate *priv = gtk_radio_button_get_instance_private (radio_button);
|
2001-10-16 21:02:24 +00:00
|
|
|
|
GSList *tmp_slist;
|
2020-04-10 02:38:30 +00:00
|
|
|
|
GtkRadioButton *selected_button = NULL;
|
2002-03-02 21:18:07 +00:00
|
|
|
|
|
|
|
|
|
/* Radio buttons with draw_indicator unset focus "normally", since
|
|
|
|
|
* they look like buttons to the user.
|
|
|
|
|
*/
|
2017-01-27 11:02:47 +00:00
|
|
|
|
if (!gtk_check_button_get_draw_indicator (GTK_CHECK_BUTTON (widget)))
|
2006-05-02 23:56:43 +00:00
|
|
|
|
return GTK_WIDGET_CLASS (gtk_radio_button_parent_class)->focus (widget, direction);
|
2015-03-29 04:24:35 +00:00
|
|
|
|
|
2020-04-10 02:38:30 +00:00
|
|
|
|
/* Find the currently active button in the group */
|
|
|
|
|
tmp_slist = priv->group;
|
|
|
|
|
while (tmp_slist)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tmp_slist->data)) &&
|
|
|
|
|
gtk_widget_get_visible (tmp_slist->data))
|
|
|
|
|
selected_button = tmp_slist->data;
|
|
|
|
|
tmp_slist = tmp_slist->next;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-16 21:02:24 +00:00
|
|
|
|
if (gtk_widget_is_focus (widget))
|
|
|
|
|
{
|
2018-03-17 09:30:10 +00:00
|
|
|
|
GPtrArray *child_array;
|
2001-10-16 21:02:24 +00:00
|
|
|
|
GtkWidget *new_focus = NULL;
|
2015-03-29 04:24:35 +00:00
|
|
|
|
GSList *l;
|
2018-03-17 09:30:10 +00:00
|
|
|
|
guint index;
|
|
|
|
|
gboolean found;
|
|
|
|
|
guint i;
|
2001-10-16 21:02:24 +00:00
|
|
|
|
|
2015-03-29 04:24:35 +00:00
|
|
|
|
if (direction == GTK_DIR_TAB_FORWARD ||
|
|
|
|
|
direction == GTK_DIR_TAB_BACKWARD)
|
|
|
|
|
return FALSE;
|
2001-10-16 21:02:24 +00:00
|
|
|
|
|
2018-03-17 09:30:10 +00:00
|
|
|
|
child_array = g_ptr_array_sized_new (g_slist_length (priv->group));
|
2015-03-29 04:24:35 +00:00
|
|
|
|
for (l = priv->group; l; l = l->next)
|
2018-03-17 09:30:10 +00:00
|
|
|
|
g_ptr_array_add (child_array, l->data);
|
2001-10-16 21:02:24 +00:00
|
|
|
|
|
2018-03-17 09:30:10 +00:00
|
|
|
|
gtk_widget_focus_sort (widget, direction, child_array);
|
|
|
|
|
found = g_ptr_array_find (child_array, widget, &index);
|
2001-10-16 21:02:24 +00:00
|
|
|
|
|
2018-03-17 09:30:10 +00:00
|
|
|
|
if (found)
|
|
|
|
|
{
|
|
|
|
|
/* Start at the *next* widget in the list */
|
|
|
|
|
if (index < child_array->len - 1)
|
|
|
|
|
index ++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Search from the start of the list */
|
|
|
|
|
index = 0;
|
|
|
|
|
}
|
2015-03-29 04:24:35 +00:00
|
|
|
|
|
2018-03-17 09:30:10 +00:00
|
|
|
|
for (i = index; i < child_array->len; i ++)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *child = g_ptr_array_index (child_array, i);
|
2015-03-29 04:24:35 +00:00
|
|
|
|
|
2018-03-17 09:30:10 +00:00
|
|
|
|
if (gtk_widget_get_mapped (child) && gtk_widget_is_sensitive (child))
|
|
|
|
|
{
|
|
|
|
|
new_focus = child;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-29 04:24:35 +00:00
|
|
|
|
|
2001-10-16 21:02:24 +00:00
|
|
|
|
|
|
|
|
|
if (new_focus)
|
2018-03-17 09:30:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_widget_grab_focus (new_focus);
|
2013-06-26 19:33:10 +00:00
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (new_focus), TRUE);
|
2020-04-10 02:38:30 +00:00
|
|
|
|
if (selected_button && selected_button != (GtkRadioButton *)new_focus)
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (selected_button), FALSE);
|
2018-03-17 09:30:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_ptr_array_free (child_array, TRUE);
|
2001-10-16 21:02:24 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (selected_button && selected_button != radio_button)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_radio_button_clicked (GtkButton *button)
|
|
|
|
|
{
|
2010-07-07 23:04:11 +00:00
|
|
|
|
GtkRadioButton *radio_button = GTK_RADIO_BUTTON (button);
|
2018-06-18 10:33:37 +00:00
|
|
|
|
GtkRadioButtonPrivate *priv = gtk_radio_button_get_instance_private (radio_button);
|
2010-07-07 23:04:11 +00:00
|
|
|
|
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
GtkToggleButton *tmp_button;
|
|
|
|
|
GSList *tmp_list;
|
|
|
|
|
|
2002-10-13 23:56:31 +00:00
|
|
|
|
g_object_ref (GTK_WIDGET (button));
|
1999-01-22 08:12:00 +00:00
|
|
|
|
|
2010-10-19 02:16:17 +00:00
|
|
|
|
if (gtk_toggle_button_get_active (toggle_button))
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
|
|
|
|
tmp_button = NULL;
|
2010-07-07 23:04:11 +00:00
|
|
|
|
tmp_list = priv->group;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
|
|
while (tmp_list)
|
|
|
|
|
{
|
|
|
|
|
tmp_button = tmp_list->data;
|
|
|
|
|
tmp_list = tmp_list->next;
|
|
|
|
|
|
2010-10-19 02:16:17 +00:00
|
|
|
|
if (tmp_button != toggle_button &&
|
|
|
|
|
gtk_toggle_button_get_active (tmp_button))
|
1997-11-24 22:37:52 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
tmp_button = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 02:34:30 +00:00
|
|
|
|
if (tmp_button)
|
2019-10-26 05:00:24 +00:00
|
|
|
|
gtk_toggle_button_set_active (toggle_button,
|
|
|
|
|
!gtk_toggle_button_get_active (toggle_button));
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-26 05:00:24 +00:00
|
|
|
|
gtk_toggle_button_set_active (toggle_button,
|
|
|
|
|
!gtk_toggle_button_get_active (toggle_button));
|
2010-07-07 23:04:11 +00:00
|
|
|
|
|
|
|
|
|
tmp_list = priv->group;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
while (tmp_list)
|
|
|
|
|
{
|
|
|
|
|
tmp_button = tmp_list->data;
|
|
|
|
|
tmp_list = tmp_list->next;
|
|
|
|
|
|
2010-10-19 02:16:17 +00:00
|
|
|
|
if (gtk_toggle_button_get_active (tmp_button) && (tmp_button != toggle_button))
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
2019-05-18 18:15:54 +00:00
|
|
|
|
g_signal_emit_by_name (tmp_button, "clicked");
|
1997-11-24 22:37:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (button));
|
1999-01-22 08:12:00 +00:00
|
|
|
|
|
2002-10-13 23:56:31 +00:00
|
|
|
|
g_object_unref (button);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|