File: scrolist.tcl

package info (click to toggle)
moomps 4.6-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,444 kB
  • ctags: 2,307
  • sloc: tcl: 34,882; sh: 167; makefile: 91
file content (59 lines) | stat: -rw-r--r-- 2,654 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# $Id: scrolist.tcl,v 1.25 2002/05/30 17:11:45 jfontain Exp $


class scrollList {}

proc scrollList::scrollList {this parentPath args} composite {
    [new frame $parentPath -highlightthickness $widget::option(button,highlightthickness)] $args
} {
    composite::manage $this [new listbox $widget::($this,path) -highlightthickness 0] listbox
    set listboxPath $composite::($this,listbox,path)

    bind $widget::($this,path) <FocusIn> "focus $listboxPath"          ;# when focus is set on base Tk widget, pass it on to listbox
    bind $listboxPath <Button2-Motion> break                                                           ;# disable button 2 scrolling
    pack $listboxPath -fill both -expand 1

    composite::manage $this\
        [new scrollbar $widget::($this,path) -command "$listboxPath yview" -highlightthickness 0 -takefocus 0] scrollbar
    widget::configure $composite::($this,listbox) -yscrollcommand "scrollList::updateScrollbar $this"

    composite::complete $this
}

proc scrollList::~scrollList {this} {}

proc scrollList::options {this} {
    return [list\
        [list -font $widget::option(listbox,font) $widget::option(listbox,font)]\
        [list -height $widget::option(listbox,height) $widget::option(listbox,height)]\
        [list -list {} {}]\
        [list -selectmode $widget::option(listbox,selectmode) $widget::option(listbox,selectmode)]\
        [list -width $widget::option(listbox,width) $widget::option(listbox,width)]\
    ]
}

proc scrollList::set-list {this value} {
    set listboxPath $composite::($this,listbox,path)
    $listboxPath delete 0 end
    eval $listboxPath insert 0 $value
    $listboxPath activate 0
}

foreach option {-font -height -selectmode -width} {
    proc scrollList::set$option {this value} "\$composite::(\$this,listbox,path) configure $option \$value"
}

# wrap all relevant listbox commands
foreach command {activate bbox curselection delete get index insert nearest scan see selection size} {
    proc scrollList::$command {this args} "eval \$composite::(\$this,listbox,path) $command \$args"
}

proc scrollList::updateScrollbar {this first last} {
    if {($last-$first)<1} {
        $composite::($this,scrollbar,path) set $first $last
        # pack scrollbar to the right of listbox and before it in the packing order so that it is visible for small ensemble widths
        pack $composite::($this,scrollbar,path) -fill y -before $composite::($this,listbox,path) -side right
    } else {                                                        ;# there is no need for a scrollbar since whole list can be seen
        pack forget $composite::($this,scrollbar,path)
    }
}