author | ca |
Fri, 02 Jan 1998 17:07:36 +0100 | |
changeset 639 | 663a913ec30b |
parent 623 | 4de870640523 |
child 659 | 16bb1d26f658 |
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 |
|
517 | 15 |
instanceVariableNames:'validateDoubleClickBlock selectionHolder rootHolder imageWidth |
569 | 16 |
showLines listOfNodes imageInset textInset labelOffsetY |
17 |
openIndicator computeResources closeIndicator showRoot |
|
18 |
extentOpenIndicator extentCloseIndicator showDirectoryIndicator |
|
639 | 19 |
indicatorExtentDiv2 imageOpened imageClosed imageItem |
20 |
discardMotionEvents' |
|
490 | 21 |
classVariableNames:'ImageOpened ImageClosed ImageItem OpenIndicator CloseIndicator' |
444 | 22 |
poolDictionaries:'' |
23 |
category:'Views-Text' |
|
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]. |
90 |
||
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 |
||
126 |
!SelectionInTreeView class methodsFor:'default images'! |
|
127 |
||
128 |
closeIndicator |
|
589 | 129 |
<resource: #fileImage> |
130 |
||
490 | 131 |
CloseIndicator isNil ifTrue:[ |
132 |
CloseIndicator := Image fromFile:('xpmBitmaps/plus.xpm'). |
|
133 |
]. |
|
134 |
^ CloseIndicator |
|
135 |
" |
|
136 |
CloseIndicator := nil |
|
137 |
" |
|
589 | 138 |
|
139 |
"Modified: / 29.10.1997 / 03:36:00 / cg" |
|
471 | 140 |
! |
141 |
||
444 | 142 |
imageClosed |
589 | 143 |
<resource: #fileImage> |
144 |
||
444 | 145 |
ImageClosed isNil ifTrue:[ |
146 |
ImageClosed := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm'). |
|
147 |
]. |
|
148 |
^ ImageClosed |
|
149 |
" |
|
150 |
ImageClosed := nil |
|
151 |
" |
|
152 |
||
589 | 153 |
"Modified: / 29.10.1997 / 03:36:05 / cg" |
444 | 154 |
! |
155 |
||
156 |
imageItem |
|
589 | 157 |
<resource: #fileImage> |
158 |
||
444 | 159 |
ImageItem isNil ifTrue:[ |
160 |
ImageItem := Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm') |
|
161 |
||
162 |
]. |
|
163 |
^ ImageItem |
|
164 |
" |
|
165 |
ImageItem := nil |
|
166 |
" |
|
167 |
||
589 | 168 |
"Modified: / 29.10.1997 / 03:36:10 / cg" |
444 | 169 |
! |
170 |
||
171 |
imageOpened |
|
589 | 172 |
<resource: #fileImage> |
173 |
||
444 | 174 |
ImageOpened isNil ifTrue:[ |
175 |
ImageOpened := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm'). |
|
176 |
||
177 |
]. |
|
178 |
^ ImageOpened |
|
179 |
" |
|
180 |
ImageOpened := nil |
|
181 |
" |
|
589 | 182 |
|
183 |
"Modified: / 29.10.1997 / 03:36:15 / cg" |
|
490 | 184 |
! |
185 |
||
186 |
openIndicator |
|
589 | 187 |
<resource: #fileImage> |
188 |
||
490 | 189 |
OpenIndicator isNil ifTrue:[ |
190 |
OpenIndicator := Image fromFile:('xpmBitmaps/minus.xpm'). |
|
191 |
]. |
|
192 |
^ OpenIndicator |
|
193 |
" |
|
194 |
OpenIndicator := nil |
|
195 |
" |
|
196 |
||
589 | 197 |
"Modified: / 29.10.1997 / 03:36:21 / cg" |
444 | 198 |
! ! |
199 |
||
200 |
!SelectionInTreeView methodsFor:'accessing'! |
|
201 |
||
490 | 202 |
nodeAtIndex:anIndex |
203 |
"returns node at an index or nil |
|
204 |
" |
|
205 |
(anIndex notNil and:[anIndex ~~ 0 and:[anIndex <= listOfNodes size]]) ifTrue:[ |
|
206 |
^ listOfNodes at:anIndex |
|
207 |
]. |
|
208 |
^ nil |
|
209 |
! |
|
210 |
||
507 | 211 |
root |
212 |
"gets the root of the model; the first item into list. |
|
213 |
" |
|
214 |
^ self nodeAtIndex:1 |
|
215 |
! |
|
216 |
||
217 |
root:aRoot |
|
218 |
"sets the root of the model; the first item into list. |
|
219 |
" |
|
514 | 220 |
aRoot notNil ifTrue:[aRoot expand]. |
507 | 221 |
model root:aRoot |
222 |
! |
|
223 |
||
490 | 224 |
textInset |
225 |
"get the left inset of the text label |
|
226 |
" |
|
227 |
^ textInset |
|
228 |
! |
|
229 |
||
230 |
textInset:anInset |
|
231 |
"set the left inset of the text label |
|
232 |
" |
|
233 |
anInset ~~ textInset ifTrue:[ |
|
234 |
anInset >= 0 ifTrue:[ |
|
235 |
textInset := anInset. |
|
236 |
self invalidate |
|
237 |
] ifFalse:[ |
|
238 |
self error |
|
239 |
] |
|
240 |
]. |
|
241 |
! ! |
|
242 |
||
243 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
|
244 |
||
245 |
showDirectoryIndicator |
|
246 |
"returns true if directories has an open/closed indicator |
|
247 |
" |
|
248 |
^ showDirectoryIndicator |
|
249 |
! |
|
250 |
||
251 |
showDirectoryIndicator:aState |
|
252 |
"set or clear open/closed indicator for directories |
|
253 |
" |
|
254 |
"show or hide lines |
|
255 |
" |
|
256 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
494 | 257 |
showDirectoryIndicator := aState. |
546 | 258 |
self recomputeDirectoryIndicator. |
490 | 259 |
self invalidate |
260 |
]. |
|
261 |
! |
|
262 |
||
263 |
showLines |
|
264 |
"returns true if lines are shown |
|
265 |
" |
|
266 |
^ showLines |
|
267 |
! |
|
268 |
||
269 |
showLines:aState |
|
270 |
"show or hide lines |
|
271 |
" |
|
272 |
aState ~~ showLines ifTrue:[ |
|
273 |
showLines := aState. |
|
274 |
self invalidate |
|
275 |
]. |
|
494 | 276 |
! |
277 |
||
278 |
showRoot |
|
279 |
"list with or without root |
|
280 |
" |
|
281 |
^ showRoot |
|
282 |
! |
|
283 |
||
284 |
showRoot:aState |
|
285 |
"list with or without root |
|
286 |
" |
|
287 |
showRoot ~~ aState ifTrue:[ |
|
514 | 288 |
model showRoot:(showRoot := aState) |
289 |
]. |
|
517 | 290 |
! |
291 |
||
292 |
validateDoubleClickBlock |
|
293 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
294 |
on a node will be performed. In case of returning false, the doubleClick will |
|
295 |
not be handled. |
|
296 |
" |
|
297 |
^ validateDoubleClickBlock |
|
298 |
||
299 |
||
300 |
! |
|
301 |
||
302 |
validateDoubleClickBlock:aOneArgBlock |
|
303 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
304 |
on a node will be performed. In case of returning false, the doubleClick will |
|
305 |
not be handled. |
|
306 |
" |
|
307 |
validateDoubleClickBlock := aOneArgBlock |
|
308 |
||
309 |
||
514 | 310 |
! ! |
311 |
||
312 |
!SelectionInTreeView methodsFor:'accessing-channels'! |
|
313 |
||
314 |
rootHolder |
|
315 |
"get the holder which keeps the hierarchical list entry or nil |
|
316 |
" |
|
317 |
^ rootHolder |
|
318 |
! |
|
319 |
||
320 |
rootHolder:aValueHolder |
|
321 |
"set the holder which keeps the hierarchical list entry or nil |
|
322 |
" |
|
323 |
rootHolder notNil ifTrue:[ |
|
324 |
rootHolder removeDependent:self |
|
325 |
]. |
|
326 |
(rootHolder := aValueHolder) notNil ifTrue:[ |
|
327 |
rootHolder addDependent:self. |
|
328 |
self rootFromModel. |
|
494 | 329 |
]. |
514 | 330 |
! |
331 |
||
332 |
selectionHolder |
|
333 |
"get the holder which keeps a list of selected items or nil |
|
334 |
" |
|
335 |
^ selectionHolder |
|
336 |
||
337 |
! |
|
338 |
||
339 |
selectionHolder:aHolder |
|
340 |
"set the holder which keeps a list of selected items or nil |
|
341 |
" |
|
342 |
selectionHolder notNil ifTrue:[ |
|
343 |
selectionHolder removeDependent:self |
|
344 |
]. |
|
345 |
||
346 |
(selectionHolder := aHolder) notNil ifTrue:[ |
|
347 |
selectionHolder addDependent:self. |
|
348 |
self selectionFromModel |
|
349 |
]. |
|
350 |
||
490 | 351 |
! ! |
352 |
||
353 |
!SelectionInTreeView methodsFor:'accessing-images'! |
|
354 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
355 |
imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
356 |
"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
|
357 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
358 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
359 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
360 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
361 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
362 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
363 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
364 |
"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
|
365 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
366 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
367 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
368 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
369 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
370 |
|
569 | 371 |
imageOnDevice:anImage |
372 |
"associate iamge to device and clear pixel mask (in case of realized); |
|
373 |
returns the new image. |
|
374 |
" |
|
375 |
|img| |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
376 |
|
569 | 377 |
img := anImage onDevice:device. |
378 |
||
379 |
realized ifTrue:[ |
|
380 |
img := img clearMaskedPixels |
|
381 |
]. |
|
382 |
^ img |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
383 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
384 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
385 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
386 |
"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
|
387 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
388 |
^ imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
389 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
390 |
"Created: 3.7.1997 / 12:34:28 / cg" |
471 | 391 |
! ! |
392 |
||
514 | 393 |
!SelectionInTreeView methodsFor:'change & update'! |
394 |
||
395 |
update:something with:aParameter from:aModel |
|
396 |
"one of my models changed its value |
|
397 |
" |
|
398 |
aModel == rootHolder ifTrue:[ |
|
399 |
^ self rootFromModel |
|
400 |
]. |
|
401 |
aModel == selectionHolder ifTrue:[ |
|
402 |
^ self selectionFromModel |
|
403 |
]. |
|
404 |
||
585 | 405 |
aModel == aModel ifTrue:[ |
406 |
something == #list ifTrue:[ |
|
407 |
^ self getListFromModel |
|
408 |
] |
|
409 |
]. |
|
514 | 410 |
^ super update:something with:aParameter from:aModel. |
411 |
||
412 |
||
413 |
||
414 |
! ! |
|
415 |
||
444 | 416 |
!SelectionInTreeView methodsFor:'drawing'! |
417 |
||
481 | 418 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
419 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 420 |
|
421 |
! |
|
422 |
||
423 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 424 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 425 |
|
426 |
! |
|
427 |
||
428 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 429 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 430 |
|
431 |
! |
|
432 |
||
433 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 434 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 435 |
|
436 |
! |
|
437 |
||
438 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 439 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
440 |
||
444 | 441 |
! |
442 |
||
443 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 444 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 445 |
|
446 |
! ! |
|
447 |
||
448 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
449 |
||
481 | 450 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
451 |
||
494 | 452 |
|size end index yBot yTop yCtr level figWidthDiv2 |
453 |
x xFig xStr node lv idx image xCross| |
|
481 | 454 |
|
552 | 455 |
level := nil. "/ to force evaluation of #ifFalse in loop |
456 |
||
494 | 457 |
index := self visibleLineToAbsoluteLine:startVisLineNr. |
458 |
size := listOfNodes size. |
|
459 |
yTop := self yOfVisibleLine:startVisLineNr. |
|
569 | 460 |
yTop := yTop - 1. |
494 | 461 |
end := endVisLineNr - startVisLineNr + 1. |
481 | 462 |
|
463 |
"/ clear rectangle line and set background color |
|
464 |
self paint:bg. |
|
465 |
self fillRectangleX:0 y:yTop width:width height:(end * fontHeight). |
|
466 |
||
494 | 467 |
index isNil ifTrue:[^ self]. |
541 | 468 |
figWidthDiv2 := imageWidth // 2. |
494 | 469 |
yCtr := yTop - (fontHeight // 2). |
485 | 470 |
|
481 | 471 |
self paint:fg on:bg. |
494 | 472 |
(end := index + end) > size ifTrue:[end := size + 1]. |
481 | 473 |
|
494 | 474 |
[index < end] whileTrue:[ |
475 |
node := listOfNodes at:index. |
|
476 |
yBot := yTop + fontHeight. |
|
477 |
yCtr := yCtr + fontHeight. |
|
485 | 478 |
|
494 | 479 |
(lv := node level) == level ifFalse:[ |
480 |
level := lv. |
|
481 |
xFig := self xOfFigureLevel:lv. |
|
482 |
xStr := self xOfStringLevel:lv. |
|
483 |
xCross := (self xOfFigureLevel:(lv-1)) + figWidthDiv2. |
|
481 | 484 |
]. |
485 |
||
486 |
showLines ifTrue:[ |
|
494 | 487 |
(node isCollapsable and:[node numberOfChildren ~~ 0]) ifTrue:[ |
488 |
x := xFig + figWidthDiv2. |
|
489 |
self displayLineFromX:x y:yCtr toX:x y:yBot |
|
481 | 490 |
]. |
494 | 491 |
(level ~~ 1 and:[node parent children last == node]) ifTrue:[ |
569 | 492 |
self displayLineFromX:xCross y:yTop - 1 toX:xCross y:yCtr . "/ vertical |
490 | 493 |
]. |
494 | 494 |
self displayLineFromX:xCross y:yCtr toX:xFig y:yCtr . "/ horizontal |
481 | 495 |
|
496 |
"/ draw vertical lines |
|
494 | 497 |
idx := index. |
481 | 498 |
|
494 | 499 |
[(lv > 0 and:[(idx := idx + 1) <= size])] whileTrue:[ |
500 |
(x := (listOfNodes at:idx) level) <= lv ifTrue:[ |
|
501 |
lv := x - 1. |
|
502 |
x := (self xOfFigureLevel:lv) + figWidthDiv2. |
|
569 | 503 |
self displayLineFromX:x y:yTop - 1 toX:x y:yBot. |
481 | 504 |
] |
505 |
] |
|
506 |
]. |
|
507 |
||
508 |
"/ draw image |
|
494 | 509 |
image := self figureFor:node. |
541 | 510 |
image notNil ifTrue:[ |
529 | 511 |
self displayForm:image x:xFig y:(yCtr - (image height // 2)). |
541 | 512 |
]. |
481 | 513 |
|
514 |
"/ draw text label |
|
494 | 515 |
self drawLabelIndex:index atX:xStr y:yCtr . |
490 | 516 |
|
494 | 517 |
"/ draw directory indicator |
569 | 518 |
(showDirectoryIndicator and:[node showIndicator]) ifTrue:[ |
494 | 519 |
node isCollapsable ifTrue:[ |
520 |
image := openIndicator. |
|
521 |
x := extentOpenIndicator. |
|
522 |
] ifFalse:[ |
|
523 |
image := closeIndicator. |
|
524 |
x := extentCloseIndicator. |
|
525 |
]. |
|
526 |
self displayForm:image x:(xCross - x x) |
|
527 |
y:(yCtr - x y) |
|
485 | 528 |
]. |
481 | 529 |
"/ setup next line |
494 | 530 |
index := index + 1. |
531 |
yTop := yBot. |
|
481 | 532 |
]. |
533 |
||
541 | 534 |
"Modified: 6.10.1997 / 13:31:51 / cg" |
485 | 535 |
! |
536 |
||
444 | 537 |
drawLabelIndex:anIndex atX:x y:yCenter |
538 |
"draw text label at x and y centered |
|
539 |
" |
|
569 | 540 |
|lbl| |
444 | 541 |
|
569 | 542 |
(lbl := (listOfNodes at:anIndex) name) notNil ifTrue:[ |
543 |
self displayOpaqueString:lbl x:x y:(yCenter + labelOffsetY). |
|
544 |
] |
|
545 |
! |
|
444 | 546 |
|
569 | 547 |
redrawX:x y:y width:w height:h |
548 |
||
549 |
self shown ifTrue:[ |
|
550 |
super redrawX:x y:y width:w height:h. |
|
551 |
]. |
|
444 | 552 |
! ! |
553 |
||
494 | 554 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 555 |
|
494 | 556 |
detectNode:aOneArgBlock |
557 |
"evaluate the argument, aBlock for each node in the list until |
|
558 |
the block returns true; in this case return the node which caused |
|
559 |
the true evaluation. If none node is detected, nil is returned. |
|
560 |
" |
|
561 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 562 |
! |
563 |
||
564 |
selectedNodesDo:aOneArgBlock |
|
565 |
"evaluate the block on each node selected |
|
566 |
" |
|
567 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 568 |
! ! |
569 |
||
569 | 570 |
!SelectionInTreeView methodsFor:'event handling'! |
571 |
||
639 | 572 |
buttonMotion:buttonMask x:x y:y |
573 |
"mouse-move while button was pressed - handle selection changes" |
|
574 |
||
575 |
discardMotionEvents ifFalse:[ |
|
576 |
super buttonMotion:buttonMask x:x y:y |
|
577 |
] |
|
578 |
||
579 |
||
580 |
! |
|
581 |
||
569 | 582 |
buttonMultiPress:button x:x y:y |
583 |
||
584 |
(self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[ |
|
585 |
^ super buttonMultiPress:button x:x y:y |
|
586 |
]. |
|
587 |
"/ discard doubleClick on indicator |
|
588 |
! |
|
589 |
||
590 |
buttonPress:button x:x y:y |
|
591 |
"check for indicator |
|
592 |
" |
|
639 | 593 |
|expand node lineNr| |
569 | 594 |
|
595 |
lineNr := self indicatiorLineForButton:button atX:x y:y. |
|
596 |
||
597 |
lineNr == 0 ifTrue:[ |
|
598 |
^ super buttonPress:button x:x y:y |
|
599 |
]. |
|
600 |
node := listOfNodes at:lineNr. |
|
601 |
||
602 |
( validateDoubleClickBlock isNil |
|
603 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
604 |
) ifFalse:[ |
|
605 |
^ super buttonPress:button x:x y:y |
|
606 |
]. |
|
639 | 607 |
discardMotionEvents := true. |
569 | 608 |
dragIsActive := false. |
609 |
clickPosition := nil. |
|
610 |
||
639 | 611 |
self hasSelection ifTrue:[ |
612 |
(selectConditionBlock isNil or:[selectConditionBlock value:lineNr]) ifTrue:[ |
|
613 |
self selection:lineNr |
|
614 |
] ifFalse:[ |
|
615 |
self selection:nil |
|
569 | 616 |
] |
617 |
]. |
|
639 | 618 |
self nodeAt:lineNr expand:(node isExpandable). |
569 | 619 |
|
639 | 620 |
! |
621 |
||
622 |
buttonRelease:button x:x y:y |
|
623 |
"stop any autoscroll" |
|
569 | 624 |
|
639 | 625 |
discardMotionEvents ifTrue:[ |
626 |
clickPosition := nil. |
|
627 |
discardMotionEvents := false. |
|
628 |
]. |
|
629 |
super buttonRelease:button x:x y:y |
|
630 |
||
569 | 631 |
! |
632 |
||
633 |
doubleClicked |
|
634 |
"handle a double click; collapse or expand selected entry |
|
635 |
in case of having children |
|
636 |
" |
|
637 |
|node| |
|
638 |
||
639 |
(node := self selectedNode) notNil ifTrue:[ |
|
640 |
( validateDoubleClickBlock isNil |
|
641 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
642 |
) ifTrue:[ |
|
643 |
self selectedNodeExpand:(node isExpandable). |
|
644 |
super doubleClicked |
|
645 |
] |
|
646 |
] |
|
647 |
||
648 |
! |
|
649 |
||
650 |
indicatiorLineForButton:aButton atX:x y:y |
|
651 |
"returns linenumber assigned to indicator at x/y or 0 |
|
652 |
" |
|
653 |
|sensor nr x0 node| |
|
654 |
||
655 |
( enabled |
|
656 |
and:[showDirectoryIndicator |
|
657 |
and:[aButton == 1 or:[aButton == #select]]] |
|
658 |
) ifTrue:[ |
|
659 |
sensor := self sensor. |
|
660 |
||
661 |
(sensor ctrlDown or:[sensor shiftDown]) ifFalse:[ |
|
662 |
nr := self visibleLineToListLine:(self visibleLineOfY:y). |
|
663 |
||
664 |
nr notNil ifTrue:[ |
|
665 |
node := listOfNodes at:nr. |
|
666 |
x0 := self xOfFigureLevel:(node level - 1). |
|
667 |
||
668 |
(x > x0 and:[(x0 + imageWidth) > x and:[node numberOfChildren ~~ 0]]) ifTrue:[ |
|
669 |
^ nr |
|
670 |
] |
|
671 |
] |
|
672 |
] |
|
673 |
]. |
|
674 |
^ 0 |
|
675 |
! ! |
|
676 |
||
444 | 677 |
!SelectionInTreeView methodsFor:'initialization'! |
678 |
||
514 | 679 |
destroy |
680 |
"remove dependencies |
|
681 |
" |
|
682 |
rootHolder notNil ifTrue:[ |
|
683 |
rootHolder removeDependent:self |
|
684 |
]. |
|
685 |
selectionHolder notNil ifTrue:[ |
|
686 |
selectionHolder removeDependent:self |
|
687 |
]. |
|
688 |
super destroy. |
|
689 |
||
690 |
||
691 |
! |
|
692 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
693 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
694 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
695 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
696 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
697 |
super fetchDeviceResources. |
478 | 698 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
699 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
700 |
|
478 | 701 |
fetchImageResources |
702 |
"initialize heavily used device resources - to avoid rendering |
|
703 |
images again and again later; returns maximum extent of the images used. |
|
704 |
Could be redefined by subclass |
|
471 | 705 |
" |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
706 |
|extent| |
494 | 707 |
|
708 |
imageOpened isNil ifTrue:[ |
|
569 | 709 |
imageOpened := (self class imageOpened) onDevice:device |
494 | 710 |
]. |
444 | 711 |
|
494 | 712 |
imageClosed isNil ifTrue:[ |
569 | 713 |
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
|
714 |
]. |
569 | 715 |
extent := (imageOpened extent) max:(imageClosed extent). |
494 | 716 |
|
717 |
imageItem isNil ifTrue:[ |
|
569 | 718 |
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
|
719 |
]. |
569 | 720 |
^ extent max:(imageItem extent) |
444 | 721 |
! |
722 |
||
480 | 723 |
getFontParameters |
546 | 724 |
"save old computed height derived from images |
725 |
" |
|
726 |
|lineHeight| |
|
727 |
||
728 |
lineHeight := fontHeight ? 0. |
|
480 | 729 |
super getFontParameters. |
569 | 730 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 731 |
|
546 | 732 |
lineHeight > fontHeight ifTrue:[ |
733 |
fontHeight := lineHeight |
|
734 |
]. |
|
480 | 735 |
! |
736 |
||
444 | 737 |
initialize |
471 | 738 |
"setup instance attributes |
739 |
" |
|
444 | 740 |
super initialize. |
569 | 741 |
self bitGravity:#NorthWest. |
485 | 742 |
showLines := true. |
494 | 743 |
showRoot := true. |
546 | 744 |
computeResources := true. |
485 | 745 |
showDirectoryIndicator := false. |
639 | 746 |
discardMotionEvents := false. |
747 |
||
494 | 748 |
textInset := 2. |
749 |
imageInset := 0. "/ set during indication enabled |
|
750 |
imageWidth := 8. "/ default: will change during startup |
|
514 | 751 |
self model:nil. "/ creates a default model. |
478 | 752 |
! |
753 |
||
569 | 754 |
realize |
755 |
super realize. |
|
756 |
self refetchDeviceResources. |
|
757 |
||
758 |
! |
|
759 |
||
478 | 760 |
refetchDeviceResources |
761 |
"reinitialize heavily used device resources - to avoid rendering |
|
762 |
images again and again later |
|
763 |
" |
|
551 | 764 |
|extent| |
478 | 765 |
|
569 | 766 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 767 |
computeResources := false. |
768 |
extent := self fetchImageResources. |
|
494 | 769 |
|
546 | 770 |
extent y >= fontHeight ifTrue:[ |
771 |
fontHeight := 1 + extent y. |
|
494 | 772 |
]. |
546 | 773 |
imageWidth := extent x. |
774 |
self recomputeDirectoryIndicator. |
|
569 | 775 |
self computeNumberOfLinesShown. |
546 | 776 |
] |
444 | 777 |
! ! |
778 |
||
483 | 779 |
!SelectionInTreeView methodsFor:'model'! |
444 | 780 |
|
781 |
getListFromModel |
|
782 |
"if I have a model, get my list from it using the listMessage. |
|
783 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
784 |
" |
|
483 | 785 |
super list:(self listFromModel) keepSelection:true |
786 |
! |
|
444 | 787 |
|
483 | 788 |
listFromModel |
789 |
"get list from model and return the new list. |
|
790 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
791 |
" |
|
792 |
|msg| |
|
444 | 793 |
|
468 | 794 |
widthOfWidestLine := nil. |
444 | 795 |
|
514 | 796 |
(msg := listMsg ? aspectMsg) notNil ifTrue:[ |
797 |
listOfNodes := model perform:msg. |
|
798 |
listOfNodes size ~~ 0 ifTrue:[ |
|
546 | 799 |
self refetchDeviceResources. |
514 | 800 |
^ listOfNodes collect:[:n|n name] |
483 | 801 |
] |
802 |
]. |
|
803 |
listOfNodes := #(). |
|
804 |
^ #() |
|
494 | 805 |
! |
806 |
||
807 |
model:aModel |
|
514 | 808 |
"check whether model is nil; than a default model is created |
809 |
" |
|
810 |
|model| |
|
811 |
||
812 |
model := aModel ? (SelectionInTree new). |
|
813 |
model showRoot:showRoot. |
|
814 |
super model:model. |
|
815 |
! |
|
816 |
||
817 |
rootFromModel |
|
818 |
"update hierarchical list from root model; 'rootHolder' |
|
819 |
" |
|
820 |
|root| |
|
821 |
||
585 | 822 |
root := rootHolder root. |
514 | 823 |
|
824 |
self root == root ifFalse:[ |
|
825 |
self selection:nil. |
|
826 |
self root:root. |
|
585 | 827 |
]. |
514 | 828 |
! |
829 |
||
830 |
selectionFromModel |
|
831 |
"set the selection derived from the selectionHolder |
|
832 |
" |
|
545 | 833 |
|coll value sz| |
514 | 834 |
|
835 |
(value := selectionHolder value) isNil ifTrue:[ |
|
836 |
^ self deselect |
|
507 | 837 |
]. |
514 | 838 |
|
839 |
multipleSelectOk ifFalse:[ |
|
840 |
self selectNode:value |
|
841 |
] ifTrue:[ |
|
545 | 842 |
(sz := value size) ~~ 0 ifTrue:[ |
843 |
coll := OrderedCollection new:sz. |
|
514 | 844 |
|
845 |
value do:[:aNode||i| |
|
846 |
(i := self indexOfNode:aNode) notNil ifTrue:[ |
|
847 |
coll add:i |
|
848 |
] |
|
849 |
] |
|
850 |
]. |
|
851 |
coll size == 0 ifTrue:[self deselect] |
|
852 |
ifFalse:[self selection:coll] |
|
853 |
] |
|
854 |
! |
|
855 |
||
856 |
selectionToModel |
|
857 |
"write selection to selection holder |
|
858 |
" |
|
859 |
|newSel oldSel| |
|
860 |
||
861 |
oldSel := selectionHolder value. |
|
862 |
||
863 |
multipleSelectOk ifFalse:[ |
|
864 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
865 |
selectionHolder value:newSel |
|
866 |
] |
|
867 |
] ifTrue:[ |
|
868 |
selection size == 0 ifTrue:[ |
|
869 |
oldSel notNil ifTrue:[ |
|
870 |
selectionHolder value:nil |
|
871 |
] |
|
872 |
] ifFalse:[ |
|
873 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
874 |
||
875 |
newSel size ~~ oldSel size ifTrue:[ |
|
876 |
selectionHolder value:newSel. |
|
877 |
] ifFalse:[ |
|
878 |
newSel do:[:aNode| |
|
879 |
(oldSel includes:aNode) ifFalse:[ |
|
880 |
^ selectionHolder value:newSel |
|
881 |
] |
|
882 |
] |
|
883 |
] |
|
884 |
] |
|
885 |
] |
|
444 | 886 |
! ! |
887 |
||
490 | 888 |
!SelectionInTreeView methodsFor:'private'! |
889 |
||
890 |
list:aList keepSelection:keepSelection |
|
585 | 891 |
"setup new list; keep selection dependent on the boolean state |
892 |
keepSelection |
|
893 |
" |
|
490 | 894 |
|list| |
895 |
||
896 |
list := aList. |
|
897 |
||
898 |
list size == 0 ifTrue:[ |
|
899 |
listOfNodes := #() |
|
900 |
] ifFalse:[ |
|
901 |
(list first respondsTo:#hasChildren) ifTrue:[ |
|
902 |
listOfNodes := aList. |
|
546 | 903 |
self refetchDeviceResources. |
490 | 904 |
list := listOfNodes collect:[:aNode| aNode name ]. |
905 |
] |
|
906 |
]. |
|
907 |
super list:list keepSelection:keepSelection |
|
546 | 908 |
! |
909 |
||
569 | 910 |
nodeAt:anIndex expand:doExpand |
585 | 911 |
"expand or collapse the node at an index, anIndex dependent on the boolean state |
912 |
of doExpand |
|
913 |
" |
|
569 | 914 |
|node| |
915 |
||
916 |
node := listOfNodes at:anIndex. |
|
917 |
||
918 |
node hasChildren ifTrue:[ |
|
919 |
node isExpandable ifTrue:[ |
|
920 |
doExpand ifFalse:[^ self]. |
|
921 |
node expand |
|
922 |
] ifFalse:[ |
|
923 |
doExpand ifTrue:[^ self]. |
|
924 |
node collapse |
|
925 |
]. |
|
926 |
||
927 |
node numberOfChildren == 0 ifTrue:[ |
|
928 |
"/ no children; redraw selected line (image might change) |
|
929 |
self redrawLine:anIndex. |
|
930 |
] ifFalse:[ |
|
931 |
"/ with children; update list and redraw to end. |
|
585 | 932 |
model removeDependent:self. |
933 |
model recomputeList. |
|
934 |
model addDependent:self. |
|
569 | 935 |
list := self listFromModel. |
936 |
self redrawFromLine:anIndex. |
|
937 |
self contentsChanged. |
|
938 |
] |
|
939 |
] |
|
940 |
||
941 |
! |
|
942 |
||
546 | 943 |
recomputeDirectoryIndicator |
944 |
"setup attributes used by directory indicator |
|
945 |
" |
|
946 |
|x1 x2 y| |
|
947 |
||
948 |
imageInset := 0. |
|
949 |
||
950 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
951 |
^ self |
|
952 |
]. |
|
569 | 953 |
openIndicator isNil ifTrue:[ |
954 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
955 |
]. |
|
956 |
closeIndicator isNil ifTrue:[ |
|
957 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
958 |
]. |
|
546 | 959 |
|
960 |
x1 := (openIndicator widthOn:self) // 2. |
|
961 |
y := openIndicator heightOn:self. |
|
962 |
extentOpenIndicator := Point x:x1 y:(y // 2). |
|
963 |
x2 := (closeIndicator widthOn:self) // 2. |
|
964 |
y := closeIndicator heightOn:self. |
|
965 |
extentCloseIndicator := Point x:x2 y:(y // 2). |
|
966 |
||
967 |
x2 > x1 ifTrue:[x1 := x2]. |
|
968 |
||
969 |
(x1 := x1 + self class minImageInset) > (imageWidth // 2) ifTrue:[ |
|
970 |
imageInset := x1 - (imageWidth // 2). |
|
971 |
]. |
|
972 |
||
490 | 973 |
! ! |
974 |
||
468 | 975 |
!SelectionInTreeView methodsFor:'private queries'! |
976 |
||
977 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
978 |
"return the length (in characters) of the longest line in a line-range |
|
979 |
" |
|
980 |
|max| |
|
981 |
||
982 |
max := self widthOfContents:firstLine and:lastLine. |
|
983 |
^ (max // fontWidth) + 1 |
|
984 |
! |
|
985 |
||
986 |
widthOfContents |
|
987 |
"return the width of the contents in pixels |
|
988 |
- used for scrollbar interface" |
|
989 |
||
990 |
list isNil ifTrue:[^ 0]. |
|
991 |
||
992 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
993 |
widthOfWidestLine := self widthOfContents:1 and:(self size). |
|
994 |
]. |
|
995 |
^ widthOfWidestLine + (leftMargin * 2) |
|
996 |
||
997 |
! |
|
998 |
||
999 |
widthOfContents:firstLine and:lastLine |
|
1000 |
"return the length (in pixels) of the longest line in a line-range |
|
1001 |
" |
|
1002 |
|max "{ Class: SmallInteger }" |
|
1003 |
thisLen "{ Class: SmallInteger }" |
|
1004 |
first "{ Class: SmallInteger }" |
|
1005 |
last "{ Class: SmallInteger }" | |
|
1006 |
||
1007 |
listOfNodes size == 0 ifTrue:[^ 0]. |
|
1008 |
||
1009 |
last := listOfNodes size. |
|
1010 |
first := firstLine. |
|
1011 |
||
1012 |
(first > last) ifTrue:[^ 0]. |
|
1013 |
||
1014 |
(lastLine < last) ifTrue:[ |
|
1015 |
last := lastLine |
|
1016 |
]. |
|
1017 |
max := 0. |
|
1018 |
||
1019 |
listOfNodes from:first to:last do:[:anItem||name| |
|
1020 |
thisLen := self xOfStringNode:anItem. |
|
1021 |
||
1022 |
(name := anItem name) notNil ifTrue:[ |
|
1023 |
thisLen := thisLen + (name widthOn:self). |
|
1024 |
]. |
|
1025 |
(thisLen > max) ifTrue:[ |
|
1026 |
max := thisLen. |
|
1027 |
] |
|
1028 |
]. |
|
1029 |
^ max + leftOffset. |
|
1030 |
! |
|
1031 |
||
1032 |
withoutRedrawAt:anIndex put:aString |
|
1033 |
"change a line without redisplay" |
|
1034 |
||
1035 |
|width| |
|
1036 |
||
1037 |
width := widthOfWidestLine. |
|
1038 |
widthOfWidestLine := nil. |
|
1039 |
||
1040 |
super withoutRedrawAt:anIndex put:aString. |
|
1041 |
||
1042 |
(widthOfWidestLine := width) notNil ifTrue:[ |
|
1043 |
width := self widthOfContents:anIndex and:anIndex. |
|
1044 |
||
1045 |
width > widthOfWidestLine ifTrue:[ |
|
1046 |
widthOfWidestLine := width |
|
1047 |
] ifFalse:[ |
|
1048 |
widthOfWidestLine := nil "/ means: unknown |
|
1049 |
] |
|
1050 |
]. |
|
1051 |
||
1052 |
||
1053 |
! ! |
|
1054 |
||
483 | 1055 |
!SelectionInTreeView methodsFor:'queries'! |
1056 |
||
1057 |
figureFor:aNode |
|
1058 |
"access figure for a node |
|
1059 |
" |
|
1060 |
aNode hasChildren ifTrue:[ |
|
1061 |
aNode isExpandable ifTrue:[ ^ imageClosed ] |
|
1062 |
ifFalse:[ ^ imageOpened ] |
|
1063 |
]. |
|
1064 |
^ imageItem |
|
1065 |
! |
|
1066 |
||
1067 |
indexOfNode:aNode |
|
1068 |
"returns index of a node |
|
1069 |
" |
|
1070 |
^ listOfNodes findFirst:[:n| n == aNode ] |
|
1071 |
! |
|
1072 |
||
494 | 1073 |
xOfFigureLevel:aLevel |
1074 |
"origin x where to draw the icon |
|
1075 |
" |
|
1076 |
|l| |
|
1077 |
||
1078 |
showRoot ifTrue:[l := aLevel] |
|
1079 |
ifFalse:[l := aLevel - 1]. |
|
1080 |
||
1081 |
showDirectoryIndicator ifFalse:[l := l - 1]. |
|
1082 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
|
1083 |
||
1084 |
! |
|
1085 |
||
483 | 1086 |
xOfFigureNode:aNode |
1087 |
"origin x where to draw the icon |
|
1088 |
" |
|
494 | 1089 |
^ self xOfFigureLevel:(aNode level) |
1090 |
! |
|
490 | 1091 |
|
494 | 1092 |
xOfStringLevel:aLevel |
1093 |
"origin x where to draw the text( label ) |
|
1094 |
" |
|
1095 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 1096 |
|
1097 |
! |
|
1098 |
||
1099 |
xOfStringNode:aNode |
|
1100 |
"origin x where to draw the text( label ) |
|
1101 |
" |
|
494 | 1102 |
^ self xOfStringLevel:(aNode level) |
483 | 1103 |
|
1104 |
! ! |
|
1105 |
||
444 | 1106 |
!SelectionInTreeView methodsFor:'selection'! |
1107 |
||
494 | 1108 |
selectFromListOfNames:aListOfNames |
1109 |
"set selection from a list of names |
|
1110 |
" |
|
497 | 1111 |
|node rdwNd| |
494 | 1112 |
|
1113 |
aListOfNames size < 1 ifTrue:[ |
|
1114 |
^ self selection:nil |
|
1115 |
]. |
|
1116 |
||
1117 |
node := model root. |
|
1118 |
||
1119 |
aListOfNames do:[:el||next| |
|
1120 |
next := node detectChild:[:e|e name = el]. |
|
1121 |
||
1122 |
next notNil ifTrue:[ |
|
1123 |
node hidden ifTrue:[ |
|
1124 |
rdwNd isNil ifTrue:[ |
|
1125 |
rdwNd := node. |
|
1126 |
self selectNode:node. |
|
1127 |
]. |
|
1128 |
node expand |
|
1129 |
]. |
|
1130 |
node := next |
|
1131 |
] |
|
1132 |
]. |
|
1133 |
||
1134 |
rdwNd notNil ifTrue:[ |
|
585 | 1135 |
model removeDependent:self. |
1136 |
model recomputeList. |
|
1137 |
model addDependent:self. |
|
494 | 1138 |
list := self listFromModel. |
1139 |
self redrawFromLine:(self indexOfNode:rdwNd). |
|
1140 |
self contentsChanged. |
|
1141 |
]. |
|
1142 |
self selectNode:node. |
|
1143 |
||
1144 |
! |
|
1145 |
||
468 | 1146 |
selectNode:aNode |
1147 |
"change selection to a node |
|
1148 |
" |
|
483 | 1149 |
self selection:(self indexOfNode:aNode) |
468 | 1150 |
|
1151 |
||
1152 |
! |
|
1153 |
||
456 | 1154 |
selectedIndex |
1155 |
"get single selected index or 0 |
|
1156 |
" |
|
483 | 1157 |
selection size == 1 ifTrue:[^ selection first]. |
1158 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 1159 |
^ 0 |
444 | 1160 |
! |
1161 |
||
1162 |
selectedNode |
|
1163 |
"get the single selected node or nil |
|
1164 |
" |
|
456 | 1165 |
|idx| |
1166 |
||
1167 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
1168 |
^ listOfNodes at:idx |
|
444 | 1169 |
]. |
1170 |
^ nil |
|
514 | 1171 |
! |
1172 |
||
1173 |
selectionChangedFrom:oldSelection |
|
1174 |
"update selectionHolder if not nil |
|
1175 |
" |
|
1176 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1177 |
"/ first change my selectionHolders value ... |
514 | 1178 |
selectionHolder notNil ifTrue:[ |
1179 |
self selectionToModel. |
|
1180 |
]. |
|
1181 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1182 |
"/ ... then make notifications. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1183 |
super selectionChangedFrom:oldSelection. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1184 |
|
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1185 |
|
444 | 1186 |
! ! |
1187 |
||
507 | 1188 |
!SelectionInTreeView methodsFor:'selection-actions'! |
1189 |
||
1190 |
selectedNodeAdd:something |
|
1191 |
"add a node or collection of nodes after selected node |
|
1192 |
" |
|
1193 |
|node| |
|
1194 |
||
1195 |
something notNil ifTrue:[ |
|
1196 |
(node := self selectedNode) notNil ifTrue:[ |
|
1197 |
node parent notNil ifTrue:[ |
|
1198 |
node isCollapsable ifTrue:[ |
|
1199 |
model add:something beforeIndex:1 below:node |
|
1200 |
] ifFalse:[ |
|
1201 |
model add:something after:node |
|
1202 |
] |
|
1203 |
] ifFalse:[ |
|
1204 |
model add:something beforeIndex:1 below:(self root) |
|
1205 |
] |
|
1206 |
] |
|
1207 |
] |
|
1208 |
||
1209 |
! |
|
1210 |
||
1211 |
selectedNodeBecomeChildOfNext |
|
1212 |
"become node a child of followd node |
|
1213 |
" |
|
1214 |
|idx node cprt nprt| |
|
1215 |
||
1216 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
1217 |
idx := cprt indexOfChild:node. |
|
1218 |
||
1219 |
idx == cprt children size ifFalse:[ |
|
1220 |
nprt := cprt childAt:(idx + 1). |
|
1221 |
||
1222 |
nprt notNil ifTrue:[ |
|
1223 |
model removeDependent:self. |
|
1224 |
model removeSelection. |
|
1225 |
selection := nil. |
|
1226 |
model collapse:nprt. |
|
1227 |
model add:node beforeIndex:1 below:nprt. |
|
1228 |
model addDependent:self. |
|
1229 |
model expand:nprt. |
|
1230 |
||
1231 |
self selectNode:node. |
|
1232 |
] |
|
1233 |
] |
|
1234 |
] |
|
1235 |
! |
|
1236 |
||
1237 |
selectedNodeBecomeSisterOfParent |
|
1238 |
"become node a sister of its current parent |
|
1239 |
" |
|
1240 |
|node cprt nprt| |
|
1241 |
||
1242 |
( (node := self selectedNode) isNil |
|
1243 |
or:[(cprt := node parent) isNil |
|
1244 |
or:[(nprt := cprt parent) isNil]] |
|
1245 |
) ifFalse:[ |
|
1246 |
model removeDependent:self. |
|
1247 |
model removeSelection. |
|
1248 |
selection := nil. |
|
1249 |
model addDependent:self. |
|
1250 |
||
1251 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
|
1252 |
self selectNode:node. |
|
1253 |
] |
|
1254 |
||
1255 |
! |
|
1256 |
||
1257 |
selectedNodeChangeSequenceOrder:anOffset |
|
1258 |
"move child 'anOffset' forward or backward in list of children |
|
1259 |
" |
|
1260 |
|idx node size parent| |
|
1261 |
||
1262 |
( (node := self selectedNode) notNil |
|
1263 |
and:[(parent := node parent) notNil |
|
1264 |
and:[(size := parent children size) > 1]] |
|
1265 |
) ifTrue:[ |
|
1266 |
idx := parent indexOfChild:node. |
|
1267 |
||
1268 |
model removeDependent:self. |
|
1269 |
model removeSelection. |
|
1270 |
selection := nil. |
|
1271 |
model addDependent:self. |
|
1272 |
||
1273 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
1274 |
idx := size |
|
1275 |
] ifFalse:[ |
|
1276 |
idx > size ifTrue:[idx := 1] |
|
1277 |
]. |
|
1278 |
model add:node beforeIndex:idx below:parent. |
|
1279 |
self selectNode:node. |
|
1280 |
] |
|
1281 |
! |
|
1282 |
||
1283 |
selectedNodeExpand:doExpand |
|
1284 |
"collapse or expand selected node |
|
1285 |
" |
|
1286 |
|node index| |
|
1287 |
||
1288 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
|
1289 |
node := listOfNodes at:index. |
|
1290 |
||
1291 |
node hasChildren ifTrue:[ |
|
1292 |
node isExpandable ifTrue:[ |
|
1293 |
doExpand ifFalse:[^ self]. |
|
1294 |
node expand |
|
1295 |
] ifFalse:[ |
|
1296 |
doExpand ifTrue:[^ self]. |
|
1297 |
node collapse |
|
1298 |
]. |
|
1299 |
||
1300 |
node numberOfChildren == 0 ifTrue:[ |
|
1301 |
"/ no children; redraw selected line (image might change) |
|
1302 |
self redrawLine:index. |
|
1303 |
] ifFalse:[ |
|
1304 |
"/ with children; update list and redraw to end. |
|
585 | 1305 |
model removeDependent:self. |
1306 |
model recomputeList. |
|
1307 |
model addDependent:self. |
|
507 | 1308 |
list := self listFromModel. |
1309 |
self redrawFromLine:index. |
|
1310 |
self contentsChanged. |
|
1311 |
] |
|
1312 |
] |
|
1313 |
]. |
|
1314 |
! |
|
1315 |
||
1316 |
selectedNodesRemove |
|
1317 |
"remove selected nodes |
|
1318 |
" |
|
1319 |
model removeSelection. |
|
1320 |
self selection:nil. |
|
1321 |
||
1322 |
! ! |
|
1323 |
||
444 | 1324 |
!SelectionInTreeView class methodsFor:'documentation'! |
1325 |
||
1326 |
version |
|
639 | 1327 |
^ '$Header: /cvs/stx/stx/libwidg2/Attic/SelTreeV.st,v 1.32 1998-01-02 16:07:36 ca Exp $' |
444 | 1328 |
! ! |