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

Option menu problem



Hi all.

I'm writing a program that uses an option menu with GtkRadioMenuItem
widgets. Normally, the currently selected item shows up on the widget.
However, if an item is selected by the program itself, the widget
doesn't show the change. Am I missing something?

To illustrate the problem I've included a quick test program. It has
an option menu with two options. Options can be activated in the usual
way by clicking on the menu. The "Change" button toggles the active
option. However, when the "Change" button is clicked, the GtkOptionMenu
doesn't show the change. Bringing up the menu by clicking on it shows
that the menu has changed, even though the text on the GtkOptionMenu
doesn't show it. So, any ideas how I get it to change the text when a
different item is activated?

I'm using GTK+ 1.2.3 on Solaris.


Chris.


------
#include <gtk/gtk.h>

GtkWidget *opt_a, *opt_b;

void button_callback(GtkWidget *widget, gpointer data)
{
	if (GTK_CHECK_MENU_ITEM(opt_a)->active)
		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(opt_b), 
TRUE);
	else
		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(opt_a), 
TRUE);
	return;
}

int main(int argc, char **argv)
{
	GtkWidget *window, *hbox, *button, *menu, *optionmenu;
	GSList *group;
	
	gtk_init(&argc, &argv);
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_realize(window);
	
	hbox = gtk_hbox_new(FALSE, 4);
	gtk_container_add(GTK_CONTAINER(window), hbox);
	
	button = gtk_button_new_with_label("Change");
	gtk_signal_connect(GTK_OBJECT(button), "clicked",
			GTK_SIGNAL_FUNC(button_callback), NULL);
	gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
	
	menu = gtk_menu_new();
	opt_a = gtk_radio_menu_item_new_with_label(NULL, "Wibble");
	gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(opt_a), TRUE);
	group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(opt_a));
	gtk_menu_append(GTK_MENU(menu), opt_a);
	opt_b = gtk_radio_menu_item_new_with_label(group, "Blarg");
	gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(opt_b), TRUE);
	gtk_menu_append(GTK_MENU(menu), opt_b);
	optionmenu = gtk_option_menu_new();
	gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu), menu);
	gtk_box_pack_start(GTK_BOX(hbox), optionmenu, TRUE, TRUE, 0);
	gtk_widget_set_usize(optionmenu, 100, -2);	/* Why??! */
	
	gtk_widget_show_all(window);
	gtk_main();
	
	return 0;
}

------




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