PageRenderTime 63ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/tcl/interface/tk/packages/BWidget/listbox.tcl

http://chattcl.googlecode.com/
TCL | 1638 lines | 1158 code | 218 blank | 262 comment | 253 complexity | 937ad78da28c3ee94683a1d2baa4fa29 MD5 | raw file
Possible License(s): Unlicense, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. # ----------------------------------------------------------------------------
  2. # listbox.tcl
  3. # This file is part of Unifix BWidget Toolkit
  4. # $Id: listbox.tcl,v 1.1 2006/10/29 14:40:41 sabosbru Exp $
  5. # ----------------------------------------------------------------------------
  6. # Index of commands:
  7. # - ListBox::create
  8. # - ListBox::configure
  9. # - ListBox::cget
  10. # - ListBox::insert
  11. # - ListBox::itemconfigure
  12. # - ListBox::itemcget
  13. # - ListBox::bindText
  14. # - ListBox::bindImage
  15. # - ListBox::delete
  16. # - ListBox::move
  17. # - ListBox::reorder
  18. # - ListBox::selection
  19. # - ListBox::exists
  20. # - ListBox::index
  21. # - ListBox::item - deprecated
  22. # - ListBox::items
  23. # - ListBox::see
  24. # - ListBox::edit
  25. # - ListBox::xview
  26. # - ListBox::yview
  27. # - ListBox::_update_edit_size
  28. # - ListBox::_destroy
  29. # - ListBox::_see
  30. # - ListBox::_update_scrollregion
  31. # - ListBox::_draw_item
  32. # - ListBox::_redraw_items
  33. # - ListBox::_redraw_selection
  34. # - ListBox::_redraw_listbox
  35. # - ListBox::_redraw_idle
  36. # - ListBox::_resize
  37. # - ListBox::_init_drag_cmd
  38. # - ListBox::_drop_cmd
  39. # - ListBox::_over_cmd
  40. # - ListBox::_auto_scroll
  41. # - ListBox::_scroll
  42. # ----------------------------------------------------------------------------
  43. namespace eval ListBox {
  44. Widget::define ListBox listbox DragSite DropSite DynamicHelp
  45. namespace eval Item {
  46. Widget::declare ListBox::Item {
  47. {-indent Int 0 0 "%d >= 0"}
  48. {-text String "" 0}
  49. {-font String "" 0}
  50. {-foreground String "" 0}
  51. {-image TkResource "" 0 label}
  52. {-window String "" 0}
  53. {-data String "" 0}
  54. {-fill Synonym -foreground}
  55. {-fg Synonym -foreground}
  56. }
  57. }
  58. DynamicHelp::include ListBox::Item balloon
  59. Widget::tkinclude ListBox canvas .c \
  60. remove {
  61. -insertwidth -insertbackground -insertborderwidth -insertofftime
  62. -insertontime -selectborderwidth -closeenough -confine -scrollregion
  63. -xscrollincrement -yscrollincrement -width -height
  64. } \
  65. initialize {
  66. -relief sunken -borderwidth 2 -takefocus 1
  67. -highlightthickness 1 -width 200
  68. }
  69. DragSite::include ListBox "LISTBOX_ITEM" 1
  70. DropSite::include ListBox {
  71. LISTBOX_ITEM {copy {} move {}}
  72. }
  73. Widget::declare ListBox {
  74. {-deltax Int 10 0 "%d >= 0"}
  75. {-deltay Int 15 0 "%d >= 0"}
  76. {-padx Int 20 0 "%d >= 0"}
  77. {-foreground TkResource "" 0 listbox}
  78. {-background TkResource "" 0 listbox}
  79. {-selectbackground TkResource "" 0 listbox}
  80. {-selectforeground TkResource "" 0 listbox}
  81. {-font TkResource "" 0 listbox}
  82. {-width TkResource "" 0 listbox}
  83. {-height TkResource "" 0 listbox}
  84. {-redraw Boolean 1 0}
  85. {-multicolumn Boolean 0 0}
  86. {-dropovermode Flag "wpi" 0 "wpi"}
  87. {-selectmode Enum none 1 {none single multiple}}
  88. {-fg Synonym -foreground}
  89. {-bg Synonym -background}
  90. {-dropcmd String "ListBox::_drag_and_drop" 0}
  91. {-autofocus Boolean 1 1}
  92. {-selectfill Boolean 0 1}
  93. }
  94. Widget::addmap ListBox "" .c {-deltay -yscrollincrement}
  95. bind ListBox <FocusIn> [list after idle {BWidget::refocus %W %W.c}]
  96. bind ListBox <Destroy> [list ListBox::_destroy %W]
  97. bind ListBox <Configure> [list ListBox::_resize %W]
  98. bind ListBoxFocus <1> [list focus %W]
  99. bind ListBox <Key-Up> [list ListBox::_keyboard_navigation %W -1]
  100. bind ListBox <Key-Down> [list ListBox::_keyboard_navigation %W 1]
  101. variable _edit
  102. }
  103. # ----------------------------------------------------------------------------
  104. # Command ListBox::create
  105. # ----------------------------------------------------------------------------
  106. proc ListBox::create { path args } {
  107. Widget::init ListBox $path $args
  108. variable $path
  109. upvar 0 $path data
  110. frame $path -class ListBox -bd 0 -highlightthickness 0 -relief flat \
  111. -takefocus 0
  112. # For 8.4+ we don't want to inherit the padding
  113. catch {$path configure -padx 0 -pady 0}
  114. # widget informations
  115. set data(nrows) -1
  116. # items informations
  117. set data(items) {}
  118. set data(selitems) {}
  119. # update informations
  120. set data(upd,level) 0
  121. set data(upd,afterid) ""
  122. set data(upd,level) 0
  123. set data(upd,delete) {}
  124. # drag and drop informations
  125. set data(dnd,scroll) ""
  126. set data(dnd,afterid) ""
  127. set data(dnd,item) ""
  128. eval [list canvas $path.c] [Widget::subcget $path .c] \
  129. [list -xscrollincrement 8]
  130. pack $path.c -expand yes -fill both
  131. DragSite::setdrag $path $path.c ListBox::_init_drag_cmd \
  132. [Widget::cget $path -dragendcmd] 1
  133. DropSite::setdrop $path $path.c ListBox::_over_cmd ListBox::_drop_cmd 1
  134. Widget::create ListBox $path
  135. set w [Widget::cget $path -width]
  136. set h [Widget::cget $path -height]
  137. set dy [Widget::cget $path -deltay]
  138. $path.c configure -width [expr {$w*8}] -height [expr {$h*$dy}]
  139. # Insert $path into the canvas bindings, so that anyone binding
  140. # directly onto the widget will see their bindings activated when
  141. # the canvas has focus.
  142. set bindtags [bindtags $path.c]
  143. set bindtags [linsert $bindtags 1 $path]
  144. # Let any click within the canvas focus on the canvas so that
  145. # MouseWheel scroll events will be properly handled by the canvas.
  146. if {[Widget::cget $path -autofocus]} {
  147. lappend bindtags ListBoxFocus
  148. BWidget::bindMouseWheel $path.c
  149. }
  150. bindtags $path.c $bindtags
  151. # Add slightly modified up/down bindings to the canvas, in case
  152. # it gets the focus (like with -autofocus).
  153. bind $path.c <Key-Up> {ListBox::_keyboard_navigation [winfo parent %W] -1}
  154. bind $path.c <Key-Down> {ListBox::_keyboard_navigation [winfo parent %W] 1}
  155. switch -exact -- [Widget::getoption $path -selectmode] {
  156. single {
  157. $path bindText <Button-1> [list ListBox::_mouse_select $path set]
  158. $path bindImage <Button-1> [list ListBox::_mouse_select $path set]
  159. }
  160. multiple {
  161. set cmd ListBox::_multiple_select
  162. $path bindText <Button-1> [list $cmd $path n %x %y]
  163. $path bindText <Shift-Button-1> [list $cmd $path s %x %y]
  164. $path bindText <Control-Button-1> [list $cmd $path c %x %y]
  165. $path bindImage <Button-1> [list $cmd $path n %x %y]
  166. $path bindImage <Shift-Button-1> [list $cmd $path s %x %y]
  167. $path bindImage <Control-Button-1> [list $cmd $path c %x %y]
  168. }
  169. }
  170. return $path
  171. }
  172. # ----------------------------------------------------------------------------
  173. # Command ListBox::configure
  174. # ----------------------------------------------------------------------------
  175. proc ListBox::configure { path args } {
  176. set res [Widget::configure $path $args]
  177. set ch1 [expr {[Widget::hasChanged $path -deltay dy] |
  178. [Widget::hasChanged $path -padx val] |
  179. [Widget::hasChanged $path -multicolumn val]}]
  180. set ch2 [expr {[Widget::hasChanged $path -selectbackground val] |
  181. [Widget::hasChanged $path -selectforeground val]}]
  182. set redraw 0
  183. if { [Widget::hasChanged $path -height h] } {
  184. $path.c configure -height [expr {$h*$dy}]
  185. set redraw 1
  186. }
  187. if { [Widget::hasChanged $path -width w] } {
  188. $path.c configure -width [expr {$w*8}]
  189. set redraw 1
  190. }
  191. if { [Widget::hasChanged $path -background bg] } {
  192. $path.c itemconfigure box -fill $bg
  193. }
  194. if { !$redraw } {
  195. if { $ch1 } {
  196. _redraw_idle $path 2
  197. } elseif { $ch2 } {
  198. _redraw_idle $path 1
  199. }
  200. }
  201. if { [Widget::hasChanged $path -redraw bool] && $bool } {
  202. variable $path
  203. upvar 0 $path data
  204. set lvl $data(upd,level)
  205. set data(upd,level) 0
  206. _redraw_idle $path $lvl
  207. }
  208. set force [Widget::hasChanged $path -dragendcmd dragend]
  209. DragSite::setdrag $path $path.c ListBox::_init_drag_cmd $dragend $force
  210. DropSite::setdrop $path $path.c ListBox::_over_cmd ListBox::_drop_cmd
  211. return $res
  212. }
  213. # ----------------------------------------------------------------------------
  214. # Command ListBox::cget
  215. # ----------------------------------------------------------------------------
  216. proc ListBox::cget { path option } {
  217. return [Widget::cget $path $option]
  218. }
  219. # ----------------------------------------------------------------------------
  220. # Command ListBox::insert
  221. # ----------------------------------------------------------------------------
  222. proc ListBox::insert { path index item args } {
  223. variable $path
  224. upvar 0 $path data
  225. set item [Widget::nextIndex $path $item]
  226. if { [lsearch -exact $data(items) $item] != -1 } {
  227. return -code error "item \"$item\" already exists"
  228. }
  229. Widget::init ListBox::Item $path.$item $args
  230. set data(items) [linsert $data(items) $index $item]
  231. set data(upd,create,$item) $item
  232. _redraw_idle $path 2
  233. return $item
  234. }
  235. # Bastien Chevreux (bach@mwgdna.com)
  236. # The multipleinsert command performs inserts several items at once into
  237. # the list. It is faster than calling insert multiple times as it uses the
  238. # Widget::copyinit command for initializing all items after the 1st. The
  239. # speedup factor is between 2 and 3 for typical usage, but could be higher
  240. # for inserts with many options.
  241. #
  242. # Syntax: path and index are as in the insert command
  243. # args is a list of even numbered elements where the 1st of each pair
  244. # corresponds to the item of 'insert' and the second to args of 'insert'.
  245. # ----------------------------------------------------------------------------
  246. # Command ListBox::multipleinsert
  247. # ----------------------------------------------------------------------------
  248. proc ListBox::multipleinsert { path index args } {
  249. variable $path
  250. upvar 0 $path data
  251. # If we got only one list as arg, take the first element as args
  252. # This enables callers to use
  253. # $list multipleinsert index $thelist
  254. # instead of
  255. # eval $list multipleinsert index $thelist
  256. if {[llength $args] == 1} {
  257. set args [lindex $args 0]
  258. }
  259. set count 0
  260. foreach {item iargs} $args {
  261. if { [lsearch -exact $data(items) $item] != -1 } {
  262. return -code error "item \"$item\" already exists"
  263. }
  264. if {$count==0} {
  265. Widget::init ListBox::Item $path.$item $iargs
  266. set firstpath $path.$item
  267. } else {
  268. Widget::copyinit ListBox::Item $firstpath $path.$item $iargs
  269. }
  270. set data(items) [linsert $data(items) $index $item]
  271. set data(upd,create,$item) $item
  272. incr count
  273. }
  274. _redraw_idle $path 2
  275. return $item
  276. }
  277. # ----------------------------------------------------------------------------
  278. # Command ListBox::itemconfigure
  279. # ----------------------------------------------------------------------------
  280. proc ListBox::itemconfigure { path item args } {
  281. variable $path
  282. upvar 0 $path data
  283. if { [lsearch -exact $data(items) $item] == -1 } {
  284. return -code error "item \"$item\" does not exist"
  285. }
  286. set oldind [Widget::getoption $path.$item -indent]
  287. set res [Widget::configure $path.$item $args]
  288. set chind [Widget::hasChanged $path.$item -indent indent]
  289. set chw [Widget::hasChanged $path.$item -window win]
  290. set chi [Widget::hasChanged $path.$item -image img]
  291. set cht [Widget::hasChanged $path.$item -text txt]
  292. set chf [Widget::hasChanged $path.$item -font fnt]
  293. set chfg [Widget::hasChanged $path.$item -foreground fg]
  294. set idn [$path.c find withtag n:$item]
  295. _set_help $path $item
  296. if { $idn == "" } {
  297. # item is not drawn yet
  298. _redraw_idle $path 2
  299. return $res
  300. }
  301. set oldb [$path.c bbox $idn]
  302. set coords [$path.c coords $idn]
  303. set padx [Widget::getoption $path -padx]
  304. set x0 [expr {[lindex $coords 0]-$padx-$oldind+$indent}]
  305. set y0 [lindex $coords 1]
  306. if { $chw || $chi } {
  307. # -window or -image modified
  308. set idi [$path.c find withtag i:$item]
  309. set type [lindex [$path.c gettags $idi] 0]
  310. if { [string length $win] } {
  311. if { [string equal $type "win"] } {
  312. $path.c itemconfigure $idi -window $win
  313. } else {
  314. $path.c delete $idi
  315. $path.c create window $x0 $y0 -window $win -anchor w \
  316. -tags [list win i:$item]
  317. }
  318. } elseif { [string length $img] } {
  319. if { [string equal $type "img"] } {
  320. $path.c itemconfigure $idi -image $img
  321. } else {
  322. $path.c delete $idi
  323. $path.c create image $x0 $y0 -image $img -anchor w \
  324. -tags [list img i:$item]
  325. }
  326. } else {
  327. $path.c delete $idi
  328. }
  329. }
  330. if { $cht || $chf || $chfg } {
  331. # -text or -font modified, or -foreground modified
  332. set fnt [_getoption $path $item -font]
  333. set fg [_getoption $path $item -foreground]
  334. $path.c itemconfigure $idn -text $txt -font $fnt -fill $fg
  335. _redraw_idle $path 1
  336. }
  337. if { $chind } {
  338. # -indent modified
  339. $path.c coords $idn [expr {$x0+$padx}] $y0
  340. $path.c coords i:$item $x0 $y0
  341. _redraw_idle $path 1
  342. }
  343. if { [Widget::getoption $path -multicolumn] && ($cht || $chf || $chind) } {
  344. set bbox [$path.c bbox $idn]
  345. if { [lindex $bbox 2] > [lindex $oldb 2] } {
  346. _redraw_idle $path 2
  347. }
  348. }
  349. return $res
  350. }
  351. # ----------------------------------------------------------------------------
  352. # Command ListBox::itemcget
  353. # ----------------------------------------------------------------------------
  354. proc ListBox::itemcget { path item option } {
  355. return [Widget::cget $path.$item $option]
  356. }
  357. # ----------------------------------------------------------------------------
  358. # Command ListBox::bindText
  359. # ----------------------------------------------------------------------------
  360. proc ListBox::bindText { path event script } {
  361. if { $script != "" } {
  362. set map [list %W $path]
  363. set script [string map $map $script]
  364. append script " \[ListBox::_get_current [list $path]\]"
  365. }
  366. $path.c bind "click" $event $script
  367. }
  368. # ----------------------------------------------------------------------------
  369. # Command ListBox::bindImage
  370. # ----------------------------------------------------------------------------
  371. proc ListBox::bindImage { path event script } {
  372. if { $script != "" } {
  373. set map [list %W $path]
  374. set script [string map $map $script]
  375. append script " \[ListBox::_get_current [list $path]\]"
  376. }
  377. $path.c bind "img" $event $script
  378. }
  379. # ----------------------------------------------------------------------------
  380. # Command ListBox::delete
  381. # ----------------------------------------------------------------------------
  382. proc ListBox::delete { path args } {
  383. variable $path
  384. upvar 0 $path data
  385. Widget::getVariable $path help
  386. foreach litems $args {
  387. foreach item $litems {
  388. set idx [lsearch -exact $data(items) $item]
  389. if { $idx != -1 } {
  390. set data(items) [lreplace $data(items) $idx $idx]
  391. array unset help $item
  392. Widget::destroy $path.$item
  393. if { [info exists data(upd,create,$item)] } {
  394. unset data(upd,create,$item)
  395. } else {
  396. lappend data(upd,delete) $item
  397. }
  398. }
  399. }
  400. }
  401. set sel $data(selitems)
  402. set data(selitems) {}
  403. eval [list selection $path set] $sel
  404. _redraw_idle $path 2
  405. }
  406. # ----------------------------------------------------------------------------
  407. # Command ListBox::move
  408. # ----------------------------------------------------------------------------
  409. proc ListBox::move { path item index } {
  410. variable $path
  411. upvar 0 $path data
  412. if { [set idx [lsearch -exact $data(items) $item]] == -1 } {
  413. return -code error "item \"$item\" does not exist"
  414. }
  415. set data(items) [linsert [lreplace $data(items) $idx $idx] $index $item]
  416. _redraw_idle $path 2
  417. }
  418. # ----------------------------------------------------------------------------
  419. # Command ListBox::reorder
  420. # ----------------------------------------------------------------------------
  421. proc ListBox::reorder { path neworder } {
  422. variable $path
  423. upvar 0 $path data
  424. set data(items) [BWidget::lreorder $data(items) $neworder]
  425. _redraw_idle $path 2
  426. }
  427. # ----------------------------------------------------------------------------
  428. # Command ListBox::selection
  429. # ----------------------------------------------------------------------------
  430. proc ListBox::selection { path cmd args } {
  431. variable $path
  432. upvar 0 $path data
  433. switch -- $cmd {
  434. set {
  435. set data(selitems) {}
  436. foreach item $args {
  437. if { [lsearch -exact $data(selitems) $item] == -1 } {
  438. if { [lsearch -exact $data(items) $item] != -1 } {
  439. lappend data(selitems) $item
  440. }
  441. }
  442. }
  443. }
  444. add {
  445. foreach item $args {
  446. if { [lsearch -exact $data(selitems) $item] == -1 } {
  447. if { [lsearch -exact $data(items) $item] != -1 } {
  448. lappend data(selitems) $item
  449. }
  450. }
  451. }
  452. }
  453. remove {
  454. foreach item $args {
  455. if { [set idx [lsearch -exact $data(selitems) $item]] != -1 } {
  456. set data(selitems) [lreplace $data(selitems) $idx $idx]
  457. }
  458. }
  459. }
  460. clear {
  461. set data(selitems) {}
  462. }
  463. get {
  464. return $data(selitems)
  465. }
  466. includes {
  467. return [expr {[lsearch -exact $data(selitems) $args] != -1}]
  468. }
  469. default {
  470. return
  471. }
  472. }
  473. _redraw_idle $path 1
  474. }
  475. # ----------------------------------------------------------------------------
  476. # Command ListBox::exists
  477. # ----------------------------------------------------------------------------
  478. proc ListBox::exists { path item } {
  479. variable $path
  480. upvar 0 $path data
  481. return [expr {[lsearch -exact $data(items) $item] != -1}]
  482. }
  483. # ----------------------------------------------------------------------------
  484. # Command ListBox::index
  485. # ----------------------------------------------------------------------------
  486. proc ListBox::index { path item } {
  487. variable $path
  488. upvar 0 $path data
  489. if {[string equal $item "active"]} { return [$path selection get] }
  490. return [lsearch -exact $data(items) $item]
  491. }
  492. # ----------------------------------------------------------------------------
  493. # ListBox::find
  494. # Returns the item given a position.
  495. # findInfo @x,y ?confine?
  496. # lineNumber
  497. # ----------------------------------------------------------------------------
  498. proc ListBox::find {path findInfo {confine ""}} {
  499. variable $path
  500. upvar 0 $path widgetData
  501. if {[regexp -- {^@([0-9]+),([0-9]+)$} $findInfo match x y]} {
  502. set x [$path.c canvasx $x]
  503. set y [$path.c canvasy $y]
  504. } elseif {[regexp -- {^[0-9]+$} $findInfo lineNumber]} {
  505. set dy [Widget::getoption $path -deltay]
  506. set y [expr {$dy*($lineNumber+0.5)}]
  507. set confine ""
  508. } else {
  509. return -code error "invalid find spec \"$findInfo\""
  510. }
  511. set found 0
  512. set xi 0
  513. foreach xs $widgetData(xlist) {
  514. if {$x <= $xs} {
  515. foreach id [$path.c find overlapping $xi $y $xs $y] {
  516. set ltags [$path.c gettags $id]
  517. set item [lindex $ltags 0]
  518. if { [string equal $item "item"] ||
  519. [string equal $item "img"] ||
  520. [string equal $item "win"] } {
  521. # item is the label or image/window of the node
  522. set item [string range [lindex $ltags 1] 2 end]
  523. set found 1
  524. break
  525. }
  526. }
  527. break
  528. }
  529. set xi $xs
  530. }
  531. if {$found} {
  532. if {[string equal $confine "confine"]} {
  533. # test if x stand inside node bbox
  534. set xi [expr {[lindex [$path.c coords n:$item] 0]-[Widget::getoption $path -padx]}]
  535. set xs [lindex [$path.c bbox n:$item] 2]
  536. if {$x >= $xi && $x <= $xs} {
  537. return $item
  538. }
  539. } else {
  540. return $item
  541. }
  542. }
  543. return ""
  544. }
  545. # ----------------------------------------------------------------------------
  546. # Command ListBox::item - deprecated
  547. # ----------------------------------------------------------------------------
  548. proc ListBox::item { path first {last ""} } {
  549. variable $path
  550. upvar 0 $path data
  551. if { ![string length $last] } {
  552. return [lindex $data(items) $first]
  553. } else {
  554. return [lrange $data(items) $first $last]
  555. }
  556. }
  557. # ----------------------------------------------------------------------------
  558. # Command ListBox::items
  559. # ----------------------------------------------------------------------------
  560. proc ListBox::items { path {first ""} {last ""}} {
  561. variable $path
  562. upvar 0 $path data
  563. if { ![string length $first] } {
  564. return $data(items)
  565. }
  566. if { ![string length $last] } {
  567. return [lindex $data(items) $first]
  568. } else {
  569. return [lrange $data(items) $first $last]
  570. }
  571. }
  572. # ----------------------------------------------------------------------------
  573. # Command ListBox::see
  574. # ----------------------------------------------------------------------------
  575. proc ListBox::see { path item } {
  576. variable $path
  577. upvar 0 $path data
  578. if { [Widget::getoption $path -redraw] && $data(upd,afterid) != "" } {
  579. after cancel $data(upd,afterid)
  580. _redraw_listbox $path
  581. }
  582. set idn [$path.c find withtag n:$item]
  583. if { $idn != "" } {
  584. ListBox::_see $path $idn right
  585. ListBox::_see $path $idn left
  586. }
  587. }
  588. # ----------------------------------------------------------------------------
  589. # Command ListBox::edit
  590. # ----------------------------------------------------------------------------
  591. proc ListBox::edit { path item text {verifycmd ""} {clickres 0} {select 1}} {
  592. variable _edit
  593. variable $path
  594. upvar 0 $path data
  595. if { [Widget::getoption $path -redraw] && $data(upd,afterid) != "" } {
  596. after cancel $data(upd,afterid)
  597. _redraw_listbox $path
  598. }
  599. set idn [$path.c find withtag n:$item]
  600. if { $idn != "" } {
  601. ListBox::_see $path $idn right
  602. ListBox::_see $path $idn left
  603. set oldfg [$path.c itemcget $idn -fill]
  604. set sbg [Widget::getoption $path -selectbackground]
  605. set coords [$path.c coords $idn]
  606. set x [lindex $coords 0]
  607. set y [lindex $coords 1]
  608. set bd [expr {[$path.c cget -borderwidth]+[$path.c cget -highlightthickness]}]
  609. set w [expr {[winfo width $path] - 2*$bd}]
  610. set wmax [expr {[$path.c canvasx $w]-$x}]
  611. $path.c itemconfigure $idn -fill [Widget::getoption $path -background]
  612. $path.c itemconfigure s:$item -fill {} -outline {}
  613. set _edit(text) $text
  614. set _edit(wait) 0
  615. set frame [frame $path.edit \
  616. -relief flat -borderwidth 0 -highlightthickness 0 \
  617. -background [Widget::getoption $path -background]]
  618. set ent [entry $frame.edit \
  619. -width 0 \
  620. -relief solid \
  621. -borderwidth 1 \
  622. -highlightthickness 0 \
  623. -foreground [_getoption $path $item -foreground] \
  624. -background [Widget::getoption $path -background] \
  625. -selectforeground [Widget::getoption $path -selectforeground] \
  626. -selectbackground $sbg \
  627. -font [_getoption $path $item -font] \
  628. -textvariable ListBox::_edit(text)]
  629. pack $ent -ipadx 8 -anchor w
  630. set idw [$path.c create window $x $y -window $frame -anchor w]
  631. trace variable ListBox::_edit(text) w [list ListBox::_update_edit_size $path $ent $idw $wmax]
  632. tkwait visibility $ent
  633. grab $frame
  634. BWidget::focus set $ent
  635. _update_edit_size $path $ent $idw $wmax
  636. update
  637. if { $select } {
  638. $ent selection range 0 end
  639. $ent icursor end
  640. $ent xview end
  641. }
  642. bindtags $ent [list $ent Entry]
  643. bind $ent <Escape> {set ListBox::_edit(wait) 0}
  644. bind $ent <Return> {set ListBox::_edit(wait) 1}
  645. if { $clickres == 0 || $clickres == 1 } {
  646. bind $frame <Button> [list set ListBox::_edit(wait) $clickres]
  647. }
  648. set ok 0
  649. while { !$ok } {
  650. tkwait variable ListBox::_edit(wait)
  651. if { !$_edit(wait) || [llength $verifycmd]==0 ||
  652. [uplevel \#0 $verifycmd [list $_edit(text)]] } {
  653. set ok 1
  654. }
  655. }
  656. trace vdelete ListBox::_edit(text) w [list ListBox::_update_edit_size $path $ent $idw $wmax]
  657. grab release $frame
  658. BWidget::focus release $ent
  659. destroy $frame
  660. $path.c delete $idw
  661. $path.c itemconfigure $idn -fill $oldfg
  662. $path.c itemconfigure s:$item -fill $sbg -outline $sbg
  663. if { $_edit(wait) } {
  664. return $_edit(text)
  665. }
  666. }
  667. return ""
  668. }
  669. # ----------------------------------------------------------------------------
  670. # Command ListBox::xview
  671. # ----------------------------------------------------------------------------
  672. proc ListBox::xview { path args } {
  673. return [eval [linsert $args 0 $path.c xview]]
  674. }
  675. # ----------------------------------------------------------------------------
  676. # Command ListBox::yview
  677. # ----------------------------------------------------------------------------
  678. proc ListBox::yview { path args } {
  679. return [eval [linsert $args 0 $path.c yview]]
  680. }
  681. proc ListBox::getcanvas { path } {
  682. return $path.c
  683. }
  684. proc ListBox::curselection { path } {
  685. return [$path selection get]
  686. }
  687. # ----------------------------------------------------------------------------
  688. # Command ListBox::_update_edit_size
  689. # ----------------------------------------------------------------------------
  690. proc ListBox::_update_edit_size { path entry idw wmax args } {
  691. set entw [winfo reqwidth $entry]
  692. if { $entw >= $wmax } {
  693. $path.c itemconfigure $idw -width $wmax
  694. } else {
  695. $path.c itemconfigure $idw -width 0
  696. }
  697. }
  698. # ----------------------------------------------------------------------------
  699. # Command ListBox::_getoption
  700. # Returns the value of option for node. If empty, returned value is those
  701. # of the ListBox.
  702. # ----------------------------------------------------------------------------
  703. proc ListBox::_getoption { path item option } {
  704. set value [Widget::getoption $path.$item $option]
  705. if {![string length $value]} {
  706. set value [Widget::getoption $path $option]
  707. }
  708. return $value
  709. }
  710. # ----------------------------------------------------------------------------
  711. # Command ListBox::_destroy
  712. # ----------------------------------------------------------------------------
  713. proc ListBox::_destroy { path } {
  714. variable $path
  715. upvar 0 $path data
  716. if { $data(upd,afterid) != "" } {
  717. after cancel $data(upd,afterid)
  718. }
  719. if { $data(dnd,afterid) != "" } {
  720. after cancel $data(dnd,afterid)
  721. }
  722. foreach item $data(items) {
  723. Widget::destroy $path.$item
  724. }
  725. Widget::destroy $path
  726. unset data
  727. }
  728. # ----------------------------------------------------------------------------
  729. # Command ListBox::_see
  730. # ----------------------------------------------------------------------------
  731. proc ListBox::_see { path idn side } {
  732. set bbox [$path.c bbox $idn]
  733. set scrl [$path.c cget -scrollregion]
  734. set ymax [lindex $scrl 3]
  735. set dy [$path.c cget -yscrollincrement]
  736. set yv [$path.c yview]
  737. set yv0 [expr {round([lindex $yv 0]*$ymax/$dy)}]
  738. set yv1 [expr {round([lindex $yv 1]*$ymax/$dy)}]
  739. set y [expr {int([lindex [$path.c coords $idn] 1]/$dy)}]
  740. if { $y < $yv0 } {
  741. $path.c yview scroll [expr {$y-$yv0}] units
  742. } elseif { $y >= $yv1 } {
  743. $path.c yview scroll [expr {$y-$yv1+1}] units
  744. }
  745. set xmax [lindex $scrl 2]
  746. set dx [$path.c cget -xscrollincrement]
  747. set xv [$path.c xview]
  748. if { [string equal $side "right"] } {
  749. set xv1 [expr {round([lindex $xv 1]*$xmax/$dx)}]
  750. set x1 [expr {int([lindex $bbox 2]/$dx)}]
  751. if { $x1 >= $xv1 } {
  752. $path.c xview scroll [expr {$x1-$xv1+1}] units
  753. }
  754. } else {
  755. set xv0 [expr {round([lindex $xv 0]*$xmax/$dx)}]
  756. set x0 [expr {int([lindex $bbox 0]/$dx)}]
  757. if { $x0 < $xv0 } {
  758. $path.c xview scroll [expr {$x0-$xv0}] units
  759. }
  760. }
  761. }
  762. # ----------------------------------------------------------------------------
  763. # Command ListBox::_update_scrollregion
  764. # ----------------------------------------------------------------------------
  765. proc ListBox::_update_scrollregion { path } {
  766. set bd [$path.c cget -borderwidth]
  767. set ht [$path.c cget -highlightthickness]
  768. set bd [expr {2*($bd + $ht)}]
  769. set w [expr {[winfo width $path] - $bd}]
  770. set h [expr {[winfo height $path] - $bd}]
  771. set xinc [$path.c cget -xscrollincrement]
  772. set yinc [$path.c cget -yscrollincrement]
  773. set bbox [$path.c bbox item win img]
  774. if { [llength $bbox] } {
  775. set xs [lindex $bbox 2]
  776. set ys [lindex $bbox 3]
  777. if { $w < $xs } {
  778. set w [expr {int($xs)}]
  779. if { [set r [expr {$w % $xinc}]] } {
  780. set w [expr {$w+$xinc-$r}]
  781. }
  782. }
  783. if { $h < $ys } {
  784. set h [expr {int($ys)}]
  785. if { [set r [expr {$h % $yinc}]] } {
  786. set h [expr {$h+$yinc-$r}]
  787. }
  788. }
  789. }
  790. $path.c configure -scrollregion [list 0 0 $w $h]
  791. }
  792. proc ListBox::_update_select_fill { path } {
  793. variable $path
  794. upvar 0 $path data
  795. set width [winfo width $path]
  796. foreach item $data(items) {
  797. set bbox [$path.c bbox n:$item]
  798. set bbox [list 0 [lindex $bbox 1] $width [lindex $bbox 3]]
  799. $path.c coords b:$item $bbox
  800. }
  801. _redraw_selection $path
  802. }
  803. # ----------------------------------------------------------------------------
  804. # Command ListBox::_draw_item
  805. # ----------------------------------------------------------------------------
  806. proc ListBox::_draw_item {path item x0 x1 y bg selfill multi ww} {
  807. set indent [Widget::getoption $path.$item -indent]
  808. set i [$path.c create text [expr {$x1+$indent}] $y \
  809. -text [Widget::getoption $path.$item -text] \
  810. -fill [_getoption $path $item -foreground] \
  811. -font [_getoption $path $item -font] \
  812. -anchor w \
  813. -tags [list item n:$item click]]
  814. if { $selfill && !$multi } {
  815. set bbox [$path.c bbox n:$item]
  816. set bbox [list 0 [lindex $bbox 1] $ww [lindex $bbox 3]]
  817. set tags [list box b:$item click]
  818. $path.c create rect $bbox -fill $bg -width 0 -tags $tags
  819. $path.c raise $i
  820. }
  821. if { [set win [Widget::getoption $path.$item -window]] != "" } {
  822. $path.c create window [expr {$x0+$indent}] $y \
  823. -window $win -anchor w -tags [list win i:$item]
  824. } elseif { [set img [Widget::getoption $path.$item -image]] != "" } {
  825. $path.c create image [expr {$x0+$indent}] $y \
  826. -image $img -anchor w -tags [list img i:$item]
  827. }
  828. _set_help $path $item
  829. }
  830. # ----------------------------------------------------------------------------
  831. # Command ListBox::_redraw_items
  832. # ----------------------------------------------------------------------------
  833. proc ListBox::_redraw_items { path } {
  834. variable $path
  835. upvar 0 $path data
  836. set cursor [$path.c cget -cursor]
  837. $path.c configure -cursor watch
  838. update idletasks ; # make sure watch cursor is reflected
  839. set dx [Widget::getoption $path -deltax]
  840. set dy [Widget::getoption $path -deltay]
  841. set padx [Widget::getoption $path -padx]
  842. set y0 [expr {$dy/2}]
  843. set x0 4
  844. set x1 [expr {$x0+$padx}]
  845. set nitem 0
  846. set drawn {}
  847. set data(xlist) {}
  848. if { [Widget::cget $path -multicolumn] } {
  849. set nrows $data(nrows)
  850. } else {
  851. set nrows [llength $data(items)]
  852. }
  853. foreach item $data(upd,delete) {
  854. $path.c delete i:$item n:$item s:$item b:$item
  855. }
  856. # Pass these to _draw_item so it doesn't have to request them
  857. # for each item.
  858. set bg [Widget::cget $path -background]
  859. set selfill [Widget::cget $path -selectfill]
  860. set multi [Widget::cget $path -multicolumn]
  861. set ww [winfo width $path]
  862. foreach item $data(items) {
  863. if { [info exists data(upd,create,$item)] } {
  864. _draw_item $path $item $x0 $x1 $y0 $bg $selfill $multi $ww
  865. unset data(upd,create,$item)
  866. } else {
  867. set indent [Widget::getoption $path.$item -indent]
  868. $path.c coords n:$item [expr {$x1+$indent}] $y0
  869. $path.c coords i:$item [expr {$x0+$indent}] $y0
  870. }
  871. incr y0 $dy
  872. incr nitem
  873. lappend drawn n:$item
  874. if { $nitem == $nrows } {
  875. set y0 [expr {$dy/2}]
  876. set bbox [eval [linsert $drawn 0 $path.c bbox]]
  877. set drawn {}
  878. set x0 [expr {[lindex $bbox 2]+$dx}]
  879. set x1 [expr {$x0+$padx}]
  880. set nitem 0
  881. lappend data(xlist) [lindex $bbox 2]
  882. }
  883. }
  884. if { $nitem && $nitem < $nrows } {
  885. set bbox [eval [linsert $drawn 0 $path.c bbox]]
  886. lappend data(xlist) [lindex $bbox 2]
  887. }
  888. set data(upd,delete) {}
  889. $path.c configure -cursor $cursor
  890. }
  891. # ----------------------------------------------------------------------------
  892. # Command ListBox::_redraw_selection
  893. # ----------------------------------------------------------------------------
  894. proc ListBox::_redraw_selection { path } {
  895. variable $path
  896. upvar 0 $path data
  897. set selbg [Widget::getoption $path -selectbackground]
  898. set selfg [Widget::getoption $path -selectforeground]
  899. set selfill [Widget::getoption $path -selectfill]
  900. set multi [Widget::getoption $path -multicolumn]
  901. foreach id [$path.c find withtag sel] {
  902. set item [string range [lindex [$path.c gettags $id] 1] 2 end]
  903. $path.c itemconfigure "n:$item" \
  904. -fill [_getoption $path $item -foreground]
  905. }
  906. $path.c delete sel
  907. if {$selfill && !$multi} {
  908. # cache window width for use below
  909. set width [winfo width $path]
  910. }
  911. foreach item $data(selitems) {
  912. set bbox [$path.c bbox "n:$item"]
  913. if { [llength $bbox] } {
  914. if { $selfill && !$multi } {
  915. # With -selectfill, make box occupy full width of widget
  916. set bbox [list 0 [lindex $bbox 1] $width [lindex $bbox 3]]
  917. }
  918. set tags [list sel s:$item click]
  919. set id [$path.c create rectangle $bbox \
  920. -fill $selbg -outline $selbg -tags $tags]
  921. $path.c itemconfigure "n:$item" -fill $selfg
  922. $path.c lower $id
  923. $path.c lower b:$item
  924. }
  925. }
  926. }
  927. # ----------------------------------------------------------------------------
  928. # Command ListBox::_redraw_listbox
  929. # ----------------------------------------------------------------------------
  930. proc ListBox::_redraw_listbox { path } {
  931. variable $path
  932. upvar 0 $path data
  933. if { [Widget::getoption $path -redraw] } {
  934. if { $data(upd,level) == 2 } {
  935. _redraw_items $path
  936. }
  937. _redraw_selection $path
  938. _update_scrollregion $path
  939. if {[Widget::cget $path -selectfill]} {
  940. _update_select_fill $path
  941. }
  942. set data(upd,level) 0
  943. set data(upd,afterid) ""
  944. }
  945. }
  946. # ----------------------------------------------------------------------------
  947. # Command ListBox::_redraw_idle
  948. # ----------------------------------------------------------------------------
  949. proc ListBox::_redraw_idle { path level } {
  950. variable $path
  951. upvar 0 $path data
  952. if { $data(nrows) != -1 } {
  953. # widget is realized
  954. if { [Widget::getoption $path -redraw] && $data(upd,afterid) == "" } {
  955. set data(upd,afterid) \
  956. [after idle [list ListBox::_redraw_listbox $path]]
  957. }
  958. }
  959. if { $level > $data(upd,level) } {
  960. set data(upd,level) $level
  961. }
  962. return ""
  963. }
  964. # ----------------------------------------------------------------------------
  965. # Command ListBox::_resize
  966. # ----------------------------------------------------------------------------
  967. proc ListBox::_resize { path } {
  968. variable $path
  969. upvar 0 $path data
  970. if { [Widget::getoption $path -multicolumn] } {
  971. set bd [expr {[$path.c cget -borderwidth]+[$path.c cget -highlightthickness]}]
  972. set h [expr {[winfo height $path] - 2*$bd}]
  973. set nrows [expr {$h/[$path.c cget -yscrollincrement]}]
  974. if { $nrows == 0 } {
  975. set nrows 1
  976. }
  977. if { $nrows != $data(nrows) } {
  978. set data(nrows) $nrows
  979. _redraw_idle $path 2
  980. } else {
  981. _update_scrollregion $path
  982. }
  983. } elseif { $data(nrows) == -1 } {
  984. # first Configure event
  985. set data(nrows) 0
  986. ListBox::_redraw_listbox $path
  987. if {[Widget::cget $path -selectfill]} {
  988. _update_select_fill $path
  989. }
  990. } else {
  991. if {[Widget::cget $path -selectfill]} {
  992. _update_select_fill $path
  993. }
  994. _update_scrollregion $path
  995. }
  996. }
  997. # ----------------------------------------------------------------------------
  998. # Command ListBox::_init_drag_cmd
  999. # ----------------------------------------------------------------------------
  1000. proc ListBox::_init_drag_cmd { path X Y top } {
  1001. set path [winfo parent $path]
  1002. set ltags [$path.c gettags current]
  1003. set item [lindex $ltags 0]
  1004. if { [string equal $item "item"] ||
  1005. [string equal $item "img"] ||
  1006. [string equal $item "win"] } {
  1007. set item [string range [lindex $ltags 1] 2 end]
  1008. if {[llength [set cmd [Widget::getoption $path -draginitcmd]]]} {
  1009. return [uplevel \#0 $cmd [list $path $item $top]]
  1010. }
  1011. if { [set type [Widget::getoption $path -dragtype]] == "" } {
  1012. set type "LISTBOX_ITEM"
  1013. }
  1014. if { [set img [Widget::getoption $path.$item -image]] != "" } {
  1015. pack [label $top.l -image $img -padx 0 -pady 0]
  1016. }
  1017. return [list $type {copy move link} $item]
  1018. }
  1019. return {}
  1020. }
  1021. # ----------------------------------------------------------------------------
  1022. # Command ListBox::_drop_cmd
  1023. # ----------------------------------------------------------------------------
  1024. proc ListBox::_drop_cmd { path source X Y op type dnddata } {
  1025. set path [winfo parent $path]
  1026. variable $path
  1027. upvar 0 $path data
  1028. if { [string length $data(dnd,afterid)] } {
  1029. after cancel $data(dnd,afterid)
  1030. set data(dnd,afterid) ""
  1031. }
  1032. $path.c delete drop
  1033. set data(dnd,scroll) ""
  1034. if { [llength $data(dnd,item)] || ![llength $data(items)] } {
  1035. if {[llength [set cmd [Widget::getoption $path -dropcmd]]]} {
  1036. return [uplevel \#0 $cmd [list $path $source $data(dnd,item) $op $type $dnddata]]
  1037. }
  1038. }
  1039. return 0
  1040. }
  1041. # ----------------------------------------------------------------------------
  1042. # Command ListBox::_over_cmd
  1043. # ----------------------------------------------------------------------------
  1044. proc ListBox::_over_cmd { path source event X Y op type dnddata } {
  1045. set path [winfo parent $path]
  1046. variable $path
  1047. upvar 0 $path data
  1048. if { [string equal $event "leave"] } {
  1049. # we leave the window listbox
  1050. $path.c delete drop
  1051. if { [string length $data(dnd,afterid)] } {
  1052. after cancel $data(dnd,afterid)
  1053. set data(dnd,afterid) ""
  1054. }
  1055. set data(dnd,scroll) ""
  1056. return 0
  1057. }
  1058. if { [string equal $event "enter"] } {
  1059. # we enter the window listbox - dnd data initialization
  1060. set mode [Widget::getoption $path -dropovermode]
  1061. set data(dnd,mode) 0
  1062. foreach c {w p i} {
  1063. set data(dnd,mode) [expr {($data(dnd,mode) << 1) | ([string first $c $mode] != -1)}]
  1064. }
  1065. }
  1066. set x [expr {$X-[winfo rootx $path]}]
  1067. set y [expr {$Y-[winfo rooty $path]}]
  1068. $path.c delete drop
  1069. set data(dnd,item) ""
  1070. # test for auto-scroll unless mode is widget only
  1071. if { $data(dnd,mode) != 4 && [_auto_scroll $path $x $y] != "" } {
  1072. return 2
  1073. }
  1074. if { $data(dnd,mode) & 4 } {
  1075. # dropovermode includes widget
  1076. set target [list widget]
  1077. set vmode 4
  1078. } else {
  1079. set target [list ""]
  1080. set vmode 0
  1081. }
  1082. if { ($data(dnd,mode) & 2) && ![llength $data(items)] } {
  1083. # dropovermode includes position and listbox is empty
  1084. lappend target "" 0
  1085. set vmode [expr {$vmode | 2}]
  1086. }
  1087. if { ($data(dnd,mode) & 3) && [llength $data(items)]} {
  1088. # dropovermode includes item or position
  1089. # we extract the box (xi,yi,xs,ys) where we can find item around x,y
  1090. set len [llength $data(items)]
  1091. set xc [$path.c canvasx $x]
  1092. set yc [$path.c canvasy $y]
  1093. set dy [$path.c cget -yscrollincrement]
  1094. set line [expr {int($yc/$dy)}]
  1095. set yi [expr {$line*$dy}]
  1096. set ys [expr {$yi+$dy}]
  1097. set xi 0
  1098. set pos $line
  1099. if { [Widget::getoption $path -multicolumn] } {
  1100. set nrows $data(nrows)
  1101. } else {
  1102. set nrows $len
  1103. }
  1104. if { $line < $nrows } {
  1105. foreach xs $data(xlist) {
  1106. if { $xc <= $xs } {
  1107. break
  1108. }
  1109. set xi $xs
  1110. incr pos $nrows
  1111. }
  1112. if { $pos < $len } {
  1113. set item [lindex $data(items) $pos]
  1114. set xi [expr {[lindex [$path.c coords n:$item] 0]-[Widget::getoption $path -padx]-1}]
  1115. if { $data(dnd,mode) & 1 } {
  1116. # dropovermode includes item
  1117. lappend target $item
  1118. set vmode [expr {$vmode | 1}]
  1119. } else {
  1120. lappend target ""
  1121. }
  1122. if { $data(dnd,mode) & 2 } {
  1123. # dropovermode includes position
  1124. if { $yc >= $yi+$dy/2 } {
  1125. # position is after $item
  1126. incr pos
  1127. set yl $ys
  1128. } else {
  1129. # position is before $item
  1130. set yl $yi
  1131. }
  1132. lappend target $pos
  1133. set vmode [expr {$vmode | 2}]
  1134. } else {
  1135. lappend target ""
  1136. }
  1137. } else {
  1138. lappend target "" ""
  1139. }
  1140. } else {
  1141. lappend target "" ""
  1142. }
  1143. if { ($vmode & 3) == 3 } {
  1144. # result have both item and position
  1145. # we compute what is the preferred method
  1146. if { $yc-$yi <= 3 || $ys-$yc <= 3 } {
  1147. lappend target "position"
  1148. } else {
  1149. lappend target "item"
  1150. }
  1151. }
  1152. }
  1153. if {$vmode && [llength [set cmd [Widget::getoption $path -dropovercmd]]]} {
  1154. # user-defined dropover command
  1155. set res [uplevel \#0 $cmd [list $source $target $op $type $dnddata]]
  1156. set code [lindex $res 0]
  1157. set vmode 0
  1158. if {$code & 1} {
  1159. # update vmode
  1160. switch -exact -- [lindex $res 1] {
  1161. item {set vmode 1}
  1162. position {set vmode 2}
  1163. widget {set vmode 4}
  1164. }
  1165. }
  1166. } else {
  1167. if { ($vmode & 3) == 3 } {
  1168. # result have both item and position
  1169. # we choose the preferred method
  1170. if { [string equal [lindex $target 3] "position"] } {
  1171. set vmode [expr {$vmode & ~1}]
  1172. } else {
  1173. set vmode [expr {$vmode & ~2}]
  1174. }
  1175. }
  1176. if { $data(dnd,mode) == 4 || $data(dnd,mode) == 0 } {
  1177. # dropovermode is widget or empty - recall is not necessary
  1178. set code 1
  1179. } else {
  1180. set code 3
  1181. }
  1182. }
  1183. # draw dnd visual following vmode
  1184. if {[llength $data(items)]} {
  1185. if { $vmode & 1 } {
  1186. set data(dnd,item) [list "item" [lindex $target 1]]
  1187. $path.c create rectangle $xi $yi $xs $ys -tags drop
  1188. } elseif { $vmode & 2 } {
  1189. set data(dnd,item) [concat "position" [lindex $target 2]]
  1190. $path.c create line $xi $yl $xs $yl -tags drop
  1191. } elseif { $vmode & 4 } {
  1192. set data(dnd,item) [list "widget"]
  1193. } else {
  1194. set code [expr {$code & 2}]
  1195. }
  1196. }
  1197. if { $code & 1 } {
  1198. DropSite::setcursor based_arrow_down
  1199. } else {
  1200. DropSite::setcursor dot
  1201. }
  1202. return $code
  1203. }
  1204. # ----------------------------------------------------------------------------
  1205. # Command ListBox::_auto_scroll
  1206. # ----------------------------------------------------------------------------
  1207. proc ListBox::_auto_scroll { path x y } {
  1208. variable $path
  1209. upvar 0 $path data
  1210. set xmax [winfo width $path]
  1211. set ymax [winfo height $path]
  1212. set scroll {}
  1213. if { $y <= 6 } {
  1214. if { [lindex [$path.c yview] 0] > 0 } {
  1215. set scroll [list yview -1]
  1216. DropSite::setcursor sb_up_arrow
  1217. }
  1218. } elseif { $y >= $ymax-6 } {
  1219. if { [lindex [$path.c yview] 1] < 1 } {
  1220. set scroll [list yview 1]
  1221. DropSite::setcursor sb_down_arrow
  1222. }
  1223. } elseif { $x <= 6 } {
  1224. if { [lindex [$path.c xview] 0] > 0 } {
  1225. set scroll [list xview -1]
  1226. DropSite::setcursor sb_left_arrow
  1227. }
  1228. } elseif { $x >= $xmax-6 } {
  1229. if { [lindex [$path.c xview] 1] < 1 } {
  1230. set scroll [list xview 1]
  1231. DropSite::setcursor sb_right_arrow
  1232. }
  1233. }
  1234. if { [string length $data(dnd,afterid)] && ![string equal $data(dnd,scroll) $scroll] } {
  1235. after cancel $data(dnd,afterid)
  1236. set data(dnd,afterid) ""
  1237. }
  1238. set data(dnd,scroll) $scroll
  1239. if { [llength $scroll] && ![string length $data(dnd,afterid)] } {
  1240. set data(dnd,afterid) [after 200 [list ListBox::_scroll $path $scroll]]
  1241. }
  1242. return $data(dnd,afterid)
  1243. }
  1244. # -----------------------------------------------------------------------------
  1245. # Command ListBox::_multiple_select
  1246. # -----------------------------------------------------------------------------
  1247. proc ListBox::_multiple_select { path mode x y idx } {
  1248. variable $path
  1249. upvar 0 $path data
  1250. if { ![info exists data(anchor)] || ![info exists data(sel_anchor)] } {
  1251. set data(anchor) $idx
  1252. set data(sel_anchor) {}
  1253. }
  1254. switch -exact -- $mode {
  1255. n {
  1256. _mouse_select $path set $idx
  1257. set data(anchor) $idx
  1258. set data(sel_anchor) {}
  1259. }
  1260. c {
  1261. set l [_mouse_select $path get]
  1262. if { [lsearch -exact $l $idx] >= 0 } {
  1263. _mouse_select $path remove $idx
  1264. } else {
  1265. _mouse_select $path add $idx
  1266. }
  1267. set data(anchor) $idx
  1268. set data(sel_anchor) {}
  1269. }
  1270. s {
  1271. eval [list $path _mouse_select remove] $data(sel_anchor)
  1272. set ix [$path index $idx]
  1273. set ia [$path index $data(anchor)]
  1274. if { $ix > $ia } {
  1275. set istart $ia
  1276. set iend $ix
  1277. } else {
  1278. set istart $ix
  1279. set iend $ia
  1280. }
  1281. for { set i $istart } { $i <= $iend } { incr i } {
  1282. set l [$path selection get]
  1283. set t [$path items $i]
  1284. set li [lsearch -exact $l $t]
  1285. if { $li < 0 } {
  1286. _mouse_select $path add $t
  1287. lappend data(sel_anchor) $t
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. # ----------------------------------------------------------------------------
  1294. # Command ListBox::_scroll
  1295. # ----------------------------------------------------------------------------
  1296. proc ListBox::_scroll { path cmd dir } {
  1297. variable $path
  1298. upvar 0 $path data
  1299. if { ($dir == -1 && [lindex [$path.c $cmd] 0] > 0) ||
  1300. ($dir == 1 && [lindex [$path.c $cmd] 1] < 1) } {
  1301. $path $cmd scroll $dir units
  1302. set data(dnd,afterid) \
  1303. [after 100 [list ListBox::_scroll $path $cmd $dir]]
  1304. } else {
  1305. set data(dnd,afterid) ""
  1306. DropSite::setcursor dot
  1307. }
  1308. }
  1309. # ListBox::_set_help --
  1310. #
  1311. # Register dynamic help for an item in the listbox.
  1312. #
  1313. # Arguments:
  1314. # path ListBox to query
  1315. # item Item in the listbox
  1316. # force Optional argument to force a reset of the help
  1317. #
  1318. # Results:
  1319. # none
  1320. proc ListBox::_set_help { path node } {
  1321. Widget::getVariable $path help
  1322. set item $path.$node
  1323. set opts [list -helptype -helptext -helpvar]
  1324. foreach {cty ctx cv} [eval [linsert $opts 0 Widget::hasChangedX $item]] break
  1325. set text [Widget::getoption $item -helptext]
  1326. ## If we've never set help for this item before, and text is not blank,
  1327. ## we need to setup help. We also need to reset help if any of the
  1328. ## options have changed.
  1329. if { (![info exists help($node)] && $text != "") || $cty || $ctx || $cv } {
  1330. set help($node) 1
  1331. set type [Widget::getoption $item -helptype]

Large files files are truncated, but you can click here to view the full file