/usr/lib/grass64/bwidget/utils.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 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | # ------------------------------------------------------------------------------
# utils.tcl
# This file is part of Unifix BWidget Toolkit
# $Id: utils.tcl 10192 2002-01-24 19:25:32Z radim $
# ------------------------------------------------------------------------------
# Index of commands:
# - GlobalVar::exists
# - GlobalVar::setvarvar
# - GlobalVar::getvarvar
# - BWidget::assert
# - BWidget::clonename
# - BWidget::get3dcolor
# - BWidget::XLFDfont
# - BWidget::place
# - BWidget::grab
# - BWidget::focus
# ------------------------------------------------------------------------------
namespace eval GlobalVar {
proc use {} {}
}
namespace eval BWidget {
variable _top
variable _gstack {}
variable _fstack {}
proc use {} {}
}
# ------------------------------------------------------------------------------
# Command GlobalVar::exists
# ------------------------------------------------------------------------------
proc GlobalVar::exists { varName } {
return [uplevel \#0 [list info exists $varName]]
}
# ------------------------------------------------------------------------------
# Command GlobalVar::setvar
# ------------------------------------------------------------------------------
proc GlobalVar::setvar { varName value } {
return [uplevel \#0 [list set $varName $value]]
}
# ------------------------------------------------------------------------------
# Command GlobalVar::getvar
# ------------------------------------------------------------------------------
proc GlobalVar::getvar { varName } {
return [uplevel \#0 [list set $varName]]
}
# ------------------------------------------------------------------------------
# Command GlobalVar::tracevar
# ------------------------------------------------------------------------------
proc GlobalVar::tracevar { cmd varName args } {
return [uplevel \#0 trace $cmd [list $varName] $args]
}
# ------------------------------------------------------------------------------
# Command BWidget::lreorder
# ------------------------------------------------------------------------------
proc BWidget::lreorder { list neworder } {
set pos 0
set newlist {}
foreach e $neworder {
if { [lsearch -exact $list $e] != -1 } {
lappend newlist $e
set tabelt($e) 1
}
}
set len [llength $newlist]
if { !$len } {
return $list
}
if { $len == [llength $list] } {
return $newlist
}
set pos 0
foreach e $list {
if { ![info exists tabelt($e)] } {
set newlist [linsert $newlist $pos $e]
}
incr pos
}
return $newlist
}
# ------------------------------------------------------------------------------
# Command BWidget::assert
# ------------------------------------------------------------------------------
proc BWidget::assert { exp {msg ""}} {
set res [uplevel expr $exp]
if { !$res} {
if { $msg == "" } {
return -code error "Assertion failed: {$exp}"
} else {
return -code error $msg
}
}
}
# ------------------------------------------------------------------------------
# Command BWidget::clonename
# ------------------------------------------------------------------------------
proc BWidget::clonename { menu } {
set path ""
set menupath ""
set found 0
foreach widget [lrange [split $menu "."] 1 end] {
if { $found || [winfo class "$path.$widget"] == "Menu" } {
set found 1
append menupath "#" $widget
append path "." $menupath
} else {
append menupath "#" $widget
append path "." $widget
}
}
return $path
}
# ------------------------------------------------------------------------------
# Command BWidget::getname
# ------------------------------------------------------------------------------
proc BWidget::getname { name } {
if { [string length $name] } {
set text [option get . "${name}Name" ""]
if { [string length $text] } {
return [parsetext $text]
}
}
return {}
}
# ------------------------------------------------------------------------------
# Command BWidget::parsetext
# ------------------------------------------------------------------------------
proc BWidget::parsetext { text } {
set result ""
set index -1
set start 0
while { [string length $text] } {
set idx [string first "&" $text]
if { $idx == -1 } {
append result $text
set text ""
} else {
set char [string index $text [expr {$idx+1}]]
if { $char == "&" } {
append result [string range $text 0 $idx]
set text [string range $text [expr {$idx+2}] end]
set start [expr {$start+$idx+1}]
} else {
append result [string range $text 0 [expr {$idx-1}]]
set text [string range $text [expr {$idx+1}] end]
incr start $idx
set index $start
}
}
}
return [list $result $index]
}
# ------------------------------------------------------------------------------
# Command BWidget::get3dcolor
# ------------------------------------------------------------------------------
proc BWidget::get3dcolor { path bgcolor } {
foreach val [winfo rgb $path $bgcolor] {
lappend dark [expr 60*$val/100]
set tmp1 [expr 14*$val/10]
if { $tmp1 > 65535 } {
set tmp1 65535
}
set tmp2 [expr (65535+$val)/2]
lappend light [expr ($tmp1 > $tmp2) ? $tmp1:$tmp2]
}
return [list [eval format "#%04x%04x%04x" $dark] [eval format "#%04x%04x%04x" $light]]
}
# ------------------------------------------------------------------------------
# Command BWidget::XLFDfont
# ------------------------------------------------------------------------------
proc BWidget::XLFDfont { cmd args } {
switch -- $cmd {
create {
set font "-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
}
configure {
set font [lindex $args 0]
set args [lrange $args 1 end]
}
default {
return -code error "XLFDfont: commande incorrecte: $cmd"
}
}
set lfont [split $font "-"]
if { [llength $lfont] != 15 } {
return -code error "XLFDfont: description XLFD incorrecte: $font"
}
foreach {option value} $args {
switch -- $option {
-foundry { set index 1 }
-family { set index 2 }
-weight { set index 3 }
-slant { set index 4 }
-size { set index 7 }
default { return -code error "XLFDfont: option incorrecte: $option" }
}
set lfont [lreplace $lfont $index $index $value]
}
return [join $lfont "-"]
}
# ------------------------------------------------------------------------------
# Command BWidget::place
# ------------------------------------------------------------------------------
proc BWidget::place { path w h args } {
variable _top
update idletasks
set reqw [winfo reqwidth $path]
set reqh [winfo reqheight $path]
if { $w == 0 } {set w $reqw}
if { $h == 0 } {set h $reqh}
set arglen [llength $args]
if { $arglen > 3 } {
return -code error "BWidget::place: bad number of argument"
}
if { $arglen > 0 } {
set where [lindex $args 0]
set idx [lsearch {"at" "center" "left" "right" "above" "below"} $where]
if { $idx == -1 } {
return -code error "BWidget::place: incorrect position \"$where\""
}
if { $idx == 0 } {
set err [catch {
set x [expr {int([lindex $args 1])}]
set y [expr {int([lindex $args 2])}]
}]
if { $err } {
return -code error "BWidget::place: incorrect position"
}
if { $x >= 0 } {
set x "+$x"
}
if { $y >= 0 } {
set y "+$y"
}
} else {
if { $arglen == 2 } {
set widget [lindex $args 1]
if { ![winfo exists $widget] } {
return -code error "BWidget::place: \"$widget\" does not exist"
}
}
set sw [winfo screenwidth $path]
set sh [winfo screenheight $path]
if { $idx == 1 } {
if { $arglen == 2 } {
# center to widget
set x0 [expr [winfo rootx $widget] + ([winfo width $widget] - $w)/2]
set y0 [expr [winfo rooty $widget] + ([winfo height $widget] - $h)/2]
} else {
# center to screen
set x0 [expr ([winfo screenwidth $path] - $w)/2 - [winfo vrootx $path]]
set y0 [expr ([winfo screenheight $path] - $h)/2 - [winfo vrooty $path]]
}
set x "+$x0"
set y "+$y0"
if { $x0+$w > $sw } {set x "-0"; set x0 [expr {$sw-$w}]}
if { $x0 < 0 } {set x "+0"}
if { $y0+$h > $sh } {set y "-0"; set y0 [expr {$sh-$h}]}
if { $y0 < 0 } {set y "+0"}
} else {
set x0 [winfo rootx $widget]
set y0 [winfo rooty $widget]
set x1 [expr {$x0 + [winfo width $widget]}]
set y1 [expr {$y0 + [winfo height $widget]}]
if { $idx == 2 || $idx == 3 } {
set y "+$y0"
if { $y0+$h > $sh } {set y "-0"; set y0 [expr {$sh-$h}]}
if { $y0 < 0 } {set y "+0"}
if { $idx == 2 } {
# try left, then right if out, then 0 if out
if { $x0 >= $w } {
set x [expr {$x0-$sw}]
} elseif { $x1+$w <= $sw } {
set x "+$x1"
} else {
set x "+0"
}
} else {
# try right, then left if out, then 0 if out
if { $x1+$w <= $sw } {
set x "+$x1"
} elseif { $x0 >= $w } {
set x [expr {$x0-$sw}]
} else {
set x "-0"
}
}
} else {
set x "+$x0"
if { $x0+$w > $sw } {set x "-0"; set x0 [expr {$sw-$w}]}
if { $x0 < 0 } {set x "+0"}
if { $idx == 4 } {
# try top, then bottom, then 0
if { $h <= $y0 } {
set y [expr {$y0-$sh}]
} elseif { $y1+$h <= $sh } {
set y "+$y1"
} else {
set y "+0"
}
} else {
# try bottom, then top, then 0
if { $y1+$h <= $sh } {
set y "+$y1"
} elseif { $h <= $y0 } {
set y [expr {$y0-$sh}]
} else {
set y "-0"
}
}
}
}
}
wm geometry $path "${w}x${h}${x}${y}"
} else {
wm geometry $path "${w}x${h}"
}
update idletasks
}
# ------------------------------------------------------------------------------
# Command BWidget::grab
# ------------------------------------------------------------------------------
proc BWidget::grab { option path } {
variable _gstack
if { $option == "release" } {
catch {::grab release $path}
while { [llength $_gstack] } {
set grinfo [lindex $_gstack end]
set _gstack [lreplace $_gstack end end]
foreach {oldg mode} $grinfo {
if { [string compare $oldg $path] && [winfo exists $oldg] } {
if { $mode == "global" } {
catch {::grab -global $oldg}
} else {
catch {::grab $oldg}
}
return
}
}
}
} else {
set oldg [::grab current]
if { $oldg != "" } {
lappend _gstack [list $oldg [::grab status $oldg]]
}
if { $option == "global" } {
::grab -global $path
} else {
::grab $path
}
}
}
# ------------------------------------------------------------------------------
# Command BWidget::focus
# ------------------------------------------------------------------------------
proc BWidget::focus { option path } {
variable _fstack
if { $option == "release" } {
while { [llength $_fstack] } {
set oldf [lindex $_fstack end]
set _fstack [lreplace $_fstack end end]
if { [string compare $oldf $path] && [winfo exists $oldf] } {
catch {::focus -force $oldf}
return
}
}
} elseif { $option == "set" } {
lappend _fstack [::focus]
::focus -force $path
}
}
|