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