develooper Front page | perl.wxperl.users | Postings from May 2010

Re: wxEventObject of EVT_MENU?

Thread Previous | Thread Next
From:
Mark Dootson
Date:
May 17, 2010 00:02
Subject:
Re: wxEventObject of EVT_MENU?
Message ID:
4BF0E9AE.8060706@znix.com
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















Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About