HierarchicalListView.st
changeset 3977 e81ca26b8a23
parent 3937 d705c5da9d20
child 3978 d3d9bdf72a52
--- a/HierarchicalListView.st	Thu Dec 02 08:18:00 2010 +0100
+++ b/HierarchicalListView.st	Thu Dec 02 17:48:50 2010 +0100
@@ -973,166 +973,98 @@
 !
 
 drawLinesFrom:start to:stop x:xL y:yT toX:xR
-    "draw the lines between start to stop without clearing the background
-    "
-    |item prevItem parent p1 p2 showVLines showHLine lv buildInArray showLeftIdc
+    "draw the lines between start to stop without clearing the background"
 
-     x        "{ Class:SmallInteger }"
-     xText    "{ Class:SmallInteger }"
+    |item yNext|
 
-     y        "{ Class:SmallInteger }"
-     yTop     "{ Class:SmallInteger }"
-     yBot     "{ Class:SmallInteger }"
-     yCtr     "{ Class:SmallInteger }"
+    item := list at:start ifAbsent:[^ nil ].
 
-     begHLnY  "{ Class:SmallInteger }"
-     runHLnY  "{ Class:SmallInteger }"
-     lftVrtX  "{ Class:SmallInteger }"
-     rgtVrtX  "{ Class:SmallInteger }"
-     level    "{ Class:SmallInteger }"
+    self maskOrigin:( (self viewOrigin + (0 @ 1)) \\ (lineMask extent)).
+    self paint:lineColor on:bgColor.
 
