author | ca |
Mon, 11 Aug 1997 13:01:26 +0200 | |
changeset 490 | 1129f3cf5cea |
parent 485 | 26e87be7210f |
child 494 | 76d8c4e0b612 |
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 |
|
490 | 15 |
instanceVariableNames:'doubleClickSelectionBlock figuresWidth showLines listOfNodes |
16 |
imageOpened imageClosed imageItem imageInset textInset |
|
17 |
openIndicator closeIndicator showDirectoryIndicator |
|
18 |
indicatorWidthDiv2 indicatorHeightDiv2' |
|
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 |
56 |
||
57 |
[author:] |
|
58 |
Claus Atzkern |
|
59 |
" |
|
60 |
||
61 |
! |
|
62 |
||
63 |
examples |
|
64 |
" |
|
65 |
shows the tree of smalltalk classes: |
|
66 |
[exBegin] |
|
456 | 67 |
|top model sel root| |
68 |
||
69 |
root := TreeItem newAsTreeFromSmalltalkClass:Object. |
|
70 |
root expand. |
|
71 |
model := SelectionInTree new root:root. |
|
72 |
top := StandardSystemView new. |
|
73 |
top extent:300@300. |
|
74 |
||
75 |
sel := SelectionInTreeView new. |
|
76 |
sel model: model. |
|
77 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
78 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
79 |
top open. |
|
80 |
[exEnd] |
|
81 |
||
82 |
||
485 | 83 |
|
456 | 84 |
same, including nil-subclasses (i.e. really all classes): |
85 |
[exBegin] |
|
86 |
|top model sel root| |
|
444 | 87 |
|
456 | 88 |
root := TreeItem newAsTreeFromSmalltalkClass:nil. |
89 |
root expand. |
|
90 |
model := SelectionInTree new root:root. |
|
91 |
top := StandardSystemView new. |
|
92 |
top extent:300@300. |
|
93 |
||
94 |
sel := SelectionInTreeView new. |
|
95 |
sel model: model. |
|
96 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
97 |
||
98 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
99 |
top open. |
|
100 |
[exEnd] |
|
101 |
||
485 | 102 |
|
483 | 103 |
|
485 | 104 |
shows the tree of smalltalk classes; show directory indication and no |
105 |
lines. |
|
106 |
[exBegin] |
|
483 | 107 |
|top model sel root| |
108 |
||
109 |
root := TreeItem newAsTreeFromSmalltalkClass:Object. |
|
110 |
root expand. |
|
111 |
model := SelectionInTree new root:root. |
|
112 |
top := StandardSystemView new. |
|
113 |
top extent:300@300. |
|
114 |
||
115 |
sel := SelectionInTreeView new. |
|
485 | 116 |
sel showLines:false. |
117 |
sel showDirectoryIndicator:true. |
|
118 |
||
483 | 119 |
sel model: model. |
485 | 120 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
483 | 121 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
122 |
top open. |
|
485 | 123 |
[exEnd] |
124 |
" |
|
125 |
||
444 | 126 |
! ! |
127 |
||
128 |
!SelectionInTreeView class methodsFor:'constants'! |
|
129 |
||
490 | 130 |
shownIndicatorInset |
131 |
"returns the additional inset used when setting directory indication to enabled |
|
471 | 132 |
" |
490 | 133 |
^ 4 |
134 |
||
135 |
||
136 |
! ! |
|
137 |
||
138 |
!SelectionInTreeView class methodsFor:'default images'! |
|
139 |
||
140 |
closeIndicator |
|
141 |
CloseIndicator isNil ifTrue:[ |
|
142 |
CloseIndicator := Image fromFile:('xpmBitmaps/plus.xpm'). |
|
143 |
]. |
|
144 |
^ CloseIndicator |
|
145 |
" |
|
146 |
CloseIndicator := nil |
|
147 |
" |
|
471 | 148 |
! |
149 |
||
444 | 150 |
imageClosed |
151 |
ImageClosed isNil ifTrue:[ |
|
152 |
ImageClosed := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm'). |
|
153 |
]. |
|
154 |
^ ImageClosed |
|
155 |
" |
|
156 |
ImageClosed := nil |
|
157 |
" |
|
158 |
||
159 |
! |
|
160 |
||
161 |
imageItem |
|
162 |
ImageItem isNil ifTrue:[ |
|
163 |
ImageItem := Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm') |
|
164 |
||
165 |
]. |
|
166 |
^ ImageItem |
|
167 |
" |
|
168 |
ImageItem := nil |
|
169 |
" |
|
170 |
||
171 |
! |
|
172 |
||
173 |
imageOpened |
|
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 |
" |
|
490 | 182 |
! |
183 |
||
184 |
openIndicator |
|
185 |
OpenIndicator isNil ifTrue:[ |
|
186 |
OpenIndicator := Image fromFile:('xpmBitmaps/minus.xpm'). |
|
187 |
]. |
|
188 |
^ OpenIndicator |
|
189 |
" |
|
190 |
OpenIndicator := nil |
|
191 |
" |
|
192 |
||
444 | 193 |
! ! |
194 |
||
195 |
!SelectionInTreeView methodsFor:'accessing'! |
|
196 |
||
490 | 197 |
nodeAtIndex:anIndex |
198 |
"returns node at an index or nil |
|
199 |
" |
|
200 |
(anIndex notNil and:[anIndex ~~ 0 and:[anIndex <= listOfNodes size]]) ifTrue:[ |
|
201 |
^ listOfNodes at:anIndex |
|
202 |
]. |
|
203 |
^ nil |
|
204 |
! |
|
205 |
||
206 |
textInset |
|
207 |
"get the left inset of the text label |
|
208 |
" |
|
209 |
^ textInset |
|
210 |
! |
|
211 |
||
212 |
textInset:anInset |
|
213 |
"set the left inset of the text label |
|
214 |
" |
|
215 |
|inset| |
|
216 |
||
217 |
anInset ~~ textInset ifTrue:[ |
|
218 |
anInset >= 0 ifTrue:[ |
|
219 |
textInset := anInset. |
|
220 |
self invalidate |
|
221 |
] ifFalse:[ |
|
222 |
self error |
|
223 |
] |
|
224 |
]. |
|
225 |
! ! |
|
226 |
||
227 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
|
228 |
||
229 |
doubleClickSelectionBlock |
|
230 |
"get the conditionBlock; this block is evaluated before a doubleClick action |
|
231 |
on a node containg children will be performed. In case of returning false, the |
|
232 |
doubleClick will not be handled. |
|
233 |
" |
|
234 |
^ doubleClickSelectionBlock |
|
235 |
||
236 |
||
237 |
! |
|
238 |
||
239 |
doubleClickSelectionBlock:aBlock |
|
240 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
241 |
on a node containg children will be performed. In case of returning false, the |
|
242 |
doubleClick will not be handled. |
|
243 |
" |
|
244 |
doubleClickSelectionBlock := aBlock |
|
245 |
||
246 |
||
247 |
! |
|
248 |
||
249 |
showDirectoryIndicator |
|
250 |
"returns true if directories has an open/closed indicator |
|
251 |
" |
|
252 |
^ showDirectoryIndicator |
|
253 |
! |
|
254 |
||
255 |
showDirectoryIndicator:aState |
|
256 |
"set or clear open/closed indicator for directories |
|
257 |
" |
|
258 |
"show or hide lines |
|
259 |
" |
|
260 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
261 |
(showDirectoryIndicator := aState) ifTrue:[ |
|
262 |
imageInset := imageInset + self class shownIndicatorInset. |
|
263 |
] ifFalse:[ |
|
264 |
imageInset := imageInset - self class shownIndicatorInset. |
|
265 |
]. |
|
266 |
self invalidate |
|
267 |
]. |
|
268 |
! |
|
269 |
||
270 |
showLines |
|
271 |
"returns true if lines are shown |
|
272 |
" |
|
273 |
^ showLines |
|
274 |
! |
|
275 |
||
276 |
showLines:aState |
|
277 |
"show or hide lines |
|
278 |
" |
|
279 |
aState ~~ showLines ifTrue:[ |
|
280 |
showLines := aState. |
|
281 |
self invalidate |
|
282 |
]. |
|
283 |
! ! |
|
284 |
||
285 |
!SelectionInTreeView methodsFor:'accessing-images'! |
|
286 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
287 |
imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
288 |
"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
|
289 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
290 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
291 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
292 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
293 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
294 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
295 |
imageClosed:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
296 |
"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
|
297 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
298 |
imageClosed := something. |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
299 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
300 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
301 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
302 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
303 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
304 |
"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
|
305 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
306 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
307 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
308 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
309 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
310 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
311 |
imageItem:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
312 |
"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
|
313 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
314 |
imageItem := something. |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
315 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
316 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
317 |
! |
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 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
320 |
"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
|
321 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
322 |
^ imageOpened |
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 |
"Created: 3.7.1997 / 12:34:28 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
325 |
! |
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 |
imageOpened:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
328 |
"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
|
329 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
330 |
imageOpened := something. |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
331 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
332 |
"Created: 3.7.1997 / 12:34:28 / cg" |
471 | 333 |
! ! |
334 |
||
444 | 335 |
!SelectionInTreeView methodsFor:'drawing'! |
336 |
||
481 | 337 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
338 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 339 |
|
340 |
! |
|
341 |
||
342 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 343 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 344 |
|
345 |
! |
|
346 |
||
347 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 348 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 349 |
|
350 |
! |
|
351 |
||
352 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 353 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 354 |
|
355 |
! |
|
356 |
||
357 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 358 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
359 |
||
444 | 360 |
! |
361 |
||
362 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 363 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 364 |
|
365 |
! ! |
|
366 |
||
367 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
368 |
||
481 | 369 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
370 |
||
490 | 371 |
|nodeIndex listSize end fontHgDiv2 yBot yTop yCtr xFig2 figInset |
485 | 372 |
x x1 xFig xStr node level lvl idx image isCollapsable hasChildren radius extent xCross| |
481 | 373 |
|
374 |
nodeIndex := self visibleLineToAbsoluteLine:startVisLineNr. |
|
375 |
listSize := listOfNodes size. |
|
376 |
yTop := self yOfVisibleLine:startVisLineNr. |
|
377 |
end := endVisLineNr - startVisLineNr + 1. |
|
378 |
||
379 |
"/ clear rectangle line and set background color |
|
380 |
self paint:bg. |
|
381 |
self fillRectangleX:0 y:yTop width:width height:(end * fontHeight). |
|
382 |
||
383 |
nodeIndex isNil ifTrue:[^ self]. |
|
384 |
fontHgDiv2 := fontHeight // 2. |
|
490 | 385 |
xFig2 := figuresWidth // 2.. |
386 |
radius := xFig2 // 2 - 1. |
|
387 |
extent := radius + radius + 1. |
|
388 |
figInset := figuresWidth + imageInset. |
|
485 | 389 |
|
481 | 390 |
self paint:fg on:bg. |
391 |
||
392 |
(end := nodeIndex + end) > listSize ifTrue:[ |
|
393 |
end := listSize + 1 |
|
394 |
]. |
|
395 |
||
396 |
[nodeIndex < end] whileTrue:[ |
|
397 |
node := listOfNodes at:nodeIndex. |
|
398 |
yBot := yTop + fontHeight. |
|
399 |
yCtr := yTop + fontHgDiv2. |
|
400 |
image := self figureFor:node. |
|
401 |
||
485 | 402 |
(hasChildren := node hasChildren) ifTrue:[ |
403 |
isCollapsable := node isCollapsable. |
|
490 | 404 |
] ifFalse:[ |
405 |
isCollapsable := false |
|
485 | 406 |
]. |
407 |
||
481 | 408 |
(lvl := node level) == level ifFalse:[ |
485 | 409 |
level := lvl. |
410 |
xFig := self xOfFigureNode:node. |
|
411 |
xStr := self xOfStringNode:node. |
|
490 | 412 |
xCross := xFig + xFig2 - figInset. |
481 | 413 |
]. |
414 |
||
415 |
showLines ifTrue:[ |
|
485 | 416 |
(isCollapsable and:[node numberOfChildren ~~ 0]) ifTrue:[ |
490 | 417 |
x := xFig + xFig2. |
481 | 418 |
self displayLineFromX:x y:yCtr toX:x y:yBot |
419 |
]. |
|
420 |
"/ draw horizontal and vertical line |
|
490 | 421 |
nodeIndex == 1 ifFalse:[ "/ not for root |
422 |
self displayLineFromX:xCross y:yTop toX:xCross y:yCtr. "/ vertical |
|
423 |
]. |
|
485 | 424 |
self displayLineFromX:xCross y:yCtr toX:xFig y:yCtr. "/ horizontal |
481 | 425 |
|
426 |
"/ draw vertical lines |
|
427 |
idx := nodeIndex. |
|
428 |
||
429 |
idx ~~ listSize ifTrue:[ |
|
490 | 430 |
x := figInset - xFig2. |
481 | 431 |
|
432 |
[(lvl > 0 and:[(idx := idx + 1) <= listSize])] whileTrue:[ |
|
433 |
node := listOfNodes at:idx. |
|
434 |
||
435 |
node level > lvl ifFalse:[ |
|
436 |
x1 := (self xOfFigureNode:node) - x. |
|
437 |
self displayLineFromX:x1 y:yTop toX:x1 y:yBot. |
|
438 |
lvl := node level - 1 |
|
439 |
] |
|
440 |
] |
|
441 |
] |
|
442 |
]. |
|
443 |
||
444 |
"/ draw image |
|
445 |
self displayForm:image x:xFig y:(yCtr - (image height // 2)). |
|
446 |
||
447 |
"/ draw text label |
|
448 |
self drawLabelIndex:nodeIndex atX:xStr y:yCtr. |
|
449 |
||
485 | 450 |
(hasChildren and:[showDirectoryIndicator]) ifTrue:[ |
490 | 451 |
isCollapsable ifTrue:[image := openIndicator] |
452 |
ifFalse:[image := closeIndicator]. |
|
453 |
||
454 |
self displayForm:image |
|
455 |
x:(xCross - indicatorWidthDiv2) |
|
456 |
y:(yCtr - indicatorHeightDiv2) |
|
485 | 457 |
]. |
458 |
||
481 | 459 |
"/ setup next line |
460 |
nodeIndex := nodeIndex + 1. |
|
461 |
yTop := yBot. |
|
462 |
]. |
|
463 |
||
464 |
||
485 | 465 |
|
466 |
||
467 |
||
468 |
||
469 |
! |
|
470 |
||
444 | 471 |
drawLabelIndex:anIndex atX:x y:yCenter |
472 |
"draw text label at x and y centered |
|
473 |
" |
|
474 |
|y lbl| |
|
475 |
||
476 |
lbl := (listOfNodes at:anIndex) name. |
|
477 |
||
478 |
lbl notNil ifTrue:[ |
|
479 |
y := yCenter - ((lbl heightOn:self) // 2). |
|
480 |
||
481 |
(lbl respondsTo:#string) ifTrue:[ |
|
482 |
y := y + fontAscent. |
|
483 |
]. |
|
484 |
self displayOpaqueString:lbl x:x y:y. |
|
485 |
] |
|
486 |
! ! |
|
487 |
||
490 | 488 |
!SelectionInTreeView methodsFor:'event handling'! |
489 |
||
490 |
buttonMultiPress:button x:x y:y |
|
491 |
|node xFig| |
|
492 |
||
493 |
" |
|
494 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
495 |
(node := self selectedNode) notNil ifTrue:[ |
|
496 |
node hasChildren ifTrue:[ |
|
497 |
xFig := self xOfFigureNode:node. |
|
498 |
||
499 |
(x < xFig and:[x > (xFig - figuresWidth)]) ifTrue:[ |
|
500 |
^ self |
|
501 |
] |
|
502 |
] |
|
503 |
] |
|
504 |
]. |
|
505 |
" |
|
506 |
super buttonMultiPress:button x:x y:y |
|
507 |
! ! |
|
508 |
||
444 | 509 |
!SelectionInTreeView methodsFor:'initialization'! |
510 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
511 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
512 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
513 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
514 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
515 |
super fetchDeviceResources. |
478 | 516 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
517 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
518 |
|
478 | 519 |
fetchImageResources |
520 |
"initialize heavily used device resources - to avoid rendering |
|
521 |
images again and again later; returns maximum extent of the images used. |
|
522 |
Could be redefined by subclass |
|
471 | 523 |
" |
490 | 524 |
|y x t inset| |
444 | 525 |
|
490 | 526 |
imageOpened := (self class imageOpened) onDevice:device. |
527 |
imageClosed := (self class imageClosed) onDevice:device. |
|
528 |
imageItem := (self class imageItem) onDevice:device. |
|
529 |
openIndicator := (self class openIndicator) onDevice:device. |
|
530 |
closeIndicator := (self class closeIndicator) onDevice:device. |
|
478 | 531 |
|
471 | 532 |
y := imageClosed heightOn:self. |
533 |
x := imageClosed widthOn:self. |
|
444 | 534 |
|
471 | 535 |
(t := imageOpened heightOn:self) > y ifTrue:[y := t]. |
536 |
(t := imageOpened widthOn:self) > x ifTrue:[x := t]. |
|
490 | 537 |
|
538 |
(t := imageItem heightOn:self) > y ifTrue:[y := t]. |
|
539 |
(t := imageItem widthOn:self) > x ifTrue:[x := t]. |
|
540 |
||
471 | 541 |
(t := imageItem heightOn:self) > y ifTrue:[y := t]. |
542 |
(t := imageItem widthOn:self) > x ifTrue:[x := t]. |
|
543 |
||
490 | 544 |
indicatorWidthDiv2 := openIndicator heightOn:self. |
545 |
indicatorHeightDiv2 := openIndicator widthOn:self. |
|
546 |
inset := self class shownIndicatorInset. |
|
547 |
||
548 |
(t := inset + indicatorWidthDiv2) > y ifTrue:[y := t]. |
|
549 |
(t := inset + indicatorHeightDiv2) > x ifTrue:[x := t]. |
|
550 |
||
551 |
indicatorWidthDiv2 := indicatorWidthDiv2 // 2. |
|
552 |
indicatorHeightDiv2 := indicatorHeightDiv2 // 2. |
|
553 |
||
554 |
(t := 4 + (closeIndicator heightOn:self)) > y ifTrue:[y := t]. |
|
555 |
(t := 4 + (closeIndicator widthOn:self )) > x ifTrue:[x := t]. |
|
556 |
||
557 |
||
471 | 558 |
^ x @ y |
478 | 559 |
|
444 | 560 |
! |
561 |
||
480 | 562 |
getFontParameters |
563 |
super getFontParameters. |
|
564 |
||
565 |
figuresWidth notNil ifTrue:[ |
|
566 |
self refetchDeviceResources |
|
567 |
] |
|
568 |
! |
|
569 |
||
444 | 570 |
initialize |
471 | 571 |
"setup instance attributes |
572 |
" |
|
444 | 573 |
super initialize. |
485 | 574 |
showLines := true. |
575 |
showDirectoryIndicator := false. |
|
490 | 576 |
textInset := 2. |
577 |
imageInset := 0. |
|
578 |
figuresWidth := 18. "/ default: will change during startup |
|
478 | 579 |
! |
580 |
||
581 |
refetchDeviceResources |
|
582 |
"reinitialize heavily used device resources - to avoid rendering |
|
583 |
images again and again later |
|
584 |
" |
|
480 | 585 |
|y extent| |
478 | 586 |
|
490 | 587 |
extent := self fetchImageResources. |
478 | 588 |
|
589 |
extent y > fontHeight ifTrue:[ |
|
480 | 590 |
fontHeight := extent y. |
478 | 591 |
]. |
480 | 592 |
|
490 | 593 |
figuresWidth := extent x. |
471 | 594 |
|
444 | 595 |
! ! |
596 |
||
483 | 597 |
!SelectionInTreeView methodsFor:'model'! |
444 | 598 |
|
599 |
getListFromModel |
|
600 |
"if I have a model, get my list from it using the listMessage. |
|
601 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
602 |
" |
|
483 | 603 |
super list:(self listFromModel) keepSelection:true |
604 |
! |
|
444 | 605 |
|
483 | 606 |
listFromModel |
607 |
"get list from model and return the new list. |
|
608 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
609 |
" |
|
610 |
|msg| |
|
444 | 611 |
|
468 | 612 |
widthOfWidestLine := nil. |
444 | 613 |
|
483 | 614 |
model notNil ifTrue:[ |
615 |
(msg := listMsg ? aspectMsg) notNil ifTrue:[ |
|
616 |
listOfNodes := model perform:msg. |
|
444 | 617 |
|
483 | 618 |
listOfNodes size ~~ 0 ifTrue:[ |
619 |
^ listOfNodes collect:[:n|n name] |
|
620 |
] |
|
621 |
] |
|
622 |
]. |
|
623 |
listOfNodes := #(). |
|
624 |
^ #() |
|
444 | 625 |
! ! |
626 |
||
490 | 627 |
!SelectionInTreeView methodsFor:'private'! |
628 |
||
629 |
list:aList keepSelection:keepSelection |
|
630 |
|list| |
|
631 |
||
632 |
list := aList. |
|
633 |
||
634 |
list size == 0 ifTrue:[ |
|
635 |
listOfNodes := #() |
|
636 |
] ifFalse:[ |
|
637 |
(list first respondsTo:#hasChildren) ifTrue:[ |
|
638 |
listOfNodes := aList. |
|
639 |
list := listOfNodes collect:[:aNode| aNode name ]. |
|
640 |
] |
|
641 |
]. |
|
642 |
super list:list keepSelection:keepSelection |
|
643 |
! ! |
|
644 |
||
468 | 645 |
!SelectionInTreeView methodsFor:'private queries'! |
646 |
||
647 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
648 |
"return the length (in characters) of the longest line in a line-range |
|
649 |
" |
|
650 |
|max| |
|
651 |
||
652 |
max := self widthOfContents:firstLine and:lastLine. |
|
653 |
^ (max // fontWidth) + 1 |
|
654 |
! |
|
655 |
||
656 |
widthOfContents |
|
657 |
"return the width of the contents in pixels |
|
658 |
- used for scrollbar interface" |
|
659 |
||
660 |
|max| |
|
661 |
||
662 |
list isNil ifTrue:[^ 0]. |
|
663 |
||
664 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
665 |
widthOfWidestLine := self widthOfContents:1 and:(self size). |
|
666 |
]. |
|
667 |
^ widthOfWidestLine + (leftMargin * 2) |
|
668 |
||
669 |
! |
|
670 |
||
671 |
widthOfContents:firstLine and:lastLine |
|
672 |
"return the length (in pixels) of the longest line in a line-range |
|
673 |
" |
|
674 |
|max "{ Class: SmallInteger }" |
|
675 |
thisLen "{ Class: SmallInteger }" |
|
676 |
first "{ Class: SmallInteger }" |
|
677 |
last "{ Class: SmallInteger }" | |
|
678 |
||
679 |
listOfNodes size == 0 ifTrue:[^ 0]. |
|
680 |
||
681 |
last := listOfNodes size. |
|
682 |
first := firstLine. |
|
683 |
||
684 |
(first > last) ifTrue:[^ 0]. |
|
685 |
||
686 |
(lastLine < last) ifTrue:[ |
|
687 |
last := lastLine |
|
688 |
]. |
|
689 |
max := 0. |
|
690 |
||
691 |
listOfNodes from:first to:last do:[:anItem||name| |
|
692 |
thisLen := self xOfStringNode:anItem. |
|
693 |
||
694 |
(name := anItem name) notNil ifTrue:[ |
|
695 |
thisLen := thisLen + (name widthOn:self). |
|
696 |
]. |
|
697 |
(thisLen > max) ifTrue:[ |
|
698 |
max := thisLen. |
|
699 |
] |
|
700 |
]. |
|
701 |
^ max + leftOffset. |
|
702 |
! |
|
703 |
||
704 |
withoutRedrawAt:anIndex put:aString |
|
705 |
"change a line without redisplay" |
|
706 |
||
707 |
|width| |
|
708 |
||
709 |
width := widthOfWidestLine. |
|
710 |
widthOfWidestLine := nil. |
|
711 |
||
712 |
super withoutRedrawAt:anIndex put:aString. |
|
713 |
||
714 |
(widthOfWidestLine := width) notNil ifTrue:[ |
|
715 |
width := self widthOfContents:anIndex and:anIndex. |
|
716 |
||
717 |
width > widthOfWidestLine ifTrue:[ |
|
718 |
widthOfWidestLine := width |
|
719 |
] ifFalse:[ |
|
720 |
widthOfWidestLine := nil "/ means: unknown |
|
721 |
] |
|
722 |
]. |
|
723 |
||
724 |
||
725 |
! ! |
|
726 |
||
483 | 727 |
!SelectionInTreeView methodsFor:'queries'! |
728 |
||
729 |
figureFor:aNode |
|
730 |
"access figure for a node |
|
731 |
" |
|
732 |
aNode hasChildren ifTrue:[ |
|
733 |
aNode isExpandable ifTrue:[ ^ imageClosed ] |
|
734 |
ifFalse:[ ^ imageOpened ] |
|
735 |
]. |
|
736 |
^ imageItem |
|
737 |
! |
|
738 |
||
739 |
indexOfNode:aNode |
|
740 |
"returns index of a node |
|
741 |
" |
|
742 |
^ listOfNodes findFirst:[:n| n == aNode ] |
|
743 |
! |
|
744 |
||
745 |
xOfFigureNode:aNode |
|
746 |
"origin x where to draw the icon |
|
747 |
" |
|
490 | 748 |
|level| |
749 |
||
750 |
level := aNode level. |
|
751 |
||
752 |
showDirectoryIndicator ifFalse:[ |
|
753 |
level := level - 1 |
|
754 |
]. |
|
755 |
^ (level * (imageInset + figuresWidth)) - leftOffset |
|
483 | 756 |
|
757 |
! |
|
758 |
||
759 |
xOfStringNode:aNode |
|
760 |
"origin x where to draw the text( label ) |
|
761 |
" |
|
490 | 762 |
^ (self xOfFigureNode:aNode) + figuresWidth + textInset |
483 | 763 |
|
764 |
! ! |
|
765 |
||
444 | 766 |
!SelectionInTreeView methodsFor:'selection'! |
767 |
||
768 |
doubleClicked |
|
769 |
"handle a double click; collapse or expand selected entry |
|
770 |
in case of having children |
|
771 |
" |
|
483 | 772 |
|node index| |
444 | 773 |
|
483 | 774 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
775 |
node := listOfNodes at:index. |
|
471 | 776 |
|
483 | 777 |
node hasChildren ifTrue:[ |
778 |
"/ node has children |
|
779 |
( doubleClickSelectionBlock isNil |
|
780 |
or:[doubleClickSelectionBlock value:index]) ifFalse:[ |
|
781 |
^ self |
|
478 | 782 |
]. |
483 | 783 |
node isExpandable ifTrue:[node expand] |
784 |
ifFalse:[node collapse]. |
|
785 |
||
471 | 786 |
node numberOfChildren == 0 ifTrue:[ |
483 | 787 |
"/ no children; redraw selected line (image might change) |
788 |
self redrawLine:index. |
|
471 | 789 |
] ifFalse:[ |
483 | 790 |
"/ with children; update list and redraw to end. |
791 |
model updateList. |
|
792 |
list := self listFromModel. |
|
793 |
self redrawFromLine:index. |
|
794 |
self contentsChanged. |
|
471 | 795 |
] |
456 | 796 |
]. |
797 |
super doubleClicked. |
|
798 |
] |
|
478 | 799 |
|
456 | 800 |
! |
801 |
||
468 | 802 |
selectNode:aNode |
803 |
"change selection to a node |
|
804 |
" |
|
483 | 805 |
self selection:(self indexOfNode:aNode) |
468 | 806 |
|
807 |
||
808 |
! |
|
809 |
||
456 | 810 |
selectedIndex |
811 |
"get single selected index or 0 |
|
812 |
" |
|
483 | 813 |
selection size == 1 ifTrue:[^ selection first]. |
814 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 815 |
^ 0 |
444 | 816 |
! |
817 |
||
818 |
selectedNode |
|
819 |
"get the single selected node or nil |
|
820 |
" |
|
456 | 821 |
|idx| |
822 |
||
823 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
824 |
^ listOfNodes at:idx |
|
444 | 825 |
]. |
826 |
^ nil |
|
827 |
! ! |
|
828 |
||
829 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
830 |
||
831 |
version |
|
490 | 832 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.13 1997-08-11 11:01:26 ca Exp $' |
444 | 833 |
! ! |