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