Re: [gtk-list] Re: GtkOptionMenu



Havoc Pennington wrote:
> 
> > How to read the index of the currently selected item?
> 
> I think you can't do that now; you have to connect to "activate" on
> each menu item. This is fixed in GTK 1.4, which has a
> gtk_option_menu_get_history () corresponding to
> gtk_option_menu_set_history (). Unfortunately that doesn't help you
> for the present.

After some tinkering I came up with an ugly, but legal
and working solution.

Hopefully this will help others in the same situation.

Almer. S. Tigelaar.

/**
 * option_menu_index:
 * @optionmenu: a gtkoptionmenu
 * 
 * Tries to find out (in an ugly way) the selected
 * item in @optionmenu
 * 
 * Return value: the selected index
 **/
static int
option_menu_index (GtkOptionMenu *optionmenu)
{
	GtkMenu *menu;
	GtkMenuItem *selected;
	GList *iterator;
	int index = -1;
	int i = 0;

	g_return_val_if_fail (optionmenu != NULL, -1);
	
	menu = (GtkMenu *) gtk_option_menu_get_menu (optionmenu);
	iterator = GTK_MENU_SHELL (menu)->children;
	selected = (GtkMenuItem *) gtk_menu_get_active (menu);
	
	while (iterator) {
		
		if (iterator->data == selected) {
		
			index = i;
			break;
		}
		
		iterator = iterator->next;
		i++;
	}

	return index;
}



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