HierarchicalItem.st
changeset 1540 3fab5658652a
parent 1539 646c83d24f77
child 1571 a230fb988d3e
--- a/HierarchicalItem.st	Mon Sep 20 15:14:26 1999 +0200
+++ b/HierarchicalItem.st	Mon Sep 20 18:40:34 1999 +0200
@@ -745,6 +745,82 @@
     isExpanded := aBoolean
 ! !
 
+!HierarchicalItem methodsFor:'private displaying'!
+
+displayLabel:aLabel on:aGC x:x y:y h:h
+    "display the label at x@y
+    "
+    |y0 lH hF|
+
+    lH := self heightOf:aLabel on:aGC.
+    lH == 0 ifTrue:[^ self].
+
+    y0 := y - (lH + 1 - h // 2).
+
+    aLabel isImageOrForm ifTrue:[
+        ^ aLabel displayOn:aGC x:x y:y0
+    ].
+    y0 := y0 + (aGC font ascent).
+
+    aLabel isString ifFalse:[
+        ^ aLabel displayOn:aGC x:x y:y0
+    ].
+
+    (aLabel indexOf:(Character cr)) == 0 ifTrue:[
+        ^ aLabel displayOn:aGC x:x y:y0
+    ].
+
+    hF := aGC font height.
+
+    aLabel asCollectionOfLines do:[:el|
+        el displayOn:aGC x:x y:y0.
+        y0 := y0 + hF
+    ].
+!
+
+heightOf:aLabel on:aGC
+    "returns the height of the label or 0
+    "
+    |h|
+
+    aLabel isSequenceable ifFalse:[
+        ^ aLabel notNil ifTrue:[aLabel heightOn:aGC] ifFalse:[0]
+    ].
+
+    aLabel isString ifFalse:[
+        h := 0.
+        aLabel do:[:el|h := h max:(self heightOf:el on:aGC)].
+      ^ h
+    ].
+
+    h := 1 + (aLabel occurrencesOf:(Character cr)).
+    ^ h * (aGC font height)
+!
+
+widthOf:aLabel on:aGC
+    "returns the height of the label or 0
+    "
+    |w|
+
+    aLabel isSequenceable ifFalse:[
+        ^ aLabel notNil ifTrue:[aLabel widthOn:aGC] ifFalse:[0]
+    ].
+
+    aLabel isString ifFalse:[
+        w := -5.
+        aLabel do:[:el|w := w + 5 + (self widthOf:el on:aGC)].
+      ^ w
+    ].
+
+    (aLabel indexOf:(Character cr)) == 0 ifTrue:[
+        ^ aLabel widthOn:aGC
+    ].
+
+    w := 0.
+    aLabel asCollectionOfLines do:[:el|w := w max:(el widthOn:aGC)].
+  ^ w
+! !
+
 !HierarchicalItem methodsFor:'private hierarchy'!
 
 recursiveSetCollapsed
@@ -830,79 +906,33 @@
     "draw the receiver in the graphicsContext, aGC.
     "
     |label
-     yF "{ Class:SmallInteger }"
      x0 "{ Class:SmallInteger }"
-     y0 "{ Class:SmallInteger }"
-     ascent "{ Class:SmallInteger }"
-     xMax "{ Class:SmallInteger }"
     |
-    (label := self label) isNil ifTrue:[
-        ^ self
-    ].
+    (label := self label) isNil ifTrue:[^ self].
 
     (label isSequenceable and:[label isString not]) ifFalse:[
-        y0 := y - ((label heightOn:aGC) + 1 - h // 2).
-
-        label isImageOrForm ifTrue:[
-            label displayOn:aGC x:x y:y0
-        ] ifFalse:[
-            label displayOn:aGC x:x y:(y0 + aGC font ascent)
-        ].
-        ^ self
+        ^ self displayLabel:label on:aGC x:x y:y h:h
     ].
 
-    xMax   := aGC clippingBounds right.
-    x0     := x.
-    ascent := aGC font ascent.
-
+    x0 := x.
     label do:[:el|
         el notNil ifTrue:[
-            y0 := y - ((el heightOn:aGC) + 1 - h // 2).
-            el isImageOrForm ifFalse:[
-                y0 := y0 + ascent
-            ].
-            el displayOn:aGC x:x0 y:y0.
+            self displayLabel:el on:aGC x:x0 y:y h:h.
             x0 := x0 + 5 + (el widthOn:aGC).
-
-            x0 < xMax ifFalse:[
-                ^ self
-            ]
-        ]
+        ].
     ]
 !
 
 heightOn:aGC
     "return the width of the receiver, if it is to be displayed on aGC
     "
-    |label h "{ Class:SmallInteger }"|
-
-    (label := self label) isNil ifTrue:[
-        ^ 0
-    ].
-    (label isString or:[label isSequenceable not]) ifTrue:[
-        ^ label heightOn:aGC
-    ].
-    h := 0.
-    label do:[:el| el notNil ifTrue:[h := (el heightOn:aGC) max:h]].
-  ^ h
-
+    ^ self heightOf:(self label) on:aGC
 !
 
 widthOn:aGC
     "return the width of the receiver, if it is to be displayed on aGC
     "
-    |label w "{ Class:SmallInteger }"|
-
-    (label := self label) isNil ifTrue:[
-        ^ 0
-    ].
-    (label isString or:[label isSequenceable not]) ifTrue:[
-        ^ label widthOn:aGC
-    ].
-
-    w := -5.
-    label do:[:el|el notNil ifTrue:[w := w + 5 + (el widthOn:aGC)]].
-  ^ w
+    ^ self widthOf:(self label) on:aGC
 ! !
 
 !HierarchicalItem methodsFor:'protocol monitoring'!
@@ -1084,7 +1114,7 @@
 !HierarchicalItem::Example methodsFor:'accessing'!
 
 children
-    |lvl lbl txt image img icon|
+    |lvl lbl txt image img icon tmp|
 
     children notNil ifTrue:[
         ^ children
@@ -1106,7 +1136,10 @@
                 lbl := img
             ] ifFalse:[
                 i == 4 ifTrue:[
-                    lbl := self class penguinIcon
+                    tmp := #( 'penguin' 'and' 'text') asStringCollection asString.
+                    tmp removeLast.
+                    lbl := Array with:(self class penguinIcon)
+                                 with:tmp.
                 ] ifFalse:[
                     lbl := txt, (i printString), ']'
                 ]
@@ -1185,5 +1218,5 @@
 !HierarchicalItem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.10 1999-09-20 13:14:26 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.11 1999-09-20 16:40:34 cg Exp $'
 ! !