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