[gtk+/radio-group: 2/9] Convert GtkRadioButton and GtkRadioToolButton to use GtkRadioGroup



commit ac63f89763fe9072ea0ed7dbc71424cd7ed70dc4
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Nov 1 21:45:37 2010 +0100

    Convert GtkRadioButton and GtkRadioToolButton to use GtkRadioGroup
    
    This changes the API by changing the GSList group in the constructors
    and the _set_group/_get_group calls to a GtkRadioGroup.

 demos/gtk-demo/toolpalette.c         |    4 +-
 examples/radiobuttons/radiobuttons.c |    6 +-
 gtk/gtkmountoperation.c              |    5 +-
 gtk/gtkpagesetupunixdialog.c         |    2 +-
 gtk/gtkprinteroptionwidget.c         |    6 +-
 gtk/gtkradiobutton.c                 |  231 ++++++++++++++--------------------
 gtk/gtkradiobutton.h                 |   32 +++---
 gtk/gtkradiotoolbutton.c             |   28 ++--
 gtk/gtkradiotoolbutton.h             |   19 ++--
 modules/other/gail/gailradiobutton.c |   20 ++-
 modules/other/gail/gailradiobutton.h |    3 +-
 tests/testtoolbar.c                  |   11 +-
 12 files changed, 169 insertions(+), 198 deletions(-)
---
diff --git a/demos/gtk-demo/toolpalette.c b/demos/gtk-demo/toolpalette.c
index 2431d6a..8f19460 100644
--- a/demos/gtk-demo/toolpalette.c
+++ b/demos/gtk-demo/toolpalette.c
@@ -690,7 +690,7 @@ load_stock_items (GtkToolPalette *palette)
 static void
 load_toggle_items (GtkToolPalette *palette)
 {
-  GSList *toggle_group = NULL;
+  GtkRadioGroup *toggle_group;
   GtkToolItem *item;
   GtkWidget *group;
   char *label;
@@ -699,6 +699,7 @@ load_toggle_items (GtkToolPalette *palette)
   group = gtk_tool_item_group_new ("Radio Item");
   gtk_container_add (GTK_CONTAINER (palette), group);
 
+  toggle_group = gtk_radio_group_new ();
   for (i = 1; i <= 10; ++i)
     {
       label = g_strdup_printf ("#%d", i);
@@ -707,7 +708,6 @@ load_toggle_items (GtkToolPalette *palette)
       g_free (label);
 
       gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
-      toggle_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
     }
 }
 
