3 # This file defines the default bindings for Tk listbox widgets
4 # and provides procedures that help in implementing those bindings.
6 # Copyright (c) 1994 The Regents of the University of California.
7 # Copyright (c) 1994-1995 Sun Microsystems, Inc.
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 #--------------------------------------------------------------------------
13 # ckPriv elements used in this file:
15 # listboxPrev - The last element to be selected or deselected
16 # during a selection operation.
17 # listboxSelection - All of the items that were selected before the
18 # current selection operation (such as a mouse
19 # drag) started; used to cancel an operation.
20 #--------------------------------------------------------------------------
22 #-------------------------------------------------------------------------
23 # The code below creates the default class bindings for listboxes.
24 #-------------------------------------------------------------------------
33 %W xview scroll -1 units
35 bind Listbox <Right> {
36 %W xview scroll 1 units
38 bind Listbox <Prior> {
39 %W yview scroll -1 pages
43 %W yview scroll 1 pages
52 bind Listbox <space> {
53 ckListboxBeginSelect %W [%W index active]
55 bind Listbox <Select> {
56 ckListboxBeginSelect %W [%W index active]
58 bind Listbox <Escape> {
61 bind Listbox <Button-1> {
63 ckListboxBeginSelect %W [%W index @0,%y]
66 # ckListboxBeginSelect --
68 # This procedure is typically invoked on space presses. It begins
69 # the process of making a selection in the listbox. Its exact behavior
70 # depends on the selection mode currently in effect for the listbox;
71 # see the Motif documentation for details.
74 # w - The listbox widget.
75 # el - The element for the selection operation (typically the
76 # one under the pointer). Must be in numerical form.
78 proc ckListboxBeginSelect {w el} {
80 if {[$w cget -selectmode] == "multiple"} {
81 if [$w selection includes $el] {
82 $w selection clear $el
88 $w selection clear 0 end
90 $w selection anchor $el
91 set ckPriv(listboxSelection) {}
92 set ckPriv(listboxPrev) $el
98 # Moves the location cursor (active element) up or down by one element,
99 # and changes the selection if we're in browse or extended selection
103 # w - The listbox widget.
104 # amount - +1 to move down one item, -1 to move back one item.
106 proc ckListboxUpDown {w amount} {
108 $w activate [expr [$w index active] + $amount]
110 switch [$w cget -selectmode] {
112 $w selection clear 0 end
113 $w selection set active
116 $w selection clear 0 end
117 $w selection set active
118 $w selection anchor active
119 set ckPriv(listboxPrev) [$w index active]
120 set ckPriv(listboxSelection) {}
127 # This procedure is invoked to cancel an extended selection in
128 # progress. If there is an extended selection in progress, it
129 # restores all of the items between the active one and the anchor
130 # to their previous selection state.
133 # w - The listbox widget.
135 proc ckListboxCancel w {
137 if {[$w cget -selectmode] != "extended"} {
140 set first [$w index anchor]
141 set last $ckPriv(listboxPrev)
142 if {$first > $last} {
147 $w selection clear $first $last
148 while {$first <= $last} {
149 if {[lsearch $ckPriv(listboxSelection) $first] >= 0} {
150 $w selection set $first