-     minVertLevel   "{ Class:SmallInteger }"
-     minHorzLevel   "{ Class:SmallInteger }"
-     smallestLevel  "{ Class:SmallInteger }"
-    |
-    parent := prevItem := 4711. "/ to force a recompute
-
-    self maskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)).
-    self paint:lineColor on:bgColor.
-    "/ mhmh - masked draw does not seem to work under win32;
-    "/ dotted drawing is actually dashed;
-    "/ all is so ugly; so we dont draw at all
-    false "OperatingSystem isMSWINDOWSlike" ifTrue:[
+    false ifTrue:[ "/OperatingSystem isMSWINDOWSlike ifTrue:[
+        self mask:nil.
         self lineStyle:#dotted.
     ] ifFalse:[
         self mask:lineMask.
     ].
 
-    smallestLevel := self smallestLevelBetween:start and:stop.
-    minVertLevel  := 2.
-
-    showLeftIndicators ifTrue:[
-        showLeftIdc := showIndicators.
-        showRoot ifFalse:[ minVertLevel := 3 ]
-    ] ifFalse:[
-        showLeftIdc := false.
+    "/ draw all vertical lines
+    list from:start to:stop do:[:eachItem|
+        self drawVericalLineForElement:eachItem minX:xL maxX:xR.
+    ].
+    [ (item := item parent) notNil ] whileTrue:[
+        self drawVericalLineForElement:item minX:xL maxX:xR.
     ].
 
-    showRoot ifFalse:[ minHorzLevel := 2 ]
-              ifTrue:[ minHorzLevel := 1 ].
-
-    showLeftIdc ifFalse:[
-        minHorzLevel := minHorzLevel + 1.
-    ].
-
-    yBot  := begHLnY := runHLnY := yT.
-    level := 1.
+    "/ draw all the horizontal lines
+    yNext := self yVisibleOfLine:start.
 
     start to:stop do:[:anIndex|
-        (item := self at:anIndex ifAbsent:nil) isNil ifTrue:[
-            "/ list changed
-            self lineStyle:#solid.
-            self mask:nil.     
-            ^ self    
-        ].
-        yTop := yBot.
-        yBot := self yVisibleOfLine:(anIndex + 1).
-        yCtr := yTop + (yBot - yTop // 2).
+        |y0 index x0 x1 itemLevel|
 
-        item parent ~~ parent ifTrue:[
-            anIndex == 1 ifTrue:[ begHLnY := runHLnY := yCtr ].
-            parent := item parent.
-
-            prevItem == parent ifTrue:[
-                level   := level + 1.
-                lftVrtX := rgtVrtX.
-            ] ifFalse:[
-                level   := item level.
-                lftVrtX := self xVisibleOfVerticalLineAt:level.
+        item := list at:anIndex
+            ifAbsent:[
+                self lineStyle:#solid.
+                self mask:nil.
+                ^ self
             ].
-            showVLines := (level >= minVertLevel and:[lftVrtX >= xL]).
-            rgtVrtX    := self xVisibleOfVerticalLineAt:level + 1.
 
-            level >= minHorzLevel ifTrue:[
-                xText := (self xVisibleOfTextAtLevel:level) - textStartLeft.
-                showHLine := (xL < xText and:[xR > lftVrtX]).
-            ] ifFalse:[
-                showHLine := false
-            ].
-        ].
+        y0    := yNext.
+        yNext := self yVisibleOfLine:anIndex + 1.
 
-        showHLine ifTrue:[
-            ( level ~~ 2
-             or:[showRoot or:[(showLeftIdc and:[item hasIndicator])]]
-            ) ifTrue:[
-                item drawHorizontalLineUpToText ifTrue:[ x := xText ]
-                                               ifFalse:[ x := rgtVrtX ].
-
-                self displayLineFromX:lftVrtX y:yCtr toX:x y:yCtr.
-            ].
+        item parent isNil ifTrue:[
+            index := showRoot ifTrue:[0] ifFalse:[-1].
+        ] ifFalse:[
+            index := list identityIndexOf:(item parent).
         ].
-
-        anIndex == start ifTrue:[
-            (item isExpanded and:[item hasChildren]) ifTrue:[
-                self displayLineFromX:rgtVrtX y:yCtr toX:rgtVrtX y:yBot.
+        index == 0 ifTrue:[
+            (showLeftIndicators and:[item hasIndicator]) ifTrue:[
+                index := 1.
             ]
         ].
 
-        showVLines ifTrue:[
-            parent last == item ifTrue:[ y := yCtr ]
-                               ifFalse:[ y := yBot ].
-            x  := lftVrtX.
-            p2 := parent.
-            lv := level - 1.
+        index > 0 ifTrue:[
+            itemLevel := item level.
+
+            x0 := self xVisibleOfVerticalLineAt:itemLevel.
 
-            level >= smallestLevel ifTrue:[
-                self displayLineFromX:x y:runHLnY toX:x y:y.
-            ].
+            item drawHorizontalLineUpToText ifTrue:[
+                x1 := (self xVisibleOfTextAtLevel:itemLevel) - textStartLeft.
+            ] ifFalse:[
+                x1 := self xVisibleOfVerticalLineAt:(itemLevel + 1).
+            ].                
+            y0 := (y0 + yNext ) // 2.
+            self displayLineFromX:x0 y:y0 toX:x1 y:y0.
+        ].
+    ].
 
-            [ (p2 notNil and:[lv >= minVertLevel]) ] whileTrue:[
-                p1 := p2 parent.
+    self lineStyle:#solid.
+    self mask:nil.
+!
 
-                p1 notNil ifTrue:[
-                    x := self xVisibleOfVerticalLineAt:lv.
+drawVericalLineForElement:item minX:xL maxX:xR
+    "draw the vertical line my children are connected to"
+
+    |itemLevel y0 y1 x0|
 
-                    x < xL ifTrue:[
-                        p1 := nil.
-                    ] ifFalse:[
-                        p1 last ~~ p2 ifTrue:[
-                            lv >= smallestLevel ifTrue:[
-                                self displayLineFromX:x y:(yTop - 1) toX:x y:yBot
-                            ] ifFalse:[
-                                buildInArray isNil ifTrue:[buildInArray := Array new:smallestLevel].
-                                buildInArray at:lv put:yBot
-                            ]
-                        ].
-                    ].
-                ].
-                p2 := p1.
-                lv := lv - 1.
+    (item notNil and:[item isExpanded and:[item hasChildren]]) ifTrue:[
+        itemLevel := item level.
+        
+        itemLevel == 1 ifTrue:[
+            showRoot ifFalse:[^ self].
+        ].
+        x0 := self xVisibleOfVerticalLineAt:(itemLevel + 1).
+
+        (x0 between:xL and:xR) ifTrue:[
+            y0 := self yVisibleOfIndicatorForItem:item.
+            y1 := self yVisibleOfIndicatorForItem:(item last).
+
+            y1 > y0 ifTrue:[
+                self displayLineFromX:x0 y:y0 toX:x0 y:y1.
             ].
         ].
-        prevItem := item.
-        runHLnY  := yCtr.
     ].
-
-    buildInArray notNil ifTrue:[
-        y := begHLnY.
-
-        2 to:smallestLevel do:[:i| |u yB|
-            (yB := buildInArray at:i) notNil ifTrue:[
-                x := self xVisibleOfVerticalLineAt:i.
-
-                x >= xL ifTrue:[
-                    self displayLineFromX:x y:y toX:x y:yB
-                ]
-            ].
-        ]
-    ].
-    self lineStyle:#solid.
-    self mask:nil.
-
-    "Modified: / 06-10-2010 / 16:44:01 / cg"
 !
 
 validateDrawableIconFor:anItem
@@ -1632,6 +1564,19 @@
     ].
     "/ 2 := a left margin
     ^ xOffset + 2 - (viewOrigin x)
+!
+
+yVisibleOfIndicatorForItem:anItem
+    |index y0 y1|
+
+    index := list identityIndexOf:anItem.
+    index > 0 ifTrue:[
+        y0 := self yVisibleOfLine:index.
+        y1 := self yVisibleOfLine:(index + 1).
+
+        ^ (y0 + y1) // 2.
+    ].
+    ^ 0
 ! !
 
 !HierarchicalListView methodsFor:'scrolling'!
@@ -1746,9 +1691,9 @@
 !HierarchicalListView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.121 2010-10-06 14:44:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.122 2010-12-02 16:48:50 ca Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.121 2010-10-06 14:44:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.122 2010-12-02 16:48:50 ca Exp $'
 ! !