arch/Tk/demos/widtrib/mousegesture.pl untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 61 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # MouseGesture.pm - invoke callbacks via mouse gestures
2 #!perl -w
3  
4 use strict;
5 use Tk;
6 use Tk::MouseGesture;
7 use Tk::NoteBook;
8  
9 my $mw = new MainWindow;
10 $mw->geometry("700x400");
11  
12 my $nb = $mw->NoteBook->pack(qw/-fill both -expand 1/);
13 my $pp = $nb->add("TEST", -label => 'Usage');
14 $pp->Label(-text => <<EOT, -justify => 'left', -font => ['courier', 10])->pack;
15 This page can not be deleted!
16  
17 Mouse Gestures:
18 New Page: Hold down right button, and drag mouse vertically upwards.
19 Kill Page: Hold down right button, and drag mouse vertically downwards.
20 Go Back One Page: Hold down right button, and drag mouse horizontally left.
21 Go Forward One Page: Hold down right button, and drag mouse horizontally right.
22  
23 EOT
24 ;
25  
26 my $cnt = 1;
27  
28 # create gesture to add new page.
29 $mw->MouseGesture('B3-up', -command => sub {
30 $nb->add("C$cnt", -label => "C$cnt");
31 $nb->raise("C$cnt");
32 $cnt++;
33 });
34  
35 $mw->MouseGesture('B3-down', -command => sub {
36 my $page = $nb->raised;
37 return unless $page;
38 return if $page eq 'TEST';
39  
40 $nb->delete($page);
41 });
42  
43 $mw->MouseGesture('B3-left', -command => sub {
44 my $page = $nb->raised;
45 my @all = $nb->pages;
46  
47 my $i = 0;
48 $_ eq $page && last, $i++for @all;
49  
50 return if $i == 0;
51  
52 $nb->raise($all[$i-1]);
53 });
54  
55 $mw->MouseGesture('B3-right', -command => sub {
56 my $page = $nb->raised;
57 my @all = $nb->pages;
58  
59 my $i = 0;
60 $_ eq $page && last, $i++for @all;
61  
62 return if $i == $#all;
63  
64 $nb->raise($all[$i+1]);
65 });
66  
67 MainLoop;
68  
69 __END__