gtkradiomenuitem (set_group)




[This is a bug initially reported by a GtkAda user].

The behavior of gtkradiobutton and gtkradiomenuitem is different with regards
to changing the groups.

The following function is used to create the menu. Admittedly, this is not
straightforward, but is in fact part of a more complicated function that
creates the menu dynamically (if I understood correctly the initial bug
report).


GtkWidget* menu_item;
GSList*    group;
GtkWidget* menu = gtk_menu_new ();

for (i=0; i<3; i++) {
   menu_item = gtk_radio_menu_item_new_with_label (NULL, "item");
   if (i != 0) {
       set_group (menu_item, group);
   }
   group=menu_item->group;

   gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (menu_item), 1);
   gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), i == 1);
   gtk_menu_append (GTK_MENU (menu), menu_item);
}




The first two items will appear selected on the screen, whereas they are in
fact part of the same group.
A simple fix (which is in fact done in gtk_radio_button_set_group) is to
insert the following call just after setting the group:

gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
                                group==NULL);


This apparently is enough to deactivate the other items in the group is
necessary after the second call to set_active at the end of the function.

Emmanuel



   



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