class: ListView
authorClaus Gittinger <cg@exept.de>
Fri, 06 Sep 2013 14:37:23 +0200
changeset 4749 9f4dfdcf92b8
parent 4748 3f24bdf8a355
child 4750 0b55ac6feb54
class: ListView changed: #widthOfContents tinung for huge collections (widthOfContents computation)
ListView.st
--- a/ListView.st	Fri Sep 06 14:24:32 2013 +0200
+++ b/ListView.st	Fri Sep 06 14:37:23 2013 +0200
@@ -3478,7 +3478,12 @@
     "return the width of the contents in pixels
      - used for scrollbar interface"
 
-    |max f d lengthOfLongestString lengthOfLongestLine|
+    |f d 
+     start "{ Class: SmallInteger }"
+     stop  "{ Class: SmallInteger }"
+     lengthOfLongestString  "{ Class: SmallInteger }"
+     lengthOfLongestLine    "{ Class: SmallInteger }"
+     max   "{ Class: SmallInteger }"|
 
     list isNil ifTrue:[^ 0].
     widthOfWidestLine notNil ifTrue:[^ widthOfWidestLine + (leftMargin * 2)].
@@ -3489,27 +3494,35 @@
     ].
     f := font := font onDevice:d.
 
+    start := 1.
+    stop := numberOfLinesForWidthOfContentsComputation 
+                isNil 
+                    ifTrue:[ list size ]
+                    ifFalse:[ (numberOfLinesForWidthOfContentsComputation max:1) min: list size ].
+
     includesNonStrings ifTrue:[
-        max := list
-                   inject:0
-                   into:[:maxSoFar :entry |
-                             (
-                                 entry isNil ifTrue:[
-                                     0
-                                 ] ifFalse:[
-                                    entry isString ifTrue:[
-                                        f widthOf:entry
-                                    ] ifFalse:[
-                                        entry widthOn:self
-                                    ]
-                                 ]
-                             ) max:maxSoFar.
-                        ]
+        max := 0.
+        start to:stop do:[:lineNr |
+            |entry w|
+
+            entry := list at:lineNr.
+            entry notNil ifTrue:[
+                entry isString ifTrue:[
+                    w := f widthOf:entry
+                ] ifFalse:[
+                    w := entry widthOn:self
+                ].
+                max := max max:w.
+             ].
+        ].
     ] ifFalse:[
         fontIsFixedWidth ifTrue:[
             max := lengthOfLongestString := 0.
             list notNil ifTrue:[
-                list do:[:line |
+                start to:stop do:[:lineNr |
+                    |line|
+
+                    line := list at:lineNr.
                     line notNil ifTrue:[
                         (line isString and:[line hasChangeOfEmphasis not]) ifTrue:[
                             line size > lengthOfLongestString ifTrue:[
@@ -3525,9 +3538,10 @@
         ] ifFalse:[
             max := lengthOfLongestLine := 0.
             list notNil ifTrue:[
-                list do:[:line |
-                    |len|
-
+                start to:stop do:[:lineNr |
+                    |line len|
+
+                    line := list at:lineNr.
                     line notNil ifTrue:[
                         len := line size.
                         "/ consider this a speed hack (not exact, but fast)
@@ -5134,10 +5148,10 @@
 !ListView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.379 2013-09-06 12:24:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.380 2013-09-06 12:37:23 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.379 2013-09-06 12:24:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.380 2013-09-06 12:37:23 cg Exp $'
 ! !