diff --git a/examples/radiobuttons/radiobuttons.c b/examples/radiobuttons/radiobuttons.c
index 2869df9..aaf50b0 100644
--- a/examples/radiobuttons/radiobuttons.c
+++ b/examples/radiobuttons/radiobuttons.c
@@ -18,7 +18,7 @@ int main( int   argc,
     GtkWidget *box2;
     GtkWidget *button;
     GtkWidget *separator;
-    GSList *group;
+    GtkRadioGroup *group;
 
     gtk_init (&argc, &argv);
 
@@ -40,11 +40,11 @@ int main( int   argc,
     gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
     gtk_widget_show (box2);
 
-    button = gtk_radio_button_new_with_label (NULL, "button1");
+    group = gtk_radio_group_new ();
+    button = gtk_radio_button_new_with_label (group, "button1");
     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
     gtk_widget_show (button);
 
-    group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
     button = gtk_radio_button_new_with_label (group, "button2");
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c
index 2cdd1d5..e9b9329 100644
--- a/gtk/gtkmountoperation.c
+++ b/gtk/gtkmountoperation.c
@@ -549,7 +549,7 @@ gtk_mount_operation_ask_password (GMountOperation   *mount_op,
     {
       GtkWidget *anon_box;
       GtkWidget *choice;
-      GSList    *group;
+      GtkRadioGroup *group;
 
       anon_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
       gtk_box_pack_start (GTK_BOX (vbox), anon_box,
@@ -622,7 +622,7 @@ gtk_mount_operation_ask_password (GMountOperation   *mount_op,
     {
       GtkWidget    *choice;
       GtkWidget    *remember_box;
-      GSList       *group;
+      GtkRadioGroup *group;
       GPasswordSave password_save;
 
       remember_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
@@ -650,7 +650,6 @@ gtk_mount_operation_ask_password (GMountOperation   *mount_op,
                         G_CALLBACK (remember_button_toggled), operation);
       gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
 
-      group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
       choice = gtk_radio_button_new_with_mnemonic (group, _("Remember _forever"));
       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
                                     password_save == G_PASSWORD_SAVE_PERMANENTLY);
diff --git a/gtk/gtkpagesetupunixdialog.c b/gtk/gtkpagesetupunixdialog.c
index ed1190d..a2236c4 100644
--- a/gtk/gtkpagesetupunixdialog.c
+++ b/gtk/gtkpagesetupunixdialog.c
@@ -860,7 +860,7 @@ page_name_func (GtkCellLayout   *cell_layout,
 }
 
 static GtkWidget *
-create_radio_button (GSList      *group,
+create_radio_button (GtkRadioGroup *group,
 		     const gchar *stock_id)
 {
   GtkWidget *radio_button, *image, *label, *hbox;
diff --git a/gtk/gtkprinteroptionwidget.c b/gtk/gtkprinteroptionwidget.c
index 89891a4..76e46a6 100644
--- a/gtk/gtkprinteroptionwidget.c
+++ b/gtk/gtkprinteroptionwidget.c
@@ -645,12 +645,12 @@ alternative_set (GtkWidget   *box,
 			 (gpointer) value);
 }
 
-static GSList *
+static GtkRadioGroup *
 alternative_append (GtkWidget              *box,
 		    const gchar            *label,
                     const gchar            *value,
 		    GtkPrinterOptionWidget *widget,
-		    GSList                 *group)
+		    GtkRadioGroup          *group)
 {
   GtkWidget *button;
 
@@ -672,7 +672,7 @@ construct_widgets (GtkPrinterOptionWidget *widget)
   GtkPrinterOption *source;
   char *text;
   int i;
-  GSList *group;
+  GtkRadioGroup *group;
 
   source = priv->source;
   
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index b412044..99fbf41 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -28,6 +28,7 @@
 #include "gtklabel.h"
 #include "gtkmarshalers.h"
 #include "gtkradiobutton.h"
+#include "gtkradiogroupprivate.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 
@@ -105,7 +106,7 @@
 
 struct _GtkRadioButtonPrivate
 {
-  GSList *group;
+  GtkRadioGroup *group;
 };
 
 enum {
@@ -211,7 +212,7 @@ gtk_radio_button_init (GtkRadioButton *radio_button)
 
   GTK_BUTTON (radio_button)->depress_on_activate = FALSE;
 
-  priv->group = g_slist_prepend (NULL, radio_button);
+  priv->group = NULL;
 
   _gtk_button_set_depressed (GTK_BUTTON (radio_button), TRUE);
   gtk_widget_set_state (GTK_WIDGET (radio_button), GTK_STATE_ACTIVE);
@@ -229,17 +230,17 @@ gtk_radio_button_set_property (GObject      *object,
 
   switch (prop_id)
     {
-      GSList *slist;
+      GtkRadioGroup *group;
       GtkRadioButton *button;
 
     case PROP_GROUP:
         button = g_value_get_object (value);
 
       if (button)
-	slist = gtk_radio_button_get_group (button);
+	group = gtk_radio_button_get_group (button);
       else
-	slist = NULL;
-      gtk_radio_button_set_group (radio_button, slist);
+	group = NULL;
+      gtk_radio_button_set_group (radio_button, group);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -261,11 +262,23 @@ gtk_radio_button_get_property (GObject    *object,
     }
 }
 
+static void
+gtk_radio_button_ensure_group (GtkRadioButton *radio_button)
+{
+  GtkRadioButtonPrivate *priv = radio_button->priv;
+
+  if (priv->group == NULL)
+    {
+      priv->group = g_object_ref_sink (gtk_radio_group_new ());
+      _gtk_radio_group_add_item (priv->group, G_OBJECT (radio_button));
+    }
+}
+
 /**
  * gtk_radio_button_set_group:
  * @radio_button: a #GtkRadioButton.
- * @group: (transfer none) (element-type GtkRadioButton): an existing radio
- *     button group, such as one returned from gtk_radio_button_get_group().
+ * @group: (allow-none): an existing #GtkRadioGroup or %NULL
+ *     to remove the radio button from its current group
  *
  * Sets a #GtkRadioButton's group. It should be noted that this does not change
  * the layout of your interface in any way, so if you are changing the group,
@@ -274,57 +287,44 @@ gtk_radio_button_get_property (GObject    *object,
  */
 void
 gtk_radio_button_set_group (GtkRadioButton *radio_button,
-			    GSList         *group)
+			    GtkRadioGroup *group)
 {
   GtkRadioButtonPrivate *priv;
-  GtkWidget *old_group_singleton = NULL;
-  GtkWidget *new_group_singleton = NULL;
+  GObject *old_group_singleton = NULL;
+  GObject *new_group_singleton;
+  GObject *old_group_active;
+  gboolean is_active;
 
   g_return_if_fail (GTK_IS_RADIO_BUTTON (radio_button));
-  g_return_if_fail (!g_slist_find (group, radio_button));
 
   priv = radio_button->priv;
 
-  if (priv->group)
-    {
-      GSList *slist;
+  if (priv->group == group)
+    return;
 
-      priv->group = g_slist_remove (priv->group, radio_button);
+  if (group == NULL)
+    group = gtk_radio_group_new ();
 
-      if (priv->group && !priv->group->next)
-	old_group_singleton = g_object_ref (priv->group->data);
+  if (priv->group)
+    {
+      _gtk_radio_group_remove_item (priv->group, G_OBJECT (radio_button));
+      old_group_singleton = _gtk_radio_group_get_singleton (priv->group);
 
-      for (slist = priv->group; slist; slist = slist->next)
-	{
-	  GtkRadioButton *tmp_button;
-	  
-	  tmp_button = slist->data;
+      /* Ensure some widget is active in the old group */
+      old_group_active = gtk_radio_group_get_active_item (priv->group);
+      if (old_group_active)
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (old_group_active), TRUE);
 
-	  tmp_button->priv->group = priv->group;
-	}
+      g_object_unref (priv->group);
     }
-  
-  if (group && !group->next)
-    new_group_singleton = g_object_ref (group->data);
 
-  priv->group = g_slist_prepend (group, radio_button);
+  priv->group = g_object_ref_sink (group);
+  new_group_singleton = _gtk_radio_group_get_singleton (group);
 
-  if (group)
-    {
-      GSList *slist;
-      
-      for (slist = group; slist; slist = slist->next)
-	{
-	  GtkRadioButton *tmp_button;
-	  
-	  tmp_button = slist->data;
-
-	  tmp_button->priv->group = priv->group;
-	}
-    }
+  _gtk_radio_group_add_item (group, G_OBJECT (radio_button));
 
   g_object_ref (radio_button);
-  
+
   g_object_notify (G_OBJECT (radio_button), "group");
   g_signal_emit (radio_button, group_changed_signal, 0);
   if (old_group_singleton)
@@ -338,7 +338,11 @@ gtk_radio_button_set_group (GtkRadioButton *radio_button,
       g_object_unref (new_group_singleton);
     }
 
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), group == NULL);
+  is_active = gtk_radio_group_get_active_item (group) == G_OBJECT (radio_button);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button),
+				is_active);
+  if (is_active)
+    _gtk_radio_group_emit_active_changed (group);
 
   g_object_unref (radio_button);
 }
@@ -379,17 +383,8 @@ gtk_radio_button_join_group (GtkRadioButton *radio_button,
 
   if (group_source)
     {
-      GSList *group;
+      GtkRadioGroup *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
@@ -408,7 +403,7 @@ gtk_radio_button_join_group (GtkRadioButton *radio_button,
  * Returns: a new radio button
  */
 GtkWidget*
-gtk_radio_button_new (GSList *group)
+gtk_radio_button_new (GtkRadioGroup *group)
 {
   GtkRadioButton *radio_button;
 
@@ -431,7 +426,7 @@ gtk_radio_button_new (GSList *group)
  * Returns: (transfer full): a new radio button.
  */
 GtkWidget*
-gtk_radio_button_new_with_label (GSList      *group,
+gtk_radio_button_new_with_label (GtkRadioGroup *group,
 				 const gchar *label)
 {
   GtkWidget *radio_button;
@@ -459,7 +454,7 @@ gtk_radio_button_new_with_label (GSList      *group,
  * Returns: (transfer full): a new #GtkRadioButton
  */
 GtkWidget*
-gtk_radio_button_new_with_mnemonic (GSList      *group,
+gtk_radio_button_new_with_mnemonic (GtkRadioGroup *group,
 				    const gchar *label)
 {
   GtkWidget *radio_button;
@@ -488,10 +483,10 @@ gtk_radio_button_new_with_mnemonic (GSList      *group,
 GtkWidget*
 gtk_radio_button_new_from_widget (GtkRadioButton *radio_group_member)
 {
-  GSList *l = NULL;
+  GtkRadioGroup *group = NULL;
   if (radio_group_member)
-    l = gtk_radio_button_get_group (radio_group_member);
-  return gtk_radio_button_new (l);
+    group = gtk_radio_button_get_group (radio_group_member);
+  return gtk_radio_button_new (group);
 }
 
 /**
@@ -508,10 +503,10 @@ GtkWidget*
 gtk_radio_button_new_with_label_from_widget (GtkRadioButton *radio_group_member,
 					     const gchar    *label)
 {
-  GSList *l = NULL;
+  GtkRadioGroup *group = NULL;
   if (radio_group_member)
-    l = gtk_radio_button_get_group (radio_group_member);
-  return gtk_radio_button_new_with_label (l, label);
+    group = gtk_radio_button_get_group (radio_group_member);
+  return gtk_radio_button_new_with_label (group, label);
 }
 
 /**
@@ -530,10 +525,10 @@ GtkWidget*
 gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *radio_group_member,
 					        const gchar    *label)
 {
-  GSList *l = NULL;
+  GtkRadioGroup *group = NULL;
   if (radio_group_member)
-    l = gtk_radio_button_get_group (radio_group_member);
-  return gtk_radio_button_new_with_mnemonic (l, label);
+    group = gtk_radio_button_get_group (radio_group_member);
+  return gtk_radio_button_new_with_mnemonic (group, label);
 }
 
 
@@ -543,16 +538,17 @@ gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *radio_group_memb
  *
  * Retrieves the group assigned to a radio button.
  *
- * Return value: (element-type GtkRadioButton) (transfer none): a linked list
+ * Return value: (transfer none): a #GtkRadioGroup
  * 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.
+ * as @radio_button.
  */
-GSList*
+GtkRadioGroup *
 gtk_radio_button_get_group (GtkRadioButton *radio_button)
 {
   g_return_val_if_fail (GTK_IS_RADIO_BUTTON (radio_button), NULL);
 
+  gtk_radio_button_ensure_group (radio_button);
+
   return radio_button->priv->group;
 }
 
@@ -560,32 +556,22 @@ gtk_radio_button_get_group (GtkRadioButton *radio_button)
 static void
 gtk_radio_button_destroy (GtkWidget *widget)
 {
-  GtkWidget *old_group_singleton = NULL;
+  GObject *old_group_singleton = NULL;
   GtkRadioButton *radio_button = GTK_RADIO_BUTTON (widget);
   GtkRadioButtonPrivate *priv = radio_button->priv;
-  GtkRadioButton *tmp_button;
-  GSList *tmp_list;
-  gboolean was_in_group;
+  gboolean was_in_group = FALSE;
 
-  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;
-
-  tmp_list = priv->group;
-
-  while (tmp_list)
+  if (priv->group)
     {
-      tmp_button = tmp_list->data;
-      tmp_list = tmp_list->next;
+      _gtk_radio_group_remove_item (priv->group, G_OBJECT (radio_button));
+      was_in_group = !_gtk_radio_group_is_empty (priv->group);
+      old_group_singleton = _gtk_radio_group_get_singleton (priv->group);
 
-      tmp_button->priv->group = priv->group;
+      /* this button is no longer in the group */
+      g_object_unref (priv->group);
+      priv->group = NULL;
     }
 
-  /* this button is no longer in the group */
-  priv->group = NULL;
-
   if (old_group_singleton)
     g_signal_emit (old_group_singleton, group_changed_signal, 0);
   if (was_in_group)
@@ -647,14 +633,15 @@ gtk_radio_button_focus (GtkWidget         *widget,
 {
   GtkRadioButton *radio_button = GTK_RADIO_BUTTON (widget);
   GtkRadioButtonPrivate *priv = radio_button->priv;
-  GSList *tmp_slist;
 
   /* Radio buttons with draw_indicator unset focus "normally", since
    * they look like buttons to the user.
    */
   if (!gtk_toggle_button_get_mode (GTK_TOGGLE_BUTTON (widget)))
     return GTK_WIDGET_CLASS (gtk_radio_button_parent_class)->focus (widget, direction);
-  
+
+  gtk_radio_button_ensure_group (radio_button);
+
   if (gtk_widget_is_focus (widget))
     {
       GtkSettings *settings = gtk_widget_get_settings (widget);
@@ -668,12 +655,12 @@ gtk_radio_button_focus (GtkWidget         *widget,
 	{
 	case GTK_DIR_LEFT:
 	case GTK_DIR_RIGHT:
-	  focus_list = g_slist_copy (priv->group);
+	  focus_list = gtk_radio_group_get_items (priv->group);
 	  focus_list = g_slist_sort_with_data (focus_list, left_right_compare, toplevel);
 	  break;
 	case GTK_DIR_UP:
 	case GTK_DIR_DOWN:
-	  focus_list = g_slist_copy (priv->group);
+	  focus_list = gtk_radio_group_get_items (priv->group);
 	  focus_list = g_slist_sort_with_data (focus_list, up_down_compare, toplevel);
 	  break;
 	case GTK_DIR_TAB_FORWARD:
@@ -756,22 +743,15 @@ gtk_radio_button_focus (GtkWidget         *widget,
     }
   else
     {
-      GtkRadioButton *selected_button = NULL;
-      
+      GObject *selected_button;
+
       /* We accept the focus if, we don't have the focus and
        *  - we are the currently active button in the group
        *  - there is no currently active radio button.
        */
-      
-      tmp_slist = priv->group;
-      while (tmp_slist)
-	{
-	  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tmp_slist->data)))
-	    selected_button = tmp_slist->data;
-	  tmp_slist = tmp_slist->next;
-	}
-      
-      if (selected_button && selected_button != radio_button)
+
+      selected_button = gtk_radio_group_get_active_item (priv->group);
+      if (selected_button && selected_button != G_OBJECT (radio_button))
 	return FALSE;
 
       gtk_widget_grab_focus (widget);
@@ -785,34 +765,22 @@ gtk_radio_button_clicked (GtkButton *button)
   GtkRadioButton *radio_button = GTK_RADIO_BUTTON (button);
   GtkRadioButtonPrivate *priv = radio_button->priv;
   GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
-  GtkToggleButton *tmp_button;
+  GObject *active_item;
   GtkStateType new_state;
-  GSList *tmp_list;
   gint toggled;
   gboolean depressed;
 
+  gtk_radio_button_ensure_group (radio_button);
+
   toggled = FALSE;
 
   g_object_ref (GTK_WIDGET (button));
 
   if (gtk_toggle_button_get_active (toggle_button))
     {
-      tmp_button = NULL;
-      tmp_list = priv->group;
-
-      while (tmp_list)
-	{
-	  tmp_button = tmp_list->data;
-	  tmp_list = tmp_list->next;
-
-          if (tmp_button != toggle_button &&
-              gtk_toggle_button_get_active (tmp_button))
-	    break;
-
-	  tmp_button = NULL;
-	}
+      active_item = gtk_radio_group_get_active_item (priv->group);
 
-      if (!tmp_button)
+      if (active_item == NULL || active_item == G_OBJECT (button))
 	{
 	  new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
 	}
@@ -830,18 +798,10 @@ gtk_radio_button_clicked (GtkButton *button)
       _gtk_toggle_button_set_active (toggle_button,
                                      !gtk_toggle_button_get_active (toggle_button));
 
-      tmp_list = priv->group;
-      while (tmp_list)
-	{
-	  tmp_button = tmp_list->data;
-	  tmp_list = tmp_list->next;
-
-	  if (gtk_toggle_button_get_active (tmp_button) && (tmp_button != toggle_button))
-	    {
-	      gtk_button_clicked (GTK_BUTTON (tmp_button));
-	      break;
-	    }
-	}
+      active_item = gtk_radio_group_get_active_item (priv->group);
+      _gtk_radio_group_set_active_item (priv->group, G_OBJECT (toggle_button));
+      if (active_item != G_OBJECT (toggle_button))
+	gtk_button_clicked (GTK_BUTTON (active_item));
 
       new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
     }
@@ -861,6 +821,9 @@ gtk_radio_button_clicked (GtkButton *button)
       gtk_toggle_button_toggled (toggle_button);
 
       g_object_notify (G_OBJECT (toggle_button), "active");
+
+      if (gtk_toggle_button_get_active (toggle_button))
+	_gtk_radio_group_emit_active_changed (priv->group);
     }
 
   _gtk_button_set_depressed (button, depressed);
diff --git a/gtk/gtkradiobutton.h b/gtk/gtkradiobutton.h
index 2fe40c6..1ee2454 100644
--- a/gtk/gtkradiobutton.h
+++ b/gtk/gtkradiobutton.h
@@ -33,6 +33,7 @@
 
 
 #include <gtk/gtkcheckbutton.h>
+#include <gtk/gtkradiogroup.h>
 
 
 G_BEGIN_DECLS
@@ -74,21 +75,22 @@ struct _GtkRadioButtonClass
 
 GType	   gtk_radio_button_get_type	     (void) G_GNUC_CONST;
 
-GtkWidget* gtk_radio_button_new                           (GSList         *group);
-GtkWidget* gtk_radio_button_new_from_widget               (GtkRadioButton *radio_group_member);
-GtkWidget* gtk_radio_button_new_with_label                (GSList         *group,
-                                                           const gchar    *label);
-GtkWidget* gtk_radio_button_new_with_label_from_widget    (GtkRadioButton *radio_group_member,
-                                                           const gchar    *label);
-GtkWidget* gtk_radio_button_new_with_mnemonic             (GSList         *group,
-                                                           const gchar    *label);
-GtkWidget* gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *radio_group_member,
-                                                           const gchar    *label);
-GSList*    gtk_radio_button_get_group                     (GtkRadioButton *radio_button);
-void       gtk_radio_button_set_group                     (GtkRadioButton *radio_button,
-                                                           GSList         *group);
-void            gtk_radio_button_join_group        (GtkRadioButton        *radio_button,
-                                                    GtkRadioButton        *group_source);
+GtkWidget*     gtk_radio_button_new                           (GtkRadioGroup  *group);
+GtkWidget*     gtk_radio_button_new_from_widget               (GtkRadioButton *radio_group_member);
+GtkWidget*     gtk_radio_button_new_with_label                (GtkRadioGroup  *group,
+							       const gchar    *label);
+GtkWidget*     gtk_radio_button_new_with_label_from_widget    (GtkRadioButton *radio_group_member,
+							       const gchar    *label);
+GtkWidget*     gtk_radio_button_new_with_mnemonic             (GtkRadioGroup  *group,
+							       const gchar    *label);
+GtkWidget*     gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *radio_group_member,
+							       const gchar    *label);
+GtkRadioGroup *gtk_radio_button_get_group                     (GtkRadioButton *radio_button);
+void           gtk_radio_button_set_group                     (GtkRadioButton *radio_button,
+							       GtkRadioGroup  *group);
+void           gtk_radio_button_join_group                    (GtkRadioButton *radio_button,
+							       GtkRadioButton *group_source);
+
 G_END_DECLS
 
 #endif /* __GTK_RADIO_BUTTON_H__ */
diff --git a/gtk/gtkradiotoolbutton.c b/gtk/gtkradiotoolbutton.c
index 9a37c18..fdd5863 100644
--- a/gtk/gtkradiotoolbutton.c
+++ b/gtk/gtkradiotoolbutton.c
@@ -91,13 +91,13 @@ gtk_radio_tool_button_set_property (GObject         *object,
     case PROP_GROUP:
       {
 	GtkRadioToolButton *arg;
-	GSList *slist = NULL;
-	if (G_VALUE_HOLDS_OBJECT (value)) 
+	GtkRadioGroup *group = NULL;
+	if (G_VALUE_HOLDS_OBJECT (value))
 	  {
 	    arg = GTK_RADIO_TOOL_BUTTON (g_value_get_object (value));
 	    if (arg)
-	      slist = gtk_radio_tool_button_get_group (arg);
-	    gtk_radio_tool_button_set_group (button, slist);
+	      group = gtk_radio_tool_button_get_group (arg);
+	    gtk_radio_tool_button_set_group (button, group);
 	  }
       }
       break;
@@ -118,7 +118,7 @@ gtk_radio_tool_button_set_property (GObject         *object,
  * Since: 2.4
  **/
 GtkToolItem *
-gtk_radio_tool_button_new (GSList *group)
+gtk_radio_tool_button_new (GtkRadioGroup *group)
 {
   GtkRadioToolButton *button;
   
@@ -144,7 +144,7 @@ gtk_radio_tool_button_new (GSList *group)
  * Since: 2.4
  **/
 GtkToolItem *
-gtk_radio_tool_button_new_from_stock (GSList      *group,
+gtk_radio_tool_button_new_from_stock (GtkRadioGroup *group,
 				      const gchar *stock_id)
 {
   GtkRadioToolButton *button;
@@ -174,14 +174,14 @@ gtk_radio_tool_button_new_from_stock (GSList      *group,
 GtkToolItem *
 gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
 {
-  GSList *list = NULL;
+  GtkRadioGroup *radio_group = NULL;
   
   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
 
   if (group)
-    list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
+    radio_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
   
-  return gtk_radio_tool_button_new (list);
+  return gtk_radio_tool_button_new (radio_group);
 }
 
 /**
@@ -201,14 +201,14 @@ GtkToolItem *
 gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
 						  const gchar        *stock_id)
 {
-  GSList *list = NULL;
+  GtkRadioGroup *radio_group = NULL;
   
   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
 
   if (group)
-    list = gtk_radio_tool_button_get_group (group);
+    radio_group = gtk_radio_tool_button_get_group (group);
   
-  return gtk_radio_tool_button_new_from_stock (list, stock_id);
+  return gtk_radio_tool_button_new_from_stock (radio_group, stock_id);
 }
 
 static GtkRadioButton *
@@ -227,7 +227,7 @@ get_radio_button (GtkRadioToolButton *button)
  *
  * Since: 2.4
  */
-GSList *
+GtkRadioGroup *
 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
 {
   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
@@ -246,7 +246,7 @@ gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
  **/
 void
 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
-				 GSList             *group)
+				 GtkRadioGroup      *group)
 {
   g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
 
diff --git a/gtk/gtkradiotoolbutton.h b/gtk/gtkradiotoolbutton.h
index 7f77efd..7f217f5 100644
--- a/gtk/gtkradiotoolbutton.h
+++ b/gtk/gtkradiotoolbutton.h
@@ -28,6 +28,7 @@
 #define __GTK_RADIO_TOOL_BUTTON_H__
 
 #include <gtk/gtktoggletoolbutton.h>
+#include <gtk/gtkradiogroup.h>
 
 G_BEGIN_DECLS
 
@@ -59,15 +60,15 @@ struct _GtkRadioToolButtonClass
 
 GType        gtk_radio_tool_button_get_type       (void) G_GNUC_CONST;
 
-GtkToolItem *gtk_radio_tool_button_new                        (GSList             *group);
-GtkToolItem *gtk_radio_tool_button_new_from_stock             (GSList             *group,
-							       const gchar        *stock_id);
-GtkToolItem *gtk_radio_tool_button_new_from_widget            (GtkRadioToolButton *group);
-GtkToolItem *gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
-							       const gchar        *stock_id);
-GSList *     gtk_radio_tool_button_get_group                  (GtkRadioToolButton *button);
-void         gtk_radio_tool_button_set_group                  (GtkRadioToolButton *button,
-							       GSList             *group);
+GtkToolItem *  gtk_radio_tool_button_new                        (GtkRadioGroup      *group);
+GtkToolItem *  gtk_radio_tool_button_new_from_stock             (GtkRadioGroup      *group,
+								 const gchar        *stock_id);
+GtkToolItem *  gtk_radio_tool_button_new_from_widget            (GtkRadioToolButton *group);
+GtkToolItem *  gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
+								 const gchar        *stock_id);
+GtkRadioGroup *gtk_radio_tool_button_get_group                  (GtkRadioToolButton *button);
+void           gtk_radio_tool_button_set_group                  (GtkRadioToolButton *button,
+								 GtkRadioGroup      *group);
 
 G_END_DECLS
 
diff --git a/modules/other/gail/gailradiobutton.c b/modules/other/gail/gailradiobutton.c
index 46b85a0..0a820b1 100644
--- a/modules/other/gail/gailradiobutton.c
+++ b/modules/other/gail/gailradiobutton.c
@@ -44,6 +44,7 @@ static void
 gail_radio_button_init (GailRadioButton *radio_button)
 {
   radio_button->old_group = NULL;
+  radio_button->old_group_size = 0;
 }
 
 static void
@@ -60,7 +61,9 @@ gail_radio_button_ref_relation_set (AtkObject *obj)
 {
   GtkWidget *widget;
   AtkRelationSet *relation_set;
+  GtkRadioGroup *group;
   GSList *list;
+  guint list_length;
   GailRadioButton *radio_button;
 
   g_return_val_if_fail (GAIL_IS_RADIO_BUTTON (obj), NULL);
@@ -80,9 +83,12 @@ gail_radio_button_ref_relation_set (AtkObject *obj)
   /*
    * If the radio button'group has changed remove the relation
    */
-  list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
-  
-  if (radio_button->old_group != list)
+  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
+  list = gtk_radio_group_get_items (group);
+  list_length = g_slist_length (list);
+
+  if (radio_button->old_group != group ||
+      radio_button->old_group_size != list_length)
     {
       AtkRelation *relation;
 
@@ -96,15 +102,14 @@ gail_radio_button_ref_relation_set (AtkObject *obj)
      * Get the members of the button group
      */
 
-    radio_button->old_group = list;
-    if (list)
+    radio_button->old_group = group;
+    radio_button->old_group_size = list_length;
+    if (group)
     {
       AtkObject **accessible_array;
-      guint list_length;
       AtkRelation* relation;
       gint i = 0;
 
-      list_length = g_slist_length (list);
       accessible_array = (AtkObject**) g_malloc (sizeof (AtkObject *) * 
                           list_length);
       while (list != NULL)
@@ -126,5 +131,6 @@ gail_radio_button_ref_relation_set (AtkObject *obj)
       g_object_unref (relation);
     }
   }
+  g_slist_free (list);
   return relation_set;
 }
diff --git a/modules/other/gail/gailradiobutton.h b/modules/other/gail/gailradiobutton.h
index 0a4fe21..1c6ea98 100644
--- a/modules/other/gail/gailradiobutton.h
+++ b/modules/other/gail/gailradiobutton.h
@@ -38,7 +38,8 @@ struct _GailRadioButton
 {
   GailToggleButton parent;
 
-  GSList *old_group;
+  GtkRadioGroup *old_group;
+  guint old_group_size;
 };
 
 GType gail_radio_button_get_type (void);
diff --git a/tests/testtoolbar.c b/tests/testtoolbar.c
index f45da9c..ecbd639 100644
--- a/tests/testtoolbar.c
+++ b/tests/testtoolbar.c
@@ -515,8 +515,8 @@ main (gint argc, gchar **argv)
   GtkWidget *button;
   GtkWidget *label;
   GIcon *gicon;
-  GSList *group;
-  
+  GtkRadioGroup *group;
+
   gtk_init (&argc, &argv);
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -671,9 +671,9 @@ main (gint argc, gchar **argv)
   gtk_tool_item_set_expand (item, TRUE);
   gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
   g_assert (gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), 0) != 0);
-  
-  item = gtk_radio_tool_button_new_from_stock (NULL, GTK_STOCK_JUSTIFY_LEFT);
-  group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
+
+  group = gtk_radio_group_new ();
+  item = gtk_radio_tool_button_new_from_stock (group, GTK_STOCK_JUSTIFY_LEFT);
   add_item_to_list (store, item, "Left");
   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
   
@@ -681,7 +681,6 @@ main (gint argc, gchar **argv)
   item = gtk_radio_tool_button_new_from_stock (group, GTK_STOCK_JUSTIFY_CENTER);
   make_prop_editor (G_OBJECT (item));
 
-  group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
   add_item_to_list (store, item, "Center");
   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]