author | ca |
Tue, 02 Sep 1997 14:20:38 +0200 | |
changeset 507 | 546f43d75275 |
parent 497 | 9b5503aa6f57 |
child 514 | c25e078ed84c |
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 |
|
494 | 15 |
instanceVariableNames:'doubleClickSelectionBlock imageWidth showLines listOfNodes |
16 |
imageInset textInset openIndicator closeIndicator showRoot |
|
17 |
extentOpenIndicator extentCloseIndicator showDirectoryIndicator |
|
18 |
indicatorExtentDiv2 imageOpened imageClosed imageItem' |
|
490 | 19 |
classVariableNames:'ImageOpened ImageClosed ImageItem OpenIndicator CloseIndicator' |
444 | 20 |
poolDictionaries:'' |
21 |
category:'Views-Text' |
|
22 |
! |
|
23 |
||
24 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
25 |
||
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
43 |
somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like) |
|
44 |
lists and adds the functions to show/hide subtrees. |
|
456 | 45 |
Requires SelectionInTree as model and TreeItem (or compatible) list entries. |
444 | 46 |
|
456 | 47 |
This class obsoletes SelectionInTreeView, which is no longer |
446 | 48 |
maintained but kept for backward compatibility. |
49 |
||
50 |
||
444 | 51 |
[see also:] |
456 | 52 |
SelectionInTree |
53 |
TreeItem |
|
54 |
SelectionInTreeView |
|
444 | 55 |
SelectionInListView |
494 | 56 |
FileSelectionTree |
444 | 57 |
|
58 |
[author:] |
|
59 |
Claus Atzkern |
|
60 |
" |
|
61 |
||
62 |
! |
|
63 |
||
64 |
examples |
|
65 |
" |
|
66 |
shows the tree of smalltalk classes: |
|
67 |
[exBegin] |
|
456 | 68 |
|top model sel root| |
69 |
||
70 |
root := TreeItem newAsTreeFromSmalltalkClass:Object. |
|
71 |
root expand. |
|
72 |
model := SelectionInTree new root:root. |
|
73 |
top := StandardSystemView new. |
|
74 |
top extent:300@300. |
|
75 |
||
76 |
sel := SelectionInTreeView new. |
|
77 |
sel model: model. |
|
78 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
79 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
80 |
top open. |
|
81 |
[exEnd] |
|
82 |
||
83 |
||
485 | 84 |
|
456 | 85 |
same, including nil-subclasses (i.e. really all classes): |
86 |
[exBegin] |
|
87 |
|top model sel root| |
|
444 | 88 |
|
456 | 89 |
root := TreeItem newAsTreeFromSmalltalkClass:nil. |
90 |
root expand. |
|
91 |
model := SelectionInTree new root:root. |
|
92 |
top := StandardSystemView new. |
|
93 |
top extent:300@300. |
|
94 |
||
95 |
sel := SelectionInTreeView new. |
|
96 |
sel model: model. |
|
97 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
98 |
||
99 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
100 |
top open. |
|
101 |
[exEnd] |
|
102 |
||
485 | 103 |
|
483 | 104 |
|
485 | 105 |
shows the tree of smalltalk classes; show directory indication and no |
106 |
lines. |
|
107 |
[exBegin] |
|
483 | 108 |
|top model sel root| |
109 |
||
110 |
root := TreeItem newAsTreeFromSmalltalkClass:Object. |
|
111 |
root expand. |
|
112 |
model := SelectionInTree new root:root. |
|
113 |
top := StandardSystemView new. |
|
114 |
top extent:300@300. |
|
115 |
||
116 |
sel := SelectionInTreeView new. |
|
485 | 117 |
sel showLines:false. |
118 |
sel showDirectoryIndicator:true. |
|
119 |
||
483 | 120 |
sel model: model. |
485 | 121 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
483 | 122 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
123 |
top open. |
|
485 | 124 |
[exEnd] |
125 |
" |
|
126 |
||
444 | 127 |
! ! |
128 |
||
129 |
!SelectionInTreeView class methodsFor:'constants'! |
|
130 |
||
494 | 131 |
minImageInset |
132 |
"returns minimum inset from directory indication to image |
|
471 | 133 |
" |
494 | 134 |
^ 6 |
490 | 135 |
|
136 |
||
137 |
! ! |
|
138 |
||
139 |
!SelectionInTreeView class methodsFor:'default images'! |
|
140 |
||
141 |
closeIndicator |
|
142 |
CloseIndicator isNil ifTrue:[ |
|
143 |
CloseIndicator := Image fromFile:('xpmBitmaps/plus.xpm'). |
|
144 |
]. |
|
145 |
^ CloseIndicator |
|
146 |
" |
|
147 |
CloseIndicator := nil |
|
148 |
" |
|
471 | 149 |
! |
150 |
||
444 | 151 |
imageClosed |
152 |
ImageClosed isNil ifTrue:[ |
|
153 |
ImageClosed := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm'). |
|
154 |
]. |
|
155 |
^ ImageClosed |
|
156 |
" |
|
157 |
ImageClosed := nil |
|
158 |
" |
|
159 |
||
160 |
! |
|
161 |
||
162 |
imageItem |
|
163 |
ImageItem isNil ifTrue:[ |
|
164 |
ImageItem := Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm') |
|
165 |
||
166 |
]. |
|
167 |
^ ImageItem |
|
168 |
" |
|
169 |
ImageItem := nil |
|
170 |
" |
|
171 |
||
172 |
! |
|
173 |
||
174 |
imageOpened |
|
175 |
ImageOpened isNil ifTrue:[ |
|
176 |
ImageOpened := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm'). |
|
177 |
||
178 |
]. |
|
179 |
^ ImageOpened |
|
180 |
" |
|
181 |
ImageOpened := nil |
|
182 |
" |
|
490 | 183 |
! |
184 |
||
185 |
openIndicator |
|
186 |
OpenIndicator isNil ifTrue:[ |
|
187 |
OpenIndicator := Image fromFile:('xpmBitmaps/minus.xpm'). |
|
188 |
]. |
|
189 |
^ OpenIndicator |
|
190 |
" |
|
191 |
OpenIndicator := nil |
|
192 |
" |
|
193 |
||
444 | 194 |
! ! |
195 |
||
196 |
!SelectionInTreeView methodsFor:'accessing'! |
|
197 |
||
490 | 198 |
nodeAtIndex:anIndex |
199 |
"returns node at an index or nil |
|
200 |
" |
|
201 |
(anIndex notNil and:[anIndex ~~ 0 and:[anIndex <= listOfNodes size]]) ifTrue:[ |
|
202 |
^ listOfNodes at:anIndex |
|
203 |
]. |
|
204 |
^ nil |
|
205 |
! |
|
206 |
||
507 | 207 |
root |
208 |
"gets the root of the model; the first item into list. |
|
209 |
" |
|
210 |
^ self nodeAtIndex:1 |
|
211 |
! |
|
212 |
||
213 |
root:aRoot |
|
214 |
"sets the root of the model; the first item into list. |
|
215 |
" |
|
216 |
model isNil ifTrue:[ |
|
217 |
aRoot isNil ifTrue:[ |
|
218 |
^ self |
|
219 |
]. |
|
220 |
self model:(SelectionInTree new) |
|
221 |
]. |
|
222 |
model root:aRoot |
|
223 |
! |
|
224 |
||
490 | 225 |
textInset |
226 |
"get the left inset of the text label |
|
227 |
" |
|
228 |
^ textInset |
|
229 |
! |
|
230 |
||
231 |
textInset:anInset |
|
232 |
"set the left inset of the text label |
|
233 |
" |
|
234 |
anInset ~~ textInset ifTrue:[ |
|
235 |
anInset >= 0 ifTrue:[ |
|
236 |
textInset := anInset. |
|
237 |
self invalidate |
|
238 |
] ifFalse:[ |
|
239 |
self error |
|
240 |
] |
|
241 |
]. |
|
242 |
! ! |
|
243 |
||
244 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
|
245 |
||
246 |
doubleClickSelectionBlock |
|
247 |
"get the conditionBlock; this block is evaluated before a doubleClick action |
|
248 |
on a node containg children will be performed. In case of returning false, the |
|
249 |
doubleClick will not be handled. |
|
250 |
" |
|
251 |
^ doubleClickSelectionBlock |
|
252 |
||
253 |
||
254 |
! |
|
255 |
||
256 |
doubleClickSelectionBlock:aBlock |
|
257 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
258 |
on a node containg children will be performed. In case of returning false, the |
|
259 |
doubleClick will not be handled. |
|
260 |
" |
|
261 |
doubleClickSelectionBlock := aBlock |
|
262 |
||
263 |
||
264 |
! |
|
265 |
||
266 |
showDirectoryIndicator |
|
267 |
"returns true if directories has an open/closed indicator |
|
268 |
" |
|
269 |
^ showDirectoryIndicator |
|
270 |
! |
|
271 |
||
272 |
showDirectoryIndicator:aState |
|
273 |
"set or clear open/closed indicator for directories |
|
274 |
" |
|
275 |
"show or hide lines |
|
276 |
" |
|
277 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
494 | 278 |
showDirectoryIndicator := aState. |
279 |
self refetchDeviceResources. |
|
490 | 280 |
self invalidate |
281 |
]. |
|
282 |
! |
|
283 |
||
284 |
showLines |
|
285 |
"returns true if lines are shown |
|
286 |
" |
|
287 |
^ showLines |
|
288 |
! |
|
289 |
||
290 |
showLines:aState |
|
291 |
"show or hide lines |
|
292 |
" |
|
293 |
aState ~~ showLines ifTrue:[ |
|
294 |
showLines := aState. |
|
295 |
self invalidate |
|
296 |
]. |
|
494 | 297 |
! |
298 |
||
299 |
showRoot |
|
300 |
"list with or without root |
|
301 |
" |
|
302 |
^ showRoot |
|
303 |
! |
|
304 |
||
305 |
showRoot:aState |
|
306 |
"list with or without root |
|
307 |
" |
|
308 |
showRoot ~~ aState ifTrue:[ |
|
309 |
showRoot := aState. |
|
310 |
model notNil ifTrue:[model showRoot:showRoot]. |
|
311 |
]. |
|
490 | 312 |
! ! |
313 |
||
314 |
!SelectionInTreeView methodsFor:'accessing-images'! |
|
315 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
316 |
imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
317 |
"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
|
318 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
319 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
320 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
321 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
322 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
323 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
324 |
imageClosed:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
325 |
"set 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
|
326 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
327 |
imageClosed := something. |
494 | 328 |
self refetchDeviceResources. |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
329 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
330 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
331 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
332 |
"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
|
333 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
334 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
335 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
336 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
337 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
338 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
339 |
imageItem:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
340 |
"set 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
|
341 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
342 |
imageItem := something. |
494 | 343 |
self refetchDeviceResources. |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
344 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
345 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
346 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
347 |
"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
|
348 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
349 |
^ imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
350 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
351 |
"Created: 3.7.1997 / 12:34:28 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
352 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
353 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
354 |
imageOpened:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
355 |
"set 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
|
356 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
357 |
imageOpened := something. |
494 | 358 |
self refetchDeviceResources. |
471 | 359 |
! ! |
360 |
||
444 | 361 |
!SelectionInTreeView methodsFor:'drawing'! |
362 |
||
481 | 363 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
364 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 365 |
|
366 |
! |
|
367 |
||
368 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 369 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 370 |
|
371 |
! |
|
372 |
||
373 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 374 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 375 |
|
376 |
! |
|
377 |
||
378 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 379 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 380 |
|
381 |
! |
|
382 |
||
383 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 384 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
385 |
||
444 | 386 |
! |
387 |
||
388 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 389 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 390 |
|
391 |
! ! |
|
392 |
||
393 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
394 |
||
481 | 395 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
396 |
||
494 | 397 |
|size end index yBot yTop yCtr level figWidthDiv2 |
398 |
x xFig xStr node lv idx image xCross| |
|
481 | 399 |
|
494 | 400 |
index := self visibleLineToAbsoluteLine:startVisLineNr. |
401 |
size := listOfNodes size. |
|
402 |
yTop := self yOfVisibleLine:startVisLineNr. |
|
403 |
end := endVisLineNr - startVisLineNr + 1. |
|
481 | 404 |
|
405 |
"/ clear rectangle line and set background color |
|
406 |
self paint:bg. |
|
407 |
self fillRectangleX:0 y:yTop width:width height:(end * fontHeight). |
|
408 |
||
494 | 409 |
index isNil ifTrue:[^ self]. |
410 |
figWidthDiv2 := imageWidth // 2.. |
|
411 |
yCtr := yTop - (fontHeight // 2). |
|
485 | 412 |
|
481 | 413 |
self paint:fg on:bg. |
494 | 414 |
(end := index + end) > size ifTrue:[end := size + 1]. |
481 | 415 |
|
494 | 416 |
[index < end] whileTrue:[ |
417 |
node := listOfNodes at:index. |
|
418 |
yBot := yTop + fontHeight. |
|
419 |
yCtr := yCtr + fontHeight. |
|
485 | 420 |
|
494 | 421 |
(lv := node level) == level ifFalse:[ |
422 |
level := lv. |
|
423 |
xFig := self xOfFigureLevel:lv. |
|
424 |
xStr := self xOfStringLevel:lv. |
|
425 |
xCross := (self xOfFigureLevel:(lv-1)) + figWidthDiv2. |
|
481 | 426 |
]. |
427 |
||
428 |
showLines ifTrue:[ |
|
494 | 429 |
(node isCollapsable and:[node numberOfChildren ~~ 0]) ifTrue:[ |
430 |
x := xFig + figWidthDiv2. |
|
431 |
self displayLineFromX:x y:yCtr toX:x y:yBot |
|
481 | 432 |
]. |
494 | 433 |
(level ~~ 1 and:[node parent children last == node]) ifTrue:[ |
434 |
self displayLineFromX:xCross y:yTop toX:xCross y:yCtr . "/ vertical |
|
490 | 435 |
]. |
494 | 436 |
self displayLineFromX:xCross y:yCtr toX:xFig y:yCtr . "/ horizontal |
481 | 437 |
|
438 |
"/ draw vertical lines |
|
494 | 439 |
idx := index. |
481 | 440 |
|
494 | 441 |
[(lv > 0 and:[(idx := idx + 1) <= size])] whileTrue:[ |
442 |
(x := (listOfNodes at:idx) level) <= lv ifTrue:[ |
|
443 |
lv := x - 1. |
|
444 |
x := (self xOfFigureLevel:lv) + figWidthDiv2. |
|
445 |
self displayLineFromX:x y:yTop toX:x y:yBot. |
|
481 | 446 |
] |
447 |
] |
|
448 |
]. |
|
449 |
||
450 |
"/ draw image |
|
494 | 451 |
image := self figureFor:node. |
481 | 452 |
self displayForm:image x:xFig y:(yCtr - (image height // 2)). |
453 |
||
454 |
"/ draw text label |
|
494 | 455 |
self drawLabelIndex:index atX:xStr y:yCtr . |
490 | 456 |
|
494 | 457 |
"/ draw directory indicator |
458 |
(showDirectoryIndicator and:[node hasChildren]) ifTrue:[ |
|
459 |
node isCollapsable ifTrue:[ |
|
460 |
image := openIndicator. |
|
461 |
x := extentOpenIndicator. |
|
462 |
] ifFalse:[ |
|
463 |
image := closeIndicator. |
|
464 |
x := extentCloseIndicator. |
|
465 |
]. |
|
466 |
self displayForm:image x:(xCross - x x) |
|
467 |
y:(yCtr - x y) |
|
485 | 468 |
]. |
481 | 469 |
"/ setup next line |
494 | 470 |
index := index + 1. |
471 |
yTop := yBot. |
|
481 | 472 |
]. |
473 |
||
474 |
||
485 | 475 |
|
476 |
||
477 |
||
478 |
||
479 |
! |
|
480 |
||
444 | 481 |
drawLabelIndex:anIndex atX:x y:yCenter |
482 |
"draw text label at x and y centered |
|
483 |
" |
|
484 |
|y lbl| |
|
485 |
||
486 |
lbl := (listOfNodes at:anIndex) name. |
|
487 |
||
488 |
lbl notNil ifTrue:[ |
|
489 |
y := yCenter - ((lbl heightOn:self) // 2). |
|
490 |
||
491 |
(lbl respondsTo:#string) ifTrue:[ |
|
492 |
y := y + fontAscent. |
|
493 |
]. |
|
494 |
self displayOpaqueString:lbl x:x y:y. |
|
495 |
] |
|
496 |
! ! |
|
497 |
||
494 | 498 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 499 |
|
494 | 500 |
detectNode:aOneArgBlock |
501 |
"evaluate the argument, aBlock for each node in the list until |
|
502 |
the block returns true; in this case return the node which caused |
|
503 |
the true evaluation. If none node is detected, nil is returned. |
|
504 |
" |
|
505 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 506 |
! |
507 |
||
508 |
selectedNodesDo:aOneArgBlock |
|
509 |
"evaluate the block on each node selected |
|
510 |
" |
|
511 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 512 |
! ! |
513 |
||
444 | 514 |
!SelectionInTreeView methodsFor:'initialization'! |
515 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
516 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
517 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
518 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
519 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
520 |
super fetchDeviceResources. |
478 | 521 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
522 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
523 |
|
478 | 524 |
fetchImageResources |
525 |
"initialize heavily used device resources - to avoid rendering |
|
526 |
images again and again later; returns maximum extent of the images used. |
|
527 |
Could be redefined by subclass |
|
471 | 528 |
" |
494 | 529 |
|y x t| |
530 |
||
531 |
imageOpened isNil ifTrue:[ |
|
532 |
imageOpened := (self class imageOpened) onDevice:device. |
|
533 |
]. |
|
444 | 534 |
|
494 | 535 |
imageClosed isNil ifTrue:[ |
536 |
imageClosed := (self class imageClosed) onDevice:device. |
|
537 |
]. |
|
538 |
||
539 |
imageItem isNil ifTrue:[ |
|
540 |
imageItem := (self class imageItem) onDevice:device. |
|
541 |
]. |
|
478 | 542 |
|
471 | 543 |
y := imageClosed heightOn:self. |
544 |
x := imageClosed widthOn:self. |
|
444 | 545 |
|
471 | 546 |
(t := imageOpened heightOn:self) > y ifTrue:[y := t]. |
547 |
(t := imageOpened widthOn:self) > x ifTrue:[x := t]. |
|
490 | 548 |
|
549 |
(t := imageItem heightOn:self) > y ifTrue:[y := t]. |
|
550 |
(t := imageItem widthOn:self) > x ifTrue:[x := t]. |
|
551 |
||
471 | 552 |
^ x @ y |
478 | 553 |
|
444 | 554 |
! |
555 |
||
480 | 556 |
getFontParameters |
557 |
super getFontParameters. |
|
558 |
||
494 | 559 |
imageWidth notNil ifTrue:[ |
480 | 560 |
self refetchDeviceResources |
561 |
] |
|
562 |
! |
|
563 |
||
444 | 564 |
initialize |
471 | 565 |
"setup instance attributes |
566 |
" |
|
444 | 567 |
super initialize. |
485 | 568 |
showLines := true. |
494 | 569 |
showRoot := true. |
485 | 570 |
showDirectoryIndicator := false. |
494 | 571 |
textInset := 2. |
572 |
imageInset := 0. "/ set during indication enabled |
|
573 |
imageWidth := 8. "/ default: will change during startup |
|
478 | 574 |
! |
575 |
||
576 |
refetchDeviceResources |
|
577 |
"reinitialize heavily used device resources - to avoid rendering |
|
578 |
images again and again later |
|
579 |
" |
|
494 | 580 |
|extent x1 x2 y| |
478 | 581 |
|
490 | 582 |
extent := self fetchImageResources. |
494 | 583 |
imageInset := 0. |
478 | 584 |
|
494 | 585 |
showDirectoryIndicator ifTrue:[ |
586 |
openIndicator isNil ifTrue:[ |
|
587 |
openIndicator := (self class openIndicator) onDevice:device |
|
588 |
]. |
|
589 |
||
590 |
closeIndicator isNil ifTrue:[ |
|
591 |
closeIndicator := (self class closeIndicator) onDevice:device. |
|
592 |
]. |
|
593 |
||
594 |
x1 := (openIndicator widthOn:self) // 2. |
|
595 |
y := openIndicator heightOn:self. |
|
596 |
y > extent y ifTrue:[extent y:y]. |
|
597 |
extentOpenIndicator := Point x:x1 y:(y // 2). |
|
598 |
||
599 |
x2 := (closeIndicator widthOn:self) // 2. |
|
600 |
y := closeIndicator heightOn:self. |
|
601 |
y > extent y ifTrue:[extent y:y]. |
|
602 |
extentCloseIndicator := Point x:x2 y:(y // 2). |
|
603 |
||
604 |
x2 > x1 ifTrue:[x1 := x2]. |
|
605 |
||
606 |
(x1 := x1 + self class minImageInset) > (imageWidth // 2) ifTrue:[ |
|
607 |
imageInset := x1 - (imageWidth // 2). |
|
608 |
]. |
|
478 | 609 |
]. |
494 | 610 |
extent y >= fontHeight ifTrue:[ |
611 |
fontHeight := 1 + extent y. |
|
612 |
]. |
|
613 |
imageWidth := extent x. |
|
471 | 614 |
|
444 | 615 |
! ! |
616 |
||
483 | 617 |
!SelectionInTreeView methodsFor:'model'! |
444 | 618 |
|
619 |
getListFromModel |
|
620 |
"if I have a model, get my list from it using the listMessage. |
|
621 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
622 |
" |
|
483 | 623 |
super list:(self listFromModel) keepSelection:true |
624 |
! |
|
444 | 625 |
|
483 | 626 |
listFromModel |
627 |
"get list from model and return the new list. |
|
628 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
629 |
" |
|
630 |
|msg| |
|
444 | 631 |
|
468 | 632 |
widthOfWidestLine := nil. |
444 | 633 |
|
483 | 634 |
model notNil ifTrue:[ |
635 |
(msg := listMsg ? aspectMsg) notNil ifTrue:[ |
|
636 |
listOfNodes := model perform:msg. |
|
444 | 637 |
|
483 | 638 |
listOfNodes size ~~ 0 ifTrue:[ |
639 |
^ listOfNodes collect:[:n|n name] |
|
640 |
] |
|
641 |
] |
|
642 |
]. |
|
643 |
listOfNodes := #(). |
|
644 |
^ #() |
|
494 | 645 |
! |
646 |
||
647 |
model:aModel |
|
507 | 648 |
aModel notNil ifTrue:[ |
649 |
aModel showRoot:showRoot. |
|
650 |
]. |
|
494 | 651 |
super model:aModel |
444 | 652 |
! ! |
653 |
||
490 | 654 |
!SelectionInTreeView methodsFor:'private'! |
655 |
||
656 |
list:aList keepSelection:keepSelection |
|
657 |
|list| |
|
658 |
||
659 |
list := aList. |
|
660 |
||
661 |
list size == 0 ifTrue:[ |
|
662 |
listOfNodes := #() |
|
663 |
] ifFalse:[ |
|
664 |
(list first respondsTo:#hasChildren) ifTrue:[ |
|
665 |
listOfNodes := aList. |
|
666 |
list := listOfNodes collect:[:aNode| aNode name ]. |
|
667 |
] |
|
668 |
]. |
|
669 |
super list:list keepSelection:keepSelection |
|
670 |
! ! |
|
671 |
||
468 | 672 |
!SelectionInTreeView methodsFor:'private queries'! |
673 |
||
674 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
675 |
"return the length (in characters) of the longest line in a line-range |
|
676 |
" |
|
677 |
|max| |
|
678 |
||
679 |
max := self widthOfContents:firstLine and:lastLine. |
|
680 |
^ (max // fontWidth) + 1 |
|
681 |
! |
|
682 |
||
683 |
widthOfContents |
|
684 |
"return the width of the contents in pixels |
|
685 |
- used for scrollbar interface" |
|
686 |
||
687 |
list isNil ifTrue:[^ 0]. |
|
688 |
||
689 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
690 |
widthOfWidestLine := self widthOfContents:1 and:(self size). |
|
691 |
]. |
|
692 |
^ widthOfWidestLine + (leftMargin * 2) |
|
693 |
||
694 |
! |
|
695 |
||
696 |
widthOfContents:firstLine and:lastLine |
|
697 |
"return the length (in pixels) of the longest line in a line-range |
|
698 |
" |
|
699 |
|max "{ Class: SmallInteger }" |
|
700 |
thisLen "{ Class: SmallInteger }" |
|
701 |
first "{ Class: SmallInteger }" |
|
702 |
last "{ Class: SmallInteger }" | |
|
703 |
||
704 |
listOfNodes size == 0 ifTrue:[^ 0]. |
|
705 |
||
706 |
last := listOfNodes size. |
|
707 |
first := firstLine. |
|
708 |
||
709 |
(first > last) ifTrue:[^ 0]. |
|
710 |
||
711 |
(lastLine < last) ifTrue:[ |
|
712 |
last := lastLine |
|
713 |
]. |
|
714 |
max := 0. |
|
715 |
||
716 |
listOfNodes from:first to:last do:[:anItem||name| |
|
717 |
thisLen := self xOfStringNode:anItem. |
|
718 |
||
719 |
(name := anItem name) notNil ifTrue:[ |
|
720 |
thisLen := thisLen + (name widthOn:self). |
|
721 |
]. |
|
722 |
(thisLen > max) ifTrue:[ |
|
723 |
max := thisLen. |
|
724 |
] |
|
725 |
]. |
|
726 |
^ max + leftOffset. |
|
727 |
! |
|
728 |
||
729 |
withoutRedrawAt:anIndex put:aString |
|
730 |
"change a line without redisplay" |
|
731 |
||
732 |
|width| |
|
733 |
||
734 |
width := widthOfWidestLine. |
|
735 |
widthOfWidestLine := nil. |
|
736 |
||
737 |
super withoutRedrawAt:anIndex put:aString. |
|
738 |
||
739 |
(widthOfWidestLine := width) notNil ifTrue:[ |
|
740 |
width := self widthOfContents:anIndex and:anIndex. |
|
741 |
||
742 |
width > widthOfWidestLine ifTrue:[ |
|
743 |
widthOfWidestLine := width |
|
744 |
] ifFalse:[ |
|
745 |
widthOfWidestLine := nil "/ means: unknown |
|
746 |
] |
|
747 |
]. |
|
748 |
||
749 |
||
750 |
! ! |
|
751 |
||
483 | 752 |
!SelectionInTreeView methodsFor:'queries'! |
753 |
||
754 |
figureFor:aNode |
|
755 |
"access figure for a node |
|
756 |
" |
|
757 |
aNode hasChildren ifTrue:[ |
|
758 |
aNode isExpandable ifTrue:[ ^ imageClosed ] |
|
759 |
ifFalse:[ ^ imageOpened ] |
|
760 |
]. |
|
761 |
^ imageItem |
|
762 |
! |
|
763 |
||
764 |
indexOfNode:aNode |
|
765 |
"returns index of a node |
|
766 |
" |
|
767 |
^ listOfNodes findFirst:[:n| n == aNode ] |
|
768 |
! |
|
769 |
||
494 | 770 |
xOfFigureLevel:aLevel |
771 |
"origin x where to draw the icon |
|
772 |
" |
|
773 |
|l| |
|
774 |
||
775 |
showRoot ifTrue:[l := aLevel] |
|
776 |
ifFalse:[l := aLevel - 1]. |
|
777 |
||
778 |
showDirectoryIndicator ifFalse:[l := l - 1]. |
|
779 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
|
780 |
||
781 |
! |
|
782 |
||
483 | 783 |
xOfFigureNode:aNode |
784 |
"origin x where to draw the icon |
|
785 |
" |
|
494 | 786 |
^ self xOfFigureLevel:(aNode level) |
787 |
! |
|
490 | 788 |
|
494 | 789 |
xOfStringLevel:aLevel |
790 |
"origin x where to draw the text( label ) |
|
791 |
" |
|
792 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 793 |
|
794 |
! |
|
795 |
||
796 |
xOfStringNode:aNode |
|
797 |
"origin x where to draw the text( label ) |
|
798 |
" |
|
494 | 799 |
^ self xOfStringLevel:(aNode level) |
483 | 800 |
|
801 |
! ! |
|
802 |
||
444 | 803 |
!SelectionInTreeView methodsFor:'selection'! |
804 |
||
805 |
doubleClicked |
|
806 |
"handle a double click; collapse or expand selected entry |
|
807 |
in case of having children |
|
808 |
" |
|
507 | 809 |
|node| |
471 | 810 |
|
507 | 811 |
(node := self selectedNode) notNil ifTrue:[ |
812 |
self selectedNodeExpand:(node isExpandable). |
|
456 | 813 |
super doubleClicked. |
814 |
] |
|
478 | 815 |
|
456 | 816 |
! |
817 |
||
494 | 818 |
selectFromListOfNames:aListOfNames |
819 |
"set selection from a list of names |
|
820 |
" |
|
497 | 821 |
|node rdwNd| |
494 | 822 |
|
823 |
aListOfNames size < 1 ifTrue:[ |
|
824 |
^ self selection:nil |
|
825 |
]. |
|
826 |
||
827 |
node := model root. |
|
828 |
||
829 |
aListOfNames do:[:el||next| |
|
830 |
next := node detectChild:[:e|e name = el]. |
|
831 |
||
832 |
next notNil ifTrue:[ |
|
833 |
node hidden ifTrue:[ |
|
834 |
rdwNd isNil ifTrue:[ |
|
835 |
rdwNd := node. |
|
836 |
self selectNode:node. |
|
837 |
]. |
|
838 |
node expand |
|
839 |
]. |
|
840 |
node := next |
|
841 |
] |
|
842 |
]. |
|
843 |
||
844 |
rdwNd notNil ifTrue:[ |
|
845 |
model updateList. |
|
846 |
list := self listFromModel. |
|
847 |
self redrawFromLine:(self indexOfNode:rdwNd). |
|
848 |
self contentsChanged. |
|
849 |
]. |
|
850 |
self selectNode:node. |
|
851 |
||
852 |
! |
|
853 |
||
468 | 854 |
selectNode:aNode |
855 |
"change selection to a node |
|
856 |
" |
|
483 | 857 |
self selection:(self indexOfNode:aNode) |
468 | 858 |
|
859 |
||
860 |
! |
|
861 |
||
456 | 862 |
selectedIndex |
863 |
"get single selected index or 0 |
|
864 |
" |
|
483 | 865 |
selection size == 1 ifTrue:[^ selection first]. |
866 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 867 |
^ 0 |
444 | 868 |
! |
869 |
||
870 |
selectedNode |
|
871 |
"get the single selected node or nil |
|
872 |
" |
|
456 | 873 |
|idx| |
874 |
||
875 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
876 |
^ listOfNodes at:idx |
|
444 | 877 |
]. |
878 |
^ nil |
|
879 |
! ! |
|
880 |
||
507 | 881 |
!SelectionInTreeView methodsFor:'selection-actions'! |
882 |
||
883 |
selectedNodeAdd:something |
|
884 |
"add a node or collection of nodes after selected node |
|
885 |
" |
|
886 |
|node| |
|
887 |
||
888 |
something notNil ifTrue:[ |
|
889 |
(node := self selectedNode) notNil ifTrue:[ |
|
890 |
node parent notNil ifTrue:[ |
|
891 |
node isCollapsable ifTrue:[ |
|
892 |
model add:something beforeIndex:1 below:node |
|
893 |
] ifFalse:[ |
|
894 |
model add:something after:node |
|
895 |
] |
|
896 |
] ifFalse:[ |
|
897 |
model add:something beforeIndex:1 below:(self root) |
|
898 |
] |
|
899 |
] |
|
900 |
] |
|
901 |
||
902 |
! |
|
903 |
||
904 |
selectedNodeBecomeChildOfNext |
|
905 |
"become node a child of followd node |
|
906 |
" |
|
907 |
|idx node cprt nprt| |
|
908 |
||
909 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
910 |
idx := cprt indexOfChild:node. |
|
911 |
||
912 |
idx == cprt children size ifFalse:[ |
|
913 |
nprt := cprt childAt:(idx + 1). |
|
914 |
||
915 |
nprt notNil ifTrue:[ |
|
916 |
model removeDependent:self. |
|
917 |
model removeSelection. |
|
918 |
selection := nil. |
|
919 |
model collapse:nprt. |
|
920 |
model add:node beforeIndex:1 below:nprt. |
|
921 |
model addDependent:self. |
|
922 |
model expand:nprt. |
|
923 |
||
924 |
self selectNode:node. |
|
925 |
] |
|
926 |
] |
|
927 |
] |
|
928 |
! |
|
929 |
||
930 |
selectedNodeBecomeSisterOfParent |
|
931 |
"become node a sister of its current parent |
|
932 |
" |
|
933 |
|node cprt nprt| |
|
934 |
||
935 |
( (node := self selectedNode) isNil |
|
936 |
or:[(cprt := node parent) isNil |
|
937 |
or:[(nprt := cprt parent) isNil]] |
|
938 |
) ifFalse:[ |
|
939 |
model removeDependent:self. |
|
940 |
model removeSelection. |
|
941 |
selection := nil. |
|
942 |
model addDependent:self. |
|
943 |
||
944 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
|
945 |
self selectNode:node. |
|
946 |
] |
|
947 |
||
948 |
! |
|
949 |
||
950 |
selectedNodeChangeSequenceOrder:anOffset |
|
951 |
"move child 'anOffset' forward or backward in list of children |
|
952 |
" |
|
953 |
|idx node size parent| |
|
954 |
||
955 |
( (node := self selectedNode) notNil |
|
956 |
and:[(parent := node parent) notNil |
|
957 |
and:[(size := parent children size) > 1]] |
|
958 |
) ifTrue:[ |
|
959 |
idx := parent indexOfChild:node. |
|
960 |
||
961 |
model removeDependent:self. |
|
962 |
model removeSelection. |
|
963 |
selection := nil. |
|
964 |
model addDependent:self. |
|
965 |
||
966 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
967 |
idx := size |
|
968 |
] ifFalse:[ |
|
969 |
idx > size ifTrue:[idx := 1] |
|
970 |
]. |
|
971 |
model add:node beforeIndex:idx below:parent. |
|
972 |
self selectNode:node. |
|
973 |
] |
|
974 |
! |
|
975 |
||
976 |
selectedNodeExpand:doExpand |
|
977 |
"collapse or expand selected node |
|
978 |
" |
|
979 |
|node index| |
|
980 |
||
981 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
|
982 |
node := listOfNodes at:index. |
|
983 |
||
984 |
node hasChildren ifTrue:[ |
|
985 |
node isExpandable ifTrue:[ |
|
986 |
doExpand ifFalse:[^ self]. |
|
987 |
node expand |
|
988 |
] ifFalse:[ |
|
989 |
doExpand ifTrue:[^ self]. |
|
990 |
node collapse |
|
991 |
]. |
|
992 |
||
993 |
node numberOfChildren == 0 ifTrue:[ |
|
994 |
"/ no children; redraw selected line (image might change) |
|
995 |
self redrawLine:index. |
|
996 |
] ifFalse:[ |
|
997 |
"/ with children; update list and redraw to end. |
|
998 |
model updateList. |
|
999 |
list := self listFromModel. |
|
1000 |
self redrawFromLine:index. |
|
1001 |
self contentsChanged. |
|
1002 |
] |
|
1003 |
] |
|
1004 |
]. |
|
1005 |
! |
|
1006 |
||
1007 |
selectedNodesRemove |
|
1008 |
"remove selected nodes |
|
1009 |
" |
|
1010 |
model removeSelection. |
|
1011 |
self selection:nil. |
|
1012 |
||
1013 |
! ! |
|
1014 |
||
444 | 1015 |
!SelectionInTreeView class methodsFor:'documentation'! |
1016 |
||
1017 |
version |
|
507 | 1018 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.16 1997-09-02 12:20:38 ca Exp $' |
444 | 1019 |
! ! |