/usr/share/astk/BWidget-1.7.0/dynhelp.tcl is in code-aster-gui 1.8.4-5.
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 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | # ----------------------------------------------------------------------------
# dynhelp.tcl
# This file is part of Unifix BWidget Toolkit
# $Id: dynhelp.tcl 606 2004-04-05 07:06:06Z mcourtoi $
# ----------------------------------------------------------------------------
# Index of commands:
# - DynamicHelp::configure
# - DynamicHelp::include
# - DynamicHelp::sethelp
# - DynamicHelp::register
# - DynamicHelp::_motion_balloon
# - DynamicHelp::_motion_info
# - DynamicHelp::_leave_info
# - DynamicHelp::_menu_info
# - DynamicHelp::_show_help
# - DynamicHelp::_init
# ----------------------------------------------------------------------------
# JDC: allow variable and ballon help at the same timees
namespace eval DynamicHelp {
Widget::define DynamicHelp dynhelp -classonly
Widget::declare DynamicHelp {
{-foreground TkResource black 0 label}
{-topbackground TkResource black 0 {label -foreground}}
{-background TkResource "#FFFFC0" 0 label}
{-borderwidth TkResource 1 0 label}
{-justify TkResource left 0 label}
{-font TkResource "helvetica 8" 0 label}
{-delay Int 600 0 "%d >= 100 & %d <= 2000"}
{-state Enum "normal" 0 {normal disabled}}
{-padx TkResource 1 0 label}
{-pady TkResource 1 0 label}
{-bd Synonym -borderwidth}
{-bg Synonym -background}
{-fg Synonym -foreground}
{-topbg Synonym -topbackground}
}
proc use {} {}
variable _registered
variable _canvases
variable _top ".help_shell"
variable _id ""
variable _delay 600
variable _current_balloon ""
variable _current_variable ""
variable _saved
Widget::init DynamicHelp $_top {}
bind BwHelpBalloon <Enter> {DynamicHelp::_motion_balloon enter %W %X %Y}
bind BwHelpBalloon <Motion> {DynamicHelp::_motion_balloon motion %W %X %Y}
bind BwHelpBalloon <Leave> {DynamicHelp::_motion_balloon leave %W %X %Y}
bind BwHelpBalloon <Button> {DynamicHelp::_motion_balloon button %W %X %Y}
bind BwHelpBalloon <Destroy> {DynamicHelp::_unset_help %W}
bind BwHelpVariable <Enter> {DynamicHelp::_motion_info %W}
bind BwHelpVariable <Motion> {DynamicHelp::_motion_info %W}
bind BwHelpVariable <Leave> {DynamicHelp::_leave_info %W}
bind BwHelpVariable <Destroy> {DynamicHelp::_unset_help %W}
bind BwHelpMenu <<MenuSelect>> {DynamicHelp::_menu_info select %W}
bind BwHelpMenu <Unmap> {DynamicHelp::_menu_info unmap %W}
bind BwHelpMenu <Destroy> {DynamicHelp::_unset_help %W}
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::configure
# ----------------------------------------------------------------------------
proc DynamicHelp::configure { args } {
variable _top
variable _delay
set res [Widget::configure $_top $args]
if { [Widget::hasChanged $_top -delay val] } {
set _delay $val
}
return $res
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::include
# ----------------------------------------------------------------------------
proc DynamicHelp::include { class type } {
set helpoptions [list \
[list -helptext String "" 0] \
[list -helpvar String "" 0] \
[list -helptype Enum $type 0 [list balloon variable]] \
]
Widget::declare $class $helpoptions
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::sethelp
# ----------------------------------------------------------------------------
proc DynamicHelp::sethelp { path subpath {force 0}} {
foreach {ctype ctext cvar} [Widget::hasChangedX $path \
-helptype -helptext -helpvar] break
if { $force || $ctype || $ctext || $cvar } {
set htype [Widget::cget $path -helptype]
switch $htype {
balloon {
return [register $subpath balloon \
[Widget::cget $path -helptext]]
}
variable {
return [register $subpath variable \
[Widget::cget $path -helpvar] \
[Widget::cget $path -helptext]]
}
}
return [register $subpath $htype]
}
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::register
#
# DynamicHelp::register path balloon ?itemOrTag? text
# DynamicHelp::register path variable ?itemOrTag? text varName
# DynamicHelp::register path menu varName
# DynamicHelp::register path menuentry index text
# ----------------------------------------------------------------------------
proc DynamicHelp::register { path type args } {
variable _registered
set len [llength $args]
if {$type == "balloon" && $len > 1} { set type canvasBalloon }
if {$type == "variable" && $len > 2} { set type canvasVariable }
if { ![winfo exists $path] } {
_unset_help $path
return 0
}
switch $type {
balloon {
set text [lindex $args 0]
if {$text == ""} {
if {[info exists _registered($path,balloon)]} {
unset _registered($path,balloon)
}
return 0
}
_add_balloon $path $text
}
canvasBalloon {
set tagOrItem [lindex $args 0]
set text [lindex $args 1]
if {$text == ""} {
if {[info exists _registered($path,$tagOrItem,balloon)]} {
unset _registered($path,$tagOrItem,balloon)
}
return 0
}
_add_canvas_balloon $path $text $tagOrItem
}
variable {
set var [lindex $args 0]
set text [lindex $args 1]
if {$text == "" || $var == ""} {
if {[info exists _registered($path,variable)]} {
unset _registered($path,variable)
}
return 0
}
_add_variable $path $text $var
}
canvasVariable {
set tagOrItem [lindex $args 0]
set var [lindex $args 1]
set text [lindex $args 2]
if {$text == "" || $var == ""} {
if {[info exists _registered($path,$tagOrItem,variable)]} {
unset _registered($path,$tagOrItem,variable)
}
return 0
}
_add_canvas_variable $path $text $var $tagOrItem
}
menu {
set var [lindex $args 0]
if {$var == ""} {
set cpath [BWidget::clonename $path]
if {[winfo exists $cpath]} { set path $cpath }
if {[info exists _registered($path)]} {
unset _registered($path)
}
return 0
}
_add_menu $path $var
}
menuentry {
set cpath [BWidget::clonename $path]
if { [winfo exists $cpath] } { set path $cpath }
if {![info exists _registered($path)]} { return 0 }
set text [lindex $args 1]
set index [lindex $args 0]
if {$text == "" || $index == ""} {
set idx [lsearch $_registed($path) [list $index *]]
set _registered($path) [lreplace $_registered($path) $idx $idx]
return 0
}
_add_menuentry $path $text $index
}
default {
_unset_help $path
return 0
}
}
return 1
}
proc DynamicHelp::add { path args } {
variable _registered
array set data {
-type balloon
-text ""
-item ""
-index -1
-command ""
-variable ""
}
if {[winfo exists $path] && [winfo class $path] == "Menu"} {
set data(-type) menu
}
array set data $args
set item $path
switch -- $data(-type) {
"balloon" {
if {$data(-item) != ""} {
_add_canvas_balloon $path $data(-text) $data(-item)
set item $path,$data(-item)
} else {
_add_balloon $path $data(-text)
}
if {$data(-variable) != ""} {
set _registered($item,balloonVar) $data(-variable)
}
}
"variable" {
set var $data(-variable)
if {$data(-item) != ""} {
_add_canvas_variable $path $data(-text) $var $data(-item)
set item $path,$data(-item)
} else {
_add_variable $path $data(-text) $var
}
}
"menu" {
if {$data(-index) != -1} {
set cpath [BWidget::clonename $path]
if { [winfo exists $cpath] } { set path $cpath }
if {![info exists _registered($path)]} { return 0 }
_add_menuentry $path $data(-text) $data(-index)
set item $path,$data(-index)
} else {
_add_menu $path $data(-variable)
}
}
default {
return 0
}
}
if {$data(-command) != ""} {set _registered($item,command) $data(-command)}
return 1
}
proc DynamicHelp::delete { path } {
_unset_help $path
}
proc DynamicHelp::_add_bind_tag { path tag } {
set evt [bindtags $path]
set idx [lsearch $evt $tag]
set evt [lreplace $evt $idx $idx]
lappend evt $tag
bindtags $path $evt
}
proc DynamicHelp::_add_balloon { path text } {
variable _registered
set _registered($path,balloon) $text
_add_bind_tag $path BwHelpBalloon
}
proc DynamicHelp::_add_canvas_balloon { path text tagOrItem } {
variable _canvases
variable _registered
set _registered($path,$tagOrItem,balloon) $text
if {![info exists _canvases($path,balloon)]} {
## This canvas doesn't have the bindings yet.
_add_bind_tag $path BwHelpBalloon
$path bind BwHelpBalloon <Enter> \
{DynamicHelp::_motion_balloon enter %W %X %Y 1}
$path bind BwHelpBalloon <Motion> \
{DynamicHelp::_motion_balloon motion %W %X %Y 1}
$path bind BwHelpBalloon <Leave> \
{DynamicHelp::_motion_balloon leave %W %X %Y 1}
$path bind BwHelpBalloon <Button> \
{DynamicHelp::_motion_balloon button %W %X %Y 1}
set _canvases($path,balloon) 1
}
$path addtag BwHelpBalloon withtag $tagOrItem
}
proc DynamicHelp::_add_variable { path text varName } {
variable _registered
set _registered($path,variable) [list $varName $text]
_add_bind_tag $path BwHelpVariable
}
proc DynamicHelp::_add_canvas_variable { path text varName tagOrItem } {
variable _canvases
variable _registered
set _registered($path,$tagOrItem,variable) [list $varName $text]
if {![info exists _canvases($path,variable)]} {
## This canvas doesn't have the bindings yet.
_add_bind_tag $path BwHelpVariable
$path bind BwHelpVariable <Enter> \
{DynamicHelp::_motion_info %W 1}
$path bind BwHelpVariable <Motion> \
{DynamicHelp::_motion_info %W 1}
$path bind BwHelpVariable <Leave> \
{DynamicHelp::_leave_info %W 1}
set _canvases($path,variable) 1
}
$path addtag BwHelpVariable withtag $tagOrItem
}
proc DynamicHelp::_add_menu { path varName } {
variable _registered
set cpath [BWidget::clonename $path]
if { [winfo exists $cpath] } { set path $cpath }
set _registered($path) [list $varName]
_add_bind_tag $path BwHelpMenu
}
proc DynamicHelp::_add_menuentry { path text index } {
variable _registered
set idx [lsearch $_registered($path) [list $index *]]
set list [list $index $text]
if { $idx == -1 } {
lappend _registered($path) $list
} else {
set _registered($path) \
[lreplace $_registered($path) $idx $idx $list]
}
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::_motion_balloon
# ----------------------------------------------------------------------------
proc DynamicHelp::_motion_balloon { type path x y {isCanvasItem 0} } {
variable _top
variable _id
variable _delay
variable _current_balloon
set w $path
if {$isCanvasItem} { set path [_get_canvas_path $path balloon] }
if { $_current_balloon != $path && $type == "enter" } {
set _current_balloon $path
set type "motion"
destroy $_top
}
if { $_current_balloon == $path } {
if { $_id != "" } {
after cancel $_id
set _id ""
}
if { $type == "motion" } {
if { ![winfo exists $_top] } {
set cmd [list DynamicHelp::_show_help $path $w $x $y]
set _id [after $_delay $cmd]
}
} else {
destroy $_top
set _current_balloon ""
}
}
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::_motion_info
# ----------------------------------------------------------------------------
proc DynamicHelp::_motion_info { path {isCanvasItem 0} } {
variable _saved
variable _registered
variable _current_variable
if {$isCanvasItem} { set path [_get_canvas_path $path variable] }
if { $_current_variable != $path
&& [info exists _registered($path,variable)] } {
set varName [lindex $_registered($path,variable) 0]
if {![info exists _saved]} { set _saved [GlobalVar::getvar $varName] }
set string [lindex $_registered($path,variable) 1]
if {[info exists _registered($path,command)]} {
set string [eval $_registered($path,command)]
}
GlobalVar::setvar $varName $string
set _current_variable $path
}
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::_leave_info
# ----------------------------------------------------------------------------
proc DynamicHelp::_leave_info { path {isCanvasItem 0} } {
variable _saved
variable _registered
variable _current_variable
if {$isCanvasItem} { set path [_get_canvas_path $path variable] }
if { [info exists _registered($path,variable)] } {
set varName [lindex $_registered($path,variable) 0]
GlobalVar::setvar $varName $_saved
}
unset _saved
set _current_variable ""
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::_menu_info
# Version of R1v1 restored, due to lack of [winfo ismapped] and <Unmap>
# under windows for menu.
# ----------------------------------------------------------------------------
proc DynamicHelp::_menu_info { event path } {
variable _registered
if { [info exists _registered($path)] } {
set index [$path index active]
set varName [lindex $_registered($path) 0]
if { ![string equal $index "none"] &&
[set idx [lsearch $_registered($path) [list $index *]]] != -1 } {
set string [lindex [lindex $_registered($path) $idx] 1]
if {[info exists _registered($path,$index,command)]} {
set string [eval $_registered($path,$index,command)]
}
GlobalVar::setvar $varName $string
} else {
GlobalVar::setvar $varName ""
}
}
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::_show_help
# ----------------------------------------------------------------------------
proc DynamicHelp::_show_help { path w x y } {
variable _top
variable _registered
variable _id
variable _delay
if { [Widget::getoption $_top -state] == "disabled" } { return }
if { [info exists _registered($path,balloon)] } {
destroy $_top
set string $_registered($path,balloon)
if {[info exists _registered($path,balloonVar)]} {
upvar #0 $_registered($path,balloonVar) var
if {[info exists var]} { set string $var }
}
if {[info exists _registered($path,command)]} {
set string [eval $_registered($path,command)]
}
if {$string == ""} { return }
toplevel $_top -relief flat \
-bg [Widget::getoption $_top -topbackground] \
-bd [Widget::getoption $_top -borderwidth] \
-screen [winfo screen $w]
wm overrideredirect $_top 1
wm transient $_top
wm withdraw $_top
catch { wm attributes $_top -topmost 1 }
label $_top.label -text $string \
-relief flat -bd 0 -highlightthickness 0 \
-padx [Widget::getoption $_top -padx] \
-pady [Widget::getoption $_top -pady] \
-foreground [Widget::getoption $_top -foreground] \
-background [Widget::getoption $_top -background] \
-font [Widget::getoption $_top -font] \
-justify [Widget::getoption $_top -justify]
pack $_top.label -side left
update idletasks
if {![winfo exists $_top]} {return}
set scrwidth [winfo vrootwidth .]
set scrheight [winfo vrootheight .]
set width [winfo reqwidth $_top]
set height [winfo reqheight $_top]
incr y 12
incr x 8
if { $x+$width > $scrwidth } {
set x [expr {$scrwidth - $width}]
}
if { $y+$height > $scrheight } {
set y [expr {$y - 12 - $height}]
}
wm geometry $_top "+$x+$y"
update idletasks
if {![winfo exists $_top]} { return }
wm deiconify $_top
raise $_top
}
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::_unset_help
# ----------------------------------------------------------------------------
proc DynamicHelp::_unset_help { path } {
variable _canvases
variable _registered
if {[info exists _registered($path)]} { unset _registered($path) }
if {[winfo exists $path]} {
set cpath [BWidget::clonename $path]
if {[info exists _registered($cpath)]} { unset _registered($cpath) }
}
array unset _canvases $path,*
array unset _registered $path,*
}
# ----------------------------------------------------------------------------
# Command DynamicHelp::_get_canvas_path
# ----------------------------------------------------------------------------
proc DynamicHelp::_get_canvas_path { path type {item ""} } {
variable _registered
if {$item == ""} { set item [$path find withtag current] }
## Check the tags related to this item for the one that
## represents our text. If we have text specific to this
## item or for 'all' items, they override any other tags.
eval [list lappend tags $item all] [$path itemcget $item -tags]
foreach tag $tags {
set check $path,$tag
if {![info exists _registered($check,$type)]} { continue }
return $check
}
}
|