Listbox Bindings

   

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 32.  The Listbox Widget


A listbox has an active element and it may have one or more selected elements. The active element is highlighted with an underline, and the selected elements are highlighted with a different color. There are a large number of key bindings for listboxes. You must set the input focus to the listbox for the key bindings to work. Chapter 36 describes focus. There are four selection modes for a listbox, and the bindings vary depending what mode the listbox is in. Table 32-3 lists the four possible selectMode settings:

Table 32-3. The values for the selectMode of a listbox.
singleA single element can be selected.
browseA single element can be selected, and the selection can be dragged with the mouse. This is the default.
multipleMore than one element can be selected by toggling the selection state of items, but you only select or deselect one line at a time.
extendedMore than one element can be selected by dragging out a selection with the shift or control keys.

Browse Select Mode

In browse selection mode, <Button-1> selects the item under the mouse and dragging with the mouse moves the selection, too. Table 32-4 gives the bindings for browse mode.

Table 32-4. Bindings for browse selection mode.
<Button-1>Selects the item under the mouse. This becomes the active element, too.
<B1-Motion>Same as <Button-1>, the selection moves with the mouse.
<Shift-Button-1>Activates the item under the mouse. The selection is not changed.
<Key-Up> <Key-Down>Moves the active item up (down) one line, and selects it.
<Control-Home>Activates and select the first element of the listbox.
<Control-End>Activates and select the last element of the listbox.
<space> <Select> <Control-slash>Selects the active element.

Single Select Mode

In single selection mode, <Button-1> selects the item under the mouse, but dragging the mouse does not change the selection. When you release the mouse, the item under that point is activated. Table 32-5 specifies the bindings for single mode:

Table 32-5. Bindings for single selection mode.
<ButtonPress-1>Selects the item under the mouse.
<ButtonRelease-1>Activates the item under the mouse.
<Shift-Button-1>Activates the item under the mouse. The selection is not changed.
<Key-Up> <Key-Down>Moves the active item up (down) one line. The selection is not changed.
<Control-Home>Activates and selects the first element of the listbox.
<Control-End>Activates and selects the last element of the listbox.
<space> <Select> <Control-slash>Selects the active element.
<Control-backslash>Clears the selection.

Extended Select Mode

In extended selection mode, multiple items are selected by dragging out a selection with the first mouse button. Hold down the Shift key to adjust the ends of the selection. Use the Control key to make a disjoint selection. The Control key works in a toggle fashion, changing the selection state of the item under the mouse. If this starts a new part of the selection, then dragging the mouse extends the new part of the selection. If the toggle action cleared the selected item, then dragging the mouse continues to clear the selection. The extended mode is quite intuitive once you try it. Table 32-6 specifies the complete set of bindings for extended mode:

Table 32-6. Bindings for extended selection mode.
<Button-1>Selects the item under the mouse. This becomes the anchor point for adjusting the selection.
<B1-Motion>Sweeps out a selection from the anchor point.
<ButtonRelease-1>Activates the item under the mouse.
<Shift-Button-1>Adjusts the selection from the anchor item to the item under the mouse.
<Shift-B1-Motion>Continues to adjust the selection from the anchor.
<Control-Button-1>Toggles the selection state of the item under the mouse, and makes this the anchor point.
<Control-B1-Motion>Sets the selection state of the items from the anchor point to the item under the mouse to be the same as the selection state of the anchor point.
<Key-Up> <Key-Down>Moves the active item up (down) one line, and start a new selection with this item as the anchor point.
<Shift-Up> <Shift-Down>Moves the active element up (down) and extends the selection to include this element.
<Control-Home>Activates and selects the first element of the listbox.
<Control-Shift-Home>Extends the selection to the first element.
<Control-End>Activates and selects the last element of the listbox.
<Control-Shift-End>Extends the selection to the last element.
<space> <Select> Selects the active element.
<Escape>Cancels the previous selection action.
<Control-slash>Selects everything in the listbox.
<Control-backslash>Clears the selection.

Multiple Select Mode

In multiple selection mode you can select more than one item, but you can add or remove only one item at a time. Dragging the mouse does not sweep out a selection. If you click on a selected item it is deselected. Table 32-7 specifies the complete set of bindings for multiple selection mode.

Table 32-7. Bindings for multiple selection mode.
<Button-1>Selects the item under the mouse.
<ButtonRelease-1>Activates the item under the mouse.
<Key-Up> <Key-Down>Moves the active item up (down) one line, and starts a new selection with this item as the anchor point.
<Shift-Up> <Shift-Down>Moves the active element up (down).
<Control-Home>Activates and selects the first element of the listbox.
<Control-Shift-Home>Activates the first element of the listbox.
<Control-End>Activates and selects the last element of the listbox.
<Control-Shift-End>Activates the last element of the listbox.
<space> <Select>Selects the active element.
<Control-slash>Selects everything in the listbox.
<Control-backslash>Clears the selection.

Scroll Bindings

There are a number of bindings that scroll the display of the listbox. In addition to the standard middle-drag scrolling, there are some additional key bindings for scrolling. Table 32-8 summarizes the the scroll-related bindings:

Table 32-8. Listbox scroll bindings.
<Button-2>Marks the start of a scroll operation.
<B2-Motion>Scrolls vertically and horizontally.
<Left> <Right>Scrolls horizontally by one character.
<Control-Left> <Control-Right> <Control-Prior> <Control-Next>Scrolls horizontally by one screen width.
<Prior> <Next>Scrolls vertically by one screen height.
<Home> <End>Scrolls to left and right edges of the screen, respectively.


       
    Top
     



    Practical Programming in Tcl and Tk
    Practical Programming in Tcl and Tk (4th Edition)
    ISBN: 0130385603
    EAN: 2147483647
    Year: 1999
    Pages: 478

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net