Re: [gtk-list] Re: Getting text of a menu item from a GtkOptionMenu



Havoc Pennington wrote:

> The simplest way, which I often use, is to gtk_object_set_data() some
> unique identifier on each menu item; it might be the data structure in
> your program the option menu is associated with, or an enumeration value
> (use GPOINTER_TO_INT() and GINT_TO_POINTER() to stuff an enum value into
> the gpointer you store with set_data()). Then one normally connects to the
> "activate" signal of each menu item of the option menu, and the callback
> checks the data stored on the menu item to determine which item it is.

Isn't it easier just connecting to the menu's "deactivate" signal
(which is what the option menu does itself), e.g.

  gtk_signal_connect (GTK_OBJECT (GTK_OPTION_MENU (option_menu)->menu),
                      "deactivate", GTK_SIGNAL_FUNC (on_option_selected),
                      NULL);


static void
on_option_selected (GtkMenuShell *menu_shell,
                    gpointer data)
{
  GtkWidget *active_item;
  gint item_index;
  
  active_item = gtk_menu_get_active (GTK_MENU (menu_shell));
  item_index = g_list_index (menu_shell->children, active_item);

  g_print ("In on_option_selected active: %i\n", item_index);
}


Damon



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