/usr/share/perl5/Tk/DoubleClick.pm is in libtk-doubleclick-perl 0.04-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | package Tk::DoubleClick;
our $VERSION = '0.04';
use strict;
use warnings;
=head1 NAME
Tk::DoubleClick - Correctly handle single-click vs double-click events,
=head1 VERSION
Version 0.04
=head1 SYNOPSIS
use Tk::Doubleclick;
bind_clicks(
$widget,
[ \&single_callback, @args ], # Single callback with args
\&double_callback, # Double callback without args
-delay => 500,
-button => 'right',
);
=head1 DESCRIPTION
Tk::DoubleClick module correctly handle single-click vs double-click events,
calling only the appropriate callback for the given event.
This module always exports C<bind_clicks()>.
=head1 FUNCTIONS
=head2 bind_clicks()
Required parameters:
=over 5
=item $widget
Widget to bind to mousebuttons. Typically a Tk::Button object, but could
actually be almost any widget.
=item [ \&single_click_callback, @single_click_args ],
The callback subroutine to invoke when the event is a single-click, along
with the arguments to pass. When no arguments are passed, the brackets
can be omitted.
=item [ \&double_click_callback, @double_click_args ],
The callback subroutine to invoke when the event is a double-click, along
with the arguments to pass. When no arguments are passed, the brackets
can be omitted.
=back
Options:
=over 5
=item -delay
Maximum delay time detween clicks in milliseconds. Default is 300.
If the second click of a two proximate mouse clicks occurs within the given
delay time, the event is considered a double-click. If not, the two clicks
are considered two separate (albeit nearly simultaneous) single-clicks.
=item -button
Mouse button to bind. Options are 1, 2, 3, or the corresponding synonyms
'left', 'middle', or 'right'. The default is 1 ('left').
=back
=head1 EXAMPLE
# Libraries
use strict;
use warnings;
use Tk;
use Tk::DoubleClick;
# User-defined
my $a_colors = [
[ '#8800FF', '#88FF88', '#88FFFF' ],
[ '#FF0000', '#FF0088', '#FF00FF' ],
[ '#FF8800', '#FF8888', '#FF88FF' ],
[ '#FFFF00', '#FFFF88', '#FFFFFF' ],
];
# Main program
my $nsingle = my $ndouble = 0;
my $mw = new MainWindow(-title => "Double-click example");
my $f1 = $mw->Frame->pack(-expand => 1, -fill => 'both');
my @args = qw( -width 12 -height 2 -relief groove -borderwidth 4 );
my @pack = qw( -side left -expand 1 -fill both );
# Display single/double click counts
my $lb1 = $f1->Label(-text => "Single Clicks", @args);
my $lb2 = $f1->Label(-textvar => \$nsingle, @args);
my $lb3 = $f1->Label(-text => "Double Clicks", @args);
my $lb4 = $f1->Label(-textvar => \$ndouble, @args);
$lb1->pack($lb2, $lb3, $lb4, @pack);
# Create button for each color, and bind single/double clicks to it
foreach my $a_color (@$a_colors) {
my $fr = $mw->Frame->pack(-expand => 1, -fill => 'both');
foreach my $bg (@$a_color) {
my $b = $fr->Button(-bg => $bg, -text => $bg, @args);
$b->pack(@pack);
bind_clicks($b, [\&single, $lb2, $bg], [\&double, $lb4, $bg]);
}
}
# Make 'Escape' quit the program
$mw->bind("<Escape>" => sub { exit });
MainLoop;
# Callbacks
sub single {
my ($lbl, $color) = @_;
$lbl->configure(-bg => $color);
++$nsingle;
}
sub double {
my ($lbl, $color) = @_;
$lbl->configure(-bg => $color);
++$ndouble;
}
=head1 ACKNOWLEDGEMENTS
Thanks to Mark Freeman for numerous great suggestions and documentation help.
=head1 AUTHOR
John C. Norton, C<< <jchnorton at verizon.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-tk-doubleclick at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tk-DoubleClick>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Tk::DoubleClick
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-DoubleClick>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Tk-DoubleClick>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Tk-DoubleClick>
=item * Search CPAN
L<http://search.cpan.org/dist/Tk-DoubleClick/>
=back
=head1 ACKNOWLEDGEMENTS
Thanks to Mark Freeman for numerous great suggestions and documentation help.
=head1 COPYRIGHT & LICENSE
Copyright 2009 John C. Norton.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(bind_clicks);
# Track last-clicked mouse number, widget, "after" event id and callback.
my $h_pend = { 'mn' => 0, 'wi' => 0, 'id' => 0, 'cb' => 0 };
sub bind_clicks {
my ($widget, $a_single, $a_double, %args) = @_;
my $delay = delete $args{-delay} || 300;
my $button = delete $args{-button} || 'left';
my $h_button = { left => 1, middle => 2, right => 3 };
my $mousenum = $h_button->{$button} || $button;
($mousenum =~ /^[123]$/) or $mousenum = 1;
my $c_single = $a_single;
if (ref $a_single eq 'ARRAY') {
my $c_cmd = shift @$a_single;
$c_single = sub { $c_cmd->(@$a_single) };
}
my $c_double = $a_double;
if (ref $a_double eq 'ARRAY') {
my $c_cmd = shift @$a_double;
$c_double = sub { $c_cmd->(@$a_double) };
}
my $button_name = "<Button-$mousenum>";
my $c_pending = sub {
my ($mousenum, $widget, $id) = @_;
$h_pend->{'mn'} = $mousenum;
$h_pend->{'wi'} = $widget;
$h_pend->{'id'} = $id;
$h_pend->{'cb'} = $c_single;
};
my $c_cmd = sub {
my $b_sched = 0; # Schedule new single-click?
if (!$h_pend->{'id'}) {
# No click is pending -- schedule a new one
$b_sched = 1;
} else {
# Cancel pending single-click event
$h_pend->{'wi'}->afterCancel($h_pend->{'id'});
$h_pend->{'id'} = 0;
if ($h_pend->{'mn'} == $mousenum and $h_pend->{'wi'} eq $widget) {
# Invoke double-click callback and reset pending event
$c_double->();
$c_pending->(0, 0, 0);
} else {
# Invoke previous single-click, and schedule a new one
$h_pend->{'cb'}->();
$b_sched = 1;
}
}
# Schedule new single-click subroutine when $delay expires
if ($b_sched) {
my $c_after = sub { $c_pending->(0, 0, 0); $c_single->() };
my $id = $widget->after($delay => $c_after);
$c_pending->($mousenum, $widget, $id);
}
};
$widget->bind($button_name => $c_cmd);
}
1;
|