summaryrefslogtreecommitdiff
path: root/gtk/gtkradiobutton.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2004-02-26 18:58:26 +0000
committerOwen Taylor <otaylor@src.gnome.org>2004-02-26 18:58:26 +0000
commit0be6a2bb07401b6b6d064d78d5eeb97eec9dd3ec (patch)
tree5de34749639da63ec14adf4938f0b6901dfdfd20 /gtk/gtkradiobutton.c
parentd2e3514d63bdc2b76bfb78ea0f833c7f4ddf23ea (diff)
downloadgtk+-0be6a2bb07401b6b6d064d78d5eeb97eec9dd3ec.tar.gz
Add a ::group-changed signal emitted when the radio button/menu item is
Wed Feb 25 19:11:31 2004 Owen Taylor <otaylor@redhat.com> * gtk/gtkradiobutton.[ch] gtk/gtkradiomenuitem.[ch]: Add a ::group-changed signal emitted when the radio button/menu item is moved from one group of radio buttons to another. (#79563, based partially on a patch from Padraig O'Briain)
Diffstat (limited to 'gtk/gtkradiobutton.c')
-rw-r--r--gtk/gtkradiobutton.c64
1 files changed, 62 insertions, 2 deletions
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index f850ffaa49..bbb5e6c212 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -25,6 +25,7 @@
*/
#include "gtklabel.h"
+#include "gtkmarshalers.h"
#include "gtkradiobutton.h"
#include "gtkintl.h"
@@ -54,6 +55,7 @@ static void gtk_radio_button_get_property (GObject *object,
static GtkCheckButtonClass *parent_class = NULL;
+static guint group_changed_signal = 0;
GType
gtk_radio_button_get_type (void)
@@ -117,6 +119,27 @@ gtk_radio_button_class_init (GtkRadioButtonClass *class)
button_class->clicked = gtk_radio_button_clicked;
check_button_class->draw_indicator = gtk_radio_button_draw_indicator;
+
+ class->group_changed = NULL;
+
+ /**
+ * GtkStyle::group-changed:
+ * @style: the object which received the signal
+ *
+ * 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
+ * vice-versa, and when a buttton is moved from one group of 2 or
+ * more buttons to a different one, but not when the composition
+ * of the group that a button belongs to changes.
+ */
+ group_changed_signal = g_signal_new ("group-changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GtkRadioButtonClass, group_changed),
+ NULL, NULL,
+ _gtk_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
static void
@@ -184,15 +207,21 @@ void
gtk_radio_button_set_group (GtkRadioButton *radio_button,
GSList *group)
{
+ GtkWidget *old_group_singleton = NULL;
+ GtkWidget *new_group_singleton = NULL;
+
g_return_if_fail (GTK_IS_RADIO_BUTTON (radio_button));
g_return_if_fail (!g_slist_find (group, radio_button));
if (radio_button->group)
{
GSList *slist;
-
+
radio_button->group = g_slist_remove (radio_button->group, radio_button);
+ if (radio_button->group && !radio_button->group->next)
+ old_group_singleton = g_object_ref (radio_button->group->data);
+
for (slist = radio_button->group; slist; slist = slist->next)
{
GtkRadioButton *tmp_button;
@@ -203,6 +232,9 @@ gtk_radio_button_set_group (GtkRadioButton *radio_button,
}
}
+ if (group && !group->next)
+ new_group_singleton = g_object_ref (group->data);
+
radio_button->group = g_slist_prepend (group, radio_button);
if (group)
@@ -219,7 +251,23 @@ gtk_radio_button_set_group (GtkRadioButton *radio_button,
}
}
+ g_object_ref (radio_button);
+
+ g_signal_emit (radio_button, group_changed_signal, 0);
+ if (old_group_singleton)
+ {
+ g_signal_emit (old_group_singleton, group_changed_signal, 0);
+ g_object_unref (old_group_singleton);
+ }
+ if (new_group_singleton)
+ {
+ g_signal_emit (new_group_singleton, group_changed_signal, 0);
+ g_object_unref (new_group_singleton);
+ }
+
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), group == NULL);
+
+ g_object_unref (radio_button);
}
GtkWidget*
@@ -329,13 +377,20 @@ gtk_radio_button_get_group (GtkRadioButton *radio_button)
static void
gtk_radio_button_destroy (GtkObject *object)
{
+ GtkWidget *old_group_singleton = NULL;
GtkRadioButton *radio_button;
GtkRadioButton *tmp_button;
GSList *tmp_list;
-
+ gboolean was_in_group;
+
radio_button = GTK_RADIO_BUTTON (object);
+ was_in_group = radio_button->group && radio_button->group->next;
+
radio_button->group = g_slist_remove (radio_button->group, radio_button);
+ if (radio_button->group && !radio_button->group->next)
+ old_group_singleton = radio_button->group->data;
+
tmp_list = radio_button->group;
while (tmp_list)
@@ -348,6 +403,11 @@ gtk_radio_button_destroy (GtkObject *object)
/* this button is no longer in the group */
radio_button->group = NULL;
+
+ if (old_group_singleton)
+ g_signal_emit (old_group_singleton, group_changed_signal, 0);
+ if (was_in_group)
+ g_signal_emit (radio_button, group_changed_signal, 0);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);