Hi,
On 16/05/2010 20:18, Gabor Szabo wrote:
I can add it to the callback as it is closure but shouldn't for example the
GetEventObject method of http://docs.wxwidgets.org/2.8.10/wx_wxevent.html
return the MenuItem ?
Intuitively you might expect so, but GetEventObject returns the
'originating object' so it will be a wxWindow - or at least a
wxEvtHandler. wxMenuItem is a data object produced 'on demand' by
wxMenu methods.
To do what I would guess you want without closures: (code isn't tested
so may have typo's)
For MenuBar based menu
sub evthandler {
my ($handler, $event) = @_;
my $id = $event->GetId;
my $mbar = $event->GetEventObject->GetMenuBar;
my( $item, $menu ) = $mbar->FindItem($id);
my $checktext = $item->GetLabel;
....
....
}
For popup, you do effectively need your popup menu 'enclosed' in scope.
my $popmenu = Wx::Menu->new(...)
...
...
sub evthandler {
my ($handler, $event) = @_;
my $id = $event->GetId;
my( $item, $menu ) = $popmenu->FindItem($id);
my $checktext = $item->GetLabel;
....
....
}
HTH
Mark