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)
This commit is contained in:
Owen Taylor 2004-02-26 18:58:26 +00:00 committed by Owen Taylor
parent d2e3514d63
commit 0be6a2bb07
9 changed files with 164 additions and 6 deletions

View File

@ -1,3 +1,10 @@
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)
Thu Feb 26 13:23:47 2004 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkwindow-x11.c (set_text_property): Use the right

View File

@ -1,3 +1,10 @@
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)
Thu Feb 26 13:23:47 2004 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkwindow-x11.c (set_text_property): Use the right

View File

@ -1,3 +1,10 @@
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)
Thu Feb 26 13:23:47 2004 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkwindow-x11.c (set_text_property): Use the right

View File

@ -1,3 +1,10 @@
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)
Thu Feb 26 13:23:47 2004 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkwindow-x11.c (set_text_property): Use the right

View File

@ -1,3 +1,10 @@
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)
Thu Feb 26 13:23:47 2004 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkwindow-x11.c (set_text_property): Use the right

View File

@ -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);

View File

@ -59,8 +59,10 @@ struct _GtkRadioButtonClass
{
GtkCheckButtonClass parent_class;
/* Signals */
void (*group_changed) (void);
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);

View File

@ -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);
}

View File

@ -55,8 +55,10 @@ struct _GtkRadioMenuItemClass
{
GtkCheckMenuItemClass parent_class;
/* Signals */
void (*group_changed) (void);
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);