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