hor. scroll on selection: changed algorithm
authorca
Mon, 29 Nov 2004 15:53:42 +0100
changeset 2780 692ba895ad57
parent 2779 e5b0570c2c32
child 2781 062d03cf175e
hor. scroll on selection: changed algorithm
HierarchicalListView.st
--- a/HierarchicalListView.st	Thu Nov 25 15:38:36 2004 +0100
+++ b/HierarchicalListView.st	Mon Nov 29 15:53:42 2004 +0100
@@ -371,9 +371,10 @@
 !HierarchicalListView methodsFor:'accessing-behavior'!
 
 autoScrollHorizontal
-    "true, than automatically scroll horizontal upto the text label
-     of the current selected line.
-    "
+    "returns true if automatic horizontal scrolling 
+     (upto the text label of the selected line)
+     is allowed (the default is true)."
+
     autoScrollHorizontal == true ifTrue:[
         ^ renderer autoScrollHorizontal
     ].
@@ -1592,40 +1593,50 @@
     self scrollTo:(vwOrgX @ vwOrgY).
 !
 
-makeLineVisible:aLnrNr
-    "make the line horizontal and vertical visible
+makeLineVisible:aLineNumber
+    "make the line horizontally and vertically visible
     "
-    |newY item y0 newX|
+    |newY item y0 oldX newX wLine|
 
     alignTextRight ifTrue:[^ self].
 
-    (shown and:[aLnrNr notNil]) ifFalse:[^ self].
+    (shown and:[aLineNumber notNil]) ifFalse:[^ self].
 
-    aLnrNr <= 1 ifTrue:[
-        aLnrNr == 1 ifTrue:[
-            newX := self computeViewOriginXat:1.
-            self scrollTo:(newX @ 0).
-        ].
+    aLineNumber < 1 ifTrue:[
         ^ self
     ].
 
-    item := self at:aLnrNr ifAbsent:nil.
-    item isNil ifTrue:[^ self].
+    newX := oldX := viewOrigin x.
 
-    y0 := self yVisibleOfLine:aLnrNr.
+    aLineNumber == 1 ifTrue:[
+        newX := self computeViewOriginXat:1.
+        newY := 0.
+    ] ifFalse:[
+        item := self at:aLineNumber ifAbsent:nil.
+        item isNil ifTrue:[^ self].
+
+        y0 := self yVisibleOfLine:aLineNumber.
 
-    (     y0 < margin
-     or:[(y0 + (renderer heightFor:item)) > (height - margin)]
-    ) ifTrue:[
-        newY := ((self yAbsoluteOfLine:aLnrNr) - (height // 2)) max:0.
-    ] ifFalse:[
-        newY := viewOrigin y.
-    ].
+        (     y0 < margin
+         or:[(y0 + (renderer heightFor:item)) > (height - margin)]
+        ) ifTrue:[
+            newY := ((self yAbsoluteOfLine:aLineNumber) - (height // 2)) max:0.
+        ] ifFalse:[
+            newY := viewOrigin y.
+        ].
 
-    newX := viewOrigin x.
-
-    (self autoScrollHorizontal or:[newX ~~ 0]) ifTrue:[
-        newX := self computeViewOriginXat:aLnrNr
+        self autoScrollHorizontal ifTrue:[
+            wLine := self widthOfWidestLineBetween:aLineNumber and:aLineNumber.
+            (wLine < self innerWidth) ifTrue:[
+                (oldX == 0) ifTrue:[
+                    newX := self computeViewOriginXat:aLineNumber.
+                ] ifFalse:[
+                    newX := 0
+                ].
+            ] ifFalse:[
+                newX := self computeViewOriginXat:aLineNumber.
+            ].
+        ].
     ].
     self scrollTo:(newX @ newY).
 ! !
@@ -1633,5 +1644,5 @@
 !HierarchicalListView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.93 2004-10-28 12:38:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.94 2004-11-29 14:53:42 ca Exp $'
 ! !