1390
|
1 |
SelectionInListModelView subclass:#HierarchicalListView
|
|
2 |
instanceVariableNames:'imageInset imageWidth lineMask lineColor showRoot showLines
|
|
3 |
showLeftIndicators indicatorAction useDefaultIcons icons
|
|
4 |
openIndicator closeIndicator'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'AAA'
|
|
8 |
!
|
|
9 |
|
|
10 |
!HierarchicalListView class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
This class implements a hierarchical list view based on a
|
|
15 |
hierachical list
|
|
16 |
|
|
17 |
[Instance variables:]
|
|
18 |
textStartLeft <Integer> inset between icon and text
|
|
19 |
imageInset <Integer> inset between left side and icon
|
|
20 |
imageWidth <Integer> width of widest icon
|
|
21 |
lineMask <Form> line mask
|
|
22 |
lineColor <Color> line color
|
|
23 |
showRoot <Boolean> root element is shown or hidden
|
|
24 |
derives from the hierachical list.
|
|
25 |
showLines <Boolean> show or hide lines
|
|
26 |
useDefaultIcons <Boolean> use the default icons if no icon
|
|
27 |
for an item is specified
|
|
28 |
icons <IdentityDictionary> list of registered icons;
|
|
29 |
identifier := <key> value := <icon>
|
|
30 |
showLeftIndicators <Boolean> show or hide indicator for most left items
|
|
31 |
indicatorAction <Block> action evaluated if indicator is pressed
|
|
32 |
openIndicator <Icon, Image or Form> expanded indicator
|
|
33 |
closeIndicator <Icon, Image or Form> collapsed indicator
|
|
34 |
|
|
35 |
[author:]
|
|
36 |
Claus Atzkern
|
|
37 |
|
|
38 |
[see also:]
|
|
39 |
ListModelView
|
|
40 |
SelectionInListModelView
|
|
41 |
HierarchicalList
|
|
42 |
HierarchicalItem
|
|
43 |
"
|
|
44 |
|
|
45 |
|
|
46 |
!
|
|
47 |
|
|
48 |
examples
|
|
49 |
"
|
|
50 |
[exBegin]
|
|
51 |
|top sel list item|
|
|
52 |
|
|
53 |
list := HierarchicalList new.
|
|
54 |
item := HierarchicalItem::Example labeled:'Root Item'.
|
|
55 |
|
|
56 |
item expand.
|
|
57 |
list showRoot:false.
|
|
58 |
list root:item.
|
|
59 |
|
|
60 |
top := StandardSystemView new; extent:300@300.
|
|
61 |
sel := ScrollableView for:HierarchicalListView miniScroller:true
|
|
62 |
origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
63 |
|
|
64 |
sel list:list.
|
|
65 |
sel multipleSelectOk:true.
|
|
66 |
|
|
67 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ].
|
|
68 |
sel indicatorAction:[:i| (list at:i) toggleExpand ].
|
|
69 |
|
|
70 |
top open.
|
|
71 |
[exEnd]
|
|
72 |
|
|
73 |
|
|
74 |
"
|
|
75 |
! !
|
|
76 |
|
|
77 |
!HierarchicalListView class methodsFor:'resources'!
|
|
78 |
|
|
79 |
closeIndicator
|
|
80 |
"returns a little [+] bitmap"
|
|
81 |
|
|
82 |
<resource: #fileImage>
|
|
83 |
|
|
84 |
^ Icon constantNamed:#plus
|
|
85 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/plus.xpm')]
|
|
86 |
|
|
87 |
|
|
88 |
!
|
|
89 |
|
|
90 |
collapsedIcon
|
|
91 |
"returns icon to indicate a collapsed entry
|
|
92 |
"
|
|
93 |
<resource: #fileImage>
|
|
94 |
|
|
95 |
^ Icon constantNamed:#directory
|
|
96 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm')]
|
|
97 |
|
|
98 |
!
|
|
99 |
|
|
100 |
emptyIcon
|
|
101 |
"returns icon to indicate an not extendable entry
|
|
102 |
"
|
|
103 |
<resource: #fileImage>
|
|
104 |
|
|
105 |
^ Icon constantNamed:#plainFile
|
|
106 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm')]
|
|
107 |
|
|
108 |
!
|
|
109 |
|
|
110 |
expandedIcon
|
|
111 |
"returns icon to indicate an extended entry
|
|
112 |
"
|
|
113 |
<resource: #fileImage>
|
|
114 |
|
|
115 |
^ Icon constantNamed:#directoryOpened
|
|
116 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm')]
|
|
117 |
|
|
118 |
!
|
|
119 |
|
|
120 |
openIndicator
|
|
121 |
"returns a little [-] bitmap"
|
|
122 |
|
|
123 |
<resource: #fileImage>
|
|
124 |
|
|
125 |
^ Icon constantNamed:#minus
|
|
126 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/minus.xpm')]
|
|
127 |
|
|
128 |
! !
|
|
129 |
|
|
130 |
!HierarchicalListView methodsFor:'accessing'!
|
|
131 |
|
|
132 |
list:aList
|
|
133 |
"get the status of <showRoot> from the list
|
|
134 |
"
|
|
135 |
aList notNil ifTrue:[
|
|
136 |
showRoot := aList showRoot
|
|
137 |
].
|
|
138 |
super list:aList
|
|
139 |
! !
|
|
140 |
|
|
141 |
!HierarchicalListView methodsFor:'accessing colors'!
|
|
142 |
|
|
143 |
lineColor
|
|
144 |
"get the line color
|
|
145 |
"
|
|
146 |
^ lineColor
|
|
147 |
|
|
148 |
|
|
149 |
!
|
|
150 |
|
|
151 |
lineColor:aColor
|
|
152 |
"set the line color
|
|
153 |
"
|
|
154 |
(aColor notNil and:[aColor ~= lineColor]) ifTrue:[
|
|
155 |
lineColor := aColor.
|
|
156 |
|
|
157 |
shown ifTrue:[
|
|
158 |
lineColor := lineColor on:device.
|
|
159 |
|
|
160 |
showLines ifTrue:[
|
|
161 |
self invalidate
|
|
162 |
]
|
|
163 |
]
|
|
164 |
]
|
|
165 |
|
|
166 |
! !
|
|
167 |
|
|
168 |
!HierarchicalListView methodsFor:'accessing look'!
|
|
169 |
|
|
170 |
registerKeysAndIcons:aDictionary
|
|
171 |
"register icons by key and value derived from a directory
|
|
172 |
"
|
|
173 |
|image|
|
|
174 |
|
|
175 |
(aDictionary isNil or:[aDictionary isEmpty]) ifTrue:[
|
|
176 |
^ self
|
|
177 |
].
|
|
178 |
|
|
179 |
aDictionary keysAndValuesDo:[:aKey :anImage|
|
|
180 |
(image := self imageOnDevice:anImage) notNil ifTrue:[
|
|
181 |
icons at:aKey put:image
|
|
182 |
]
|
|
183 |
]
|
|
184 |
|
|
185 |
!
|
|
186 |
|
|
187 |
showLeftIndicators
|
|
188 |
"show or hide the indicators for the most left items
|
|
189 |
"
|
|
190 |
^ showLeftIndicators
|
|
191 |
|
|
192 |
!
|
|
193 |
|
|
194 |
showLeftIndicators:aState
|
|
195 |
"show or hide the indicators for the most left items
|
|
196 |
"
|
|
197 |
aState ~~ showLeftIndicators ifTrue:[
|
|
198 |
showLeftIndicators := aState.
|
|
199 |
self invalidate
|
|
200 |
].
|
|
201 |
|
|
202 |
!
|
|
203 |
|
|
204 |
showLines
|
|
205 |
"returns true if lines are shown
|
|
206 |
"
|
|
207 |
^ showLines
|
|
208 |
|
|
209 |
!
|
|
210 |
|
|
211 |
showLines:aState
|
|
212 |
"show or hide lines
|
|
213 |
"
|
|
214 |
aState ~~ showLines ifTrue:[
|
|
215 |
showLines := aState.
|
|
216 |
self invalidate
|
|
217 |
].
|
|
218 |
|
|
219 |
!
|
|
220 |
|
|
221 |
useDefaultIcons
|
|
222 |
"use the default icons if no icon for an item is specified;
|
|
223 |
** default: true
|
|
224 |
"
|
|
225 |
^ useDefaultIcons
|
|
226 |
!
|
|
227 |
|
|
228 |
useDefaultIcons:aBool
|
|
229 |
"use the default icons if no icon for an item is specified;
|
|
230 |
** default: true
|
|
231 |
"
|
|
232 |
useDefaultIcons ~~ aBool ifTrue:[
|
|
233 |
useDefaultIcons := aBool.
|
|
234 |
|
|
235 |
shown ifTrue:[
|
|
236 |
self invalidate
|
|
237 |
]
|
|
238 |
]
|
|
239 |
! !
|
|
240 |
|
|
241 |
!HierarchicalListView methodsFor:'actions'!
|
|
242 |
|
|
243 |
indicatorAction
|
|
244 |
"if the action is not nil, indicators are shown and a click on the indicator
|
|
245 |
will evaluate the action with none or one argument, the index into the list
|
|
246 |
"
|
|
247 |
^ indicatorAction
|
|
248 |
!
|
|
249 |
|
|
250 |
indicatorAction:anAction
|
|
251 |
"if the action is not nil, indicators are shown and a click on the indicator
|
|
252 |
will evaluate the action with none or one argument, the index into the list
|
|
253 |
"
|
|
254 |
|wasNilBefore|
|
|
255 |
|
|
256 |
wasNilBefore := indicatorAction isNil.
|
|
257 |
indicatorAction := anAction.
|
|
258 |
|
|
259 |
wasNilBefore == (anAction isNil) ifTrue:[
|
|
260 |
self invalidate
|
|
261 |
].
|
|
262 |
! !
|
|
263 |
|
|
264 |
!HierarchicalListView methodsFor:'change & update'!
|
|
265 |
|
|
266 |
lineChangedAt:aLnNr with:arg
|
|
267 |
"line changed at position; check whether line height changed
|
|
268 |
"
|
|
269 |
|item
|
|
270 |
lv "{ Class:SmallInteger }"
|
|
271 |
x0 "{ Class:SmallInteger }"
|
|
272 |
x1 "{ Class:SmallInteger }"
|
|
273 |
h "{ Class:SmallInteger }"
|
|
274 |
y0 "{ Class:SmallInteger }"
|
|
275 |
y1 "{ Class:SmallInteger }"
|
|
276 |
|
|
|
277 |
|
1399
|
278 |
(arg == #icon or:[arg == #hierarchy]) ifFalse:[
|
1390
|
279 |
^ super lineChangedAt:aLnNr with:arg
|
|
280 |
].
|
|
281 |
y0 := (self yVisibleOfLine:aLnNr) max:margin.
|
|
282 |
y1 := (self yVisibleOfLine:(aLnNr + 1)) min:(height - margin).
|
|
283 |
|
1399
|
284 |
(h := y1 - y0) > 0 ifTrue:[
|
|
285 |
x0 := margin.
|
|
286 |
x1 := width - margin.
|
|
287 |
|
|
288 |
(item := list at:aLnNr ifAbsent:nil) isNil ifFalse:[
|
|
289 |
lv := item level.
|
|
290 |
x0 := self xOfFigureLevel:lv.
|
|
291 |
x1 := x0 + imageWidth.
|
1390
|
292 |
|
1399
|
293 |
arg == #hierarchy ifTrue:[
|
|
294 |
x0 := self xOfFigureLevel:(lv -1).
|
|
295 |
].
|
|
296 |
x0 := x0 max:margin.
|
|
297 |
x1 := x1 min:(width - margin).
|
1390
|
298 |
|
1399
|
299 |
x1 > x0 ifFalse:[
|
|
300 |
^ self
|
|
301 |
]
|
|
302 |
].
|
|
303 |
self redrawX:x0 y:y0 width:x1 - x0 height:h.
|
1390
|
304 |
]
|
|
305 |
|
|
306 |
|
|
307 |
|
1399
|
308 |
|
1390
|
309 |
!
|
|
310 |
|
|
311 |
update:what with:aPara from:chgObj
|
|
312 |
"get the status of <showRoot> from the list
|
|
313 |
"
|
|
314 |
chgObj == list ifTrue:[
|
|
315 |
showRoot ~~ list showRoot ifTrue:[
|
|
316 |
showRoot := list showRoot.
|
|
317 |
self invalidate.
|
|
318 |
]
|
|
319 |
].
|
|
320 |
super update:what with:aPara from:chgObj
|
|
321 |
! !
|
|
322 |
|
|
323 |
!HierarchicalListView methodsFor:'drawing basics'!
|
|
324 |
|
1399
|
325 |
displayElement:anItem x:xL y:yT toX:xR y:yB
|
|
326 |
"draw a label at xL/yT; fg/bg colors are already set
|
|
327 |
"
|
|
328 |
anItem displayOn:self x:xL y:yT toX:xR y:yB
|
|
329 |
|
|
330 |
!
|
|
331 |
|
|
332 |
drawElementsFrom:start to:stop x:xL y:yT toX:xR
|
1390
|
333 |
"draw the items between start to stop without clearing the background
|
|
334 |
"
|
|
335 |
|item prevItem parent icon showIndc showIcon showText nxtPrnt
|
|
336 |
|
|
337 |
yTop "{ Class:SmallInteger }"
|
|
338 |
yCtr "{ Class:SmallInteger }"
|
|
339 |
yBot "{ Class:SmallInteger }"
|
|
340 |
|
|
341 |
xIndc "{ Class:SmallInteger }"
|
|
342 |
xIcon "{ Class:SmallInteger }"
|
|
343 |
xText "{ Class:SmallInteger }"
|
|
344 |
|
|
345 |
widthLvl "{ Class:SmallInteger }"
|
|
346 |
insetTxt "{ Class:SmallInteger }"
|
|
347 |
|
|
348 |
offIndcX "{ Class:SmallInteger }"
|
|
349 |
offIndcY "{ Class:SmallInteger }"
|
|
350 |
offIconX "{ Class:SmallInteger }"
|
|
351 |
|
|
|
352 |
widthLvl := imageInset + imageWidth.
|
|
353 |
insetTxt := textStartLeft + imageWidth.
|
|
354 |
offIconX := self xOfFigureLevel:0.
|
|
355 |
showIndc := false.
|
|
356 |
|
|
357 |
indicatorAction notNil ifTrue:[
|
|
358 |
icon := openIndicator extent // 2.
|
|
359 |
offIndcX := imageWidth // 2 - widthLvl.
|
|
360 |
offIndcX := offIndcX - icon x.
|
|
361 |
offIndcY := icon y.
|
|
362 |
].
|
|
363 |
|
|
364 |
showLines ifTrue:[
|
1399
|
365 |
self drawLinesFrom:start to:stop x:xL y:yT toX:xR
|
1390
|
366 |
].
|
|
367 |
|
|
368 |
parent := 4711. "/ to force a recompute
|
|
369 |
prevItem := 4711. "/ to force a recomputation of the level
|
1399
|
370 |
yBot := yT.
|
1390
|
371 |
|
|
372 |
start to:stop do:[:anIndex|
|
|
373 |
(item := list at:anIndex ifAbsent:nil) isNil ifTrue:[
|
|
374 |
^ self "/ list changed
|
|
375 |
].
|
|
376 |
yTop := yBot.
|
|
377 |
yBot := self yVisibleOfLine:(anIndex + 1).
|
|
378 |
yCtr := yTop + (yBot - yTop // 2).
|
|
379 |
|
|
380 |
(nxtPrnt := item parent) ~~ parent ifTrue:[
|
|
381 |
parent := nxtPrnt.
|
|
382 |
xIcon := prevItem == parent ifTrue:[xIcon + widthLvl]
|
|
383 |
ifFalse:[item level * widthLvl + offIconX].
|
|
384 |
|
|
385 |
xText := xIcon + insetTxt.
|
1399
|
386 |
showIcon := xIcon < xR and:[xText > xL].
|
|
387 |
showText := xText < xR.
|
1390
|
388 |
|
|
389 |
indicatorAction notNil ifTrue:[
|
|
390 |
xIndc := xIcon + offIndcX.
|
|
391 |
|
|
392 |
showIndc := ( (parent notNil or:[showLeftIndicators])
|
1399
|
393 |
and:[(xIcon > xL and:[xIndc < xR])]
|
1390
|
394 |
)
|
|
395 |
]
|
|
396 |
].
|
|
397 |
|
|
398 |
(showIcon and:[(icon := self figureFor:item) notNil]) ifTrue:[
|
|
399 |
icon width > imageWidth ifTrue:[
|
|
400 |
imageWidth := icon width.
|
|
401 |
StopRedrawSignal raise
|
|
402 |
].
|
|
403 |
self displayForm:icon x:xIcon y:(yCtr - (icon height // 2))
|
|
404 |
].
|
|
405 |
|
|
406 |
showText ifTrue:[
|
1399
|
407 |
self drawLabelAt:anIndex x:xText y:yTop toX:xR y:yBot
|
1390
|
408 |
].
|
|
409 |
(showIndc and:[item hasChildren]) ifTrue:[
|
|
410 |
icon := item isExpanded ifTrue:[openIndicator] ifFalse:[closeIndicator].
|
|
411 |
self displayForm:icon x:xIndc y:(yCtr - offIndcY)
|
|
412 |
].
|
|
413 |
prevItem := item.
|
|
414 |
]
|
|
415 |
!
|
|
416 |
|
1399
|
417 |
drawLinesFrom:start to:stop x:xL y:yT toX:xR
|
1390
|
418 |
"draw the lines between start to stop without clearing the background
|
|
419 |
"
|
|
420 |
|item prevItem parent p1 p2 showVLines showHLine lv nxtPrnt
|
|
421 |
showRootNot isFirst buildInArray
|
|
422 |
|
|
423 |
x "{ Class:SmallInteger }"
|
|
424 |
y "{ Class:SmallInteger }"
|
|
425 |
|
|
426 |
yTop "{ Class:SmallInteger }"
|
|
427 |
yBot "{ Class:SmallInteger }"
|
|
428 |
yCtr "{ Class:SmallInteger }"
|
|
429 |
|
|
430 |
begHLnY "{ Class:SmallInteger }"
|
|
431 |
runHLnY "{ Class:SmallInteger }"
|
|
432 |
begHLnX "{ Class:SmallInteger }"
|
|
433 |
endHLnX "{ Class:SmallInteger }"
|
|
434 |
|
|
435 |
widthLvl "{ Class:SmallInteger }"
|
|
436 |
offsHLnX "{ Class:SmallInteger }"
|
|
437 |
|
|
438 |
level "{ Class:SmallInteger }"
|
|
439 |
startLvI "{ Class:SmallInteger }"
|
|
440 |
startLvX "{ Class:SmallInteger }"
|
|
441 |
limitLvI "{ Class:SmallInteger }"
|
|
442 |
limitLvX "{ Class:SmallInteger }"
|
|
443 |
|
|
|
444 |
widthLvl := imageInset + imageWidth.
|
|
445 |
offsHLnX := imageWidth // 2 + (self xOfFigureLevel:-1).
|
|
446 |
|
|
447 |
parent := 4711. "/ to force a recompute
|
|
448 |
prevItem := 4711. "/ to force a recomputation of the level
|
|
449 |
|
|
450 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)).
|
|
451 |
self paint:lineColor on:bgColor.
|
|
452 |
self mask:lineMask.
|
|
453 |
startLvI := self smallestLevelBetween:start and:stop.
|
|
454 |
startLvX := self xOfFigureLevel:startLvI.
|
|
455 |
limitLvI := 2.
|
|
456 |
limitLvX := limitLvI * widthLvl + offsHLnX.
|
|
457 |
|
|
458 |
buildInArray := Array new:20.
|
|
459 |
buildInArray atAllPut:0.
|
|
460 |
|
|
461 |
showRootNot := showRoot not.
|
1399
|
462 |
yBot := yT.
|
|
463 |
begHLnY := runHLnY := yT.
|
1390
|
464 |
|
|
465 |
start to:stop do:[:anIndex|
|
|
466 |
(item := list at:anIndex ifAbsent:nil) isNil ifTrue:[
|
|
467 |
^ self mask:nil "/ list changed
|
|
468 |
].
|
|
469 |
yTop := yBot.
|
|
470 |
yBot := self yVisibleOfLine:(anIndex + 1).
|
|
471 |
yCtr := yTop + (yBot - yTop // 2).
|
|
472 |
anIndex == 1 ifTrue:[ begHLnY := runHLnY := yCtr ].
|
|
473 |
|
|
474 |
(nxtPrnt := item parent) ~~ parent ifTrue:[
|
|
475 |
parent := nxtPrnt.
|
|
476 |
|
|
477 |
prevItem == parent ifTrue:[
|
|
478 |
level := level + 1.
|
|
479 |
begHLnX := endHLnX.
|
|
480 |
] ifFalse:[
|
|
481 |
level := item level.
|
|
482 |
begHLnX := item level * widthLvl + offsHLnX.
|
|
483 |
].
|
|
484 |
|
|
485 |
isFirst := parent isNil or:[(showRootNot and:[level == 2])].
|
|
486 |
endHLnX := begHLnX + widthLvl.
|
1399
|
487 |
showVLines := begHLnX >= xL and:[level > 1].
|
|
488 |
showHLine := xL < endHLnX and:[xR > begHLnX].
|
1390
|
489 |
|
|
490 |
(showHLine and:[isFirst]) ifTrue:[
|
|
491 |
showHLine := showLeftIndicators and:[indicatorAction notNil]
|
|
492 |
]
|
|
493 |
].
|
|
494 |
|
|
495 |
showHLine ifTrue:[
|
|
496 |
self displayLineFromX:begHLnX y:yCtr toX:endHLnX y:yCtr
|
|
497 |
].
|
|
498 |
|
|
499 |
showVLines ifTrue:[
|
|
500 |
y := (parent last == item) ifTrue:[yCtr] ifFalse:[yBot].
|
|
501 |
x := begHLnX.
|
|
502 |
p2 := parent.
|
|
503 |
lv := level - 1.
|
|
504 |
self displayLineFromX:x y:runHLnY toX:x y:y.
|
|
505 |
|
|
506 |
[((p1 := p2 parent) notNil and:[(x := x - widthLvl) >= limitLvX])] whileTrue:[
|
1399
|
507 |
(p1 last ~~ p2 and:[x <= xR]) ifTrue:[
|
1390
|
508 |
x >= startLvX ifTrue:[
|
|
509 |
self displayLineFromX:x y:(yTop - 1) toX:x y:yBot
|
|
510 |
] ifFalse:[
|
|
511 |
buildInArray at:lv put:yBot
|
|
512 |
].
|
|
513 |
].
|
|
514 |
lv := lv - 1.
|
|
515 |
p2 := p1
|
|
516 |
]
|
|
517 |
].
|
|
518 |
prevItem := item.
|
|
519 |
runHLnY := yCtr.
|
|
520 |
].
|
|
521 |
|
|
522 |
"/
|
|
523 |
"/ draw outstanding verical lines to left
|
|
524 |
"/
|
|
525 |
x := limitLvX.
|
|
526 |
y := begHLnY.
|
|
527 |
|
|
528 |
limitLvI to:startLvI do:[:i|
|
|
529 |
(yBot := buildInArray at:i) ~~ 0 ifTrue:[
|
|
530 |
self displayLineFromX:x y:y toX:x y:yBot
|
|
531 |
].
|
|
532 |
x := x + widthLvl.
|
|
533 |
].
|
|
534 |
( start == stop
|
|
535 |
and:[(item := list at:start ifAbsent:nil) notNil
|
|
536 |
and:[item isExpanded
|
|
537 |
and:[item hasChildren]]]
|
|
538 |
) ifTrue:[
|
|
539 |
x := begHLnX + widthLvl.
|
|
540 |
|
1399
|
541 |
(x >= xL and:[x <= xR]) ifTrue:[
|
1390
|
542 |
yBot := self yVisibleOfLine:(start + 1).
|
1399
|
543 |
yCtr := yT + (yBot - yT // 2).
|
1390
|
544 |
self displayLineFromX:x y:yCtr toX:x y:yBot.
|
|
545 |
]
|
|
546 |
].
|
|
547 |
self mask:nil.
|
|
548 |
|
|
549 |
|
|
550 |
!
|
|
551 |
|
|
552 |
redrawLabelFromItem:anItem atY:y h:h
|
|
553 |
"called to redraw a label caused by a selection change
|
|
554 |
"
|
|
555 |
|w "{ Class:SmallInteger }"
|
|
556 |
x "{ Class:SmallInteger }"
|
|
557 |
|
|
|
558 |
x := (self xOfStringLevel:(anItem level)) - (textStartLeft // 2).
|
|
559 |
x := x max:margin.
|
|
560 |
|
|
561 |
(w := width - x) > 0 ifTrue:[
|
1399
|
562 |
self redrawX:x y:y width:w height:h
|
1390
|
563 |
]
|
|
564 |
|
|
565 |
|
|
566 |
! !
|
|
567 |
|
|
568 |
!HierarchicalListView methodsFor:'event handling'!
|
|
569 |
|
|
570 |
buttonMultiPress:button x:x y:y
|
|
571 |
"handle a button multiPress event
|
|
572 |
"
|
|
573 |
|lnNr|
|
|
574 |
|
|
575 |
enabled ifTrue:[
|
|
576 |
( (button == 1 or:[button == #select])
|
|
577 |
and:[(lnNr := self indicatorLineAtX:x y:y) notNil]
|
|
578 |
) ifFalse:[
|
|
579 |
super buttonMultiPress:button x:x y:y
|
|
580 |
]
|
|
581 |
]
|
|
582 |
!
|
|
583 |
|
|
584 |
buttonPress:button x:x y:y
|
|
585 |
"handle a button press event
|
|
586 |
"
|
|
587 |
|lnNr menu item appl|
|
|
588 |
|
|
589 |
enabled ifTrue:[
|
|
590 |
((button == 2) or:[button == #menu]) ifTrue:[
|
|
591 |
( (item := self selectedElement) notNil
|
|
592 |
and:[(menu := item middleButtonMenu) notNil]
|
|
593 |
) ifTrue:[
|
|
594 |
menu isCollection ifTrue:[
|
|
595 |
menu := Menu new fromLiteralArrayEncoding:menu.
|
|
596 |
appl := self application.
|
|
597 |
|
|
598 |
appl notNil ifTrue:[
|
|
599 |
menu findGuiResourcesIn:appl.
|
|
600 |
menu receiver:appl
|
|
601 |
] ifFalse:[
|
|
602 |
menu receiver:item
|
|
603 |
]
|
|
604 |
].
|
|
605 |
^ menu startUp
|
|
606 |
].
|
|
607 |
] ifFalse:[
|
|
608 |
(lnNr := self indicatorLineAtX:x y:y) notNil ifTrue:[
|
|
609 |
(indicatorAction numArgs == 1) ifTrue:[
|
|
610 |
indicatorAction value:lnNr
|
|
611 |
] ifFalse:[
|
|
612 |
indicatorAction value
|
|
613 |
].
|
|
614 |
^ self
|
|
615 |
]
|
|
616 |
].
|
|
617 |
super buttonPress:button x:x y:y
|
|
618 |
]
|
|
619 |
!
|
|
620 |
|
|
621 |
keyPress:aKey x:x y:y
|
|
622 |
"a key was pressed - handle page-keys here
|
|
623 |
"
|
|
624 |
<resource: #keyboard( #CursorLeft #CursorRight )>
|
|
625 |
|
|
626 |
|item parent index size stop step|
|
|
627 |
|
|
628 |
(aKey == #CursorLeft or:[aKey == #CursorRight]) ifFalse:[
|
|
629 |
^ super keyPress:aKey x:x y:y
|
|
630 |
].
|
|
631 |
|
|
632 |
( enabled
|
|
633 |
and:[(size := list size) > 1
|
|
634 |
and:[(index := self selectedIndex) ~~ 0
|
|
635 |
and:[(item := list at:index ifAbsent:nil) notNil]]]
|
|
636 |
) ifTrue:[
|
|
637 |
parent := item parent.
|
|
638 |
|
|
639 |
aKey == #CursorLeft ifTrue:[step := -1. stop := 1]
|
|
640 |
ifFalse:[step := 1. stop := size].
|
|
641 |
|
|
642 |
(index + step) to:stop by:step do:[:i|
|
|
643 |
item := list at:i ifAbsent:[^ nil ].
|
|
644 |
item parent ~~ parent ifTrue:[^ self selection:i]
|
|
645 |
].
|
|
646 |
|
|
647 |
index := aKey == #CursorLeft ifTrue:[size] ifFalse:[1].
|
|
648 |
self selection:index
|
|
649 |
].
|
|
650 |
! !
|
|
651 |
|
|
652 |
!HierarchicalListView methodsFor:'fetch resources'!
|
|
653 |
|
|
654 |
fetchResources
|
|
655 |
"fetch device colors and ..., to avoid reallocation at redraw time;
|
|
656 |
*** called after a create or snapin to fetch all device resources
|
|
657 |
"
|
|
658 |
|image|
|
|
659 |
|
|
660 |
super fetchResources.
|
|
661 |
|
|
662 |
lineMask := lineMask onDevice:device.
|
|
663 |
lineColor := lineColor onDevice:device.
|
|
664 |
openIndicator := self imageOnDevice:openIndicator.
|
|
665 |
closeIndicator := self imageOnDevice:closeIndicator.
|
|
666 |
imageWidth := 4.
|
|
667 |
|
|
668 |
icons keysAndValuesDo:[:aKey :anImage|
|
|
669 |
image := self imageOnDevice:anImage.
|
|
670 |
icons at:aKey put:image.
|
|
671 |
imageWidth := image width max:imageWidth.
|
|
672 |
].
|
|
673 |
imageWidth := imageWidth // 2.
|
|
674 |
imageWidth odd ifTrue:[imageWidth := imageWidth + 1].
|
|
675 |
imageWidth := imageWidth * 2.
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
! !
|
|
680 |
|
|
681 |
!HierarchicalListView methodsFor:'initialize / release'!
|
|
682 |
|
|
683 |
initStyle
|
|
684 |
"setup viewStyle specifics
|
|
685 |
"
|
|
686 |
|cls|
|
|
687 |
|
|
688 |
super initStyle.
|
|
689 |
|
|
690 |
cls := self class.
|
|
691 |
|
|
692 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55].
|
|
693 |
icons := IdentityDictionary new.
|
|
694 |
|
|
695 |
icons at:#expanded ifAbsentPut:[cls expandedIcon].
|
|
696 |
icons at:#collapsed ifAbsentPut:[cls collapsedIcon].
|
|
697 |
icons at:#empty ifAbsentPut:[cls emptyIcon].
|
|
698 |
|
|
699 |
openIndicator := self class openIndicator.
|
|
700 |
closeIndicator := self class closeIndicator.
|
|
701 |
lineColor := fgColor.
|
|
702 |
highlightMode := #label.
|
|
703 |
showRoot := true.
|
|
704 |
showLeftIndicators := true.
|
|
705 |
useDefaultIcons := true.
|
|
706 |
showLines := true.
|
|
707 |
imageInset := 4.
|
|
708 |
imageWidth := 8. "/ default
|
|
709 |
! !
|
|
710 |
|
|
711 |
!HierarchicalListView methodsFor:'private'!
|
|
712 |
|
|
713 |
figureFor:anItem
|
|
714 |
"return a (bitmap) figure for an item
|
|
715 |
"
|
|
716 |
|key image w h|
|
|
717 |
|
|
718 |
"/ the item may provide an icon
|
|
719 |
"/ (it knows for itself if its open or closed)
|
|
720 |
|
|
721 |
(key := anItem icon) notNil ifTrue:[
|
|
722 |
(key isImageOrForm and:[key device == device]) ifTrue:[
|
|
723 |
^ key
|
|
724 |
].
|
|
725 |
|
|
726 |
(image := icons at:key ifAbsent:nil) notNil ifTrue:[
|
|
727 |
^ image
|
|
728 |
].
|
|
729 |
|
|
730 |
key isImageOrForm ifTrue:[
|
|
731 |
image := self imageOnDevice:key.
|
|
732 |
icons at:key put:image.
|
|
733 |
^ image
|
|
734 |
]
|
|
735 |
].
|
|
736 |
|
|
737 |
useDefaultIcons ifFalse:[^ nil].
|
|
738 |
|
|
739 |
"/ ok, item did not return an icon - use default.
|
|
740 |
|
|
741 |
anItem hasChildren ifTrue:[
|
|
742 |
key := anItem isExpanded ifTrue:[#expanded] ifFalse:[#collapsed]
|
|
743 |
] ifFalse:[
|
|
744 |
key := #empty
|
|
745 |
].
|
|
746 |
^ icons at:key
|
|
747 |
!
|
|
748 |
|
|
749 |
heightOfLineAt:aLineNr
|
|
750 |
"returns the total height for a line at an index, including
|
|
751 |
lineSpacing, the figure and the label
|
|
752 |
"
|
|
753 |
|item icon height|
|
|
754 |
|
|
755 |
item := list at:aLineNr ifAbsent:[^ 4].
|
|
756 |
height := item heightOn:self.
|
|
757 |
|
|
758 |
(icon := self figureFor:item) notNil ifTrue:[
|
1391
|
759 |
height := (icon heightOn:self) max:height.
|
1390
|
760 |
].
|
|
761 |
^ lineSpacing + height
|
|
762 |
|
|
763 |
|
|
764 |
!
|
|
765 |
|
|
766 |
indicatorLineAtX:x y:y
|
|
767 |
"returns the lineNumber assigned to an indicator at x/y or nil
|
|
768 |
"
|
|
769 |
|lnNr item x0|
|
|
770 |
|
|
771 |
( indicatorAction isNil
|
|
772 |
or:[(lnNr := self yVisibleToLineNr:y) isNil
|
|
773 |
or:[(item := list at:lnNr ifAbsent:nil) isNil
|
|
774 |
or:[item hasChildren not]]]
|
|
775 |
) ifFalse:[
|
|
776 |
x0 := self xOfFigureLevel:(item level - 1).
|
|
777 |
|
|
778 |
(x > x0 and:[(x0 + imageWidth) > x]) ifTrue:[
|
|
779 |
^ lnNr
|
|
780 |
]
|
|
781 |
].
|
|
782 |
^ nil
|
|
783 |
!
|
|
784 |
|
|
785 |
smallestLevelBetween:start and:stop
|
|
786 |
"returns the smallest level between a range
|
|
787 |
"
|
|
788 |
|prevItem currParent nextParent item
|
|
789 |
|
|
790 |
lvl "{ Class:SmallInteger }"
|
|
791 |
min "{ Class:SmallInteger }"
|
|
792 |
beg "{ Class:SmallInteger }"
|
|
793 |
|
|
|
794 |
|
|
795 |
prevItem := list at:start ifAbsent:[ ^ 1 ].
|
|
796 |
|
|
797 |
(currParent := prevItem parent) isNil ifTrue:[
|
|
798 |
^ 1
|
|
799 |
].
|
|
800 |
|
|
801 |
(min := prevItem level) == 2 ifTrue:[
|
|
802 |
^ min
|
|
803 |
].
|
|
804 |
beg := start + 1.
|
|
805 |
|
|
806 |
beg to:stop do:[:i|
|
|
807 |
item := list at:i ifAbsent:[^ min].
|
|
808 |
|
|
809 |
(nextParent := item parent) == currParent ifFalse:[
|
|
810 |
(currParent := nextParent) == prevItem ifFalse:[
|
|
811 |
(lvl := item level) == 2 ifTrue:[
|
|
812 |
^ 2
|
|
813 |
].
|
|
814 |
min := min min:lvl
|
|
815 |
]
|
|
816 |
].
|
|
817 |
prevItem := item
|
|
818 |
].
|
|
819 |
^ min
|
|
820 |
|
|
821 |
|
|
822 |
|
|
823 |
|
|
824 |
|
|
825 |
!
|
|
826 |
|
|
827 |
widthOfWidestLineBetween:firstLine and:lastLine
|
|
828 |
"return the width of the longest line in pixels
|
|
829 |
"
|
|
830 |
|nprnt pprnt pitem item
|
|
831 |
textX "{ Class: SmallInteger }"
|
|
832 |
level "{ Class: SmallInteger }"
|
|
833 |
width "{ Class: SmallInteger }"
|
|
834 |
deltaX "{ Class: SmallInteger }"
|
|
835 |
startX "{ Class: SmallInteger }"
|
|
836 |
|
|
|
837 |
|
|
838 |
pprnt := 4711. "/ force a computation
|
|
839 |
pitem := 4712. "/ force a computation
|
|
840 |
width := 20.
|
|
841 |
deltaX := imageInset + imageWidth.
|
|
842 |
startX := self xOfStringLevel:1.
|
|
843 |
|
|
844 |
firstLine to:lastLine do:[:idx|
|
|
845 |
item := list at:idx ifAbsent:[^ width + startX].
|
|
846 |
|
|
847 |
(nprnt := item parent) ~~ pprnt ifTrue:[
|
|
848 |
(pprnt := nprnt) == pitem ifTrue:[
|
|
849 |
level := level + 1.
|
|
850 |
textX := textX + deltaX.
|
|
851 |
] ifFalse:[
|
|
852 |
level := item level.
|
|
853 |
textX := level - 1 * deltaX.
|
|
854 |
]
|
|
855 |
].
|
|
856 |
pitem := item.
|
1399
|
857 |
width := ((item widthOn:self) + textX) max:width
|
1390
|
858 |
].
|
|
859 |
^ width + startX
|
|
860 |
|
|
861 |
|
|
862 |
!
|
|
863 |
|
|
864 |
xOfFigureLevel:aLevel
|
|
865 |
"origin x where to draw the icon
|
|
866 |
"
|
|
867 |
|l "{ Class:SmallInteger }"|
|
|
868 |
|
|
869 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1].
|
|
870 |
|
|
871 |
indicatorAction isNil ifTrue:[
|
|
872 |
l := l - 1
|
|
873 |
] ifFalse:[
|
|
874 |
showLeftIndicators ifFalse:[
|
|
875 |
l := l - 1
|
|
876 |
]
|
|
877 |
].
|
|
878 |
^ (l * (imageInset + imageWidth)) + imageInset - (viewOrigin x)
|
|
879 |
!
|
|
880 |
|
|
881 |
xOfStringLevel:aLevel
|
|
882 |
"origin x where to draw the text( label )
|
|
883 |
"
|
|
884 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textStartLeft
|
|
885 |
|
|
886 |
! !
|
|
887 |
|
|
888 |
!HierarchicalListView class methodsFor:'documentation'!
|
|
889 |
|
|
890 |
version
|
1400
|
891 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.4 1999-05-28 18:07:14 cg Exp $'
|
1390
|
892 |
! !
|