--- a/HierarchicalListView.st Fri Nov 22 08:23:24 2002 +0100
+++ b/HierarchicalListView.st Fri Nov 22 11:28:02 2002 +0100
@@ -15,10 +15,10 @@
SelectionInListModelView subclass:#HierarchicalListView
instanceVariableNames:'imageInset imageWidth lineColor showRoot showLines
- showLeftIndicators indicatorAction useDefaultIcons icons
- openIndicator closeIndicator alignTextRight alignTextRightX
- maxWidthOfText minLineHeight levelOfLastItem expandOnSelect
- autoScrollHorizontal'
+ useDefaultIcons icons openIndicator closeIndicator alignTextRight
+ alignTextRightX maxWidthOfText minLineHeight levelOfLastItem
+ expandOnSelect autoScrollHorizontal showIndicators
+ showLeftIndicators indicatorAction'
classVariableNames:''
poolDictionaries:''
category:'Views-Trees'
@@ -60,6 +60,7 @@
showRoot <Boolean> root element is shown or hidden
derives from the hierachical list.
showLines <Boolean> show or hide lines
+ showIndicators <Boolean> show or hide indicators
useDefaultIcons <Boolean> use the default icons if no icon
for an item is specified
icons <IdentityDictionary> list of registered icons;
@@ -471,6 +472,21 @@
!
+showIndicators
+ "returns true if indicators are shown
+ "
+ ^ showIndicators
+!
+
+showIndicators:aBoolean
+ "true if indicators are shown
+ "
+ showIndicators ~~ aBoolean ifTrue:[
+ showIndicators := aBoolean.
+ shown ifTrue:[ self invalidate ].
+ ].
+!
+
showLeftIndicators
"show or hide the indicators for the most left items
"
@@ -481,12 +497,29 @@
showLeftIndicators:aBoolean
"show or hide the indicators for the most left items
"
- aBoolean ~~ showLeftIndicators ifTrue:[
+ |oldInset newInset|
+
+ aBoolean == showLeftIndicators ifTrue:[ ^ self ].
+
+ (widthOfContents isNil or:[list size == 0]) ifTrue:[
showLeftIndicators := aBoolean.
+ ^ self
+ ].
- (shown and:[indicatorAction notNil]) ifTrue:[
- self invalidate
- ]
+ oldInset := self xVisibleOfIconAtLevel:3.
+ showLeftIndicators := aBoolean.
+ newInset := self xVisibleOfIconAtLevel:3.
+
+ newInset ~~ oldInset ifTrue:[
+ widthOfContents := widthOfContents + (newInset - oldInset).
+ ].
+
+ shown ifTrue:[
+ self invalidate
+ ].
+
+ newInset ~~ oldInset ifTrue:[
+ self contentsChanged
].
!
@@ -525,41 +558,17 @@
!HierarchicalListView methodsFor:'actions'!
indicatorAction
- "if the action is not nil, indicators are shown and a click on the indicator
- will evaluate the action with none or one argument, the index into the list
+ "the action evaluated if an indicator is pressed; otherwise
+ if indicators are shown a default action is performed (toggle expand item).
"
^ indicatorAction
!
indicatorAction:anAction
- "if the action is not nil, indicators are shown and a click on the indicator
- will evaluate the action with none or one argument, the index into the list
+ "the action evaluated if an indicator is pressed; otherwise
+ if indicators are shown a default action is performed (toggle expand item).
"
- |maxLevel contentsChgSize|
-
- (indicatorAction isNil) == (anAction isNil) ifTrue:[
- indicatorAction := anAction.
- ^ self
- ].
-
- (widthOfContents isNil or:[list size == 0]) ifTrue:[
- indicatorAction := anAction.
- self invalidate.
- ^ self
- ].
-
- "/ must recompute width of contents
-
- maxLevel := 0.
- list do:[:el| maxLevel := maxLevel max:(el level) ].
-
- contentsChgSize := self xVisibleOfIconAtLevel:maxLevel.
indicatorAction := anAction.
- contentsChgSize := (self xVisibleOfIconAtLevel:maxLevel) - contentsChgSize.
- widthOfContents := widthOfContents + contentsChgSize.
-
- self invalidate.
- contentsChgSize ~~ 0 ifTrue:[ self contentsChanged ].
! !
!HierarchicalListView methodsFor:'change & update'!
@@ -571,7 +580,7 @@
"
|item expanded availY usedY vwOrgX vwOrgY idx|
- indicatorAction isNil ifTrue:[^ self].
+ showIndicators ifFalse:[^ self].
item := list at:aLnNr ifAbsent:nil.
item isNil ifTrue:[^ self].
@@ -579,7 +588,13 @@
item hasIndicator ifFalse:[^ self].
expanded := item isExpanded.
- indicatorAction valueWithOptionalArgument:aLnNr.
+
+ indicatorAction notNil ifTrue:[
+ indicatorAction valueWithOptionalArgument:aLnNr.
+ ] ifFalse:[
+ item toggleExpand
+ ].
+
(expanded or:[item isExpanded not]) ifTrue:[^ self].
"/ compute the index of last child assigned to item
@@ -775,7 +790,7 @@
xL := xLeft.
xR := xL + w.
- indicatorAction notNil ifTrue:[
+ showIndicators ifTrue:[
offIndcY := openIndicator width // 2.
].
@@ -803,7 +818,7 @@
showText := (xText < xR).
showIcon := (xIcon < xR and:[xText > xL]).
- indicatorAction notNil ifTrue:[
+ showIndicators ifTrue:[
xIndc := self xVisibleOfIndicatorAtLevel:level.
showIndc := (xIcon > xL and:[xIndc < xR]).
@@ -861,17 +876,20 @@
self mask:lineMask.
smallestLevel := self smallestLevelBetween:start and:stop.
+ minVertLevel := 2.
+
+ showLeftIndicators ifTrue:[
+ showLeftIdc := showIndicators.
+ showRoot ifFalse:[ minVertLevel := 3 ]
+ ] ifFalse:[
+ showLeftIdc := false.
+ ].
showRoot ifFalse:[ minHorzLevel := 2 ]
ifTrue:[ minHorzLevel := 1 ].
- minVertLevel := 2.
- showLeftIdc := indicatorAction notNil and:[showLeftIndicators].
-
- showLeftIdc ifTrue:[
- showRoot ifFalse:[ minVertLevel := 3 ]
- ] ifFalse:[
- minHorzLevel := minHorzLevel + 1
+ showLeftIdc ifFalse:[
+ minHorzLevel := minHorzLevel + 1.
].
yBot := begHLnY := runHLnY := yT.
@@ -1060,13 +1078,15 @@
item := nil
].
- (button == 1 or:[button == #select]) ifTrue:[
- (item notNil and:[indicatorAction notNil and:[item hasIndicator]]) ifTrue:[
- x0 := self xVisibleOfIndicatorAtLevel:(item level).
+ showIndicators ifTrue:[
+ (button == 1 or:[button == #select]) ifTrue:[
+ (item notNil and:[item hasIndicator]) ifTrue:[
+ x0 := self xVisibleOfIndicatorAtLevel:(item level).
- (x between:x0 and:(x0 + openIndicator width)) ifTrue:[
- self indicatorPressedAt:line.
- ^ self
+ (x between:x0 and:(x0 + openIndicator width)) ifTrue:[
+ self indicatorPressedAt:line.
+ ^ self
+ ].
].
].
].
@@ -1213,6 +1233,8 @@
initialize
super initialize.
levelOfLastItem := 1.
+
+ self showIndicators:true.
! !
!HierarchicalListView methodsFor:'private'!
@@ -1379,7 +1401,7 @@
x := self xVisibleOfVerticalLineAt:aLevel.
(showRoot and:[aLevel == 1]) ifTrue:[
- (indicatorAction notNil and:[showLeftIndicators]) ifFalse:[
+ showLeftIndicators ifFalse:[
^ x - (imageWidth // 2)
].
].
@@ -1423,7 +1445,7 @@
showRoot ifTrue:[ firstLevel := 1 ]
ifFalse:[ firstLevel := 2 ].
- (indicatorAction notNil and:[showLeftIndicators]) ifTrue:[
+ showLeftIndicators ifTrue:[
aLevel < firstLevel ifTrue:[
xOffset := opWidth2 - (firstLevel * xOffset)
] ifFalse:[
@@ -1511,5 +1533,5 @@
!HierarchicalListView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.75 2002-11-20 10:00:56 ca Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.76 2002-11-22 10:28:02 ca Exp $'
! !