Re: [gtk-list] Re: ItemFactory anyone?

> 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         },

P.S.: This example is from my port of xBill under GTK. The prerelease can be found on:

  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.


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