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