Tk Library Source Code

Artifact [6946891638]
Login

Artifact 6946891638ee0d31a638606b51efc6c7939e67f0:

Attachment "listbox-speed.patch" to ticket [1472443fff] added by jepler 2006-04-18 23:19:53.
--- listbox.tcl.orig	2006-04-18 08:52:23.000000000 -0500
+++ listbox.tcl	2006-04-18 10:02:34.000000000 -0500
@@ -252,13 +252,18 @@
 
     set item [Widget::nextIndex $path $item]
 
-    if { [lsearch -exact $data(items) $item] != -1 } {
+    if { [info exists data(exists,$item)] } {
         return -code error "item \"$item\" already exists"
     }
 
     Widget::init ListBox::Item $path.$item $args
 
-    set data(items) [linsert $data(items) $index $item]
+    if {$index == "end"} {
+        lappend data(items) $item
+    } else {
+        set data(items) [linsert $data(items) $index $item]
+    }
+    set data(exists,$item) 1
     set data(upd,create,$item) $item
 
     _redraw_idle $path 2
@@ -294,7 +299,7 @@
 
     set count 0
     foreach {item iargs} $args {
-	if { [lsearch -exact $data(items) $item] != -1 } {
+        if { [info exists data(exists,$item)] } {
 	    return -code error "item \"$item\" already exists"
 	}
 	
@@ -306,6 +311,7 @@
 	}
 
 	set data(items) [linsert $data(items) $index $item]
+        set data(exists,$item) 1
 	set data(upd,create,$item) $item
 
 	incr count
@@ -450,6 +456,9 @@
             if { $idx != -1 } {
                 set data(items) [lreplace $data(items) $idx $idx]
                 Widget::destroy $path.$item
+                if { [info exists data(exists,$item)] } {
+                    unset data(exists,$item)
+                }
                 if { [info exists data(upd,create,$item)] } {
                     unset data(upd,create,$item)
                 } else {
@@ -991,6 +1000,7 @@
     set x0   4
     set x1   [expr {$x0+$padx}]
     set nitem 0
+    set width 0
     set drawn {}
     set data(xlist) {}
     if { [Widget::cget $path -multicolumn] } {
@@ -1010,22 +1020,26 @@
             $path.c coords n:$item [expr {$x1+$indent}] $y0
             $path.c coords i:$item [expr {$x0+$indent}] $y0
         }
+        set font [_getoption $path $item -font]
+        set text [Widget::getoption $path.$item -text]
+        set tw [font measure $font $text]
+        if {$tw > $width} { set width $tw }
         incr y0 $dy
         incr nitem
         lappend drawn n:$item
         if { $nitem == $nrows } {
+            set x2    [expr $x1 + $width]
             set y0    [expr {$dy/2}]
-            set bbox  [eval [list $path.c bbox] $drawn]
             set drawn {}
-            set x0    [expr {[lindex $bbox 2]+$dx}]
+            set x0    [expr $x2+$dx]
             set x1    [expr {$x0+$padx}]
             set nitem 0
-            lappend data(xlist) [lindex $bbox 2]
+            lappend data(xlist) $x2
+            set width 0
         }
     }
     if { $nitem && $nitem < $nrows } {
-        set bbox  [eval [list $path.c bbox] $drawn]
-        lappend data(xlist) [lindex $bbox 2]
+        lappend data(xlist) [expr $x1 + $width]
     }
     set data(upd,delete) {}
     $path.c configure -cursor $cursor