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