Tk Library Source Code

Artifact [896ff43bae]
Login

Artifact 896ff43baee0a54620d171a7099468416d509431:

Attachment "listbox.patch" to ticket [3324610fff] added by takatsuki 2011-06-23 00:09:41.
--- ../listbox.tcl	2010-05-12 10:12:34.000000000 +0200
+++ listbox.tcl	2011-06-22 18:23:24.415330033 +0200
@@ -667,7 +667,7 @@
                      [string equal $item "img"]  ||
                      [string equal $item "win"] } {
                     # item is the label or image/window of the node
-                    set item [string range [lindex $ltags 1] 2 end]
+                    set item [ListBox::_get_node_name $path $id]
                     set found 1
                     break
                 }
@@ -1116,7 +1116,7 @@
     set selfill [Widget::getoption $path -selectfill]
     set multi   [Widget::getoption $path -multicolumn]
     foreach id [$path.c find withtag sel] {
-        set item [string range [lindex [$path.c gettags $id] 1] 2 end]
+        set item [ListBox::_get_node_name $path $id]
         if {-1 == [lsearch -exact $data(upd,delete) $item]} {
             $path.c itemconfigure "n:$item" \
                 -fill [_getoption $path $item -foreground]
@@ -1238,7 +1238,7 @@
     if { [string equal $item "item"] ||
          [string equal $item "img"]  ||
          [string equal $item "win"] } {
-        set item [string range [lindex $ltags 1] 2 end]
+        set item [ListBox::_get_node_name $path $id]
         if {[llength [set cmd [Widget::getoption $path -draginitcmd]]]} {
             return [uplevel \#0 $cmd [list $path $item $top]]
         }
@@ -1636,10 +1636,31 @@
     }
 }
 
+# ListBox::_get_node_name --
+#
+#	Given a listbox item, get the name of the node represented by that
+#	item.
+#
+# Arguments:
+#	path		listbox to query
+#	item		Optional item to examine; if omitted, 
+#			defaults to "current"
+#
+# Results:
+#	node	name of the listbox node.
+
+proc ListBox::_get_node_name {path {item current}} {
+    set tags [$path.c gettags $item]
+    if {[lindex $tags 0] == "img"} {
+        set node [string range [lindex $tags 2] 2 end]
+    } else {
+        set node [string range [lindex $tags 1] 2 end]
+    }
+    return $node
+}
 
 proc ListBox::_get_current { path } {
-    set t [$path.c gettags current]
-    return [string range [lindex $t 1] 2 end]
+    return [ListBox::_get_node_name $path]
 }