Re: GTKRadioButton groups breakage/weirdness



On Sat, 27 Oct 2001, Joel Becker wrote:

> GTKers,
> 	So, the following code does not work:
> 
> GtkWidget *a, *b, *c, *d;
> GSList *group = NULL;
> a = gtk_radio_button_new_with_label(NULL, "a");
> group = gtk_radio_button_group(GTK_RADIO_BUTTON(a));
> b = gtk_radio_button_new_with_label(group, "b");
> c = gtk_radio_button_new_with_label(group, "c");
> d = gtk_radio_button_new_with_label(group, "d");
> 
> 	Because of the gyrations in gtk_radio_button_set_group, these
> buttons end up in different groups.  The following code does work
> though:
> 
> GtkWidget *a, *b, *c, *d;
> GSList *group = NULL;
> a = gtk_radio_button_new_with_label(NULL, "a");
> group = gtk_radio_button_group(GTK_RADIO_BUTTON(a));
> b = gtk_radio_button_new_with_label(group, "b");
> group = gtk_radio_button_group(GTK_RADIO_BUTTON(b));
> c = gtk_radio_button_new_with_label(group, "c");
> group = gtk_radio_button_group(GTK_RADIO_BUTTON(c));
> d = gtk_radio_button_new_with_label(group, "d");
> 
> 	It appears you have to consider your group pointer invalid after
> every addition, because of the way the list is recalculated.  This is
> non-obvious, and I'd consider broken.  However, simply documenting this
> limitation would suffice.  But you have to peruse the source quite
> heavily to see where this happens.

jup, this is actually bad API.
i guess i'd accept a patch that changed radio button groups from GSList
into GList (and walked group->prev in gtk_radio_button_new_with_label), as
1) walking a GList* cast into a GSList* and just accessing ->data will work
   fine
2) users shouldn't ever modify a radio button's group, so walking the nodes
   and accessing ->data are about the only things they could do with it
3) derivation from radio buttons is a pretty rare case scenario and can
   easily be fixed if the GList group change broke anything. a note in
   Changes-2.0.would do.
4) the above "group invalidation" is a bad pitfall, especially for new users

> 
> Joel
> 

---
ciaoTJ




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