Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Tk / bind.pod
CommitLineData
86530b38
AT
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
10Tk::bind - Arrange for X events to invoke callbacks
11
12=for category Binding Events and Callbacks
13
14=head1 SYNOPSIS
15
16Retrieve bindings:
17
18S< >I<$widget>-E<gt>B<bind>
19
20S< >I<$widget>-E<gt>B<bind>(I<tag>)
21
22S< >I<$widget>-E<gt>B<bind>(I<sequence>)
23
24S< >I<$widget>-E<gt>B<bind>(I<tag>,I<sequence>)
25
26Associate and destroy bindings:
27
28S< >I<$widget>-E<gt>B<bind>(I<sequence>,I<callback>)
29
30S< >I<$widget>-E<gt>B<bind>(I<tag>,I<sequence>,I<callback>)
31
32=head1 DESCRIPTION
33
34The B<bind> method associates callbacks with X events.
35If I<callback> is specified, B<bind> will
36arrange for I<callback> to be evaluated whenever
37the event(s) given by I<sequence> occur in the window(s)
38identified by I<$widget> or I<tag>.
39If I<callback> is an empty string then the current binding for
40I<sequence> is destroyed, leaving I<sequence> unbound.
41In all of the cases where a I<callback> argument is provided,
42B<bind> returns an empty string.
43
44If I<sequence> is specified without a I<callback>, then the
45callback currently bound to I<sequence> is returned, or
46B<undef> is returned if there is no binding for I<sequence>.
47If neither I<sequence> nor I<callback> is specified, then the
48return value is a list whose elements are all the sequences
49for which there exist bindings for I<tag>.
50
51If no I<tag> is specified then the B<bind> refers to I<$widget>.
52If I<tag> is specified then it is typically a class name and the B<bind>
53refers to all instances of the class on the B<MainWindow> associated
54with I<$widget>. (It is possible for I<tag> to be another "widget object"
55but this practice is deprecated.) Perl's B<ref>(I<$object>) can be used
56to get the class name of any object.
57Each window has an associated list of tags, and a binding applies
58to a particular window if its tag is among those specified for
59the window.
60Although the B<bindtags> method may be used to assign an
61arbitrary set of binding tags to a window, the default binding
62tags provide the following behavior:
63
64If a tag is the name of an internal window the binding applies
65to that window.
66
67If the tag is the name of a toplevel window the binding applies
68to the toplevel window and all its internal windows.
69
70If the tag is the name of a class of widgets, such as B<Tk::Button>,
71the binding applies to all widgets in that class;
72
73If I<tag> has the value B<all>,
74the binding applies to all windows descended from the MainWindow
75of the application.
76
77=head1 EVENT PATTERNS
78
79The I<sequence> argument specifies a sequence of one or more
80event patterns, with optional white space between the patterns. Each
81event pattern has the following syntax:
82
83S< >'<modifier-modifier-type-detail>'
84
85The entire event pattern is surrounded by angle brackets, and normally
86needs to be quoted, as angle brackets are special to perl.
87Inside the angle brackets are zero or more modifiers, an event
88type, and an extra piece of information (I<detail>) identifying
89a particular button or keysym. Any of the fields may be omitted,
90as long as at least one of I<type> and I<detail> is present.
91The fields must be separated by white space or dashes.
92
93A second form of pattern is used to specify a user-defined, named virtual
94event; see L<Tk::event> for details. It has the following syntax:
95
96S< ><<name>>
97
98The entire virtual event pattern is surrounded by double angle brackets.
99Inside the angle brackets is the user-defined name of the virtual event.
100Modifiers, such as B<Shift> or B<Control>, may not be combined with a
101virtual event to modify it. Bindings on a virtual event may be created
102before the virtual event is defined, and if the definition of a virtual
103event changes dynamically, all windows bound to that virtual event will
104respond immediately to the new definition.
105
106=head1 MODIFIERS
107
108Modifiers consist of any of the following values:
109
110 Control Mod2, M2
111 Shift Mod3, M3
112 Lock Mod4, M4
113 Button1, B1 Mod5, M5
114 Button2, B2 Meta, M
115 Button3, B3 Alt
116 Button4, B4 Double
117 Button5, B5 Triple
118 Mod1, M1
119
120Where more than one value is listed, separated by commas, the values
121are equivalent.
122Most of the modifiers have the obvious X meanings.
123For example, B<Button1> requires that
124button 1 be depressed when the event occurs.
125For a binding to match a given event, the modifiers in the event
126must include all of those specified in the event pattern.
127An event may also contain additional modifiers not specified in
128the binding.
129For example, if button 1 is pressed while the shift and control keys
130are down, the pattern B<E<lt>Control-Button-1E<gt>> will match
131the event, but B<E<lt>Mod1-Button-1E<gt>> will not.
132If no modifiers are specified, then any combination of modifiers may
133be present in the event.
134
135B<Meta> and B<M> refer to whichever of the
136B<M1> through B<M5> modifiers is associated with the meta
137key(s) on the keyboard (keysyms B<Meta_R> and B<Meta_L>).
138If there are no meta keys, or if they are not associated with any
139modifiers, then B<Meta> and B<M> will not match any events.
140Similarly, the B<Alt> modifier refers to whichever modifier
141is associated with the alt key(s) on the keyboard (keysyms
142B<Alt_L> and B<Alt_R>).
143
144The B<Double> and B<Triple> modifiers are a convenience
145for specifying double mouse clicks and other repeated
146events. They cause a particular event pattern to be
147repeated 2 or 3 times, and also place a time and space requirement
148on the sequence: for a sequence of events to match a B<Double>
149or B<Triple> pattern, all of the events must occur close together
150in time and without substantial mouse motion in between.
151For example, B<E<lt>Double-Button-1E<gt>>
152is equivalent to B<E<lt>Button-1E<gt>E<lt>Button-1E<gt>> with the extra
153time and space requirement.
154
155=head1 EVENT TYPES
156
157The I<type> field may be any of the standard X event types, with a
158few extra abbreviations. Below is a list of all the valid types;
159where two names appear together, they are synonyms.
160
161 ButtonPress, Button Expose Map
162 ButtonRelease FocusIn Motion
163 Circulate FocusOut Property
164 Colormap Gravity Reparent
165 Configure KeyPress, Key Unmap
166 Destroy KeyRelease Visibility
167 Enter Leave Activate
168 Deactivate
169
170The last part of a long event specification is I<detail>. In the
171case of a B<ButtonPress> or B<ButtonRelease> event, it is the
172number of a button (1-5). If a button number is given, then only an
173event on that particular button will match; if no button number is
174given, then an event on any button will match. Note: giving a
175specific button number is different than specifying a button modifier;
176in the first case, it refers to a button being pressed or released,
177while in the second it refers to some other button that is already
178depressed when the matching event occurs. If a button
179number is given then I<type> may be omitted: if will default
180to B<ButtonPress>. For example, the specifier B<E<lt>1E<gt>>
181is equivalent to B<E<lt>ButtonPress-1E<gt>>.
182
183If the event type is B<KeyPress> or B<KeyRelease>, then
184I<detail> may be specified in the form of an X keysym. Keysyms
185are textual specifications for particular keys on the keyboard;
186they include all the alphanumeric ASCII characters (e.g. ``a'' is
187the keysym for the ASCII character ``a''), plus descriptions for
188non-alphanumeric characters (``comma'' is the keysym for the comma
189character), plus descriptions for all the non-ASCII keys on the
190keyboard (``Shift_L'' is the keysm for the left shift key, and
191``F1'' is the keysym for the F1 function key, if it exists). The
192complete list of keysyms is not presented here; it is
193available in other X documentation and may vary from system to
194system.
195If necessary, you can use the B<'K'> notation described below
196to print out the keysym name for a particular key.
197If a keysym I<detail> is given, then the
198I<type> field may be omitted; it will default to B<KeyPress>.
199For example, B<E<lt>Control-commaE<gt>> is equivalent to
200B<E<lt>Control-KeyPress-commaE<gt>>.
201
202=head1 BINDING CALLBACKS AND SUBSTITUTIONS
203
204The I<callback> argument to B<bind> is a perl/Tk callback.
205which will be executed whenever the given event sequence occurs.
206(See L<Tk::callbacks> for description of the possible forms.)
207I<Callback> will be associated with the same B<MainWindow>
208that is associated with the I<$widget> that was used to invoke
209the B<bind> method, and it will run as though called from B<MainLoop>.
210If I<callback> contains
211any B<Ev>(I<%>) calls, then each "nested" B<Ev>(I<%>)
212"callback" will be evaluated when the event occurs to form arguments
213to be passed to the main I<callback>.
214The replacement
215depends on the character I<%>, as defined in the
216list below. Unless otherwise indicated, the
217replacement string is the numeric (decimal) value of the given field from
218the current event. Perl/Tk has enhanced this mechanism slightly compared
219to the comparable Tcl/Tk mechanism. The enhancements are not yet all
220reflected in the list below.
221Some of the substitutions are only valid for
222certain types of events; if they are used for other types of events
223the value substituted is undefined (not the same as B<undef>!).
224
225=over 4
226
227=item B<'#'>
228
229The number of the last client request processed by the server
230(the I<serial> field from the event). Valid for all event
231types.
232
233=item B<'a'>
234
235The I<above> field from the event,
236formatted as a hexadecimal number.
237Valid only for B<Configure> events.
238
239=item B<'b'>
240
241The number of the button that was pressed or released. Valid only
242for B<ButtonPress> and B<ButtonRelease> events.
243
244=item B<'c'>
245
246The I<count> field from the event. Valid only for B<Expose> events.
247
248=item B<'d'>
249
250The I<detail> field from the event. The B<'d'> is replaced by
251a string identifying the detail. For B<Enter>,
252B<Leave>, B<FocusIn>, and B<FocusOut> events,
253the string will be one of the following:
254
255=over 8
256
257 NotifyAncestor NotifyNonlinearVirtual
258 NotifyDetailNone NotifyPointer
259 NotifyInferior NotifyPointerRoot
260 NotifyNonlinear NotifyVirtual
261
262For events other than these, the substituted string is undefined.
263(Note that this is I<not> the same as Detail part of sequence
264use to specify the event.)
265
266=back
267
268=item B<'f'>
269
270The I<focus> field from the event (B<0> or B<1>). Valid only
271for B<Enter> and B<Leave> events.
272
273=item B<'h'>
274
275The I<height> field from the event. Valid only for B<Configure>,
276B<Expose>, and B<GraphicsExpose> events.
277
278=item B<'k'>
279
280The I<keycode> field from the event. Valid only for B<KeyPress>
281and B<KeyRelease> events.
282
283=item B<'m'>
284
285The I<mode> field from the event. The substituted string is one of
286B<NotifyNormal>, B<NotifyGrab>, B<NotifyUngrab>, or
287B<NotifyWhileGrabbed>. Valid only for B<EnterWindow>,
288B<FocusIn>, B<FocusOut>, and B<LeaveWindow> events.
289
290=item B<'o'>
291
292The I<override_redirect> field from the event. Valid only for
293B<Map>, B<Reparent>, and B<Configure> events.
294
295=item B<'p'>
296
297The I<place> field from the event, substituted as one of the
298strings B<PlaceOnTop> or B<PlaceOnBottom>. Valid only
299for B<Circulate> events.
300
301=item B<'s'>
302
303The I<state> field from the event. For B<ButtonPress>,
304B<ButtonRelease>, B<Enter>, B<KeyPress>, B<KeyRelease>,
305B<Leave>, and B<Motion> events, a decimal string
306is substituted. For B<Visibility>, one of the strings
307B<VisibilityUnobscured>, B<VisibilityPartiallyObscured>,
308and B<VisibilityFullyObscured> is substituted.
309
310=item B<'t'>
311
312The I<time> field from the event. Valid only for events that
313contain a I<time> field.
314
315=item B<'w'>
316
317The I<width> field from the event. Valid only for
318B<Configure>, B<Expose>, and B<GraphicsExpose> events.
319
320=item B<'x'>
321
322The I<x> field from the event. Valid only for events containing
323an I<x> field.
324
325=item B<'y'>
326
327The I<y> field from the event. Valid only for events containing
328a I<y> field.
329
330=item B<'@'>
331
332The string "@I<x,y>" where I<x> and I<y> are as above.
333Valid only for events containing I<x> and I<y> fields.
334This format is used my methods of B<Tk::Text> and similar widgets.
335
336=item B<'A'>
337
338Substitutes the ASCII character corresponding to the event, or
339the empty string if the event doesn't correspond to an ASCII character
340(e.g. the shift key was pressed). B<XLookupString> does all the
341work of translating from the event to an ASCII character.
342Valid only for B<KeyPress> and B<KeyRelease> events.
343
344=item B<'B'>
345
346The I<border_width> field from the event. Valid only for
347B<Configure> events.
348
349=item B<'E'>
350
351The I<send_event> field from the event. Valid for all event types.
352
353=item B<'K'>
354
355The keysym corresponding to the event, substituted as a textual
356string. Valid only for B<KeyPress> and B<KeyRelease> events.
357
358=item B<'N'>
359
360The keysym corresponding to the event, substituted as
361a decimal
362number. Valid only for B<KeyPress> and B<KeyRelease> events.
363
364=item B<'R'>
365
366The I<root> window identifier from the event. Valid only for
367events containing a I<root> field.
368
369=item B<'S'>
370
371The I<subwindow> window identifier from the event,
372as an object if it is one otherwise as a hexadecimal number.
373Valid only for events containing a I<subwindow> field.
374
375=item B<'T'>
376
377The I<type> field from the event. Valid for all event types.
378
379=item B<'W'>
380
381The window to which the event was reported (the
382$widget field from the event) - as an perl/Tk object.
383Valid for all event types.
384
385=item B<'X'>
386
387The I<x_root> field from the event.
388If a virtual-root window manager is being used then the substituted
389value is the corresponding x-coordinate in the virtual root.
390Valid only for
391B<ButtonPress>, B<ButtonRelease>, B<KeyPress>, B<KeyRelease>,
392and B<Motion> events.
393
394=item B<'Y'>
395
396The I<y_root> field from the event.
397If a virtual-root window manager is being used then the substituted
398value is the corresponding y-coordinate in the virtual root.
399Valid only for
400B<ButtonPress>, B<ButtonRelease>, B<KeyPress>, B<KeyRelease>,
401and B<Motion> events.
402
403=back
404
405=head1 MULTIPLE MATCHES
406
407It is possible for several bindings to match a given X event.
408If the bindings are associated with different I<tag>'s,
409then each of the bindings will be executed, in order.
410By default, a class binding will be executed first, followed
411by a binding for the widget, a binding for its toplevel, and
412an B<all> binding.
413The B<bindtags> method may be used to change this order for
414a particular window or to associate additional binding tags with
415the window.
416
417B<return> and B<Tk-E<gt>break> may be used inside a
418callback to control the processing of matching callbacks.
419If B<return> is invoked, then the current callback
420is terminated but Tk will continue processing callbacks
421associated with other I<tag>'s.
422If B<Tk-E<gt>break> is invoked within a callback,
423then that callback terminates and no other callbacks will be invoked
424for the event.
425(B<Tk-E<gt>break> is implemented via perl's B<die> with a special value
426which is "caught" by the perl/Tk "glue" code.)
427
428If more than one binding matches a particular event and they
429have the same I<tag>, then the most specific binding
430is chosen and its callback is evaluated.
431The following tests are applied, in order, to determine which of
432several matching sequences is more specific:
433(a) an event pattern that specifies a specific button or key is more specific
434than one that doesn't;
435(b) a longer sequence (in terms of number
436of events matched) is more specific than a shorter sequence;
437(c) if the modifiers specified in one pattern are a subset of the
438modifiers in another pattern, then the pattern with more modifiers
439is more specific.
440(d) a virtual event whose physical pattern matches the sequence is less
441specific than the same physical pattern that is not associated with a
442virtual event.
443(e) given a sequence that matches two or more virtual events, one
444of the virtual events will be chosen, but the order is undefined.
445
446If the matching sequences contain more than one event, then tests
447(c)-(e) are applied in order from the most recent event to the least recent
448event in the sequences. If these tests fail to determine a winner, then the
449most recently registered sequence is the winner.
450
451If there are two (or more) virtual events that are both triggered by the
452same sequence, and both of those virtual events are bound to the same window
453tag, then only one of the virtual events will be triggered, and it will
454be picked at random:
455
456 $widget->eventAdd('<<Paste>>' => '<Control-y>');
457 $widget->eventAdd('<<Paste>>' => '<Button-2>');
458 $widget->eventAdd <<Scroll>>' => '<Button-2>');
459 $widget->bind('Tk::Entry','<<Paste>>',sub { print 'Paste'});
460 $widget->bind('Tk::Entry','<<Scroll>>', sub {print 'Scroll'});
461
462If the user types Control-y, the B<E<lt>E<lt>PasteE<gt>E<gt>> binding
463will be invoked, but if the user presses button 2 then one of
464either the B<E<lt>E<lt>PasteE<gt>E<gt>> or the B<E<lt>E<lt>ScrollE<gt>E<gt>> bindings will
465be invoked, but exactly which one gets invoked is undefined.
466
467If an X event does not match any of the existing bindings, then the
468event is ignored.
469An unbound event is not considered to be an error.
470
471=head1 MULTI-EVENT SEQUENCES AND IGNORED EVENTS
472
473When a I<sequence> specified in a B<bind> method contains
474more than one event pattern, then its callback is executed whenever
475the recent events (leading up to and including the current event)
476match the given sequence. This means, for example, that if button 1 is
477clicked repeatedly the sequence B<E<lt>Double-ButtonPress-1E<gt>> will match
478each button press but the first.
479If extraneous events that would prevent a match occur in the middle
480of an event sequence then the extraneous events are
481ignored unless they are B<KeyPress> or B<ButtonPress> events.
482For example, B<E<lt>Double-ButtonPress-1E<gt>> will match a sequence of
483presses of button 1, even though there will be B<ButtonRelease>
484events (and possibly B<Motion> events) between the
485B<ButtonPress> events.
486Furthermore, a B<KeyPress> event may be preceded by any number
487of other B<KeyPress> events for modifier keys without the
488modifier keys preventing a match.
489For example, the event sequence B<aB> will match a press of the
490B<a> key, a release of the B<a> key, a press of the B<Shift>
491key, and a press of the B<b> key: the press of B<Shift> is
492ignored because it is a modifier key.
493Finally, if several B<Motion> events occur in a row, only
494the last one is used for purposes of matching binding sequences.
495
496=head1 ERRORS
497
498If an error occurs in executing the callback for a binding then the
499B<Tk::Error> mechanism is used to report the error.
500The B<Tk::Error> mechanism will be executed at same call level,
501and associated with the same B<MainWindow> as
502as the callback was invoked.
503
504=head1 CAVEATS
505
506Note that for the B<Canvas> widget, the call to B<bind> has to be
507fully qualified. This is because there is already a bind method for
508the B<Canvas> widget, which binds individual canvas tags.
509
510S< >I<$canvas>-E<gt>B<Tk::bind>
511
512=head1 SEE ALSO
513
514L<Tk::Error|Tk::Error>
515L<Tk::callbacks|Tk::callbacks>
516L<Tk::bindtags|Tk::bindtags>
517
518=head1 KEYWORDS
519
520Event, binding
521
522=cut
523