Hi Jeff,
On 05/02/2013 10:50, Jeff wrote:
Thanks Mark.
Yes, we are using virtual. Did I mention we get around that by sensing
key EVT_KEY_UP and checking if GetKeyCode is 306. If it is we call our
"item selected" callback.
Interesting.
I found I needed the code below in a virtual list ctrl class to handle
common cases I came across. The control intercepts mouse and keyboard
events and then raises its own event that a parent window can connect to.
#---------------------------------
# Selection Change Event Handling
#---------------------------------
sub _get_selected_key {
my $self = shift;
my $selectedkey = $self->GetSelectedItemCount . 'k' .
$self->GetFirstSelected;
return $selectedkey;
}
sub OnItemSelected {
my($self, $event) = @_;
$event->Skip(1);
if(!$self->HasFlag(wxLC_SINGLE_SEL)) {
my $previousitem = $self->cpmousedownflag;
$self->cpmousedownflag(-1);
return if ($self->GetFirstSelected == $previousitem);
}
my $newevent = CP::Wx::Event::VirtualSelection->new($self->GetId);
$self->AddPendingEvent($newevent);
}
sub OnItemDeselected {
my($self, $event) = @_;
$event->Skip(1);
my $newevent = CP::Wx::Event::VirtualSelection->new($self->GetId);
$self->AddPendingEvent($newevent);
}
sub OnMouseDown {
my($self, $event) = @_;
$event->Skip(1);
$self->cpmousedownflag(-1);
my($item, $flags) = $self->HitTest( $event->GetPosition );
if($item == &Wx::wxNOT_FOUND) {
# make deselection work
if($self->ClearSelections) {
if(!$self->HasFlag(wxLC_SINGLE_SEL)) {
my $newevent = Wx::CommandEvent->new(
cpEVT_ID_VIRTUAL_KEYBOARD, $self->GetId );
$newevent->SetString($self->_get_selected_key);
$self->AddPendingEvent($newevent);
}
}
return;
}
return if $self->HasFlag(wxLC_SINGLE_SEL);
# suppress spurious item selection events on multiple clicks
if( ( $self->GetSelectedItemCount == 1 )
&& ( $self->IsSelected($item) )
) {
$self->cpmousedownflag($item);
} else {
$self->cpmousedownflag(-1);
}
# If Mouse Action may result in a multiple selection,
# we need to raise an event
if($event->ShiftDown && $event->LeftDown ) {
my $newevent = CP::Wx::Event::VirtualSelection->new($self->GetId);
$self->AddPendingEvent($newevent);
}
return;
}
sub OnKeyboardInput {
my($self, $event) = @_;
$event->Skip(1);
return if $self->HasFlag(wxLC_SINGLE_SEL);
given( $event->GetKeyCode ) {
when( [ WXK_LEFT, WXK_RIGHT, WXK_UP, WXK_DOWN, WXK_SCROLL,
WXK_PAGEUP, WXK_PAGEDOWN, WXK_END, WXK_HOME ] ) {
my $modifiers = $event->GetModifiers;
if($modifiers == wxMOD_SHIFT) {
my $newevent = Wx::CommandEvent->new(
cpEVT_ID_VIRTUAL_KEYBOARD, $self->GetId );
$newevent->SetString($self->_get_selected_key);
$self->AddPendingEvent($newevent);
}
}
default {
# do nothing
}
}
}
sub OnVirtualKeyboard {
my($self, $event) = @_;
if($event->GetString ne $self->_get_selected_key) {
my $newevent = CP::Wx::Event::VirtualSelection->new($self->GetId);
$self->AddPendingEvent($newevent);
}
}