Re: callback_data in Gtk2::SimpleMenu [and Gtk2::ItemFactory (well, Gtk2.pm)]



Don Armstrong said:
struct GtkItemFactoryEntry {

  gchar *path;
  gchar *accelerator;

  GtkItemFactoryCallback callback;

....
}

void        gtk_item_factory_create_items   (GtkItemFactory *ifactory,
                                             guint n_entries,
                                             GtkItemFactoryEntry *entries,
                                             gpointer callback_data);

entries :     an array of GtkItemFactoryEntrys whose callback members must by of
type GtkItemFactoryCallback1

As you can see, create_items takes an array of GtkItemFactoryEntrys
whose callback members are GtkItemFactoryCallback1.

GtkItemFactoryCallback1 has it's own callback_data.

void        (*GtkItemFactoryCallback1)      (gpointer callback_data,
                                             guint callback_action,
                                             GtkWidget *widget);

ah, now i see where you're getting hung up. callback is only a pointer to a
place in memory where the function resides. it's not a struct of
GtkItemFactoryCallback1 type. this is a pretty fundamental thing you have to
catch to work with glib/gtk+ in C. if you've not done much C development with
it then it's probably hard to guess just from looking at the doc. in fact the
doc is somewhat misleading until you learn how that stuff works.

in a C app things would look something like (this is just a made up case):

void
callback_func (gpointer callback_data,
               guint callback_action,
               GtkWidget *widget)
{
  /* do something really cool and interesting */
}

and the signal would be connected like:

g_object_signal_connect (item, "activate", &callback_func, callback_data);

callbac_func in thie case is of the GtkItemFactoryCallback1, but what's passed
there is only a pointer to the location in memory where that function is
located.

Now, it's possible that the callback_data to create_items is totally
separate from the callback_data in GtkItemFactoryCallback1. [If so,
someone really needs to clean up the documentation in this area of the
code, because it's not clear at all.]

as above, there's no object/struct etc. GtkItemFactoryCallback1, so there's
nothing in it. it's just a pointer to a function's location in memory and that
function has the call signature of a GtkItemFactoryCallback1.

it isn't the overhead of having the code to do it around, it's using
a hash ref instead of an array, which would both use up more memory
and time (tiny amounts, but still.)

The hashref is created and goes away once it's out of scope and no
longer referenced, so the memory useage and the time involved really
isn't that big of a deal.

as i said, but not reason to change it now.

There are places to make up time and memory useage, but if it causes
the program to get locked into a particular design implementation, you
have to weigh it carefully.

it hasn't. in my original email i showed how what you want could be done
without changing anything other than tacking on an extra array element that's
ignored by itemfactory and used in a special way by simplemenu.

Regardless, as you're the person responsible for maintaining this
slice of code, do it any way that works for you... it's merely a
suggestion comming from someone who has seen the time it takes to keep
a purely array based paramater system in sync with changing function
calls.

in this case the array elements aren't defined by us, they're defined by the
structure itself which can't change in gtk+ b/c of API/ABI compatibility.

-rm



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