develooper Front page | perl.wxperl.users | Postings from February 2013

Re: Getting information from EVT_LIST_ITEM_RIGHT_CLICK

Thread Previous | Thread Next
From:
Mark Dootson
Date:
February 5, 2013 03:01
Subject:
Re: Getting information from EVT_LIST_ITEM_RIGHT_CLICK
Message ID:
511075DD.7040303@znix.com
Hi,

On 31/01/2013 22:41, Dave Hayes wrote:
> Hello. I'm trying to get the text, column, and item index on a right
> click in a Wx::ListCtrl. The item index works perfectly. However, I
> can't seem to get any other information. Here's a very abbreviated idea
> of what I am doing:

I can answer this by pulling a couple of 'rabbits out of a hat' in the 
form of undocumented method calling and some extra code for none wxMSW 
platforms.

The method $event->GetPoint() will return the mouse position.

The method $listctrl->HitTest($point) actually returns three items, the 
third of which is the subitem, or column index.

The method $listctrl->GetItem actually accepts two params, the second 
being the column number (default 0).

So to get the column text that was clicked the following ought to work:

my $point = $event->GetPoint();
my $listctrl = $event->GetEventObject;
my($itemindex, $flags, $subitemindex) = $listctrl->HitTest($point);
my $text = $listctrl->GetItem($itemindex, $subitemindex)->GetText;
print qq(Right clicked text: $text\n);

Alas, the third return item from $listctrl->HitTest is only implemented 
on Windows, so we need a separate method to determine the column clicked 
on wxGTK for example. It is quite simple to implement - an 
implementation is contained in the attached code.

Hope it helps.

Regards

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