/usr/lib/grass64/bwidget/button.tcl is in grass-gui 6.4.3-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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | # ------------------------------------------------------------------------------
# button.tcl
# This file is part of Unifix BWidget Toolkit
# ------------------------------------------------------------------------------
# Index of commands:
# Public commands
# - Button::create
# - Button::configure
# - Button::cget
# - Button::invoke
# Private commands (event bindings)
# - Button::_destroy
# - Button::_enter
# - Button::_leave
# - Button::_press
# - Button::_release
# - Button::_repeat
# ------------------------------------------------------------------------------
namespace eval Button {
Widget::tkinclude Button button :cmd \
remove {-command -relief -text -textvariable -underline}
Widget::declare Button {
{-name String "" 0}
{-text String "" 0}
{-textvariable String "" 0}
{-underline Int -1 0 {=-1}}
{-armcommand String "" 0}
{-disarmcommand String "" 0}
{-command String "" 0}
{-repeatdelay Int 0 0 {=0 ""}}
{-repeatinterval Int 0 0 {=0 ""}}
{-relief Enum raised 0 {raised sunken flat ridge solid groove link}}
}
DynamicHelp::include Button balloon
Widget::syncoptions Button "" :cmd {-text {} -underline {}}
variable _current ""
variable _pressed ""
bind BwButton <Enter> {Button::_enter %W}
bind BwButton <Leave> {Button::_leave %W}
bind BwButton <ButtonPress-1> {Button::_press %W}
bind BwButton <ButtonRelease-1> {Button::_release %W}
bind BwButton <Key-space> {Button::invoke %W; break}
bind BwButton <Return> {Button::invoke %W; break}
bind BwButton <Destroy> {Widget::destroy %W; rename %W {}}
proc ::Button { path args } { return [eval Button::create $path $args] }
proc use {} {}
}
# ------------------------------------------------------------------------------
# Command Button::create
# ------------------------------------------------------------------------------
proc Button::create { path args } {
Widget::init Button $path $args
set relief [Widget::getoption $path -relief]
if { ![string compare $relief "link"] } {
set relief "flat"
}
set var [Widget::getoption $path -textvariable]
if { ![string length $var] } {
set desc [BWidget::getname [Widget::getoption $path -name]]
if { [llength $desc] } {
set text [lindex $desc 0]
set under [lindex $desc 1]
Widget::setoption $path -text $text
Widget::setoption $path -underline $under
} else {
set text [Widget::getoption $path -text]
set under [Widget::getoption $path -underline]
}
} else {
set under -1
set text ""
Widget::setoption $path -underline $under
}
eval button $path [Widget::subcget $path :cmd] \
[list -relief $relief -text $text -underline $under -textvariable $var]
bindtags $path [list $path BwButton [winfo toplevel $path] all]
set accel [string tolower [string index $text $under]]
if { $accel != "" } {
bind [winfo toplevel $path] <Alt-$accel> "Button::invoke $path"
}
DynamicHelp::sethelp $path $path 1
rename $path ::$path:cmd
proc ::$path { cmd args } "return \[eval Button::\$cmd $path \$args\]"
return $path
}
# ------------------------------------------------------------------------------
# Command Button::configure
# ------------------------------------------------------------------------------
proc Button::configure { path args } {
set oldunder [$path:cmd cget -underline]
if { $oldunder != -1 } {
set oldaccel [string tolower [string index [$path:cmd cget -text] $oldunder]]
} else {
set oldaccel ""
}
set res [Widget::configure $path $args]
set rc [Widget::hasChanged $path -relief relief]
set sc [Widget::hasChanged $path -state state]
if { $rc || $sc } {
if { ![string compare $relief "link"] } {
if { ![string compare $state "active"] } {
set relief "raised"
} else {
set relief "flat"
}
}
$path:cmd configure -relief $relief -state $state
}
set cv [Widget::hasChanged $path -textvariable var]
set cn [Widget::hasChanged $path -name name]
set ct [Widget::hasChanged $path -text text]
set cu [Widget::hasChanged $path -underline under]
if { $cv || $cn || $ct || $cu } {
if { ![string length $var] } {
set desc [BWidget::getname $name]
if { [llength $desc] } {
set text [lindex $desc 0]
set under [lindex $desc 1]
}
} else {
set under -1
set text ""
}
set top [winfo toplevel $path]
bind $top <Alt-$oldaccel> {}
set accel [string tolower [string index $text $under]]
if { $accel != "" } {
bind $top <Alt-$accel> "Button::invoke $path"
}
$path:cmd configure -text $text -underline $under -textvariable $var
}
DynamicHelp::sethelp $path $path
return $res
}
# ------------------------------------------------------------------------------
# Command Button::cget
# ------------------------------------------------------------------------------
proc Button::cget { path option } {
return [Widget::cget $path $option]
}
# ------------------------------------------------------------------------------
# Command Button::invoke
# ------------------------------------------------------------------------------
proc Button::invoke { path } {
if { [string compare [$path:cmd cget -state] "disabled"] } {
$path:cmd configure -state active -relief sunken
update idletasks
if { [set cmd [Widget::getoption $path -armcommand]] != "" } {
uplevel \#0 $cmd
}
after 100
set relief [Widget::getoption $path -relief]
if { ![string compare $relief "link"] } {
set relief flat
}
$path:cmd configure \
-state [Widget::getoption $path -state] \
-relief $relief
if { [set cmd [Widget::getoption $path -disarmcommand]] != "" } {
uplevel \#0 $cmd
}
if { [set cmd [Widget::getoption $path -command]] != "" } {
uplevel \#0 $cmd
}
}
}
# ------------------------------------------------------------------------------
# Command Button::_enter
# ------------------------------------------------------------------------------
proc Button::_enter { path } {
variable _current
variable _pressed
set _current $path
if { [string compare [$path:cmd cget -state] "disabled"] } {
$path:cmd configure -state active
if { $_pressed == $path } {
$path:cmd configure -relief sunken
} elseif { ![string compare [Widget::getoption $path -relief] "link"] } {
$path:cmd configure -relief raised
}
}
}
# ------------------------------------------------------------------------------
# Command Button::_leave
# ------------------------------------------------------------------------------
proc Button::_leave { path } {
variable _current
variable _pressed
set _current ""
if { [string compare [$path:cmd cget -state] "disabled"] } {
$path:cmd configure -state [Widget::getoption $path -state]
set relief [Widget::getoption $path -relief]
if { $_pressed == $path } {
if { ![string compare $relief "link"] } {
set relief raised
}
$path:cmd configure -relief $relief
} elseif { ![string compare $relief "link"] } {
$path:cmd configure -relief flat
}
}
}
# ------------------------------------------------------------------------------
# Command Button::_press
# ------------------------------------------------------------------------------
proc Button::_press { path } {
variable _pressed
if { [string compare [$path:cmd cget -state] "disabled"] } {
set _pressed $path
$path:cmd configure -relief sunken
if { [set cmd [Widget::getoption $path -armcommand]] != "" } {
uplevel \#0 $cmd
if { [set delay [Widget::getoption $path -repeatdelay]] > 0 ||
[set delay [Widget::getoption $path -repeatinterval]] > 0 } {
after $delay "Button::_repeat $path"
}
}
}
}
# ------------------------------------------------------------------------------
# Command Button::_release
# ------------------------------------------------------------------------------
proc Button::_release { path } {
variable _current
variable _pressed
if { $_pressed == $path } {
set _pressed ""
set relief [Widget::getoption $path -relief]
if { ![string compare $relief "link"] } {
set relief raised
}
$path:cmd configure -relief $relief
if { [set cmd [Widget::getoption $path -disarmcommand]] != "" } {
uplevel \#0 $cmd
}
if { $_current == $path &&
[string compare [$path:cmd cget -state] "disabled"] &&
[set cmd [Widget::getoption $path -command]] != "" } {
uplevel \#0 $cmd
}
}
}
# ------------------------------------------------------------------------------
# Command Button::_repeat
# ------------------------------------------------------------------------------
proc Button::_repeat { path } {
variable _current
variable _pressed
if { $_current == $path && $_pressed == $path &&
[string compare [$path:cmd cget -state] "disabled"] &&
[set cmd [Widget::getoption $path -armcommand]] != "" } {
uplevel \#0 $cmd
}
if { $_pressed == $path &&
([set delay [Widget::getoption $path -repeatinterval]] > 0 ||
[set delay [Widget::getoption $path -repeatdelay]] > 0) } {
after $delay "Button::_repeat $path"
}
}
|