The focus highlighting features allow keyboard interaction with Tk interfaces. They work best when used in combination with the tab group widget. When focus highlighting is activated (by sourcing the relevant bindings into the Tcl script), the widget which currently has the keyboard focus is highlighted by drawing a coloured 2D border around the outside of the widget.
focuspolicy
?mode?
explicit
or pointer
. When the focus policy
is explicit
, the keyboard focus is given to a widget by
clicking on it with the mouse or via keyboard traversal (via tab groups).
When the focus policy is pointer
, the keyboard focus is
given to the widget containing the mouse pointer.
The focus policy is set automatically when the focus highlighting
module is loaded by getting the value of the X resource
.focusPolicy
(class FocusPolicy
).
The following procedures and data are defined by the focus highlighting module. They are used by the event-bindings created by the module when it is sourced and should not generally be used by scripts.
__showfocus
widget
__showfocus
procedure removes any focus highlight.
If it is a widget path name, it displays the focus highlight around the
given widget. This procedure is bound to the FocusIn
and
FocusOut
events on all widgets except frames and top
level widgets.__resizefocus widget
Configure
event on all
widgets.
__showfocus(
element)
Note: since all widget classes have bindings for the
FocusIn
, FocusOut
and Configure
events, new bindings for these events must be added using the
widget :: add_binding
proc.
The focus highlighting module binds event handlers to widgets to allow keyboard interaction. These handlers are:
space
key invokes the button if it is not disabled
(ie: it acts as a mouse-click).listbox
widgets cannot easily be used
via the keyboard since they provide no way of indicating which list
item currently has the keyboard focus. However, if a listbox is in
single-select mode, the selected item and the item with the keyboard
focus are one and the same. Because of this, the focus-highlighting
module redefines the tk_listboxSingleSelect
procedure
to add bindings to listboxes allowing them to be used via the
keyboard.The focus highlighting module gets its parameters from the X resource database via the following resources:
.focusPolicy
FocusPolicy
explicit
or pointer
explicit
Pointer
means that the widget with the mouse pointer
receives keyboard input; explicit
means that the
keyboard focus must be moved via the cursor and tab keys (the
tabgroup
widgets must be used
to allow keyboard navigation.
.focusHighlightWidth
FocusHighlightWidth
2
.focusHighlightColor
FocusHighlightColor
red
The focus highlighting module can be loaded using the source
command. However, if the Itcl widget library is installed so as to take
advantage of Tcl's auto-loading system one can load the module by invoking
the command focuspolicy
at the top of the script.