author | ca |
Thu, 19 Dec 2002 07:21:30 +0100 | |
changeset 2417 | a0b7d30a4073 |
parent 2414 | d219f6330831 |
child 2421 | f5654eeb3118 |
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 |
2377 | 17 |
instanceVariableNames:'imageInset imageWidth lineColor showRoot showLines |
2392 | 18 |
useDefaultIcons icons openIndicator closeIndicator alignTextRight |
19 |
alignTextRightX maxWidthOfText minLineHeight levelOfLastItem |
|
20 |
expandOnSelect autoScrollHorizontal showIndicators |
|
21 |
showLeftIndicators indicatorAction' |
|
2361 | 22 |
classVariableNames:'' |
23 |
poolDictionaries:'' |
|
24 |
category:'Views-Trees' |
|
1390 | 25 |
! |
26 |
||
27 |
!HierarchicalListView class methodsFor:'documentation'! |
|
28 |
||
1431 | 29 |
copyright |
30 |
" |
|
31 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
32 |
All Rights Reserved |
|
33 |
||
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
||
42 |
! |
|
43 |
||
1757 | 44 |
documentation |
1390 | 45 |
" |
1757 | 46 |
This class implements a hierarchical list view based on a |
47 |
hierachical list. |
|
48 |
It provides functionality similar to SelectionInTreeView, but optimizes |
|
49 |
redraws, and operates directly upon the model (in contrast to |
|
50 |
SelectionInTreeView, which generates a list internally). |
|
1390 | 51 |
|
1757 | 52 |
[Instance variables:] |
53 |
textStartLeft <Integer> inset between icon and text |
|
54 |
imageInset <Integer> inset between left side and icon |
|
55 |
imageWidth <Integer> width of widest icon |
|
2312 | 56 |
minLineHeight <Integer> minimum required line height |
57 |
including open/close indication ... |
|
1757 | 58 |
lineMask <Form> line mask |
59 |
lineColor <Color> line color |
|
60 |
showRoot <Boolean> root element is shown or hidden |
|
61 |
derives from the hierachical list. |
|
62 |
showLines <Boolean> show or hide lines |
|
2392 | 63 |
showIndicators <Boolean> show or hide indicators |
1757 | 64 |
useDefaultIcons <Boolean> use the default icons if no icon |
65 |
for an item is specified |
|
66 |
icons <IdentityDictionary> list of registered icons; |
|
67 |
identifier := <key> value := <icon> |
|
68 |
showLeftIndicators <Boolean> show or hide indicator for most left items |
|
2417
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
69 |
indicatorAction <Block> action evaluated if indicator is pressed (0/1/2 arguments) |
1757 | 70 |
openIndicator <Icon, Image or Form> expanded indicator |
71 |
closeIndicator <Icon, Image or Form> collapsed indicator |
|
1390 | 72 |
|
1757 | 73 |
alignTextRight <Boolean> enable disable of align the text right |
74 |
icon text |
|
75 |
icon text of child |
|
76 |
should be set after creation of the widget!! |
|
77 |
alignTextRightX <Integer> left x position of aligned right text |
|
78 |
maxWidthOfText <Integer> keeps the maximum width of a text label |
|
79 |
||
2210 | 80 |
levelOfLastItem <Integer> keeps the level of the last item; |
81 |
in case of a delete last items from list |
|
82 |
we know were to redraw lines from |
|
2229 | 83 |
|
84 |
autoScrollHorizontal <Boolean> true, than automatically scroll horizontal upto |
|
85 |
the text label of the current selected line. |
|
86 |
||
87 |
expandOnSelect <Boolean> true, than the item selected by a buttonPress |
|
88 |
event will be immediately expanded. |
|
89 |
||
1757 | 90 |
[author:] |
91 |
Claus Atzkern |
|
92 |
||
93 |
[see also:] |
|
94 |
ListModelView |
|
95 |
SelectionInListModelView |
|
1390 | 96 |
HierarchicalList |
97 |
HierarchicalItem |
|
98 |
" |
|
1757 | 99 |
! |
100 |
||
101 |
examples |
|
102 |
" |
|
1916 | 103 |
show a hierarchical list |
1757 | 104 |
[exBegin] |
105 |
|top sel list item| |
|
106 |
||
107 |
list := HierarchicalList new. |
|
108 |
item := HierarchicalItem::Example labeled:'Root Item'. |
|
109 |
||
110 |
item expand. |
|
111 |
list showRoot:false. |
|
112 |
list root:item. |
|
113 |
||
114 |
top := StandardSystemView new; extent:300@300. |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
115 |
sel := ScrollableView for:HierarchicalListView miniScrollerH:true |
1757 | 116 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
117 |
||
118 |
sel list:list. |
|
119 |
sel multipleSelectOk:true. |
|
120 |
||
121 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ]. |
|
122 |
sel indicatorAction:[:i| (list at:i) toggleExpand ]. |
|
123 |
||
124 |
top open. |
|
125 |
[exEnd] |
|
126 |
||
127 |
||
1916 | 128 |
show a hierarchical list; open an editor on reselect a |
129 |
line with label is a string. |
|
130 |
||
131 |
[exBegin] |
|
132 |
|top sel list item| |
|
133 |
||
134 |
list := HierarchicalList new. |
|
135 |
item := HierarchicalItem::Example labeled:'Root Item'. |
|
136 |
||
137 |
item expand. |
|
138 |
list showRoot:false. |
|
139 |
list root:item. |
|
140 |
||
141 |
top := StandardSystemView new; extent:300@300. |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
142 |
sel := ScrollableView for:HierarchicalListView miniScrollerH:true |
1916 | 143 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
144 |
||
145 |
sel list:list. |
|
146 |
||
147 |
sel openEditorAction:[:ln :aGC| |field item| |
|
148 |
item := list at:ln. |
|
149 |
||
150 |
item label isString ifFalse:[ |
|
151 |
field := nil |
|
152 |
] ifTrue:[ |
|
153 |
field := EditField new. |
|
154 |
field level:0. |
|
155 |
field acceptOnLostFocus:true. |
|
156 |
field acceptAction:[:x| item label:(field contents) ]. |
|
157 |
field font:(aGC font). |
|
158 |
field contents:(item label). |
|
159 |
]. |
|
160 |
field |
|
161 |
]. |
|
162 |
||
163 |
sel multipleSelectOk:true. |
|
164 |
||
165 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ]. |
|
166 |
sel indicatorAction:[:i| (list at:i) toggleExpand ]. |
|
167 |
||
168 |
top open. |
|
169 |
[exEnd] |
|
170 |
||
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
171 |
[exBegin] |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
172 |
|top sel list item| |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
173 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
174 |
list := HierarchicalList new. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
175 |
item := HierarchicalItem::Example labeled:'Root Item'. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
176 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
177 |
item expand. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
178 |
list showRoot:false. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
179 |
list root:item. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
180 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
181 |
top := StandardSystemView new; extent:300@300. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
182 |
sel := ScrollableView for:HierarchicalListView miniScrollerH:true |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
183 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
184 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
185 |
sel list:list. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
186 |
sel multipleSelectOk:true. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
187 |
sel alignTextRight:true. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
188 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
189 |
sel indicatorAction:[:i| (list at:i) toggleExpand ]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
190 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
191 |
top open. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
192 |
[exBegin] |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
193 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
194 |
|
1757 | 195 |
" |
2383 | 196 |
! |
197 |
||
198 |
test |
|
199 |
|top sel list item| |
|
200 |
||
201 |
list := HierarchicalList new. |
|
202 |
item := HierarchicalItem::Example labeled:'Root Item'. |
|
203 |
||
204 |
item expand. |
|
205 |
list showRoot:false. |
|
206 |
list root:item. |
|
207 |
||
208 |
top := StandardSystemView new; extent:300@300. |
|
209 |
sel := ScrollableView for:HierarchicalListView miniScrollerH:true |
|
210 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
211 |
||
212 |
sel useDefaultIcons:false. |
|
213 |
sel list:list. |
|
214 |
sel multipleSelectOk:true. |
|
215 |
sel showLines:false. |
|
216 |
||
217 |
sel doubleClickAction:[:i| (list at:i) toggleExpand ]. |
|
218 |
sel indicatorAction:[:i| (list at:i) toggleExpand ]. |
|
219 |
||
220 |
top open. |
|
1390 | 221 |
! ! |
222 |
||
223 |
!HierarchicalListView class methodsFor:'resources'! |
|
224 |
||
225 |
closeIndicator |
|
2335 | 226 |
"This resource specification was automatically generated |
227 |
by the ImageEditor of ST/X." |
|
228 |
||
229 |
"Do not manually edit this!! If it is corrupted, |
|
230 |
the ImageEditor may not be able to read the specification." |
|
1390 | 231 |
|
2335 | 232 |
" |
233 |
self closeIndicator inspect |
|
234 |
ImageEditor openOnClass:self andSelector:#closeIndicator |
|
235 |
Icon flushCachedIcons |
|
236 |
" |
|
1390 | 237 |
|
2335 | 238 |
<resource: #image> |
239 |
||
240 |
^Icon |
|
241 |
constantNamed:#'HierarchicalListView class closeIndicator' |
|
242 |
ifAbsentPut:[(Depth2Image new) width: 9; height: 9; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'UUU@Z*)@Z")@Z")@X@I-Z")@Z")KZ*)@UUU;') ; colorMapFromArray:#[0 0 0 128 128 128 255 255 255]; yourself] |
|
1390 | 243 |
! |
244 |
||
1757 | 245 |
collapsedIcon |
2335 | 246 |
"This resource specification was automatically generated |
247 |
by the ImageEditor of ST/X." |
|
248 |
||
249 |
"Do not manually edit this!! If it is corrupted, |
|
250 |
the ImageEditor may not be able to read the specification." |
|
251 |
||
1757 | 252 |
" |
2335 | 253 |
self collapsedIcon inspect |
254 |
ImageEditor openOnClass:self andSelector:#collapsedIcon |
|
255 |
Icon flushCachedIcons |
|
256 |
" |
|
1390 | 257 |
|
2335 | 258 |
<resource: #image> |
259 |
||
260 |
^Icon |
|
261 |
constantNamed:#'HierarchicalListView class collapsedIcon' |
|
262 |
ifAbsentPut:[(Depth2Image new) width: 16; height: 16; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@@@@@@@@@@UP@@@@@@@@EUUUPAUUUT@UUUU@EUUUPAUUUT@UUUU@@@@@@@@@@@@@@@@@@@@@@@@a') ; colorMapFromArray:#[0 0 0 255 255 0]; mask:((ImageMask new) width: 16; height: 16; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@O@A>@O?<??3??O?<??3??O?<??0@@@@@@@@b') ; yourself); yourself] |
|
1390 | 263 |
! |
264 |
||
265 |
emptyIcon |
|
2335 | 266 |
"This resource specification was automatically generated |
267 |
by the ImageEditor of ST/X." |
|
268 |
||
269 |
"Do not manually edit this!! If it is corrupted, |
|
270 |
the ImageEditor may not be able to read the specification." |
|
271 |
||
1390 | 272 |
" |
2335 | 273 |
self emptyIcon inspect |
274 |
ImageEditor openOnClass:self andSelector:#emptyIcon |
|
275 |
Icon flushCachedIcons |
|
276 |
" |
|
1390 | 277 |
|
2335 | 278 |
<resource: #image> |
279 |
||
280 |
^Icon |
|
281 |
constantNamed:#'HierarchicalListView class emptyIcon' |
|
2336 | 282 |
ifAbsentPut:[(Depth2Image new) width: 16; height: 16; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@@@@EUTP@AUUE@@UUP@@EUUU@AUUUP@UUUT@EUUU@AUUUP@UUUT@@@@@@@@@@@@@@@@@@@@@@@@a') ; colorMapFromArray:#[0 0 0 255 255 255]; mask:((ImageMask new) width: 16; height: 16; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@O?@?>C?<O?8??#?>O?8??#?>O?8?? @@@@@@@@b') ; yourself); yourself] |
1390 | 283 |
! |
284 |
||
285 |
expandedIcon |
|
2335 | 286 |
"This resource specification was automatically generated |
287 |
by the ImageEditor of ST/X." |
|
288 |
||
289 |
"Do not manually edit this!! If it is corrupted, |
|
290 |
the ImageEditor may not be able to read the specification." |
|
291 |
||
1390 | 292 |
" |
2335 | 293 |
self expandedIcon inspect |
294 |
ImageEditor openOnClass:self andSelector:#expandedIcon |
|
295 |
Icon flushCachedIcons |
|
296 |
" |
|
1390 | 297 |
|
2335 | 298 |
<resource: #image> |
299 |
||
300 |
^Icon |
|
301 |
constantNamed:#'HierarchicalListView class expandedIcon' |
|
302 |
ifAbsentPut:[(Depth2Image new) width: 16; height: 16; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@@@@@@@@@@UP@@@UU@@@EUUUPA@@@@@R*** B***(@***(@****@@@@@@@@@@@@@@@@@@@@@@@@a') ; colorMapFromArray:#[0 0 0 179 179 179 255 255 0]; mask:((ImageMask new) width: 16; height: 16; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@O@A>@O?<??3???????;??/?<??0@@@@@@@@b') ; yourself); yourself] |
|
1390 | 303 |
! |
304 |
||
1757 | 305 |
openIndicator |
2335 | 306 |
"This resource specification was automatically generated |
307 |
by the ImageEditor of ST/X." |
|
308 |
||
309 |
"Do not manually edit this!! If it is corrupted, |
|
310 |
the ImageEditor may not be able to read the specification." |
|
1757 | 311 |
|
2335 | 312 |
" |
313 |
self openIndicator inspect |
|
314 |
ImageEditor openOnClass:self andSelector:#openIndicator |
|
315 |
Icon flushCachedIcons |
|
316 |
" |
|
1757 | 317 |
|
2335 | 318 |
<resource: #image> |
319 |
||
320 |
^Icon |
|
321 |
constantNamed:#'HierarchicalListView class openIndicator' |
|
322 |
ifAbsentPut:[(Depth2Image new) width: 9; height: 9; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'UUU@Z*)@Z*)(Z*)HX@I@Z*)@Z*)@Z*)@UUU.') ; colorMapFromArray:#[0 0 0 128 128 128 255 255 255]; yourself] |
|
1390 | 323 |
! ! |
324 |
||
325 |
!HierarchicalListView methodsFor:'accessing'! |
|
326 |
||
1843 | 327 |
font:aFont |
2307 | 328 |
"set a new font; if the font changed, all my items |
329 |
has to clear their cashed width and height |
|
1843 | 330 |
" |
331 |
|root| |
|
332 |
||
333 |
(aFont isNil or:[aFont = font]) ifFalse:[ |
|
2408 | 334 |
root := self root. |
335 |
root notNil ifTrue:[ root fontChanged ]. |
|
1843 | 336 |
super font:aFont |
337 |
]. |
|
338 |
! |
|
339 |
||
1390 | 340 |
list:aList |
341 |
aList notNil ifTrue:[ |
|
342 |
showRoot := aList showRoot |
|
343 |
]. |
|
344 |
super list:aList |
|
2408 | 345 |
! |
346 |
||
347 |
root |
|
348 |
"returns the anchor of the list or nil |
|
349 |
" |
|
350 |
list notNil ifTrue:[ ^ list root ]. |
|
351 |
^ nil |
|
1390 | 352 |
! ! |
353 |
||
2224 | 354 |
!HierarchicalListView methodsFor:'accessing-behavior'! |
355 |
||
356 |
autoScrollHorizontal |
|
357 |
"true, than automatically scroll horizontal upto the text label |
|
358 |
of the current selected line. |
|
359 |
" |
|
360 |
^ autoScrollHorizontal ? false |
|
361 |
! |
|
362 |
||
363 |
autoScrollHorizontal:aBoolean |
|
364 |
"true, than automatically scroll horizontal upto the text label |
|
365 |
of the current selected line. |
|
366 |
" |
|
367 |
autoScrollHorizontal := aBoolean. |
|
368 |
! |
|
369 |
||
370 |
expandOnSelect |
|
371 |
"true, than the item selected by a buttonPress event will |
|
372 |
be immediately expanded. |
|
373 |
" |
|
374 |
^ expandOnSelect |
|
375 |
! |
|
376 |
||
377 |
expandOnSelect:aBoolean |
|
378 |
"true, than the item selected by a buttonPress event will |
|
379 |
be immediately expanded. |
|
380 |
" |
|
381 |
expandOnSelect := aBoolean. |
|
382 |
! ! |
|
383 |
||
1818 | 384 |
!HierarchicalListView methodsFor:'accessing-colors'! |
1390 | 385 |
|
386 |
lineColor |
|
2307 | 387 |
"get the color of the horizontal and vertical lines |
1390 | 388 |
" |
389 |
^ lineColor |
|
390 |
! |
|
391 |
||
392 |
lineColor:aColor |
|
2307 | 393 |
"set the color of the horizontal and vertical lines |
1390 | 394 |
" |
395 |
(aColor notNil and:[aColor ~= lineColor]) ifTrue:[ |
|
396 |
lineColor := aColor. |
|
397 |
||
398 |
shown ifTrue:[ |
|
2099 | 399 |
lineColor := lineColor onDevice:device. |
2307 | 400 |
showLines ifTrue:[ self invalidate ] |
1390 | 401 |
] |
2307 | 402 |
]. |
1390 | 403 |
! ! |
404 |
||
1818 | 405 |
!HierarchicalListView methodsFor:'accessing-look'! |
1390 | 406 |
|
1568 | 407 |
alignTextRight |
408 |
"align the text right |
|
409 |
" |
|
410 |
^ alignTextRight |
|
411 |
! |
|
412 |
||
1757 | 413 |
alignTextRight:aBool |
414 |
"align the text right |
|
415 |
" |
|
416 |
alignTextRight := aBool ? false. |
|
417 |
! |
|
1568 | 418 |
|
1904 | 419 |
alignTextRightX |
420 |
"returns the minimum used text inset, if text is aligned right. |
|
421 |
" |
|
422 |
^ alignTextRightX |
|
423 |
! |
|
424 |
||
425 |
alignTextRightX:aNumber |
|
426 |
"set the minimum used text inset, if text is aligned right. |
|
427 |
" |
|
2383 | 428 |
aNumber > 0 ifTrue:[ |
1904 | 429 |
alignTextRightX := aNumber. |
430 |
||
431 |
(alignTextRight and:[widthOfContents notNil]) ifTrue:[ |
|
432 |
widthOfContents := alignTextRightX + maxWidthOfText. |
|
433 |
||
434 |
shown ifTrue:[ |
|
435 |
self invalidate. |
|
436 |
self contentsChanged. |
|
437 |
] |
|
438 |
] |
|
439 |
]. |
|
440 |
! |
|
441 |
||
2094 | 442 |
iconAt:aKey ifAbsentPut:aBlock |
443 |
"return the icon stored under a key; if not present,the |
|
444 |
result of the block if not nil is stored under the key |
|
445 |
and returned. |
|
446 |
" |
|
447 |
|icon| |
|
448 |
||
449 |
icon := icons at:aKey ifAbsent:nil. |
|
2307 | 450 |
icon notNil ifTrue:[^ icon]. |
2094 | 451 |
|
452 |
icon := aBlock value. |
|
2307 | 453 |
icon isNil ifTrue:[^ nil]. |
2094 | 454 |
|
455 |
realized ifTrue:[ |
|
456 |
icon := self imageOnDevice:icon |
|
457 |
]. |
|
458 |
icons at:aKey put:icon. |
|
459 |
^ icon |
|
460 |
! |
|
461 |
||
1390 | 462 |
registerKeysAndIcons:aDictionary |
463 |
"register icons by key and value derived from a directory |
|
464 |
" |
|
465 |
|image| |
|
466 |
||
467 |
(aDictionary isNil or:[aDictionary isEmpty]) ifTrue:[ |
|
468 |
^ self |
|
469 |
]. |
|
470 |
||
471 |
aDictionary keysAndValuesDo:[:aKey :anImage| |
|
472 |
(image := self imageOnDevice:anImage) notNil ifTrue:[ |
|
473 |
icons at:aKey put:image |
|
1746 | 474 |
] ifFalse:[ |
475 |
icons removeKey:aKey ifAbsent:nil |
|
1390 | 476 |
] |
477 |
] |
|
478 |
||
479 |
! |
|
480 |
||
2392 | 481 |
showIndicators |
482 |
"returns true if indicators are shown |
|
483 |
" |
|
484 |
^ showIndicators |
|
485 |
! |
|
486 |
||
487 |
showIndicators:aBoolean |
|
488 |
"true if indicators are shown |
|
489 |
" |
|
490 |
showIndicators ~~ aBoolean ifTrue:[ |
|
491 |
showIndicators := aBoolean. |
|
492 |
shown ifTrue:[ self invalidate ]. |
|
493 |
]. |
|
494 |
! |
|
495 |
||
1390 | 496 |
showLeftIndicators |
497 |
"show or hide the indicators for the most left items |
|
498 |
" |
|
499 |
^ showLeftIndicators |
|
500 |
||
501 |
! |
|
502 |
||
2307 | 503 |
showLeftIndicators:aBoolean |
1390 | 504 |
"show or hide the indicators for the most left items |
505 |
" |
|
2392 | 506 |
|oldInset newInset| |
507 |
||
508 |
aBoolean == showLeftIndicators ifTrue:[ ^ self ]. |
|
509 |
||
2408 | 510 |
(widthOfContents isNil or:[self size == 0]) ifTrue:[ |
2307 | 511 |
showLeftIndicators := aBoolean. |
2392 | 512 |
^ self |
513 |
]. |
|
2383 | 514 |
|
2392 | 515 |
oldInset := self xVisibleOfIconAtLevel:3. |
516 |
showLeftIndicators := aBoolean. |
|
517 |
newInset := self xVisibleOfIconAtLevel:3. |
|
518 |
||
519 |
newInset ~~ oldInset ifTrue:[ |
|
520 |
widthOfContents := widthOfContents + (newInset - oldInset). |
|
521 |
]. |
|
522 |
||
523 |
shown ifTrue:[ |
|
524 |
self invalidate |
|
525 |
]. |
|
526 |
||
527 |
newInset ~~ oldInset ifTrue:[ |
|
528 |
self contentsChanged |
|
1390 | 529 |
]. |
530 |
! |
|
531 |
||
532 |
showLines |
|
533 |
"returns true if lines are shown |
|
534 |
" |
|
2307 | 535 |
^ showLines |
1390 | 536 |
! |
537 |
||
2307 | 538 |
showLines:aBoolean |
1390 | 539 |
"show or hide lines |
540 |
" |
|
2307 | 541 |
aBoolean ~~ showLines ifTrue:[ |
542 |
showLines := aBoolean. |
|
543 |
shown ifTrue:[ self invalidate ]. |
|
1390 | 544 |
]. |
545 |
! |
|
546 |
||
547 |
useDefaultIcons |
|
548 |
"use the default icons if no icon for an item is specified; |
|
549 |
** default: true |
|
550 |
" |
|
551 |
^ useDefaultIcons |
|
552 |
! |
|
553 |
||
2307 | 554 |
useDefaultIcons:aBoolean |
1390 | 555 |
"use the default icons if no icon for an item is specified; |
556 |
** default: true |
|
557 |
" |
|
2307 | 558 |
useDefaultIcons ~~ aBoolean ifTrue:[ |
559 |
useDefaultIcons := aBoolean. |
|
560 |
shown ifTrue:[ self invalidate ]. |
|
1390 | 561 |
] |
562 |
! ! |
|
563 |
||
564 |
!HierarchicalListView methodsFor:'actions'! |
|
565 |
||
566 |
indicatorAction |
|
2392 | 567 |
"the action evaluated if an indicator is pressed; otherwise |
568 |
if indicators are shown a default action is performed (toggle expand item). |
|
2417
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
569 |
|
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
570 |
The arguments to the block are: |
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
571 |
- no argument |
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
572 |
- 1 argument index |
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
573 |
- 2 argument index, self |
1390 | 574 |
" |
575 |
^ indicatorAction |
|
576 |
! |
|
577 |
||
578 |
indicatorAction:anAction |
|
2392 | 579 |
"the action evaluated if an indicator is pressed; otherwise |
580 |
if indicators are shown a default action is performed (toggle expand item). |
|
2417
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
581 |
|
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
582 |
The arguments to the block are: |
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
583 |
- no argument |
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
584 |
- 1 argument index |
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
585 |
- 2 argument index, self |
1390 | 586 |
" |
587 |
indicatorAction := anAction. |
|
588 |
! ! |
|
589 |
||
590 |
!HierarchicalListView methodsFor:'change & update'! |
|
591 |
||
1782 | 592 |
indicatorPressedAt:aLnNr |
2224 | 593 |
"handle indicator pressed action; |
594 |
if the item changed expanded, we try to show all |
|
595 |
new visible children |
|
596 |
" |
|
597 |
|item expanded availY usedY vwOrgX vwOrgY idx| |
|
598 |
||
2392 | 599 |
showIndicators ifFalse:[^ self]. |
2224 | 600 |
|
2408 | 601 |
item := self at:aLnNr ifAbsent:nil. |
2307 | 602 |
item isNil ifTrue:[^ self]. |
2224 | 603 |
|
604 |
item hasIndicator ifFalse:[^ self]. |
|
605 |
||
606 |
expanded := item isExpanded. |
|
2392 | 607 |
|
608 |
indicatorAction notNil ifTrue:[ |
|
2417
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
609 |
indicatorAction valueWithOptionalArgument:aLnNr and:self. |
2392 | 610 |
] ifFalse:[ |
611 |
item toggleExpand |
|
612 |
]. |
|
613 |
||
2224 | 614 |
(expanded or:[item isExpanded not]) ifTrue:[^ self]. |
1783
ffe767ea66ea
check whether children exists before calling indicatorPressed action
ca
parents:
1782
diff
changeset
|
615 |
|
2224 | 616 |
"/ compute the index of last child assigned to item |
617 |
||
618 |
idx := item numberOfVisibleChildren. "/ no visible children |
|
619 |
idx == 0 ifTrue:[^ self]. |
|
620 |
||
621 |
idx := aLnNr + idx. |
|
622 |
vwOrgY := viewOrigin y. |
|
2414 | 623 |
availY := (self yVisibleOfLine:aLnNr) - (self yVisibleOfLine:1). |
2224 | 624 |
|
625 |
availY > margin ifTrue:[ |
|
626 |
usedY := (self yVisibleOfLine:(idx + 1)) - (height - margin - margin). |
|
627 |
||
628 |
usedY > 1 ifTrue:[ |
|
629 |
vwOrgY := vwOrgY + (usedY min:availY). |
|
630 |
]. |
|
631 |
]. |
|
632 |
vwOrgX := self computeViewOriginXat:aLnNr. |
|
633 |
||
634 |
self scrollTo:(vwOrgX @ vwOrgY). |
|
1782 | 635 |
! |
636 |
||
1390 | 637 |
lineChangedAt:aLnNr with:arg |
638 |
"line changed at position; check whether line height changed |
|
639 |
" |
|
640 |
|item |
|
2317 | 641 |
level "{ Class:SmallInteger }" |
1390 | 642 |
x0 "{ Class:SmallInteger }" |
643 |
x1 "{ Class:SmallInteger }" |
|
644 |
y0 "{ Class:SmallInteger }" |
|
645 |
y1 "{ Class:SmallInteger }" |
|
2303 | 646 |
yB "{ Class:SmallInteger }" |
1390 | 647 |
| |
648 |
||
2408 | 649 |
item := self at:aLnNr ifAbsent:nil. |
2317 | 650 |
item isNil ifTrue:[^ self]. |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
651 |
|
1399 | 652 |
(arg == #icon or:[arg == #hierarchy]) ifFalse:[ |
2224 | 653 |
super lineChangedAt:aLnNr with:arg. |
654 |
||
655 |
(arg ~~ #redraw and:[widthOfContents notNil]) ifTrue:[ |
|
2327 | 656 |
x0 := (self xVisibleOfTextAtLevel:(item level)) |
2353 | 657 |
+ (renderer widthFor:item) |
2229 | 658 |
+ (viewOrigin x). |
2224 | 659 |
|
660 |
x0 > widthOfContents ifTrue:[ |
|
661 |
widthOfContents := x0. |
|
662 |
self contentsChanged. |
|
663 |
] |
|
664 |
]. |
|
665 |
^ self |
|
1390 | 666 |
]. |
2317 | 667 |
level := item level. |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
668 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
669 |
(alignTextRight and:[arg == #hierarchy]) ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
670 |
"/ must test whether alignTextRightX is enough |
2317 | 671 |
(item isExpanded and:[item hasChildren]) ifTrue:[ |
2327 | 672 |
x0 := self xVisibleOfIconAtLevel:(level + 2). |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
673 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
674 |
alignTextRightX < x0 ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
675 |
alignTextRightX := x0. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
676 |
shown ifTrue:[ self invalidate ]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
677 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
678 |
widthOfContents notNil ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
679 |
widthOfContents := alignTextRightX + maxWidthOfText. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
680 |
self contentsChanged. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
681 |
]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
682 |
^ self. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
683 |
] |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
684 |
] |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
685 |
]. |
1568 | 686 |
shown ifFalse:[^ self]. |
687 |
||
2303 | 688 |
yB := height - margin. |
689 |
y0 := (self yVisibleOfLine:aLnNr) max:margin. |
|
690 |
y0 < yB ifFalse:[ ^ self ]. |
|
1390 | 691 |
|
2303 | 692 |
y1 := (self yVisibleOfLine:(aLnNr + 1)) min:yB. |
693 |
y1 > y0 ifFalse:[^ self]. |
|
1399 | 694 |
|
2327 | 695 |
x1 := (self xVisibleOfTextAtLevel:level) - 1. |
2317 | 696 |
x1 > margin ifFalse:[^ self]. |
1390 | 697 |
|
2383 | 698 |
x0 := (self xVisibleOfIndicatorAtLevel:level) max:margin. |
2317 | 699 |
x1 := x1 min:(width - margin). |
2303 | 700 |
|
2317 | 701 |
x0 < x1 ifTrue:[ |
702 |
self invalidate:(Rectangle left:x0 top:y0 width:(x1 - x0) height:(y1 - y0)) |
|
703 |
repairNow:false. |
|
2303 | 704 |
]. |
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
705 |
! |
1390 | 706 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
707 |
listChangedInsert:firstAddedIndex nItems:nLines |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
708 |
"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
|
709 |
" |
2210 | 710 |
|item level yTop yBot xLft start maxY| |
1390 | 711 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
712 |
super listChangedInsert:firstAddedIndex nItems:nLines. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
713 |
|
2408 | 714 |
item := self last. |
2210 | 715 |
levelOfLastItem := item level. |
716 |
||
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
717 |
( shown |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
718 |
and:[showLines |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
719 |
and:[firstAddedIndex > 1 |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
720 |
and:[nLines ~~ 0 |
2408 | 721 |
and:[(item := self at:firstAddedIndex ifAbsent:nil) notNil |
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
722 |
and:[(level := item level) > 1]]]]] |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
723 |
) ifFalse:[ |
2383 | 724 |
^ self. |
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
725 |
]. |
2383 | 726 |
xLft := self xVisibleOfVerticalLineAt:level. |
1390 | 727 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
728 |
(xLft > margin and:[xLft < (width - margin)]) ifFalse:[ |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
729 |
^ self |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
730 |
]. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
731 |
start := firstAddedIndex - 1. |
1390 | 732 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
733 |
start to:1 by:-1 do:[:i| |el| |
2408 | 734 |
el := self at:i. |
1399 | 735 |
|
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
736 |
el level <= level ifTrue:[ |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
737 |
i == start ifTrue:[^ self]. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
738 |
|
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
739 |
yTop := (self yVisibleOfLine:i + 1) max:margin. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
740 |
maxY := height - margin. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
741 |
|
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
742 |
yTop < maxY ifTrue:[ |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
743 |
yBot := (self yVisibleOfLine:firstAddedIndex) - 1 min:maxY. |
2383 | 744 |
self invalidate:(Rectangle left:xLft top:yTop width:2 height:(yBot - yTop)) |
1976
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
745 |
]. |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
746 |
^ self |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
747 |
] |
1788b0045176
bug fix when adding new elements; must draw vertical lines above
ca
parents:
1916
diff
changeset
|
748 |
]. |
1390 | 749 |
! |
750 |
||
2208 | 751 |
listChangedRemove:aStart toIndex:aStop |
752 |
"test whether last items are deleted; |
|
753 |
than we have to redraw lines because of different levels |
|
754 |
" |
|
2210 | 755 |
|listSize index y0 searchLevel| |
2208 | 756 |
|
2408 | 757 |
listSize := self size. |
2210 | 758 |
searchLevel := levelOfLastItem. |
2208 | 759 |
|
2307 | 760 |
listSize == 0 ifTrue:[ levelOfLastItem := 1 ] |
2408 | 761 |
ifFalse:[ levelOfLastItem := self last level ]. |
2208 | 762 |
|
2307 | 763 |
(shown and:[showLines and:[listSize ~~ 0 and:[aStart > listSize]]]) ifTrue:[ |
2408 | 764 |
index := self findLast:[:el| el level <= searchLevel ]. |
2208 | 765 |
|
766 |
(index ~~ 0 and:[index < listSize]) ifTrue:[ |
|
767 |
y0 := (self yVisibleOfLine:index) max:margin. |
|
768 |
self invalidateX:0 y:y0 width:width height:(height - margin - y0). |
|
769 |
] |
|
770 |
]. |
|
771 |
^ super listChangedRemove:aStart toIndex:aStop |
|
772 |
! |
|
773 |
||
1390 | 774 |
update:what with:aPara from:chgObj |
775 |
"get the status of <showRoot> from the list |
|
776 |
" |
|
777 |
chgObj == list ifTrue:[ |
|
2408 | 778 |
showRoot ~~ chgObj showRoot ifTrue:[ |
779 |
showRoot := chgObj showRoot. |
|
1390 | 780 |
self invalidate. |
781 |
] |
|
782 |
]. |
|
783 |
super update:what with:aPara from:chgObj |
|
784 |
! ! |
|
785 |
||
786 |
!HierarchicalListView methodsFor:'drawing basics'! |
|
787 |
||
1568 | 788 |
drawElementsFrom:start to:stop x:xLeft y:yT w:w |
1390 | 789 |
"draw the items between start to stop without clearing the background |
790 |
" |
|
2383 | 791 |
|item prevParent icon showIndc showIcon showText |
1568 | 792 |
yTop "{ Class:SmallInteger }" |
793 |
yCtr "{ Class:SmallInteger }" |
|
794 |
yBot "{ Class:SmallInteger }" |
|
2383 | 795 |
level "{ Class:SmallInteger }" |
1390 | 796 |
|
1568 | 797 |
xIndc "{ Class:SmallInteger }" |
798 |
xIcon "{ Class:SmallInteger }" |
|
799 |
xText "{ Class:SmallInteger }" |
|
800 |
xL "{ Class:SmallInteger }" |
|
801 |
xR "{ Class:SmallInteger }" |
|
802 |
height "{ Class:SmallInteger }" |
|
1390 | 803 |
|
1568 | 804 |
offIndcY "{ Class:SmallInteger }" |
1390 | 805 |
| |
2383 | 806 |
xL := xLeft. |
807 |
xR := xL + w. |
|
1390 | 808 |
|
2392 | 809 |
showIndicators ifTrue:[ |
2383 | 810 |
offIndcY := openIndicator width // 2. |
1390 | 811 |
]. |
812 |
||
813 |
showLines ifTrue:[ |
|
1399 | 814 |
self drawLinesFrom:start to:stop x:xL y:yT toX:xR |
1390 | 815 |
]. |
2383 | 816 |
prevParent := #NIL. "/ to force a recompute |
817 |
yBot := yT. |
|
818 |
showIndc := false. |
|
1390 | 819 |
|
820 |
start to:stop do:[:anIndex| |
|
2408 | 821 |
(item := self at:anIndex ifAbsent:nil) isNil ifTrue:[ |
1390 | 822 |
^ self "/ list changed |
823 |
]. |
|
2383 | 824 |
yTop := yBot. |
825 |
yBot := self yVisibleOfLine:(anIndex + 1). |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
826 |
height := yBot - yTop. |
2383 | 827 |
yCtr := yTop + (height // 2). |
1390 | 828 |
|
2383 | 829 |
item parent ~~ prevParent ifTrue:[ |
830 |
prevParent := item parent. |
|
831 |
level := item level. |
|
832 |
xIcon := self xVisibleOfIconAtLevel:level. |
|
833 |
xText := self xVisibleOfTextAtLevel:level. |
|
834 |
showText := (xText < xR). |
|
835 |
showIcon := (xIcon < xR and:[xText > xL]). |
|
1390 | 836 |
|
2392 | 837 |
showIndicators ifTrue:[ |
2383 | 838 |
xIndc := self xVisibleOfIndicatorAtLevel:level. |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
839 |
showIndc := (xIcon > xL and:[xIndc < xR]). |
1390 | 840 |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
841 |
showIndc ifTrue:[ |
2383 | 842 |
showIndc := prevParent notNil or:[showLeftIndicators] |
1756 | 843 |
] |
1390 | 844 |
] |
845 |
]. |
|
846 |
||
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
847 |
(showIcon and:[(icon := self validateDrawableIconFor:item) notNil]) ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
848 |
(xIcon + icon width) > xL ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
849 |
icon displayOn:self x:xIcon y:(yCtr - (icon height // 2)) |
1568 | 850 |
] |
1390 | 851 |
]. |
852 |
||
853 |
showText ifTrue:[ |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
854 |
self drawLabelAt:anIndex x:xText y:yTop h:height |
1390 | 855 |
]. |
2201
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2181
diff
changeset
|
856 |
(showIndc and:[item hasIndicator]) ifTrue:[ |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
857 |
item isExpanded ifTrue:[icon := openIndicator ] |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
858 |
ifFalse:[icon := closeIndicator]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
859 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
860 |
icon displayOn:self x:xIndc y:(yCtr - offIndcY) |
1390 | 861 |
]. |
2383 | 862 |
]. |
1390 | 863 |
! |
864 |
||
1399 | 865 |
drawLinesFrom:start to:stop x:xL y:yT toX:xR |
1390 | 866 |
"draw the lines between start to stop without clearing the background |
867 |
" |
|
2383 | 868 |
|item prevItem parent p1 p2 showVLines showHLine lv buildInArray showLeftIdc |
1390 | 869 |
|
870 |
x "{ Class:SmallInteger }" |
|
1570 | 871 |
xText "{ Class:SmallInteger }" |
872 |
||
1390 | 873 |
y "{ Class:SmallInteger }" |
874 |
yTop "{ Class:SmallInteger }" |
|
875 |
yBot "{ Class:SmallInteger }" |
|
876 |
yCtr "{ Class:SmallInteger }" |
|
877 |
||
878 |
begHLnY "{ Class:SmallInteger }" |
|
879 |
runHLnY "{ Class:SmallInteger }" |
|
2383 | 880 |
lftVrtX "{ Class:SmallInteger }" |
881 |
rgtVrtX "{ Class:SmallInteger }" |
|
882 |
level "{ Class:SmallInteger }" |
|
1390 | 883 |
|
2383 | 884 |
minVertLevel "{ Class:SmallInteger }" |
885 |
minHorzLevel "{ Class:SmallInteger }" |
|
886 |
smallestLevel "{ Class:SmallInteger }" |
|
1390 | 887 |
| |
2383 | 888 |
parent := prevItem := 4711. "/ to force a recompute |
1390 | 889 |
|
890 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
891 |
self paint:lineColor on:bgColor. |
|
892 |
self mask:lineMask. |
|
2383 | 893 |
|
894 |
smallestLevel := self smallestLevelBetween:start and:stop. |
|
2392 | 895 |
minVertLevel := 2. |
896 |
||
897 |
showLeftIndicators ifTrue:[ |
|
898 |
showLeftIdc := showIndicators. |
|
899 |
showRoot ifFalse:[ minVertLevel := 3 ] |
|
900 |
] ifFalse:[ |
|
901 |
showLeftIdc := false. |
|
902 |
]. |
|
2383 | 903 |
|
904 |
showRoot ifFalse:[ minHorzLevel := 2 ] |
|
905 |
ifTrue:[ minHorzLevel := 1 ]. |
|
1390 | 906 |
|
2392 | 907 |
showLeftIdc ifFalse:[ |
908 |
minHorzLevel := minHorzLevel + 1. |
|
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
909 |
]. |
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
910 |
|
2383 | 911 |
yBot := begHLnY := runHLnY := yT. |
912 |
level := 1. |
|
1570 | 913 |
|
1390 | 914 |
start to:stop do:[:anIndex| |
2408 | 915 |
(item := self at:anIndex ifAbsent:nil) isNil ifTrue:[ |
1390 | 916 |
^ self mask:nil "/ list changed |
917 |
]. |
|
918 |
yTop := yBot. |
|
919 |
yBot := self yVisibleOfLine:(anIndex + 1). |
|
920 |
yCtr := yTop + (yBot - yTop // 2). |
|
921 |
||
2383 | 922 |
item parent ~~ parent ifTrue:[ |
923 |
anIndex == 1 ifTrue:[ begHLnY := runHLnY := yCtr ]. |
|
924 |
parent := item parent. |
|
1390 | 925 |
|
926 |
prevItem == parent ifTrue:[ |
|
1567 | 927 |
level := level + 1. |
2383 | 928 |
lftVrtX := rgtVrtX. |
1390 | 929 |
] ifFalse:[ |
930 |
level := item level. |
|
2383 | 931 |
lftVrtX := self xVisibleOfVerticalLineAt:level. |
1390 | 932 |
]. |
2383 | 933 |
showVLines := (level >= minVertLevel and:[lftVrtX >= xL]). |
934 |
rgtVrtX := self xVisibleOfVerticalLineAt:level + 1. |
|
1570 | 935 |
|
2383 | 936 |
level >= minHorzLevel ifTrue:[ |
937 |
xText := (self xVisibleOfTextAtLevel:level) - textStartLeft. |
|
938 |
showHLine := (xL < xText and:[xR > lftVrtX]). |
|
939 |
] ifFalse:[ |
|
940 |
showHLine := false |
|
1570 | 941 |
]. |
1390 | 942 |
]. |
943 |
||
944 |
showHLine ifTrue:[ |
|
2383 | 945 |
( level ~~ 2 |
946 |
or:[showRoot or:[(showLeftIdc and:[item hasIndicator])]] |
|
947 |
) ifTrue:[ |
|
948 |
item drawHorizontalLineUpToText ifTrue:[ x := xText ] |
|
949 |
ifFalse:[ x := rgtVrtX ]. |
|
950 |
||
951 |
self displayLineFromX:lftVrtX y:yCtr toX:x y:yCtr. |
|
1570 | 952 |
]. |
2383 | 953 |
]. |
954 |
||
955 |
anIndex == start ifTrue:[ |
|
956 |
(item isExpanded and:[item hasChildren]) ifTrue:[ |
|
957 |
self displayLineFromX:rgtVrtX y:yCtr toX:rgtVrtX y:yBot. |
|
1570 | 958 |
] |
1390 | 959 |
]. |
960 |
||
961 |
showVLines ifTrue:[ |
|
2383 | 962 |
parent last == item ifTrue:[ y := yCtr ] |
963 |
ifFalse:[ y := yBot ]. |
|
964 |
x := lftVrtX. |
|
1390 | 965 |
p2 := parent. |
966 |
lv := level - 1. |
|
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
967 |
|
2383 | 968 |
level >= smallestLevel ifTrue:[ |
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
969 |
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
|
970 |
]. |
1390 | 971 |
|
2383 | 972 |
[ (p2 notNil and:[lv >= minVertLevel]) ] whileTrue:[ |
973 |
p1 := p2 parent. |
|
974 |
||
975 |
p1 notNil ifTrue:[ |
|
976 |
x := self xVisibleOfVerticalLineAt:lv. |
|
977 |
||
978 |
x < xL ifTrue:[ |
|
979 |
p1 := nil. |
|
1390 | 980 |
] ifFalse:[ |
2383 | 981 |
p1 last ~~ p2 ifTrue:[ |
982 |
lv >= smallestLevel ifTrue:[ |
|
983 |
self displayLineFromX:x y:(yTop - 1) toX:x y:yBot |
|
984 |
] ifFalse:[ |
|
985 |
buildInArray isNil ifTrue:[buildInArray := Array new:smallestLevel]. |
|
986 |
buildInArray at:lv put:yBot |
|
987 |
] |
|
988 |
]. |
|
1390 | 989 |
]. |
990 |
]. |
|
2383 | 991 |
p2 := p1. |
1390 | 992 |
lv := lv - 1. |
2383 | 993 |
]. |
1390 | 994 |
]. |
995 |
prevItem := item. |
|
996 |
runHLnY := yCtr. |
|
997 |
]. |
|
998 |
||
1567 | 999 |
buildInArray notNil ifTrue:[ |
1000 |
y := begHLnY. |
|
1390 | 1001 |
|
2383 | 1002 |
2 to:smallestLevel do:[:i| |u yB| |
1003 |
(yB := buildInArray at:i) notNil ifTrue:[ |
|
1004 |
x := self xVisibleOfVerticalLineAt:i. |
|
1596 | 1005 |
|
2383 | 1006 |
x >= xL ifTrue:[ |
1897
5609f92e6d4a
do not draw the first vertical line if the rootItem is not visible
ca
parents:
1843
diff
changeset
|
1007 |
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
|
1008 |
] |
1567 | 1009 |
]. |
1390 | 1010 |
] |
1011 |
]. |
|
1012 |
self mask:nil. |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1013 |
! |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1014 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1015 |
validateDrawableIconFor:anItem |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1016 |
"returns the icon to be drawn for an item or nil |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1017 |
test the extent of the icopn; on error an exception is raised |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1018 |
" |
2383 | 1019 |
|width needMore icon maxLevel startOfText oldX newX| |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1020 |
|
2327 | 1021 |
icon := self iconFor:anItem. |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1022 |
icon isNil ifTrue:[^ nil]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1023 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1024 |
width := icon width. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1025 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1026 |
(constantHeight notNil and:[icon height > constantHeight]) ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1027 |
constantHeight := icon height + lineSpacing. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1028 |
self recomputeHeightOfContents. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1029 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1030 |
width <= imageWidth ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1031 |
self contentsChanged. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1032 |
StopRedrawSignal raise |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1033 |
]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1034 |
] ifFalse:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1035 |
width <= imageWidth ifTrue:[ ^ icon ]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1036 |
]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1037 |
|
2383 | 1038 |
maxLevel := 1. |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1039 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1040 |
list criticalDo:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1041 |
list do:[:el| maxLevel := maxLevel max:(el level) ]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1042 |
]. |
2383 | 1043 |
|
1044 |
needMore := (width - imageWidth) max:2. |
|
1045 |
oldX := self xVisibleOfIconAtLevel:(maxLevel + 1). |
|
1046 |
imageWidth := imageWidth + needMore. |
|
1047 |
newX := self xVisibleOfIconAtLevel:(maxLevel + 1). |
|
1048 |
alignTextRightX := alignTextRightX max:newX. |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1049 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1050 |
widthOfContents notNil ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1051 |
alignTextRight ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1052 |
widthOfContents := alignTextRightX + maxWidthOfText |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1053 |
] ifFalse:[ |
2383 | 1054 |
widthOfContents := widthOfContents + (newX - oldX) |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1055 |
]. |
2353 | 1056 |
width := renderer widthFor:anItem. |
2327 | 1057 |
startOfText := self xVisibleOfTextAtLevel:(anItem level). |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1058 |
widthOfContents := widthOfContents max:(startOfText + width). |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1059 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1060 |
width > maxWidthOfText ifTrue:[ |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1061 |
maxWidthOfText := width |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1062 |
]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1063 |
]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1064 |
self contentsChanged. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1065 |
StopRedrawSignal raise. |
2353 | 1066 |
^ icon |
1390 | 1067 |
! ! |
1068 |
||
1069 |
!HierarchicalListView methodsFor:'event handling'! |
|
1070 |
||
1757 | 1071 |
buttonPress:button x:x y:y |
1072 |
"handle a button press event |
|
1073 |
" |
|
2313 | 1074 |
|line item x0 y0| |
2224 | 1075 |
|
1076 |
enabled ifFalse:[^ self]. |
|
2361 | 1077 |
self closeEditor. |
2224 | 1078 |
|
2313 | 1079 |
line := self yVisibleToLineNr:y. |
1080 |
line notNil ifTrue:[ |
|
2408 | 1081 |
item := self at:line ifAbsent:nil. |
2313 | 1082 |
item notNil ifTrue:[ |
2327 | 1083 |
x0 := self xVisibleOfTextAtLevel:(item level). |
2313 | 1084 |
|
1085 |
x >= x0 ifTrue:[ |
|
1086 |
y0 := self yVisibleOfLine:line. |
|
2224 | 1087 |
|
2313 | 1088 |
(item processButtonPress:button x:(x - x0) y:(y - y0)) == true ifTrue:[ |
1089 |
^ self |
|
1090 |
]. |
|
1091 |
]. |
|
1092 |
] |
|
1093 |
] ifFalse:[ |
|
1094 |
item := nil |
|
1095 |
]. |
|
1096 |
||
2392 | 1097 |
showIndicators ifTrue:[ |
1098 |
(button == 1 or:[button == #select]) ifTrue:[ |
|
1099 |
(item notNil and:[item hasIndicator]) ifTrue:[ |
|
1100 |
x0 := self xVisibleOfIndicatorAtLevel:(item level). |
|
2313 | 1101 |
|
2392 | 1102 |
(x between:x0 and:(x0 + openIndicator width)) ifTrue:[ |
1103 |
self indicatorPressedAt:line. |
|
1104 |
^ self |
|
1105 |
]. |
|
2313 | 1106 |
]. |
2224 | 1107 |
]. |
1108 |
]. |
|
2313 | 1109 |
|
2224 | 1110 |
super buttonPress:button x:x y:y. |
1111 |
! |
|
1390 | 1112 |
|
2224 | 1113 |
buttonPressOrReleaseAtLine:aLnNr x:x y:y |
1114 |
"handle a button press or release at a line |
|
1115 |
" |
|
1116 |
|oldIdx newIdx newItem| |
|
1117 |
||
1118 |
oldIdx := self selectedIndex. |
|
1119 |
super buttonPressOrReleaseAtLine:aLnNr x:x y:y. |
|
1120 |
newIdx := self selectedIndex. |
|
1121 |
||
1122 |
(newIdx ~~ oldIdx and:[newIdx ~~ 0]) ifTrue:[ |
|
1123 |
expandOnSelect ifTrue:[ |
|
2408 | 1124 |
newItem := self at:newIdx ifAbsent:nil. |
2307 | 1125 |
newItem isNil ifTrue:[^ self]. |
2224 | 1126 |
newItem expand |
1390 | 1127 |
]. |
2224 | 1128 |
self makeLineVisible:newIdx. |
1129 |
]. |
|
1757 | 1130 |
! |
1131 |
||
1132 |
keyPress:aKey x:x y:y |
|
1133 |
"a key was pressed - handle page-keys here |
|
1134 |
" |
|
1784 | 1135 |
<resource: #keyboard( #CursorLeft #CursorRight )> |
1757 | 1136 |
|
2377 | 1137 |
|item lineNr isCursorLeft| |
1757 | 1138 |
|
1782 | 1139 |
enabled ifFalse:[^ self]. |
2377 | 1140 |
|
1141 |
( aKey == Character space |
|
1142 |
or:[aKey == #CursorRight |
|
1143 |
or:[aKey == #CursorLeft]] |
|
1144 |
) ifFalse:[ |
|
1145 |
super keyPress:aKey x:x y:y. |
|
1146 |
^ self |
|
1147 |
]. |
|
1148 |
||
1149 |
lineNr := self cursorLine. |
|
1150 |
||
1151 |
lineNr ~~ 0 ifTrue:[ |
|
1152 |
item := cursorItem |
|
1153 |
] ifFalse:[ |
|
1154 |
lineNr := self selectedIndex. |
|
1155 |
lineNr == 0 ifTrue:[^ self]. |
|
1156 |
||
2408 | 1157 |
item := self at:lineNr ifAbsent:nil. |
2377 | 1158 |
item isNil ifTrue:[^ self]. |
1159 |
]. |
|
1782 | 1160 |
|
1161 |
aKey == Character space ifTrue:[ |
|
2378 | 1162 |
item toggleExpand. |
2377 | 1163 |
^ self |
1164 |
]. |
|
1165 |
isCursorLeft := aKey == #CursorLeft. |
|
1166 |
||
1167 |
item isExpanded == isCursorLeft ifTrue:[ |
|
2378 | 1168 |
item toggleExpand. |
2377 | 1169 |
^ self |
1782 | 1170 |
]. |
2377 | 1171 |
isCursorLeft ifTrue:[ |
1172 |
(item := item parent) isNil ifTrue:[^ self]. |
|
2408 | 1173 |
lineNr := self identityIndexOf:item. |
2377 | 1174 |
] ifFalse:[ |
1175 |
item hasChildren ifFalse:[^ self]. |
|
1176 |
lineNr := lineNr + 1. |
|
2179 | 1177 |
]. |
2377 | 1178 |
|
2408 | 1179 |
item := self at:lineNr ifAbsent:nil. |
2377 | 1180 |
item isNil ifTrue:[^ self]. |
1181 |
||
1182 |
(self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
|
1183 |
self selection:lineNr |
|
1184 |
]. |
|
1390 | 1185 |
! ! |
1186 |
||
1757 | 1187 |
!HierarchicalListView methodsFor:'fetch resources'! |
1188 |
||
1189 |
fetchResources |
|
1190 |
"fetch device colors and ..., to avoid reallocation at redraw time; |
|
1191 |
*** called after a create or snapin to fetch all device resources |
|
1192 |
" |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1193 |
|image defaultWidth| |
1757 | 1194 |
|
1195 |
super fetchResources. |
|
1196 |
||
1197 |
lineColor := lineColor onDevice:device. |
|
1198 |
openIndicator := self imageOnDevice:openIndicator. |
|
1199 |
closeIndicator := self imageOnDevice:closeIndicator. |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1200 |
defaultWidth := imageWidth. |
1757 | 1201 |
|
1202 |
icons keysAndValuesDo:[:aKey :anImage| |
|
1203 |
anImage isNil ifTrue:[ |
|
1204 |
('HierachicalListView [warning]: missing image: ' , aKey) errorPrintCR. |
|
1205 |
] ifFalse:[ |
|
1206 |
image := self imageOnDevice:anImage. |
|
1207 |
icons at:aKey put:image. |
|
1208 |
imageWidth := image width max:imageWidth. |
|
1209 |
] |
|
1210 |
]. |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1211 |
imageWidth := (imageWidth + 1 // 2 * 2) max:defaultWidth. |
1904 | 1212 |
alignTextRightX := imageWidth + 20 max:alignTextRightX. |
1757 | 1213 |
! ! |
1214 |
||
1390 | 1215 |
!HierarchicalListView methodsFor:'initialize / release'! |
1216 |
||
1217 |
initStyle |
|
1218 |
"setup viewStyle specifics |
|
1219 |
" |
|
1220 |
|cls| |
|
1221 |
||
1222 |
super initStyle. |
|
1223 |
||
2377 | 1224 |
cls := self class. |
1225 |
icons := Dictionary new. |
|
1390 | 1226 |
|
1227 |
openIndicator := self class openIndicator. |
|
1228 |
closeIndicator := self class closeIndicator. |
|
2312 | 1229 |
minLineHeight := (openIndicator height) max:(closeIndicator height). |
1230 |
||
1390 | 1231 |
lineColor := fgColor. |
1232 |
highlightMode := #label. |
|
1233 |
showRoot := true. |
|
1234 |
showLeftIndicators := true. |
|
1235 |
useDefaultIcons := true. |
|
1236 |
showLines := true. |
|
1237 |
imageInset := 4. |
|
2383 | 1238 |
imageWidth := 0. |
1568 | 1239 |
alignTextRight := false. |
1240 |
alignTextRightX := 8. |
|
1241 |
maxWidthOfText := 0. |
|
2224 | 1242 |
|
2325 | 1243 |
|
2328 | 1244 |
highlightEnterItem := styleSheet at:#'selection.highlightEnterItem' default:false. |
2310 | 1245 |
expandOnSelect := styleSheet at:#'selection.expandOnSelect' default:false. |
2224 | 1246 |
autoScrollHorizontal := true. |
2210 | 1247 |
! |
1248 |
||
1249 |
initialize |
|
1250 |
super initialize. |
|
1251 |
levelOfLastItem := 1. |
|
2392 | 1252 |
|
1253 |
self showIndicators:true. |
|
1390 | 1254 |
! ! |
1255 |
||
1256 |
!HierarchicalListView methodsFor:'private'! |
|
1257 |
||
2327 | 1258 |
iconFor:anItem |
1259 |
"returns an icon or image for the item or nil if the item |
|
1260 |
provides no image and #useDefaultIcons is switched off. |
|
1390 | 1261 |
" |
2307 | 1262 |
|iconOrKey image| |
1390 | 1263 |
|
2307 | 1264 |
"/ get the icon or access key from the item |
1265 |
iconOrKey := anItem icon. |
|
1390 | 1266 |
|
2307 | 1267 |
iconOrKey notNil ifTrue:[ |
1268 |
iconOrKey isImageOrForm ifTrue:[ |
|
1269 |
"/ got an image; have to register the image on my device |
|
1390 | 1270 |
|
2307 | 1271 |
iconOrKey device == device ifTrue:[ |
1272 |
^ iconOrKey |
|
1273 |
]. |
|
1274 |
^ icons at:iconOrKey ifAbsentPut:[ self imageOnDevice:iconOrKey ]. |
|
1390 | 1275 |
]. |
1276 |
||
2307 | 1277 |
image := icons at:iconOrKey ifAbsent:nil. |
1278 |
image notNil ifTrue:[ ^ image ]. |
|
1279 |
]. |
|
1280 |
||
1281 |
"/ test whether a default image should be returned |
|
1282 |
useDefaultIcons ifFalse:[ |
|
1283 |
^ nil |
|
1390 | 1284 |
]. |
1285 |
||
2307 | 1286 |
anItem hasChildren ifFalse:[ |
1287 |
^ icons at:#empty ifAbsentPut:[ self imageOnDevice:(self class emptyIcon) ] |
|
1390 | 1288 |
]. |
1898 | 1289 |
|
2307 | 1290 |
anItem isExpanded ifTrue:[ |
1291 |
^ icons at:#expanded ifAbsentPut:[ self imageOnDevice:(self class expandedIcon) ]. |
|
1898 | 1292 |
]. |
2307 | 1293 |
^ icons at:#collapsed ifAbsentPut:[ self imageOnDevice:(self class collapsedIcon) ]. |
1390 | 1294 |
! |
1295 |
||
2353 | 1296 |
lineHeightFor:anItem |
1297 |
"returns the computed line height for an item |
|
1298 |
" |
|
1299 |
|image height| |
|
1300 |
||
1301 |
height := renderer heightFor:anItem. |
|
1302 |
image := self iconFor:anItem. |
|
1303 |
||
1304 |
image notNil ifTrue:[ |
|
1305 |
height := image height max:height. |
|
1306 |
]. |
|
1307 |
||
1308 |
hasConstantHeight ifTrue:[ |
|
1309 |
icons size ~~ 0 ifTrue:[ |
|
1310 |
icons do:[:anIcon| height := anIcon height max:height ] |
|
1311 |
] ifFalse:[ |
|
1312 |
image isNil ifTrue:[ height := height max:16 ] |
|
1313 |
] |
|
1314 |
]. |
|
1315 |
height := height + lineSpacing. |
|
1316 |
^ height max:minLineHeight |
|
1317 |
! |
|
1318 |
||
1390 | 1319 |
smallestLevelBetween:start and:stop |
2327 | 1320 |
"returns the smallest level of all items in a range |
1390 | 1321 |
" |
1322 |
|prevItem currParent nextParent item |
|
1323 |
||
1324 |
lvl "{ Class:SmallInteger }" |
|
1325 |
min "{ Class:SmallInteger }" |
|
1326 |
beg "{ Class:SmallInteger }" |
|
1327 |
| |
|
1328 |
||
2408 | 1329 |
prevItem := self at:start ifAbsent:nil. |
1390 | 1330 |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1331 |
(prevItem isNil or:[(currParent := prevItem parent) isNil]) ifTrue:[ |
1390 | 1332 |
^ 1 |
1333 |
]. |
|
1334 |
||
1335 |
(min := prevItem level) == 2 ifTrue:[ |
|
1336 |
^ min |
|
1337 |
]. |
|
1338 |
beg := start + 1. |
|
1339 |
||
1340 |
beg to:stop do:[:i| |
|
2408 | 1341 |
item := self at:i ifAbsent:nil. |
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
1342 |
item isNil ifTrue:[^ min]. |
1390 | 1343 |
|
1344 |
(nextParent := item parent) == currParent ifFalse:[ |
|
1345 |
(currParent := nextParent) == prevItem ifFalse:[ |
|
1346 |
(lvl := item level) == 2 ifTrue:[ |
|
1347 |
^ 2 |
|
1348 |
]. |
|
1349 |
min := min min:lvl |
|
1350 |
] |
|
1351 |
]. |
|
1352 |
prevItem := item |
|
1353 |
]. |
|
1354 |
^ min |
|
1355 |
! |
|
1356 |
||
1357 |
widthOfWidestLineBetween:firstLine and:lastLine |
|
2327 | 1358 |
"returns the width of the longest line in pixels in a range |
1390 | 1359 |
" |
2383 | 1360 |
|parent item |
1361 |
textX "{ Class: SmallInteger }" |
|
1362 |
level "{ Class: SmallInteger }" |
|
1363 |
width "{ Class: SmallInteger }" |
|
1364 |
widthOfLabel "{ Class: SmallInteger }" |
|
1390 | 1365 |
| |
2383 | 1366 |
width := 20. |
1568 | 1367 |
|
1368 |
alignTextRight ifTrue:[ |
|
2383 | 1369 |
parent := nil. |
1370 |
level := 1. |
|
1371 |
||
1568 | 1372 |
firstLine to:lastLine do:[:idx| |
2408 | 1373 |
item := self at:idx ifAbsent:nil. |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1374 |
|
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1375 |
item notNil ifTrue:[ |
2353 | 1376 |
width := (renderer widthFor:item) max:width. |
1568 | 1377 |
|
2383 | 1378 |
item parent ~~ parent ifTrue:[ |
1379 |
level := item level max:level. |
|
1380 |
parent := item parent. |
|
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1381 |
]. |
1568 | 1382 |
]. |
1383 |
]. |
|
1384 |
maxWidthOfText := maxWidthOfText max:width. |
|
2383 | 1385 |
textX := self xVisibleOfIconAtLevel:(level + 1). |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1386 |
|
2383 | 1387 |
alignTextRightX < textX ifTrue:[ |
2417
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
1388 |
alignTextRightX := textX. |
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1389 |
shown ifTrue:[ self invalidate]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1390 |
]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1391 |
^ alignTextRightX + width |
1568 | 1392 |
]. |
1390 | 1393 |
|
2383 | 1394 |
parent := 4711. "/ force a computation |
1390 | 1395 |
|
1396 |
firstLine to:lastLine do:[:idx| |
|
2408 | 1397 |
item := self at:idx ifAbsent:nil. |
1390 | 1398 |
|
2383 | 1399 |
item notNil ifTrue:[ |
1400 |
item parent ~~ parent ifTrue:[ |
|
1401 |
textX := self xVisibleOfTextAtLevel:(item level). |
|
1402 |
parent := item parent. |
|
1403 |
]. |
|
1404 |
widthOfLabel := renderer widthFor:item. |
|
1405 |
maxWidthOfText := maxWidthOfText max:widthOfLabel. |
|
1406 |
width := widthOfLabel + textX max:width |
|
1390 | 1407 |
]. |
1408 |
]. |
|
2383 | 1409 |
^ width + viewOrigin x. |
1390 | 1410 |
! |
1411 |
||
2327 | 1412 |
xVisibleOfIconAtLevel:aLevel |
1413 |
"returns the visible origin x of the icon at a level. |
|
1390 | 1414 |
" |
2383 | 1415 |
|x| |
1390 | 1416 |
|
2383 | 1417 |
x := self xVisibleOfVerticalLineAt:aLevel. |
1390 | 1418 |
|
2383 | 1419 |
(showRoot and:[aLevel == 1]) ifTrue:[ |
2392 | 1420 |
showLeftIndicators ifFalse:[ |
2383 | 1421 |
^ x - (imageWidth // 2) |
1422 |
]. |
|
1390 | 1423 |
]. |
2383 | 1424 |
^ x + (openIndicator width // 2) + imageInset |
1425 |
! |
|
1426 |
||
1427 |
xVisibleOfIndicatorAtLevel:aLevel |
|
1428 |
"returns the visible origin x of the vertical line at a level. |
|
1429 |
" |
|
1430 |
|x| |
|
1431 |
||
1432 |
x := self xVisibleOfVerticalLineAt:aLevel. |
|
1433 |
x := x - (openIndicator width // 2). |
|
1434 |
^ x |
|
1390 | 1435 |
! |
1436 |
||
2327 | 1437 |
xVisibleOfItem:anItem |
1438 |
"returns the visible origin x of the item's label. |
|
1439 |
" |
|
1440 |
^ self xVisibleOfTextAtLevel:(anItem level) |
|
1441 |
! |
|
1442 |
||
1443 |
xVisibleOfTextAtLevel:aLevel |
|
1444 |
"returns the visible origin x of the text label at a level. |
|
1757 | 1445 |
" |
1446 |
alignTextRight ifTrue:[ |
|
1447 |
^ alignTextRightX - (viewOrigin x) |
|
1448 |
]. |
|
2327 | 1449 |
^ (self xVisibleOfIconAtLevel:aLevel) + imageWidth + textStartLeft |
2383 | 1450 |
! |
1451 |
||
1452 |
xVisibleOfVerticalLineAt:aLevel |
|
1453 |
"returns the visible origin x of the vertical line assigned to a level. |
|
1454 |
" |
|
1455 |
|xOffset opWidth2 igWidth2 firstLevel| |
|
1456 |
||
1457 |
opWidth2 := openIndicator width // 2. |
|
1458 |
igWidth2 := imageWidth // 2. |
|
1459 |
xOffset := igWidth2 + opWidth2 + imageInset. |
|
1460 |
||
1461 |
showRoot ifTrue:[ firstLevel := 1 ] |
|
1462 |
ifFalse:[ firstLevel := 2 ]. |
|
1463 |
||
2392 | 1464 |
showLeftIndicators ifTrue:[ |
2383 | 1465 |
aLevel < firstLevel ifTrue:[ |
1466 |
xOffset := opWidth2 - (firstLevel * xOffset) |
|
1467 |
] ifFalse:[ |
|
1468 |
xOffset := opWidth2 + (aLevel - firstLevel * xOffset) |
|
1469 |
] |
|
1470 |
] ifFalse:[ |
|
1471 |
aLevel < 2 ifTrue:[ |
|
1472 |
xOffset := igWidth2 - (aLevel - firstLevel * xOffset) |
|
1473 |
] ifFalse:[ |
|
1474 |
xOffset := igWidth2 + (aLevel - firstLevel - 1 * xOffset) |
|
1475 |
]. |
|
1476 |
]. |
|
1477 |
"/ 2 := a left margin |
|
1478 |
^ xOffset + 2 - (viewOrigin x) |
|
1390 | 1479 |
! ! |
1480 |
||
2224 | 1481 |
!HierarchicalListView methodsFor:'scrolling'! |
1482 |
||
1483 |
computeViewOriginXat:aLnrNr |
|
2327 | 1484 |
"returns the viewOrigin x to make the item at a line visisble |
2224 | 1485 |
" |
2383 | 1486 |
|item xLft xRgt level vwOrgX useX| |
2224 | 1487 |
|
2233 | 1488 |
vwOrgX := viewOrigin x. |
2224 | 1489 |
|
2383 | 1490 |
alignTextRight ifTrue:[ ^ vwOrgX ]. |
1491 |
aLnrNr == 1 ifTrue:[ ^ 0 ]. |
|
1492 |
||
2408 | 1493 |
item := self at:aLnrNr ifAbsent:nil. |
2307 | 1494 |
item isNil ifTrue:[ ^ vwOrgX ]. |
2224 | 1495 |
|
1496 |
level := item level. |
|
2383 | 1497 |
level == 1 ifTrue:[ ^ 0 ]. "/ is root item |
1498 |
||
1499 |
level == 2 ifTrue:[ "/ parent is root |
|
1500 |
(showRoot and:[showLeftIndicators]) ifFalse:[ ^ 0 ]. |
|
1501 |
]. |
|
2224 | 1502 |
|
2327 | 1503 |
xLft := self xVisibleOfIconAtLevel:(level - 1). |
2383 | 1504 |
xLft > 0 ifFalse:[ ^ vwOrgX + xLft max:0 ]. |
2224 | 1505 |
|
2353 | 1506 |
xRgt := (self xVisibleOfTextAtLevel:level) + (renderer widthFor:item). |
2383 | 1507 |
useX := xRgt - width. |
2224 | 1508 |
|
2383 | 1509 |
useX > 0 ifFalse:[ ^ vwOrgX ]. |
1510 |
useX := useX + 16 min:xLft. |
|
1511 |
^ vwOrgX + useX. |
|
2224 | 1512 |
! |
1513 |
||
1514 |
makeLineVisible:aLnrNr |
|
2327 | 1515 |
"make the line horizontal and vertical visible |
2224 | 1516 |
" |
1517 |
|newY item y0 newX| |
|
1518 |
||
2316
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1519 |
alignTextRight ifTrue:[^ self]. |
f91a9635462e
bug fix for alignTextRight; recomputation of alignTextRightX
ca
parents:
2313
diff
changeset
|
1520 |
|
2224 | 1521 |
(shown and:[aLnrNr notNil]) ifFalse:[^ self]. |
1522 |
||
1523 |
aLnrNr <= 1 ifTrue:[ |
|
1524 |
aLnrNr == 1 ifTrue:[ self scrollTo:(0 @ 0) ]. |
|
2353 | 1525 |
^ self |
2224 | 1526 |
]. |
1527 |
||
2408 | 1528 |
item := self at:aLnrNr ifAbsent:nil. |
2307 | 1529 |
item isNil ifTrue:[^ self]. |
2224 | 1530 |
|
1531 |
y0 := self yVisibleOfLine:aLnrNr. |
|
1532 |
||
1533 |
( y0 < margin |
|
2353 | 1534 |
or:[(y0 + (renderer heightFor:item)) > (height - margin)] |
2224 | 1535 |
) ifTrue:[ |
1536 |
newY := ((self yAbsoluteOfLine:aLnrNr) - (height // 2)) max:0. |
|
1537 |
] ifFalse:[ |
|
1538 |
newY := viewOrigin y. |
|
1539 |
]. |
|
1540 |
||
1541 |
newX := viewOrigin x. |
|
1542 |
||
1543 |
(autoScrollHorizontal or:[newX ~~ 0]) ifTrue:[ |
|
1544 |
newX := self computeViewOriginXat:aLnrNr |
|
1545 |
]. |
|
1546 |
self scrollTo:(newX @ newY). |
|
1547 |
! ! |
|
1548 |
||
1390 | 1549 |
!HierarchicalListView class methodsFor:'documentation'! |
1550 |
||
1551 |
version |
|
2417
a0b7d30a4073
instead of #numArgs use: #valueWithOptionalArgument:and
ca
parents:
2414
diff
changeset
|
1552 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalListView.st,v 1.79 2002-12-19 06:21:30 ca Exp $' |
1390 | 1553 |
! ! |