author | ca |
Tue, 05 Aug 1997 08:35:18 +0200 | |
changeset 483 | 1dad61b63e9d |
parent 481 | 91b3f1788cea |
child 485 | 26e87be7210f |
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 |
|
478 | 15 |
instanceVariableNames:'doubleClickSelectionBlock figuresWidth leftIndent |
483 | 16 |
figuresWidthDiv2 figuresInset showLines listOfNodes imageOpened |
17 |
imageClosed imageItem' |
|
444 | 18 |
classVariableNames:'ImageOpened ImageClosed ImageItem' |
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Text' |
|
21 |
! |
|
22 |
||
23 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like) |
|
43 |
lists and adds the functions to show/hide subtrees. |
|
456 | 44 |
Requires SelectionInTree as model and TreeItem (or compatible) list entries. |
444 | 45 |
|
456 | 46 |
This class obsoletes SelectionInTreeView, which is no longer |
446 | 47 |
maintained but kept for backward compatibility. |
48 |
||
49 |
||
444 | 50 |
[see also:] |
456 | 51 |
SelectionInTree |
52 |
TreeItem |
|
53 |
SelectionInTreeView |
|
444 | 54 |
SelectionInListView |
55 |
||
56 |
[author:] |
|
57 |
Claus Atzkern |
|
58 |
" |
|
59 |
||
60 |
! |
|
61 |
||
62 |
examples |
|
63 |
" |
|
64 |
shows the tree of smalltalk classes: |
|
65 |
[exBegin] |
|
456 | 66 |
|top model sel root| |
67 |
||
68 |
root := TreeItem newAsTreeFromSmalltalkClass:Object. |
|
69 |
root expand. |
|
70 |
model := SelectionInTree new root:root. |
|
71 |
top := StandardSystemView new. |
|
72 |
top extent:300@300. |
|
73 |
||
74 |
sel := SelectionInTreeView new. |
|
75 |
sel model: model. |
|
76 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
77 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
78 |
top open. |
|
79 |
[exEnd] |
|
80 |
||
81 |
||
82 |
same, including nil-subclasses (i.e. really all classes): |
|
83 |
[exBegin] |
|
84 |
|top model sel root| |
|
444 | 85 |
|
456 | 86 |
root := TreeItem newAsTreeFromSmalltalkClass:nil. |
87 |
root expand. |
|
88 |
model := SelectionInTree new root:root. |
|
89 |
top := StandardSystemView new. |
|
90 |
top extent:300@300. |
|
91 |
||
92 |
sel := SelectionInTreeView new. |
|
93 |
sel model: model. |
|
94 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
95 |
||
96 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
97 |
top open. |
|
98 |
[exEnd] |
|
99 |
" |
|
100 |
||
483 | 101 |
! |
102 |
||
103 |
test |
|
104 |
" |
|
105 |
SelectionInTreeView test |
|
106 |
" |
|
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. |
|
116 |
sel model: model. |
|
117 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
118 |
top open. |
|
444 | 119 |
! ! |
120 |
||
121 |
!SelectionInTreeView class methodsFor:'constants'! |
|
122 |
||
471 | 123 |
figuresInset |
124 |
"returns horizontal right and left inset of a figure |
|
125 |
" |
|
126 |
^ 2 |
|
127 |
! |
|
128 |
||
444 | 129 |
imageClosed |
130 |
ImageClosed isNil ifTrue:[ |
|
131 |
ImageClosed := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm'). |
|
132 |
]. |
|
133 |
^ ImageClosed |
|
134 |
" |
|
135 |
ImageClosed := nil |
|
136 |
" |
|
137 |
||
138 |
! |
|
139 |
||
140 |
imageItem |
|
141 |
ImageItem isNil ifTrue:[ |
|
142 |
ImageItem := Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm') |
|
143 |
||
144 |
]. |
|
145 |
^ ImageItem |
|
146 |
" |
|
147 |
ImageItem := nil |
|
148 |
" |
|
149 |
||
150 |
! |
|
151 |
||
152 |
imageOpened |
|
153 |
ImageOpened isNil ifTrue:[ |
|
154 |
ImageOpened := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm'). |
|
155 |
||
156 |
]. |
|
157 |
^ ImageOpened |
|
158 |
" |
|
159 |
ImageOpened := nil |
|
160 |
" |
|
161 |
! ! |
|
162 |
||
163 |
!SelectionInTreeView methodsFor:'accessing'! |
|
164 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
165 |
imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
166 |
"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
|
167 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
168 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
169 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
170 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
171 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
172 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
173 |
imageClosed:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
174 |
"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
|
175 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
176 |
imageClosed := something. |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
177 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
178 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
179 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
180 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
181 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
182 |
"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
|
183 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
184 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
185 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
186 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
187 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
188 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
189 |
imageItem:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
190 |
"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
|
191 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
192 |
imageItem := something. |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
193 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
194 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
195 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
196 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
197 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
198 |
"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
|
199 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
200 |
^ imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
201 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
202 |
"Created: 3.7.1997 / 12:34:28 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
203 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
204 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
205 |
imageOpened:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
206 |
"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
|
207 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
208 |
imageOpened := something. |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
209 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
210 |
"Created: 3.7.1997 / 12:34:28 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
211 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
212 |
|
444 | 213 |
list:aList keepSelection:keepSelection |
214 |
|list| |
|
215 |
||
216 |
list := aList. |
|
217 |
||
218 |
list size == 0 ifTrue:[ |
|
219 |
listOfNodes := #() |
|
220 |
] ifFalse:[ |
|
221 |
(list first respondsTo:#hasChildren) ifTrue:[ |
|
222 |
listOfNodes := aList. |
|
223 |
list := listOfNodes collect:[:aNode| aNode name ]. |
|
224 |
] |
|
225 |
]. |
|
226 |
super list:list keepSelection:keepSelection |
|
227 |
! ! |
|
228 |
||
471 | 229 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
230 |
||
478 | 231 |
doubleClickSelectionBlock |
232 |
"get the conditionBlock; this block is evaluated before a doubleClick action |
|
233 |
on a node containg children will be performed. In case of returning false, the |
|
234 |
doubleClick will not be handled. |
|
235 |
" |
|
236 |
^ doubleClickSelectionBlock |
|
237 |
||
238 |
||
239 |
! |
|
240 |
||
241 |
doubleClickSelectionBlock:aBlock |
|
242 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
243 |
on a node containg children will be performed. In case of returning false, the |
|
244 |
doubleClick will not be handled. |
|
245 |
" |
|
246 |
doubleClickSelectionBlock := aBlock |
|
247 |
||
248 |
||
249 |
! |
|
250 |
||
471 | 251 |
showLines |
252 |
"returns true if lines are shown |
|
253 |
" |
|
254 |
^ showLines |
|
255 |
! |
|
256 |
||
257 |
showLines:aState |
|
258 |
"show or hide lines |
|
259 |
" |
|
260 |
aState ~~ showLines ifTrue:[ |
|
261 |
showLines := aState. |
|
262 |
self invalidate |
|
263 |
]. |
|
264 |
! ! |
|
265 |
||
444 | 266 |
!SelectionInTreeView methodsFor:'drawing'! |
267 |
||
481 | 268 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
269 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 270 |
|
271 |
! |
|
272 |
||
273 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 274 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 275 |
|
276 |
! |
|
277 |
||
278 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 279 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 280 |
|
281 |
! |
|
282 |
||
283 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 284 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 285 |
|
286 |
! |
|
287 |
||
288 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 289 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
290 |
||
444 | 291 |
! |
292 |
||
293 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 294 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 295 |
|
296 |
! ! |
|
297 |
||
298 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
299 |
||
481 | 300 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
301 |
||
302 |
|nodeIndex listSize end fontHgDiv2 yBot yTop yCtr |
|
303 |
x x1 xFig xStr node level lvl idx image| |
|
304 |
||
305 |
nodeIndex := self visibleLineToAbsoluteLine:startVisLineNr. |
|
306 |
listSize := listOfNodes size. |
|
307 |
yTop := self yOfVisibleLine:startVisLineNr. |
|
308 |
end := endVisLineNr - startVisLineNr + 1. |
|
309 |
||
310 |
"/ clear rectangle line and set background color |
|
311 |
self paint:bg. |
|
312 |
self fillRectangleX:0 y:yTop width:width height:(end * fontHeight). |
|
313 |
||
314 |
nodeIndex isNil ifTrue:[^ self]. |
|
315 |
fontHgDiv2 := fontHeight // 2. |
|
316 |
self paint:fg on:bg. |
|
317 |
||
318 |
(end := nodeIndex + end) > listSize ifTrue:[ |
|
319 |
end := listSize + 1 |
|
320 |
]. |
|
321 |
||
322 |
[nodeIndex < end] whileTrue:[ |
|
323 |
node := listOfNodes at:nodeIndex. |
|
324 |
yBot := yTop + fontHeight. |
|
325 |
yCtr := yTop + fontHgDiv2. |
|
326 |
image := self figureFor:node. |
|
327 |
||
328 |
(lvl := node level) == level ifFalse:[ |
|
329 |
level := lvl. |
|
330 |
xFig := self xOfFigureNode:node. |
|
331 |
xStr := self xOfStringNode:node. |
|
332 |
]. |
|
333 |
||
334 |
showLines ifTrue:[ |
|
335 |
x := xFig + figuresWidthDiv2. |
|
336 |
||
337 |
(node isCollapsable and:[node numberOfChildren ~~ 0]) ifTrue:[ |
|
338 |
self displayLineFromX:x y:yCtr toX:x y:yBot |
|
339 |
]. |
|
340 |
"/ draw horizontal and vertical line |
|
341 |
x1 := x - leftIndent. |
|
342 |
self displayLineFromX:x1 y:yTop toX:x1 y:yCtr. "/ vertical |
|
343 |
self displayLineFromX:x1 y:yCtr toX:xFig y:yCtr. "/ horizontal |
|
344 |
||
345 |
"/ draw vertical lines |
|
346 |
idx := nodeIndex. |
|
347 |
||
348 |
idx ~~ listSize ifTrue:[ |
|
349 |
x := leftIndent - figuresWidthDiv2. |
|
350 |
||
351 |
[(lvl > 0 and:[(idx := idx + 1) <= listSize])] whileTrue:[ |
|
352 |
node := listOfNodes at:idx. |
|
353 |
||
354 |
node level > lvl ifFalse:[ |
|
355 |
x1 := (self xOfFigureNode:node) - x. |
|
356 |
self displayLineFromX:x1 y:yTop toX:x1 y:yBot. |
|
357 |
lvl := node level - 1 |
|
358 |
] |
|
359 |
] |
|
360 |
] |
|
361 |
]. |
|
362 |
||
363 |
"/ draw image |
|
364 |
self displayForm:image x:xFig y:(yCtr - (image height // 2)). |
|
365 |
||
366 |
"/ draw text label |
|
367 |
self drawLabelIndex:nodeIndex atX:xStr y:yCtr. |
|
368 |
||
369 |
"/ setup next line |
|
370 |
nodeIndex := nodeIndex + 1. |
|
371 |
yTop := yBot. |
|
372 |
]. |
|
373 |
||
374 |
||
375 |
! |
|
376 |
||
444 | 377 |
drawLabelIndex:anIndex atX:x y:yCenter |
378 |
"draw text label at x and y centered |
|
379 |
" |
|
380 |
|y lbl| |
|
381 |
||
382 |
lbl := (listOfNodes at:anIndex) name. |
|
383 |
||
384 |
lbl notNil ifTrue:[ |
|
385 |
y := yCenter - ((lbl heightOn:self) // 2). |
|
386 |
||
387 |
(lbl respondsTo:#string) ifTrue:[ |
|
388 |
y := y + fontAscent. |
|
389 |
]. |
|
390 |
self displayOpaqueString:lbl x:x y:y. |
|
391 |
] |
|
392 |
! ! |
|
393 |
||
394 |
!SelectionInTreeView methodsFor:'initialization'! |
|
395 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
396 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
397 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
398 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
399 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
400 |
super fetchDeviceResources. |
478 | 401 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
402 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
403 |
|
478 | 404 |
fetchImageResources |
405 |
"initialize heavily used device resources - to avoid rendering |
|
406 |
images again and again later; returns maximum extent of the images used. |
|
407 |
Could be redefined by subclass |
|
471 | 408 |
" |
409 |
|y x t| |
|
444 | 410 |
|
478 | 411 |
imageOpened := (self class imageOpened) onDevice:device. |
412 |
imageClosed := (self class imageClosed) onDevice:device. |
|
413 |
imageItem := (self class imageItem) onDevice:device. |
|
414 |
||
471 | 415 |
y := imageClosed heightOn:self. |
416 |
x := imageClosed widthOn:self. |
|
444 | 417 |
|
471 | 418 |
(t := imageOpened heightOn:self) > y ifTrue:[y := t]. |
419 |
(t := imageOpened widthOn:self) > x ifTrue:[x := t]. |
|
420 |
(t := imageItem heightOn:self) > y ifTrue:[y := t]. |
|
421 |
(t := imageItem widthOn:self) > x ifTrue:[x := t]. |
|
422 |
||
423 |
^ x @ y |
|
478 | 424 |
|
444 | 425 |
! |
426 |
||
480 | 427 |
getFontParameters |
428 |
super getFontParameters. |
|
429 |
||
430 |
figuresWidth notNil ifTrue:[ |
|
431 |
self refetchDeviceResources |
|
432 |
] |
|
433 |
! |
|
434 |
||
444 | 435 |
initialize |
471 | 436 |
"setup instance attributes |
437 |
" |
|
444 | 438 |
super initialize. |
471 | 439 |
showLines := true. |
478 | 440 |
figuresWidth := 18. "/ default: will change during startup |
441 |
figuresInset := 2. "/ default: will change during startup |
|
442 |
leftIndent := figuresWidth + figuresInset. "/ default: will change during startup |
|
443 |
figuresWidthDiv2 := figuresWidth // 2. "/ default: will change during startup |
|
444 |
! |
|
445 |
||
446 |
refetchDeviceResources |
|
447 |
"reinitialize heavily used device resources - to avoid rendering |
|
448 |
images again and again later |
|
449 |
" |
|
480 | 450 |
|y extent| |
478 | 451 |
|
452 |
figuresInset := self class figuresInset. |
|
453 |
extent := self fetchImageResources. |
|
454 |
||
455 |
extent y > fontHeight ifTrue:[ |
|
480 | 456 |
fontHeight := extent y. |
478 | 457 |
]. |
480 | 458 |
|
478 | 459 |
figuresWidth := extent x. |
460 |
leftIndent := figuresInset + figuresWidth. |
|
461 |
figuresWidthDiv2 := figuresWidth // 2. |
|
471 | 462 |
|
444 | 463 |
! ! |
464 |
||
483 | 465 |
!SelectionInTreeView methodsFor:'model'! |
444 | 466 |
|
467 |
getListFromModel |
|
468 |
"if I have a model, get my list from it using the listMessage. |
|
469 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
470 |
" |
|
483 | 471 |
super list:(self listFromModel) keepSelection:true |
472 |
! |
|
444 | 473 |
|
483 | 474 |
listFromModel |
475 |
"get list from model and return the new list. |
|
476 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
477 |
" |
|
478 |
|msg| |
|
444 | 479 |
|
468 | 480 |
widthOfWidestLine := nil. |
444 | 481 |
|
483 | 482 |
model notNil ifTrue:[ |
483 |
(msg := listMsg ? aspectMsg) notNil ifTrue:[ |
|
484 |
listOfNodes := model perform:msg. |
|
444 | 485 |
|
483 | 486 |
listOfNodes size ~~ 0 ifTrue:[ |
487 |
^ listOfNodes collect:[:n|n name] |
|
488 |
] |
|
489 |
] |
|
490 |
]. |
|
491 |
listOfNodes := #(). |
|
492 |
^ #() |
|
444 | 493 |
! ! |
494 |
||
468 | 495 |
!SelectionInTreeView methodsFor:'private queries'! |
496 |
||
497 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
498 |
"return the length (in characters) of the longest line in a line-range |
|
499 |
" |
|
500 |
|max| |
|
501 |
||
502 |
max := self widthOfContents:firstLine and:lastLine. |
|
503 |
^ (max // fontWidth) + 1 |
|
504 |
! |
|
505 |
||
506 |
widthOfContents |
|
507 |
"return the width of the contents in pixels |
|
508 |
- used for scrollbar interface" |
|
509 |
||
510 |
|max| |
|
511 |
||
512 |
list isNil ifTrue:[^ 0]. |
|
513 |
||
514 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
515 |
widthOfWidestLine := self widthOfContents:1 and:(self size). |
|
516 |
]. |
|
517 |
^ widthOfWidestLine + (leftMargin * 2) |
|
518 |
||
519 |
! |
|
520 |
||
521 |
widthOfContents:firstLine and:lastLine |
|
522 |
"return the length (in pixels) of the longest line in a line-range |
|
523 |
" |
|
524 |
|max "{ Class: SmallInteger }" |
|
525 |
thisLen "{ Class: SmallInteger }" |
|
526 |
first "{ Class: SmallInteger }" |
|
527 |
last "{ Class: SmallInteger }" | |
|
528 |
||
529 |
listOfNodes size == 0 ifTrue:[^ 0]. |
|
530 |
||
531 |
last := listOfNodes size. |
|
532 |
first := firstLine. |
|
533 |
||
534 |
(first > last) ifTrue:[^ 0]. |
|
535 |
||
536 |
(lastLine < last) ifTrue:[ |
|
537 |
last := lastLine |
|
538 |
]. |
|
539 |
max := 0. |
|
540 |
||
541 |
listOfNodes from:first to:last do:[:anItem||name| |
|
542 |
thisLen := self xOfStringNode:anItem. |
|
543 |
||
544 |
(name := anItem name) notNil ifTrue:[ |
|
545 |
thisLen := thisLen + (name widthOn:self). |
|
546 |
]. |
|
547 |
(thisLen > max) ifTrue:[ |
|
548 |
max := thisLen. |
|
549 |
] |
|
550 |
]. |
|
551 |
^ max + leftOffset. |
|
552 |
! |
|
553 |
||
554 |
withoutRedrawAt:anIndex put:aString |
|
555 |
"change a line without redisplay" |
|
556 |
||
557 |
|width| |
|
558 |
||
559 |
width := widthOfWidestLine. |
|
560 |
widthOfWidestLine := nil. |
|
561 |
||
562 |
super withoutRedrawAt:anIndex put:aString. |
|
563 |
||
564 |
(widthOfWidestLine := width) notNil ifTrue:[ |
|
565 |
width := self widthOfContents:anIndex and:anIndex. |
|
566 |
||
567 |
width > widthOfWidestLine ifTrue:[ |
|
568 |
widthOfWidestLine := width |
|
569 |
] ifFalse:[ |
|
570 |
widthOfWidestLine := nil "/ means: unknown |
|
571 |
] |
|
572 |
]. |
|
573 |
||
574 |
||
575 |
! ! |
|
576 |
||
483 | 577 |
!SelectionInTreeView methodsFor:'queries'! |
578 |
||
579 |
figureFor:aNode |
|
580 |
"access figure for a node |
|
581 |
" |
|
582 |
aNode hasChildren ifTrue:[ |
|
583 |
aNode isExpandable ifTrue:[ ^ imageClosed ] |
|
584 |
ifFalse:[ ^ imageOpened ] |
|
585 |
]. |
|
586 |
^ imageItem |
|
587 |
||
588 |
"Modified: 3.7.1997 / 12:31:48 / cg" |
|
589 |
! |
|
590 |
||
591 |
indexOfNode:aNode |
|
592 |
"returns index of a node |
|
593 |
" |
|
594 |
^ listOfNodes findFirst:[:n| n == aNode ] |
|
595 |
! |
|
596 |
||
597 |
xOfFigureNode:aNode |
|
598 |
"origin x where to draw the icon |
|
599 |
" |
|
600 |
^ ((aNode level-1) * leftIndent) + figuresInset - leftOffset. |
|
601 |
||
602 |
! |
|
603 |
||
604 |
xOfStringNode:aNode |
|
605 |
"origin x where to draw the text( label ) |
|
606 |
" |
|
607 |
^ (self xOfFigureNode:aNode) + leftIndent |
|
608 |
||
609 |
! ! |
|
610 |
||
444 | 611 |
!SelectionInTreeView methodsFor:'selection'! |
612 |
||
613 |
doubleClicked |
|
614 |
"handle a double click; collapse or expand selected entry |
|
615 |
in case of having children |
|
616 |
" |
|
483 | 617 |
|node index| |
444 | 618 |
|
483 | 619 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
620 |
node := listOfNodes at:index. |
|
471 | 621 |
|
483 | 622 |
node hasChildren ifTrue:[ |
623 |
"/ node has children |
|
624 |
( doubleClickSelectionBlock isNil |
|
625 |
or:[doubleClickSelectionBlock value:index]) ifFalse:[ |
|
626 |
^ self |
|
478 | 627 |
]. |
483 | 628 |
node isExpandable ifTrue:[node expand] |
629 |
ifFalse:[node collapse]. |
|
630 |
||
471 | 631 |
node numberOfChildren == 0 ifTrue:[ |
483 | 632 |
"/ no children; redraw selected line (image might change) |
633 |
self redrawLine:index. |
|
471 | 634 |
] ifFalse:[ |
483 | 635 |
"/ with children; update list and redraw to end. |
636 |
model updateList. |
|
637 |
list := self listFromModel. |
|
638 |
self redrawFromLine:index. |
|
639 |
self contentsChanged. |
|
471 | 640 |
] |
456 | 641 |
]. |
642 |
super doubleClicked. |
|
643 |
] |
|
478 | 644 |
|
456 | 645 |
! |
646 |
||
468 | 647 |
selectNode:aNode |
648 |
"change selection to a node |
|
649 |
" |
|
483 | 650 |
self selection:(self indexOfNode:aNode) |
468 | 651 |
|
652 |
||
653 |
! |
|
654 |
||
456 | 655 |
selectedIndex |
656 |
"get single selected index or 0 |
|
657 |
" |
|
483 | 658 |
selection size == 1 ifTrue:[^ selection first]. |
659 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 660 |
^ 0 |
444 | 661 |
! |
662 |
||
663 |
selectedNode |
|
664 |
"get the single selected node or nil |
|
665 |
" |
|
456 | 666 |
|idx| |
667 |
||
668 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
669 |
^ listOfNodes at:idx |
|
444 | 670 |
]. |
671 |
^ nil |
|
672 |
! ! |
|
673 |
||
674 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
675 |
||
676 |
version |
|
483 | 677 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.11 1997-08-05 06:35:18 ca Exp $' |
444 | 678 |
! ! |