1Tk::DoubleClick(3)    User Contributed Perl Documentation   Tk::DoubleClick(3)
2
3
4

NAME

6       Tk::DoubleClick - Correctly handle single-click vs double-click events,
7

VERSION

9       Version 0.04
10

SYNOPSIS

12           use Tk::Doubleclick;
13
14           bind_clicks(
15               $widget,
16               [ \&single_callback, @args ],    # Single callback with args
17               \&double_callback,               # Double callback without args
18               -delay  => 500,
19               -button => 'right',
20           );
21

DESCRIPTION

23       Tk::DoubleClick module correctly handle single-click vs double-click
24       events, calling only the appropriate callback for the given event.
25
26       This module always exports bind_clicks().
27

FUNCTIONS

29   bind_clicks()
30       Required parameters:
31
32       $widget
33            Widget to bind to mousebuttons.  Typically a Tk::Button object,
34            but could actually be almost any widget.
35
36       [ \&single_click_callback, @single_click_args ],
37            The callback subroutine to invoke when the event is a single-
38            click, along with the arguments to pass.  When no arguments are
39            passed, the brackets can be omitted.
40
41       [ \&double_click_callback, @double_click_args ],
42            The callback subroutine to invoke when the event is a double-
43            click, along with the arguments to pass.  When no arguments are
44            passed, the brackets can be omitted.
45
46       Options:
47
48       -delay
49            Maximum delay time detween clicks in milliseconds. Default is 300.
50            If the second click of a two proximate mouse clicks occurs within
51            the given delay time, the event is considered a double-click.  If
52            not, the two clicks are considered two separate (albeit nearly
53            simultaneous) single-clicks.
54
55       -button
56            Mouse button to bind. Options are 1, 2, 3, or the corresponding
57            synonyms 'left', 'middle', or 'right'.  The default is 1 ('left').
58

EXAMPLE

60           # Libraries
61           use strict;
62           use warnings;
63           use Tk;
64           use Tk::DoubleClick;
65
66           # User-defined
67           my $a_colors  = [
68               [ '#8800FF', '#88FF88', '#88FFFF' ],
69               [ '#FF0000', '#FF0088', '#FF00FF' ],
70               [ '#FF8800', '#FF8888', '#FF88FF' ],
71               [ '#FFFF00', '#FFFF88', '#FFFFFF' ],
72           ];
73
74           # Main program
75           my $nsingle = my $ndouble = 0;
76           my $mw      = new MainWindow(-title => "Double-click example");
77           my $f1      = $mw->Frame->pack(-expand => 1, -fill => 'both');
78           my @args    = qw( -width 12 -height 2 -relief groove -borderwidth 4 );
79           my @pack    = qw( -side left -expand 1 -fill both );
80
81           # Display single/double click counts
82           my $lb1 = $f1->Label(-text    => "Single Clicks", @args);
83           my $lb2 = $f1->Label(-textvar => \$nsingle,       @args);
84           my $lb3 = $f1->Label(-text    => "Double Clicks", @args);
85           my $lb4 = $f1->Label(-textvar => \$ndouble,       @args);
86           $lb1->pack($lb2, $lb3, $lb4, @pack);
87
88           # Create button for each color, and bind single/double clicks to it
89           foreach my $a_color (@$a_colors) {
90               my $fr = $mw->Frame->pack(-expand => 1, -fill => 'both');
91               foreach my $bg (@$a_color) {
92                   my $b = $fr->Button(-bg => $bg, -text => $bg, @args);
93                   $b->pack(@pack);
94                   bind_clicks($b, [\&single, $lb2, $bg], [\&double, $lb4, $bg]);
95               }
96           }
97
98           # Make 'Escape' quit the program
99           $mw->bind("<Escape>" => sub { exit });
100
101           MainLoop;
102
103
104           # Callbacks
105           sub single {
106               my ($lbl, $color) = @_;
107               $lbl->configure(-bg => $color);
108               ++$nsingle;
109           }
110
111           sub double {
112               my ($lbl, $color) = @_;
113               $lbl->configure(-bg => $color);
114               ++$ndouble;
115           }
116

ACKNOWLEDGEMENTS

118       Thanks to Mark Freeman for numerous great suggestions and documentation
119       help.
120

AUTHOR

122       John C. Norton, "<jchnorton at verizon.net>"
123

BUGS

125       Please report any bugs or feature requests to "bug-tk-doubleclick at
126       rt.cpan.org", or through the web interface at
127       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tk-DoubleClick>.  I
128       will be notified, and then you'll automatically be notified of progress
129       on your bug as I make changes.
130

SUPPORT

132       You can find documentation for this module with the perldoc command.
133
134           perldoc Tk::DoubleClick
135
136       You can also look for information at:
137
138       •   RT: CPAN's request tracker
139
140           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-DoubleClick>
141
142       •   AnnoCPAN: Annotated CPAN documentation
143
144           <http://annocpan.org/dist/Tk-DoubleClick>
145
146       •   CPAN Ratings
147
148           <http://cpanratings.perl.org/d/Tk-DoubleClick>
149
150       •   Search CPAN
151
152           <http://search.cpan.org/dist/Tk-DoubleClick/>
153

ACKNOWLEDGEMENTS

155       Thanks to Mark Freeman for numerous great suggestions and documentation
156       help.
157
159       Copyright 2009 John C. Norton.
160
161       This program is free software; you can redistribute it and/or modify it
162       under the terms of either: the GNU General Public License as published
163       by the Free Software Foundation; or the Artistic License.
164
165       See http://dev.perl.org/licenses/ for more information.
166
167
168
169perl v5.38.0                      2023-07-21                Tk::DoubleClick(3)
Impressum