Re: [gtk-list] Re: ItemFactory anyone?
- From: Tim Janik <timj gtk org>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: ItemFactory anyone?
- Date: Thu, 14 Jan 1999 19:23:50 +0100 (CET)
On Thu, 14 Jan 1999, Jan Kratochvil wrote:
> > On Wed, Jan 13, 1999 at 05:04:43PM -0800, Brandon Long wrote:
> >
> > > For instance, what is a callback action? We no longer have a space in
> > > the entry for the callback data..
> >
> > Looking at the header file, it's just an integer that can be used as an
> > index.
> >
> > struct _GtkItemFactoryEntry
> > {
> > gchar *path;
> > gchar *accelerator;
> >
> > GtkItemFactoryCallback callback;
> > guint callback_action;
> > gchar *item_type;
> > };
> >
> > void gtk_item_factory_create_items (GtkItemFactory *ifactory,
> > guint n_entries,
> > GtkItemFactoryEntry *entries,
> > gpointer callback_data);
> >
> >
> > So I suppose if you have some data you want to associate with a menu item
> > you can pass in an array or gslist as the callback_data. Then in your
> > callback function retrieve the data item you want by indexing into the array
> > or gslist using the passed in callback_action integer.
> >
> > If you already know what the menu items are going to be and they won't
> > change at runtime you can just use a case statement in your callback.
>
> Oh my god, why just don't cast the needed pointer (it WILL be probably pointer),
> to "guint"? Like in the following example:
>
> typedef struct {
> ...
> GtkWidget *highscorebox,*highscorelist;
> ...
> } UI;
> UI ui;
>
> static void widgetshowfn (gpointer callback_data,guint callback_action,GtkWidget *widget)
> { gtk_widget_show(GTK_WIDGET(*(GtkWidget **)callback_action)); }
>
> static GtkItemFactoryEntry menu[]=
> {
> ...
> {"/Game/View _high scores","<control>H",(GtkItemFactoryCallback)widgetshowfn ,(guint)&ui.highscorebox,NULL },
> ...
> };
you can't rely on sizeof (guint) to always be >= sizeof (gpointer), e.g. alphas
have sizeof (guint)==4 and sizeof(gpointer)==8, so you'll most probably screw your
pointers on some machines with the above code.
>
> P.S.: This example is from my port of xBill under GTK. The prerelease can be found on:
>
> http://atrey.karlin.mff.cuni.cz/~short/sw/#xbill
>
> Unfortunately I have exams now, I'll be able to finish it (like Gnomization, currently
> done parts should be stable, at least I hope so :-) ) sometimes in march if all wents well.
> If someone can do it instead, I'll be pleased to hear about it.
>
>
>
> Lace
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]