author | ca |
Wed, 04 Jul 2001 10:35:29 +0200 | |
changeset 1976 | 1788b0045176 |
parent 1916 | 3021f70d9211 |
child 2049 | ad5f350ae2c2 |
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 |
" |
|
1916 | 91 |
show a hierarchical list |
1757 | 92 |
[exBegin] |
93 |
|top sel list item| |
|
94 |
||
95 |
list := HierarchicalList new. |
|
96 |
item := HierarchicalItem::Example labeled:'Root Item'. |
|
97 |
||
98 |
item expand. |
|
99 |
list showRoot:false. |
|
100 |
list root:item. |
|
101 |
||
102 |
top := StandardSystemView new; extent:300@300. |
|
103 |
sel := ScrollableView for:HierarchicalListView miniScroller:true |
|
104 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
105 |
||
106 |
sel list:list. |
|
107 |
sel multipleSelectOk:true. |
|
108 |
||
109 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ]. |
|
110 |
sel indicatorAction:[:i| (list at:i) toggleExpand ]. |
|
111 |
||
112 |
top open. |
|
113 |
[exEnd] |
|
114 |
||
115 |
||
1916 | 116 |
show a hierarchical list; open an editor on reselect a |
117 |
line with label is a string. |
|
118 |
||
119 |
[exBegin] |
|
120 |
|top sel list item| |
|
121 |
||
122 |
list := HierarchicalList new. |
|
123 |
item := HierarchicalItem::Example labeled:'Root Item'. |
|
124 |
||
125 |
item expand. |
|
126 |
list showRoot:false. |
|
127 |
list root:item. |
|
128 |
||
129 |
top := StandardSystemView new; extent:300@300. |
|
130 |
sel := ScrollableView for:HierarchicalListView miniScroller:true |
|
131 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
132 |
||
133 |
sel list:list. |
|
134 |
||
135 |
sel openEditorAction:[:ln :aGC| |field item| |
|
136 |
item := list at:ln. |
|
137 |
||
138 |
item label isString ifFalse:[ |
|
139 |
field := nil |
|
140 |
] ifTrue:[ |
|
141 |
field := EditField new. |
|
142 |
field level:0. |
|
143 |
field acceptOnLostFocus:true. |
|
144 |
field acceptAction:[:x| item label:(field contents) ]. |
|
145 |
field font:(aGC font). |
|
146 |
field contents:(item label). |
|
147 |
]. |
|
148 |
field |
|
149 |
]. |
|
150 |
||
151 |
sel multipleSelectOk:true. |
|
152 |
||
153 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ]. |
|
154 |
sel indicatorAction:[:i| (list at:i) toggleExpand ]. |
|
155 |
||
156 |
top open. |
|
157 |
[exEnd] |
|
158 |
||
1757 | 159 |
" |
1390 | 160 |
! ! |
161 |
||
162 |
!HierarchicalListView class methodsFor:'resources'! |
|
163 |
||
164 |
closeIndicator |
|
165 |
"returns a little [+] bitmap" |
|
166 |
||
167 |
<resource: #fileImage> |
|
168 |
||
169 |
^ Icon constantNamed:#plus |
|
1632 | 170 |
ifAbsentPut:[Smalltalk imageFromFileNamed:'plus.xpm' forClass:self] |
1390 | 171 |
|
172 |
||
173 |
! |
|
174 |
||
1757 | 175 |
collapsedIcon |
176 |
"returns icon to indicate a collapsed entry |
|
177 |
" |
|
178 |
<resource: #fileImage> |
|
1390 | 179 |
|
1757 | 180 |
^ Icon constantNamed:#directory |
181 |
ifAbsentPut:[Smalltalk imageFromFileNamed:'dir.xpm' forClass:self] |
|
1390 | 182 |
|
183 |
! |
|
184 |
||
185 |
emptyIcon |
|
186 |
"returns icon to indicate an not extendable entry |
|
187 |
" |
|
188 |
<resource: #fileImage> |
|
189 |
||
190 |
^ Icon constantNamed:#plainFile |
|
1632 | 191 |
ifAbsentPut:[Smalltalk imageFromFileNamed:'file_plain.xpm' forClass:self] |
1390 | 192 |
|
193 |
! |
|
194 |
||
195 |
expandedIcon |
|
196 |
"returns icon to indicate an extended entry |
|
197 |
" |
|
198 |
<resource: #fileImage> |
|
199 |
||
200 |
^ Icon constantNamed:#directoryOpened |
|
1632 | 201 |
ifAbsentPut:[Smalltalk imageFromFileNamed:'dir_open.xpm' forClass:self] |
1390 | 202 |
|
203 |
! |
|
204 |
||
1757 | 205 |
openIndicator |
206 |
"returns a little [-] bitmap" |
|
207 |
||
208 |
<resource: #fileImage> |
|
209 |
||
210 |
^ Icon constantNamed:#minus |
|
211 |
ifAbsentPut:[Smalltalk imageFromFileNamed:'minus.xpm' forClass:self] |
|
1390 | 212 |
|
213 |
! ! |
|
214 |
||
215 |
!HierarchicalListView methodsFor:'accessing'! |
|
216 |
||
1843 | 217 |
font:aFont |
218 |
"set a new font |
|
219 |
" |
|
220 |
|root| |
|
221 |
||
222 |
(aFont isNil or:[aFont = font]) ifFalse:[ |
|
223 |
(list notNil and:[(root := list root) notNil]) ifTrue:[ |
|
224 |
root fontChanged |
|
225 |
]. |
|
226 |
super font:aFont |
|
227 |
]. |
|
228 |
! |
|
229 |
||
1390 | 230 |
list:aList |
231 |
"get the status of <showRoot> from the list |
|
232 |
" |
|
233 |
aList notNil ifTrue:[ |
|
234 |
showRoot := aList showRoot |
|
235 |
]. |
|
236 |
super list:aList |
|
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
237 |
! |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
238 |
|
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
239 |
parentToChildInset |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
240 |
"returns the computed inset between parent / child |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
241 |
" |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
242 |
^ imageInset + imageWidth |
1390 | 243 |
! ! |
244 |
||
1818 | 245 |
!HierarchicalListView methodsFor:'accessing-colors'! |
1390 | 246 |
|
247 |
lineColor |
|
248 |
"get the line color |
|
249 |
" |
|
250 |
^ lineColor |
|
251 |
||
252 |
||
253 |
! |
|
254 |
||
255 |
lineColor:aColor |
|
256 |
"set the line color |
|
257 |
" |
|
258 |
(aColor notNil and:[aColor ~= lineColor]) ifTrue:[ |
|
259 |
lineColor := aColor. |
|
260 |
||
261 |
shown ifTrue:[ |
|
262 |
lineColor := lineColor on:device. |
|
263 |
||
264 |
showLines ifTrue:[ |
|
265 |
self invalidate |
|
266 |
] |
|
267 |
] |
|
268 |
] |
|
269 |
||
270 |
! ! |
|
271 |
||
1818 | 272 |
!HierarchicalListView methodsFor:'accessing-look'! |
1390 | 273 |
|
1568 | 274 |
alignTextRight |
275 |
"align the text right |
|
276 |
" |
|
277 |
^ alignTextRight |
|
278 |
! |
|
279 |
||
1757 | 280 |
alignTextRight:aBool |
281 |
"align the text right |
|
282 |
" |
|
283 |
alignTextRight := aBool ? false. |
|
284 |
! |
|
1568 | 285 |
|
1904 | 286 |
alignTextRightX |
287 |
"returns the minimum used text inset, if text is aligned right. |
|
288 |
" |
|
289 |
^ alignTextRightX |
|
290 |
! |
|
291 |
||
292 |
alignTextRightX:aNumber |
|
293 |
"set the minimum used text inset, if text is aligned right. |
|
294 |
" |
|
295 |
aNumber > self parentToChildInset ifTrue:[ |
|
296 |
alignTextRightX := aNumber. |
|
297 |
||
298 |
(alignTextRight and:[widthOfContents notNil]) ifTrue:[ |
|
299 |
widthOfContents := alignTextRightX + maxWidthOfText. |
|
300 |
||
301 |
shown ifTrue:[ |
|
302 |
self invalidate. |
|
303 |
self contentsChanged. |
|
304 |
] |
|
305 |
] |
|
306 |
]. |
|
307 |
! |
|
308 |
||
1390 | 309 |
registerKeysAndIcons:aDictionary |
310 |
"register icons by key and value derived from a directory |
|
311 |
" |
|
312 |
|image| |
|
313 |
||
314 |
(aDictionary isNil or:[aDictionary isEmpty]) ifTrue:[ |
|
315 |
^ self |
|
316 |
]. |
|
317 |
||
318 |
aDictionary keysAndValuesDo:[:aKey :anImage| |
|
319 |
(image := self imageOnDevice:anImage) notNil ifTrue:[ |
|
320 |
icons at:aKey put:image |
|
1746 | 321 |
] ifFalse:[ |
322 |
icons removeKey:aKey ifAbsent:nil |
|
1390 | 323 |
] |
324 |
] |
|
325 |
||
326 |
! |
|
327 |
||
328 |
showLeftIndicators |
|
329 |
"show or hide the indicators for the most left items |
|
330 |
" |
|
331 |
^ showLeftIndicators |
|
332 |
||
333 |
! |
|
334 |
||
335 |
showLeftIndicators:aState |
|
336 |
"show or hide the indicators for the most left items |
|
337 |
" |
|
338 |
aState ~~ showLeftIndicators ifTrue:[ |
|
339 |
showLeftIndicators := aState. |
|
340 |
self invalidate |
|
341 |
]. |
|
342 |
||
343 |
! |
|
344 |
||
345 |
showLines |
|
346 |
"returns true if lines are shown |
|
347 |
" |
|
348 |
^ showLines |
|
349 |
||
350 |
! |
|
351 |
||
352 |
showLines:aState |
|
353 |
"show or hide lines |
|
354 |
" |
|
355 |
aState ~~ showLines ifTrue:[ |
|
356 |
showLines := aState. |
|
357 |
self invalidate |
|
358 |
]. |
|
359 |
||
360 |
! |
|
361 |
||
362 |
useDefaultIcons |
|
363 |
"use the default icons if no icon for an item is specified; |
|
364 |
** default: true |
|
365 |
" |
|
366 |
^ useDefaultIcons |
|
367 |
! |
|
368 |
||
369 |
useDefaultIcons:aBool |
|
370 |
"use the default icons if no icon for an item is specified; |
|
371 |
** default: true |
|
372 |
" |
|
373 |
useDefaultIcons ~~ aBool ifTrue:[ |
|
374 |
useDefaultIcons := aBool. |
|
375 |
||
376 |
shown ifTrue:[ |
|
377 |
self invalidate |
|
378 |
] |
|
379 |
] |
|
380 |
! ! |
|
381 |
||
382 |
!HierarchicalListView methodsFor:'actions'! |
|
383 |
||
384 |
indicatorAction |
|
385 |
"if the action is not nil, indicators are shown and a click on the indicator |
|
386 |
will evaluate the action with none or one argument, the index into the list |
|
387 |
" |
|
388 |
^ indicatorAction |
|
389 |
! |
|
390 |
||
391 |
indicatorAction:anAction |
|
392 |
"if the action is not nil, indicators are shown and a click on the indicator |
|
393 |
will evaluate the action with none or one argument, the index into the list |
|
394 |
" |
|
395 |
|wasNilBefore| |
|
396 |
||
397 |
wasNilBefore := indicatorAction isNil. |
|
398 |
indicatorAction := anAction. |
|
399 |
||
400 |
wasNilBefore == (anAction isNil) ifTrue:[ |
|
401 |
self invalidate |
|
402 |
]. |
|
403 |
! ! |
|
404 |
||
405 |
!HierarchicalListView methodsFor:'change & update'! |
|
406 |
||
1782 | 407 |
indicatorPressedAt:aLnNr |
1783
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
408 |
|item| |
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
409 |
|
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
410 |
indicatorAction notNil ifTrue:[ |
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
411 |
item := list at:aLnNr ifAbsent:nil. |
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
412 |
|
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
413 |
(item notNil and:[item hasChildren]) ifTrue:[ |
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
414 |
(indicatorAction numArgs == 1) ifTrue:[ |
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
415 |
indicatorAction value:aLnNr |
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
416 |
] ifFalse:[ |
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
417 |
indicatorAction value |
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
418 |
] |
1782 | 419 |
] |
420 |
] |
|
421 |
||
422 |
! |
|
423 |
||
1390 | 424 |
lineChangedAt:aLnNr with:arg |
425 |
"line changed at position; check whether line height changed |
|
426 |
" |
|
427 |
|item |
|
428 |
lv "{ Class:SmallInteger }" |
|
429 |
x0 "{ Class:SmallInteger }" |
|
430 |
x1 "{ Class:SmallInteger }" |
|
431 |
h "{ Class:SmallInteger }" |
|
432 |
y0 "{ Class:SmallInteger }" |
|
433 |
y1 "{ Class:SmallInteger }" |
|
434 |
| |
|
435 |
||
1399 | 436 |
(arg == #icon or:[arg == #hierarchy]) ifFalse:[ |
1390 | 437 |
^ super lineChangedAt:aLnNr with:arg |
438 |
]. |
|
1568 | 439 |
shown ifFalse:[^ self]. |
440 |
||
1390 | 441 |
y0 := (self yVisibleOfLine:aLnNr) max:margin. |
442 |
y1 := (self yVisibleOfLine:(aLnNr + 1)) min:(height - margin). |
|
443 |
||
1399 | 444 |
(h := y1 - y0) > 0 ifTrue:[ |
445 |
x0 := margin. |
|
446 |
x1 := width - margin. |
|
447 |
||
448 |
(item := list at:aLnNr ifAbsent:nil) isNil ifFalse:[ |
|
449 |
lv := item level. |
|
1570 | 450 |
x1 := (self xOfStringLevel:lv) - (textStartLeft // 2). |
1390 | 451 |
|
1399 | 452 |
arg == #hierarchy ifTrue:[ |
453 |
x0 := self xOfFigureLevel:(lv -1). |
|
1570 | 454 |
] ifFalse:[ |
455 |
x0 := self xOfFigureLevel:lv |
|
1399 | 456 |
]. |
457 |
x0 := x0 max:margin. |
|
458 |
x1 := x1 min:(width - margin). |
|
1568 | 459 |
x1 > x0 ifFalse:[^ self] |
460 |
]. |
|
461 |
self repairDamage. |
|
462 |
self invalidate:(Rectangle left:x0 top:y0 width:(x1 - x0) height:h) |
|
463 |
repairNow:true. |
|
464 |
] |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
465 |
! |
1390 | 466 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
467 |
listChangedInsert:firstAddedIndex nItems:nLines |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
468 |
"must draw vertical lines above the added items |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
469 |
" |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
470 |
|item prnt idx level yTop yBot xLft rec start maxY| |
1390 | 471 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
472 |
super listChangedInsert:firstAddedIndex nItems:nLines. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
473 |
|
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
474 |
( shown |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
475 |
and:[showLines |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
476 |
and:[firstAddedIndex > 1 |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
477 |
and:[nLines ~~ 0 |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
478 |
and:[(item := list at:firstAddedIndex ifAbsent:nil) notNil |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
479 |
and:[(level := item level) > 1]]]]] |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
480 |
) ifFalse:[ |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
481 |
^ self. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
482 |
]. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
483 |
xLft := (self xOfFigureLevel:(level - 1)) + (imageWidth // 2) - 1. |
1390 | 484 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
485 |
(xLft > margin and:[xLft < (width - margin)]) ifFalse:[ |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
486 |
^ self |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
487 |
]. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
488 |
start := firstAddedIndex - 1. |
1390 | 489 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
490 |
start to:1 by:-1 do:[:i| |el| |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
491 |
el := list at:i. |
1399 | 492 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
493 |
el level <= level ifTrue:[ |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
494 |
i == start ifTrue:[^ self]. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
495 |
|
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
496 |
yTop := (self yVisibleOfLine:i + 1) max:margin. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
497 |
maxY := height - margin. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
498 |
|
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
499 |
yTop < maxY ifTrue:[ |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
500 |
yBot := (self yVisibleOfLine:firstAddedIndex) - 1 min:maxY. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
501 |
self invalidate:(Rectangle left:xLft top:yTop width:3 height:(yBot - yTop)) |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
502 |
]. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
503 |
^ self |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
504 |
] |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
505 |
]. |
1390 | 506 |
! |
507 |
||
508 |
update:what with:aPara from:chgObj |
|
509 |
"get the status of <showRoot> from the list |
|
510 |
" |
|
511 |
chgObj == list ifTrue:[ |
|
512 |
showRoot ~~ list showRoot ifTrue:[ |
|
513 |
showRoot := list showRoot. |
|
514 |
self invalidate. |
|
515 |
] |
|
516 |
]. |
|
517 |
super update:what with:aPara from:chgObj |
|
518 |
! ! |
|
519 |
||
520 |
!HierarchicalListView methodsFor:'drawing basics'! |
|
521 |
||
1757 | 522 |
displayElement:anItem x:x y:y h:h |
523 |
"draw a label at x/y; fg/bg colors are already set |
|
524 |
" |
|
525 |
anItem displayOn:self x:x y:y h:h |
|
526 |
||
1399 | 527 |
! |
528 |
||
1568 | 529 |
drawElementsFrom:start to:stop x:xLeft y:yT w:w |
1390 | 530 |
"draw the items between start to stop without clearing the background |
531 |
" |
|
532 |
|item prevItem parent icon showIndc showIcon showText nxtPrnt |
|
533 |
||
1568 | 534 |
yTop "{ Class:SmallInteger }" |
535 |
yCtr "{ Class:SmallInteger }" |
|
536 |
yBot "{ Class:SmallInteger }" |
|
1390 | 537 |
|
1568 | 538 |
xIndc "{ Class:SmallInteger }" |
539 |
xIcon "{ Class:SmallInteger }" |
|
540 |
xText "{ Class:SmallInteger }" |
|
541 |
xDeltaIT "{ Class:SmallInteger }" |
|
542 |
xL "{ Class:SmallInteger }" |
|
543 |
xR "{ Class:SmallInteger }" |
|
544 |
height "{ Class:SmallInteger }" |
|
1390 | 545 |
|
1568 | 546 |
widthLvl "{ Class:SmallInteger }" |
547 |
insetTxt "{ Class:SmallInteger }" |
|
1390 | 548 |
|
1568 | 549 |
offIndcX "{ Class:SmallInteger }" |
550 |
offIndcY "{ Class:SmallInteger }" |
|
551 |
offIconX "{ Class:SmallInteger }" |
|
552 |
iconWidth "{ Class:SmallInteger }" |
|
553 |
iconRgtX "{ Class:SmallInteger }" |
|
1390 | 554 |
| |
555 |
widthLvl := imageInset + imageWidth. |
|
556 |
insetTxt := textStartLeft + imageWidth. |
|
1568 | 557 |
xL := xLeft. |
558 |
xR := xL + w. |
|
559 |
||
560 |
alignTextRight ifTrue:[ |
|
561 |
xText := alignTextRightX - (viewOrigin x). |
|
562 |
showText := xText < xR. |
|
563 |
]. |
|
564 |
||
1390 | 565 |
offIconX := self xOfFigureLevel:0. |
566 |
showIndc := false. |
|
567 |
||
568 |
indicatorAction notNil ifTrue:[ |
|
569 |
icon := openIndicator extent // 2. |
|
570 |
offIndcX := imageWidth // 2 - widthLvl. |
|
571 |
offIndcX := offIndcX - icon x. |
|
572 |
offIndcY := icon y. |
|
573 |
]. |
|
574 |
||
575 |
showLines ifTrue:[ |
|
1399 | 576 |
self drawLinesFrom:start to:stop x:xL y:yT toX:xR |
1390 | 577 |
]. |
578 |
||
579 |
parent := 4711. "/ to force a recompute |
|
580 |
prevItem := 4711. "/ to force a recomputation of the level |
|
1399 | 581 |
yBot := yT. |
1756 | 582 |
xIcon := offIconX. |
1390 | 583 |
|
584 |
start to:stop do:[:anIndex| |
|
585 |
(item := list at:anIndex ifAbsent:nil) isNil ifTrue:[ |
|
586 |
^ self "/ list changed |
|
587 |
]. |
|
588 |
yTop := yBot. |
|
589 |
yBot := self yVisibleOfLine:(anIndex + 1). |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
590 |
height := yBot - yTop. |
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
591 |
|
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
592 |
yCtr := yTop + (height // 2). |
1390 | 593 |
|
594 |
(nxtPrnt := item parent) ~~ parent ifTrue:[ |
|
595 |
parent := nxtPrnt. |
|
596 |
xIcon := prevItem == parent ifTrue:[xIcon + widthLvl] |
|
597 |
ifFalse:[item level * widthLvl + offIconX]. |
|
598 |
||
1568 | 599 |
|
600 |
alignTextRight ifFalse:[ |
|
601 |
xText := xIcon + insetTxt. |
|
602 |
showText := xText < xR. |
|
603 |
]. |
|
1399 | 604 |
showIcon := xIcon < xR and:[xText > xL]. |
1390 | 605 |
|
606 |
indicatorAction notNil ifTrue:[ |
|
607 |
xIndc := xIcon + offIndcX. |
|
608 |
||
1756 | 609 |
(xIcon > xL and:[xIndc < xR]) ifTrue:[ |
610 |
showIndc := parent notNil or:[showLeftIndicators] |
|
611 |
] ifFalse:[ |
|
612 |
showIndc := false |
|
613 |
] |
|
1390 | 614 |
] |
615 |
]. |
|
616 |
||
617 |
(showIcon and:[(icon := self figureFor:item) notNil]) ifTrue:[ |
|
1568 | 618 |
iconWidth := icon width. |
619 |
iconRgtX := xIcon + iconWidth. |
|
620 |
xDeltaIT := xText - textStartLeft - iconRgtX. |
|
621 |
||
622 |
xDeltaIT < 0 ifTrue:[ |
|
623 |
alignTextRightX := alignTextRightX - xDeltaIT. |
|
624 |
||
625 |
alignTextRight ifFalse:[ |
|
626 |
imageWidth := iconWidth. |
|
627 |
widthOfContents := widthOfContents - xDeltaIT. |
|
628 |
] ifTrue:[ |
|
629 |
widthOfContents := alignTextRightX + maxWidthOfText |
|
630 |
]. |
|
631 |
self contentsChanged. |
|
1390 | 632 |
StopRedrawSignal raise |
633 |
]. |
|
1568 | 634 |
iconRgtX > xL ifTrue:[ |
635 |
self displayForm:icon x:xIcon y:(yCtr - (icon height // 2)) |
|
636 |
] |
|
1390 | 637 |
]. |
638 |
||
639 |
showText ifTrue:[ |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
640 |
self drawLabelAt:anIndex x:xText y:yTop h:height |
1390 | 641 |
]. |
642 |
(showIndc and:[item hasChildren]) ifTrue:[ |
|
643 |
icon := item isExpanded ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
|
644 |
self displayForm:icon x:xIndc y:(yCtr - offIndcY) |
|
645 |
]. |
|
646 |
prevItem := item. |
|
647 |
] |
|
1568 | 648 |
|
649 |
||
1390 | 650 |
! |
651 |
||
1399 | 652 |
drawLinesFrom:start to:stop x:xL y:yT toX:xR |
1390 | 653 |
"draw the lines between start to stop without clearing the background |
654 |
" |
|
655 |
|item prevItem parent p1 p2 showVLines showHLine lv nxtPrnt |
|
656 |
showRootNot isFirst buildInArray |
|
657 |
||
658 |
x "{ Class:SmallInteger }" |
|
1570 | 659 |
xText "{ Class:SmallInteger }" |
660 |
||
1390 | 661 |
y "{ Class:SmallInteger }" |
662 |
yTop "{ Class:SmallInteger }" |
|
663 |
yBot "{ Class:SmallInteger }" |
|
664 |
yCtr "{ Class:SmallInteger }" |
|
665 |
||
666 |
begHLnY "{ Class:SmallInteger }" |
|
667 |
runHLnY "{ Class:SmallInteger }" |
|
668 |
begHLnX "{ Class:SmallInteger }" |
|
669 |
endHLnX "{ Class:SmallInteger }" |
|
670 |
||
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
671 |
widthLvl "{ Class:SmallInteger }" |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
672 |
offsHLnX "{ Class:SmallInteger }" |
1390 | 673 |
|
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
674 |
level "{ Class:SmallInteger }" |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
675 |
startLvI "{ Class:SmallInteger }" |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
676 |
startLvX "{ Class:SmallInteger }" |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
677 |
limitLvI "{ Class:SmallInteger }" |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
678 |
limitLvX "{ Class:SmallInteger }" |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
679 |
imgHWdt "{ Class:SmallInteger }" |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
680 |
minXVLine "{ Class:SmallInteger }" |
1390 | 681 |
| |
1792
26aa6dc38278
draw vertical line not into icon if no children defined
ca
parents:
1784
diff
changeset
|
682 |
imgHWdt := imageWidth // 2. |
1390 | 683 |
widthLvl := imageInset + imageWidth. |
1792
26aa6dc38278
draw vertical line not into icon if no children defined
ca
parents:
1784
diff
changeset
|
684 |
offsHLnX := imgHWdt + (self xOfFigureLevel:-1). |
1390 | 685 |
|
686 |
parent := 4711. "/ to force a recompute |
|
687 |
prevItem := 4711. "/ to force a recomputation of the level |
|
688 |
||
689 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
690 |
self paint:lineColor on:bgColor. |
|
691 |
self mask:lineMask. |
|
692 |
startLvI := self smallestLevelBetween:start and:stop. |
|
693 |
startLvX := self xOfFigureLevel:startLvI. |
|
694 |
limitLvI := 2. |
|
695 |
limitLvX := limitLvI * widthLvl + offsHLnX. |
|
696 |
||
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
697 |
showRoot ifFalse:[ |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
698 |
minXVLine := (self xOfFigureLevel:2) - 2. "/ tolerance |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
699 |
] ifTrue:[ |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
700 |
minXVLine := 0 |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
701 |
]. |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
702 |
|
1567 | 703 |
showRootNot := showRoot not. |
704 |
yBot := yT. |
|
705 |
begHLnY := runHLnY := yT. |
|
1756 | 706 |
endHLnX := limitLvX. |
707 |
level := 1. |
|
1390 | 708 |
|
1570 | 709 |
alignTextRight ifTrue:[ |
710 |
xText := alignTextRightX - (viewOrigin x) - textStartLeft. |
|
711 |
]. |
|
712 |
||
1390 | 713 |
start to:stop do:[:anIndex| |
714 |
(item := list at:anIndex ifAbsent:nil) isNil ifTrue:[ |
|
715 |
^ self mask:nil "/ list changed |
|
716 |
]. |
|
717 |
yTop := yBot. |
|
718 |
yBot := self yVisibleOfLine:(anIndex + 1). |
|
719 |
yCtr := yTop + (yBot - yTop // 2). |
|
720 |
anIndex == 1 ifTrue:[ begHLnY := runHLnY := yCtr ]. |
|
721 |
||
722 |
(nxtPrnt := item parent) ~~ parent ifTrue:[ |
|
723 |
parent := nxtPrnt. |
|
724 |
||
725 |
prevItem == parent ifTrue:[ |
|
1567 | 726 |
level := level + 1. |
1390 | 727 |
begHLnX := endHLnX. |
728 |
] ifFalse:[ |
|
729 |
level := item level. |
|
1567 | 730 |
begHLnX := level * widthLvl + offsHLnX. |
1390 | 731 |
]. |
732 |
||
733 |
isFirst := parent isNil or:[(showRootNot and:[level == 2])]. |
|
734 |
endHLnX := begHLnX + widthLvl. |
|
1399 | 735 |
showVLines := begHLnX >= xL and:[level > 1]. |
1570 | 736 |
|
737 |
alignTextRight ifFalse:[ |
|
738 |
xText := endHLnX + (widthLvl // 2). |
|
739 |
]. |
|
740 |
showHLine := (xL < xText and:[xR > begHLnX]). |
|
1390 | 741 |
|
742 |
(showHLine and:[isFirst]) ifTrue:[ |
|
743 |
showHLine := showLeftIndicators and:[indicatorAction notNil] |
|
744 |
] |
|
745 |
]. |
|
746 |
||
747 |
showHLine ifTrue:[ |
|
1570 | 748 |
item drawHorizontalLineUpToText ifTrue:[ |
749 |
p1 := xText |
|
750 |
] ifFalse:[ |
|
1792
26aa6dc38278
draw vertical line not into icon if no children defined
ca
parents:
1784
diff
changeset
|
751 |
item hasChildren ifTrue:[ |
26aa6dc38278
draw vertical line not into icon if no children defined
ca
parents:
1784
diff
changeset
|
752 |
p1 := endHLnX. |
26aa6dc38278
draw vertical line not into icon if no children defined
ca
parents:
1784
diff
changeset
|
753 |
] ifFalse:[ |
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
754 |
(showRoot not and:[item parent isRootItem]) ifTrue:[ |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
755 |
p1 := xL - 1 "/ do not draw the horizontal line |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
756 |
] ifFalse:[ |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
757 |
p1 := begHLnX + imgHWdt |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
758 |
] |
1792
26aa6dc38278
draw vertical line not into icon if no children defined
ca
parents:
1784
diff
changeset
|
759 |
] |
1570 | 760 |
]. |
1792
26aa6dc38278
draw vertical line not into icon if no children defined
ca
parents:
1784
diff
changeset
|
761 |
xL < p1 ifTrue:[ |
1570 | 762 |
self displayLineFromX:begHLnX y:yCtr toX:p1 y:yCtr |
763 |
] |
|
1390 | 764 |
]. |
765 |
||
766 |
showVLines ifTrue:[ |
|
767 |
y := (parent last == item) ifTrue:[yCtr] ifFalse:[yBot]. |
|
768 |
x := begHLnX. |
|
769 |
p2 := parent. |
|
770 |
lv := level - 1. |
|
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
771 |
|
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
772 |
x >= minXVLine ifTrue:[ |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
773 |
self displayLineFromX:x y:runHLnY toX:x y:y. |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
774 |
]. |
1390 | 775 |
|
776 |
[((p1 := p2 parent) notNil and:[(x := x - widthLvl) >= limitLvX])] whileTrue:[ |
|
1399 | 777 |
(p1 last ~~ p2 and:[x <= xR]) ifTrue:[ |
1390 | 778 |
x >= startLvX ifTrue:[ |
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
779 |
x >= minXVLine ifTrue:[ |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
780 |
self displayLineFromX:x y:(yTop - 1) toX:x y:yBot |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
781 |
] |
1390 | 782 |
] ifFalse:[ |
1567 | 783 |
buildInArray isNil ifTrue:[buildInArray := Array new:startLvI]. |
1390 | 784 |
buildInArray at:lv put:yBot |
785 |
]. |
|
786 |
]. |
|
787 |
lv := lv - 1. |
|
788 |
p2 := p1 |
|
789 |
] |
|
790 |
]. |
|
791 |
prevItem := item. |
|
792 |
runHLnY := yCtr. |
|
793 |
]. |
|
794 |
||
795 |
"/ |
|
796 |
"/ draw outstanding verical lines to left |
|
797 |
"/ |
|
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
798 |
x := minXVLine max:xL. |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
799 |
|
1567 | 800 |
(item isExpanded and:[item hasChildren]) ifTrue:[ |
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
801 |
(endHLnX >= x and:[endHLnX <= xR]) ifTrue:[ |
1567 | 802 |
self displayLineFromX:endHLnX y:yCtr toX:endHLnX y:yBot. |
803 |
] |
|
1390 | 804 |
]. |
1567 | 805 |
|
806 |
buildInArray notNil ifTrue:[ |
|
807 |
x := limitLvX. |
|
808 |
y := begHLnY. |
|
1390 | 809 |
|
1567 | 810 |
limitLvI to:startLvI do:[:i| |
1597 | 811 |
|yB| |
1596 | 812 |
|
1597 | 813 |
(yB := buildInArray at:i) notNil ifTrue:[ |
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
814 |
x >= minXVLine ifTrue:[ |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
815 |
self displayLineFromX:x y:y toX:x y:yB |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
816 |
] |
1567 | 817 |
]. |
818 |
x := x + widthLvl. |
|
1390 | 819 |
] |
820 |
]. |
|
821 |
self mask:nil. |
|
822 |
! ! |
|
823 |
||
824 |
!HierarchicalListView methodsFor:'event handling'! |
|
825 |
||
826 |
buttonMultiPress:button x:x y:y |
|
827 |
"handle a button multiPress event |
|
828 |
" |
|
829 |
|lnNr| |
|
830 |
||
831 |
enabled ifTrue:[ |
|
832 |
( (button == 1 or:[button == #select]) |
|
833 |
and:[(lnNr := self indicatorLineAtX:x y:y) notNil] |
|
834 |
) ifFalse:[ |
|
835 |
super buttonMultiPress:button x:x y:y |
|
836 |
] |
|
837 |
] |
|
838 |
! |
|
839 |
||
1757 | 840 |
buttonPress:button x:x y:y |
841 |
"handle a button press event |
|
842 |
" |
|
843 |
|lnNr| |
|
1390 | 844 |
|
1757 | 845 |
enabled ifTrue:[ |
846 |
(button == 1 or:[button == #select]) ifTrue:[ |
|
847 |
(lnNr := self indicatorLineAtX:x y:y) notNil ifTrue:[ |
|
1782 | 848 |
^ self indicatorPressedAt:lnNr |
1390 | 849 |
] |
850 |
]. |
|
851 |
super buttonPress:button x:x y:y |
|
852 |
] |
|
1757 | 853 |
! |
854 |
||
855 |
keyPress:aKey x:x y:y |
|
856 |
"a key was pressed - handle page-keys here |
|
857 |
" |
|
1784 | 858 |
<resource: #keyboard( #CursorLeft #CursorRight )> |
1757 | 859 |
|
860 |
|item parent index size stop step| |
|
861 |
||
1782 | 862 |
enabled ifFalse:[^ self]. |
863 |
||
864 |
aKey == Character space ifTrue:[ |
|
865 |
(indicatorAction notNil and:[(index := self selectedIndex) ~~ 0]) ifTrue:[ |
|
866 |
^ self indicatorPressedAt:index |
|
867 |
] |
|
868 |
]. |
|
869 |
||
1757 | 870 |
(aKey == #CursorLeft or:[aKey == #CursorRight]) ifFalse:[ |
871 |
^ super keyPress:aKey x:x y:y |
|
872 |
]. |
|
1390 | 873 |
|
1757 | 874 |
( enabled |
875 |
and:[(size := list size) > 1 |
|
876 |
and:[(index := self selectedIndex) ~~ 0 |
|
877 |
and:[(item := list at:index ifAbsent:nil) notNil]]] |
|
878 |
) ifTrue:[ |
|
879 |
parent := item parent. |
|
1390 | 880 |
|
1757 | 881 |
aKey == #CursorLeft ifTrue:[step := -1. stop := 1] |
882 |
ifFalse:[step := 1. stop := size]. |
|
883 |
||
884 |
(index + step) to:stop by:step do:[:i| |
|
885 |
item := list at:i ifAbsent:nil. |
|
886 |
item isNil ifTrue:[^ nil]. |
|
887 |
item parent ~~ parent ifTrue:[^ self selection:i] |
|
1390 | 888 |
]. |
889 |
||
890 |
index := aKey == #CursorLeft ifTrue:[size] ifFalse:[1]. |
|
891 |
self selection:index |
|
892 |
]. |
|
893 |
! ! |
|
894 |
||
1757 | 895 |
!HierarchicalListView methodsFor:'fetch resources'! |
896 |
||
897 |
fetchResources |
|
898 |
"fetch device colors and ..., to avoid reallocation at redraw time; |
|
899 |
*** called after a create or snapin to fetch all device resources |
|
900 |
" |
|
901 |
|image| |
|
902 |
||
903 |
super fetchResources. |
|
904 |
||
905 |
lineMask := lineMask onDevice:device. |
|
906 |
lineColor := lineColor onDevice:device. |
|
907 |
openIndicator := self imageOnDevice:openIndicator. |
|
908 |
closeIndicator := self imageOnDevice:closeIndicator. |
|
909 |
imageWidth := 2. |
|
910 |
||
911 |
icons keysAndValuesDo:[:aKey :anImage| |
|
912 |
anImage isNil ifTrue:[ |
|
913 |
('HierachicalListView [warning]: missing image: ' , aKey) errorPrintCR. |
|
914 |
] ifFalse:[ |
|
915 |
image := self imageOnDevice:anImage. |
|
916 |
icons at:aKey put:image. |
|
917 |
imageWidth := image width max:imageWidth. |
|
918 |
] |
|
919 |
]. |
|
920 |
imageWidth := imageWidth + 1 // 2 * 2. |
|
1904 | 921 |
alignTextRightX := imageWidth + 20 max:alignTextRightX. |
1757 | 922 |
! ! |
923 |
||
1390 | 924 |
!HierarchicalListView methodsFor:'initialize / release'! |
925 |
||
926 |
initStyle |
|
927 |
"setup viewStyle specifics |
|
928 |
" |
|
929 |
|cls| |
|
930 |
||
931 |
super initStyle. |
|
932 |
||
933 |
cls := self class. |
|
934 |
||
935 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
|
1779
5848ce6ff439
change registeredIcons from IdentityDictionary to Dictionary
ca
parents:
1757
diff
changeset
|
936 |
icons := Dictionary new. |
1390 | 937 |
|
938 |
openIndicator := self class openIndicator. |
|
939 |
closeIndicator := self class closeIndicator. |
|
940 |
lineColor := fgColor. |
|
941 |
highlightMode := #label. |
|
942 |
showRoot := true. |
|
943 |
showLeftIndicators := true. |
|
944 |
useDefaultIcons := true. |
|
945 |
showLines := true. |
|
946 |
imageInset := 4. |
|
1746 | 947 |
imageWidth := 4. "/ default |
1568 | 948 |
alignTextRight := false. |
949 |
alignTextRightX := 8. |
|
950 |
maxWidthOfText := 0. |
|
1390 | 951 |
! ! |
952 |
||
953 |
!HierarchicalListView methodsFor:'private'! |
|
954 |
||
955 |
figureFor:anItem |
|
956 |
"return a (bitmap) figure for an item |
|
957 |
" |
|
1756 | 958 |
|key image| |
1390 | 959 |
|
960 |
"/ the item may provide an icon |
|
961 |
"/ (it knows for itself if its open or closed) |
|
962 |
||
963 |
(key := anItem icon) notNil ifTrue:[ |
|
964 |
(key isImageOrForm and:[key device == device]) ifTrue:[ |
|
965 |
^ key |
|
966 |
]. |
|
967 |
||
968 |
(image := icons at:key ifAbsent:nil) notNil ifTrue:[ |
|
969 |
^ image |
|
970 |
]. |
|
971 |
||
972 |
key isImageOrForm ifTrue:[ |
|
973 |
image := self imageOnDevice:key. |
|
974 |
icons at:key put:image. |
|
975 |
^ image |
|
976 |
] |
|
977 |
]. |
|
978 |
||
979 |
useDefaultIcons ifFalse:[^ nil]. |
|
980 |
||
981 |
"/ ok, item did not return an icon - use default. |
|
982 |
||
983 |
anItem hasChildren ifTrue:[ |
|
984 |
key := anItem isExpanded ifTrue:[#expanded] ifFalse:[#collapsed] |
|
985 |
] ifFalse:[ |
|
986 |
key := #empty |
|
987 |
]. |
|
1898 | 988 |
image := icons at:key ifAbsent:nil. |
989 |
||
990 |
image isNil ifTrue:[ |
|
991 |
key == #expanded ifTrue:[image := self class expandedIcon]. |
|
992 |
key == #collapsed ifTrue:[image := self class collapsedIcon]. |
|
993 |
key == #empty ifTrue:[image := self class emptyIcon]. |
|
994 |
||
995 |
image isNil ifTrue:[^ nil]. |
|
996 |
image := self imageOnDevice:image. |
|
997 |
icons at:key put:image. |
|
998 |
]. |
|
999 |
^ image |
|
1390 | 1000 |
! |
1001 |
||
1002 |
heightOfLineAt:aLineNr |
|
1003 |
"returns the total height for a line at an index, including |
|
1004 |
lineSpacing, the figure and the label |
|
1005 |
" |
|
1006 |
|item icon height| |
|
1007 |
||
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1008 |
item := list at:aLineNr ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1009 |
item isNil ifTrue:[^ 4]. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1010 |
|
1390 | 1011 |
height := item heightOn:self. |
1012 |
||
1013 |
(icon := self figureFor:item) notNil ifTrue:[ |
|
1391 | 1014 |
height := (icon heightOn:self) max:height. |
1390 | 1015 |
]. |
1016 |
^ lineSpacing + height |
|
1017 |
||
1018 |
||
1019 |
! |
|
1020 |
||
1757 | 1021 |
indicatorLineAtX:x y:y |
1022 |
"returns the lineNumber assigned to an indicator at x/y or nil |
|
1023 |
" |
|
1024 |
|lnNr item x0| |
|
1390 | 1025 |
|
1757 | 1026 |
( indicatorAction isNil |
1027 |
or:[(lnNr := self yVisibleToLineNr:y) isNil |
|
1028 |
or:[(item := list at:lnNr ifAbsent:nil) isNil |
|
1029 |
or:[item hasChildren not]]] |
|
1030 |
) ifFalse:[ |
|
1031 |
x0 := self xOfFigureLevel:(item level - 1). |
|
1032 |
||
1033 |
(x > x0 and:[(x0 + imageWidth) > x]) ifTrue:[ |
|
1034 |
^ lnNr |
|
1035 |
] |
|
1756 | 1036 |
]. |
1757 | 1037 |
^ nil |
1390 | 1038 |
! |
1039 |
||
1040 |
smallestLevelBetween:start and:stop |
|
1041 |
"returns the smallest level between a range |
|
1042 |
" |
|
1043 |
|prevItem currParent nextParent item |
|
1044 |
||
1045 |
lvl "{ Class:SmallInteger }" |
|
1046 |
min "{ Class:SmallInteger }" |
|
1047 |
beg "{ Class:SmallInteger }" |
|
1048 |
| |
|
1049 |
||
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1050 |
prevItem := list at:start ifAbsent:nil. |
1390 | 1051 |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1052 |
(prevItem isNil or:[(currParent := prevItem parent) isNil]) ifTrue:[ |
1390 | 1053 |
^ 1 |
1054 |
]. |
|
1055 |
||
1056 |
(min := prevItem level) == 2 ifTrue:[ |
|
1057 |
^ min |
|
1058 |
]. |
|
1059 |
beg := start + 1. |
|
1060 |
||
1061 |
beg to:stop do:[:i| |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1062 |
item := list at:i ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1063 |
item isNil ifTrue:[^ min]. |
1390 | 1064 |
|
1065 |
(nextParent := item parent) == currParent ifFalse:[ |
|
1066 |
(currParent := nextParent) == prevItem ifFalse:[ |
|
1067 |
(lvl := item level) == 2 ifTrue:[ |
|
1068 |
^ 2 |
|
1069 |
]. |
|
1070 |
min := min min:lvl |
|
1071 |
] |
|
1072 |
]. |
|
1073 |
prevItem := item |
|
1074 |
]. |
|
1075 |
^ min |
|
1076 |
||
1077 |
||
1078 |
||
1079 |
||
1080 |
||
1081 |
! |
|
1082 |
||
1083 |
widthOfWidestLineBetween:firstLine and:lastLine |
|
1084 |
"return the width of the longest line in pixels |
|
1085 |
" |
|
1756 | 1086 |
|nprnt pprnt pitem item |
1390 | 1087 |
textX "{ Class: SmallInteger }" |
1088 |
level "{ Class: SmallInteger }" |
|
1089 |
width "{ Class: SmallInteger }" |
|
1090 |
deltaX "{ Class: SmallInteger }" |
|
1091 |
startX "{ Class: SmallInteger }" |
|
1568 | 1092 |
itemW "{ Class: SmallInteger }" |
1390 | 1093 |
| |
1568 | 1094 |
width := 20. |
1095 |
||
1096 |
alignTextRight ifTrue:[ |
|
1097 |
firstLine to:lastLine do:[:idx| |
|
1098 |
item := list at:idx ifAbsent:nil. |
|
1099 |
||
1100 |
item isNil ifTrue:[ |
|
1101 |
maxWidthOfText := maxWidthOfText max:width. |
|
1102 |
^ alignTextRightX + width |
|
1103 |
]. |
|
1104 |
width := (item widthOn:self) max:width. |
|
1105 |
]. |
|
1106 |
maxWidthOfText := maxWidthOfText max:width. |
|
1107 |
^ alignTextRightX + width |
|
1108 |
]. |
|
1390 | 1109 |
|
1110 |
pprnt := 4711. "/ force a computation |
|
1111 |
pitem := 4712. "/ force a computation |
|
1112 |
deltaX := imageInset + imageWidth. |
|
1568 | 1113 |
|
1390 | 1114 |
startX := self xOfStringLevel:1. |
1568 | 1115 |
startX := startX + (viewOrigin x). |
1756 | 1116 |
textX := 0. |
1117 |
level := 1. |
|
1390 | 1118 |
|
1119 |
firstLine to:lastLine do:[:idx| |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1120 |
item := list at:idx ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1121 |
item isNil ifTrue:[^ width + startX]. |
1390 | 1122 |
|
1123 |
(nprnt := item parent) ~~ pprnt ifTrue:[ |
|
1124 |
(pprnt := nprnt) == pitem ifTrue:[ |
|
1125 |
level := level + 1. |
|
1126 |
textX := textX + deltaX. |
|
1127 |
] ifFalse:[ |
|
1128 |
level := item level. |
|
1129 |
textX := level - 1 * deltaX. |
|
1130 |
] |
|
1131 |
]. |
|
1132 |
pitem := item. |
|
1568 | 1133 |
itemW := item widthOn:self. |
1134 |
maxWidthOfText := maxWidthOfText max:itemW. |
|
1135 |
width := (itemW + textX) max:width |
|
1390 | 1136 |
]. |
1568 | 1137 |
^ width + startX. |
1390 | 1138 |
|
1139 |
! |
|
1140 |
||
1141 |
xOfFigureLevel:aLevel |
|
1142 |
"origin x where to draw the icon |
|
1143 |
" |
|
1144 |
|l "{ Class:SmallInteger }"| |
|
1145 |
||
1146 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
|
1147 |
||
1148 |
indicatorAction isNil ifTrue:[ |
|
1149 |
l := l - 1 |
|
1150 |
] ifFalse:[ |
|
1151 |
showLeftIndicators ifFalse:[ |
|
1152 |
l := l - 1 |
|
1153 |
] |
|
1154 |
]. |
|
1155 |
^ (l * (imageInset + imageWidth)) + imageInset - (viewOrigin x) |
|
1156 |
! |
|
1157 |
||
1757 | 1158 |
xOfStringLevel:aLevel |
1159 |
"origin x where to draw the text( label ) |
|
1160 |
" |
|
1161 |
alignTextRight ifTrue:[ |
|
1162 |
^ alignTextRightX - (viewOrigin x) |
|
1163 |
]. |
|
1164 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textStartLeft |
|
1756 | 1165 |
|
1554 | 1166 |
! |
1167 |
||
1168 |
xVisibleOfItem:anItem |
|
1169 |
"returns the visible x of the labeled text |
|
1170 |
" |
|
1171 |
^ self xOfStringLevel:(anItem level) |
|
1172 |
||
1390 | 1173 |
! ! |
1174 |
||
1175 |
!HierarchicalListView class methodsFor:'documentation'! |
|
1176 |
||
1177 |
version |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
1178 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.37 2001-07-04 08:35:29 ca Exp $' |
1390 | 1179 |
! ! |