]> Pileus Git - ~andy/gtk/commitdiff
add gtk_radio_button_join_group method for bindings
authorJohn (J5) Palmieri <johnp@redhat.com>
Tue, 7 Sep 2010 02:55:03 +0000 (22:55 -0400)
committerJohn (J5) Palmieri <johnp@redhat.com>
Tue, 7 Sep 2010 14:41:40 +0000 (10:41 -0400)
* this mirrors the committed change for gtk_radio_action_join_group in
  commit 85b53969b24d318b219663841e678943516f443a
* Due to object ownership issues it is impossible to correctly use
  get_group/set_group from a GI binding
* join_group is safer because at the binding level it works with individual
  GtkRadioButton objects and not with the list of objects that gets
  modified in the library

https://bugzilla.gnome.org/show_bug.cgi?id=628935

gtk/gtkradiobutton.c
gtk/gtkradiobutton.h

index fc78eadb46308be7db002c7ec375ef039d810f60..6881e105c7114405f4446c3684a1a4d20022599a 100644 (file)
@@ -346,6 +346,61 @@ gtk_radio_button_set_group (GtkRadioButton *radio_button,
   g_object_unref (radio_button);
 }
 
+/**
+ * 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:
+ * |[
+ *   GtkRadioButton *radio_button;
+ *   GtkRadioButton *last_button;
+ *
+ *   while (/&ast; more buttons to add &ast;/)
+ *     {
+ *        radio_button = gtk_radio_button_new (...);
+ *
+ *        gtk_radio_button_join_group (radio_button, last_button);
+ *        last_button = radio_button;
+ *     }
+ * ]|
+ *
+ * Since: 3.0
+ */
+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);
+    }
+}
+
 /**
  * gtk_radio_button_new:
  * @group: an existing radio button group, or %NULL if you are creating a new group.
index 84e704282142a3a8c6e4b45f09a306a1c0c65078..20f91cfcdf05457411412826ee4768f0bbf623b6 100644 (file)
@@ -86,7 +86,8 @@ GtkWidget* gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *radio
 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);
 G_END_DECLS
 
 #endif /* __GTK_RADIO_BUTTON_H__ */