| 1 |
# Copyright (c) 1990 The Regents of the University of California. |
| 2 |
# Copyright (c) 1994-1996 Sun Microsystems, Inc. |
| 3 |
# See the file "license.terms" for information on usage and redistribution |
| 4 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 5 |
# |
| 6 |
# |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
Tk::bindtags - Determine which bindings apply to a window, and order of evaluation |
| 11 |
|
| 12 |
=for category Binding Events and Callbacks |
| 13 |
|
| 14 |
=head1 SYNOPSIS |
| 15 |
|
| 16 |
I<$widget>-E<gt>B<bindtags>([I<tagList>]); |
| 17 |
|
| 18 |
I<@tags> = I<$widget>-E<gt>B<bindtags>; |
| 19 |
|
| 20 |
=head1 DESCRIPTION |
| 21 |
|
| 22 |
When a binding is created with the B<bind> command, it is |
| 23 |
associated either with a particular window such as I<$widget>, |
| 24 |
a class name such as B<Tk::Button>, the keyword B<all>, or any |
| 25 |
other string. |
| 26 |
All of these forms are called I<binding tags>. |
| 27 |
Each window has a list of binding tags that determine how |
| 28 |
events are processed for the window. |
| 29 |
When an event occurs in a window, it is applied to each of the |
| 30 |
window's tags in order: for each tag, the most specific binding |
| 31 |
that matches the given tag and event is executed. |
| 32 |
See the L<Tk::bind> documentation for more information on the matching |
| 33 |
process. |
| 34 |
|
| 35 |
By default, each window has four binding tags consisting of the |
| 36 |
the window's class name, name of the window, the name of the window's |
| 37 |
nearest toplevel ancestor, and B<all>, in that order. |
| 38 |
Toplevel windows have only three tags by default, since the toplevel |
| 39 |
name is the same as that of the window. |
| 40 |
|
| 41 |
Note that this order is I<different> from order used by Tcl/Tk. |
| 42 |
Tcl/Tk has the window ahead of the class name in the binding order. |
| 43 |
This is because Tcl is procedural rather than object oriented and |
| 44 |
the normal way for Tcl/Tk applications to override class bindings |
| 45 |
is with an instance binding. However, with perl/Tk the normal way |
| 46 |
to override a class binding is to derive a class. The perl/Tk order |
| 47 |
causes instance bindings to execute after the class binding, and |
| 48 |
so instance bind callbacks can make use of state changes (e.g. changes |
| 49 |
to the selection) than the class bindings have made. |
| 50 |
|
| 51 |
The B<bindtags> command allows the binding tags for a window to be |
| 52 |
read and modified. |
| 53 |
|
| 54 |
If I<$widget>-E<gt>B<bindtags> is invoked without an argument, then the |
| 55 |
current set of binding tags for $widget is returned as a list. |
| 56 |
If the I<tagList> argument is specified to B<bindtags>, |
| 57 |
then it must be a reference to and array; the tags for $widget are changed |
| 58 |
to the elements of the array. (A reference to an anonymous array can |
| 59 |
be created by enclosin the elements in B<[ ]>.) |
| 60 |
The elements of I<tagList> may be arbitrary strings or widget objects, |
| 61 |
if no window exists for an object at the time an event is processed, |
| 62 |
then the tag is ignored for that event. |
| 63 |
The order of the elements in I<tagList> determines the order in |
| 64 |
which binding callbacks are executed in response to events. |
| 65 |
For example, the command |
| 66 |
|
| 67 |
$b->bindtags([$b,ref($b),$b->toplevel,'all']) |
| 68 |
|
| 69 |
applies the Tcl/Tk binding order which binding callbacks will be |
| 70 |
evaluated for a button (say) B<$b> so that B<$b>'s instance bindings |
| 71 |
are invoked first, following by bindings for B<$b>'s class, followed by |
| 72 |
bindings for B<$b>'s toplevel, followed by 'B<all>' bindings. |
| 73 |
|
| 74 |
If I<tagList> is an empty list i.e. B<[]>, then the binding |
| 75 |
tags for $widget are returned to the perl/Tk default state described above. |
| 76 |
|
| 77 |
The B<bindtags> command may be used to introduce arbitrary |
| 78 |
additional binding tags for a window, or to remove standard tags. |
| 79 |
For example, the command |
| 80 |
|
| 81 |
$b->bindtags(['TrickyButton',$b->toplevel,'all']) |
| 82 |
|
| 83 |
replaces the (say) B<Tk::Button> tag for B<$b> with B<TrickyButton>. |
| 84 |
This means that the default widget bindings for buttons, which are |
| 85 |
associated with the B<Tk::Button> tag, will no longer apply to B<$b>, |
| 86 |
but any bindings associated with B<TrickyButton> (perhaps some |
| 87 |
new button behavior) will apply. |
| 88 |
|
| 89 |
=head1 BUGS |
| 90 |
|
| 91 |
The current mapping of the 'native' Tk behaviour of this method |
| 92 |
i.e. returning a list but only accepting a reference to an array is |
| 93 |
counter intuitive. The perl/Tk interface may be tidied up, returning |
| 94 |
a list is sensible so, most likely fix will be to allow a list to be |
| 95 |
passed to I<set> the bindtags. |
| 96 |
|
| 97 |
=head1 SEE ALSO |
| 98 |
|
| 99 |
L<Tk::bind|Tk::bind> |
| 100 |
L<Tk::callbacks|Tk::callbacks> |
| 101 |
|
| 102 |
=head1 KEYWORDS |
| 103 |
|
| 104 |
binding, event, tag |
| 105 |
|
| 106 |
=cut |
| 107 |
|