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