You can usually retrieve the label of a specific
GtkMenuItem with:
if (GTK_BIN (menu_item)->child)
{
GtkWidget *child = GTK_BIN (menu_item)->child;
/* do stuff with child */
if (GTK_IS_LABEL (child))
{
gchar *text;
gtk_label_get (GTK_LABEL (child), &text);
g_print ("menu item text: %s\n", text);
}
} |
To get the active menu item from a GtkOptionMenu you can
do:
if (GTK_OPTION_MENU (option_menu)->menu_item)
{
GtkWidget *menu_item = GTK_OPTION_MENU (option_menu)->menu_item;
} |
But, there's a catch. For this specific case, you can
not get the label widget from
menu_item with the above code, because the
option menu reparents the menu_item's child temporarily to
display the currently active contents. So to retrive the child
of the currently active menu_item of an option menu, you'll
have to do:
if (GTK_BIN (option_menu)->child)
{
GtkWidget *child = GTK_BIN (option_menu)->child;
/* do stuff with child */
} |