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