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

Re: wxLC_VIRTUAL and EVT_LIST_ITEM_RIGHT_CLICK

Thread Previous
From:
Jeff
Date:
February 5, 2013 11:30
Subject:
Re: wxLC_VIRTUAL and EVT_LIST_ITEM_RIGHT_CLICK
Message ID:
5110ED33.5050706@roqc.no
I should mention that we only wanted one event after user sweeps across 
control using shift key ( ie no event until they are done ).  Depending 
on the app, the call back can be quite complex and time consuming.

On 2/5/2013 6:03 AM, Mark Dootson wrote:
> 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);
>     }
> }
>
> ______________________________________________________________________
> This email has been scanned by the Symantec Email Security.cloud service.
> For more information please visit http://www.symanteccloud.com
> ______________________________________________________________________


Thread Previous


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