diff options
author | Owen Taylor <otaylor@redhat.com> | 2004-02-26 18:58:26 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2004-02-26 18:58:26 +0000 |
commit | 0be6a2bb07401b6b6d064d78d5eeb97eec9dd3ec (patch) | |
tree | 5de34749639da63ec14adf4938f0b6901dfdfd20 /gtk/gtkradiomenuitem.c | |
parent | d2e3514d63bdc2b76bfb78ea0f833c7f4ddf23ea (diff) | |
download | gtk+-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/gtkradiomenuitem.c')
-rw-r--r-- | gtk/gtkradiomenuitem.c | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/gtk/gtkradiomenuitem.c b/gtk/gtkradiomenuitem.c index b0bcd2d0ed..771f0aca75 100644 --- a/gtk/gtkradiomenuitem.c +++ b/gtk/gtkradiomenuitem.c @@ -25,6 +25,7 @@ */ #include "gtkaccellabel.h" +#include "gtkmarshalers.h" #include "gtkradiomenuitem.h" @@ -35,6 +36,8 @@ static void gtk_radio_menu_item_activate (GtkMenuItem *menu_item static GtkCheckMenuItemClass *parent_class = NULL; +static guint group_changed_signal = 0; + GType gtk_radio_menu_item_get_type (void) { @@ -79,15 +82,21 @@ void gtk_radio_menu_item_set_group (GtkRadioMenuItem *radio_menu_item, GSList *group) { + GtkWidget *old_group_singleton = NULL; + GtkWidget *new_group_singleton = NULL; + g_return_if_fail (GTK_IS_RADIO_MENU_ITEM (radio_menu_item)); g_return_if_fail (!g_slist_find (group, radio_menu_item)); - + if (radio_menu_item->group) { GSList *slist; - + radio_menu_item->group = g_slist_remove (radio_menu_item->group, radio_menu_item); + if (radio_menu_item->group && !radio_menu_item->group->next) + old_group_singleton = g_object_ref (radio_menu_item->group->data); + for (slist = radio_menu_item->group; slist; slist = slist->next) { GtkRadioMenuItem *tmp_item; @@ -98,6 +107,9 @@ gtk_radio_menu_item_set_group (GtkRadioMenuItem *radio_menu_item, } } + if (group && !group->next) + new_group_singleton = g_object_ref (group->data); + radio_menu_item->group = g_slist_prepend (group, radio_menu_item); if (group) @@ -119,6 +131,22 @@ gtk_radio_menu_item_set_group (GtkRadioMenuItem *radio_menu_item, /* gtk_widget_set_state (GTK_WIDGET (radio_menu_item), GTK_STATE_ACTIVE); */ } + + g_object_ref (radio_menu_item); + + g_signal_emit (radio_menu_item, 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); + } + + g_object_unref (radio_menu_item); } GtkWidget* @@ -271,6 +299,25 @@ gtk_radio_menu_item_class_init (GtkRadioMenuItemClass *klass) object_class->destroy = gtk_radio_menu_item_destroy; menu_item_class->activate = gtk_radio_menu_item_activate; + + /** + * GtkStyle::group-changed: + * @style: the object which received the signal + * + * Emitted when the group of radio menu items that a radio menu item belongs + * to changes. This is emitted when a radio menu item switches from + * being alone to being part of a group of 2 or more menu items, or + * vice-versa, and when a buttton is moved from one group of 2 or + * more menu items to a different one, but not when the composition + * of the group that a menu item belongs to changes. + */ + group_changed_signal = g_signal_new ("group-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkRadioMenuItemClass, group_changed), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); } static void @@ -283,16 +330,23 @@ gtk_radio_menu_item_init (GtkRadioMenuItem *radio_menu_item) static void gtk_radio_menu_item_destroy (GtkObject *object) { + GtkWidget *old_group_singleton = NULL; GtkRadioMenuItem *radio_menu_item; GtkRadioMenuItem *tmp_menu_item; GSList *tmp_list; + gboolean was_in_group; g_return_if_fail (GTK_IS_RADIO_MENU_ITEM (object)); radio_menu_item = GTK_RADIO_MENU_ITEM (object); + was_in_group = radio_menu_item->group && radio_menu_item->group->next; + radio_menu_item->group = g_slist_remove (radio_menu_item->group, radio_menu_item); + if (radio_menu_item->group && !radio_menu_item->group->next) + old_group_singleton = radio_menu_item->group->data; + tmp_list = radio_menu_item->group; while (tmp_list) @@ -306,6 +360,11 @@ gtk_radio_menu_item_destroy (GtkObject *object) /* this radio menu item is no longer in the group */ radio_menu_item->group = NULL; + if (old_group_singleton) + g_signal_emit (old_group_singleton, group_changed_signal, 0); + if (was_in_group) + g_signal_emit (radio_menu_item, group_changed_signal, 0); + if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } |