author | ca |
Sat, 04 Apr 1998 10:45:57 +0200 | |
changeset 838 | d15daece0c54 |
parent 835 | 36202285352f |
child 846 | 368acc8d9258 |
permissions | -rw-r--r-- |
444 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
14 |
SelectionInListView subclass:#SelectionInTreeView |
|
792 | 15 |
instanceVariableNames:'validateDoubleClickBlock selectionHolder rootHolder imageWidth |
16 |
showLines listOfNodes imageInset textInset labelOffsetY lineMask |
|
811 | 17 |
lineColor computeResources showRoot showDirectoryIndicator |
18 |
closeIndicator openIndicator showDirectoryIndicatorForRoot |
|
19 |
imageOpened imageClosed imageItem discardMotionEvents |
|
835 | 20 |
registeredImages supportsExpandAll' |
811 | 21 |
classVariableNames:'' |
792 | 22 |
poolDictionaries:'' |
23 |
category:'Views-Text' |
|
444 | 24 |
! |
25 |
||
26 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
27 |
||
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
31 |
All Rights Reserved |
|
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 |
||
43 |
documentation |
|
44 |
" |
|
45 |
somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like) |
|
46 |
lists and adds the functions to show/hide subtrees. |
|
456 | 47 |
Requires SelectionInTree as model and TreeItem (or compatible) list entries. |
444 | 48 |
|
456 | 49 |
This class obsoletes SelectionInTreeView, which is no longer |
446 | 50 |
maintained but kept for backward compatibility. |
51 |
||
52 |
||
444 | 53 |
[see also:] |
456 | 54 |
SelectionInTree |
55 |
TreeItem |
|
56 |
SelectionInTreeView |
|
444 | 57 |
SelectionInListView |
494 | 58 |
FileSelectionTree |
444 | 59 |
|
60 |
[author:] |
|
61 |
Claus Atzkern |
|
62 |
" |
|
63 |
||
64 |
! |
|
65 |
||
66 |
examples |
|
67 |
" |
|
68 |
shows the tree of smalltalk classes: |
|
69 |
[exBegin] |
|
514 | 70 |
|top sel| |
456 | 71 |
|
514 | 72 |
top := StandardSystemView new; extent:300@300. |
456 | 73 |
sel := SelectionInTreeView new. |
514 | 74 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
456 | 75 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
76 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
77 |
top open. |
|
78 |
[exEnd] |
|
79 |
||
80 |
||
485 | 81 |
|
456 | 82 |
same, including nil-subclasses (i.e. really all classes): |
83 |
[exBegin] |
|
514 | 84 |
|top sel| |
444 | 85 |
|
514 | 86 |
top := StandardSystemView new; extent:300@300. |
456 | 87 |
sel := SelectionInTreeView new. |
514 | 88 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:nil). |
456 | 89 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
685 | 90 |
sel lineColor:(Color red). |
456 | 91 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
92 |
top open. |
|
93 |
[exEnd] |
|
94 |
||
485 | 95 |
|
483 | 96 |
|
485 | 97 |
shows the tree of smalltalk classes; show directory indication and no |
98 |
lines. |
|
99 |
[exBegin] |
|
514 | 100 |
|top sel| |
483 | 101 |
|
514 | 102 |
top := StandardSystemView new; extent:300@300. |
483 | 103 |
sel := SelectionInTreeView new. |
485 | 104 |
sel showLines:false. |
105 |
sel showDirectoryIndicator:true. |
|
514 | 106 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
485 | 107 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
483 | 108 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
109 |
top open. |
|
485 | 110 |
[exEnd] |
111 |
" |
|
112 |
||
514 | 113 |
|
444 | 114 |
! ! |
115 |
||
116 |
!SelectionInTreeView class methodsFor:'constants'! |
|
117 |
||
494 | 118 |
minImageInset |
119 |
"returns minimum inset from directory indication to image |
|
471 | 120 |
" |
494 | 121 |
^ 6 |
490 | 122 |
|
123 |
||
124 |
! ! |
|
125 |
||
811 | 126 |
!SelectionInTreeView class methodsFor:'resources'! |
490 | 127 |
|
128 |
closeIndicator |
|
589 | 129 |
<resource: #fileImage> |
130 |
||
811 | 131 |
^ Icon |
132 |
constantNamed:#plus |
|
133 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/plus.xpm')] |
|
134 |
||
589 | 135 |
|
811 | 136 |
|
137 |
||
138 |
||
139 |
||
471 | 140 |
! |
141 |
||
444 | 142 |
imageClosed |
589 | 143 |
<resource: #fileImage> |
144 |
||
811 | 145 |
^ Icon |
146 |
constantNamed:#directory |
|
147 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm')] |
|
444 | 148 |
|
149 |
! |
|
150 |
||
151 |
imageItem |
|
589 | 152 |
<resource: #fileImage> |
153 |
||
811 | 154 |
^ Icon |
155 |
constantNamed:#plainFile |
|
156 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm')] |
|
444 | 157 |
|
811 | 158 |
|
444 | 159 |
|
811 | 160 |
|
161 |
||
444 | 162 |
! |
163 |
||
164 |
imageOpened |
|
589 | 165 |
<resource: #fileImage> |
166 |
||
811 | 167 |
^ Icon |
168 |
constantNamed:#directoryOpened |
|
169 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm')] |
|
444 | 170 |
|
490 | 171 |
! |
172 |
||
173 |
openIndicator |
|
589 | 174 |
<resource: #fileImage> |
175 |
||
811 | 176 |
^ Icon |
177 |
constantNamed:#minus |
|
178 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/minus.xpm')] |
|
490 | 179 |
|
811 | 180 |
|
444 | 181 |
! ! |
182 |
||
183 |
!SelectionInTreeView methodsFor:'accessing'! |
|
184 |
||
685 | 185 |
lineColor |
186 |
"returns user configured line color or nil |
|
187 |
" |
|
188 |
^ lineColor |
|
189 |
||
190 |
! |
|
191 |
||
192 |
lineColor:aColor |
|
193 |
"returns user configured line color or nil |
|
194 |
" |
|
195 |
|col| |
|
196 |
||
197 |
col := aColor = fgColor ifTrue:[nil] ifFalse:[aColor]. |
|
198 |
||
199 |
col = lineColor ifFalse:[ |
|
200 |
lineColor := col. |
|
201 |
||
202 |
shown ifTrue:[ |
|
203 |
lineColor notNil ifTrue:[lineColor := lineColor on:device]. |
|
204 |
self invalidate |
|
205 |
] |
|
206 |
] |
|
207 |
! |
|
208 |
||
490 | 209 |
nodeAtIndex:anIndex |
210 |
"returns node at an index or nil |
|
211 |
" |
|
785 | 212 |
(anIndex notNil and:[anIndex between:1 and:listOfNodes size]) ifTrue:[ |
490 | 213 |
^ listOfNodes at:anIndex |
214 |
]. |
|
215 |
^ nil |
|
216 |
! |
|
217 |
||
507 | 218 |
root |
219 |
"gets the root of the model; the first item into list. |
|
220 |
" |
|
221 |
^ self nodeAtIndex:1 |
|
222 |
! |
|
223 |
||
224 |
root:aRoot |
|
225 |
"sets the root of the model; the first item into list. |
|
226 |
" |
|
514 | 227 |
aRoot notNil ifTrue:[aRoot expand]. |
507 | 228 |
model root:aRoot |
229 |
! |
|
230 |
||
490 | 231 |
textInset |
232 |
"get the left inset of the text label |
|
233 |
" |
|
234 |
^ textInset |
|
235 |
! |
|
236 |
||
237 |
textInset:anInset |
|
238 |
"set the left inset of the text label |
|
239 |
" |
|
240 |
anInset ~~ textInset ifTrue:[ |
|
241 |
anInset >= 0 ifTrue:[ |
|
242 |
textInset := anInset. |
|
243 |
self invalidate |
|
244 |
] ifFalse:[ |
|
245 |
self error |
|
246 |
] |
|
247 |
]. |
|
248 |
! ! |
|
249 |
||
250 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
|
251 |
||
252 |
showDirectoryIndicator |
|
253 |
"returns true if directories has an open/closed indicator |
|
254 |
" |
|
255 |
^ showDirectoryIndicator |
|
256 |
! |
|
257 |
||
258 |
showDirectoryIndicator:aState |
|
259 |
"set or clear open/closed indicator for directories |
|
260 |
" |
|
261 |
"show or hide lines |
|
262 |
" |
|
263 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
494 | 264 |
showDirectoryIndicator := aState. |
546 | 265 |
self recomputeDirectoryIndicator. |
490 | 266 |
self invalidate |
267 |
]. |
|
268 |
! |
|
269 |
||
659 | 270 |
showDirectoryIndicatorForRoot |
271 |
"returns true if root directory has an open/closed indicator if |
|
272 |
the common showDirectoryIndicator is enabled |
|
273 |
" |
|
274 |
^ showDirectoryIndicatorForRoot |
|
275 |
! |
|
276 |
||
277 |
showDirectoryIndicatorForRoot:aState |
|
278 |
"true if root directory has an open/closed indicator if |
|
279 |
the common showDirectoryIndicator is enabled |
|
280 |
" |
|
281 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
282 |
showDirectoryIndicatorForRoot := aState. |
|
283 |
self recomputeDirectoryIndicator. |
|
284 |
self invalidate |
|
285 |
]. |
|
286 |
! |
|
287 |
||
490 | 288 |
showLines |
289 |
"returns true if lines are shown |
|
290 |
" |
|
291 |
^ showLines |
|
292 |
! |
|
293 |
||
294 |
showLines:aState |
|
295 |
"show or hide lines |
|
296 |
" |
|
297 |
aState ~~ showLines ifTrue:[ |
|
298 |
showLines := aState. |
|
299 |
self invalidate |
|
300 |
]. |
|
494 | 301 |
! |
302 |
||
303 |
showRoot |
|
304 |
"list with or without root |
|
305 |
" |
|
306 |
^ showRoot |
|
307 |
! |
|
308 |
||
309 |
showRoot:aState |
|
310 |
"list with or without root |
|
311 |
" |
|
312 |
showRoot ~~ aState ifTrue:[ |
|
514 | 313 |
model showRoot:(showRoot := aState) |
314 |
]. |
|
517 | 315 |
! |
316 |
||
835 | 317 |
supportsExpandAll |
318 |
^ supportsExpandAll |
|
319 |
! |
|
320 |
||
321 |
supportsExpandAll:aBool |
|
322 |
||
323 |
supportsExpandAll := aBool |
|
324 |
! |
|
325 |
||
517 | 326 |
validateDoubleClickBlock |
327 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
328 |
on a node will be performed. In case of returning false, the doubleClick will |
|
329 |
not be handled. |
|
330 |
" |
|
331 |
^ validateDoubleClickBlock |
|
332 |
||
333 |
||
334 |
! |
|
335 |
||
336 |
validateDoubleClickBlock:aOneArgBlock |
|
337 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
338 |
on a node will be performed. In case of returning false, the doubleClick will |
|
339 |
not be handled. |
|
340 |
" |
|
341 |
validateDoubleClickBlock := aOneArgBlock |
|
342 |
||
343 |
||
514 | 344 |
! ! |
345 |
||
346 |
!SelectionInTreeView methodsFor:'accessing-channels'! |
|
347 |
||
348 |
rootHolder |
|
349 |
"get the holder which keeps the hierarchical list entry or nil |
|
350 |
" |
|
351 |
^ rootHolder |
|
352 |
! |
|
353 |
||
354 |
rootHolder:aValueHolder |
|
355 |
"set the holder which keeps the hierarchical list entry or nil |
|
356 |
" |
|
357 |
rootHolder notNil ifTrue:[ |
|
358 |
rootHolder removeDependent:self |
|
359 |
]. |
|
360 |
(rootHolder := aValueHolder) notNil ifTrue:[ |
|
361 |
rootHolder addDependent:self. |
|
362 |
self rootFromModel. |
|
494 | 363 |
]. |
514 | 364 |
! |
365 |
||
366 |
selectionHolder |
|
367 |
"get the holder which keeps a list of selected items or nil |
|
368 |
" |
|
369 |
^ selectionHolder |
|
370 |
||
371 |
! |
|
372 |
||
373 |
selectionHolder:aHolder |
|
374 |
"set the holder which keeps a list of selected items or nil |
|
375 |
" |
|
376 |
selectionHolder notNil ifTrue:[ |
|
377 |
selectionHolder removeDependent:self |
|
378 |
]. |
|
379 |
||
380 |
(selectionHolder := aHolder) notNil ifTrue:[ |
|
381 |
selectionHolder addDependent:self. |
|
382 |
self selectionFromModel |
|
383 |
]. |
|
384 |
||
490 | 385 |
! ! |
386 |
||
387 |
!SelectionInTreeView methodsFor:'accessing-images'! |
|
388 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
389 |
imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
390 |
"return the value of the instance variable 'imageClosed' (automatically generated)" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
391 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
392 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
393 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
394 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
395 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
396 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
397 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
398 |
"return the value of the instance variable 'imageItem' (automatically generated)" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
399 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
400 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
401 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
402 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
403 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
404 |
|
569 | 405 |
imageOnDevice:anImage |
406 |
"associate iamge to device and clear pixel mask (in case of realized); |
|
407 |
returns the new image. |
|
408 |
" |
|
409 |
|img| |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
410 |
|
569 | 411 |
img := anImage onDevice:device. |
412 |
||
413 |
realized ifTrue:[ |
|
414 |
img := img clearMaskedPixels |
|
415 |
]. |
|
416 |
^ img |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
417 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
418 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
419 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
420 |
"return the value of the instance variable 'imageOpened' (automatically generated)" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
421 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
422 |
^ imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
423 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
424 |
"Created: 3.7.1997 / 12:34:28 / cg" |
471 | 425 |
! ! |
426 |
||
514 | 427 |
!SelectionInTreeView methodsFor:'change & update'! |
428 |
||
429 |
update:something with:aParameter from:aModel |
|
430 |
"one of my models changed its value |
|
785 | 431 |
" |
432 |
|idx| |
|
433 |
||
514 | 434 |
aModel == rootHolder ifTrue:[ |
435 |
^ self rootFromModel |
|
436 |
]. |
|
437 |
aModel == selectionHolder ifTrue:[ |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
438 |
^ self selectionFromModel |
514 | 439 |
]. |
440 |
||
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
441 |
aModel == model ifTrue:[ |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
442 |
something == #list ifTrue:[ |
585 | 443 |
^ self getListFromModel |
444 |
] |
|
785 | 445 |
] ifFalse:[ |
446 |
(aModel isKindOf:TreeItem) ifTrue:[ |
|
811 | 447 |
(something == #size or:[something == #children]) ifTrue:[ |
448 |
model recomputeList. |
|
785 | 449 |
^ self |
450 |
]. |
|
811 | 451 |
|
452 |
(idx := self indexOfNode:aModel) ~~ 0 ifTrue:[ |
|
453 |
something == #value ifTrue:[ |
|
454 |
list at:idx put:(aModel name). |
|
455 |
self redrawLine:idx. |
|
456 |
^ self |
|
457 |
]. |
|
458 |
||
459 |
something == #indication ifTrue:[ |
|
460 |
self redrawIndicatorLine:idx. |
|
461 |
^ self |
|
462 |
]. |
|
463 |
]. |
|
464 |
^ self |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
465 |
] |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
466 |
]. |
514 | 467 |
^ super update:something with:aParameter from:aModel. |
468 |
||
469 |
||
470 |
||
811 | 471 |
|
514 | 472 |
! ! |
473 |
||
444 | 474 |
!SelectionInTreeView methodsFor:'drawing'! |
475 |
||
481 | 476 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
477 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 478 |
|
479 |
! |
|
480 |
||
481 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 482 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 483 |
|
484 |
! |
|
485 |
||
486 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 487 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 488 |
|
489 |
! |
|
490 |
||
491 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 492 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 493 |
|
494 |
! |
|
495 |
||
496 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 497 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
498 |
||
444 | 499 |
! |
500 |
||
501 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 502 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 503 |
|
504 |
! ! |
|
505 |
||
506 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
507 |
||
481 | 508 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
769 | 509 |
"redraw a visible line range with clearing the background |
510 |
" |
|
511 |
|y0 y1 sz| |
|
481 | 512 |
|
769 | 513 |
shown ifTrue:[ |
514 |
y0 := self yOfVisibleLine:startVisLineNr. |
|
515 |
y0 := y0 - 1. |
|
516 |
sz := endVisLineNr - startVisLineNr + 1. |
|
517 |
y1 := sz * fontHeight. |
|
518 |
||
519 |
"/ clear rectangle line and set background color |
|
520 |
self paint:bg. |
|
521 |
self fillRectangleX:0 y:y0 width:width height:y1. |
|
522 |
||
523 |
(y1 := self visibleLineToAbsoluteLine:startVisLineNr) notNil ifTrue:[ |
|
524 |
self redrawLinesX:0 y:y0 toX:width start:y1 stop:(y1 + sz) |
|
525 |
] |
|
526 |
] |
|
527 |
! |
|
528 |
||
529 |
drawLabelIndex:anIndex atX:x y:yCenter |
|
530 |
"draw text label at x and y centered |
|
531 |
" |
|
532 |
|lbl| |
|
533 |
||
534 |
(lbl := (listOfNodes at:anIndex) name) notNil ifTrue:[ |
|
535 |
self displayOpaqueString:lbl x:x y:(yCenter + labelOffsetY). |
|
536 |
] |
|
537 |
! |
|
538 |
||
811 | 539 |
redrawIndicatorLine:aLineNr |
540 |
"redraw the directory indicator for a line |
|
541 |
" |
|
542 |
|node ext img visLn |
|
543 |
x "{ Class:SmallInteger }" |
|
544 |
y "{ Class:SmallInteger }" |
|
545 |
lv "{ Class:SmallInteger }" |
|
546 |
dX "{ Class:SmallInteger }" |
|
547 |
| |
|
548 |
||
549 |
( shown |
|
550 |
and:[showDirectoryIndicator |
|
551 |
and:[(visLn := self listLineToVisibleLine:aLineNr) notNil]] |
|
552 |
) ifFalse:[ |
|
553 |
^ self |
|
554 |
]. |
|
555 |
||
556 |
node := listOfNodes at:aLineNr. |
|
557 |
||
558 |
((lv := node level) ~~ 1 or:[showDirectoryIndicatorForRoot]) ifFalse:[ |
|
559 |
^ self |
|
560 |
]. |
|
561 |
||
562 |
(x := imageWidth // 2) odd ifTrue:[x := x + 1]. |
|
563 |
x := (self xOfFigureLevel:(lv - 1)) + x. |
|
564 |
||
565 |
"/ draw directory indicator |
|
566 |
||
567 |
img := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
|
568 |
ext := img extent // 2. |
|
569 |
dX := ext x. |
|
570 |
||
571 |
(x + dX > 0 and:[(x := x - dX) < (width - margin)]) ifTrue:[ |
|
572 |
(self isInSelection:aLineNr) ifTrue:[ self paint:hilightFgColor on:hilightBgColor ] |
|
573 |
ifFalse:[ self paint:fgColor on:bgColor ]. |
|
574 |
||
575 |
y := (self yOfVisibleLine:visLn) + (fontHeight // 2) - 1. |
|
576 |
self displayForm:img x:x y:(y - ext y) |
|
577 |
]. |
|
578 |
||
579 |
||
580 |
||
581 |
! |
|
582 |
||
769 | 583 |
redrawLinesX:x0 y:y0 toX:x1 start:start stop:stop |
584 |
"redraw from line to line without clearing the background |
|
585 |
" |
|
811 | 586 |
|node image extent isSelected defLineColor rnode prnt |
785 | 587 |
x "{ Class:SmallInteger }" |
588 |
y "{ Class:SmallInteger }" |
|
589 |
level "{ Class:SmallInteger }" |
|
590 |
yTop "{ Class:SmallInteger }" |
|
591 |
yBot "{ Class:SmallInteger }" |
|
592 |
yCtr "{ Class:SmallInteger }" |
|
593 |
size "{ Class:SmallInteger }" |
|
594 |
end "{ Class:SmallInteger }" |
|
595 |
index "{ Class:SmallInteger }" |
|
596 |
xCross "{ Class:SmallInteger }" |
|
597 |
xFig "{ Class:SmallInteger }" |
|
598 |
xStr "{ Class:SmallInteger }" |
|
599 |
dyLvl "{ Class:SmallInteger }" |
|
600 |
soVDt "{ Class:SmallInteger }" |
|
601 |
soVLn "{ Class:SmallInteger }" |
|
602 |
lv "{ Class:SmallInteger }" |
|
769 | 603 |
figWidthDiv2 "{ Class:SmallInteger }" |
604 |
| |
|
785 | 605 |
size := listOfNodes size. |
606 |
index := start. |
|
607 |
end := stop min:size. |
|
608 |
level := -1. "/ to force evaluation of #ifFalse in loop |
|
609 |
soVDt := 0. |
|
610 |
yTop := y0. |
|
611 |
yCtr := yTop - (fontHeight // 2). |
|
612 |
dyLvl := imageInset + imageWidth. |
|
541 | 613 |
figWidthDiv2 := imageWidth // 2. |
685 | 614 |
figWidthDiv2 odd ifTrue:[figWidthDiv2 := figWidthDiv2 + 1]. |
785 | 615 |
|
616 |
showLines ifTrue:[ |
|
617 |
soVDt := (figWidthDiv2 + (self xOfFigureLevel:1)) - dyLvl - dyLvl. |
|
618 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
619 |
defLineColor := lineColor ? fgColor. |
|
620 |
]. |
|
485 | 621 |
|
769 | 622 |
[index <= end] whileTrue:[ |
494 | 623 |
node := listOfNodes at:index. |
624 |
yBot := yTop + fontHeight. |
|
625 |
yCtr := yCtr + fontHeight. |
|
485 | 626 |
|
494 | 627 |
(lv := node level) == level ifFalse:[ |
628 |
xFig := self xOfFigureLevel:lv. |
|
629 |
xStr := self xOfStringLevel:lv. |
|
785 | 630 |
xCross := xFig - dyLvl + figWidthDiv2. |
631 |
level := lv. |
|
632 |
soVLn := lv * dyLvl + soVDt. |
|
481 | 633 |
]. |
634 |
||
769 | 635 |
(isSelected := self isInSelection:index) ifTrue:[ |
785 | 636 |
self paint:hilightFgColor on:hilightBgColor |
769 | 637 |
]. |
481 | 638 |
showLines ifTrue:[ |
785 | 639 |
isSelected ifFalse:[ |
640 |
self paint:defLineColor on:bgColor |
|
685 | 641 |
]. |
642 |
self mask:lineMask. |
|
643 |
||
769 | 644 |
xCross < x1 ifTrue:[ |
645 |
( ((x := xFig + figWidthDiv2) between:x0 and:x1) |
|
646 |
and:[node isCollapsable |
|
785 | 647 |
and:[node children notEmpty]] |
769 | 648 |
) ifTrue:[ |
649 |
self displayLineFromX:x y:yCtr toX:x y:yBot |
|
650 |
]. |
|
651 |
||
652 |
"/ vertical line from previous to current form |
|
785 | 653 |
(xCross >= x0 and:[level ~~ 1]) ifTrue:[ |
811 | 654 |
prnt := node parent children. |
655 |
prnt isEmpty ifTrue:[ ^ self ]. "/ error occured |
|
656 |
lv := prnt last == node ifTrue:[yCtr] ifFalse:[yBot]. |
|
785 | 657 |
self displayLineFromX:xCross y:yTop - 1 toX:xCross y:lv |
769 | 658 |
]. |
659 |
||
660 |
"/ horizontal line from previous to current form |
|
661 |
( xFig > x0 |
|
662 |
and:[(level ~~ 1 |
|
663 |
or:[showDirectoryIndicatorForRoot and:[showDirectoryIndicator]])] |
|
664 |
) ifTrue:[ |
|
665 |
self displayLineFromX:xCross y:yCtr toX:xFig y:yCtr |
|
666 |
] |
|
490 | 667 |
]. |
659 | 668 |
|
769 | 669 |
"/ draw all vertical lines to left side |
785 | 670 |
(xCross >= x0 and:[(rnode := node parent) notNil]) ifTrue:[ |
671 |
x := soVLn. |
|
672 |
y := yTop - 1. |
|
481 | 673 |
|
785 | 674 |
[((prnt := rnode parent) notNil and:[(x := x - dyLvl) >= x0])] whileTrue:[ |
675 |
(prnt children last ~~ rnode and:[x <= x1]) ifTrue:[ |
|
676 |
self displayLineFromX:x y:y toX:x y:yBot |
|
677 |
]. |
|
678 |
rnode := prnt |
|
481 | 679 |
] |
685 | 680 |
]. |
681 |
self mask:nil. |
|
785 | 682 |
]. |
683 |
isSelected ifFalse:[ |
|
684 |
self paint:fgColor on:bgColor |
|
481 | 685 |
]. |
686 |
||
687 |
"/ draw image |
|
769 | 688 |
(image := self figureFor:node) notNil ifTrue:[ |
785 | 689 |
(xFig < x1 and:[xStr > x0]) ifTrue:[ |
769 | 690 |
self displayForm:image x:xFig y:(yCtr - (image height // 2)) |
691 |
] |
|
541 | 692 |
]. |
481 | 693 |
|
694 |
"/ draw text label |
|
770 | 695 |
xStr < x1 ifTrue:[ |
696 |
self drawLabelIndex:index atX:xStr y:yCtr . |
|
697 |
]. |
|
490 | 698 |
|
494 | 699 |
"/ draw directory indicator |
659 | 700 |
|
569 | 701 |
(showDirectoryIndicator and:[node showIndicator]) ifTrue:[ |
659 | 702 |
(level ~~ 1 or:[showDirectoryIndicatorForRoot]) ifTrue:[ |
811 | 703 |
image := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
704 |
extent := image extent // 2. |
|
705 |
x := extent x. |
|
769 | 706 |
|
811 | 707 |
(xCross + x > x0 and:[(x := xCross - x) < x1]) ifTrue:[ |
708 |
self displayForm:image x:x y:(yCtr - extent y) |
|
769 | 709 |
] |
659 | 710 |
] |
485 | 711 |
]. |
481 | 712 |
"/ setup next line |
494 | 713 |
index := index + 1. |
714 |
yTop := yBot. |
|
769 | 715 |
] |
811 | 716 |
|
792 | 717 |
! |
718 |
||
719 |
redrawSelFrameForYs:aList fromX:x0 toX:x1 |
|
720 |
"redraw selection frames for each line starting at an absolute |
|
721 |
y derived from the argument a list. |
|
722 |
" |
|
723 |
| |
|
724 |
spc "{ Class: SmallInteger }" |
|
725 |
dY "{ Class: SmallInteger }" |
|
726 |
w "{ Class: SmallInteger }" |
|
727 |
y "{ Class: SmallInteger }" |
|
728 |
x "{ Class: SmallInteger }" |
|
729 |
| |
|
730 |
||
731 |
aList size == 0 ifTrue:[ ^ self ]. |
|
732 |
||
733 |
strikeOut ifTrue:[ |
|
734 |
y := fontHeight // 2. |
|
735 |
self paint:bgColor. |
|
736 |
aList do:[:sY| self displayLineFromX:x0 y:(sY + y) toX:x1 y:(sY + y) ]. |
|
737 |
^ self |
|
738 |
]. |
|
739 |
spc := lineSpacing // 2. |
|
740 |
||
741 |
hilightFrameColor notNil ifTrue:[ |
|
742 |
hilightLevel == 0 ifTrue:[ |
|
743 |
dY := fontHeight - 1. |
|
744 |
self paint:hilightFrameColor. |
|
745 |
||
746 |
aList do:[:sY| |
|
747 |
y := sY - spc. self displayLineFromX:x0 y:y toX:x1 y:y. |
|
748 |
y := y + dY. self displayLineFromX:x0 y:y toX:x1 y:y. |
|
749 |
] |
|
750 |
] |
|
751 |
] ifFalse:[ |
|
752 |
hilightStyle == #motif ifTrue:[ |
|
753 |
dY := fontHeight - spc - 2. |
|
754 |
self paint:bgColor. |
|
755 |
||
756 |
aList do:[:sY| |
|
757 |
y := sY - spc + 1. self displayLineFromX:x0 y:y toX:x1 y:y. |
|
758 |
y := sY + dY. self displayLineFromX:x0 y:y toX:x1 y:y. |
|
759 |
] |
|
760 |
] |
|
761 |
]. |
|
762 |
||
763 |
hilightLevel ~~ 0 ifTrue:[ |
|
764 |
"/ draw edge |
|
765 |
||
766 |
w := ((width - (2 * margin)) max:(self widthOfContents)) + leftOffset. |
|
767 |
x := margin - leftOffset. |
|
768 |
||
769 |
aList do:[:sY| |
|
770 |
self drawEdgesForX:x y:(sY - spc) width:w height:fontHeight level:hilightLevel. |
|
771 |
] |
|
772 |
] |
|
773 |
||
774 |
||
775 |
||
444 | 776 |
! ! |
777 |
||
494 | 778 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 779 |
|
494 | 780 |
detectNode:aOneArgBlock |
781 |
"evaluate the argument, aBlock for each node in the list until |
|
782 |
the block returns true; in this case return the node which caused |
|
783 |
the true evaluation. If none node is detected, nil is returned. |
|
784 |
" |
|
785 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 786 |
! |
787 |
||
788 |
selectedNodesDo:aOneArgBlock |
|
789 |
"evaluate the block on each node selected |
|
790 |
" |
|
791 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 792 |
! ! |
793 |
||
569 | 794 |
!SelectionInTreeView methodsFor:'event handling'! |
795 |
||
639 | 796 |
buttonMotion:buttonMask x:x y:y |
797 |
"mouse-move while button was pressed - handle selection changes" |
|
798 |
||
799 |
discardMotionEvents ifFalse:[ |
|
800 |
super buttonMotion:buttonMask x:x y:y |
|
801 |
] |
|
802 |
||
803 |
||
804 |
! |
|
805 |
||
569 | 806 |
buttonMultiPress:button x:x y:y |
807 |
||
808 |
(self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[ |
|
809 |
^ super buttonMultiPress:button x:x y:y |
|
810 |
]. |
|
811 |
"/ discard doubleClick on indicator |
|
812 |
! |
|
813 |
||
814 |
buttonPress:button x:x y:y |
|
815 |
"check for indicator |
|
816 |
" |
|
838 | 817 |
|expand node lineNr isExpandable| |
569 | 818 |
|
819 |
lineNr := self indicatiorLineForButton:button atX:x y:y. |
|
820 |
||
821 |
lineNr == 0 ifTrue:[ |
|
822 |
^ super buttonPress:button x:x y:y |
|
823 |
]. |
|
824 |
node := listOfNodes at:lineNr. |
|
825 |
||
835 | 826 |
node hasChildren ifFalse:[ "/ no children exists |
827 |
^ super buttonPress:button x:x y:y |
|
828 |
]. |
|
829 |
||
639 | 830 |
discardMotionEvents := true. |
569 | 831 |
dragIsActive := false. |
832 |
clickPosition := nil. |
|
833 |
||
639 | 834 |
self hasSelection ifTrue:[ |
835 |
(selectConditionBlock isNil or:[selectConditionBlock value:lineNr]) ifTrue:[ |
|
836 |
self selection:lineNr |
|
837 |
] ifFalse:[ |
|
838 |
self selection:nil |
|
569 | 839 |
] |
840 |
]. |
|
835 | 841 |
isExpandable := node isExpandable. |
842 |
||
843 |
self isCtrlMetaAltOrShiftPressed ifFalse:[ |
|
844 |
^ self nodeAt:lineNr expand:isExpandable |
|
845 |
]. |
|
846 |
||
847 |
isExpandable ifTrue:[ |
|
848 |
supportsExpandAll ifFalse:[ |
|
849 |
^ self nodeAt:lineNr expand:isExpandable |
|
850 |
]. |
|
851 |
node expandAll |
|
852 |
] ifFalse:[ |
|
853 |
(node hasExpandedChildren) ifTrue:[ |
|
854 |
node hasChildrenWithSubChildren ifFalse:[ |
|
855 |
^ self nodeAt:lineNr expand:isExpandable |
|
856 |
]. |
|
857 |
node collapseAllChildren |
|
858 |
] ifFalse:[ |
|
859 |
supportsExpandAll ifFalse:[ |
|
860 |
^ self nodeAt:lineNr expand:isExpandable |
|
861 |
]. |
|
862 |
node expandAllChildren |
|
863 |
] |
|
864 |
]. |
|
865 |
||
866 |
node children isEmpty ifTrue:[ |
|
867 |
"/ no children; redraw selected line (image might change) |
|
868 |
self redrawLine:lineNr. |
|
869 |
] ifFalse:[ |
|
870 |
"/ with children; update list and redraw to end. |
|
838 | 871 |
self recomputeListFromNodeAt:lineNr |
835 | 872 |
] |
873 |
||
569 | 874 |
|
639 | 875 |
! |
876 |
||
877 |
buttonRelease:button x:x y:y |
|
878 |
"stop any autoscroll" |
|
569 | 879 |
|
639 | 880 |
discardMotionEvents ifTrue:[ |
881 |
clickPosition := nil. |
|
882 |
discardMotionEvents := false. |
|
883 |
]. |
|
884 |
super buttonRelease:button x:x y:y |
|
885 |
||
569 | 886 |
! |
887 |
||
888 |
doubleClicked |
|
889 |
"handle a double click; collapse or expand selected entry |
|
890 |
in case of having children |
|
891 |
" |
|
892 |
|node| |
|
893 |
||
894 |
(node := self selectedNode) notNil ifTrue:[ |
|
895 |
( validateDoubleClickBlock isNil |
|
896 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
897 |
) ifTrue:[ |
|
898 |
self selectedNodeExpand:(node isExpandable). |
|
899 |
super doubleClicked |
|
900 |
] |
|
901 |
] |
|
902 |
||
903 |
! |
|
904 |
||
905 |
indicatiorLineForButton:aButton atX:x y:y |
|
906 |
"returns linenumber assigned to indicator at x/y or 0 |
|
907 |
" |
|
835 | 908 |
|nr x0 node| |
569 | 909 |
|
910 |
( enabled |
|
911 |
and:[showDirectoryIndicator |
|
912 |
and:[aButton == 1 or:[aButton == #select]]] |
|
913 |
) ifTrue:[ |
|
835 | 914 |
nr := self visibleLineToListLine:(self visibleLineOfY:y). |
569 | 915 |
|
835 | 916 |
nr notNil ifTrue:[ |
917 |
node := listOfNodes at:nr. |
|
918 |
node hasChildren ifTrue:[ |
|
919 |
x0 := self xOfFigureLevel:(node level - 1). |
|
569 | 920 |
|
835 | 921 |
(x > x0 and:[(x0 + imageWidth) > x and:[node children notEmpty]]) ifTrue:[ |
922 |
^ nr |
|
569 | 923 |
] |
924 |
] |
|
925 |
] |
|
926 |
]. |
|
927 |
^ 0 |
|
785 | 928 |
|
756 | 929 |
! |
930 |
||
835 | 931 |
isCtrlMetaAltOrShiftPressed |
932 |
"returns true if CTRL, META, ALT or SHIFT is pressed |
|
933 |
" |
|
934 |
|sensor| |
|
935 |
||
936 |
(sensor := self sensor) notNil ifTrue:[ |
|
937 |
^ ( sensor ctrlDown |
|
938 |
or:[sensor altDown |
|
939 |
or:[sensor shiftDown |
|
940 |
or:[sensor metaDown]]] |
|
941 |
) |
|
942 |
]. |
|
943 |
^ false |
|
944 |
! |
|
945 |
||
756 | 946 |
key:key select:index x:x y:y |
947 |
"select an entry by a keyboard action. This is treated like a doubleClick |
|
948 |
on that entry. |
|
949 |
Add on: In case that the entry is not selectable, scroll to the entry |
|
950 |
" |
|
951 |
(enabled and:[keyActionStyle notNil]) ifFalse:[ |
|
952 |
^ self |
|
953 |
]. |
|
954 |
||
955 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[ |
|
780 | 956 |
^ super key:key select:index x:x y:y |
756 | 957 |
]. |
958 |
||
959 |
keyActionStyle == #pass ifTrue:[ |
|
960 |
^ self |
|
961 |
]. |
|
962 |
||
963 |
self gotoLine:index |
|
785 | 964 |
! |
965 |
||
811 | 966 |
keyPress:key x:x y:y |
967 |
"handle keyboard input" |
|
968 |
||
969 |
<resource: #keyboard ( #CursorLeft #CursorRight ) > |
|
970 |
||
971 |
|idx node inc end| |
|
972 |
||
973 |
enabled ifFalse:[ |
|
974 |
^ self |
|
975 |
]. |
|
976 |
||
977 |
(key == #CursorLeft or:[key == #CursorRight]) ifTrue:[ |
|
978 |
(idx := self selectedIndex) == 0 ifTrue:[ ^ self ]. |
|
979 |
||
980 |
(key == #CursorLeft) ifTrue:[ inc := -1. end := 0 ] |
|
981 |
ifFalse:[ inc := 1. end := 1 + listOfNodes size ]. |
|
982 |
||
983 |
[(idx := idx + inc) ~~ end] whileTrue:[ |
|
984 |
node := listOfNodes at:idx. |
|
825 | 985 |
node hasChildren ifTrue:[ |
811 | 986 |
^ self key:key select:idx x:x y:y |
987 |
] |
|
988 |
]. |
|
989 |
^ self |
|
990 |
]. |
|
991 |
^ super keyPress:key x:x y:y |
|
992 |
||
993 |
||
994 |
||
995 |
||
996 |
! |
|
997 |
||
785 | 998 |
redrawX:x y:y width:w height:h |
999 |
"a region must be redrawn" |
|
1000 |
||
792 | 1001 |
|savClip startLn sel |
1002 |
lnSpace "{ Class:SmallInteger }" |
|
785 | 1003 |
y0 "{ Class:SmallInteger }" |
1004 |
y1 "{ Class:SmallInteger }" |
|
1005 |
visStart "{ Class:SmallInteger }" |
|
1006 |
visEnd "{ Class:SmallInteger }" |
|
1007 |
stopLn "{ Class:SmallInteger }" |
|
1008 |
maxY "{ Class:SmallInteger }" |
|
792 | 1009 |
maxX "{ Class:SmallInteger }" |
1010 |
dltLine "{ Class:SmallInteger }" |
|
785 | 1011 |
startY "{ Class:SmallInteger }"| |
1012 |
||
1013 |
shown ifFalse:[^ self]. |
|
1014 |
||
1015 |
visStart := self visibleLineOfY:(y + 1). |
|
1016 |
startLn := self visibleLineToAbsoluteLine:visStart. |
|
1017 |
||
1018 |
self paint:bgColor. |
|
1019 |
self fillRectangleX:x y:y width:w height:h. |
|
792 | 1020 |
startLn isNil ifTrue:[ ^ self ]. |
785 | 1021 |
|
792 | 1022 |
sel := nil. |
1023 |
maxX := x + w. |
|
1024 |
maxY := y + h. |
|
1025 |
lnSpace := lineSpacing // 2. |
|
1026 |
visEnd := self visibleLineOfY:maxY. |
|
1027 |
startY := self yOfVisibleLine:visStart. |
|
1028 |
dltLine := startLn - visStart. |
|
1029 |
stopLn := dltLine + visEnd. |
|
1030 |
savClip := clipRect. |
|
785 | 1031 |
|
792 | 1032 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h). |
1033 |
||
1034 |
self hasSelection ifTrue:[ |
|
1035 |
"/ redraw the background for all selected lines in the invalid range |
|
785 | 1036 |
|
792 | 1037 |
self selectionDo:[:lnNr| |
1038 |
(lnNr between:startLn and:stopLn) ifTrue:[ |
|
1039 |
sel isNil ifTrue:[ |
|
1040 |
sel := OrderedCollection new. |
|
785 | 1041 |
self paint:hilightBgColor. |
792 | 1042 |
]. |
1043 |
sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)). |
|
1044 |
y0 := y0 - lnSpace. |
|
1045 |
y1 := y0 + fontHeight min:maxY. |
|
1046 |
y0 := y0 max:y. |
|
1047 |
self fillRectangleX:x y:y0 width:w height:y1 - y0. |
|
785 | 1048 |
] |
792 | 1049 |
] |
785 | 1050 |
]. |
1051 |
||
792 | 1052 |
self redrawLinesX:x y:startY - lnSpace toX:maxX start:startLn stop:stopLn. |
1053 |
||
1054 |
"/ draw selection frames |
|
1055 |
self redrawSelFrameForYs:sel fromX:x toX:maxX. |
|
1056 |
||
1057 |
self clippingRectangle:savClip. |
|
1058 |
||
569 | 1059 |
! ! |
1060 |
||
444 | 1061 |
!SelectionInTreeView methodsFor:'initialization'! |
1062 |
||
685 | 1063 |
create |
1064 |
super create. |
|
695
3e5240577e37
dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents:
685
diff
changeset
|
1065 |
lineMask := lineMask onDevice:device. |
685 | 1066 |
|
1067 |
lineColor notNil ifTrue:[ |
|
695
3e5240577e37
dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents:
685
diff
changeset
|
1068 |
lineColor := lineColor onDevice:device |
685 | 1069 |
] |
1070 |
! |
|
1071 |
||
514 | 1072 |
destroy |
1073 |
"remove dependencies |
|
1074 |
" |
|
811 | 1075 |
rootHolder removeDependent:self. |
1076 |
selectionHolder removeDependent:self. |
|
1077 |
||
1078 |
model notNil ifTrue:[ |
|
1079 |
model stopRunningTasks |
|
514 | 1080 |
]. |
1081 |
super destroy. |
|
1082 |
||
1083 |
! |
|
1084 |
||
785 | 1085 |
fetchDefaultImages |
1086 |
"returns a directory with default keys and images; could be |
|
1087 |
redefined by subclass. |
|
1088 |
" |
|
1089 |
^ nil |
|
1090 |
! |
|
1091 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1092 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1093 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1094 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1095 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1096 |
super fetchDeviceResources. |
478 | 1097 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1098 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1099 |
|
478 | 1100 |
fetchImageResources |
1101 |
"initialize heavily used device resources - to avoid rendering |
|
1102 |
images again and again later; returns maximum extent of the images used. |
|
1103 |
Could be redefined by subclass |
|
471 | 1104 |
" |
785 | 1105 |
|img x y keysAndIcons| |
494 | 1106 |
|
1107 |
imageOpened isNil ifTrue:[ |
|
569 | 1108 |
imageOpened := (self class imageOpened) onDevice:device |
494 | 1109 |
]. |
444 | 1110 |
|
494 | 1111 |
imageClosed isNil ifTrue:[ |
569 | 1112 |
imageClosed := self imageOnDevice:(self class imageClosed) |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
1113 |
]. |
785 | 1114 |
|
1115 |
x := (imageOpened width) max:(imageClosed width). |
|
1116 |
y := (imageOpened height) max:(imageClosed height). |
|
494 | 1117 |
|
1118 |
imageItem isNil ifTrue:[ |
|
569 | 1119 |
imageItem := self imageOnDevice:(self class imageItem) |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
1120 |
]. |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1121 |
|
785 | 1122 |
x := (imageItem width) max:x. |
1123 |
y := (imageItem height) max:y. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1124 |
|
785 | 1125 |
(keysAndIcons := self fetchDefaultImages) notNil ifTrue:[ |
1126 |
keysAndIcons keysAndValuesDo:[:aKey :anIcon| |
|
1127 |
(anIcon isImage and:[aKey notNil]) ifTrue:[ |
|
1128 |
registeredImages at:aKey put:(self imageOnDevice:anIcon copy) |
|
1129 |
] |
|
1130 |
] |
|
1131 |
]. |
|
1132 |
registeredImages keysAndValuesDo:[:k :img| |
|
1133 |
x := (img width) max:x. |
|
1134 |
y := (img height) max:y. |
|
1135 |
]. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1136 |
|
785 | 1137 |
(listOfNodes size > 0 and:[(img := listOfNodes first icon) isImage]) ifTrue:[ |
1138 |
x := (img width) max:x. |
|
1139 |
y := (img height) max:y. |
|
1140 |
]. |
|
1141 |
^ x @ y |
|
444 | 1142 |
! |
1143 |
||
480 | 1144 |
getFontParameters |
546 | 1145 |
"save old computed height derived from images |
1146 |
" |
|
1147 |
|lineHeight| |
|
1148 |
||
1149 |
lineHeight := fontHeight ? 0. |
|
480 | 1150 |
super getFontParameters. |
569 | 1151 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 1152 |
|
546 | 1153 |
lineHeight > fontHeight ifTrue:[ |
1154 |
fontHeight := lineHeight |
|
1155 |
]. |
|
685 | 1156 |
fontHeight odd ifTrue:[ |
1157 |
fontHeight := fontHeight + 1 |
|
1158 |
] |
|
480 | 1159 |
! |
1160 |
||
444 | 1161 |
initialize |
471 | 1162 |
"setup instance attributes |
1163 |
" |
|
444 | 1164 |
super initialize. |
835 | 1165 |
supportsExpandAll := true. |
569 | 1166 |
self bitGravity:#NorthWest. |
773 | 1167 |
showRoot := showDirectoryIndicatorForRoot := showLines := computeResources := true. |
1168 |
showDirectoryIndicator := discardMotionEvents := false. |
|
685 | 1169 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
773 | 1170 |
registeredImages := IdentityDictionary new. |
659 | 1171 |
textInset := 4. |
494 | 1172 |
imageInset := 0. "/ set during indication enabled |
1173 |
imageWidth := 8. "/ default: will change during startup |
|
514 | 1174 |
self model:nil. "/ creates a default model. |
478 | 1175 |
! |
1176 |
||
569 | 1177 |
realize |
1178 |
super realize. |
|
1179 |
self refetchDeviceResources. |
|
1180 |
! |
|
1181 |
||
811 | 1182 |
recomputeDirectoryIndicator |
1183 |
"setup attributes used by directory indicator |
|
1184 |
" |
|
1185 |
|x w| |
|
1186 |
||
1187 |
imageInset := 0. |
|
1188 |
||
1189 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
1190 |
^ self |
|
1191 |
]. |
|
1192 |
openIndicator isNil ifTrue:[ |
|
1193 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
1194 |
]. |
|
1195 |
closeIndicator isNil ifTrue:[ |
|
1196 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
1197 |
]. |
|
1198 |
x := (openIndicator width) max:(closeIndicator width). |
|
1199 |
x := x // 2. |
|
1200 |
w := imageWidth // 2. |
|
1201 |
||
1202 |
(x := x + self class minImageInset) > w ifTrue:[ |
|
1203 |
imageInset := x - w. |
|
1204 |
]. |
|
1205 |
||
1206 |
||
1207 |
||
1208 |
! |
|
1209 |
||
478 | 1210 |
refetchDeviceResources |
1211 |
"reinitialize heavily used device resources - to avoid rendering |
|
1212 |
images again and again later |
|
1213 |
" |
|
551 | 1214 |
|extent| |
478 | 1215 |
|
569 | 1216 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 1217 |
computeResources := false. |
1218 |
extent := self fetchImageResources. |
|
494 | 1219 |
|
546 | 1220 |
extent y >= fontHeight ifTrue:[ |
1221 |
fontHeight := 1 + extent y. |
|
494 | 1222 |
]. |
685 | 1223 |
fontHeight odd ifTrue:[ |
1224 |
fontHeight := fontHeight + 1 |
|
1225 |
]. |
|
1226 |
||
546 | 1227 |
imageWidth := extent x. |
1228 |
self recomputeDirectoryIndicator. |
|
569 | 1229 |
self computeNumberOfLinesShown. |
546 | 1230 |
] |
444 | 1231 |
! ! |
1232 |
||
483 | 1233 |
!SelectionInTreeView methodsFor:'model'! |
444 | 1234 |
|
1235 |
getListFromModel |
|
1236 |
"if I have a model, get my list from it using the listMessage. |
|
1237 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1238 |
" |
|
483 | 1239 |
super list:(self listFromModel) keepSelection:true |
1240 |
! |
|
444 | 1241 |
|
483 | 1242 |
listFromModel |
1243 |
"get list from model and return the new list. |
|
1244 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1245 |
" |
|
838 | 1246 |
|msg list |
1247 |
runs "{ Class: SmallInteger }" |
|
1248 |
idx "{ Class: SmallInteger }" |
|
1249 |
| |
|
468 | 1250 |
widthOfWidestLine := nil. |
444 | 1251 |
|
514 | 1252 |
(msg := listMsg ? aspectMsg) notNil ifTrue:[ |
1253 |
listOfNodes := model perform:msg. |
|
838 | 1254 |
|
1255 |
(runs := listOfNodes size) ~~ 0 ifTrue:[ |
|
546 | 1256 |
self refetchDeviceResources. |
838 | 1257 |
idx := 1. |
1258 |
list := OrderedCollection new:runs. |
|
1259 |
||
1260 |
runs timesRepeat:[ |
|
1261 |
list add:(listOfNodes at:idx) name. |
|
1262 |
idx := idx + 1. |
|
1263 |
]. |
|
1264 |
^ list |
|
483 | 1265 |
] |
1266 |
]. |
|
1267 |
listOfNodes := #(). |
|
1268 |
^ #() |
|
838 | 1269 |
|
494 | 1270 |
! |
1271 |
||
1272 |
model:aModel |
|
514 | 1273 |
"check whether model is nil; than a default model is created |
1274 |
" |
|
1275 |
|model| |
|
1276 |
||
811 | 1277 |
model notNil ifTrue:[ |
1278 |
model stopRunningTasks |
|
1279 |
]. |
|
1280 |
||
514 | 1281 |
model := aModel ? (SelectionInTree new). |
1282 |
model showRoot:showRoot. |
|
1283 |
super model:model. |
|
811 | 1284 |
|
514 | 1285 |
! |
1286 |
||
1287 |
rootFromModel |
|
1288 |
"update hierarchical list from root model; 'rootHolder' |
|
1289 |
" |
|
1290 |
|root| |
|
1291 |
||
585 | 1292 |
root := rootHolder root. |
514 | 1293 |
|
1294 |
self root == root ifFalse:[ |
|
1295 |
self selection:nil. |
|
1296 |
self root:root. |
|
585 | 1297 |
]. |
514 | 1298 |
! |
1299 |
||
1300 |
selectionFromModel |
|
1301 |
"set the selection derived from the selectionHolder |
|
1302 |
" |
|
545 | 1303 |
|coll value sz| |
514 | 1304 |
|
1305 |
(value := selectionHolder value) isNil ifTrue:[ |
|
1306 |
^ self deselect |
|
507 | 1307 |
]. |
514 | 1308 |
|
1309 |
multipleSelectOk ifFalse:[ |
|
1310 |
self selectNode:value |
|
1311 |
] ifTrue:[ |
|
545 | 1312 |
(sz := value size) ~~ 0 ifTrue:[ |
1313 |
coll := OrderedCollection new:sz. |
|
514 | 1314 |
|
1315 |
value do:[:aNode||i| |
|
1316 |
(i := self indexOfNode:aNode) notNil ifTrue:[ |
|
1317 |
coll add:i |
|
1318 |
] |
|
1319 |
] |
|
1320 |
]. |
|
1321 |
coll size == 0 ifTrue:[self deselect] |
|
1322 |
ifFalse:[self selection:coll] |
|
1323 |
] |
|
1324 |
! |
|
1325 |
||
1326 |
selectionToModel |
|
1327 |
"write selection to selection holder |
|
1328 |
" |
|
1329 |
|newSel oldSel| |
|
1330 |
||
1331 |
oldSel := selectionHolder value. |
|
1332 |
||
1333 |
multipleSelectOk ifFalse:[ |
|
1334 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
1335 |
selectionHolder value:newSel |
|
1336 |
] |
|
1337 |
] ifTrue:[ |
|
1338 |
selection size == 0 ifTrue:[ |
|
1339 |
oldSel notNil ifTrue:[ |
|
1340 |
selectionHolder value:nil |
|
1341 |
] |
|
1342 |
] ifFalse:[ |
|
1343 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
1344 |
||
1345 |
newSel size ~~ oldSel size ifTrue:[ |
|
1346 |
selectionHolder value:newSel. |
|
1347 |
] ifFalse:[ |
|
1348 |
newSel do:[:aNode| |
|
785 | 1349 |
(oldSel includesIdentical:aNode) ifFalse:[ |
514 | 1350 |
^ selectionHolder value:newSel |
1351 |
] |
|
1352 |
] |
|
1353 |
] |
|
1354 |
] |
|
1355 |
] |
|
444 | 1356 |
! ! |
1357 |
||
490 | 1358 |
!SelectionInTreeView methodsFor:'private'! |
1359 |
||
1360 |
list:aList keepSelection:keepSelection |
|
585 | 1361 |
"setup new list; keep selection dependent on the boolean state |
1362 |
keepSelection |
|
1363 |
" |
|
838 | 1364 |
|list time| |
490 | 1365 |
|
1366 |
list := aList. |
|
1367 |
||
1368 |
list size == 0 ifTrue:[ |
|
1369 |
listOfNodes := #() |
|
1370 |
] ifFalse:[ |
|
1371 |
(list first respondsTo:#hasChildren) ifTrue:[ |
|
1372 |
listOfNodes := aList. |
|
546 | 1373 |
self refetchDeviceResources. |
490 | 1374 |
list := listOfNodes collect:[:aNode| aNode name ]. |
1375 |
] |
|
1376 |
]. |
|
1377 |
super list:list keepSelection:keepSelection |
|
546 | 1378 |
! |
1379 |
||
569 | 1380 |
nodeAt:anIndex expand:doExpand |
585 | 1381 |
"expand or collapse the node at an index, anIndex dependent on the boolean state |
1382 |
of doExpand |
|
1383 |
" |
|
569 | 1384 |
|node| |
1385 |
||
1386 |
node := listOfNodes at:anIndex. |
|
1387 |
||
811 | 1388 |
node hasChildren ifFalse:[ "/ no children exists |
1389 |
^ self |
|
1390 |
]. |
|
1391 |
node isExpandable ifTrue:[ |
|
835 | 1392 |
doExpand ifFalse:[^ self]. "/ already expanded |
811 | 1393 |
node expand |
1394 |
] ifFalse:[ |
|
835 | 1395 |
doExpand ifTrue:[^ self]. "/ already collapsed |
811 | 1396 |
node collapse |
1397 |
]. |
|
1398 |
||
1399 |
node children isEmpty ifTrue:[ |
|
1400 |
"/ no children; redraw selected line (image might change) |
|
1401 |
self redrawLine:anIndex. |
|
1402 |
] ifFalse:[ |
|
1403 |
"/ with children; update list and redraw to end. |
|
838 | 1404 |
self recomputeListFromNodeAt:anIndex |
811 | 1405 |
] |
1406 |
||
835 | 1407 |
|
838 | 1408 |
! |
1409 |
||
1410 |
recomputeListFromNodeAt:anIndex |
|
1411 |
||
1412 |
model removeDependent:self. |
|
1413 |
model recomputeList. |
|
1414 |
model addDependent:self. |
|
1415 |
||
1416 |
list := self listFromModel. |
|
1417 |
self redrawFromLine:anIndex. |
|
1418 |
self contentsChanged. |
|
811 | 1419 |
! ! |
1420 |
||
1421 |
!SelectionInTreeView methodsFor:'private - drag and drop'! |
|
569 | 1422 |
|
811 | 1423 |
collectionOfDragObjects |
1424 |
"returns collection of dragable objects assigned to selection |
|
1425 |
Here, by default, a collection of text-dragObjects is generated; |
|
1426 |
however, if a dragObjectConverter is defined, that one gets a chance |
|
1427 |
to convert as appropriate." |
|
1428 |
||
1429 |
|collection converted selection dLbl dObj node| |
|
1430 |
||
1431 |
selection := self selectionAsCollection. |
|
1432 |
||
1433 |
collection := selection collect:[:nr| |
|
1434 |
node := listOfNodes at:nr. |
|
1435 |
dObj := self dragObjectForNode:node. |
|
1436 |
dObj theObject:(node contents). |
|
1437 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(list at:nr). |
|
1438 |
dObj displayObject:dLbl. |
|
1439 |
dObj |
|
1440 |
]. |
|
1441 |
||
1442 |
dragObjectConverter notNil ifTrue:[ |
|
1443 |
converted := OrderedCollection new. |
|
1444 |
collection keysAndValuesDo:[:nr :obj | |
|
1445 |
(dObj := dragObjectConverter value:obj) notNil ifTrue:[ |
|
1446 |
dLbl := LabelAndIcon icon:(self figureFor:(listOfNodes at:nr)) string:(list at:nr). |
|
1447 |
converted displayObject:dLbl. |
|
1448 |
converted add:dObj |
|
1449 |
] |
|
1450 |
]. |
|
1451 |
collection := converted |
|
1452 |
]. |
|
1453 |
^ collection. |
|
1454 |
||
1455 |
||
569 | 1456 |
|
1457 |
! |
|
1458 |
||
811 | 1459 |
dragObjectForNode:aNode |
1460 |
"returns the dragable object for a node; could be redefined in subclass |
|
546 | 1461 |
" |
811 | 1462 |
^ DropObject new:aNode. |
546 | 1463 |
|
811 | 1464 |
|
1465 |
! |
|
546 | 1466 |
|
811 | 1467 |
startDragX:x y:y |
1468 |
"start drag |
|
1469 |
" |
|
1470 |
dragIsActive := true. |
|
546 | 1471 |
|
811 | 1472 |
DragAndDropManager startDrag:(self collectionOfDragObjects) |
1473 |
from:self |
|
1474 |
atEnd:endDragAction |
|
546 | 1475 |
|
1476 |
||
490 | 1477 |
! ! |
1478 |
||
468 | 1479 |
!SelectionInTreeView methodsFor:'private queries'! |
1480 |
||
1481 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
1482 |
"return the length (in characters) of the longest line in a line-range |
|
1483 |
" |
|
1484 |
|max| |
|
1485 |
||
1486 |
max := self widthOfContents:firstLine and:lastLine. |
|
1487 |
^ (max // fontWidth) + 1 |
|
1488 |
! |
|
1489 |
||
1490 |
widthOfContents |
|
1491 |
"return the width of the contents in pixels |
|
1492 |
- used for scrollbar interface" |
|
1493 |
||
1494 |
list isNil ifTrue:[^ 0]. |
|
1495 |
||
1496 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
1497 |
widthOfWidestLine := self widthOfContents:1 and:(self size). |
|
1498 |
]. |
|
1499 |
^ widthOfWidestLine + (leftMargin * 2) |
|
1500 |
||
1501 |
! |
|
1502 |
||
1503 |
widthOfContents:firstLine and:lastLine |
|
1504 |
"return the length (in pixels) of the longest line in a line-range |
|
1505 |
" |
|
838 | 1506 |
|parent name item tmpValue |
1507 |
max "{ Class: SmallInteger }" |
|
1508 |
index "{ Class: SmallInteger }" |
|
1509 |
runs "{ Class: SmallInteger }" |
|
1510 |
level "{ Class: SmallInteger }" |
|
1511 |
xOfStr "{ Class: SmallInteger }" |
|
1512 |
dltX "{ Class: SmallInteger }" |
|
1513 |
width "{ Class: SmallInteger }" |
|
1514 |
newSz "{ Class: SmallInteger }" |
|
1515 |
maxSz "{ Class: SmallInteger }"| |
|
468 | 1516 |
|
838 | 1517 |
( (listOfNodes size == 0) |
1518 |
or:[(runs := lastLine min:(listOfNodes size)) < firstLine] |
|
1519 |
) ifTrue:[ |
|
1520 |
^ 0 |
|
1521 |
]. |
|
468 | 1522 |
|
838 | 1523 |
level := 1. |
1524 |
xOfStr := self xOfStringLevel:level. |
|
1525 |
max := xOfStr. |
|
1526 |
dltX := imageInset + imageWidth. |
|
1527 |
width := '1' widthOn:self. |
|
1528 |
parent := 4711. "/ to force a computation |
|
1529 |
index := firstLine. |
|
1530 |
runs := runs - index + 1. |
|
468 | 1531 |
|
838 | 1532 |
runs timesRepeat:[ |
1533 |
item := listOfNodes at:index. |
|
1534 |
name := item name. |
|
1535 |
index := index + 1. |
|
468 | 1536 |
|
838 | 1537 |
(newSz := name size) ~~ 0 ifTrue:[ |
1538 |
item parent ~~ parent ifTrue:[ |
|
1539 |
parent := item parent. |
|
1540 |
tmpValue := item level. |
|
1541 |
xOfStr := xOfStr + ((tmpValue - level) * dltX). |
|
1542 |
level := tmpValue. |
|
1543 |
maxSz := 0. |
|
1544 |
]. |
|
1545 |
maxSz < newSz ifTrue:[ |
|
1546 |
maxSz := newSz. |
|
1547 |
max := max max:(xOfStr + (maxSz * width)). |
|
1548 |
] |
|
468 | 1549 |
] |
1550 |
]. |
|
838 | 1551 |
^ max + leftOffset. |
1552 |
||
1553 |
||
468 | 1554 |
! |
1555 |
||
1556 |
withoutRedrawAt:anIndex put:aString |
|
1557 |
"change a line without redisplay" |
|
1558 |
||
1559 |
|width| |
|
1560 |
||
1561 |
width := widthOfWidestLine. |
|
1562 |
widthOfWidestLine := nil. |
|
1563 |
||
1564 |
super withoutRedrawAt:anIndex put:aString. |
|
1565 |
||
1566 |
(widthOfWidestLine := width) notNil ifTrue:[ |
|
1567 |
width := self widthOfContents:anIndex and:anIndex. |
|
838 | 1568 |
widthOfWidestLine := widthOfWidestLine max:width. |
468 | 1569 |
]. |
1570 |
||
1571 |
||
1572 |
! ! |
|
1573 |
||
483 | 1574 |
!SelectionInTreeView methodsFor:'queries'! |
1575 |
||
1576 |
figureFor:aNode |
|
1577 |
"access figure for a node |
|
1578 |
" |
|
785 | 1579 |
|icon img| |
1580 |
||
1581 |
(icon := aNode icon) notNil ifTrue:[ |
|
1582 |
img := registeredImages at:icon ifAbsent:nil. |
|
773 | 1583 |
|
785 | 1584 |
img notNil ifTrue:[ |
1585 |
^ img |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1586 |
]. |
785 | 1587 |
icon isImage ifTrue:[ |
1588 |
img := self imageOnDevice:(icon copy). |
|
1589 |
registeredImages at:icon put:img. |
|
1590 |
^ img |
|
1591 |
] |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1592 |
]. |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1593 |
|
785 | 1594 |
"/ fallback solution |
1595 |
||
483 | 1596 |
aNode hasChildren ifTrue:[ |
785 | 1597 |
^ aNode isExpandable ifTrue:[imageClosed] ifFalse:[imageOpened] |
483 | 1598 |
]. |
1599 |
^ imageItem |
|
1600 |
! |
|
1601 |
||
1602 |
indexOfNode:aNode |
|
1603 |
"returns index of a node |
|
1604 |
" |
|
785 | 1605 |
^ listOfNodes identityIndexOf:aNode |
483 | 1606 |
! |
1607 |
||
494 | 1608 |
xOfFigureLevel:aLevel |
1609 |
"origin x where to draw the icon |
|
1610 |
" |
|
785 | 1611 |
|l "{ Class:SmallInteger }"| |
494 | 1612 |
|
785 | 1613 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
494 | 1614 |
|
659 | 1615 |
showDirectoryIndicator ifFalse:[ |
1616 |
l := l - 1 |
|
1617 |
] ifTrue:[ |
|
1618 |
showDirectoryIndicatorForRoot ifFalse:[ |
|
1619 |
l := l - 1 |
|
1620 |
] |
|
1621 |
]. |
|
494 | 1622 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
1623 |
||
1624 |
! |
|
1625 |
||
483 | 1626 |
xOfFigureNode:aNode |
1627 |
"origin x where to draw the icon |
|
1628 |
" |
|
494 | 1629 |
^ self xOfFigureLevel:(aNode level) |
1630 |
! |
|
490 | 1631 |
|
494 | 1632 |
xOfStringLevel:aLevel |
1633 |
"origin x where to draw the text( label ) |
|
1634 |
" |
|
1635 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 1636 |
|
1637 |
! |
|
1638 |
||
1639 |
xOfStringNode:aNode |
|
1640 |
"origin x where to draw the text( label ) |
|
1641 |
" |
|
494 | 1642 |
^ self xOfStringLevel:(aNode level) |
483 | 1643 |
|
1644 |
! ! |
|
1645 |
||
444 | 1646 |
!SelectionInTreeView methodsFor:'selection'! |
1647 |
||
494 | 1648 |
selectFromListOfNames:aListOfNames |
1649 |
"set selection from a list of names |
|
1650 |
" |
|
785 | 1651 |
|node rdwNd chgd| |
494 | 1652 |
|
1653 |
aListOfNames size < 1 ifTrue:[ |
|
1654 |
^ self selection:nil |
|
1655 |
]. |
|
1656 |
||
1657 |
node := model root. |
|
785 | 1658 |
chgd := false. |
494 | 1659 |
|
1660 |
aListOfNames do:[:el||next| |
|
1661 |
next := node detectChild:[:e|e name = el]. |
|
1662 |
||
1663 |
next notNil ifTrue:[ |
|
1664 |
node hidden ifTrue:[ |
|
785 | 1665 |
chgd := true. |
494 | 1666 |
node expand |
1667 |
]. |
|
1668 |
node := next |
|
1669 |
] |
|
1670 |
]. |
|
785 | 1671 |
chgd ifTrue:[ |
585 | 1672 |
model recomputeList. |
494 | 1673 |
]. |
1674 |
self selectNode:node. |
|
1675 |
||
1676 |
! |
|
1677 |
||
468 | 1678 |
selectNode:aNode |
1679 |
"change selection to a node |
|
1680 |
" |
|
483 | 1681 |
self selection:(self indexOfNode:aNode) |
468 | 1682 |
|
1683 |
||
1684 |
! |
|
1685 |
||
456 | 1686 |
selectedIndex |
1687 |
"get single selected index or 0 |
|
1688 |
" |
|
483 | 1689 |
selection size == 1 ifTrue:[^ selection first]. |
1690 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 1691 |
^ 0 |
444 | 1692 |
! |
1693 |
||
1694 |
selectedNode |
|
1695 |
"get the single selected node or nil |
|
1696 |
" |
|
456 | 1697 |
|idx| |
1698 |
||
1699 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
1700 |
^ listOfNodes at:idx |
|
444 | 1701 |
]. |
1702 |
^ nil |
|
514 | 1703 |
! |
1704 |
||
1705 |
selectionChangedFrom:oldSelection |
|
1706 |
"update selectionHolder if not nil |
|
1707 |
" |
|
1708 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1709 |
"/ first change my selectionHolders value ... |
514 | 1710 |
selectionHolder notNil ifTrue:[ |
1711 |
self selectionToModel. |
|
1712 |
]. |
|
1713 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1714 |
"/ ... then make notifications. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1715 |
super selectionChangedFrom:oldSelection. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1716 |
|
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1717 |
|
444 | 1718 |
! ! |
1719 |
||
507 | 1720 |
!SelectionInTreeView methodsFor:'selection-actions'! |
1721 |
||
1722 |
selectedNodeAdd:something |
|
1723 |
"add a node or collection of nodes after selected node |
|
1724 |
" |
|
1725 |
|node| |
|
1726 |
||
1727 |
something notNil ifTrue:[ |
|
1728 |
(node := self selectedNode) notNil ifTrue:[ |
|
1729 |
node parent notNil ifTrue:[ |
|
1730 |
node isCollapsable ifTrue:[ |
|
1731 |
model add:something beforeIndex:1 below:node |
|
1732 |
] ifFalse:[ |
|
1733 |
model add:something after:node |
|
1734 |
] |
|
1735 |
] ifFalse:[ |
|
1736 |
model add:something beforeIndex:1 below:(self root) |
|
1737 |
] |
|
1738 |
] |
|
1739 |
] |
|
1740 |
||
1741 |
! |
|
1742 |
||
1743 |
selectedNodeBecomeChildOfNext |
|
1744 |
"become node a child of followd node |
|
1745 |
" |
|
1746 |
|idx node cprt nprt| |
|
1747 |
||
1748 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
1749 |
idx := cprt indexOfChild:node. |
|
1750 |
||
1751 |
idx == cprt children size ifFalse:[ |
|
1752 |
nprt := cprt childAt:(idx + 1). |
|
1753 |
||
1754 |
nprt notNil ifTrue:[ |
|
1755 |
model removeDependent:self. |
|
1756 |
model removeSelection. |
|
1757 |
selection := nil. |
|
1758 |
model collapse:nprt. |
|
1759 |
model add:node beforeIndex:1 below:nprt. |
|
1760 |
model addDependent:self. |
|
1761 |
model expand:nprt. |
|
1762 |
||
1763 |
self selectNode:node. |
|
1764 |
] |
|
1765 |
] |
|
1766 |
] |
|
1767 |
! |
|
1768 |
||
1769 |
selectedNodeBecomeSisterOfParent |
|
1770 |
"become node a sister of its current parent |
|
1771 |
" |
|
1772 |
|node cprt nprt| |
|
1773 |
||
1774 |
( (node := self selectedNode) isNil |
|
1775 |
or:[(cprt := node parent) isNil |
|
1776 |
or:[(nprt := cprt parent) isNil]] |
|
1777 |
) ifFalse:[ |
|
1778 |
model removeDependent:self. |
|
1779 |
model removeSelection. |
|
1780 |
selection := nil. |
|
1781 |
model addDependent:self. |
|
1782 |
||
1783 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
|
1784 |
self selectNode:node. |
|
1785 |
] |
|
1786 |
||
1787 |
! |
|
1788 |
||
1789 |
selectedNodeChangeSequenceOrder:anOffset |
|
1790 |
"move child 'anOffset' forward or backward in list of children |
|
1791 |
" |
|
1792 |
|idx node size parent| |
|
1793 |
||
1794 |
( (node := self selectedNode) notNil |
|
1795 |
and:[(parent := node parent) notNil |
|
1796 |
and:[(size := parent children size) > 1]] |
|
1797 |
) ifTrue:[ |
|
1798 |
idx := parent indexOfChild:node. |
|
1799 |
||
1800 |
model removeDependent:self. |
|
1801 |
model removeSelection. |
|
1802 |
selection := nil. |
|
1803 |
model addDependent:self. |
|
1804 |
||
1805 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
1806 |
idx := size |
|
1807 |
] ifFalse:[ |
|
1808 |
idx > size ifTrue:[idx := 1] |
|
1809 |
]. |
|
1810 |
model add:node beforeIndex:idx below:parent. |
|
1811 |
self selectNode:node. |
|
1812 |
] |
|
1813 |
! |
|
1814 |
||
1815 |
selectedNodeExpand:doExpand |
|
1816 |
"collapse or expand selected node |
|
1817 |
" |
|
811 | 1818 |
|index| |
507 | 1819 |
|
1820 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
|
811 | 1821 |
self nodeAt:index expand:doExpand |
507 | 1822 |
]. |
785 | 1823 |
|
507 | 1824 |
! |
1825 |
||
1826 |
selectedNodesRemove |
|
1827 |
"remove selected nodes |
|
1828 |
" |
|
1829 |
model removeSelection. |
|
1830 |
self selection:nil. |
|
1831 |
||
1832 |
! ! |
|
1833 |
||
444 | 1834 |
!SelectionInTreeView class methodsFor:'documentation'! |
1835 |
||
1836 |
version |
|
838 | 1837 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.53 1998-04-04 08:45:17 ca Exp $' |
444 | 1838 |
! ! |