/usr/lib/blt2.4/hierbox.tcl is in blt 2.4z-7ubuntu2.
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 | #
# hierbox.tcl
# ----------------------------------------------------------------------
# Bindings for the BLT hierbox widget
# ----------------------------------------------------------------------
# AUTHOR: George Howlett
# Bell Labs Innovations for Lucent Technologies
# gah@lucent.com
# http://www.tcltk.com/blt
#
# RCS: $Id: hierbox.tcl,v 1.1 2002/02/03 20:00:43 ghowlett Exp $
#
# ----------------------------------------------------------------------
# Copyright (c) 1998 Lucent Technologies, Inc.
# ======================================================================
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that the copyright notice and warranty disclaimer appear in
# supporting documentation, and that the names of Lucent Technologies
# any of their entities not be used in advertising or publicity
# pertaining to distribution of the software without specific, written
# prior permission.
#
# Lucent Technologies disclaims all warranties with regard to this
# software, including all implied warranties of merchantability and
# fitness. In no event shall Lucent be liable for any special, indirect
# or consequential damages or any damages whatsoever resulting from loss
# of use, data or profits, whether in an action of contract, negligence
# or other tortuous action, arising out of or in connection with the use
# or performance of this software.
#
# ======================================================================
array set bltHierbox {
afterId ""
scroll 0
space off
x 0
y 0
}
catch {
namespace eval blt::Hierbox {}
}
#
# ButtonPress assignments
#
# B1-Enter start auto-scrolling
# B1-Leave stop auto-scrolling
# ButtonPress-2 start scan
# B2-Motion adjust scan
# ButtonRelease-2 stop scan
#
bind Hierbox <ButtonPress-2> {
set bltHierbox(cursor) [%W cget -cursor]
%W configure -cursor hand1
%W scan mark %x %y
}
bind Hierbox <B2-Motion> {
%W scan dragto %x %y
}
bind Hierbox <ButtonRelease-2> {
%W configure -cursor $bltHierbox(cursor)
}
bind Hierbox <B1-Leave> {
if { $bltHierbox(scroll) } {
blt::Hierbox::AutoScroll %W
}
}
bind Hierbox <B1-Enter> {
after cancel $bltHierbox(afterId)
}
#
# KeyPress assignments
#
# Up
# Down
# Shift-Up
# Shift-Down
# Prior (PageUp)
# Next (PageDn)
# Left
# Right
# space Start selection toggle of entry currently with focus.
# Return Start selection toggle of entry currently with focus.
# Home
# End
# F1
# F2
# ASCII char Go to next open entry starting with character.
#
# KeyRelease
#
# space Stop selection toggle of entry currently with focus.
# Return Stop selection toggle of entry currently with focus.
bind Hierbox <KeyPress-Up> {
blt::Hierbox::MoveFocus %W up
if { $bltHierbox(space) } {
%W selection toggle focus
}
}
bind Hierbox <KeyPress-Down> {
blt::Hierbox::MoveFocus %W down
if { $bltHierbox(space) } {
%W selection toggle focus
}
}
bind Hierbox <Shift-KeyPress-Up> {
blt::Hierbox::MoveFocus %W prevsibling
}
bind Hierbox <Shift-KeyPress-Down> {
blt::Hierbox::MoveFocus %W nextsibling
}
bind Hierbox <KeyPress-Prior> {
blt::Hierbox::MovePage %W top
}
bind Hierbox <KeyPress-Next> {
blt::Hierbox::MovePage %W bottom
}
bind Hierbox <KeyPress-Left> {
%W close focus
}
bind Hierbox <KeyPress-Right> {
%W open focus
%W see focus -anchor w
}
bind Hierbox <KeyPress-space> {
blt::HierboxToggle %W focus
set bltHierbox(space) on
}
bind Hierbox <KeyRelease-space> {
set bltHierbox(space) off
}
bind Hierbox <KeyPress-Return> {
blt::HierboxToggle %W focus
set bltHierbox(space) on
}
bind Hierbox <KeyRelease-Return> {
set bltHierbox(space) off
}
bind Hierbox <KeyPress> {
blt::Hierbox::NextMatchingEntry %W %A
}
bind Hierbox <KeyPress-Home> {
blt::Hierbox::MoveFocus %W root
}
bind Hierbox <KeyPress-End> {
blt::Hierbox::MoveFocus %W end
}
bind Hierbox <KeyPress-F1> {
%W open -r root
}
bind Hierbox <KeyPress-F2> {
eval %W close -r [%W entry children root 0 end]
}
# ----------------------------------------------------------------------
# USAGE: blt::HierboxToggle <hierbox> <index>
# Arguments: hierbox hierarchy widget
#
# Invoked when the user presses the space bar. Toggles the selection
# for the entry at <index>.
# ----------------------------------------------------------------------
proc blt::HierboxToggle { widget index } {
switch -- [$widget cget -selectmode] {
single {
if { [$widget selection includes $index] } {
$widget selection clearall
} else {
$widget selection set $index
}
}
multiple {
$widget selection toggle $index
}
}
}
# ----------------------------------------------------------------------
# USAGE: blt::Hierbox::MovePage <hierbox> <where>
# Arguments: hierbox hierarchy widget
#
# Invoked by KeyPress bindings. Pages the current view up or down.
# The <where> argument should be either "top" or "bottom".
# ----------------------------------------------------------------------
proc blt::Hierbox::MovePage { widget where } {
# If the focus is already at the top/bottom of the window, we want
# to scroll a page. It's really one page minus an entry because we
# want to see the last entry on the next/last page.
if { [$widget index focus] == [$widget index view.$where] } {
if {$where == "top"} {
$widget yview scroll -1 pages
$widget yview scroll 1 units
} else {
$widget yview scroll 1 pages
$widget yview scroll -1 units
}
}
update
# Adjust the entry focus and the view. Also activate the entry.
# just in case the mouse point is not in the widget.
$widget entry highlight view.$where
$widget focus view.$where
$widget see view.$where
if { [$widget cget -selectmode] == "single" } {
$widget selection clearall
$widget selection set focus
}
}
#
# Edit mode assignments
#
# ButtonPress-3 Enables/disables edit mode on entry. Sets focus to
# entry.
#
# KeyPress
#
# Left Move insertion position to previous.
# Right Move insertion position to next.
# Up Move insertion position up one line.
# Down Move insertion position down one line.
# Return End edit mode.
# Shift-Return Line feed.
# Home Move to first position.
# End Move to last position.
# ASCII char Insert character left of insertion point.
# Del Delete character right of insertion point.
# Delete Delete character left of insertion point.
# Ctrl-X Cut
# Ctrl-V Copy
# Ctrl-P Paste
#
# KeyRelease
#
# ButtonPress-1 Start selection if in entry, otherwise clear selection.
# B1-Motion Extend/reduce selection.
# ButtonRelease-1 End selection if in entry, otherwise use last selection.
# B1-Enter Disabled.
# B1-Leave Disabled.
# ButtonPress-2 Same as above.
# B2-Motion Same as above.
# ButtonRelease-2 Same as above.
#
# All bindings in editting mode will "break" to override other bindings.
#
#
bind Hierbox <ButtonPress-3> {
set node [%W nearest %x %y]
%W entry insert $node @%x,%y ""
# %W entry insert $node 2 ""
}
proc blt::Hierbox::Init { widget } {
#
# Active entry bindings
#
$widget bind Entry <Enter> {
%W entry highlight current
}
$widget bind Entry <Leave> {
%W entry highlight ""
}
#
# Button bindings
#
$widget button bind all <ButtonRelease-1> {
%W see -anchor nw current
%W toggle current
}
$widget button bind all <Enter> {
%W button highlight current
}
$widget button bind all <Leave> {
%W button highlight ""
}
#
# ButtonPress-1
#
# Performs the following operations:
#
# 1. Clears the previous selection.
# 2. Selects the current entry.
# 3. Sets the focus to this entry.
# 4. Scrolls the entry into view.
# 5. Sets the selection anchor to this entry, just in case
# this is "multiple" mode.
#
$widget bind Entry <ButtonPress-1> {
blt::Hierbox::SetSelectionAnchor %W current
set bltHierbox(scroll) 1
}
$widget bin Entry <Double-ButtonPress-1> {
%W toggle current
}
#
# B1-Motion
#
# For "multiple" mode only. Saves the current location of the
# pointer for auto-scrolling.
#
$widget bind Entry <B1-Motion> {
set bltHierbox(x) %x
set bltHierbox(y) %y
set index [%W nearest %x %y]
if { [%W cget -selectmode] == "multiple" } {
%W selection mark $index
} else {
blt::Hierbox::SetSelectionAnchor %W $index
}
}
#
# ButtonRelease-1
#
# For "multiple" mode only.
#
$widget bind Entry <ButtonRelease-1> {
if { [%W cget -selectmode] == "multiple" } {
%W selection anchor current
}
after cancel $bltHierbox(afterId)
set bltHierbox(scroll) 0
}
#
# Shift-ButtonPress-1
#
# For "multiple" mode only.
#
$widget bind Entry <Shift-ButtonPress-1> {
if { [%W cget -selectmode] == "multiple" && [%W selection present] } {
if { [%W index anchor] == "" } {
%W selection anchor current
}
set index [%W index anchor]
%W selection clearall
%W selection set $index current
} else {
blt::Hierbox::SetSelectionAnchor %W current
}
}
$widget bind Entry <Shift-B1-Motion> {
# do nothing
}
$widget bind Entry <Shift-ButtonRelease-1> {
after cancel $bltHierbox(afterId)
set bltHierbox(scroll) 0
}
#
# Control-ButtonPress-1
#
# For "multiple" mode only.
#
$widget bind Entry <Control-ButtonPress-1> {
if { [%W cget -selectmode] == "multiple" } {
set index [%W index current]
%W selection toggle $index
%W selection anchor $index
} else {
blt::Hierbox::SetSelectionAnchor %W current
}
}
$widget bind Entry <Control-B1-Motion> {
# do nothing
}
$widget bind Entry <Control-ButtonRelease-1> {
after cancel $bltHierbox(afterId)
set bltHierbox(scroll) 0
}
#
# Control-Shift-ButtonPress-1
#
# For "multiple" mode only.
#
$widget bind Entry <Control-Shift-ButtonPress-1> {
if { [%W cget -selectmode] == "multiple" && [%W selection present] } {
if { [%W index anchor] == "" } {
%W selection anchor current
}
if { [%W selection includes anchor] } {
%W selection set anchor current
} else {
%W selection clear anchor current
%W selection set current
}
} else {
blt::Hierbox::SetSelectionAnchor %W current
}
}
$widget bind Entry <Control-Shift-B1-Motion> {
# do nothing
}
}
# ----------------------------------------------------------------------
# USAGE: blt::Hierbox::AutoScroll <hierbox>
#
# Invoked when the user is selecting elements in a hierbox widget
# and drags the mouse pointer outside of the widget. Scrolls the
# view in the direction of the pointer.
#
# Arguments: hierbox hierarchy widget
#
# ----------------------------------------------------------------------
proc blt::Hierbox::AutoScroll { widget } {
global bltHierbox
if { ![winfo exists $widget] } {
return
}
set x $bltHierbox(x)
set y $bltHierbox(y)
set index [$widget nearest $x $y]
if { $y >= [winfo height $widget] } {
$widget yview scroll 1 units
set neighbor down
} elseif { $y < 0 } {
$widget yview scroll -1 units
set neighbor up
} else {
set neighbor $index
}
if { [$widget cget -selectmode] == "single" } {
blt::Hierbox::SetSelectionAnchor $widget $neighbor
} else {
$widget selection mark $index
}
set bltHierbox(afterId) [after 10 blt::Hierbox::AutoScroll $widget]
}
proc blt::Hierbox::SetSelectionAnchor { widget index } {
set index [$widget index $index]
$widget selection clearall
$widget see $index
$widget focus $index
$widget selection set $index
$widget selection anchor $index
}
# ----------------------------------------------------------------------
# USAGE: blt::Hierbox::NextMatchingEntry <hierbox> <char>
# Arguments: hierbox hierarchy widget
#
# Invoked by KeyPress bindings. Searches for an entry that starts
# with the letter <char> and makes that entry active.
# ----------------------------------------------------------------------
proc blt::Hierbox::NextMatchingEntry { widget key } {
if {[string match {[ -~]} $key]} {
set last [$widget index focus]
set next [$widget index next]
while { $next != $last } {
set label [$widget entry cget $next -label]
if { [string index $label 0] == $key } {
break
}
set next [$widget index -at $next next]
}
$widget focus $next
if {[$widget cget -selectmode] == "single"} {
$widget selection clearall
$widget selection set focus
}
$widget see focus
}
}
# ----------------------------------------------------------------------
# USAGE: blt::Hierbox::MoveFocus <hierbox> <where>
#
# Invoked by KeyPress bindings. Moves the active selection to the
# entry <where>, which is an index such as "up", "down", "prevsibling",
# "nextsibling", etc.
# ----------------------------------------------------------------------
proc blt::Hierbox::MoveFocus { widget where } {
catch {$widget focus $where}
if { [$widget cget -selectmode] == "single" } {
$widget selection clearall
$widget selection set focus
}
$widget see focus
}
|