Re: dynamic menus



On Mon, Jul 12, 2004 at 05:46:21PM +0200, Karl H. Beckers wrote:

I wasn't sure this was going to work, but this far it does. Now, if I 
want to programatically
select one of the entries, I don't know which entry has which index. So 
I need to look at
each item, check the label, get the index if the label text matches.

However, I can't find a way to enumerate across all the menuitems.

Or are there better ways to do it?

First, you know the index. The entries are simply
sequentially numbered from 0, so if you constructed them
you also know the index.

Then, there's sometimes the possbility you don't have the
original map from/to indices available any more. You can
obtain the list of items:

    GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(option_menu));
    GList     *list = GTK_MENU_SHELL(menu)->children;

and scan the list. It's usually a better idea to identifiy
the items explicitely with some g_object_set_[q]data(...) at
the time of construction and checking these instead of the
labels.

Yeti


--
Do not use tab characters. Their effect is not predictable.



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