finding parent of options menu item?
- From: mcmahill mtl mit edu
- Cc: gtk-app-devel-list gnome org
- Subject: finding parent of options menu item?
- Date: Thu, 20 Jun 2002 21:20:53 -0400 (EDT)
I'm trying to figure out how to get a pointer to the option menu inside
the callback for a menu. I'm creating an options menu with the following
function. In the callback,
void my_callback(GtkWidget *w, gpointer data)
{
int which;
which = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
}
I get passed a pointer to the `item' from the units_menu_new function
(since thats the widget the callback is attached to). w->parent is then a
pointer to `menu' from the units_menu_new function, but w->parent->parent
doesn't seem to point to opt_menu from units_menu_new but thats the
pointer I want to be able to get.
Any suggestions?
GtkWidget *units_menu_new(const units_data *units,
int initial,
void (*callback)(GtkWidget *, gpointer))
{
GtkWidget *opt_menu;
GtkWidget *menu;
GtkWidget *item;
int i;
opt_menu = gtk_option_menu_new();
menu = gtk_menu_new();
i=0;
while (units[i].name != NULL) {
item = gtk_menu_item_new_with_label(units[i].name);
gtk_signal_connect(GTK_OBJECT(item), "activate",
GTK_SIGNAL_FUNC(callback),
(gpointer) gui);
/* keep track of which entry this is */
gtk_object_set_user_data(GTK_OBJECT(item),GINT_TO_POINTER(i));
gtk_menu_append(GTK_MENU(menu), item);
gtk_widget_show(item);
i++;
}
/* attach our new menu to the options menu */
gtk_option_menu_set_menu(GTK_OPTION_MENU(opt_menu), menu);
/* pick the default (initial) selection */
gtk_option_menu_set_history(GTK_OPTION_MENU(opt_menu), initial);
gtk_widget_show_all(opt_menu);
return opt_menu;
}
thanks for the help
-dan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]