blib/lib/ChordPro/Wx/CheckListBox.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 50 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #! perl
2  
3 # CheckListBox that displays tooltips.
4  
5 use v5.26;
6 use Object::Pad;
7 use utf8;
8 use Wx qw[:everything];
9  
10 class ChordPro::Wx::CheckListBox
11 :repr(HASH)
12 :isa(Wx::CheckListBox);
13  
14 # Since macOS does not seem to generate LEAVE_WINDOW (and ENTER_WINDOW)
15 # events, we'll use a timer to clear the tips.
16  
17 use Wx qw[:timer];
18 my $timer;
19  
20 method show_tip( $item ) { # undef means clear
21  
22 # Panel Notebook Main
23 my $main = $self->GetParent->GetParent->GetParent;
24  
25 if ( ( $item // Wx::wxNOT_FOUND ) == Wx::wxNOT_FOUND ) {
26 $main->{l_stylemods_tip}->SetLabel("");
27 return;
28 }
29  
30 my $data = $self->GetClientData($item);
31 my $desc = "";
32 $desc .= ucfirst($data->{src}) . ": " unless $data->{src} eq "std";
33 $desc .= $data->{desc};
34 $main->{l_stylemods_tip}->SetLabel($desc);
35  
36 # Create (once) and start timer.
37 unless ( $timer ) {
38 $timer = Wx::Timer->new($self);
39 Wx::Event::EVT_TIMER( $self, $timer, $self->can("OnTimer") );
40 }
41 $timer->Start( 2000, wxTIMER_ONE_SHOT ); # 2 secs
42 }
43  
44 #### Event Handlers ####
45  
46 method OnTimer( $event ) {
47 $self->show_tip(undef);
48 }
49  
50 # For OnEnter and OnMotion, we show the description of the hovered choice.
51  
52 # method OnEnter( $event ) { # Not generated on macOS?
53 # $self->show_tip( $self->HitTest($event->GetPosition()) );
54 # }
55  
56 method OnMotion( $event ) {
57 $self->show_tip( $self->HitTest($event->GetPosition()) );
58 }
59  
60 # When leaving, clear the tip.
61  
62 # method OnLeave( $event ) { # Not generated on macOS?
63 # $self->show_tip(undef);
64 # }
65  
66  
67 1;