author | tm |
Fri, 05 Feb 1999 12:00:47 +0100 | |
changeset 1188 | 5c365b74eedd |
parent 1175 | 1fa0de353686 |
child 1190 | ae1b8efaf402 |
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 |
|
847 | 15 |
instanceVariableNames:'validateDoubleClickBlock selectionHolder rootHolder imageWidth |
16 |
showLines listOfNodes imageInset textInset labelOffsetY lineMask |
|
1171 | 17 |
itemClass lineColor computeResources showRoot |
18 |
showDirectoryIndicator closeIndicator openIndicator |
|
19 |
showDirectoryIndicatorForRoot imageOpened imageClosed imageItem |
|
20 |
discardMotionEvents registeredImages supportsExpandAll |
|
21 |
buildInArray drawVLinesFromLevel highlightMode editorWidget |
|
1175 | 22 |
editorIndex editValueFgColor' |
1171 | 23 |
classVariableNames:'DefaultHilightMode SelectionInset' |
847 | 24 |
poolDictionaries:'' |
25 |
category:'Views-Text' |
|
444 | 26 |
! |
27 |
||
28 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
29 |
||
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
||
43 |
! |
|
44 |
||
45 |
documentation |
|
46 |
" |
|
47 |
somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like) |
|
48 |
lists and adds the functions to show/hide subtrees. |
|
456 | 49 |
Requires SelectionInTree as model and TreeItem (or compatible) list entries. |
444 | 50 |
|
456 | 51 |
This class obsoletes SelectionInTreeView, which is no longer |
446 | 52 |
maintained but kept for backward compatibility. |
53 |
||
54 |
||
444 | 55 |
[see also:] |
456 | 56 |
SelectionInTree |
57 |
TreeItem |
|
58 |
SelectionInTreeView |
|
444 | 59 |
SelectionInListView |
494 | 60 |
FileSelectionTree |
444 | 61 |
|
62 |
[author:] |
|
63 |
Claus Atzkern |
|
64 |
" |
|
65 |
||
66 |
! |
|
67 |
||
68 |
examples |
|
69 |
" |
|
70 |
shows the tree of smalltalk classes: |
|
71 |
[exBegin] |
|
514 | 72 |
|top sel| |
456 | 73 |
|
514 | 74 |
top := StandardSystemView new; extent:300@300. |
456 | 75 |
sel := SelectionInTreeView new. |
514 | 76 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
456 | 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] |
|
514 | 86 |
|top sel| |
444 | 87 |
|
514 | 88 |
top := StandardSystemView new; extent:300@300. |
456 | 89 |
sel := SelectionInTreeView new. |
514 | 90 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:nil). |
456 | 91 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
685 | 92 |
sel lineColor:(Color red). |
456 | 93 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
94 |
top open. |
|
95 |
[exEnd] |
|
96 |
||
485 | 97 |
|
483 | 98 |
|
485 | 99 |
shows the tree of smalltalk classes; show directory indication and no |
100 |
lines. |
|
101 |
[exBegin] |
|
514 | 102 |
|top sel| |
483 | 103 |
|
514 | 104 |
top := StandardSystemView new; extent:300@300. |
483 | 105 |
sel := SelectionInTreeView new. |
485 | 106 |
sel showLines:false. |
107 |
sel showDirectoryIndicator:true. |
|
514 | 108 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
485 | 109 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
483 | 110 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
111 |
top open. |
|
485 | 112 |
[exEnd] |
113 |
" |
|
114 |
||
514 | 115 |
|
444 | 116 |
! ! |
117 |
||
118 |
!SelectionInTreeView class methodsFor:'constants'! |
|
119 |
||
494 | 120 |
minImageInset |
121 |
"returns minimum inset from directory indication to image |
|
471 | 122 |
" |
494 | 123 |
^ 6 |
490 | 124 |
|
125 |
||
126 |
! ! |
|
127 |
||
900 | 128 |
!SelectionInTreeView class methodsFor:'defaults'! |
129 |
||
1171 | 130 |
defaultModelClass |
131 |
"returns the default model |
|
132 |
" |
|
133 |
^ SelectionInTree |
|
134 |
! |
|
135 |
||
900 | 136 |
updateStyleCache |
137 |
"extract values from the styleSheet and cache them in class variables" |
|
138 |
||
139 |
<resource: #style (#'selection.highlightMode')> |
|
140 |
||
1171 | 141 |
SelectionInset := 4. |
900 | 142 |
DefaultHilightMode := StyleSheet at:'selection.highlightMode' default:#line. |
143 |
" |
|
144 |
self updateStyleCache |
|
145 |
" |
|
146 |
||
147 |
||
148 |
! ! |
|
149 |
||
811 | 150 |
!SelectionInTreeView class methodsFor:'resources'! |
490 | 151 |
|
152 |
closeIndicator |
|
589 | 153 |
<resource: #fileImage> |
154 |
||
811 | 155 |
^ Icon |
156 |
constantNamed:#plus |
|
157 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/plus.xpm')] |
|
158 |
||
589 | 159 |
|
811 | 160 |
|
161 |
||
162 |
||
163 |
||
471 | 164 |
! |
165 |
||
444 | 166 |
imageClosed |
589 | 167 |
<resource: #fileImage> |
168 |
||
811 | 169 |
^ Icon |
170 |
constantNamed:#directory |
|
171 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm')] |
|
444 | 172 |
|
173 |
! |
|
174 |
||
175 |
imageItem |
|
589 | 176 |
<resource: #fileImage> |
177 |
||
811 | 178 |
^ Icon |
179 |
constantNamed:#plainFile |
|
180 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm')] |
|
444 | 181 |
|
811 | 182 |
|
444 | 183 |
|
811 | 184 |
|
185 |
||
444 | 186 |
! |
187 |
||
188 |
imageOpened |
|
589 | 189 |
<resource: #fileImage> |
190 |
||
811 | 191 |
^ Icon |
192 |
constantNamed:#directoryOpened |
|
193 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm')] |
|
444 | 194 |
|
490 | 195 |
! |
196 |
||
197 |
openIndicator |
|
589 | 198 |
<resource: #fileImage> |
199 |
||
811 | 200 |
^ Icon |
201 |
constantNamed:#minus |
|
202 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/minus.xpm')] |
|
490 | 203 |
|
811 | 204 |
|
444 | 205 |
! ! |
206 |
||
207 |
!SelectionInTreeView methodsFor:'accessing'! |
|
208 |
||
900 | 209 |
highlightMode |
210 |
"get the mode how to draw a selected line: |
|
211 |
#line draw whole line selected |
|
212 |
#label draw label selected |
|
213 |
" |
|
214 |
^ highlightMode |
|
215 |
! |
|
216 |
||
217 |
highlightMode:aMode |
|
218 |
"set the mode how to draw a selected line: |
|
219 |
#line draw whole line selected |
|
220 |
#label draw label selected |
|
221 |
" |
|
222 |
|mode| |
|
223 |
||
224 |
(mode := aMode) == #label ifFalse:[ |
|
225 |
mode := #line |
|
226 |
]. |
|
227 |
||
228 |
mode ~~ highlightMode ifTrue:[ |
|
229 |
highlightMode := mode. |
|
230 |
||
231 |
shown ifTrue:[ |
|
232 |
self invalidate |
|
233 |
] |
|
234 |
] |
|
235 |
! |
|
236 |
||
1171 | 237 |
itemClass |
238 |
"returns current itemClass used |
|
239 |
" |
|
240 |
^ itemClass |
|
241 |
||
242 |
||
243 |
! |
|
244 |
||
245 |
itemClass:anItemClass |
|
246 |
"set itemClass to be used |
|
247 |
" |
|
248 |
|directory| |
|
249 |
||
250 |
(anItemClass notNil and:[anItemClass ~~ itemClass]) ifTrue:[ |
|
251 |
itemClass := anItemClass. |
|
252 |
computeResources := true. |
|
253 |
self refetchDeviceResources. |
|
254 |
]. |
|
255 |
||
256 |
! |
|
257 |
||
685 | 258 |
lineColor |
259 |
"returns user configured line color or nil |
|
260 |
" |
|
261 |
^ lineColor |
|
262 |
||
263 |
! |
|
264 |
||
265 |
lineColor:aColor |
|
266 |
"returns user configured line color or nil |
|
267 |
" |
|
268 |
|col| |
|
269 |
||
270 |
col := aColor = fgColor ifTrue:[nil] ifFalse:[aColor]. |
|
271 |
||
272 |
col = lineColor ifFalse:[ |
|
273 |
lineColor := col. |
|
274 |
||
275 |
shown ifTrue:[ |
|
276 |
lineColor notNil ifTrue:[lineColor := lineColor on:device]. |
|
277 |
self invalidate |
|
278 |
] |
|
279 |
] |
|
280 |
! |
|
281 |
||
490 | 282 |
nodeAtIndex:anIndex |
283 |
"returns node at an index or nil |
|
284 |
" |
|
785 | 285 |
(anIndex notNil and:[anIndex between:1 and:listOfNodes size]) ifTrue:[ |
490 | 286 |
^ listOfNodes at:anIndex |
287 |
]. |
|
288 |
^ nil |
|
289 |
! |
|
290 |
||
507 | 291 |
root |
292 |
"gets the root of the model; the first item into list. |
|
293 |
" |
|
294 |
^ self nodeAtIndex:1 |
|
295 |
! |
|
296 |
||
297 |
root:aRoot |
|
298 |
"sets the root of the model; the first item into list. |
|
299 |
" |
|
514 | 300 |
aRoot notNil ifTrue:[aRoot expand]. |
507 | 301 |
model root:aRoot |
302 |
! |
|
303 |
||
490 | 304 |
textInset |
305 |
"get the left inset of the text label |
|
306 |
" |
|
307 |
^ textInset |
|
308 |
! |
|
309 |
||
310 |
textInset:anInset |
|
311 |
"set the left inset of the text label |
|
312 |
" |
|
313 |
anInset ~~ textInset ifTrue:[ |
|
314 |
anInset >= 0 ifTrue:[ |
|
315 |
textInset := anInset. |
|
316 |
self invalidate |
|
317 |
] ifFalse:[ |
|
318 |
self error |
|
319 |
] |
|
320 |
]. |
|
321 |
! ! |
|
322 |
||
323 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
|
324 |
||
855 | 325 |
drawVLinesFromLevel |
326 |
"returns the level vertical lines are drawn from; |
|
327 |
starting at 1 up to n |
|
328 |
" |
|
329 |
^ drawVLinesFromLevel |
|
330 |
! |
|
331 |
||
332 |
drawVLinesFromLevel:aLevel |
|
333 |
"set the level vertical lines are drawn from; |
|
334 |
starting at 1 up to n |
|
335 |
" |
|
336 |
|lv| |
|
337 |
||
338 |
lv := (aLevel ? 1) max:1. |
|
339 |
||
340 |
lv ~~ drawVLinesFromLevel ifTrue:[ |
|
341 |
drawVLinesFromLevel := lv. |
|
342 |
self invalidate |
|
343 |
] |
|
344 |
! |
|
345 |
||
490 | 346 |
showDirectoryIndicator |
347 |
"returns true if directories has an open/closed indicator |
|
348 |
" |
|
349 |
^ showDirectoryIndicator |
|
350 |
! |
|
351 |
||
352 |
showDirectoryIndicator:aState |
|
353 |
"set or clear open/closed indicator for directories |
|
354 |
" |
|
355 |
"show or hide lines |
|
356 |
" |
|
357 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
494 | 358 |
showDirectoryIndicator := aState. |
546 | 359 |
self recomputeDirectoryIndicator. |
490 | 360 |
self invalidate |
361 |
]. |
|
362 |
! |
|
363 |
||
659 | 364 |
showDirectoryIndicatorForRoot |
365 |
"returns true if root directory has an open/closed indicator if |
|
366 |
the common showDirectoryIndicator is enabled |
|
367 |
" |
|
368 |
^ showDirectoryIndicatorForRoot |
|
369 |
! |
|
370 |
||
371 |
showDirectoryIndicatorForRoot:aState |
|
372 |
"true if root directory has an open/closed indicator if |
|
373 |
the common showDirectoryIndicator is enabled |
|
374 |
" |
|
375 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
376 |
showDirectoryIndicatorForRoot := aState. |
|
377 |
self recomputeDirectoryIndicator. |
|
378 |
self invalidate |
|
379 |
]. |
|
380 |
! |
|
381 |
||
490 | 382 |
showLines |
383 |
"returns true if lines are shown |
|
384 |
" |
|
385 |
^ showLines |
|
386 |
! |
|
387 |
||
388 |
showLines:aState |
|
389 |
"show or hide lines |
|
390 |
" |
|
391 |
aState ~~ showLines ifTrue:[ |
|
392 |
showLines := aState. |
|
393 |
self invalidate |
|
394 |
]. |
|
494 | 395 |
! |
396 |
||
397 |
showRoot |
|
398 |
"list with or without root |
|
399 |
" |
|
400 |
^ showRoot |
|
401 |
! |
|
402 |
||
403 |
showRoot:aState |
|
404 |
"list with or without root |
|
405 |
" |
|
406 |
showRoot ~~ aState ifTrue:[ |
|
514 | 407 |
model showRoot:(showRoot := aState) |
408 |
]. |
|
517 | 409 |
! |
410 |
||
835 | 411 |
supportsExpandAll |
412 |
^ supportsExpandAll |
|
413 |
! |
|
414 |
||
415 |
supportsExpandAll:aBool |
|
416 |
||
417 |
supportsExpandAll := aBool |
|
418 |
! |
|
419 |
||
517 | 420 |
validateDoubleClickBlock |
421 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
422 |
on a node will be performed. In case of returning false, the doubleClick will |
|
423 |
not be handled. |
|
424 |
" |
|
425 |
^ validateDoubleClickBlock |
|
426 |
||
427 |
||
428 |
! |
|
429 |
||
430 |
validateDoubleClickBlock:aOneArgBlock |
|
431 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
432 |
on a node will be performed. In case of returning false, the doubleClick will |
|
433 |
not be handled. |
|
434 |
" |
|
435 |
validateDoubleClickBlock := aOneArgBlock |
|
436 |
||
437 |
||
514 | 438 |
! ! |
439 |
||
440 |
!SelectionInTreeView methodsFor:'accessing-channels'! |
|
441 |
||
442 |
rootHolder |
|
443 |
"get the holder which keeps the hierarchical list entry or nil |
|
444 |
" |
|
445 |
^ rootHolder |
|
446 |
! |
|
447 |
||
448 |
rootHolder:aValueHolder |
|
449 |
"set the holder which keeps the hierarchical list entry or nil |
|
450 |
" |
|
451 |
rootHolder notNil ifTrue:[ |
|
452 |
rootHolder removeDependent:self |
|
453 |
]. |
|
855 | 454 |
|
514 | 455 |
(rootHolder := aValueHolder) notNil ifTrue:[ |
456 |
rootHolder addDependent:self. |
|
457 |
self rootFromModel. |
|
494 | 458 |
]. |
514 | 459 |
! |
460 |
||
461 |
selectionHolder |
|
462 |
"get the holder which keeps a list of selected items or nil |
|
463 |
" |
|
464 |
^ selectionHolder |
|
465 |
||
466 |
! |
|
467 |
||
468 |
selectionHolder:aHolder |
|
469 |
"set the holder which keeps a list of selected items or nil |
|
470 |
" |
|
471 |
selectionHolder notNil ifTrue:[ |
|
472 |
selectionHolder removeDependent:self |
|
473 |
]. |
|
474 |
||
475 |
(selectionHolder := aHolder) notNil ifTrue:[ |
|
476 |
selectionHolder addDependent:self. |
|
477 |
self selectionFromModel |
|
478 |
]. |
|
479 |
||
490 | 480 |
! ! |
481 |
||
482 |
!SelectionInTreeView methodsFor:'accessing-images'! |
|
483 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
484 |
imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
485 |
"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
|
486 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
487 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
488 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
489 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
490 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
491 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
492 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
493 |
"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
|
494 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
495 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
496 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
497 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
498 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
499 |
|
569 | 500 |
imageOnDevice:anImage |
846 | 501 |
"associate image to device and clear pixel mask (in case of realized); |
569 | 502 |
returns the new image. |
503 |
" |
|
504 |
|img| |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
505 |
|
846 | 506 |
img := anImage. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
507 |
img notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
508 |
img device ~~ device ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
509 |
img := img copy. |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
510 |
]. |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
511 |
img := img on:device. |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
512 |
img := img clearMaskedPixels. |
569 | 513 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
514 |
^ img |
846 | 515 |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
516 |
"Modified: / 12.8.1998 / 12:46:38 / cg" |
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 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
519 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
520 |
"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
|
521 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
522 |
^ imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
523 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
524 |
"Created: 3.7.1997 / 12:34:28 / cg" |
471 | 525 |
! ! |
526 |
||
514 | 527 |
!SelectionInTreeView methodsFor:'change & update'! |
528 |
||
855 | 529 |
modelChanged:what with:aPara |
530 |
"hierarchical list changed |
|
531 |
" |
|
532 |
|start size visLn h y0 y1 cY parent pvLv ndLv| |
|
533 |
||
534 |
aPara isNil ifTrue:[ |
|
535 |
what == #list ifTrue:[ self getListFromModel ] |
|
536 |
ifFalse:[ super update:what with:aPara from:model ]. |
|
537 |
^ self |
|
538 |
]. |
|
539 |
||
540 |
(what == #insertCollection: or:[what == #removeFrom:]) ifFalse:[ |
|
541 |
what == #at: ifTrue:[ ^ self redrawLine:aPara ]. |
|
542 |
what == #replace ifTrue:[ ^ self invalidateRepairNow:true ]. |
|
543 |
||
544 |
^ super update:what with:aPara from:model. |
|
545 |
]. |
|
546 |
list := self listFromModel. |
|
547 |
||
548 |
shown ifFalse:[ |
|
549 |
^ self contentsChanged |
|
550 |
]. |
|
551 |
(self sensor notNil and: [self sensor hasExposeEventFor:self]) ifTrue:[ "/ outstanding expose events |
|
552 |
self invalidateRepairNow:true. |
|
553 |
^ self contentsChanged |
|
554 |
]. |
|
555 |
||
556 |
start := aPara at:1. |
|
557 |
size := aPara at:2. |
|
558 |
parent := aPara at:3. |
|
559 |
||
860 | 560 |
what == #removeFrom: ifTrue:[ |
561 |
size := size - start + 1 |
|
562 |
]. |
|
563 |
||
855 | 564 |
start > 1 ifTrue:[ |
565 |
pvLv := (list at:start - 1) level. |
|
566 |
ndLv := parent level + 1. |
|
567 |
||
568 |
ndLv < pvLv ifTrue:[ |
|
569 |
what == #insertCollection: ifTrue:[ |
|
570 |
visLn := start + size. |
|
571 |
] ifFalse:[ |
|
572 |
visLn := start. |
|
573 |
]. |
|
574 |
||
575 |
(visLn > list size or:[(list at:visLn) level ~~ ndLv]) ifTrue:[ |
|
576 |
[(start := start - 1) ~~ 1] whileTrue:[ |
|
577 |
(list at:start) level <= ndLv ifTrue:[ |
|
578 |
self redrawFromLine:start. |
|
579 |
^ self contentsChanged. |
|
580 |
] |
|
581 |
]. |
|
582 |
self invalidateRepairNow:true. |
|
583 |
^ self contentsChanged |
|
584 |
] |
|
585 |
]. |
|
586 |
self redrawIconAndIndicatorAt:(start - 1) |
|
587 |
]. |
|
588 |
(visLn := self listLineToVisibleLine:start) isNil ifTrue:[ |
|
589 |
^ self contentsChanged |
|
590 |
]. |
|
591 |
||
592 |
h := size * fontHeight. |
|
593 |
y0 := self yOfVisibleLine:visLn. |
|
594 |
y1 := y0 + h. |
|
595 |
cY := height - y1 - 1. |
|
596 |
||
597 |
cY < 40 ifTrue:[ |
|
598 |
self redrawFromLine:start. |
|
599 |
] ifFalse:[ |
|
600 |
self catchExpose. |
|
601 |
||
602 |
what == #insertCollection: ifTrue:[ |
|
603 |
self copyFrom:self x:0 y:y0 toX:0 y:y1 width:width height:cY async:true. |
|
604 |
] ifFalse:[ |
|
605 |
self copyFrom:self x:0 y:y1 toX:0 y:y0 width:width height:cY async:true. |
|
606 |
y0 := y0 + cY. |
|
607 |
h := height - y0. |
|
608 |
]. |
|
609 |
self redrawX:0 y:y0 width:width height:h. |
|
610 |
self waitForExpose. |
|
611 |
]. |
|
612 |
device flush. |
|
613 |
self contentsChanged. |
|
614 |
! |
|
615 |
||
514 | 616 |
update:something with:aParameter from:aModel |
617 |
"one of my models changed its value |
|
785 | 618 |
" |
619 |
|idx| |
|
620 |
||
514 | 621 |
aModel == rootHolder ifTrue:[ |
622 |
^ self rootFromModel |
|
623 |
]. |
|
855 | 624 |
|
514 | 625 |
aModel == selectionHolder ifTrue:[ |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
626 |
^ self selectionFromModel |
514 | 627 |
]. |
628 |
||
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
629 |
aModel == model ifTrue:[ |
855 | 630 |
^ self modelChanged:something with:aParameter |
631 |
]. |
|
632 |
||
633 |
(aModel isKindOf:TreeItem) ifTrue:[ |
|
634 |
(something == #size or:[something == #children]) ifTrue:[ |
|
635 |
model recomputeList. |
|
636 |
^ self |
|
637 |
]. |
|
638 |
||
639 |
(idx := self indexOfNode:aModel) ~~ 0 ifTrue:[ |
|
640 |
something == #value ifTrue:[ |
|
641 |
^ self redrawLine:idx. |
|
785 | 642 |
]. |
811 | 643 |
|
855 | 644 |
something == #indication ifTrue:[ |
645 |
^ self redrawIndicatorLine:idx. |
|
811 | 646 |
]. |
855 | 647 |
]. |
648 |
^ self |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
649 |
]. |
855 | 650 |
super update:something with:aParameter from:aModel. |
811 | 651 |
|
514 | 652 |
! ! |
653 |
||
444 | 654 |
!SelectionInTreeView methodsFor:'drawing'! |
655 |
||
481 | 656 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
657 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 658 |
|
659 |
! |
|
660 |
||
661 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 662 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 663 |
|
664 |
! |
|
665 |
||
666 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 667 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 668 |
|
669 |
! |
|
670 |
||
671 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 672 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 673 |
|
674 |
! |
|
675 |
||
676 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 677 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
678 |
||
444 | 679 |
! |
680 |
||
681 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 682 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 683 |
|
846 | 684 |
! |
685 |
||
686 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
687 |
self redrawX:0 |
|
688 |
y:(self yOfVisibleLine:startVisLineNr) |
|
689 |
width:width |
|
690 |
height:(endVisLineNr - startVisLineNr + 1 * fontHeight) |
|
691 |
||
692 |
||
848 | 693 |
! |
444 | 694 |
|
848 | 695 |
redrawIconAndIndicatorAt:aLnNr |
696 |
|visLineNr x0 x1 lv| |
|
481 | 697 |
|
769 | 698 |
shown ifTrue:[ |
848 | 699 |
visLineNr := self listLineToVisibleLine:aLnNr. |
700 |
visLineNr notNil ifTrue:[ |
|
701 |
lv := (listOfNodes at:aLnNr) level. |
|
702 |
x1 := (imageWidth + (self xOfFigureLevel:lv)) min:width. |
|
703 |
x0 := (self xOfFigureLevel:(lv - 1)) max:0. |
|
769 | 704 |
|
848 | 705 |
(x0 > width or:[x1 < 0]) ifFalse:[ |
706 |
self redrawX:x0 |
|
707 |
y:(self yOfVisibleLine:visLineNr) |
|
708 |
width:(x1 - x0) |
|
709 |
height:fontHeight |
|
710 |
] |
|
769 | 711 |
] |
848 | 712 |
]. |
769 | 713 |
! |
714 |
||
811 | 715 |
redrawIndicatorLine:aLineNr |
716 |
"redraw the directory indicator for a line |
|
717 |
" |
|
718 |
|node ext img visLn |
|
719 |
x "{ Class:SmallInteger }" |
|
720 |
y "{ Class:SmallInteger }" |
|
721 |
dX "{ Class:SmallInteger }" |
|
722 |
| |
|
723 |
||
724 |
( shown |
|
725 |
and:[showDirectoryIndicator |
|
726 |
and:[(visLn := self listLineToVisibleLine:aLineNr) notNil]] |
|
727 |
) ifFalse:[ |
|
728 |
^ self |
|
729 |
]. |
|
730 |
||
731 |
node := listOfNodes at:aLineNr. |
|
732 |
||
846 | 733 |
(node parent notNil or:[showDirectoryIndicatorForRoot]) ifFalse:[ |
811 | 734 |
^ self |
735 |
]. |
|
736 |
||
846 | 737 |
x := imageWidth // 2. |
738 |
x := x + (self xOfFigureLevel:(node level - 1)). |
|
811 | 739 |
|
740 |
"/ draw directory indicator |
|
741 |
||
742 |
img := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
|
743 |
ext := img extent // 2. |
|
744 |
dX := ext x. |
|
745 |
||
746 |
(x + dX > 0 and:[(x := x - dX) < (width - margin)]) ifTrue:[ |
|
747 |
(self isInSelection:aLineNr) ifTrue:[ self paint:hilightFgColor on:hilightBgColor ] |
|
748 |
ifFalse:[ self paint:fgColor on:bgColor ]. |
|
749 |
||
750 |
y := (self yOfVisibleLine:visLn) + (fontHeight // 2) - 1. |
|
751 |
self displayForm:img x:x y:(y - ext y) |
|
752 |
]. |
|
753 |
||
754 |
||
755 |
||
900 | 756 |
! |
757 |
||
758 |
redrawVisibleLine:visLineNr |
|
759 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fgColor and:bgColor |
|
760 |
! |
|
761 |
||
762 |
redrawVisibleLine:visLineNr from:startCol to:endCol |
|
763 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fgColor and:bgColor |
|
848 | 764 |
! ! |
765 |
||
766 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
767 |
||
900 | 768 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
769 |
"redraw a visible line range with clearing the background |
|
848 | 770 |
" |
900 | 771 |
|y h| |
848 | 772 |
|
900 | 773 |
y := self yOfVisibleLine:startVisLineNr. |
774 |
h := endVisLineNr - startVisLineNr + 1 * fontHeight. |
|
775 |
||
776 |
y + h > height ifTrue:[ |
|
777 |
h := height - y |
|
778 |
]. |
|
779 |
self redrawX:0 y:y width:width height:h. |
|
848 | 780 |
! |
781 |
||
782 |
drawVHLinesX:x0 y:y0 toX:x1 start:start stop:stop |
|
783 |
"redraw from line to line without clearing the background |
|
784 |
" |
|
785 |
|node prevNode parent p1 p2 showVLines showHLine lv nxtPrnt |
|
786 |
||
787 |
x "{ Class:SmallInteger }" |
|
788 |
y "{ Class:SmallInteger }" |
|
789 |
||
790 |
yTop "{ Class:SmallInteger }" |
|
791 |
yBot "{ Class:SmallInteger }" |
|
792 |
yCtr "{ Class:SmallInteger }" |
|
793 |
||
794 |
begHLnY "{ Class:SmallInteger }" |
|
795 |
begHLnX "{ Class:SmallInteger }" |
|
796 |
endHLnX "{ Class:SmallInteger }" |
|
797 |
||
798 |
widthLvl "{ Class:SmallInteger }" |
|
799 |
offsHLnX "{ Class:SmallInteger }" |
|
800 |
||
801 |
level "{ Class:SmallInteger }" |
|
855 | 802 |
startLvI "{ Class:SmallInteger }" |
803 |
startLvX "{ Class:SmallInteger }" |
|
804 |
limitLvI "{ Class:SmallInteger }" |
|
805 |
limitLvX "{ Class:SmallInteger }" |
|
848 | 806 |
| |
807 |
yBot := y0. |
|
808 |
yCtr := yBot - (fontHeight // 2). |
|
809 |
widthLvl := imageInset + imageWidth. |
|
810 |
offsHLnX := imageWidth // 2 + (self xOfFigureLevel:-1). |
|
811 |
||
812 |
parent := 4711. "/ to force a recompute |
|
813 |
prevNode := 4711. "/ to force a recomputation of the level |
|
814 |
||
815 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
816 |
self paint:lineColor on:bgColor. |
|
817 |
self mask:lineMask. |
|
818 |
begHLnY := y0. |
|
855 | 819 |
startLvI := self smallestLevelOfNodesBetween:start and:stop. |
820 |
startLvX := self xOfFigureLevel:startLvI. |
|
821 |
limitLvI := drawVLinesFromLevel + 1. |
|
822 |
limitLvX := limitLvI * widthLvl + offsHLnX. |
|
848 | 823 |
|
824 |
buildInArray atAllPut:0. |
|
825 |
||
826 |
start == 1 ifTrue:[ |
|
827 |
begHLnY := yCtr + fontHeight. |
|
828 |
]. |
|
829 |
||
830 |
start to:stop do:[:anIndex| |
|
831 |
node := listOfNodes at:anIndex. |
|
832 |
yTop := yBot - 1. |
|
833 |
yBot := yBot + fontHeight. |
|
834 |
yCtr := yCtr + fontHeight. |
|
835 |
||
836 |
(nxtPrnt := node parent) ~~ parent ifTrue:[ |
|
837 |
parent := nxtPrnt. |
|
838 |
||
839 |
prevNode == parent ifTrue:[ |
|
840 |
level := level + 1. |
|
841 |
begHLnX := endHLnX. |
|
842 |
] ifFalse:[ |
|
843 |
level := node level. |
|
844 |
begHLnX := node level * widthLvl + offsHLnX. |
|
845 |
]. |
|
846 |
||
847 |
endHLnX := begHLnX + widthLvl. |
|
855 | 848 |
showVLines := begHLnX >= x0 and:[level > drawVLinesFromLevel]. |
848 | 849 |
showHLine := ( x0 < endHLnX |
850 |
and:[x1 > begHLnX |
|
851 |
and:[( parent notNil |
|
852 |
or:[showDirectoryIndicatorForRoot |
|
853 |
and:[showDirectoryIndicator]] |
|
854 |
) |
|
855 |
]] |
|
856 |
). |
|
857 |
]. |
|
858 |
||
859 |
showHLine ifTrue:[ |
|
860 |
self displayLineFromX:begHLnX y:yCtr toX:endHLnX y:yCtr |
|
861 |
]. |
|
862 |
||
863 |
showVLines ifTrue:[ |
|
864 |
y := (parent basicLastChild == node) ifTrue:[yCtr] ifFalse:[yBot]. |
|
865 |
x := begHLnX. |
|
866 |
p2 := parent. |
|
867 |
lv := level - 1. |
|
868 |
self displayLineFromX:x y:begHLnY toX:x y:y. |
|
869 |
||
855 | 870 |
[((p1 := p2 parent) notNil and:[(x := x - widthLvl) >= limitLvX])] whileTrue:[ |
848 | 871 |
(p1 basicLastChild ~~ p2 and:[x <= x1]) ifTrue:[ |
855 | 872 |
x >= startLvX ifTrue:[ |
848 | 873 |
self displayLineFromX:x y:yTop toX:x y:yBot |
874 |
] ifFalse:[ |
|
875 |
buildInArray at:lv put:yBot |
|
876 |
]. |
|
877 |
]. |
|
878 |
lv := lv - 1. |
|
879 |
p2 := p1 |
|
880 |
] |
|
881 |
]. |
|
882 |
prevNode := node. |
|
883 |
begHLnY := yCtr. |
|
884 |
]. |
|
885 |
||
855 | 886 |
"/ |
887 |
"/ draw outstanding verical lines to left |
|
888 |
"/ |
|
889 |
x := limitLvX. |
|
890 |
y := (start ~~ 1) ifTrue:[y0] ifFalse:[y0 + (fontHeight // 2)]. |
|
848 | 891 |
|
855 | 892 |
limitLvI to:startLvI do:[:i| |
893 |
(yBot := buildInArray at:i) ~~ 0 ifTrue:[ |
|
894 |
self displayLineFromX:x y:y toX:x y:yBot |
|
895 |
]. |
|
896 |
x := x + widthLvl. |
|
848 | 897 |
]. |
898 |
self mask:nil. |
|
899 |
||
811 | 900 |
! |
901 |
||
900 | 902 |
drawVisibleLineSelected:visLineNr with:fg and:bg |
903 |
"redraw a single line as selected." |
|
904 |
|y| |
|
905 |
||
906 |
(self visibleLineToListLine:visLineNr) isNil ifTrue:[ |
|
907 |
^ super drawVisibleLine:visLineNr with:fg and:bg |
|
908 |
]. |
|
909 |
self redrawX:0 |
|
910 |
y:(self yOfVisibleLine:visLineNr) |
|
911 |
width:width |
|
912 |
height:fontHeight |
|
913 |
! |
|
914 |
||
902 | 915 |
redrawElement:anIndex |
916 |
||
917 |
|vln x0 xT y| |
|
918 |
||
919 |
shown ifTrue:[ |
|
920 |
( highlightMode ~~ #label |
|
908 | 921 |
or:[(vln := self listLineToVisibleLine:anIndex) isNil |
922 |
or:[anIndex > listOfNodes size]] |
|
902 | 923 |
) ifTrue:[ |
924 |
super redrawElement:anIndex |
|
925 |
] ifFalse:[ |
|
926 |
y := self yOfVisibleLine:vln. |
|
927 |
xT := self xOfStringLevel:((listOfNodes at:anIndex) level). |
|
928 |
x0 := xT - textInset. |
|
929 |
self paint:bgColor. |
|
930 |
self fillRectangleX:x0 y:y width:(width - x0) height:fontHeight. |
|
931 |
self redrawLabelAt:xT y:y index:anIndex |
|
932 |
] |
|
933 |
] |
|
934 |
||
935 |
! |
|
936 |
||
900 | 937 |
redrawLabelAt:x y:yTop index:anIndex |
1171 | 938 |
|isSel y0 x0 w label node value xV wV| |
939 |
||
940 |
node := listOfNodes at:anIndex. |
|
941 |
label := node name. |
|
942 |
isSel := self isInSelection:anIndex. |
|
943 |
xV := 0. |
|
944 |
wV := 0. |
|
945 |
y0 := yTop + (fontHeight // 2) + labelOffsetY. |
|
946 |
||
947 |
(value := node printableEditValue) notNil ifTrue:[ |
|
948 |
xV := (self xOfValueNode:node) - SelectionInset |
|
949 |
]. |
|
900 | 950 |
|
951 |
highlightMode == #label ifTrue:[ |
|
952 |
x0 := x + 4. |
|
953 |
||
1171 | 954 |
isSel ifTrue:[ |
900 | 955 |
w := (label notNil ifTrue:[label widthOn:self] ifFalse:[60]) + 8. |
956 |
self paint:hilightBgColor. |
|
957 |
self fillRectangleX:x y:yTop width:w height:fontHeight. |
|
1171 | 958 |
|
959 |
(value notNil and:[(editorWidget isNil or:[editorIndex ~~ anIndex])]) ifTrue:[ |
|
960 |
wV := SelectionInset + SelectionInset + (value widthOn:self). |
|
961 |
self fillRectangleX:xV y:yTop width:wV height:fontHeight. |
|
962 |
] |
|
900 | 963 |
] |
964 |
] ifFalse:[ |
|
965 |
x0 := x |
|
966 |
]. |
|
967 |
||
968 |
label notNil ifTrue:[ |
|
1171 | 969 |
isSel ifTrue:[self paint:hilightFgColor on:hilightBgColor] |
970 |
ifFalse:[self paint:fgColor on:bgColor]. |
|
971 |
||
972 |
self displayOpaqueString:label x:x0 y:y0. |
|
973 |
||
974 |
value notNil ifTrue:[ |
|
1175 | 975 |
isSel ifFalse:[ |
976 |
self paint:editValueFgColor on:bgColor |
|
977 |
]. |
|
1171 | 978 |
self displayOpaqueString:value x:(xV + SelectionInset) y:y0 |
979 |
]. |
|
980 |
||
900 | 981 |
]. |
982 |
||
1171 | 983 |
(isSel and:[highlightMode == #label]) ifTrue:[ |
984 |
self redrawSelFrameAtX:x y:yTop toX:(x + w). |
|
985 |
||
986 |
wV ~~ 0 ifTrue:[ |
|
987 |
self redrawSelFrameAtX:xV y:yTop toX:(xV + wV) |
|
988 |
] |
|
900 | 989 |
]. |
990 |
||
1171 | 991 |
|
900 | 992 |
! |
993 |
||
769 | 994 |
redrawLinesX:x0 y:y0 toX:x1 start:start stop:stop |
995 |
"redraw from line to line without clearing the background |
|
996 |
" |
|
848 | 997 |
|node prevNode parent icon showIndc showIcon showText nxtPrnt |
846 | 998 |
|
999 |
x "{ Class:SmallInteger }" |
|
1000 |
y "{ Class:SmallInteger }" |
|
1001 |
end "{ Class:SmallInteger }" |
|
1002 |
||
1003 |
yBot "{ Class:SmallInteger }" |
|
1004 |
yCtr "{ Class:SmallInteger }" |
|
1005 |
||
848 | 1006 |
xIndc "{ Class:SmallInteger }" |
846 | 1007 |
xIcon "{ Class:SmallInteger }" |
1008 |
xText "{ Class:SmallInteger }" |
|
1009 |
||
1010 |
soVDt "{ Class:SmallInteger }" |
|
1011 |
||
1012 |
widthLvl "{ Class:SmallInteger }" |
|
1013 |
insetTxt "{ Class:SmallInteger }" |
|
848 | 1014 |
|
1015 |
offIndcX "{ Class:SmallInteger }" |
|
1016 |
offIndcY "{ Class:SmallInteger }" |
|
1017 |
offIconX "{ Class:SmallInteger }" |
|
769 | 1018 |
| |
848 | 1019 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
1020 |
^ self |
|
1021 |
]. |
|
846 | 1022 |
yBot := y0. |
1023 |
yCtr := yBot - (fontHeight // 2). |
|
1024 |
widthLvl := imageInset + imageWidth. |
|
1025 |
insetTxt := imageWidth + textInset. |
|
848 | 1026 |
offIconX := self xOfFigureLevel:0. |
1027 |
showIndc := false. |
|
846 | 1028 |
|
1029 |
showDirectoryIndicator ifTrue:[ |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1030 |
offIndcX := imageWidth // 2 - widthLvl. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1031 |
offIndcY := 0. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1032 |
openIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1033 |
icon := openIndicator extent // 2. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1034 |
offIndcX := offIndcX - icon x. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1035 |
offIndcY := icon y. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1036 |
] |
846 | 1037 |
]. |
785 | 1038 |
|
1039 |
showLines ifTrue:[ |
|
848 | 1040 |
self drawVHLinesX:x0 y:y0 toX:x1 start:start stop:end |
785 | 1041 |
]. |
485 | 1042 |
|
846 | 1043 |
parent := 4711. "/ to force a recompute |
1044 |
prevNode := 4711. "/ to force a recomputation of the level |
|
1045 |
||
1046 |
start to:end do:[:anIndex| |
|
1047 |
node := listOfNodes at:anIndex. |
|
1048 |
yBot := yBot + fontHeight. |
|
494 | 1049 |
yCtr := yCtr + fontHeight. |
485 | 1050 |
|
848 | 1051 |
(nxtPrnt := node parent) ~~ parent ifTrue:[ |
1052 |
parent := nxtPrnt. |
|
1053 |
xIcon := prevNode == parent ifTrue:[xIcon + widthLvl] |
|
1054 |
ifFalse:[node level * widthLvl + offIconX]. |
|
481 | 1055 |
|
848 | 1056 |
xText := xIcon + insetTxt. |
1057 |
showIcon := xIcon < x1 and:[xText > x0]. |
|
1058 |
showText := xText < x1. |
|
769 | 1059 |
|
848 | 1060 |
showDirectoryIndicator ifTrue:[ |
1061 |
xIndc := xIcon + offIndcX. |
|
481 | 1062 |
|
848 | 1063 |
showIndc := ( (parent notNil or:[showDirectoryIndicatorForRoot]) |
1064 |
and:[(xIcon > x0 and:[xIndc < x1])] |
|
1065 |
) |
|
1066 |
] |
|
785 | 1067 |
]. |
481 | 1068 |
|
846 | 1069 |
(showIcon and:[(icon := self figureFor:node) notNil]) ifTrue:[ |
1070 |
self displayForm:icon x:xIcon y:(yCtr - (icon height // 2)) |
|
770 | 1071 |
]. |
848 | 1072 |
|
846 | 1073 |
showText ifTrue:[ |
900 | 1074 |
self redrawLabelAt:xText y:(yBot - fontHeight) index:anIndex |
485 | 1075 |
]. |
848 | 1076 |
(showIndc and:[node showIndicator]) ifTrue:[ |
846 | 1077 |
icon := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
1091
2e86163cfb17
care for non-existing icon image
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1078 |
icon notNil ifTrue:[ |
2e86163cfb17
care for non-existing icon image
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1079 |
self displayForm:icon x:xIndc y:(yCtr - offIndcY) |
2e86163cfb17
care for non-existing icon image
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1080 |
] |
846 | 1081 |
]. |
1082 |
prevNode := node. |
|
769 | 1083 |
] |
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1084 |
|
1091
2e86163cfb17
care for non-existing icon image
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1085 |
"Modified: / 22.8.1998 / 12:56:50 / cg" |
792 | 1086 |
! |
1087 |
||
900 | 1088 |
redrawSelFrameAtX:x0 y:y0 toX:x1 |
1089 |
"redraw selection frame for a line |
|
792 | 1090 |
" |
900 | 1091 |
| |
792 | 1092 |
w "{ Class: SmallInteger }" |
1093 |
y "{ Class: SmallInteger }" |
|
1094 |
x "{ Class: SmallInteger }" |
|
1095 |
| |
|
1096 |
||
1097 |
hilightFrameColor notNil ifTrue:[ |
|
1098 |
hilightLevel == 0 ifTrue:[ |
|
1099 |
self paint:hilightFrameColor. |
|
1105
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1100 |
highlightMode == #line ifTrue:[ |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1101 |
self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1102 |
y := y0 + fontHeight - 1. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1103 |
^self displayLineFromX:x0 y:y toX:x1 y:y. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1104 |
] ifFalse:[ |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1105 |
^self displayRectangleX:x0 y:y0 width:x1 - x0 height:fontHeight |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1106 |
] |
792 | 1107 |
] |
1108 |
] ifFalse:[ |
|
1109 |
hilightStyle == #motif ifTrue:[ |
|
1110 |
self paint:bgColor. |
|
900 | 1111 |
y := y0 + 1. |
1105
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1112 |
highlightMode == #line ifTrue:[ |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1113 |
self displayLineFromX:x0 y:y toX:x1 y:y. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1114 |
y := y0 + fontHeight - 2. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1115 |
self displayLineFromX:x0 y:y toX:x1 y:y. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1116 |
] ifFalse:[ |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1117 |
self displayRectangleX:x0 + 1 y:y width:x1 - x0 - 2 height:fontHeight - 2 |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1118 |
] |
792 | 1119 |
] |
1120 |
]. |
|
1121 |
||
1122 |
hilightLevel ~~ 0 ifTrue:[ |
|
1123 |
"/ draw edge |
|
1124 |
||
900 | 1125 |
highlightMode == #line ifTrue:[ |
1126 |
w := ((width - (2 * margin)) max:(self widthOfContents)) + leftOffset. |
|
1127 |
x := margin - leftOffset. |
|
1128 |
] ifFalse:[ |
|
1129 |
w := x1 - x0. |
|
1130 |
x := x0. |
|
1131 |
]. |
|
1132 |
self drawEdgesForX:x y:y0 width:w height:fontHeight level:hilightLevel. |
|
792 | 1133 |
] |
1134 |
||
1135 |
||
1136 |
||
900 | 1137 |
! |
1138 |
||
1139 |
redrawX:x y:y width:w height:h |
|
1140 |
"a region must be redrawn" |
|
1141 |
||
1142 |
|savClip startLn sel |
|
1143 |
y0 "{ Class:SmallInteger }" |
|
1144 |
y1 "{ Class:SmallInteger }" |
|
1145 |
visStart "{ Class:SmallInteger }" |
|
1146 |
visEnd "{ Class:SmallInteger }" |
|
1147 |
stopLn "{ Class:SmallInteger }" |
|
1148 |
maxY "{ Class:SmallInteger }" |
|
1149 |
maxX "{ Class:SmallInteger }" |
|
1150 |
dltLine "{ Class:SmallInteger }" |
|
1151 |
startY "{ Class:SmallInteger }"| |
|
1152 |
||
1153 |
shown ifFalse:[^ self]. |
|
1154 |
||
1155 |
visStart := self visibleLineOfY:(y + 1). |
|
1156 |
startLn := self visibleLineToAbsoluteLine:visStart. |
|
1157 |
||
1158 |
self paint:bgColor. |
|
1159 |
self fillRectangleX:x y:y width:w height:h. |
|
1160 |
startLn isNil ifTrue:[ ^ self ]. |
|
1161 |
||
1162 |
sel := nil. |
|
1163 |
maxX := x + w. |
|
1164 |
maxY := y + h. |
|
1165 |
visEnd := self visibleLineOfY:maxY. |
|
1166 |
startY := self yOfVisibleLine:visStart. |
|
1167 |
dltLine := startLn - visStart. |
|
1168 |
stopLn := dltLine + visEnd. |
|
1169 |
savClip := clipRect. |
|
1170 |
||
1171 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h). |
|
1172 |
||
1173 |
(highlightMode == #line and:[self hasSelection]) ifTrue:[ |
|
1174 |
"/ redraw the background for all selected lines in the invalid range |
|
1175 |
||
1176 |
self selectionDo:[:lnNr| |
|
1177 |
(lnNr between:startLn and:stopLn) ifTrue:[ |
|
1178 |
sel isNil ifTrue:[ |
|
1179 |
sel := OrderedCollection new. |
|
1180 |
self paint:hilightBgColor. |
|
1181 |
]. |
|
1182 |
sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)). |
|
1183 |
y1 := y0 + fontHeight min:maxY. |
|
1184 |
y0 := y0 max:y. |
|
1185 |
self fillRectangleX:x y:y0 width:w height:y1 - y0. |
|
1186 |
] |
|
1187 |
] |
|
1188 |
]. |
|
1189 |
self redrawLinesX:x y:startY toX:maxX start:startLn stop:stopLn. |
|
1190 |
||
1191 |
"/ draw selection frames |
|
1192 |
sel notNil ifTrue:[ |
|
1193 |
sel do:[:y0| self redrawSelFrameAtX:x y:y0 toX:maxX] |
|
1194 |
]. |
|
1195 |
||
1196 |
self clippingRectangle:savClip. |
|
444 | 1197 |
! ! |
1198 |
||
494 | 1199 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 1200 |
|
494 | 1201 |
detectNode:aOneArgBlock |
1202 |
"evaluate the argument, aBlock for each node in the list until |
|
1203 |
the block returns true; in this case return the node which caused |
|
1204 |
the true evaluation. If none node is detected, nil is returned. |
|
1205 |
" |
|
1206 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 1207 |
! |
1208 |
||
1209 |
selectedNodesDo:aOneArgBlock |
|
1210 |
"evaluate the block on each node selected |
|
1211 |
" |
|
1212 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 1213 |
! ! |
1214 |
||
569 | 1215 |
!SelectionInTreeView methodsFor:'event handling'! |
1216 |
||
639 | 1217 |
buttonMotion:buttonMask x:x y:y |
1218 |
"mouse-move while button was pressed - handle selection changes" |
|
1219 |
||
1220 |
discardMotionEvents ifFalse:[ |
|
1221 |
super buttonMotion:buttonMask x:x y:y |
|
1222 |
] |
|
1223 |
||
1224 |
||
1225 |
! |
|
1226 |
||
569 | 1227 |
buttonMultiPress:button x:x y:y |
1228 |
||
1229 |
(self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[ |
|
1230 |
^ super buttonMultiPress:button x:x y:y |
|
1231 |
]. |
|
1232 |
"/ discard doubleClick on indicator |
|
1233 |
! |
|
1234 |
||
1235 |
buttonPress:button x:x y:y |
|
1171 | 1236 |
"handle button press event |
1237 |
" |
|
1238 |
|node menu d| |
|
1239 |
||
1240 |
((button == 2) or:[button == #menu]) ifTrue:[ |
|
1241 |
( (node := self selectedNode) notNil |
|
1242 |
and:[(menu := node middleButtonMenu) notNil] |
|
1243 |
) ifTrue:[ |
|
1188 | 1244 |
menu isCollection ifTrue:[ |
1245 |
|appl| |
|
1246 |
||
1247 |
menu := Menu new fromLiteralArrayEncoding:menu. |
|
1248 |
||
1249 |
(appl := self application) notNil ifTrue:[ |
|
1250 |
menu findGuiResourcesIn:appl |
|
1251 |
]. |
|
1252 |
menu receiver:appl. |
|
1253 |
]. |
|
1171 | 1254 |
menu startUp |
1255 |
] ifFalse:[ |
|
1256 |
super buttonPress:button x:x y:y |
|
1257 |
] |
|
1258 |
] ifFalse:[ |
|
1259 |
self handleSelectButtonAtX:x y:y. |
|
1260 |
||
1261 |
( editorWidget isNil |
|
1262 |
and:[(node := self selectedNode) notNil |
|
1263 |
and:[node canEdit |
|
1264 |
and:[x >= (self xOfValueNode:node)]]] |
|
1265 |
) ifTrue:[ |
|
1266 |
self openEditor |
|
1267 |
] |
|
1268 |
] |
|
1269 |
! |
|
1270 |
||
1271 |
buttonRelease:button x:x y:y |
|
1272 |
"stop any autoscroll" |
|
1273 |
||
1274 |
discardMotionEvents ifTrue:[ |
|
1275 |
clickPosition := nil. |
|
1276 |
discardMotionEvents := false. |
|
1277 |
]. |
|
1278 |
super buttonRelease:button x:x y:y |
|
1279 |
||
1280 |
! |
|
1281 |
||
1282 |
doubleClicked |
|
1283 |
"handle a double click; collapse or expand selected entry |
|
1284 |
in case of having children |
|
1285 |
" |
|
1286 |
|node| |
|
1287 |
||
1288 |
(node := self selectedNode) notNil ifTrue:[ |
|
1289 |
( validateDoubleClickBlock isNil |
|
1290 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
1291 |
) ifTrue:[ |
|
1292 |
self selectedNodeExpand:(node isExpandable). |
|
1293 |
super doubleClicked |
|
1294 |
] |
|
1295 |
] |
|
1296 |
||
1297 |
! |
|
1298 |
||
1299 |
handleSelectButtonAtX:x y:y |
|
1300 |
"handle a select button click |
|
569 | 1301 |
" |
855 | 1302 |
|expand node lineNr sensor isExpd| |
569 | 1303 |
|
1171 | 1304 |
lineNr := self indicatiorLineForButton:#select atX:x y:y. |
569 | 1305 |
|
1306 |
lineNr == 0 ifTrue:[ |
|
1171 | 1307 |
^ super buttonPress:#select x:x y:y |
569 | 1308 |
]. |
1309 |
node := listOfNodes at:lineNr. |
|
1310 |
||
639 | 1311 |
discardMotionEvents := true. |
569 | 1312 |
dragIsActive := false. |
1313 |
clickPosition := nil. |
|
1314 |
||
639 | 1315 |
self hasSelection ifTrue:[ |
1316 |
(selectConditionBlock isNil or:[selectConditionBlock value:lineNr]) ifTrue:[ |
|
1317 |
self selection:lineNr |
|
1318 |
] ifFalse:[ |
|
1319 |
self selection:nil |
|
569 | 1320 |
] |
1321 |
]. |
|
855 | 1322 |
|
1323 |
isExpd := node isExpandable. |
|
835 | 1324 |
|
855 | 1325 |
( supportsExpandAll |
1326 |
and:[(sensor := self sensor) notNil |
|
1327 |
and:[(sensor ctrlDown or:[sensor shiftDown])]] |
|
1328 |
) ifTrue:[ |
|
1329 |
isExpd ifTrue:[model doExpandAll:node] |
|
1330 |
ifFalse:[model doCollapseAll:node] |
|
835 | 1331 |
] ifFalse:[ |
855 | 1332 |
isExpd ifTrue:[model doExpand:node] |
1333 |
ifFalse:[model doCollapse:node]. |
|
835 | 1334 |
]. |
848 | 1335 |
|
639 | 1336 |
! |
1337 |
||
569 | 1338 |
indicatiorLineForButton:aButton atX:x y:y |
1339 |
"returns linenumber assigned to indicator at x/y or 0 |
|
1340 |
" |
|
846 | 1341 |
|sensor nr x0 node| |
569 | 1342 |
|
1343 |
( enabled |
|
1344 |
and:[showDirectoryIndicator |
|
1345 |
and:[aButton == 1 or:[aButton == #select]]] |
|
1346 |
) ifTrue:[ |
|
835 | 1347 |
nr := self visibleLineToListLine:(self visibleLineOfY:y). |
569 | 1348 |
|
835 | 1349 |
nr notNil ifTrue:[ |
1350 |
node := listOfNodes at:nr. |
|
1351 |
node hasChildren ifTrue:[ |
|
1352 |
x0 := self xOfFigureLevel:(node level - 1). |
|
569 | 1353 |
|
835 | 1354 |
(x > x0 and:[(x0 + imageWidth) > x and:[node children notEmpty]]) ifTrue:[ |
1355 |
^ nr |
|
569 | 1356 |
] |
1357 |
] |
|
1358 |
] |
|
1359 |
]. |
|
1360 |
^ 0 |
|
756 | 1361 |
! |
1362 |
||
835 | 1363 |
isCtrlMetaAltOrShiftPressed |
1364 |
"returns true if CTRL, META, ALT or SHIFT is pressed |
|
1365 |
" |
|
1366 |
|sensor| |
|
1367 |
||
1368 |
(sensor := self sensor) notNil ifTrue:[ |
|
1369 |
^ ( sensor ctrlDown |
|
1370 |
or:[sensor altDown |
|
1371 |
or:[sensor shiftDown |
|
1372 |
or:[sensor metaDown]]] |
|
1373 |
) |
|
1374 |
]. |
|
1375 |
^ false |
|
1376 |
! |
|
1377 |
||
756 | 1378 |
key:key select:index x:x y:y |
1379 |
"select an entry by a keyboard action. This is treated like a doubleClick |
|
1380 |
on that entry. |
|
1381 |
Add on: In case that the entry is not selectable, scroll to the entry |
|
1382 |
" |
|
1383 |
(enabled and:[keyActionStyle notNil]) ifFalse:[ |
|
1384 |
^ self |
|
1385 |
]. |
|
1386 |
||
1387 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[ |
|
780 | 1388 |
^ super key:key select:index x:x y:y |
756 | 1389 |
]. |
1390 |
||
1391 |
keyActionStyle == #pass ifTrue:[ |
|
1392 |
^ self |
|
1393 |
]. |
|
1394 |
||
1395 |
self gotoLine:index |
|
785 | 1396 |
! |
1397 |
||
811 | 1398 |
keyPress:key x:x y:y |
1399 |
"handle keyboard input" |
|
1400 |
||
1401 |
<resource: #keyboard ( #CursorLeft #CursorRight ) > |
|
1402 |
||
1403 |
|idx node inc end| |
|
1404 |
||
1405 |
enabled ifFalse:[ |
|
1406 |
^ self |
|
1407 |
]. |
|
1408 |
||
1409 |
(key == #CursorLeft or:[key == #CursorRight]) ifTrue:[ |
|
1410 |
(idx := self selectedIndex) == 0 ifTrue:[ ^ self ]. |
|
1411 |
||
1412 |
(key == #CursorLeft) ifTrue:[ inc := -1. end := 0 ] |
|
1413 |
ifFalse:[ inc := 1. end := 1 + listOfNodes size ]. |
|
1414 |
||
1415 |
[(idx := idx + inc) ~~ end] whileTrue:[ |
|
1416 |
node := listOfNodes at:idx. |
|
825 | 1417 |
node hasChildren ifTrue:[ |
811 | 1418 |
^ self key:key select:idx x:x y:y |
1419 |
] |
|
1420 |
]. |
|
1421 |
^ self |
|
1422 |
]. |
|
1423 |
^ super keyPress:key x:x y:y |
|
1424 |
||
1425 |
||
1426 |
||
1427 |
||
569 | 1428 |
! ! |
1429 |
||
444 | 1430 |
!SelectionInTreeView methodsFor:'initialization'! |
1431 |
||
685 | 1432 |
create |
1433 |
super create. |
|
695
3e5240577e37
dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents:
685
diff
changeset
|
1434 |
lineMask := lineMask onDevice:device. |
685 | 1435 |
|
846 | 1436 |
lineColor := lineColor isNil ifTrue:[fgColor] |
1437 |
ifFalse:[lineColor onDevice:device]. |
|
1175 | 1438 |
|
1439 |
editValueFgColor := editValueFgColor onDevice:device. |
|
685 | 1440 |
! |
1441 |
||
514 | 1442 |
destroy |
1443 |
"remove dependencies |
|
1444 |
" |
|
811 | 1445 |
rootHolder removeDependent:self. |
1446 |
selectionHolder removeDependent:self. |
|
1447 |
||
1448 |
model notNil ifTrue:[ |
|
1449 |
model stopRunningTasks |
|
514 | 1450 |
]. |
1451 |
super destroy. |
|
1452 |
||
1453 |
! |
|
1454 |
||
785 | 1455 |
fetchDefaultImages |
1456 |
"returns a directory with default keys and images; could be |
|
1457 |
redefined by subclass. |
|
1458 |
" |
|
1171 | 1459 |
^ itemClass notNil ifTrue:[itemClass keysAndIcons] |
1460 |
ifFalse:[nil] |
|
785 | 1461 |
! |
1462 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1463 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1464 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1465 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1466 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1467 |
super fetchDeviceResources. |
478 | 1468 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1469 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1470 |
|
478 | 1471 |
fetchImageResources |
1472 |
"initialize heavily used device resources - to avoid rendering |
|
1473 |
images again and again later; returns maximum extent of the images used. |
|
1474 |
Could be redefined by subclass |
|
471 | 1475 |
" |
785 | 1476 |
|img x y keysAndIcons| |
494 | 1477 |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1478 |
x := y := 0. |
494 | 1479 |
imageOpened isNil ifTrue:[ |
846 | 1480 |
imageOpened := self imageOnDevice:(self class imageOpened) |
494 | 1481 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1482 |
imageOpened notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1483 |
x := x max:(imageOpened width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1484 |
y := y max:(imageOpened height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1485 |
]. |
444 | 1486 |
|
494 | 1487 |
imageClosed isNil ifTrue:[ |
569 | 1488 |
imageClosed := self imageOnDevice:(self class imageClosed) |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
1489 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1490 |
imageClosed notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1491 |
x := x max:(imageClosed width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1492 |
y := y max:(imageClosed height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1493 |
]. |
494 | 1494 |
|
1495 |
imageItem isNil ifTrue:[ |
|
569 | 1496 |
imageItem := self imageOnDevice:(self class imageItem) |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
1497 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1498 |
imageItem notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1499 |
x := x max:(imageItem width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1500 |
y := y max:(imageItem height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1501 |
]. |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1502 |
|
785 | 1503 |
(keysAndIcons := self fetchDefaultImages) notNil ifTrue:[ |
1504 |
keysAndIcons keysAndValuesDo:[:aKey :anIcon| |
|
1505 |
(anIcon isImage and:[aKey notNil]) ifTrue:[ |
|
846 | 1506 |
registeredImages at:aKey put:(self imageOnDevice:anIcon) |
785 | 1507 |
] |
1508 |
] |
|
1509 |
]. |
|
1510 |
registeredImages keysAndValuesDo:[:k :img| |
|
1511 |
x := (img width) max:x. |
|
1512 |
y := (img height) max:y. |
|
1513 |
]. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1514 |
|
785 | 1515 |
(listOfNodes size > 0 and:[(img := listOfNodes first icon) isImage]) ifTrue:[ |
1516 |
x := (img width) max:x. |
|
1517 |
y := (img height) max:y. |
|
1518 |
]. |
|
1519 |
^ x @ y |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1520 |
|
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1521 |
"Modified: / 12.8.1998 / 12:45:53 / cg" |
444 | 1522 |
! |
1523 |
||
480 | 1524 |
getFontParameters |
546 | 1525 |
"save old computed height derived from images |
1526 |
" |
|
1527 |
|lineHeight| |
|
1528 |
||
1529 |
lineHeight := fontHeight ? 0. |
|
480 | 1530 |
super getFontParameters. |
569 | 1531 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 1532 |
|
546 | 1533 |
lineHeight > fontHeight ifTrue:[ |
1534 |
fontHeight := lineHeight |
|
1535 |
]. |
|
685 | 1536 |
fontHeight odd ifTrue:[ |
1537 |
fontHeight := fontHeight + 1 |
|
1538 |
] |
|
480 | 1539 |
! |
1540 |
||
900 | 1541 |
initStyle |
1542 |
"setup viewStyle specifics" |
|
1543 |
||
1544 |
super initStyle. |
|
1171 | 1545 |
highlightMode := DefaultHilightMode ? #label. |
900 | 1546 |
|
1547 |
! |
|
1548 |
||
444 | 1549 |
initialize |
471 | 1550 |
"setup instance attributes |
1551 |
" |
|
444 | 1552 |
super initialize. |
1171 | 1553 |
|
1554 |
itemClass isNil ifTrue:[ |
|
1555 |
itemClass := TreeItem |
|
1556 |
]. |
|
1557 |
||
835 | 1558 |
supportsExpandAll := true. |
569 | 1559 |
self bitGravity:#NorthWest. |
773 | 1560 |
showRoot := showDirectoryIndicatorForRoot := showLines := computeResources := true. |
1561 |
showDirectoryIndicator := discardMotionEvents := false. |
|
685 | 1562 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
773 | 1563 |
registeredImages := IdentityDictionary new. |
855 | 1564 |
drawVLinesFromLevel := 1. |
659 | 1565 |
textInset := 4. |
494 | 1566 |
imageInset := 0. "/ set during indication enabled |
1567 |
imageWidth := 8. "/ default: will change during startup |
|
848 | 1568 |
|
1569 |
buildInArray := Array new:50. "/ used for temporary calculation |
|
1570 |
"/ suppress garbage collection |
|
1571 |
||
514 | 1572 |
self model:nil. "/ creates a default model. |
1171 | 1573 |
highlightMode := #label. |
1175 | 1574 |
editValueFgColor := Color blue. |
478 | 1575 |
! |
1576 |
||
569 | 1577 |
realize |
1578 |
super realize. |
|
1579 |
self refetchDeviceResources. |
|
1580 |
! |
|
1581 |
||
811 | 1582 |
recomputeDirectoryIndicator |
1583 |
"setup attributes used by directory indicator |
|
1584 |
" |
|
1585 |
|x w| |
|
1586 |
||
1587 |
imageInset := 0. |
|
1588 |
||
1589 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
1590 |
^ self |
|
1591 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1592 |
|
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1593 |
x := 0. |
811 | 1594 |
openIndicator isNil ifTrue:[ |
1595 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
1596 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1597 |
openIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1598 |
x := openIndicator width |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1599 |
]. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1600 |
|
811 | 1601 |
closeIndicator isNil ifTrue:[ |
1602 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
1603 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1604 |
closeIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1605 |
x := x max:(closeIndicator width) |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1606 |
]. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1607 |
|
811 | 1608 |
x := x // 2. |
1609 |
w := imageWidth // 2. |
|
1610 |
||
1611 |
(x := x + self class minImageInset) > w ifTrue:[ |
|
1612 |
imageInset := x - w. |
|
1613 |
]. |
|
1614 |
||
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1615 |
"Modified: / 13.8.1998 / 12:02:04 / cg" |
811 | 1616 |
! |
1617 |
||
478 | 1618 |
refetchDeviceResources |
1619 |
"reinitialize heavily used device resources - to avoid rendering |
|
1620 |
images again and again later |
|
1621 |
" |
|
551 | 1622 |
|extent| |
478 | 1623 |
|
569 | 1624 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 1625 |
computeResources := false. |
1626 |
extent := self fetchImageResources. |
|
494 | 1627 |
|
546 | 1628 |
extent y >= fontHeight ifTrue:[ |
1629 |
fontHeight := 1 + extent y. |
|
494 | 1630 |
]. |
685 | 1631 |
fontHeight odd ifTrue:[ |
1632 |
fontHeight := fontHeight + 1 |
|
1633 |
]. |
|
846 | 1634 |
"/ round and not odd: because of line drawing |
685 | 1635 |
|
846 | 1636 |
imageWidth := (extent x) // 2. |
1637 |
imageWidth odd ifTrue:[imageWidth := imageWidth + 1]. |
|
1638 |
imageWidth := imageWidth * 2. |
|
1639 |
||
546 | 1640 |
self recomputeDirectoryIndicator. |
569 | 1641 |
self computeNumberOfLinesShown. |
546 | 1642 |
] |
444 | 1643 |
! ! |
1644 |
||
483 | 1645 |
!SelectionInTreeView methodsFor:'model'! |
444 | 1646 |
|
1647 |
getListFromModel |
|
1648 |
"if I have a model, get my list from it using the listMessage. |
|
1649 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1650 |
" |
|
483 | 1651 |
super list:(self listFromModel) keepSelection:true |
1652 |
! |
|
444 | 1653 |
|
483 | 1654 |
listFromModel |
1655 |
"get list from model and return the new list. |
|
1656 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1657 |
" |
|
846 | 1658 |
|msg| |
838 | 1659 |
|
846 | 1660 |
widthOfWidestLine := nil. |
847 | 1661 |
list := listOfNodes := (msg := listMsg ? aspectMsg) notNil ifTrue:[model perform:msg] ifFalse:[#()]. |
1662 |
self refetchDeviceResources. |
|
846 | 1663 |
^ listOfNodes |
494 | 1664 |
! |
1665 |
||
1666 |
model:aModel |
|
514 | 1667 |
"check whether model is nil; than a default model is created |
1668 |
" |
|
855 | 1669 |
|model root| |
514 | 1670 |
|
811 | 1671 |
model notNil ifTrue:[ |
1672 |
model stopRunningTasks |
|
1673 |
]. |
|
1674 |
||
1171 | 1675 |
model := aModel ? (self class defaultModelClass new). |
1676 |
self itemClass:(model class defaultItemClass). |
|
855 | 1677 |
root := model root. |
1678 |
||
514 | 1679 |
model showRoot:showRoot. |
855 | 1680 |
|
1681 |
root notNil ifTrue:[ |
|
1682 |
root expand |
|
1683 |
]. |
|
514 | 1684 |
super model:model. |
855 | 1685 |
self getListFromModel |
811 | 1686 |
|
514 | 1687 |
! |
1688 |
||
1689 |
rootFromModel |
|
1690 |
"update hierarchical list from root model; 'rootHolder' |
|
1691 |
" |
|
1692 |
|root| |
|
1693 |
||
585 | 1694 |
root := rootHolder root. |
514 | 1695 |
|
1696 |
self root == root ifFalse:[ |
|
1697 |
self selection:nil. |
|
1698 |
self root:root. |
|
585 | 1699 |
]. |
514 | 1700 |
! |
1701 |
||
1702 |
selectionFromModel |
|
1703 |
"set the selection derived from the selectionHolder |
|
1704 |
" |
|
855 | 1705 |
|coll value size idx| |
514 | 1706 |
|
1707 |
(value := selectionHolder value) isNil ifTrue:[ |
|
1708 |
^ self deselect |
|
507 | 1709 |
]. |
514 | 1710 |
|
848 | 1711 |
(multipleSelectOk and:[value isCollection]) ifFalse:[ |
1712 |
^ self selectNode:value |
|
1713 |
]. |
|
1714 |
||
855 | 1715 |
(size := value size) == 0 ifTrue:[ |
848 | 1716 |
^ self deselect |
1717 |
]. |
|
1718 |
||
855 | 1719 |
size == 1 ifTrue:[ |
848 | 1720 |
^ self selectNode:(value at:1) |
1721 |
]. |
|
1722 |
||
855 | 1723 |
model doMakeVisible:value. |
1724 |
||
1725 |
coll := OrderedCollection new:size. |
|
514 | 1726 |
|
860 | 1727 |
value do:[:el| |
1728 |
idx := el isNumber ifTrue:[el] ifFalse:[self indexOfNode:el]. |
|
1729 |
||
1730 |
idx ~~ 0 ifTrue:[ |
|
1731 |
coll add:idx |
|
1732 |
]. |
|
1733 |
]. |
|
1734 |
||
1735 |
coll isEmpty ifTrue:[ |
|
1736 |
coll := nil |
|
848 | 1737 |
]. |
1738 |
self selection:coll |
|
514 | 1739 |
! |
1740 |
||
1741 |
selectionToModel |
|
1742 |
"write selection to selection holder |
|
1743 |
" |
|
1744 |
|newSel oldSel| |
|
1745 |
||
1746 |
oldSel := selectionHolder value. |
|
1747 |
||
1748 |
multipleSelectOk ifFalse:[ |
|
1749 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
1750 |
selectionHolder value:newSel |
|
1751 |
] |
|
1752 |
] ifTrue:[ |
|
1753 |
selection size == 0 ifTrue:[ |
|
1754 |
oldSel notNil ifTrue:[ |
|
1755 |
selectionHolder value:nil |
|
1756 |
] |
|
1757 |
] ifFalse:[ |
|
1758 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
1759 |
||
1760 |
newSel size ~~ oldSel size ifTrue:[ |
|
1761 |
selectionHolder value:newSel. |
|
1762 |
] ifFalse:[ |
|
1763 |
newSel do:[:aNode| |
|
785 | 1764 |
(oldSel includesIdentical:aNode) ifFalse:[ |
514 | 1765 |
^ selectionHolder value:newSel |
1766 |
] |
|
1767 |
] |
|
1768 |
] |
|
1769 |
] |
|
1770 |
] |
|
444 | 1771 |
! ! |
1772 |
||
490 | 1773 |
!SelectionInTreeView methodsFor:'private'! |
1774 |
||
1171 | 1775 |
closeEditor |
1776 |
"close the editor |
|
1777 |
" |
|
1778 |
editorWidget notNil ifTrue:[ |
|
1779 |
editorWidget destroy. |
|
1780 |
editorIndex := 0. |
|
1781 |
editorWidget := nil. |
|
1782 |
]. |
|
1783 |
||
1784 |
! |
|
1785 |
||
490 | 1786 |
list:aList keepSelection:keepSelection |
585 | 1787 |
"setup new list; keep selection dependent on the boolean state |
1788 |
keepSelection |
|
1789 |
" |
|
838 | 1790 |
|list time| |
490 | 1791 |
|
846 | 1792 |
list := (aList size == 0) ifTrue:[#()] ifFalse:[aList]. |
1793 |
super list:list keepSelection:keepSelection. |
|
1794 |
self refetchDeviceResources. |
|
490 | 1795 |
|
1171 | 1796 |
! |
1797 |
||
1798 |
openEditor |
|
1799 |
"open an editor on selection |
|
1800 |
" |
|
1175 | 1801 |
|node x0 x1 y0| |
1171 | 1802 |
|
1803 |
editorWidget notNil ifTrue:[ |
|
1804 |
^ self |
|
1805 |
]. |
|
1806 |
editorIndex := self selectedIndex. |
|
1807 |
||
1808 |
( (node := listOfNodes at:editorIndex ifAbsent:nil) isNil |
|
1809 |
or:[(y0 := self listLineToVisibleLine:editorIndex) isNil |
|
1810 |
or:[(editorWidget := node editor) isNil]] |
|
1811 |
) ifTrue:[ |
|
1812 |
^ self |
|
1813 |
]. |
|
1175 | 1814 |
editorWidget withAllSubViewsDo:[:v| v font:font ]. |
1815 |
||
1171 | 1816 |
y0 := self yOfVisibleLine:y0. |
1817 |
x0 := self xOfValueNode:node. |
|
1818 |
x1 := (editorWidget preferredExtent x) max:50. |
|
1819 |
x1 := (x0 + x1) min:(self width - 5). |
|
1820 |
||
1821 |
editorWidget geometryLayout:(Rectangle left:x0 right:x1 top:y0 bottom:y0 + fontHeight). |
|
1822 |
||
1823 |
self addComponent:editorWidget. |
|
1824 |
editorWidget realize. |
|
1825 |
self paint:bgColor. |
|
1826 |
||
1827 |
self fillRectangleX:(x0 - SelectionInset) |
|
1828 |
y:y0 |
|
1829 |
width:SelectionInset + SelectionInset + (x1 - x0) |
|
1830 |
height:fontHeight. |
|
1831 |
||
1832 |
||
1833 |
||
1834 |
||
1835 |
||
811 | 1836 |
! ! |
1837 |
||
1838 |
!SelectionInTreeView methodsFor:'private - drag and drop'! |
|
569 | 1839 |
|
811 | 1840 |
collectionOfDragObjects |
1841 |
"returns collection of dragable objects assigned to selection |
|
1842 |
Here, by default, a collection of text-dragObjects is generated; |
|
1843 |
however, if a dragObjectConverter is defined, that one gets a chance |
|
1844 |
to convert as appropriate." |
|
1845 |
||
1846 |
|collection converted selection dLbl dObj node| |
|
1847 |
||
1848 |
selection := self selectionAsCollection. |
|
1849 |
||
1850 |
collection := selection collect:[:nr| |
|
1851 |
node := listOfNodes at:nr. |
|
1852 |
dObj := self dragObjectForNode:node. |
|
1853 |
dObj theObject:(node contents). |
|
846 | 1854 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
811 | 1855 |
dObj displayObject:dLbl. |
1856 |
dObj |
|
1857 |
]. |
|
1858 |
||
1859 |
dragObjectConverter notNil ifTrue:[ |
|
1860 |
converted := OrderedCollection new. |
|
1861 |
collection keysAndValuesDo:[:nr :obj | |
|
1862 |
(dObj := dragObjectConverter value:obj) notNil ifTrue:[ |
|
846 | 1863 |
node := listOfNodes at:nr. |
1864 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
|
811 | 1865 |
converted displayObject:dLbl. |
1866 |
converted add:dObj |
|
1867 |
] |
|
1868 |
]. |
|
1869 |
collection := converted |
|
1870 |
]. |
|
1871 |
^ collection. |
|
1872 |
||
1873 |
||
569 | 1874 |
|
1875 |
! |
|
1876 |
||
811 | 1877 |
dragObjectForNode:aNode |
1878 |
"returns the dragable object for a node; could be redefined in subclass |
|
546 | 1879 |
" |
811 | 1880 |
^ DropObject new:aNode. |
546 | 1881 |
|
811 | 1882 |
|
1883 |
! |
|
546 | 1884 |
|
811 | 1885 |
startDragX:x y:y |
1886 |
"start drag |
|
1887 |
" |
|
1888 |
dragIsActive := true. |
|
546 | 1889 |
|
811 | 1890 |
DragAndDropManager startDrag:(self collectionOfDragObjects) |
1891 |
from:self |
|
1892 |
atEnd:endDragAction |
|
546 | 1893 |
|
1894 |
||
490 | 1895 |
! ! |
1896 |
||
468 | 1897 |
!SelectionInTreeView methodsFor:'private queries'! |
1898 |
||
1899 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
1900 |
"return the length (in characters) of the longest line in a line-range |
|
1901 |
" |
|
846 | 1902 |
^ self widthOfContents // fontWidth + 1 |
468 | 1903 |
! |
1904 |
||
848 | 1905 |
smallestLevelOfNodesBetween:start and:stop |
1906 |
"returns the smallest level of the nodes in a line range |
|
1907 |
" |
|
1908 |
|prevNode currParent nextParent |
|
1909 |
||
1910 |
lvl "{ Class:SmallInteger }" |
|
1911 |
min "{ Class:SmallInteger }" |
|
1912 |
end "{ Class:SmallInteger }" |
|
1913 |
beg "{ Class:SmallInteger }" |
|
1914 |
| |
|
1915 |
||
1916 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
|
1917 |
^ 0 |
|
1918 |
]. |
|
1919 |
||
1920 |
prevNode := listOfNodes at:start. |
|
1921 |
currParent := prevNode parent. |
|
1922 |
||
1923 |
currParent isNil ifTrue:[ |
|
1924 |
^ 1 |
|
1925 |
]. |
|
1926 |
||
1927 |
(min := prevNode level) == 2 ifTrue:[ |
|
1928 |
^ min |
|
1929 |
]. |
|
1930 |
beg := start + 1. |
|
1931 |
||
1932 |
listOfNodes from:beg to:end do:[:currNode| |
|
1933 |
(nextParent := currNode parent) == currParent ifFalse:[ |
|
1934 |
(currParent := nextParent) == prevNode ifFalse:[ |
|
1935 |
(lvl := currNode level) == 2 ifTrue:[ |
|
1936 |
^ 2 |
|
1937 |
]. |
|
1938 |
min := min min:lvl |
|
1939 |
] |
|
1940 |
]. |
|
1941 |
prevNode := currNode |
|
1942 |
]. |
|
1943 |
^ min |
|
1944 |
||
1945 |
||
1946 |
||
1947 |
||
1948 |
! |
|
1949 |
||
468 | 1950 |
widthOfContents |
1951 |
"return the width of the contents in pixels |
|
1952 |
- used for scrollbar interface" |
|
1953 |
||
846 | 1954 |
listOfNodes isNil ifTrue:[^ 0]. |
468 | 1955 |
|
1956 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
846 | 1957 |
widthOfWidestLine := self widthOfLongestLine |
468 | 1958 |
]. |
1959 |
^ widthOfWidestLine + (leftMargin * 2) |
|
1960 |
||
1961 |
! |
|
1962 |
||
846 | 1963 |
widthOfLongestLine |
1964 |
"return the width of the longest line in pixels |
|
468 | 1965 |
" |
848 | 1966 |
|parent pItem p |
846 | 1967 |
startX "{ Class: SmallInteger }" |
1968 |
deltaX "{ Class: SmallInteger }" |
|
838 | 1969 |
level "{ Class: SmallInteger }" |
1970 |
width "{ Class: SmallInteger }" |
|
1971 |
maxSz "{ Class: SmallInteger }"| |
|
468 | 1972 |
|
848 | 1973 |
buildInArray atAllPut:0. |
846 | 1974 |
parent := nil. |
1975 |
maxSz := 1. |
|
838 | 1976 |
level := 1. |
846 | 1977 |
|
1978 |
listOfNodes do:[:anItem| |
|
848 | 1979 |
(p := anItem parent) ~~ parent ifTrue:[ |
1980 |
buildInArray at:level put:maxSz. |
|
846 | 1981 |
|
848 | 1982 |
(parent := p) == pItem ifTrue:[level := level + 1] |
1983 |
ifFalse:[level := anItem level]. |
|
1984 |
||
1985 |
maxSz := buildInArray at:level. |
|
846 | 1986 |
]. |
1987 |
pItem := anItem. |
|
1988 |
maxSz := maxSz max:(anItem name size). |
|
1989 |
]. |
|
848 | 1990 |
buildInArray at:level put:maxSz. |
468 | 1991 |
|
846 | 1992 |
startX := self xOfStringLevel:1. |
1993 |
deltaX := imageInset + imageWidth. |
|
1994 |
width := '1' widthOn:self. |
|
1995 |
maxSz := 0. |
|
468 | 1996 |
|
848 | 1997 |
buildInArray do:[:el| |
846 | 1998 |
el == 0 ifTrue:[ ^ maxSz + leftOffset ]. |
1999 |
maxSz := maxSz max:(el * width + startX). |
|
2000 |
startX := startX + deltaX. |
|
468 | 2001 |
]. |
846 | 2002 |
! ! |
2003 |
||
2004 |
!SelectionInTreeView methodsFor:'private redefinitions'! |
|
2005 |
||
2006 |
expandTabs |
|
2007 |
"nothing to do |
|
2008 |
" |
|
838 | 2009 |
|
2010 |
||
468 | 2011 |
! |
2012 |
||
846 | 2013 |
list:aCollection expandTabs:expand scanForNonStrings:scan |
2014 |
||
2015 |
includesNonStrings := false. |
|
2016 |
self list:aCollection expandTabs:false scanForNonStrings:false includesNonStrings:false |
|
2017 |
! |
|
2018 |
||
468 | 2019 |
withoutRedrawAt:anIndex put:aString |
2020 |
"change a line without redisplay" |
|
2021 |
||
2022 |
|width| |
|
2023 |
||
2024 |
width := widthOfWidestLine. |
|
2025 |
widthOfWidestLine := nil. |
|
2026 |
super withoutRedrawAt:anIndex put:aString. |
|
846 | 2027 |
widthOfWidestLine := width. |
468 | 2028 |
|
846 | 2029 |
(widthOfWidestLine notNil and:[aString size ~~ 0]) ifTrue:[ |
2030 |
width := self xOfStringNode:(listOfNodes at:anIndex) |
|
2031 |
+ (aString widthOn:self) |
|
2032 |
+ leftOffset. |
|
2033 |
||
838 | 2034 |
widthOfWidestLine := widthOfWidestLine max:width. |
468 | 2035 |
]. |
2036 |
! ! |
|
2037 |
||
483 | 2038 |
!SelectionInTreeView methodsFor:'queries'! |
2039 |
||
2040 |
figureFor:aNode |
|
2041 |
"access figure for a node |
|
2042 |
" |
|
785 | 2043 |
|icon img| |
2044 |
||
2045 |
(icon := aNode icon) notNil ifTrue:[ |
|
2046 |
img := registeredImages at:icon ifAbsent:nil. |
|
773 | 2047 |
|
785 | 2048 |
img notNil ifTrue:[ |
2049 |
^ img |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2050 |
]. |
785 | 2051 |
icon isImage ifTrue:[ |
846 | 2052 |
img := self imageOnDevice:icon. |
785 | 2053 |
registeredImages at:icon put:img. |
2054 |
^ img |
|
2055 |
] |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2056 |
]. |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2057 |
|
846 | 2058 |
aNode hasChildren ifFalse:[ |
2059 |
^ imageItem |
|
2060 |
]. |
|
2061 |
^ aNode hidden ifTrue:[imageClosed] ifFalse:[imageOpened] |
|
785 | 2062 |
|
483 | 2063 |
! |
2064 |
||
2065 |
indexOfNode:aNode |
|
2066 |
"returns index of a node |
|
2067 |
" |
|
785 | 2068 |
^ listOfNodes identityIndexOf:aNode |
483 | 2069 |
! |
2070 |
||
494 | 2071 |
xOfFigureLevel:aLevel |
2072 |
"origin x where to draw the icon |
|
2073 |
" |
|
785 | 2074 |
|l "{ Class:SmallInteger }"| |
494 | 2075 |
|
785 | 2076 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
494 | 2077 |
|
659 | 2078 |
showDirectoryIndicator ifFalse:[ |
2079 |
l := l - 1 |
|
2080 |
] ifTrue:[ |
|
2081 |
showDirectoryIndicatorForRoot ifFalse:[ |
|
2082 |
l := l - 1 |
|
2083 |
] |
|
2084 |
]. |
|
494 | 2085 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
2086 |
||
2087 |
! |
|
2088 |
||
483 | 2089 |
xOfFigureNode:aNode |
2090 |
"origin x where to draw the icon |
|
2091 |
" |
|
494 | 2092 |
^ self xOfFigureLevel:(aNode level) |
2093 |
! |
|
490 | 2094 |
|
494 | 2095 |
xOfStringLevel:aLevel |
2096 |
"origin x where to draw the text( label ) |
|
2097 |
" |
|
2098 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 2099 |
|
2100 |
! |
|
2101 |
||
2102 |
xOfStringNode:aNode |
|
2103 |
"origin x where to draw the text( label ) |
|
2104 |
" |
|
494 | 2105 |
^ self xOfStringLevel:(aNode level) |
483 | 2106 |
|
1171 | 2107 |
! |
2108 |
||
2109 |
xOfValueNode:aNode |
|
2110 |
"returns the left x position of the start of the value |
|
2111 |
" |
|
2112 |
|p x| |
|
2113 |
||
2114 |
p := aNode parent. |
|
2115 |
||
2116 |
x := p notNil ifTrue:[30 + (p childrenWidthOn:self)] |
|
2117 |
ifFalse:[0]. |
|
2118 |
||
2119 |
^ x + (self xOfStringNode:aNode) |
|
2120 |
||
483 | 2121 |
! ! |
2122 |
||
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2123 |
!SelectionInTreeView methodsFor:'scrolling'! |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2124 |
|
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2125 |
needScrollToMakeLine:aListLineNr |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2126 |
"redefined to scroll whenever line is not in top half" |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2127 |
|
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2128 |
(aListLineNr >= firstLineShown) ifTrue:[ |
1162 | 2129 |
(aListLineNr < (firstLineShown + nFullLinesShown)) ifTrue:[ |
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2130 |
^ false |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2131 |
] |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2132 |
]. |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2133 |
^ true |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2134 |
|
1171 | 2135 |
! |
2136 |
||
2137 |
originChanged:delta |
|
2138 |
"sent after scrolling - have to update origin of editor |
|
2139 |
" |
|
2140 |
super originChanged:delta. |
|
2141 |
||
2142 |
editorWidget notNil ifTrue:[ |
|
2143 |
editorWidget origin:(editorWidget origin - delta) |
|
2144 |
] |
|
2145 |
||
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2146 |
! ! |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2147 |
|
444 | 2148 |
!SelectionInTreeView methodsFor:'selection'! |
2149 |
||
468 | 2150 |
selectNode:aNode |
2151 |
"change selection to a node |
|
2152 |
" |
|
855 | 2153 |
|index| |
848 | 2154 |
|
860 | 2155 |
(index := aNode) notNil ifTrue:[ |
2156 |
index isNumber ifFalse:[ |
|
2157 |
(index := self indexOfNode:aNode) == 0 ifTrue:[ |
|
2158 |
model doMakeVisible:aNode. |
|
2159 |
index := self indexOfNode:aNode. |
|
2160 |
] |
|
855 | 2161 |
]. |
848 | 2162 |
index == 0 ifTrue:[ |
855 | 2163 |
index := nil |
848 | 2164 |
] |
2165 |
]. |
|
2166 |
self selection:index |
|
468 | 2167 |
|
2168 |
||
2169 |
! |
|
2170 |
||
456 | 2171 |
selectedIndex |
2172 |
"get single selected index or 0 |
|
2173 |
" |
|
483 | 2174 |
selection size == 1 ifTrue:[^ selection first]. |
2175 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 2176 |
^ 0 |
444 | 2177 |
! |
2178 |
||
2179 |
selectedNode |
|
2180 |
"get the single selected node or nil |
|
2181 |
" |
|
456 | 2182 |
|idx| |
2183 |
||
2184 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
2185 |
^ listOfNodes at:idx |
|
444 | 2186 |
]. |
2187 |
^ nil |
|
514 | 2188 |
! |
2189 |
||
2190 |
selectionChangedFrom:oldSelection |
|
2191 |
"update selectionHolder if not nil |
|
2192 |
" |
|
1171 | 2193 |
self closeEditor. |
514 | 2194 |
|
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2195 |
"/ first change my selectionHolders value ... |
514 | 2196 |
selectionHolder notNil ifTrue:[ |
2197 |
self selectionToModel. |
|
2198 |
]. |
|
2199 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2200 |
"/ ... then make notifications. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2201 |
super selectionChangedFrom:oldSelection. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2202 |
|
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2203 |
|
1171 | 2204 |
! |
2205 |
||
2206 |
setSelection:aSelection |
|
2207 |
"if no selection exists, close the editor |
|
2208 |
" |
|
2209 |
(aSelection isNil or:[aSelection == 0]) ifTrue:[ |
|
2210 |
self closeEditor |
|
2211 |
]. |
|
2212 |
super setSelection:aSelection |
|
2213 |
||
2214 |
||
444 | 2215 |
! ! |
2216 |
||
855 | 2217 |
!SelectionInTreeView methodsFor:'selection actions'! |
507 | 2218 |
|
2219 |
selectedNodeAdd:something |
|
2220 |
"add a node or collection of nodes after selected node |
|
2221 |
" |
|
2222 |
|node| |
|
2223 |
||
2224 |
something notNil ifTrue:[ |
|
2225 |
(node := self selectedNode) notNil ifTrue:[ |
|
2226 |
node parent notNil ifTrue:[ |
|
2227 |
node isCollapsable ifTrue:[ |
|
2228 |
model add:something beforeIndex:1 below:node |
|
2229 |
] ifFalse:[ |
|
2230 |
model add:something after:node |
|
2231 |
] |
|
2232 |
] ifFalse:[ |
|
2233 |
model add:something beforeIndex:1 below:(self root) |
|
2234 |
] |
|
2235 |
] |
|
2236 |
] |
|
2237 |
||
2238 |
! |
|
2239 |
||
2240 |
selectedNodeBecomeChildOfNext |
|
2241 |
"become node a child of followd node |
|
2242 |
" |
|
2243 |
|idx node cprt nprt| |
|
2244 |
||
2245 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
2246 |
idx := cprt indexOfChild:node. |
|
2247 |
||
2248 |
idx == cprt children size ifFalse:[ |
|
2249 |
nprt := cprt childAt:(idx + 1). |
|
2250 |
||
2251 |
nprt notNil ifTrue:[ |
|
855 | 2252 |
self setSelection:nil. |
2253 |
model remove:node. |
|
507 | 2254 |
model add:node beforeIndex:1 below:nprt. |
2255 |
self selectNode:node. |
|
2256 |
] |
|
2257 |
] |
|
2258 |
] |
|
2259 |
! |
|
2260 |
||
2261 |
selectedNodeBecomeSisterOfParent |
|
2262 |
"become node a sister of its current parent |
|
2263 |
" |
|
2264 |
|node cprt nprt| |
|
2265 |
||
2266 |
( (node := self selectedNode) isNil |
|
2267 |
or:[(cprt := node parent) isNil |
|
2268 |
or:[(nprt := cprt parent) isNil]] |
|
2269 |
) ifFalse:[ |
|
855 | 2270 |
self setSelection:nil. |
2271 |
model remove:node. |
|
507 | 2272 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
855 | 2273 |
self selectNode:node. |
507 | 2274 |
] |
2275 |
||
2276 |
! |
|
2277 |
||
2278 |
selectedNodeChangeSequenceOrder:anOffset |
|
2279 |
"move child 'anOffset' forward or backward in list of children |
|
2280 |
" |
|
2281 |
|idx node size parent| |
|
2282 |
||
2283 |
( (node := self selectedNode) notNil |
|
2284 |
and:[(parent := node parent) notNil |
|
2285 |
and:[(size := parent children size) > 1]] |
|
2286 |
) ifTrue:[ |
|
2287 |
idx := parent indexOfChild:node. |
|
855 | 2288 |
self setSelection:nil. |
2289 |
model remove:node. |
|
507 | 2290 |
|
2291 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
2292 |
idx := size |
|
2293 |
] ifFalse:[ |
|
2294 |
idx > size ifTrue:[idx := 1] |
|
2295 |
]. |
|
2296 |
model add:node beforeIndex:idx below:parent. |
|
2297 |
self selectNode:node. |
|
2298 |
] |
|
2299 |
! |
|
2300 |
||
2301 |
selectedNodeExpand:doExpand |
|
2302 |
"collapse or expand selected node |
|
2303 |
" |
|
855 | 2304 |
|node| |
507 | 2305 |
|
855 | 2306 |
(node := self selectedNode) notNil ifTrue:[ |
2307 |
doExpand ifTrue:[model doExpand:node] |
|
2308 |
ifFalse:[model doCollapse:node] |
|
2309 |
] |
|
507 | 2310 |
! |
2311 |
||
2312 |
selectedNodesRemove |
|
2313 |
"remove selected nodes |
|
2314 |
" |
|
855 | 2315 |
|selection| |
2316 |
||
2317 |
selection := self selection. |
|
507 | 2318 |
self selection:nil. |
855 | 2319 |
model remove:selection. |
507 | 2320 |
! ! |
2321 |
||
444 | 2322 |
!SelectionInTreeView class methodsFor:'documentation'! |
2323 |
||
2324 |
version |
|
1188 | 2325 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.71 1999-02-05 11:00:47 tm Exp $' |
444 | 2326 |
! ! |