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

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



On Fri, 2004-01-30 at 22:37, Don Armstrong wrote:
> I ran into an interesting problem recently with Gtk2::SimpleMenu. For
> some reason, Gtk2::SimpleMenu and Gtk2::ItemFactory::create_items do
> not support per-item callback_data, even though it's supported by the
> Gtk+ API.
> 
> While you can rather easily emulate callback_data using 
> 
> callback => sub {foo(@_,$bar)};
> 
> this seems less than optimal.
> 
> The following diff fixes Gtk2::SimpleMenu and Gtk2.pm to allow using
> callback_data. [I'm not quite sure if I like
> Gtk2::ItemFactory::create_item(s) being in Gtk2, but whatever...]

> ...

> [My appologies for not making the above patch against CVS... for some
> reason SF's CVS repository is down right now.]

the whole create_item scheme has changed to entirely xs code. now so the
patch doesn't really apply. (he he)

there's no member in the ItemFactoryEntry for user data therefore i'm
not sure what your trying to do made/makes sense, so far as keeping with
the c api. the things that were accepted for the entries were the
members of the entry structs. that behavior has been carried over to the
xs implemntation of the same.
http://developer.gnome.org/doc/API/2.0/gtk/GtkItemFactory.html#GtkItemFactoryEntry

if you look at create_item and create_items you get one callback_data
per call to that function:
http://developer.gnome.org/doc/API/2.0/gtk/GtkItemFactory.html#gtk-item-factory-create-item

so if you want callback_data to be unique for each entry you use
create_item multiple times, if you want the data to be shared between
entries you use create_items. that was the behavior implemented before
but with perl var-args we were able to implement both functions with one
function body.

now, you are correct, there isn't a way to give per-entry callback data
to SimpleMenu. together with the above (incorrect) patch would then be
able to do so, but it would of messed up the ItemFactory api so that's
no good.

as it stands SimpleMenu isn't broken b/c it doesn't tell you that you
can have per entry callback data. whether or not you should be able to
is another question. based on the way that create_item was implemented
we could pull an underhand trick to support it, something like:

foreach (@{$self->{entries}})
{
	$self->create_item ($_, $_->[6] || $self->{user_data});
}

to replace:

$self->create_items ($self->{user_data}, @{$self->{entires}});

since create_item explicitly asks for the array indices it wants and
doesn't check that the correct number exists in the array, we could
stick another one on the end without a problem. that's used by the
SimpleMenu layer. it's not perfect, but it will work unless
itemfactory->create_item changes.

what do others think, should this be done? 

-rm






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