/usr/share/tcltk/bwidget1.9.12/dropsite.tcl is in bwidget 1.9.12-1.
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 | # ------------------------------------------------------------------------------
# dropsite.tcl
# This file is part of Unifix BWidget Toolkit
# $Id: dropsite.tcl,v 1.8 2009/06/30 16:17:37 oehhar Exp $
# ------------------------------------------------------------------------------
# Index of commands:
# - DropSite::include
# - DropSite::setdrop
# - DropSite::register
# - DropSite::setcursor
# - DropSite::setoperation
# - DropSite::_update_operation
# - DropSite::_compute_operation
# - DropSite::_draw_operation
# - DropSite::_init_drag
# - DropSite::_motion
# - DropSite::_release
# ----------------------------------------------------------------------------
namespace eval DropSite {
Widget::define DropSite dropsite -classonly
Widget::declare DropSite [list \
[list -dropovercmd String "" 0] \
[list -dropcmd String "" 0] \
[list -droptypes String "" 0] \
]
proc use {} {}
variable _top ".drag"
variable _opw ".drag.\#op"
variable _target ""
variable _status 0
variable _tabops
variable _defops
variable _source
variable _type
variable _data
variable _evt
# key win unix
# shift 1 | 1 -> 1
# control 4 | 4 -> 4
# alt 8 | 16 -> 24
# meta | 64 -> 88
array set _tabops {
mod,none 0
mod,shift 1
mod,control 4
mod,alt 24
ops,copy 1
ops,move 1
ops,link 1
}
if { $tcl_platform(platform) == "unix" } {
set _tabops(mod,alt) 8
} else {
set _tabops(mod,alt) 16
}
array set _defops \
[list \
copy,mod shift \
move,mod control \
link,mod alt \
copy,img @[file join $::BWIDGET::LIBRARY "images" "opcopy.xbm"] \
move,img @[file join $::BWIDGET::LIBRARY "images" "opmove.xbm"] \
link,img @[file join $::BWIDGET::LIBRARY "images" "oplink.xbm"]]
bind DragTop <KeyPress-Shift_L> {DropSite::_update_operation [expr %s | 1]}
bind DragTop <KeyPress-Shift_R> {DropSite::_update_operation [expr %s | 1]}
bind DragTop <KeyPress-Control_L> {DropSite::_update_operation [expr %s | 4]}
bind DragTop <KeyPress-Control_R> {DropSite::_update_operation [expr %s | 4]}
if { $tcl_platform(platform) == "unix" } {
bind DragTop <KeyPress-Alt_L> {DropSite::_update_operation [expr %s | 8]}
bind DragTop <KeyPress-Alt_R> {DropSite::_update_operation [expr %s | 8]}
} else {
bind DragTop <KeyPress-Alt_L> {DropSite::_update_operation [expr %s | 16]}
bind DragTop <KeyPress-Alt_R> {DropSite::_update_operation [expr %s | 16]}
}
bind DragTop <KeyRelease-Shift_L> {DropSite::_update_operation [expr %s & ~1]}
bind DragTop <KeyRelease-Shift_R> {DropSite::_update_operation [expr %s & ~1]}
bind DragTop <KeyRelease-Control_L> {DropSite::_update_operation [expr %s & ~4]}
bind DragTop <KeyRelease-Control_R> {DropSite::_update_operation [expr %s & ~4]}
if { $tcl_platform(platform) == "unix" } {
bind DragTop <KeyRelease-Alt_L> {DropSite::_update_operation [expr %s & ~8]}
bind DragTop <KeyRelease-Alt_R> {DropSite::_update_operation [expr %s & ~8]}
} else {
bind DragTop <KeyRelease-Alt_L> {DropSite::_update_operation [expr %s & ~16]}
bind DragTop <KeyRelease-Alt_R> {DropSite::_update_operation [expr %s & ~16]}
}
}
# ----------------------------------------------------------------------------
# Command DropSite::include
# ----------------------------------------------------------------------------
proc DropSite::include { class types } {
set dropoptions [list \
[list -dropenabled Boolean 0 0] \
[list -dropovercmd String "" 0] \
[list -dropcmd String "" 0] \
[list -droptypes String $types 0] \
]
Widget::declare $class $dropoptions
}
# ----------------------------------------------------------------------------
# Command DropSite::setdrop
# Widget interface to register
# ----------------------------------------------------------------------------
proc DropSite::setdrop { path subpath dropover drop {force 0}} {
set cen [Widget::hasChanged $path -dropenabled en]
set ctypes [Widget::hasChanged $path -droptypes types]
if { $en } {
if { $force || $cen || $ctypes } {
register $subpath \
-droptypes $types \
-dropcmd $drop \
-dropovercmd $dropover
}
} else {
register $subpath
}
}
# ----------------------------------------------------------------------------
# Command DropSite::register
# ----------------------------------------------------------------------------
proc DropSite::register { path args } {
variable _tabops
variable _defops
upvar \#0 DropSite::$path drop
Widget::init DropSite .drop$path $args
if { [info exists drop] } {
unset drop
}
set dropcmd [Widget::getMegawidgetOption .drop$path -dropcmd]
set types [Widget::getMegawidgetOption .drop$path -droptypes]
set overcmd [Widget::getMegawidgetOption .drop$path -dropovercmd]
Widget::destroy .drop$path
if { $dropcmd != "" && $types != "" } {
set drop(dropcmd) $dropcmd
set drop(overcmd) $overcmd
foreach {type ops} $types {
set drop($type,ops) {}
set masklist {}
foreach {descop lmod} $ops {
if { ![llength $descop] || [llength $descop] > 3 } {
return -code error "invalid operation description \"$descop\""
}
foreach {subop baseop imgop} $descop {
set subop [string trim $subop]
if { ![string length $subop] } {
return -code error "sub operation is empty"
}
if { ![string length $baseop] } {
set baseop $subop
}
if { [info exists drop($type,ops,$subop)] } {
return -code error "operation \"$subop\" already defined"
}
if { ![info exists _tabops(ops,$baseop)] } {
return -code error "invalid base operation \"$baseop\""
}
if { ![string equal $subop $baseop] &&
[info exists _tabops(ops,$subop)] } {
return -code error "sub operation \"$subop\" is a base operation"
}
if { ![string length $imgop] } {
set imgop $_defops($baseop,img)
}
}
if { [string equal $lmod "program"] } {
set drop($type,ops,$subop) $baseop
set drop($type,img,$subop) $imgop
} else {
if { ![string length $lmod] } {
set lmod $_defops($baseop,mod)
}
set mask 0
foreach mod $lmod {
if { ![info exists _tabops(mod,$mod)] } {
return -code error "invalid modifier \"$mod\""
}
set mask [expr {$mask | $_tabops(mod,$mod)}]
}
if { ($mask == 0) != ([string equal $subop "default"]) } {
return -code error "sub operation default can only be used with modifier \"none\""
}
set drop($type,mod,$mask) $subop
set drop($type,ops,$subop) $baseop
set drop($type,img,$subop) $imgop
lappend masklist $mask
}
}
if { ![info exists drop($type,mod,0)] } {
set drop($type,mod,0) default
set drop($type,ops,default) copy
set drop($type,img,default) $_defops(copy,img)
lappend masklist 0
}
set drop($type,ops,force) copy
set drop($type,img,force) $_defops(copy,img)
foreach mask [lsort -integer -decreasing $masklist] {
lappend drop($type,ops) $mask $drop($type,mod,$mask)
}
}
}
}
# ----------------------------------------------------------------------------
# Command DropSite::setcursor
# ----------------------------------------------------------------------------
proc DropSite::setcursor { cursor } {
catch {.drag configure -cursor $cursor}
}
# ----------------------------------------------------------------------------
# Command DropSite::setoperation
# ----------------------------------------------------------------------------
proc DropSite::setoperation { op } {
variable _curop
variable _dragops
variable _target
variable _type
upvar \#0 DropSite::$_target drop
if { [info exist drop($_type,ops,$op)] &&
$_dragops($drop($_type,ops,$op)) } {
set _curop $op
} else {
# force to a copy operation
set _curop force
}
}
# ----------------------------------------------------------------------------
# Command DropSite::_init_drag
# ----------------------------------------------------------------------------
proc DropSite::_init_drag { top evt source state X Y type ops data } {
variable _top
variable _source
variable _type
variable _data
variable _target
variable _status
variable _state
variable _dragops
variable _opw
variable _evt
if {[info exists _dragops]} {
unset _dragops
}
array set _dragops {copy 1 move 0 link 0}
foreach op $ops {
set _dragops($op) 1
}
set _target ""
set _status 0
set _top $top
set _source $source
set _type $type
set _data $data
label $_opw -relief flat -bd 0 -highlightthickness 0 \
-foreground black -background white
bind $top <ButtonRelease-$evt> {DropSite::_release %X %Y}
bind $top <B$evt-Motion> {DropSite::_motion %X %Y}
bind $top <Motion> {DropSite::_release %X %Y}
set _state $state
set _evt $evt
_motion $X $Y
}
# ----------------------------------------------------------------------------
# Command DropSite::_update_operation
# ----------------------------------------------------------------------------
proc DropSite::_update_operation { state } {
variable _top
variable _status
variable _state
if { $_status & 3 } {
set _state $state
_motion [winfo pointerx $_top] [winfo pointery $_top]
}
}
# ----------------------------------------------------------------------------
# Command DropSite::_compute_operation
# ----------------------------------------------------------------------------
proc DropSite::_compute_operation { target state type } {
variable _curop
variable _dragops
upvar \#0 DropSite::$target drop
foreach {mask op} $drop($type,ops) {
if { ($state & $mask) == $mask } {
if { $_dragops($drop($type,ops,$op)) } {
set _curop $op
return
}
}
}
set _curop force
}
# ----------------------------------------------------------------------------
# Command DropSite::_draw_operation
# ----------------------------------------------------------------------------
proc DropSite::_draw_operation { target type } {
variable _opw
variable _curop
variable _dragops
variable _tabops
variable _status
upvar \#0 DropSite::$target drop
if { !($_status & 1) } {
catch {place forget $_opw}
return
}
if { 0 } {
if { ![info exist drop($type,ops,$_curop)] ||
!$_dragops($drop($type,ops,$_curop)) } {
# force to a copy operation
set _curop copy
catch {
$_opw configure -bitmap $_tabops(img,copy)
place $_opw -relx 1 -rely 1 -anchor se
}
}
} elseif { [string equal $_curop "default"] } {
catch {place forget $_opw}
} else {
catch {
$_opw configure -bitmap $drop($type,img,$_curop)
place $_opw -relx 1 -rely 1 -anchor se
}
}
}
# ----------------------------------------------------------------------------
# Command DropSite::_motion
# ----------------------------------------------------------------------------
proc DropSite::_motion { X Y } {
variable _top
variable _target
variable _status
variable _state
variable _curop
variable _type
variable _data
variable _source
variable _evt
set script [bind $_top <B$_evt-Motion>]
bind $_top <B$_evt-Motion> {}
bind $_top <Motion> {}
wm geometry $_top "+[expr {$X+1}]+[expr {$Y+1}]"
update
if { ![winfo exists $_top] } {
return
}
set path [winfo containing $X $Y]
if { ![string equal $path $_target] } {
# path != current target
if { $_status & 2 } {
# current target is valid and has recall status
# generate leave event
upvar \#0 DropSite::$_target drop
uplevel \#0 $drop(overcmd) [list $_target $_source leave $X $Y $_curop $_type $_data]
}
set _target $path
upvar \#0 DropSite::$_target drop
if { [info exists drop($_type,ops)] } {
# path is a valid target
_compute_operation $_target $_state $_type
if { $drop(overcmd) != "" } {
set arg [list $_target $_source enter $X $Y $_curop $_type $_data]
set _status [uplevel \#0 $drop(overcmd) $arg]
} else {
set _status 1
catch {$_top configure -cursor based_arrow_down}
}
_draw_operation $_target $_type
update
catch {
bind $_top <B$_evt-Motion> {DropSite::_motion %X %Y}
bind $_top <Motion> {DropSite::_release %X %Y}
}
return
} else {
set _status 0
catch {$_top configure -cursor dot}
_draw_operation "" ""
}
} elseif { $_status & 2 } {
upvar \#0 DropSite::$_target drop
_compute_operation $_target $_state $_type
set arg [list $_target $_source motion $X $Y $_curop $_type $_data]
set _status [uplevel \#0 $drop(overcmd) $arg]
_draw_operation $_target $_type
}
update
catch {
bind $_top <B$_evt-Motion> {DropSite::_motion %X %Y}
bind $_top <Motion> {DropSite::_release %X %Y}
}
}
# ----------------------------------------------------------------------------
# Command DropSite::_release
# ----------------------------------------------------------------------------
proc DropSite::_release { X Y } {
variable _target
variable _status
variable _curop
variable _source
variable _type
variable _data
if { $_status & 1 } {
upvar \#0 DropSite::$_target drop
set res [uplevel \#0 $drop(dropcmd) [list $_target $_source $X $Y $_curop $_type $_data]]
DragSite::_end_drag $_source $_target $drop($_type,ops,$_curop) $_type $_data $res
} else {
if { $_status & 2 } {
# notify leave event
upvar \#0 DropSite::$_target drop
uplevel \#0 $drop(overcmd) [list $_target $_source leave $X $Y $_curop $_type $_data]
}
DragSite::_end_drag $_source "" "" $_type $_data 0
}
}
|