[926] in The GTK GIMP ToolKit mailing list archive
[gtk-list] Re: Managing option menus
daemon@ATHENA.MIT.EDU (owt1@cornell.edu)
Tue Sep 9 16:32:08 1997
From: owt1@cornell.edu
Date: Tue, 9 Sep 1997 16:31:47 -0400 (EDT)
To: gtk-list@redhat.com
In-Reply-To: <m2bu23cbxs.fsf@hubert.wuh.wustl.edu>
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com
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)
--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null