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