author | ca |
Mon, 03 Apr 2000 17:07:04 +0200 | |
changeset 1752 | 1c11b6e4ab37 |
parent 1746 | 0a4f786f8c9a |
child 1756 | f0f9ae674364 |
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 |
||
1390 | 43 |
documentation |
44 |
" |
|
45 |
This class implements a hierarchical list view based on a |
|
1431 | 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 |
|
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 |
|
68 |
||
1568 | 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 |
||
1390 | 76 |
[author:] |
77 |
Claus Atzkern |
|
78 |
||
79 |
[see also:] |
|
80 |
ListModelView |
|
81 |
SelectionInListModelView |
|
82 |
HierarchicalList |
|
83 |
HierarchicalItem |
|
84 |
" |
|
85 |
||
86 |
||
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 |
||
1509
3bc11d81df55
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1508
diff
changeset
|
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 |
||
131 |
collapsedIcon |
|
132 |
"returns icon to indicate a collapsed entry |
|
133 |
" |
|
134 |
<resource: #fileImage> |
|
135 |
||
136 |
^ Icon constantNamed:#directory |
|
1632 | 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 |
||
161 |
openIndicator |
|
162 |
"returns a little [-] bitmap" |
|
163 |
||
164 |
<resource: #fileImage> |
|
165 |
||
166 |
^ Icon constantNamed:#minus |
|
1632 | 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 |
||
217 |
alignTextRight:aBool |
|
218 |
"align the text right |
|
219 |
" |
|
220 |
alignTextRight := aBool ? false. |
|
221 |
! |
|
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 |
||
321 |
lineChangedAt:aLnNr with:arg |
|
322 |
"line changed at position; check whether line height changed |
|
323 |
" |
|
324 |
|item |
|
325 |
lv "{ Class:SmallInteger }" |
|
326 |
x0 "{ Class:SmallInteger }" |
|
327 |
x1 "{ Class:SmallInteger }" |
|
328 |
h "{ Class:SmallInteger }" |
|
329 |
y0 "{ Class:SmallInteger }" |
|
330 |
y1 "{ Class:SmallInteger }" |
|
331 |
| |
|
332 |
||
1399 | 333 |
(arg == #icon or:[arg == #hierarchy]) ifFalse:[ |
1390 | 334 |
^ super lineChangedAt:aLnNr with:arg |
335 |
]. |
|
1568 | 336 |
shown ifFalse:[^ self]. |
337 |
||
1390 | 338 |
y0 := (self yVisibleOfLine:aLnNr) max:margin. |
339 |
y1 := (self yVisibleOfLine:(aLnNr + 1)) min:(height - margin). |
|
340 |
||
1399 | 341 |
(h := y1 - y0) > 0 ifTrue:[ |
342 |
x0 := margin. |
|
343 |
x1 := width - margin. |
|
344 |
||
345 |
(item := list at:aLnNr ifAbsent:nil) isNil ifFalse:[ |
|
346 |
lv := item level. |
|
1570 | 347 |
x1 := (self xOfStringLevel:lv) - (textStartLeft // 2). |
1390 | 348 |
|
1399 | 349 |
arg == #hierarchy ifTrue:[ |
350 |
x0 := self xOfFigureLevel:(lv -1). |
|
1570 | 351 |
] ifFalse:[ |
352 |
x0 := self xOfFigureLevel:lv |
|
1399 | 353 |
]. |
354 |
x0 := x0 max:margin. |
|
355 |
x1 := x1 min:(width - margin). |
|
1568 | 356 |
x1 > x0 ifFalse:[^ self] |
357 |
]. |
|
358 |
self repairDamage. |
|
359 |
self invalidate:(Rectangle left:x0 top:y0 width:(x1 - x0) height:h) |
|
360 |
repairNow:true. |
|
361 |
] |
|
1390 | 362 |
|
363 |
||
364 |
||
365 |
||
1399 | 366 |
|
1390 | 367 |
! |
368 |
||
369 |
update:what with:aPara from:chgObj |
|
370 |
"get the status of <showRoot> from the list |
|
371 |
" |
|
372 |
chgObj == list ifTrue:[ |
|
373 |
showRoot ~~ list showRoot ifTrue:[ |
|
374 |
showRoot := list showRoot. |
|
375 |
self invalidate. |
|
376 |
] |
|
377 |
]. |
|
378 |
super update:what with:aPara from:chgObj |
|
379 |
! ! |
|
380 |
||
381 |
!HierarchicalListView methodsFor:'drawing basics'! |
|
382 |
||
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
383 |
displayElement:anItem x:x y:y h:h |
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
384 |
"draw a label at x/y; fg/bg colors are already set |
1399 | 385 |
" |
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
386 |
anItem displayOn:self x:x y:y h:h |
1399 | 387 |
|
388 |
! |
|
389 |
||
1568 | 390 |
drawElementsFrom:start to:stop x:xLeft y:yT w:w |
1390 | 391 |
"draw the items between start to stop without clearing the background |
392 |
" |
|
393 |
|item prevItem parent icon showIndc showIcon showText nxtPrnt |
|
394 |
||
1568 | 395 |
yTop "{ Class:SmallInteger }" |
396 |
yCtr "{ Class:SmallInteger }" |
|
397 |
yBot "{ Class:SmallInteger }" |
|
1390 | 398 |
|
1568 | 399 |
xIndc "{ Class:SmallInteger }" |
400 |
xIcon "{ Class:SmallInteger }" |
|
401 |
xText "{ Class:SmallInteger }" |
|
402 |
xDeltaIT "{ Class:SmallInteger }" |
|
403 |
xL "{ Class:SmallInteger }" |
|
404 |
xR "{ Class:SmallInteger }" |
|
405 |
height "{ Class:SmallInteger }" |
|
1390 | 406 |
|
1568 | 407 |
widthLvl "{ Class:SmallInteger }" |
408 |
insetTxt "{ Class:SmallInteger }" |
|
1390 | 409 |
|
1568 | 410 |
offIndcX "{ Class:SmallInteger }" |
411 |
offIndcY "{ Class:SmallInteger }" |
|
412 |
offIconX "{ Class:SmallInteger }" |
|
413 |
iconWidth "{ Class:SmallInteger }" |
|
414 |
iconRgtX "{ Class:SmallInteger }" |
|
1390 | 415 |
| |
416 |
widthLvl := imageInset + imageWidth. |
|
417 |
insetTxt := textStartLeft + imageWidth. |
|
1568 | 418 |
xL := xLeft. |
419 |
xR := xL + w. |
|
420 |
||
421 |
alignTextRight ifTrue:[ |
|
422 |
xText := alignTextRightX - (viewOrigin x). |
|
423 |
showText := xText < xR. |
|
424 |
]. |
|
425 |
||
1390 | 426 |
offIconX := self xOfFigureLevel:0. |
427 |
showIndc := false. |
|
428 |
||
429 |
indicatorAction notNil ifTrue:[ |
|
430 |
icon := openIndicator extent // 2. |
|
431 |
offIndcX := imageWidth // 2 - widthLvl. |
|
432 |
offIndcX := offIndcX - icon x. |
|
433 |
offIndcY := icon y. |
|
434 |
]. |
|
435 |
||
436 |
showLines ifTrue:[ |
|
1399 | 437 |
self drawLinesFrom:start to:stop x:xL y:yT toX:xR |
1390 | 438 |
]. |
439 |
||
440 |
parent := 4711. "/ to force a recompute |
|
441 |
prevItem := 4711. "/ to force a recomputation of the level |
|
1399 | 442 |
yBot := yT. |
1390 | 443 |
|
444 |
start to:stop do:[:anIndex| |
|
445 |
(item := list at:anIndex ifAbsent:nil) isNil ifTrue:[ |
|
446 |
^ self "/ list changed |
|
447 |
]. |
|
448 |
yTop := yBot. |
|
449 |
yBot := self yVisibleOfLine:(anIndex + 1). |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
450 |
height := yBot - yTop. |
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
451 |
|
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
452 |
yCtr := yTop + (height // 2). |
1390 | 453 |
|
454 |
(nxtPrnt := item parent) ~~ parent ifTrue:[ |
|
455 |
parent := nxtPrnt. |
|
456 |
xIcon := prevItem == parent ifTrue:[xIcon + widthLvl] |
|
457 |
ifFalse:[item level * widthLvl + offIconX]. |
|
458 |
||
1568 | 459 |
|
460 |
alignTextRight ifFalse:[ |
|
461 |
xText := xIcon + insetTxt. |
|
462 |
showText := xText < xR. |
|
463 |
]. |
|
1399 | 464 |
showIcon := xIcon < xR and:[xText > xL]. |
1390 | 465 |
|
466 |
indicatorAction notNil ifTrue:[ |
|
467 |
xIndc := xIcon + offIndcX. |
|
468 |
||
469 |
showIndc := ( (parent notNil or:[showLeftIndicators]) |
|
1399 | 470 |
and:[(xIcon > xL and:[xIndc < xR])] |
1390 | 471 |
) |
472 |
] |
|
473 |
]. |
|
474 |
||
475 |
(showIcon and:[(icon := self figureFor:item) notNil]) ifTrue:[ |
|
1568 | 476 |
iconWidth := icon width. |
477 |
iconRgtX := xIcon + iconWidth. |
|
478 |
xDeltaIT := xText - textStartLeft - iconRgtX. |
|
479 |
||
480 |
xDeltaIT < 0 ifTrue:[ |
|
481 |
alignTextRightX := alignTextRightX - xDeltaIT. |
|
482 |
||
483 |
alignTextRight ifFalse:[ |
|
484 |
imageWidth := iconWidth. |
|
485 |
widthOfContents := widthOfContents - xDeltaIT. |
|
486 |
] ifTrue:[ |
|
487 |
widthOfContents := alignTextRightX + maxWidthOfText |
|
488 |
]. |
|
489 |
self contentsChanged. |
|
1390 | 490 |
StopRedrawSignal raise |
491 |
]. |
|
1568 | 492 |
iconRgtX > xL ifTrue:[ |
493 |
self displayForm:icon x:xIcon y:(yCtr - (icon height // 2)) |
|
494 |
] |
|
1390 | 495 |
]. |
496 |
||
497 |
showText ifTrue:[ |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
498 |
self drawLabelAt:anIndex x:xText y:yTop h:height |
1390 | 499 |
]. |
500 |
(showIndc and:[item hasChildren]) ifTrue:[ |
|
501 |
icon := item isExpanded ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
|
502 |
self displayForm:icon x:xIndc y:(yCtr - offIndcY) |
|
503 |
]. |
|
504 |
prevItem := item. |
|
505 |
] |
|
1568 | 506 |
|
507 |
||
1390 | 508 |
! |
509 |
||
1399 | 510 |
drawLinesFrom:start to:stop x:xL y:yT toX:xR |
1390 | 511 |
"draw the lines between start to stop without clearing the background |
512 |
" |
|
513 |
|item prevItem parent p1 p2 showVLines showHLine lv nxtPrnt |
|
514 |
showRootNot isFirst buildInArray |
|
515 |
||
516 |
x "{ Class:SmallInteger }" |
|
1570 | 517 |
xText "{ Class:SmallInteger }" |
518 |
||
1390 | 519 |
y "{ Class:SmallInteger }" |
520 |
yTop "{ Class:SmallInteger }" |
|
521 |
yBot "{ Class:SmallInteger }" |
|
522 |
yCtr "{ Class:SmallInteger }" |
|
523 |
||
524 |
begHLnY "{ Class:SmallInteger }" |
|
525 |
runHLnY "{ Class:SmallInteger }" |
|
526 |
begHLnX "{ Class:SmallInteger }" |
|
527 |
endHLnX "{ Class:SmallInteger }" |
|
528 |
||
529 |
widthLvl "{ Class:SmallInteger }" |
|
530 |
offsHLnX "{ Class:SmallInteger }" |
|
531 |
||
532 |
level "{ Class:SmallInteger }" |
|
533 |
startLvI "{ Class:SmallInteger }" |
|
534 |
startLvX "{ Class:SmallInteger }" |
|
535 |
limitLvI "{ Class:SmallInteger }" |
|
536 |
limitLvX "{ Class:SmallInteger }" |
|
537 |
| |
|
538 |
widthLvl := imageInset + imageWidth. |
|
539 |
offsHLnX := imageWidth // 2 + (self xOfFigureLevel:-1). |
|
540 |
||
541 |
parent := 4711. "/ to force a recompute |
|
542 |
prevItem := 4711. "/ to force a recomputation of the level |
|
543 |
||
544 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
545 |
self paint:lineColor on:bgColor. |
|
546 |
self mask:lineMask. |
|
547 |
startLvI := self smallestLevelBetween:start and:stop. |
|
548 |
startLvX := self xOfFigureLevel:startLvI. |
|
549 |
limitLvI := 2. |
|
550 |
limitLvX := limitLvI * widthLvl + offsHLnX. |
|
551 |
||
1567 | 552 |
showRootNot := showRoot not. |
553 |
yBot := yT. |
|
554 |
begHLnY := runHLnY := yT. |
|
1390 | 555 |
|
1570 | 556 |
alignTextRight ifTrue:[ |
557 |
xText := alignTextRightX - (viewOrigin x) - textStartLeft. |
|
558 |
]. |
|
559 |
||
1390 | 560 |
start to:stop do:[:anIndex| |
561 |
(item := list at:anIndex ifAbsent:nil) isNil ifTrue:[ |
|
562 |
^ self mask:nil "/ list changed |
|
563 |
]. |
|
564 |
yTop := yBot. |
|
565 |
yBot := self yVisibleOfLine:(anIndex + 1). |
|
566 |
yCtr := yTop + (yBot - yTop // 2). |
|
567 |
anIndex == 1 ifTrue:[ begHLnY := runHLnY := yCtr ]. |
|
568 |
||
569 |
(nxtPrnt := item parent) ~~ parent ifTrue:[ |
|
570 |
parent := nxtPrnt. |
|
571 |
||
572 |
prevItem == parent ifTrue:[ |
|
1567 | 573 |
level := level + 1. |
1390 | 574 |
begHLnX := endHLnX. |
575 |
] ifFalse:[ |
|
576 |
level := item level. |
|
1567 | 577 |
begHLnX := level * widthLvl + offsHLnX. |
1390 | 578 |
]. |
579 |
||
580 |
isFirst := parent isNil or:[(showRootNot and:[level == 2])]. |
|
581 |
endHLnX := begHLnX + widthLvl. |
|
1399 | 582 |
showVLines := begHLnX >= xL and:[level > 1]. |
1570 | 583 |
|
584 |
alignTextRight ifFalse:[ |
|
585 |
xText := endHLnX + (widthLvl // 2). |
|
586 |
]. |
|
587 |
showHLine := (xL < xText and:[xR > begHLnX]). |
|
1390 | 588 |
|
589 |
(showHLine and:[isFirst]) ifTrue:[ |
|
590 |
showHLine := showLeftIndicators and:[indicatorAction notNil] |
|
591 |
] |
|
592 |
]. |
|
593 |
||
594 |
showHLine ifTrue:[ |
|
1570 | 595 |
item drawHorizontalLineUpToText ifTrue:[ |
596 |
p1 := xText |
|
597 |
] ifFalse:[ |
|
598 |
p1 := xL < endHLnX ifTrue:[endHLnX] ifFalse:[nil] |
|
599 |
]. |
|
600 |
p1 notNil ifTrue:[ |
|
601 |
self displayLineFromX:begHLnX y:yCtr toX:p1 y:yCtr |
|
602 |
] |
|
1390 | 603 |
]. |
604 |
||
605 |
showVLines ifTrue:[ |
|
606 |
y := (parent last == item) ifTrue:[yCtr] ifFalse:[yBot]. |
|
607 |
x := begHLnX. |
|
608 |
p2 := parent. |
|
609 |
lv := level - 1. |
|
610 |
self displayLineFromX:x y:runHLnY toX:x y:y. |
|
611 |
||
612 |
[((p1 := p2 parent) notNil and:[(x := x - widthLvl) >= limitLvX])] whileTrue:[ |
|
1399 | 613 |
(p1 last ~~ p2 and:[x <= xR]) ifTrue:[ |
1390 | 614 |
x >= startLvX ifTrue:[ |
615 |
self displayLineFromX:x y:(yTop - 1) toX:x y:yBot |
|
616 |
] ifFalse:[ |
|
1567 | 617 |
buildInArray isNil ifTrue:[buildInArray := Array new:startLvI]. |
1390 | 618 |
buildInArray at:lv put:yBot |
619 |
]. |
|
620 |
]. |
|
621 |
lv := lv - 1. |
|
622 |
p2 := p1 |
|
623 |
] |
|
624 |
]. |
|
625 |
prevItem := item. |
|
626 |
runHLnY := yCtr. |
|
627 |
]. |
|
628 |
||
629 |
"/ |
|
630 |
"/ draw outstanding verical lines to left |
|
631 |
"/ |
|
1567 | 632 |
(item isExpanded and:[item hasChildren]) ifTrue:[ |
633 |
(endHLnX >= xL and:[endHLnX <= xR]) ifTrue:[ |
|
634 |
self displayLineFromX:endHLnX y:yCtr toX:endHLnX y:yBot. |
|
635 |
] |
|
1390 | 636 |
]. |
1567 | 637 |
|
638 |
buildInArray notNil ifTrue:[ |
|
639 |
x := limitLvX. |
|
640 |
y := begHLnY. |
|
1390 | 641 |
|
1567 | 642 |
limitLvI to:startLvI do:[:i| |
1597 | 643 |
|yB| |
1596 | 644 |
|
1597 | 645 |
(yB := buildInArray at:i) notNil ifTrue:[ |
646 |
self displayLineFromX:x y:y toX:x y:yB |
|
1567 | 647 |
]. |
648 |
x := x + widthLvl. |
|
1390 | 649 |
] |
650 |
]. |
|
651 |
self mask:nil. |
|
652 |
||
653 |
! ! |
|
654 |
||
655 |
!HierarchicalListView methodsFor:'event handling'! |
|
656 |
||
657 |
buttonMultiPress:button x:x y:y |
|
658 |
"handle a button multiPress event |
|
659 |
" |
|
660 |
|lnNr| |
|
661 |
||
662 |
enabled ifTrue:[ |
|
663 |
( (button == 1 or:[button == #select]) |
|
664 |
and:[(lnNr := self indicatorLineAtX:x y:y) notNil] |
|
665 |
) ifFalse:[ |
|
666 |
super buttonMultiPress:button x:x y:y |
|
667 |
] |
|
668 |
] |
|
669 |
! |
|
670 |
||
671 |
buttonPress:button x:x y:y |
|
672 |
"handle a button press event |
|
673 |
" |
|
1579 | 674 |
|lnNr| |
1390 | 675 |
|
676 |
enabled ifTrue:[ |
|
1579 | 677 |
(button == 1 or:[button == #select]) ifTrue:[ |
1390 | 678 |
(lnNr := self indicatorLineAtX:x y:y) notNil ifTrue:[ |
679 |
(indicatorAction numArgs == 1) ifTrue:[ |
|
680 |
indicatorAction value:lnNr |
|
681 |
] ifFalse:[ |
|
682 |
indicatorAction value |
|
683 |
]. |
|
684 |
^ self |
|
685 |
] |
|
686 |
]. |
|
687 |
super buttonPress:button x:x y:y |
|
688 |
] |
|
689 |
! |
|
690 |
||
691 |
keyPress:aKey x:x y:y |
|
692 |
"a key was pressed - handle page-keys here |
|
693 |
" |
|
694 |
<resource: #keyboard( #CursorLeft #CursorRight )> |
|
695 |
||
696 |
|item parent index size stop step| |
|
697 |
||
698 |
(aKey == #CursorLeft or:[aKey == #CursorRight]) ifFalse:[ |
|
699 |
^ super keyPress:aKey x:x y:y |
|
700 |
]. |
|
701 |
||
702 |
( enabled |
|
703 |
and:[(size := list size) > 1 |
|
704 |
and:[(index := self selectedIndex) ~~ 0 |
|
705 |
and:[(item := list at:index ifAbsent:nil) notNil]]] |
|
706 |
) ifTrue:[ |
|
707 |
parent := item parent. |
|
708 |
||
709 |
aKey == #CursorLeft ifTrue:[step := -1. stop := 1] |
|
710 |
ifFalse:[step := 1. stop := size]. |
|
711 |
||
712 |
(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
|
713 |
item := list at:i ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
714 |
item isNil ifTrue:[^ nil]. |
1390 | 715 |
item parent ~~ parent ifTrue:[^ self selection:i] |
716 |
]. |
|
717 |
||
718 |
index := aKey == #CursorLeft ifTrue:[size] ifFalse:[1]. |
|
719 |
self selection:index |
|
720 |
]. |
|
721 |
! ! |
|
722 |
||
723 |
!HierarchicalListView methodsFor:'fetch resources'! |
|
724 |
||
725 |
fetchResources |
|
726 |
"fetch device colors and ..., to avoid reallocation at redraw time; |
|
727 |
*** called after a create or snapin to fetch all device resources |
|
728 |
" |
|
729 |
|image| |
|
730 |
||
731 |
super fetchResources. |
|
732 |
||
733 |
lineMask := lineMask onDevice:device. |
|
734 |
lineColor := lineColor onDevice:device. |
|
735 |
openIndicator := self imageOnDevice:openIndicator. |
|
736 |
closeIndicator := self imageOnDevice:closeIndicator. |
|
1746 | 737 |
imageWidth := 2. |
1390 | 738 |
|
739 |
icons keysAndValuesDo:[:aKey :anImage| |
|
1624 | 740 |
anImage isNil ifTrue:[ |
741 |
('HierachicalListView [warning]: missing image: ' , aKey) errorPrintCR. |
|
742 |
] ifFalse:[ |
|
743 |
image := self imageOnDevice:anImage. |
|
744 |
icons at:aKey put:image. |
|
745 |
imageWidth := image width max:imageWidth. |
|
746 |
] |
|
1390 | 747 |
]. |
1746 | 748 |
imageWidth := imageWidth + 1 // 2 * 2. |
1568 | 749 |
alignTextRightX := imageWidth + 20. |
1390 | 750 |
! ! |
751 |
||
752 |
!HierarchicalListView methodsFor:'initialize / release'! |
|
753 |
||
754 |
initStyle |
|
755 |
"setup viewStyle specifics |
|
756 |
" |
|
757 |
|cls| |
|
758 |
||
759 |
super initStyle. |
|
760 |
||
761 |
cls := self class. |
|
762 |
||
763 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
|
764 |
icons := IdentityDictionary new. |
|
765 |
||
766 |
icons at:#expanded ifAbsentPut:[cls expandedIcon]. |
|
767 |
icons at:#collapsed ifAbsentPut:[cls collapsedIcon]. |
|
768 |
icons at:#empty ifAbsentPut:[cls emptyIcon]. |
|
769 |
||
770 |
openIndicator := self class openIndicator. |
|
771 |
closeIndicator := self class closeIndicator. |
|
772 |
lineColor := fgColor. |
|
773 |
highlightMode := #label. |
|
774 |
showRoot := true. |
|
775 |
showLeftIndicators := true. |
|
776 |
useDefaultIcons := true. |
|
777 |
showLines := true. |
|
778 |
imageInset := 4. |
|
1746 | 779 |
imageWidth := 4. "/ default |
1568 | 780 |
alignTextRight := false. |
781 |
alignTextRightX := 8. |
|
782 |
maxWidthOfText := 0. |
|
1390 | 783 |
! ! |
784 |
||
785 |
!HierarchicalListView methodsFor:'private'! |
|
786 |
||
787 |
figureFor:anItem |
|
788 |
"return a (bitmap) figure for an item |
|
789 |
" |
|
790 |
|key image w h| |
|
791 |
||
792 |
"/ the item may provide an icon |
|
793 |
"/ (it knows for itself if its open or closed) |
|
794 |
||
795 |
(key := anItem icon) notNil ifTrue:[ |
|
796 |
(key isImageOrForm and:[key device == device]) ifTrue:[ |
|
797 |
^ key |
|
798 |
]. |
|
799 |
||
800 |
(image := icons at:key ifAbsent:nil) notNil ifTrue:[ |
|
801 |
^ image |
|
802 |
]. |
|
803 |
||
804 |
key isImageOrForm ifTrue:[ |
|
805 |
image := self imageOnDevice:key. |
|
806 |
icons at:key put:image. |
|
807 |
^ image |
|
808 |
] |
|
809 |
]. |
|
810 |
||
811 |
useDefaultIcons ifFalse:[^ nil]. |
|
812 |
||
813 |
"/ ok, item did not return an icon - use default. |
|
814 |
||
815 |
anItem hasChildren ifTrue:[ |
|
816 |
key := anItem isExpanded ifTrue:[#expanded] ifFalse:[#collapsed] |
|
817 |
] ifFalse:[ |
|
818 |
key := #empty |
|
819 |
]. |
|
1746 | 820 |
^ icons at:key ifAbsent:nil |
1390 | 821 |
! |
822 |
||
823 |
heightOfLineAt:aLineNr |
|
824 |
"returns the total height for a line at an index, including |
|
825 |
lineSpacing, the figure and the label |
|
826 |
" |
|
827 |
|item icon height| |
|
828 |
||
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
829 |
item := list at:aLineNr ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
830 |
item isNil ifTrue:[^ 4]. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
831 |
|
1390 | 832 |
height := item heightOn:self. |
833 |
||
834 |
(icon := self figureFor:item) notNil ifTrue:[ |
|
1391 | 835 |
height := (icon heightOn:self) max:height. |
1390 | 836 |
]. |
837 |
^ lineSpacing + height |
|
838 |
||
839 |
||
840 |
! |
|
841 |
||
842 |
indicatorLineAtX:x y:y |
|
843 |
"returns the lineNumber assigned to an indicator at x/y or nil |
|
844 |
" |
|
845 |
|lnNr item x0| |
|
846 |
||
847 |
( indicatorAction isNil |
|
848 |
or:[(lnNr := self yVisibleToLineNr:y) isNil |
|
849 |
or:[(item := list at:lnNr ifAbsent:nil) isNil |
|
850 |
or:[item hasChildren not]]] |
|
851 |
) ifFalse:[ |
|
852 |
x0 := self xOfFigureLevel:(item level - 1). |
|
853 |
||
854 |
(x > x0 and:[(x0 + imageWidth) > x]) ifTrue:[ |
|
855 |
^ lnNr |
|
856 |
] |
|
857 |
]. |
|
858 |
^ nil |
|
859 |
! |
|
860 |
||
861 |
smallestLevelBetween:start and:stop |
|
862 |
"returns the smallest level between a range |
|
863 |
" |
|
864 |
|prevItem currParent nextParent item |
|
865 |
||
866 |
lvl "{ Class:SmallInteger }" |
|
867 |
min "{ Class:SmallInteger }" |
|
868 |
beg "{ Class:SmallInteger }" |
|
869 |
| |
|
870 |
||
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
871 |
prevItem := list at:start ifAbsent:nil. |
1390 | 872 |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
873 |
(prevItem isNil or:[(currParent := prevItem parent) isNil]) ifTrue:[ |
1390 | 874 |
^ 1 |
875 |
]. |
|
876 |
||
877 |
(min := prevItem level) == 2 ifTrue:[ |
|
878 |
^ min |
|
879 |
]. |
|
880 |
beg := start + 1. |
|
881 |
||
882 |
beg to:stop do:[:i| |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
883 |
item := list at:i ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
884 |
item isNil ifTrue:[^ min]. |
1390 | 885 |
|
886 |
(nextParent := item parent) == currParent ifFalse:[ |
|
887 |
(currParent := nextParent) == prevItem ifFalse:[ |
|
888 |
(lvl := item level) == 2 ifTrue:[ |
|
889 |
^ 2 |
|
890 |
]. |
|
891 |
min := min min:lvl |
|
892 |
] |
|
893 |
]. |
|
894 |
prevItem := item |
|
895 |
]. |
|
896 |
^ min |
|
897 |
||
898 |
||
899 |
||
900 |
||
901 |
||
902 |
! |
|
903 |
||
904 |
widthOfWidestLineBetween:firstLine and:lastLine |
|
905 |
"return the width of the longest line in pixels |
|
906 |
" |
|
1568 | 907 |
|nprnt pprnt pitem item x |
1390 | 908 |
textX "{ Class: SmallInteger }" |
909 |
level "{ Class: SmallInteger }" |
|
910 |
width "{ Class: SmallInteger }" |
|
911 |
deltaX "{ Class: SmallInteger }" |
|
912 |
startX "{ Class: SmallInteger }" |
|
1568 | 913 |
itemW "{ Class: SmallInteger }" |
1390 | 914 |
| |
1568 | 915 |
width := 20. |
916 |
||
917 |
alignTextRight ifTrue:[ |
|
918 |
firstLine to:lastLine do:[:idx| |
|
919 |
item := list at:idx ifAbsent:nil. |
|
920 |
||
921 |
item isNil ifTrue:[ |
|
922 |
maxWidthOfText := maxWidthOfText max:width. |
|
923 |
^ alignTextRightX + width |
|
924 |
]. |
|
925 |
width := (item widthOn:self) max:width. |
|
926 |
]. |
|
927 |
maxWidthOfText := maxWidthOfText max:width. |
|
928 |
^ alignTextRightX + width |
|
929 |
]. |
|
1390 | 930 |
|
931 |
pprnt := 4711. "/ force a computation |
|
932 |
pitem := 4712. "/ force a computation |
|
933 |
deltaX := imageInset + imageWidth. |
|
1568 | 934 |
|
1390 | 935 |
startX := self xOfStringLevel:1. |
1568 | 936 |
startX := startX + (viewOrigin x). |
1390 | 937 |
|
938 |
firstLine to:lastLine do:[:idx| |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
939 |
item := list at:idx ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
940 |
item isNil ifTrue:[^ width + startX]. |
1390 | 941 |
|
942 |
(nprnt := item parent) ~~ pprnt ifTrue:[ |
|
943 |
(pprnt := nprnt) == pitem ifTrue:[ |
|
944 |
level := level + 1. |
|
945 |
textX := textX + deltaX. |
|
946 |
] ifFalse:[ |
|
947 |
level := item level. |
|
948 |
textX := level - 1 * deltaX. |
|
949 |
] |
|
950 |
]. |
|
951 |
pitem := item. |
|
1568 | 952 |
itemW := item widthOn:self. |
953 |
maxWidthOfText := maxWidthOfText max:itemW. |
|
954 |
width := (itemW + textX) max:width |
|
1390 | 955 |
]. |
1568 | 956 |
^ width + startX. |
1390 | 957 |
|
958 |
! |
|
959 |
||
960 |
xOfFigureLevel:aLevel |
|
961 |
"origin x where to draw the icon |
|
962 |
" |
|
963 |
|l "{ Class:SmallInteger }"| |
|
964 |
||
965 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
|
966 |
||
967 |
indicatorAction isNil ifTrue:[ |
|
968 |
l := l - 1 |
|
969 |
] ifFalse:[ |
|
970 |
showLeftIndicators ifFalse:[ |
|
971 |
l := l - 1 |
|
972 |
] |
|
973 |
]. |
|
974 |
^ (l * (imageInset + imageWidth)) + imageInset - (viewOrigin x) |
|
975 |
! |
|
976 |
||
977 |
xOfStringLevel:aLevel |
|
978 |
"origin x where to draw the text( label ) |
|
979 |
" |
|
1568 | 980 |
alignTextRight ifTrue:[ |
981 |
^ alignTextRightX - (viewOrigin x) |
|
982 |
]. |
|
1390 | 983 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textStartLeft |
984 |
||
1554 | 985 |
! |
986 |
||
987 |
xVisibleOfItem:anItem |
|
988 |
"returns the visible x of the labeled text |
|
989 |
" |
|
990 |
^ self xOfStringLevel:(anItem level) |
|
991 |
||
1390 | 992 |
! ! |
993 |
||
994 |
!HierarchicalListView class methodsFor:'documentation'! |
|
995 |
||
996 |
version |
|
1752 | 997 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.23 2000-04-03 15:07:04 ca Exp $' |
1390 | 998 |
! ! |