{ $description "Sets the gestures a gadget class responds to. The hashtable maps gestures to quotations with stack effect " { $snippet "( gadget -- )" } "." } ;
{ $notes "Methods should be defined on this word if you desire to handle an arbitrary set of gestures. To define handlers for a fixed set, it is easier to use " { $link set-gestures } "." } ;
{ $class-description "Mouse drag gesture. The " { $snippet "#" } " slot is either set to a mouse button number, or " { $link f } " indicating no specific button is expected." } ;
{ $examples { $code "T{ button-down f f 1 }""T{ button-down }" } } ;
HELP:mouse-scroll
{ $class-description "Scroll wheel motion gesture. When this gesture is sent, the " { $link scroll-direction } " global variable is set to a direction vector." }
{ $examples { $code "T{ mouse-scroll }" } } ;
HELP:mouse-enter
{ $class-description "Gesture sent when the mouse enters the bounds of a gadget." }
{ $examples { $code "T{ mouse-enter }" } } ;
HELP:mouse-leave
{ $class-description "Gesture sent when the mouse leaves the bounds of a gadget." }
{ $examples { $code "T{ mouse-leave }" } } ;
HELP:gain-focus
{ $class-description "Gesture sent when a gadget gains keyboard focus." }
{ $examples { $code "T{ gain-focus }" } } ;
HELP:lose-focus
{ $class-description "Gesture sent when a gadget loses keyboard focus." }
{ $examples { $code "T{ lose-focus }" } } ;
HELP:cut-action
{ $class-description "Gesture sent when the " { $emphasis "cut" } " standard window system action is invoked." }
{ $examples { $code "T{ cut-action }" } } ;
HELP:copy-action
{ $class-description "Gesture sent when the " { $emphasis "copy" } " standard window system action is invoked." }
{ $examples { $code "T{ copy-action }" } } ;
HELP:paste-action
{ $class-description "Gesture sent when the " { $emphasis "paste" } " standard window system action is invoked." }
{ $examples { $code "T{ paste-action }" } } ;
HELP:delete-action
{ $class-description "Gesture sent when the " { $emphasis "delete" } " standard window system action is invoked." }
{ $examples { $code "T{ delete-action }" } } ;
HELP:select-all-action
{ $class-description "Gesture sent when the " { $emphasis "select all" } " standard window system action is invoked." }
{ $examples { $code "T{ key-up f { C+ } \"a\" }""T{ key-up f f \"TAB\" }" } } ;
HELP:hand-gadget
{ $var-description "Global variable. The gadget at the mouse location." } ;
HELP:hand-loc
{ $var-description "Global variable. The mouse location relative to the top-left corner of the " { $link hand-world } "." } ;
{ hand-loc hand-rel } related-words
HELP:hand-clicked
{ $var-description "Global variable. The gadget at the location of the most recent click." } ;
HELP:hand-click-loc
{ $var-description "Global variable. The mouse location at the time of the most recent click relative to the top-left corner of the " { $link hand-world } "." } ;
{ hand-clicked hand-click-loc } related-words
HELP:hand-click#
{ $var-description "Global variable. The number of times the mouse was clicked in short succession. This counter is reset when " { $link double-click-timeout } " expires." } ;
HELP:hand-last-button
{ $var-description "Global variable. The mouse button most recently pressed." } ;
{ $var-description "Global variable. The timestamp of the most recent mouse button click. This timestamp has the same format as the output value of " { $link micros } "." } ;
{ $var-description "Global variable. A vector of mouse buttons currently held down." } ;
HELP:scroll-direction
{ $var-description "Global variable. If the most recent gesture was a " { $link mouse-scroll } ", this holds a pair of integers indicating the direction of the scrolling as a two-dimensional vector." } ;
HELP:double-click-timeout
{ $var-description "Global variable. The maximum delay between two button presses which will still increment " { $link hand-click# } "." } ;
HELP:button-gesture
{ $values { "gesture""a gesture" } }
{ $description "Sends a gesture to the most recently clicked gadget, and if the gadget does not respond to the gesture, removes specific button number information from the gesture and sends it again." } ;
HELP:fire-motion
{ $description "Sends a " { $link motion } " or " { $link drag } " gesture to the gadget under the mouse, depending on whether a mouse button is being held down or not." } ;
HELP:forget-rollover
{ $description "Sends " { $link mouse-leave } " gestures to all gadgets containing the gadget under the mouse, and resets the " { $link hand-gadget } " variable." } ;
HELP:request-focus
{ $values { "gadget" gadget } }
{ $description "Gives keyboard focus to the " { $link focusable-child } " of the gadget. This may result in " { $link lose-focus } " and " { $link gain-focus } " gestures being sent." } ;
HELP:drag-loc
{ $values { "loc""a pair of integers" } }
{ $description "Outputs the distance travelled by the mouse since the most recent press. Only meaningful inside a " { $link drag } " gesture handler." } ;
{ $description "Outputs the location of the mouse relative to the top-left corner of the gadget. Only meaningful inside a " { $link button-down } ", " { $link button-up } ", " { $link motion } " or " { $link drag } " gesture handler, where the gadget is contained in the same world as the gadget receiving the gesture." } ;
{ $description "Outputs the location of the last mouse relative to the top-left corner of the gadget. Only meaningful inside a " { $link button-down } ", " { $link button-up } ", " { $link motion } " or " { $link drag } " gesture handler, where the gadget is contained in the same world as the gadget receiving the gesture." } ;
HELP:under-hand
{ $values { "seq""a new sequence" } }
{ $description "Outputs a sequence where the first element is the " { $link hand-world } " and the last is the " { $link hand-gadget } ", with all parents in between." } ;
"User actions such as keyboard input and mouse button clicks deliver " { $emphasis "gestures" } " to gadgets. If the direct receiver of the gesture does not handle it, the gesture is passed on to the receiver's parent, and this way it travels up the gadget hierarchy. Gestures which are not handled at some point are ignored."
$nl
"There are two ways to define gesture handling logic. The simplest way is to associate a fixed set of gestures with a class:"
{ $subsection set-gestures }
"Another way is to define a generic word on a class which handles all gestures sent to gadgets of that class:"
"The gadget with keyboard focus is the current receiver of keyboard gestures and user input. Gadgets that wish to receive keyboard input should request focus when clicked:"
{ $subsection request-focus }
"The following example demonstrates defining a handler for a mouse click gesture which requests focus:"
{ $code
"my-gadget H{"
" { T{ button-down } [ request-focus ] }"
"} set-gestures"
}
"To nominate a single child as the default focusable child, implement a method on a generic word:"
{ $subsection focusable-child* }
"Gestures are sent to a gadget when it gains or loses focus; this can be used to change the gadget's appearance, for example by displaying a border:"
{ $subsection gain-focus }
{ $subsection lose-focus } ;
ARTICLE: "keyboard-gestures""Keyboard gestures"
"There are two types of keyboard gestures:"
{ $subsection key-down }
{ $subsection key-up }
"Each keyboard gesture has a set of modifiers and a key symbol. The set modifiers is denoted by an array which must either be " { $link f } ", or an order-preserving subsequence of the following:"
{ $code "{ S+ C+ A+ M+ }" }
{ $subsection S+ }
{ $subsection C+ }
{ $subsection A+ }
{ $subsection M+ }
"A key symbol is either a single-character string denoting literal input, or one of the following strings:"
{ $list
{ $snippet "CLEAR" }
{ $snippet "RET" }
{ $snippet "ENTER" }
{ $snippet "ESC" }
{ $snippet "TAB" }
{ $snippet "BACKSPACE" }
{ $snippet "HOME" }
{ $snippet "DELETE" }
{ $snippet "END" }
{ $snippet "F1" }
{ $snippet "F2" }
{ $snippet "F3" }
{ $snippet "F4" }
{ $snippet "F5" }
{ $snippet "F6" }
{ $snippet "F7" }
{ $snippet "F8" }
{ $snippet "LEFT" }
{ $snippet "RIGHT" }
{ $snippet "DOWN" }
{ $snippet "UP" }
{ $snippet "PAGE_UP" }
{ $snippet "PAGE_DOWN" }
}
"The " { $link S+ } " modifier is only ever used with the above action keys; alphanumeric input input with the shift key is delivered without the " { $link S+ } " modifier set, instead the input itself is upper case. For example, the gesture corresponding to " { $snippet "s" } " with the Control and Shift keys pressed is presented as "
{ $code "T{ key-down f { C+ } \"S\" }" }
"The " { $snippet "RET" } ", " { $snippet "TAB" } " and " { $snippet "SPACE" } " keys are never delivered in their literal form (" { $snippet "\"\\n\"" } ", " { $snippet "\"\\t\"" } " or " { $snippet "\" \"" } ").";
"Whereas keyboard gestures are intended to be used for keyboard shortcuts, certain gadgets such as text fields need to accept free-form keyboard input. This can be done by implementing a generic word:"
{ $subsection user-input* } ;
ARTICLE: "mouse-gestures""Mouse gestures"
"There are two types of mouse gestures indicating button clicks:"
{ $subsection button-down }
{ $subsection button-up }
"When a mouse button is pressed or released, two gestures are sent. The first gesture indicates the specific button number, and if this gesture is not handled, the second has a button number set to " { $link f } ":"
{ $code "T{ button-down f 1 }""T{ button-down f f }" }
"Because tuple literals fill unspecified slots with " { $link f } ", the last gesture can be written as " { $snippet "T{ button-down }" } "."
$nl
"Gestures to indicate mouse motion, depending on whenever a button is held down or not:"
{ $subsection motion }
{ $subsection drag }
"Gestures to indicate that the mouse has crossed gadget boundaries:"
{ $subsection mouse-enter }
{ $subsection mouse-leave }
"A number of global variables are set after a mouse gesture is sent. These variables can be read to obtain additional information about the gesture."
{ $subsection hand-gadget }
{ $subsection hand-world }
{ $subsection hand-loc }
{ $subsection hand-buttons }
{ $subsection hand-clicked }
{ $subsection hand-click-loc }
{ $subsection hand-click# }
"There are some utility words for working with click locations:"
{ $subsection hand-rel }
{ $subsection hand-click-rel }
{ $subsection drag-loc }
"Mouse scroll wheel gesture:"
{ $subsection mouse-scroll }
"Global variable set when a mouse scroll wheel gesture is sent:"
"Action gestures should be used in place of the above keyboard gestures if possible. For example, on Mac OS X, the standard " { $strong "Edit" } " menu items send action gestures.";