Re: [gtk-list] Managing option menus





On 9 Sep 1997, Alan Shutko wrote:

> I'm trying to use option menus to allow users to set various things,
> which I'd like reflected in a variable, kind of like pulldown menus in
> Netscape choosing parameters.  But I haven't come up with a good way
> for a generic callback to set the variable of my choice to the right
> enumerated value.

Well, it's a bit ugly, but if you have just one integer parameter, then
the best thing to do is to cast the integer to a pointer and pass it
as the user data.

Something like:

gtk_signal_connect (GTK_OBJECT(menu_item), "activate",
                    GTK_SIGNAL_FUNC(set_character_type),
                    (gpointer)((long)FIGHTER));

If I remember correctly, the intermediate cast to long is a good
thing to do for 64-bit architectures.

Then your callback looks like:

void set_character_type (GtkWidget *w, gpointer user_data)
{
   CharacterType type;

   type = (CharacterType)user_data;

...

}

Hope this helps,
                                      Owen

(In more complicated circumstances, you sometimes need to
create a structure that encapsulates the information associated
with the menu choice, and pass a pointer to that to your
callback)



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