/usr/share/tcltk/tklib0.6/widget/scrollw.tcl is in tklib 0.6-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | # -*- tcl -*-
#
# scrollw.tcl -
#
# Scrolled widget
#
# RCS: @(#) $Id: scrollw.tcl,v 1.15 2010/06/01 18:06:52 hobbs Exp $
#
# Creation and Options - widget::scrolledwindow $path ...
# -scrollbar -default "both" ; vertical horizontal none
# -auto -default "both" ; vertical horizontal none
# -sides -default "se" ;
# -size -default 0 ; scrollbar -width (not recommended to change)
# -ipad -default {0 0} ; represents internal {x y} padding between
# ; scrollbar and given widget
# All other options to frame
#
# Methods
# $path getframe => $frame
# $path setwidget $widget => $widget
# All other methods to frame
#
# Bindings
# NONE
#
if 0 {
# Samples
package require widget::scrolledwindow
#set sw [widget::scrolledwindow .sw -scrollbar vertical]
#set text [text .sw.text -wrap word]
#$sw setwidget $text
#pack $sw -fill both -expand 1
set sw [widget::scrolledwindow .sw -borderwidth 1 -relief sunken]
set text [text $sw.text -borderwidth 0 -height 4 -width 20]
$sw setwidget $text
pack $sw -fill both -expand 1 -padx 4 -pady 4
set sw [widget::scrolledwindow .ssw -borderwidth 2 -relief solid]
set text [text $sw.text -borderwidth 0 -height 4 -width 20]
$sw setwidget $text
pack $sw -fill both -expand 1 -padx 4 -pady 4
}
###
package require widget
snit::widget widget::scrolledwindow {
hulltype ttk::frame
component hscroll
component vscroll
delegate option * to hull
delegate method * to hull
#delegate option -size to {hscroll vscroll} as -width
option -scrollbar -default "both" -configuremethod C-scrollbar \
-type [list snit::enum -values [list none horizontal vertical both]]
option -auto -default "both" -configuremethod C-scrollbar \
-type [list snit::enum -values [list none horizontal vertical both]]
option -sides -default "se" -configuremethod C-scrollbar \
-type [list snit::enum -values [list ne en nw wn se es sw ws]]
option -size -default 0 -configuremethod C-size \
-type [list snit::integer -min 0 -max 30]
option -ipad -default 0 -configuremethod C-ipad \
-type [list snit::listtype -type {snit::integer} -minlen 1 -maxlen 2]
typevariable scrollopts {none horizontal vertical both}
variable realized 0 ; # set when first Configure'd
variable hsb -array {
packed 0 present 0 auto 0 row 2 col 1 lastmin -1 lastmax -1 lock 0
sticky "ew" padx 0 pady 0
}
variable vsb -array {
packed 0 present 0 auto 0 row 1 col 2 lastmin -1 lastmax -1 lock 0
sticky "ns" padx 0 pady 0
}
variable pending {} ; # pending after id for scrollbar mgmt
constructor args {
if {[tk windowingsystem] ne "aqua"} {
# ttk scrollbars on aqua are a bit wonky still
install hscroll using ttk::scrollbar $win.hscroll \
-orient horizontal -takefocus 0
install vscroll using ttk::scrollbar $win.vscroll \
-orient vertical -takefocus 0
} else {
install hscroll using scrollbar $win.hscroll \
-orient horizontal -takefocus 0
install vscroll using scrollbar $win.vscroll \
-orient vertical -takefocus 0
# in case the scrollbar has been overridden ...
catch {$hscroll configure -highlightthickness 0}
catch {$vscroll configure -highlightthickness 0}
}
set hsb(bar) $hscroll
set vsb(bar) $vscroll
bind $win <Configure> [mymethod _realize $win]
grid columnconfigure $win 1 -weight 1
grid rowconfigure $win 1 -weight 1
set pending [after idle [mymethod _setdata]]
$self configurelist $args
}
destructor {
after cancel $pending
set pending {}
}
# Do we need this ??
method getframe {} { return $win }
variable setwidget {}
method setwidget {widget} {
if {$setwidget eq $widget} { return }
if {[winfo exists $setwidget]} {
grid remove $setwidget
# in case we only scroll in one direction
catch {$setwidget configure -xscrollcommand ""}
catch {$setwidget configure -yscrollcommand ""}
$hscroll configure -command {}
$vscroll configure -command {}
set setwidget {}
}
if {$pending ne {}} {
# ensure we have called most recent _setdata
after cancel $pending
$self _setdata
}
if {[winfo exists $widget]} {
set setwidget $widget
grid $widget -in $win -row 1 -column 1 -sticky news
# in case we only scroll in one direction
if {$hsb(present)} {
$widget configure -xscrollcommand [mymethod _set_scroll hsb]
$hscroll configure -command [list $widget xview]
}
if {$vsb(present)} {
$widget configure -yscrollcommand [mymethod _set_scroll vsb]
$vscroll configure -command [list $widget yview]
}
}
return $widget
}
method C-size {option value} {
set options($option) $value
$vscroll configure -width $value
$hscroll configure -width $value
}
method C-scrollbar {option value} {
set options($option) $value
after cancel $pending
set pending [after idle [mymethod _setdata]]
}
method C-ipad {option value} {
set options($option) $value
# double value to ensure a single int value covers pad x and y
foreach {padx pady} [concat $value $value] { break }
set vsb(padx) [list $padx 0] ; set vsb(pady) 0
set hsb(padx) 0 ; set vsb(pady) [list $pady 0]
if {$vsb(present) && $vsb(packed)} {
grid configure $vsb(bar) -padx $vsb(padx) -pady $vsb(pady)
}
if {$hsb(present) && $hsb(packed)} {
grid configure $hsb(bar) -padx $hsb(padx) -pady $hsb(pady)
}
}
method _set_scroll {varname vmin vmax} {
if {!$realized} { return }
# This is only called if the scrollbar is attached properly
upvar 0 $varname sb
if {$sb(auto)} {
if {!$sb(lock)} {
# One last check to avoid loops when not locked
if {$vmin == $sb(lastmin) && $vmax == $sb(lastmax)} {
return
}
set sb(lastmin) $vmin
set sb(lastmax) $vmax
}
if {$sb(packed) && $vmin == 0 && $vmax == 1} {
if {!$sb(lock)} {
set sb(packed) 0
grid remove $sb(bar)
}
} elseif {!$sb(packed) && ($vmin != 0 || $vmax != 1)} {
set sb(packed) 1
grid $sb(bar) -column $sb(col) -row $sb(row) \
-sticky $sb(sticky) -padx $sb(padx) -pady $sb(pady)
}
set sb(lock) 1
update idletasks
set sb(lock) 0
}
$sb(bar) set $vmin $vmax
}
method _setdata {} {
set pending {}
set bar [lsearch -exact $scrollopts $options(-scrollbar)]
set auto [lsearch -exact $scrollopts $options(-auto)]
set hsb(present) [expr {$bar & 1}] ; # idx 1 or 3
set hsb(auto) [expr {$auto & 1}] ; # idx 1 or 3
set hsb(row) [expr {[string match *n* $options(-sides)] ? 0 : 2}]
set hsb(col) 1
set hsb(sticky) "ew"
set vsb(present) [expr {$bar & 2}] ; # idx 2
set vsb(auto) [expr {$auto & 2}] ; # idx 2
set vsb(row) 1
set vsb(col) [expr {[string match *w* $options(-sides)] ? 0 : 2}]
set vsb(sticky) "ns"
if {$setwidget eq ""} {
grid remove $hsb(bar)
grid remove $vsb(bar)
set hsb(packed) 0
set vsb(packed) 0
return
}
foreach varname {hsb vsb} {
upvar 0 $varname sb
foreach {vmin vmax} [$sb(bar) get] { break }
set sb(packed) [expr {$sb(present) &&
(!$sb(auto) || ($vmin != 0 || $vmax != 1))}]
if {$sb(packed)} {
grid $sb(bar) -column $sb(col) -row $sb(row) \
-sticky $sb(sticky) -padx $sb(padx) -pady $sb(pady)
} else {
grid remove $sb(bar)
}
}
}
method _realize {w} {
if {$w eq $win} {
bind $win <Configure> {}
set realized 1
}
}
}
package provide widget::scrolledwindow 1.2.1
|