# Copyright (c) 1990 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # =head1 NAME Tk::bind - Arrange for X events to invoke callbacks =for category Binding Events and Callbacks =head1 SYNOPSIS Retrieve bindings: S< >I<$widget>-EB S< >I<$widget>-EB(I) S< >I<$widget>-EB(I) S< >I<$widget>-EB(I,I) Associate and destroy bindings: S< >I<$widget>-EB(I,I) S< >I<$widget>-EB(I,I,I) =head1 DESCRIPTION The B method associates callbacks with X events. If I is specified, B will arrange for I to be evaluated whenever the event(s) given by I occur in the window(s) identified by I<$widget> or I. If I is an empty string then the current binding for I is destroyed, leaving I unbound. In all of the cases where a I argument is provided, B returns an empty string. If I is specified without a I, then the callback currently bound to I is returned, or B is returned if there is no binding for I. If neither I nor I is specified, then the return value is a list whose elements are all the sequences for which there exist bindings for I. If no I is specified then the B refers to I<$widget>. If I is specified then it is typically a class name and the B refers to all instances of the class on the B associated with I<$widget>. (It is possible for I to be another "widget object" but this practice is deprecated.) Perl's B(I<$object>) can be used to get the class name of any object. Each window has an associated list of tags, and a binding applies to a particular window if its tag is among those specified for the window. Although the B method may be used to assign an arbitrary set of binding tags to a window, the default binding tags provide the following behavior: If a tag is the name of an internal window the binding applies to that window. If the tag is the name of a toplevel window the binding applies to the toplevel window and all its internal windows. If the tag is the name of a class of widgets, such as B, the binding applies to all widgets in that class; If I has the value B, the binding applies to all windows descended from the MainWindow of the application. =head1 EVENT PATTERNS The I argument specifies a sequence of one or more event patterns, with optional white space between the patterns. Each event pattern has the following syntax: S< >'' The entire event pattern is surrounded by angle brackets, and normally needs to be quoted, as angle brackets are special to perl. Inside the angle brackets are zero or more modifiers, an event type, and an extra piece of information (I) identifying a particular button or keysym. Any of the fields may be omitted, as long as at least one of I and I is present. The fields must be separated by white space or dashes. A second form of pattern is used to specify a user-defined, named virtual event; see L for details. It has the following syntax: S< ><> The entire virtual event pattern is surrounded by double angle brackets. Inside the angle brackets is the user-defined name of the virtual event. Modifiers, such as B or B, may not be combined with a virtual event to modify it. Bindings on a virtual event may be created before the virtual event is defined, and if the definition of a virtual event changes dynamically, all windows bound to that virtual event will respond immediately to the new definition. =head1 MODIFIERS Modifiers consist of any of the following values: Control Mod2, M2 Shift Mod3, M3 Lock Mod4, M4 Button1, B1 Mod5, M5 Button2, B2 Meta, M Button3, B3 Alt Button4, B4 Double Button5, B5 Triple Mod1, M1 Where more than one value is listed, separated by commas, the values are equivalent. Most of the modifiers have the obvious X meanings. For example, B requires that button 1 be depressed when the event occurs. For a binding to match a given event, the modifiers in the event must include all of those specified in the event pattern. An event may also contain additional modifiers not specified in the binding. For example, if button 1 is pressed while the shift and control keys are down, the pattern BControl-Button-1E> will match the event, but BMod1-Button-1E> will not. If no modifiers are specified, then any combination of modifiers may be present in the event. B and B refer to whichever of the B through B modifiers is associated with the meta key(s) on the keyboard (keysyms B and B). If there are no meta keys, or if they are not associated with any modifiers, then B and B will not match any events. Similarly, the B modifier refers to whichever modifier is associated with the alt key(s) on the keyboard (keysyms B and B). The B and B modifiers are a convenience for specifying double mouse clicks and other repeated events. They cause a particular event pattern to be repeated 2 or 3 times, and also place a time and space requirement on the sequence: for a sequence of events to match a B or B pattern, all of the events must occur close together in time and without substantial mouse motion in between. For example, BDouble-Button-1E> is equivalent to BButton-1EEButton-1E> with the extra time and space requirement. =head1 EVENT TYPES The I field may be any of the standard X event types, with a few extra abbreviations. Below is a list of all the valid types; where two names appear together, they are synonyms. ButtonPress, Button Expose Map ButtonRelease FocusIn Motion Circulate FocusOut Property Colormap Gravity Reparent Configure KeyPress, Key Unmap Destroy KeyRelease Visibility Enter Leave Activate Deactivate The last part of a long event specification is I. In the case of a B or B event, it is the number of a button (1-5). If a button number is given, then only an event on that particular button will match; if no button number is given, then an event on any button will match. Note: giving a specific button number is different than specifying a button modifier; in the first case, it refers to a button being pressed or released, while in the second it refers to some other button that is already depressed when the matching event occurs. If a button number is given then I may be omitted: if will default to B. For example, the specifier B1E> is equivalent to BButtonPress-1E>. If the event type is B or B, then I may be specified in the form of an X keysym. Keysyms are textual specifications for particular keys on the keyboard; they include all the alphanumeric ASCII characters (e.g. ``a'' is the keysym for the ASCII character ``a''), plus descriptions for non-alphanumeric characters (``comma'' is the keysym for the comma character), plus descriptions for all the non-ASCII keys on the keyboard (``Shift_L'' is the keysm for the left shift key, and ``F1'' is the keysym for the F1 function key, if it exists). The complete list of keysyms is not presented here; it is available in other X documentation and may vary from system to system. If necessary, you can use the B<'K'> notation described below to print out the keysym name for a particular key. If a keysym I is given, then the I field may be omitted; it will default to B. For example, BControl-commaE> is equivalent to BControl-KeyPress-commaE>. =head1 BINDING CALLBACKS AND SUBSTITUTIONS The I argument to B is a perl/Tk callback. which will be executed whenever the given event sequence occurs. (See L for description of the possible forms.) I will be associated with the same B that is associated with the I<$widget> that was used to invoke the B method, and it will run as though called from B. If I contains any B(I<%>) calls, then each "nested" B(I<%>) "callback" will be evaluated when the event occurs to form arguments to be passed to the main I. The replacement depends on the character I<%>, as defined in the list below. Unless otherwise indicated, the replacement string is the numeric (decimal) value of the given field from the current event. Perl/Tk has enhanced this mechanism slightly compared to the comparable Tcl/Tk mechanism. The enhancements are not yet all reflected in the list below. Some of the substitutions are only valid for certain types of events; if they are used for other types of events the value substituted is undefined (not the same as B!). =over 4 =item B<'#'> The number of the last client request processed by the server (the I field from the event). Valid for all event types. =item B<'a'> The I field from the event, formatted as a hexadecimal number. Valid only for B events. =item B<'b'> The number of the button that was pressed or released. Valid only for B and B events. =item B<'c'> The I field from the event. Valid only for B events. =item B<'d'> The I field from the event. The B<'d'> is replaced by a string identifying the detail. For B, B, B, and B events, the string will be one of the following: =over 8 NotifyAncestor NotifyNonlinearVirtual NotifyDetailNone NotifyPointer NotifyInferior NotifyPointerRoot NotifyNonlinear NotifyVirtual For events other than these, the substituted string is undefined. (Note that this is I the same as Detail part of sequence use to specify the event.) =back =item B<'f'> The I field from the event (B<0> or B<1>). Valid only for B and B events. =item B<'h'> The I field from the event. Valid only for B, B, and B events. =item B<'k'> The I field from the event. Valid only for B and B events. =item B<'m'> The I field from the event. The substituted string is one of B, B, B, or B. Valid only for B, B, B, and B events. =item B<'o'> The I field from the event. Valid only for B, B, and B events. =item B<'p'> The I field from the event, substituted as one of the strings B or B. Valid only for B events. =item B<'s'> The I field from the event. For B, B, B, B, B, B, and B events, a decimal string is substituted. For B, one of the strings B, B, and B is substituted. =item B<'t'> The I