author | ca |
Wed, 03 Jun 1998 16:33:55 +0200 | |
changeset 908 | 749621e1a1d6 |
parent 902 | de7a2459bd3b |
child 1061 | 8eba9d898259 |
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. |
569 | 478 |
|
846 | 479 |
img device ~~ device ifTrue:[ |
480 |
img := img copy. |
|
569 | 481 |
]. |
846 | 482 |
img := img on:device. |
483 |
img := img clearMaskedPixels. |
|
484 |
^ img |
|
485 |
||
448
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 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
488 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
489 |
"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
|
490 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
491 |
^ imageOpened |
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 |
"Created: 3.7.1997 / 12:34:28 / cg" |
471 | 494 |
! ! |
495 |
||
514 | 496 |
!SelectionInTreeView methodsFor:'change & update'! |
497 |
||
855 | 498 |
modelChanged:what with:aPara |
499 |
"hierarchical list changed |
|
500 |
" |
|
501 |
|start size visLn h y0 y1 cY parent pvLv ndLv| |
|
502 |
||
503 |
aPara isNil ifTrue:[ |
|
504 |
what == #list ifTrue:[ self getListFromModel ] |
|
505 |
ifFalse:[ super update:what with:aPara from:model ]. |
|
506 |
^ self |
|
507 |
]. |
|
508 |
||
509 |
(what == #insertCollection: or:[what == #removeFrom:]) ifFalse:[ |
|
510 |
what == #at: ifTrue:[ ^ self redrawLine:aPara ]. |
|
511 |
what == #replace ifTrue:[ ^ self invalidateRepairNow:true ]. |
|
512 |
||
513 |
^ super update:what with:aPara from:model. |
|
514 |
]. |
|
515 |
list := self listFromModel. |
|
516 |
||
517 |
shown ifFalse:[ |
|
518 |
^ self contentsChanged |
|
519 |
]. |
|
520 |
(self sensor notNil and: [self sensor hasExposeEventFor:self]) ifTrue:[ "/ outstanding expose events |
|
521 |
self invalidateRepairNow:true. |
|
522 |
^ self contentsChanged |
|
523 |
]. |
|
524 |
||
525 |
start := aPara at:1. |
|
526 |
size := aPara at:2. |
|
527 |
parent := aPara at:3. |
|
528 |
||
860 | 529 |
what == #removeFrom: ifTrue:[ |
530 |
size := size - start + 1 |
|
531 |
]. |
|
532 |
||
855 | 533 |
start > 1 ifTrue:[ |
534 |
pvLv := (list at:start - 1) level. |
|
535 |
ndLv := parent level + 1. |
|
536 |
||
537 |
ndLv < pvLv ifTrue:[ |
|
538 |
what == #insertCollection: ifTrue:[ |
|
539 |
visLn := start + size. |
|
540 |
] ifFalse:[ |
|
541 |
visLn := start. |
|
542 |
]. |
|
543 |
||
544 |
(visLn > list size or:[(list at:visLn) level ~~ ndLv]) ifTrue:[ |
|
545 |
[(start := start - 1) ~~ 1] whileTrue:[ |
|
546 |
(list at:start) level <= ndLv ifTrue:[ |
|
547 |
self redrawFromLine:start. |
|
548 |
^ self contentsChanged. |
|
549 |
] |
|
550 |
]. |
|
551 |
self invalidateRepairNow:true. |
|
552 |
^ self contentsChanged |
|
553 |
] |
|
554 |
]. |
|
555 |
self redrawIconAndIndicatorAt:(start - 1) |
|
556 |
]. |
|
557 |
(visLn := self listLineToVisibleLine:start) isNil ifTrue:[ |
|
558 |
^ self contentsChanged |
|
559 |
]. |
|
560 |
||
561 |
h := size * fontHeight. |
|
562 |
y0 := self yOfVisibleLine:visLn. |
|
563 |
y1 := y0 + h. |
|
564 |
cY := height - y1 - 1. |
|
565 |
||
566 |
cY < 40 ifTrue:[ |
|
567 |
self redrawFromLine:start. |
|
568 |
] ifFalse:[ |
|
569 |
self catchExpose. |
|
570 |
||
571 |
what == #insertCollection: ifTrue:[ |
|
572 |
self copyFrom:self x:0 y:y0 toX:0 y:y1 width:width height:cY async:true. |
|
573 |
] ifFalse:[ |
|
574 |
self copyFrom:self x:0 y:y1 toX:0 y:y0 width:width height:cY async:true. |
|
575 |
y0 := y0 + cY. |
|
576 |
h := height - y0. |
|
577 |
]. |
|
578 |
self redrawX:0 y:y0 width:width height:h. |
|
579 |
self waitForExpose. |
|
580 |
]. |
|
581 |
device flush. |
|
582 |
self contentsChanged. |
|
583 |
! |
|
584 |
||
514 | 585 |
update:something with:aParameter from:aModel |
586 |
"one of my models changed its value |
|
785 | 587 |
" |
588 |
|idx| |
|
589 |
||
514 | 590 |
aModel == rootHolder ifTrue:[ |
591 |
^ self rootFromModel |
|
592 |
]. |
|
855 | 593 |
|
514 | 594 |
aModel == selectionHolder ifTrue:[ |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
595 |
^ self selectionFromModel |
514 | 596 |
]. |
597 |
||
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
598 |
aModel == model ifTrue:[ |
855 | 599 |
^ self modelChanged:something with:aParameter |
600 |
]. |
|
601 |
||
602 |
(aModel isKindOf:TreeItem) ifTrue:[ |
|
603 |
(something == #size or:[something == #children]) ifTrue:[ |
|
604 |
model recomputeList. |
|
605 |
^ self |
|
606 |
]. |
|
607 |
||
608 |
(idx := self indexOfNode:aModel) ~~ 0 ifTrue:[ |
|
609 |
something == #value ifTrue:[ |
|
610 |
^ self redrawLine:idx. |
|
785 | 611 |
]. |
811 | 612 |
|
855 | 613 |
something == #indication ifTrue:[ |
614 |
^ self redrawIndicatorLine:idx. |
|
811 | 615 |
]. |
855 | 616 |
]. |
617 |
^ self |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
618 |
]. |
855 | 619 |
super update:something with:aParameter from:aModel. |
811 | 620 |
|
514 | 621 |
! ! |
622 |
||
444 | 623 |
!SelectionInTreeView methodsFor:'drawing'! |
624 |
||
481 | 625 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
626 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 627 |
|
628 |
! |
|
629 |
||
630 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 631 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 632 |
|
633 |
! |
|
634 |
||
635 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 636 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 637 |
|
638 |
! |
|
639 |
||
640 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 641 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 642 |
|
643 |
! |
|
644 |
||
645 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 646 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
647 |
||
444 | 648 |
! |
649 |
||
650 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 651 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 652 |
|
846 | 653 |
! |
654 |
||
655 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
656 |
self redrawX:0 |
|
657 |
y:(self yOfVisibleLine:startVisLineNr) |
|
658 |
width:width |
|
659 |
height:(endVisLineNr - startVisLineNr + 1 * fontHeight) |
|
660 |
||
661 |
||
848 | 662 |
! |
444 | 663 |
|
848 | 664 |
redrawIconAndIndicatorAt:aLnNr |
665 |
|visLineNr x0 x1 lv| |
|
481 | 666 |
|
769 | 667 |
shown ifTrue:[ |
848 | 668 |
visLineNr := self listLineToVisibleLine:aLnNr. |
669 |
visLineNr notNil ifTrue:[ |
|
670 |
lv := (listOfNodes at:aLnNr) level. |
|
671 |
x1 := (imageWidth + (self xOfFigureLevel:lv)) min:width. |
|
672 |
x0 := (self xOfFigureLevel:(lv - 1)) max:0. |
|
769 | 673 |
|
848 | 674 |
(x0 > width or:[x1 < 0]) ifFalse:[ |
675 |
self redrawX:x0 |
|
676 |
y:(self yOfVisibleLine:visLineNr) |
|
677 |
width:(x1 - x0) |
|
678 |
height:fontHeight |
|
679 |
] |
|
769 | 680 |
] |
848 | 681 |
]. |
769 | 682 |
! |
683 |
||
811 | 684 |
redrawIndicatorLine:aLineNr |
685 |
"redraw the directory indicator for a line |
|
686 |
" |
|
687 |
|node ext img visLn |
|
688 |
x "{ Class:SmallInteger }" |
|
689 |
y "{ Class:SmallInteger }" |
|
690 |
dX "{ Class:SmallInteger }" |
|
691 |
| |
|
692 |
||
693 |
( shown |
|
694 |
and:[showDirectoryIndicator |
|
695 |
and:[(visLn := self listLineToVisibleLine:aLineNr) notNil]] |
|
696 |
) ifFalse:[ |
|
697 |
^ self |
|
698 |
]. |
|
699 |
||
700 |
node := listOfNodes at:aLineNr. |
|
701 |
||
846 | 702 |
(node parent notNil or:[showDirectoryIndicatorForRoot]) ifFalse:[ |
811 | 703 |
^ self |
704 |
]. |
|
705 |
||
846 | 706 |
x := imageWidth // 2. |
707 |
x := x + (self xOfFigureLevel:(node level - 1)). |
|
811 | 708 |
|
709 |
"/ draw directory indicator |
|
710 |
||
711 |
img := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
|
712 |
ext := img extent // 2. |
|
713 |
dX := ext x. |
|
714 |
||
715 |
(x + dX > 0 and:[(x := x - dX) < (width - margin)]) ifTrue:[ |
|
716 |
(self isInSelection:aLineNr) ifTrue:[ self paint:hilightFgColor on:hilightBgColor ] |
|
717 |
ifFalse:[ self paint:fgColor on:bgColor ]. |
|
718 |
||
719 |
y := (self yOfVisibleLine:visLn) + (fontHeight // 2) - 1. |
|
720 |
self displayForm:img x:x y:(y - ext y) |
|
721 |
]. |
|
722 |
||
723 |
||
724 |
||
900 | 725 |
! |
726 |
||
727 |
redrawVisibleLine:visLineNr |
|
728 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fgColor and:bgColor |
|
729 |
! |
|
730 |
||
731 |
redrawVisibleLine:visLineNr from:startCol to:endCol |
|
732 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fgColor and:bgColor |
|
848 | 733 |
! ! |
734 |
||
735 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
736 |
||
900 | 737 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
738 |
"redraw a visible line range with clearing the background |
|
848 | 739 |
" |
900 | 740 |
|y h| |
848 | 741 |
|
900 | 742 |
y := self yOfVisibleLine:startVisLineNr. |
743 |
h := endVisLineNr - startVisLineNr + 1 * fontHeight. |
|
744 |
||
745 |
y + h > height ifTrue:[ |
|
746 |
h := height - y |
|
747 |
]. |
|
748 |
self redrawX:0 y:y width:width height:h. |
|
848 | 749 |
! |
750 |
||
751 |
drawVHLinesX:x0 y:y0 toX:x1 start:start stop:stop |
|
752 |
"redraw from line to line without clearing the background |
|
753 |
" |
|
754 |
|node prevNode parent p1 p2 showVLines showHLine lv nxtPrnt |
|
755 |
||
756 |
x "{ Class:SmallInteger }" |
|
757 |
y "{ Class:SmallInteger }" |
|
758 |
||
759 |
yTop "{ Class:SmallInteger }" |
|
760 |
yBot "{ Class:SmallInteger }" |
|
761 |
yCtr "{ Class:SmallInteger }" |
|
762 |
||
763 |
begHLnY "{ Class:SmallInteger }" |
|
764 |
begHLnX "{ Class:SmallInteger }" |
|
765 |
endHLnX "{ Class:SmallInteger }" |
|
766 |
||
767 |
widthLvl "{ Class:SmallInteger }" |
|
768 |
offsHLnX "{ Class:SmallInteger }" |
|
769 |
||
770 |
level "{ Class:SmallInteger }" |
|
855 | 771 |
startLvI "{ Class:SmallInteger }" |
772 |
startLvX "{ Class:SmallInteger }" |
|
773 |
limitLvI "{ Class:SmallInteger }" |
|
774 |
limitLvX "{ Class:SmallInteger }" |
|
848 | 775 |
| |
776 |
yBot := y0. |
|
777 |
yCtr := yBot - (fontHeight // 2). |
|
778 |
widthLvl := imageInset + imageWidth. |
|
779 |
offsHLnX := imageWidth // 2 + (self xOfFigureLevel:-1). |
|
780 |
||
781 |
parent := 4711. "/ to force a recompute |
|
782 |
prevNode := 4711. "/ to force a recomputation of the level |
|
783 |
||
784 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
785 |
self paint:lineColor on:bgColor. |
|
786 |
self mask:lineMask. |
|
787 |
begHLnY := y0. |
|
855 | 788 |
startLvI := self smallestLevelOfNodesBetween:start and:stop. |
789 |
startLvX := self xOfFigureLevel:startLvI. |
|
790 |
limitLvI := drawVLinesFromLevel + 1. |
|
791 |
limitLvX := limitLvI * widthLvl + offsHLnX. |
|
848 | 792 |
|
793 |
buildInArray atAllPut:0. |
|
794 |
||
795 |
start == 1 ifTrue:[ |
|
796 |
begHLnY := yCtr + fontHeight. |
|
797 |
]. |
|
798 |
||
799 |
start to:stop do:[:anIndex| |
|
800 |
node := listOfNodes at:anIndex. |
|
801 |
yTop := yBot - 1. |
|
802 |
yBot := yBot + fontHeight. |
|
803 |
yCtr := yCtr + fontHeight. |
|
804 |
||
805 |
(nxtPrnt := node parent) ~~ parent ifTrue:[ |
|
806 |
parent := nxtPrnt. |
|
807 |
||
808 |
prevNode == parent ifTrue:[ |
|
809 |
level := level + 1. |
|
810 |
begHLnX := endHLnX. |
|
811 |
] ifFalse:[ |
|
812 |
level := node level. |
|
813 |
begHLnX := node level * widthLvl + offsHLnX. |
|
814 |
]. |
|
815 |
||
816 |
endHLnX := begHLnX + widthLvl. |
|
855 | 817 |
showVLines := begHLnX >= x0 and:[level > drawVLinesFromLevel]. |
848 | 818 |
showHLine := ( x0 < endHLnX |
819 |
and:[x1 > begHLnX |
|
820 |
and:[( parent notNil |
|
821 |
or:[showDirectoryIndicatorForRoot |
|
822 |
and:[showDirectoryIndicator]] |
|
823 |
) |
|
824 |
]] |
|
825 |
). |
|
826 |
]. |
|
827 |
||
828 |
showHLine ifTrue:[ |
|
829 |
self displayLineFromX:begHLnX y:yCtr toX:endHLnX y:yCtr |
|
830 |
]. |
|
831 |
||
832 |
showVLines ifTrue:[ |
|
833 |
y := (parent basicLastChild == node) ifTrue:[yCtr] ifFalse:[yBot]. |
|
834 |
x := begHLnX. |
|
835 |
p2 := parent. |
|
836 |
lv := level - 1. |
|
837 |
self displayLineFromX:x y:begHLnY toX:x y:y. |
|
838 |
||
855 | 839 |
[((p1 := p2 parent) notNil and:[(x := x - widthLvl) >= limitLvX])] whileTrue:[ |
848 | 840 |
(p1 basicLastChild ~~ p2 and:[x <= x1]) ifTrue:[ |
855 | 841 |
x >= startLvX ifTrue:[ |
848 | 842 |
self displayLineFromX:x y:yTop toX:x y:yBot |
843 |
] ifFalse:[ |
|
844 |
buildInArray at:lv put:yBot |
|
845 |
]. |
|
846 |
]. |
|
847 |
lv := lv - 1. |
|
848 |
p2 := p1 |
|
849 |
] |
|
850 |
]. |
|
851 |
prevNode := node. |
|
852 |
begHLnY := yCtr. |
|
853 |
]. |
|
854 |
||
855 | 855 |
"/ |
856 |
"/ draw outstanding verical lines to left |
|
857 |
"/ |
|
858 |
x := limitLvX. |
|
859 |
y := (start ~~ 1) ifTrue:[y0] ifFalse:[y0 + (fontHeight // 2)]. |
|
848 | 860 |
|
855 | 861 |
limitLvI to:startLvI do:[:i| |
862 |
(yBot := buildInArray at:i) ~~ 0 ifTrue:[ |
|
863 |
self displayLineFromX:x y:y toX:x y:yBot |
|
864 |
]. |
|
865 |
x := x + widthLvl. |
|
848 | 866 |
]. |
867 |
self mask:nil. |
|
868 |
||
811 | 869 |
! |
870 |
||
900 | 871 |
drawVisibleLineSelected:visLineNr with:fg and:bg |
872 |
"redraw a single line as selected." |
|
873 |
|y| |
|
874 |
||
875 |
(self visibleLineToListLine:visLineNr) isNil ifTrue:[ |
|
876 |
^ super drawVisibleLine:visLineNr with:fg and:bg |
|
877 |
]. |
|
878 |
self redrawX:0 |
|
879 |
y:(self yOfVisibleLine:visLineNr) |
|
880 |
width:width |
|
881 |
height:fontHeight |
|
882 |
! |
|
883 |
||
902 | 884 |
redrawElement:anIndex |
885 |
||
886 |
|vln x0 xT y| |
|
887 |
||
888 |
shown ifTrue:[ |
|
889 |
( highlightMode ~~ #label |
|
908 | 890 |
or:[(vln := self listLineToVisibleLine:anIndex) isNil |
891 |
or:[anIndex > listOfNodes size]] |
|
902 | 892 |
) ifTrue:[ |
893 |
super redrawElement:anIndex |
|
894 |
] ifFalse:[ |
|
895 |
y := self yOfVisibleLine:vln. |
|
896 |
xT := self xOfStringLevel:((listOfNodes at:anIndex) level). |
|
897 |
x0 := xT - textInset. |
|
898 |
self paint:bgColor. |
|
899 |
self fillRectangleX:x0 y:y width:(width - x0) height:fontHeight. |
|
900 |
self redrawLabelAt:xT y:y index:anIndex |
|
901 |
] |
|
902 |
] |
|
903 |
||
904 |
! |
|
905 |
||
900 | 906 |
redrawLabelAt:x y:yTop index:anIndex |
907 |
|isSelected y0 x0 x1 maxX w label i| |
|
908 |
||
909 |
label := (listOfNodes at:anIndex) name. |
|
910 |
isSelected := self isInSelection:anIndex. |
|
911 |
||
912 |
highlightMode == #label ifTrue:[ |
|
913 |
x0 := x + 4. |
|
914 |
||
915 |
isSelected ifTrue:[ |
|
916 |
w := (label notNil ifTrue:[label widthOn:self] ifFalse:[60]) + 8. |
|
917 |
self paint:hilightBgColor. |
|
918 |
self fillRectangleX:x y:yTop width:w height:fontHeight. |
|
919 |
] |
|
920 |
] ifFalse:[ |
|
921 |
x0 := x |
|
922 |
]. |
|
923 |
||
924 |
label notNil ifTrue:[ |
|
925 |
isSelected ifTrue:[self paint:hilightFgColor on:hilightBgColor] |
|
926 |
ifFalse:[self paint:fgColor on:bgColor]. |
|
927 |
||
928 |
self displayOpaqueString:label x:x0 y:yTop + (fontHeight // 2) + labelOffsetY. |
|
929 |
]. |
|
930 |
||
931 |
(isSelected and:[highlightMode == #label]) ifTrue:[ |
|
932 |
self redrawSelFrameAtX:x y:yTop toX:(x + w) |
|
933 |
]. |
|
934 |
||
935 |
! |
|
936 |
||
769 | 937 |
redrawLinesX:x0 y:y0 toX:x1 start:start stop:stop |
938 |
"redraw from line to line without clearing the background |
|
939 |
" |
|
848 | 940 |
|node prevNode parent icon showIndc showIcon showText nxtPrnt |
846 | 941 |
|
942 |
x "{ Class:SmallInteger }" |
|
943 |
y "{ Class:SmallInteger }" |
|
944 |
end "{ Class:SmallInteger }" |
|
945 |
||
946 |
yBot "{ Class:SmallInteger }" |
|
947 |
yCtr "{ Class:SmallInteger }" |
|
948 |
||
848 | 949 |
xIndc "{ Class:SmallInteger }" |
846 | 950 |
xIcon "{ Class:SmallInteger }" |
951 |
xText "{ Class:SmallInteger }" |
|
952 |
||
953 |
soVDt "{ Class:SmallInteger }" |
|
954 |
||
955 |
widthLvl "{ Class:SmallInteger }" |
|
956 |
insetTxt "{ Class:SmallInteger }" |
|
848 | 957 |
|
958 |
offIndcX "{ Class:SmallInteger }" |
|
959 |
offIndcY "{ Class:SmallInteger }" |
|
960 |
offIconX "{ Class:SmallInteger }" |
|
769 | 961 |
| |
848 | 962 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
963 |
^ self |
|
964 |
]. |
|
846 | 965 |
yBot := y0. |
966 |
yCtr := yBot - (fontHeight // 2). |
|
967 |
widthLvl := imageInset + imageWidth. |
|
968 |
insetTxt := imageWidth + textInset. |
|
848 | 969 |
offIconX := self xOfFigureLevel:0. |
970 |
showIndc := false. |
|
846 | 971 |
|
972 |
showDirectoryIndicator ifTrue:[ |
|
848 | 973 |
icon := openIndicator extent // 2. |
974 |
offIndcX := imageWidth // 2 - widthLvl - icon x. |
|
975 |
offIndcY := icon y. |
|
846 | 976 |
]. |
785 | 977 |
|
978 |
showLines ifTrue:[ |
|
848 | 979 |
self drawVHLinesX:x0 y:y0 toX:x1 start:start stop:end |
785 | 980 |
]. |
485 | 981 |
|
846 | 982 |
parent := 4711. "/ to force a recompute |
983 |
prevNode := 4711. "/ to force a recomputation of the level |
|
984 |
||
985 |
start to:end do:[:anIndex| |
|
986 |
node := listOfNodes at:anIndex. |
|
987 |
yBot := yBot + fontHeight. |
|
494 | 988 |
yCtr := yCtr + fontHeight. |
485 | 989 |
|
848 | 990 |
(nxtPrnt := node parent) ~~ parent ifTrue:[ |
991 |
parent := nxtPrnt. |
|
992 |
xIcon := prevNode == parent ifTrue:[xIcon + widthLvl] |
|
993 |
ifFalse:[node level * widthLvl + offIconX]. |
|
481 | 994 |
|
848 | 995 |
xText := xIcon + insetTxt. |
996 |
showIcon := xIcon < x1 and:[xText > x0]. |
|
997 |
showText := xText < x1. |
|
769 | 998 |
|
848 | 999 |
showDirectoryIndicator ifTrue:[ |
1000 |
xIndc := xIcon + offIndcX. |
|
481 | 1001 |
|
848 | 1002 |
showIndc := ( (parent notNil or:[showDirectoryIndicatorForRoot]) |
1003 |
and:[(xIcon > x0 and:[xIndc < x1])] |
|
1004 |
) |
|
1005 |
] |
|
785 | 1006 |
]. |
481 | 1007 |
|
846 | 1008 |
(showIcon and:[(icon := self figureFor:node) notNil]) ifTrue:[ |
1009 |
self displayForm:icon x:xIcon y:(yCtr - (icon height // 2)) |
|
770 | 1010 |
]. |
848 | 1011 |
|
846 | 1012 |
showText ifTrue:[ |
900 | 1013 |
self redrawLabelAt:xText y:(yBot - fontHeight) index:anIndex |
485 | 1014 |
]. |
848 | 1015 |
(showIndc and:[node showIndicator]) ifTrue:[ |
846 | 1016 |
icon := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
848 | 1017 |
self displayForm:icon x:xIndc y:(yCtr - offIndcY) |
846 | 1018 |
]. |
1019 |
prevNode := node. |
|
769 | 1020 |
] |
792 | 1021 |
! |
1022 |
||
900 | 1023 |
redrawSelFrameAtX:x0 y:y0 toX:x1 |
1024 |
"redraw selection frame for a line |
|
792 | 1025 |
" |
900 | 1026 |
| |
792 | 1027 |
w "{ Class: SmallInteger }" |
1028 |
y "{ Class: SmallInteger }" |
|
1029 |
x "{ Class: SmallInteger }" |
|
1030 |
| |
|
1031 |
||
1032 |
hilightFrameColor notNil ifTrue:[ |
|
1033 |
hilightLevel == 0 ifTrue:[ |
|
1034 |
self paint:hilightFrameColor. |
|
900 | 1035 |
self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
1036 |
y := y0 + fontHeight - 1. |
|
1037 |
^ self displayLineFromX:x0 y:y toX:x1 y:y. |
|
792 | 1038 |
] |
1039 |
] ifFalse:[ |
|
1040 |
hilightStyle == #motif ifTrue:[ |
|
1041 |
self paint:bgColor. |
|
1042 |
||
900 | 1043 |
y := y0 + 1. |
1044 |
self displayLineFromX:x0 y:y toX:x1 y:y. |
|
1045 |
y := y0 + fontHeight - 2. |
|
1046 |
self displayLineFromX:x0 y:y toX:x1 y:y. |
|
792 | 1047 |
] |
1048 |
]. |
|
1049 |
||
1050 |
hilightLevel ~~ 0 ifTrue:[ |
|
1051 |
"/ draw edge |
|
1052 |
||
900 | 1053 |
highlightMode == #line ifTrue:[ |
1054 |
w := ((width - (2 * margin)) max:(self widthOfContents)) + leftOffset. |
|
1055 |
x := margin - leftOffset. |
|
1056 |
] ifFalse:[ |
|
1057 |
w := x1 - x0. |
|
1058 |
x := x0. |
|
1059 |
]. |
|
1060 |
self drawEdgesForX:x y:y0 width:w height:fontHeight level:hilightLevel. |
|
792 | 1061 |
] |
1062 |
||
1063 |
||
1064 |
||
900 | 1065 |
! |
1066 |
||
1067 |
redrawX:x y:y width:w height:h |
|
1068 |
"a region must be redrawn" |
|
1069 |
||
1070 |
|savClip startLn sel |
|
1071 |
y0 "{ Class:SmallInteger }" |
|
1072 |
y1 "{ Class:SmallInteger }" |
|
1073 |
visStart "{ Class:SmallInteger }" |
|
1074 |
visEnd "{ Class:SmallInteger }" |
|
1075 |
stopLn "{ Class:SmallInteger }" |
|
1076 |
maxY "{ Class:SmallInteger }" |
|
1077 |
maxX "{ Class:SmallInteger }" |
|
1078 |
dltLine "{ Class:SmallInteger }" |
|
1079 |
startY "{ Class:SmallInteger }"| |
|
1080 |
||
1081 |
shown ifFalse:[^ self]. |
|
1082 |
||
1083 |
visStart := self visibleLineOfY:(y + 1). |
|
1084 |
startLn := self visibleLineToAbsoluteLine:visStart. |
|
1085 |
||
1086 |
self paint:bgColor. |
|
1087 |
self fillRectangleX:x y:y width:w height:h. |
|
1088 |
startLn isNil ifTrue:[ ^ self ]. |
|
1089 |
||
1090 |
sel := nil. |
|
1091 |
maxX := x + w. |
|
1092 |
maxY := y + h. |
|
1093 |
visEnd := self visibleLineOfY:maxY. |
|
1094 |
startY := self yOfVisibleLine:visStart. |
|
1095 |
dltLine := startLn - visStart. |
|
1096 |
stopLn := dltLine + visEnd. |
|
1097 |
savClip := clipRect. |
|
1098 |
||
1099 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h). |
|
1100 |
||
1101 |
(highlightMode == #line and:[self hasSelection]) ifTrue:[ |
|
1102 |
"/ redraw the background for all selected lines in the invalid range |
|
1103 |
||
1104 |
self selectionDo:[:lnNr| |
|
1105 |
(lnNr between:startLn and:stopLn) ifTrue:[ |
|
1106 |
sel isNil ifTrue:[ |
|
1107 |
sel := OrderedCollection new. |
|
1108 |
self paint:hilightBgColor. |
|
1109 |
]. |
|
1110 |
sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)). |
|
1111 |
y1 := y0 + fontHeight min:maxY. |
|
1112 |
y0 := y0 max:y. |
|
1113 |
self fillRectangleX:x y:y0 width:w height:y1 - y0. |
|
1114 |
] |
|
1115 |
] |
|
1116 |
]. |
|
1117 |
self redrawLinesX:x y:startY toX:maxX start:startLn stop:stopLn. |
|
1118 |
||
1119 |
"/ draw selection frames |
|
1120 |
sel notNil ifTrue:[ |
|
1121 |
sel do:[:y0| self redrawSelFrameAtX:x y:y0 toX:maxX] |
|
1122 |
]. |
|
1123 |
||
1124 |
self clippingRectangle:savClip. |
|
444 | 1125 |
! ! |
1126 |
||
494 | 1127 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 1128 |
|
494 | 1129 |
detectNode:aOneArgBlock |
1130 |
"evaluate the argument, aBlock for each node in the list until |
|
1131 |
the block returns true; in this case return the node which caused |
|
1132 |
the true evaluation. If none node is detected, nil is returned. |
|
1133 |
" |
|
1134 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 1135 |
! |
1136 |
||
1137 |
selectedNodesDo:aOneArgBlock |
|
1138 |
"evaluate the block on each node selected |
|
1139 |
" |
|
1140 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 1141 |
! ! |
1142 |
||
569 | 1143 |
!SelectionInTreeView methodsFor:'event handling'! |
1144 |
||
639 | 1145 |
buttonMotion:buttonMask x:x y:y |
1146 |
"mouse-move while button was pressed - handle selection changes" |
|
1147 |
||
1148 |
discardMotionEvents ifFalse:[ |
|
1149 |
super buttonMotion:buttonMask x:x y:y |
|
1150 |
] |
|
1151 |
||
1152 |
||
1153 |
! |
|
1154 |
||
569 | 1155 |
buttonMultiPress:button x:x y:y |
1156 |
||
1157 |
(self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[ |
|
1158 |
^ super buttonMultiPress:button x:x y:y |
|
1159 |
]. |
|
1160 |
"/ discard doubleClick on indicator |
|
1161 |
! |
|
1162 |
||
1163 |
buttonPress:button x:x y:y |
|
1164 |
"check for indicator |
|
1165 |
" |
|
855 | 1166 |
|expand node lineNr sensor isExpd| |
569 | 1167 |
|
1168 |
lineNr := self indicatiorLineForButton:button atX:x y:y. |
|
1169 |
||
1170 |
lineNr == 0 ifTrue:[ |
|
1171 |
^ super buttonPress:button x:x y:y |
|
1172 |
]. |
|
1173 |
node := listOfNodes at:lineNr. |
|
1174 |
||
639 | 1175 |
discardMotionEvents := true. |
569 | 1176 |
dragIsActive := false. |
1177 |
clickPosition := nil. |
|
1178 |
||
639 | 1179 |
self hasSelection ifTrue:[ |
1180 |
(selectConditionBlock isNil or:[selectConditionBlock value:lineNr]) ifTrue:[ |
|
1181 |
self selection:lineNr |
|
1182 |
] ifFalse:[ |
|
1183 |
self selection:nil |
|
569 | 1184 |
] |
1185 |
]. |
|
855 | 1186 |
|
1187 |
isExpd := node isExpandable. |
|
835 | 1188 |
|
855 | 1189 |
( supportsExpandAll |
1190 |
and:[(sensor := self sensor) notNil |
|
1191 |
and:[(sensor ctrlDown or:[sensor shiftDown])]] |
|
1192 |
) ifTrue:[ |
|
1193 |
isExpd ifTrue:[model doExpandAll:node] |
|
1194 |
ifFalse:[model doCollapseAll:node] |
|
835 | 1195 |
] ifFalse:[ |
855 | 1196 |
isExpd ifTrue:[model doExpand:node] |
1197 |
ifFalse:[model doCollapse:node]. |
|
835 | 1198 |
]. |
848 | 1199 |
|
639 | 1200 |
! |
1201 |
||
1202 |
buttonRelease:button x:x y:y |
|
1203 |
"stop any autoscroll" |
|
569 | 1204 |
|
639 | 1205 |
discardMotionEvents ifTrue:[ |
1206 |
clickPosition := nil. |
|
1207 |
discardMotionEvents := false. |
|
1208 |
]. |
|
1209 |
super buttonRelease:button x:x y:y |
|
1210 |
||
569 | 1211 |
! |
1212 |
||
1213 |
doubleClicked |
|
1214 |
"handle a double click; collapse or expand selected entry |
|
1215 |
in case of having children |
|
1216 |
" |
|
1217 |
|node| |
|
1218 |
||
1219 |
(node := self selectedNode) notNil ifTrue:[ |
|
1220 |
( validateDoubleClickBlock isNil |
|
1221 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
1222 |
) ifTrue:[ |
|
1223 |
self selectedNodeExpand:(node isExpandable). |
|
1224 |
super doubleClicked |
|
1225 |
] |
|
1226 |
] |
|
1227 |
||
1228 |
! |
|
1229 |
||
1230 |
indicatiorLineForButton:aButton atX:x y:y |
|
1231 |
"returns linenumber assigned to indicator at x/y or 0 |
|
1232 |
" |
|
846 | 1233 |
|sensor nr x0 node| |
569 | 1234 |
|
1235 |
( enabled |
|
1236 |
and:[showDirectoryIndicator |
|
1237 |
and:[aButton == 1 or:[aButton == #select]]] |
|
1238 |
) ifTrue:[ |
|
835 | 1239 |
nr := self visibleLineToListLine:(self visibleLineOfY:y). |
569 | 1240 |
|
835 | 1241 |
nr notNil ifTrue:[ |
1242 |
node := listOfNodes at:nr. |
|
1243 |
node hasChildren ifTrue:[ |
|
1244 |
x0 := self xOfFigureLevel:(node level - 1). |
|
569 | 1245 |
|
835 | 1246 |
(x > x0 and:[(x0 + imageWidth) > x and:[node children notEmpty]]) ifTrue:[ |
1247 |
^ nr |
|
569 | 1248 |
] |
1249 |
] |
|
1250 |
] |
|
1251 |
]. |
|
1252 |
^ 0 |
|
756 | 1253 |
! |
1254 |
||
835 | 1255 |
isCtrlMetaAltOrShiftPressed |
1256 |
"returns true if CTRL, META, ALT or SHIFT is pressed |
|
1257 |
" |
|
1258 |
|sensor| |
|
1259 |
||
1260 |
(sensor := self sensor) notNil ifTrue:[ |
|
1261 |
^ ( sensor ctrlDown |
|
1262 |
or:[sensor altDown |
|
1263 |
or:[sensor shiftDown |
|
1264 |
or:[sensor metaDown]]] |
|
1265 |
) |
|
1266 |
]. |
|
1267 |
^ false |
|
1268 |
! |
|
1269 |
||
756 | 1270 |
key:key select:index x:x y:y |
1271 |
"select an entry by a keyboard action. This is treated like a doubleClick |
|
1272 |
on that entry. |
|
1273 |
Add on: In case that the entry is not selectable, scroll to the entry |
|
1274 |
" |
|
1275 |
(enabled and:[keyActionStyle notNil]) ifFalse:[ |
|
1276 |
^ self |
|
1277 |
]. |
|
1278 |
||
1279 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[ |
|
780 | 1280 |
^ super key:key select:index x:x y:y |
756 | 1281 |
]. |
1282 |
||
1283 |
keyActionStyle == #pass ifTrue:[ |
|
1284 |
^ self |
|
1285 |
]. |
|
1286 |
||
1287 |
self gotoLine:index |
|
785 | 1288 |
! |
1289 |
||
811 | 1290 |
keyPress:key x:x y:y |
1291 |
"handle keyboard input" |
|
1292 |
||
1293 |
<resource: #keyboard ( #CursorLeft #CursorRight ) > |
|
1294 |
||
1295 |
|idx node inc end| |
|
1296 |
||
1297 |
enabled ifFalse:[ |
|
1298 |
^ self |
|
1299 |
]. |
|
1300 |
||
1301 |
(key == #CursorLeft or:[key == #CursorRight]) ifTrue:[ |
|
1302 |
(idx := self selectedIndex) == 0 ifTrue:[ ^ self ]. |
|
1303 |
||
1304 |
(key == #CursorLeft) ifTrue:[ inc := -1. end := 0 ] |
|
1305 |
ifFalse:[ inc := 1. end := 1 + listOfNodes size ]. |
|
1306 |
||
1307 |
[(idx := idx + inc) ~~ end] whileTrue:[ |
|
1308 |
node := listOfNodes at:idx. |
|
825 | 1309 |
node hasChildren ifTrue:[ |
811 | 1310 |
^ self key:key select:idx x:x y:y |
1311 |
] |
|
1312 |
]. |
|
1313 |
^ self |
|
1314 |
]. |
|
1315 |
^ super keyPress:key x:x y:y |
|
1316 |
||
1317 |
||
1318 |
||
1319 |
||
569 | 1320 |
! ! |
1321 |
||
444 | 1322 |
!SelectionInTreeView methodsFor:'initialization'! |
1323 |
||
685 | 1324 |
create |
1325 |
super create. |
|
695
3e5240577e37
dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents:
685
diff
changeset
|
1326 |
lineMask := lineMask onDevice:device. |
685 | 1327 |
|
846 | 1328 |
lineColor := lineColor isNil ifTrue:[fgColor] |
1329 |
ifFalse:[lineColor onDevice:device]. |
|
685 | 1330 |
! |
1331 |
||
514 | 1332 |
destroy |
1333 |
"remove dependencies |
|
1334 |
" |
|
811 | 1335 |
rootHolder removeDependent:self. |
1336 |
selectionHolder removeDependent:self. |
|
1337 |
||
1338 |
model notNil ifTrue:[ |
|
1339 |
model stopRunningTasks |
|
514 | 1340 |
]. |
1341 |
super destroy. |
|
1342 |
||
1343 |
! |
|
1344 |
||
785 | 1345 |
fetchDefaultImages |
1346 |
"returns a directory with default keys and images; could be |
|
1347 |
redefined by subclass. |
|
1348 |
" |
|
1349 |
^ nil |
|
1350 |
! |
|
1351 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1352 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1353 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1354 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1355 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1356 |
super fetchDeviceResources. |
478 | 1357 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1358 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1359 |
|
478 | 1360 |
fetchImageResources |
1361 |
"initialize heavily used device resources - to avoid rendering |
|
1362 |
images again and again later; returns maximum extent of the images used. |
|
1363 |
Could be redefined by subclass |
|
471 | 1364 |
" |
785 | 1365 |
|img x y keysAndIcons| |
494 | 1366 |
|
1367 |
imageOpened isNil ifTrue:[ |
|
846 | 1368 |
imageOpened := self imageOnDevice:(self class imageOpened) |
494 | 1369 |
]. |
444 | 1370 |
|
494 | 1371 |
imageClosed isNil ifTrue:[ |
569 | 1372 |
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
|
1373 |
]. |
785 | 1374 |
|
1375 |
x := (imageOpened width) max:(imageClosed width). |
|
1376 |
y := (imageOpened height) max:(imageClosed height). |
|
494 | 1377 |
|
1378 |
imageItem isNil ifTrue:[ |
|
569 | 1379 |
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
|
1380 |
]. |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1381 |
|
785 | 1382 |
x := (imageItem width) max:x. |
1383 |
y := (imageItem height) max:y. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1384 |
|
785 | 1385 |
(keysAndIcons := self fetchDefaultImages) notNil ifTrue:[ |
1386 |
keysAndIcons keysAndValuesDo:[:aKey :anIcon| |
|
1387 |
(anIcon isImage and:[aKey notNil]) ifTrue:[ |
|
846 | 1388 |
registeredImages at:aKey put:(self imageOnDevice:anIcon) |
785 | 1389 |
] |
1390 |
] |
|
1391 |
]. |
|
1392 |
registeredImages keysAndValuesDo:[:k :img| |
|
1393 |
x := (img width) max:x. |
|
1394 |
y := (img height) max:y. |
|
1395 |
]. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1396 |
|
785 | 1397 |
(listOfNodes size > 0 and:[(img := listOfNodes first icon) isImage]) ifTrue:[ |
1398 |
x := (img width) max:x. |
|
1399 |
y := (img height) max:y. |
|
1400 |
]. |
|
1401 |
^ x @ y |
|
444 | 1402 |
! |
1403 |
||
480 | 1404 |
getFontParameters |
546 | 1405 |
"save old computed height derived from images |
1406 |
" |
|
1407 |
|lineHeight| |
|
1408 |
||
1409 |
lineHeight := fontHeight ? 0. |
|
480 | 1410 |
super getFontParameters. |
569 | 1411 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 1412 |
|
546 | 1413 |
lineHeight > fontHeight ifTrue:[ |
1414 |
fontHeight := lineHeight |
|
1415 |
]. |
|
685 | 1416 |
fontHeight odd ifTrue:[ |
1417 |
fontHeight := fontHeight + 1 |
|
1418 |
] |
|
480 | 1419 |
! |
1420 |
||
900 | 1421 |
initStyle |
1422 |
"setup viewStyle specifics" |
|
1423 |
||
1424 |
super initStyle. |
|
1425 |
highlightMode := DefaultHilightMode ? #line. |
|
1426 |
||
1427 |
! |
|
1428 |
||
444 | 1429 |
initialize |
471 | 1430 |
"setup instance attributes |
1431 |
" |
|
444 | 1432 |
super initialize. |
835 | 1433 |
supportsExpandAll := true. |
569 | 1434 |
self bitGravity:#NorthWest. |
773 | 1435 |
showRoot := showDirectoryIndicatorForRoot := showLines := computeResources := true. |
1436 |
showDirectoryIndicator := discardMotionEvents := false. |
|
685 | 1437 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
773 | 1438 |
registeredImages := IdentityDictionary new. |
855 | 1439 |
drawVLinesFromLevel := 1. |
659 | 1440 |
textInset := 4. |
494 | 1441 |
imageInset := 0. "/ set during indication enabled |
1442 |
imageWidth := 8. "/ default: will change during startup |
|
848 | 1443 |
|
1444 |
buildInArray := Array new:50. "/ used for temporary calculation |
|
1445 |
"/ suppress garbage collection |
|
1446 |
||
514 | 1447 |
self model:nil. "/ creates a default model. |
900 | 1448 |
highlightMode := #line. |
478 | 1449 |
! |
1450 |
||
569 | 1451 |
realize |
1452 |
super realize. |
|
1453 |
self refetchDeviceResources. |
|
1454 |
! |
|
1455 |
||
811 | 1456 |
recomputeDirectoryIndicator |
1457 |
"setup attributes used by directory indicator |
|
1458 |
" |
|
1459 |
|x w| |
|
1460 |
||
1461 |
imageInset := 0. |
|
1462 |
||
1463 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
1464 |
^ self |
|
1465 |
]. |
|
1466 |
openIndicator isNil ifTrue:[ |
|
1467 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
1468 |
]. |
|
1469 |
closeIndicator isNil ifTrue:[ |
|
1470 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
1471 |
]. |
|
1472 |
x := (openIndicator width) max:(closeIndicator width). |
|
1473 |
x := x // 2. |
|
1474 |
w := imageWidth // 2. |
|
1475 |
||
1476 |
(x := x + self class minImageInset) > w ifTrue:[ |
|
1477 |
imageInset := x - w. |
|
1478 |
]. |
|
1479 |
||
1480 |
||
1481 |
||
1482 |
! |
|
1483 |
||
478 | 1484 |
refetchDeviceResources |
1485 |
"reinitialize heavily used device resources - to avoid rendering |
|
1486 |
images again and again later |
|
1487 |
" |
|
551 | 1488 |
|extent| |
478 | 1489 |
|
569 | 1490 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 1491 |
computeResources := false. |
1492 |
extent := self fetchImageResources. |
|
494 | 1493 |
|
546 | 1494 |
extent y >= fontHeight ifTrue:[ |
1495 |
fontHeight := 1 + extent y. |
|
494 | 1496 |
]. |
685 | 1497 |
fontHeight odd ifTrue:[ |
1498 |
fontHeight := fontHeight + 1 |
|
1499 |
]. |
|
846 | 1500 |
"/ round and not odd: because of line drawing |
685 | 1501 |
|
846 | 1502 |
imageWidth := (extent x) // 2. |
1503 |
imageWidth odd ifTrue:[imageWidth := imageWidth + 1]. |
|
1504 |
imageWidth := imageWidth * 2. |
|
1505 |
||
546 | 1506 |
self recomputeDirectoryIndicator. |
569 | 1507 |
self computeNumberOfLinesShown. |
546 | 1508 |
] |
444 | 1509 |
! ! |
1510 |
||
483 | 1511 |
!SelectionInTreeView methodsFor:'model'! |
444 | 1512 |
|
1513 |
getListFromModel |
|
1514 |
"if I have a model, get my list from it using the listMessage. |
|
1515 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1516 |
" |
|
483 | 1517 |
super list:(self listFromModel) keepSelection:true |
1518 |
! |
|
444 | 1519 |
|
483 | 1520 |
listFromModel |
1521 |
"get list from model and return the new list. |
|
1522 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1523 |
" |
|
846 | 1524 |
|msg| |
838 | 1525 |
|
846 | 1526 |
widthOfWidestLine := nil. |
847 | 1527 |
list := listOfNodes := (msg := listMsg ? aspectMsg) notNil ifTrue:[model perform:msg] ifFalse:[#()]. |
1528 |
self refetchDeviceResources. |
|
846 | 1529 |
^ listOfNodes |
494 | 1530 |
! |
1531 |
||
1532 |
model:aModel |
|
514 | 1533 |
"check whether model is nil; than a default model is created |
1534 |
" |
|
855 | 1535 |
|model root| |
514 | 1536 |
|
811 | 1537 |
model notNil ifTrue:[ |
1538 |
model stopRunningTasks |
|
1539 |
]. |
|
1540 |
||
514 | 1541 |
model := aModel ? (SelectionInTree new). |
855 | 1542 |
root := model root. |
1543 |
||
514 | 1544 |
model showRoot:showRoot. |
855 | 1545 |
|
1546 |
root notNil ifTrue:[ |
|
1547 |
root expand |
|
1548 |
]. |
|
514 | 1549 |
super model:model. |
855 | 1550 |
self getListFromModel |
811 | 1551 |
|
514 | 1552 |
! |
1553 |
||
1554 |
rootFromModel |
|
1555 |
"update hierarchical list from root model; 'rootHolder' |
|
1556 |
" |
|
1557 |
|root| |
|
1558 |
||
585 | 1559 |
root := rootHolder root. |
514 | 1560 |
|
1561 |
self root == root ifFalse:[ |
|
1562 |
self selection:nil. |
|
1563 |
self root:root. |
|
585 | 1564 |
]. |
514 | 1565 |
! |
1566 |
||
1567 |
selectionFromModel |
|
1568 |
"set the selection derived from the selectionHolder |
|
1569 |
" |
|
855 | 1570 |
|coll value size idx| |
514 | 1571 |
|
1572 |
(value := selectionHolder value) isNil ifTrue:[ |
|
1573 |
^ self deselect |
|
507 | 1574 |
]. |
514 | 1575 |
|
848 | 1576 |
(multipleSelectOk and:[value isCollection]) ifFalse:[ |
1577 |
^ self selectNode:value |
|
1578 |
]. |
|
1579 |
||
855 | 1580 |
(size := value size) == 0 ifTrue:[ |
848 | 1581 |
^ self deselect |
1582 |
]. |
|
1583 |
||
855 | 1584 |
size == 1 ifTrue:[ |
848 | 1585 |
^ self selectNode:(value at:1) |
1586 |
]. |
|
1587 |
||
855 | 1588 |
model doMakeVisible:value. |
1589 |
||
1590 |
coll := OrderedCollection new:size. |
|
514 | 1591 |
|
860 | 1592 |
value do:[:el| |
1593 |
idx := el isNumber ifTrue:[el] ifFalse:[self indexOfNode:el]. |
|
1594 |
||
1595 |
idx ~~ 0 ifTrue:[ |
|
1596 |
coll add:idx |
|
1597 |
]. |
|
1598 |
]. |
|
1599 |
||
1600 |
coll isEmpty ifTrue:[ |
|
1601 |
coll := nil |
|
848 | 1602 |
]. |
1603 |
self selection:coll |
|
514 | 1604 |
! |
1605 |
||
1606 |
selectionToModel |
|
1607 |
"write selection to selection holder |
|
1608 |
" |
|
1609 |
|newSel oldSel| |
|
1610 |
||
1611 |
oldSel := selectionHolder value. |
|
1612 |
||
1613 |
multipleSelectOk ifFalse:[ |
|
1614 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
1615 |
selectionHolder value:newSel |
|
1616 |
] |
|
1617 |
] ifTrue:[ |
|
1618 |
selection size == 0 ifTrue:[ |
|
1619 |
oldSel notNil ifTrue:[ |
|
1620 |
selectionHolder value:nil |
|
1621 |
] |
|
1622 |
] ifFalse:[ |
|
1623 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
1624 |
||
1625 |
newSel size ~~ oldSel size ifTrue:[ |
|
1626 |
selectionHolder value:newSel. |
|
1627 |
] ifFalse:[ |
|
1628 |
newSel do:[:aNode| |
|
785 | 1629 |
(oldSel includesIdentical:aNode) ifFalse:[ |
514 | 1630 |
^ selectionHolder value:newSel |
1631 |
] |
|
1632 |
] |
|
1633 |
] |
|
1634 |
] |
|
1635 |
] |
|
444 | 1636 |
! ! |
1637 |
||
490 | 1638 |
!SelectionInTreeView methodsFor:'private'! |
1639 |
||
1640 |
list:aList keepSelection:keepSelection |
|
585 | 1641 |
"setup new list; keep selection dependent on the boolean state |
1642 |
keepSelection |
|
1643 |
" |
|
838 | 1644 |
|list time| |
490 | 1645 |
|
846 | 1646 |
list := (aList size == 0) ifTrue:[#()] ifFalse:[aList]. |
1647 |
super list:list keepSelection:keepSelection. |
|
1648 |
self refetchDeviceResources. |
|
490 | 1649 |
|
811 | 1650 |
! ! |
1651 |
||
1652 |
!SelectionInTreeView methodsFor:'private - drag and drop'! |
|
569 | 1653 |
|
811 | 1654 |
collectionOfDragObjects |
1655 |
"returns collection of dragable objects assigned to selection |
|
1656 |
Here, by default, a collection of text-dragObjects is generated; |
|
1657 |
however, if a dragObjectConverter is defined, that one gets a chance |
|
1658 |
to convert as appropriate." |
|
1659 |
||
1660 |
|collection converted selection dLbl dObj node| |
|
1661 |
||
1662 |
selection := self selectionAsCollection. |
|
1663 |
||
1664 |
collection := selection collect:[:nr| |
|
1665 |
node := listOfNodes at:nr. |
|
1666 |
dObj := self dragObjectForNode:node. |
|
1667 |
dObj theObject:(node contents). |
|
846 | 1668 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
811 | 1669 |
dObj displayObject:dLbl. |
1670 |
dObj |
|
1671 |
]. |
|
1672 |
||
1673 |
dragObjectConverter notNil ifTrue:[ |
|
1674 |
converted := OrderedCollection new. |
|
1675 |
collection keysAndValuesDo:[:nr :obj | |
|
1676 |
(dObj := dragObjectConverter value:obj) notNil ifTrue:[ |
|
846 | 1677 |
node := listOfNodes at:nr. |
1678 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
|
811 | 1679 |
converted displayObject:dLbl. |
1680 |
converted add:dObj |
|
1681 |
] |
|
1682 |
]. |
|
1683 |
collection := converted |
|
1684 |
]. |
|
1685 |
^ collection. |
|
1686 |
||
1687 |
||
569 | 1688 |
|
1689 |
! |
|
1690 |
||
811 | 1691 |
dragObjectForNode:aNode |
1692 |
"returns the dragable object for a node; could be redefined in subclass |
|
546 | 1693 |
" |
811 | 1694 |
^ DropObject new:aNode. |
546 | 1695 |
|
811 | 1696 |
|
1697 |
! |
|
546 | 1698 |
|
811 | 1699 |
startDragX:x y:y |
1700 |
"start drag |
|
1701 |
" |
|
1702 |
dragIsActive := true. |
|
546 | 1703 |
|
811 | 1704 |
DragAndDropManager startDrag:(self collectionOfDragObjects) |
1705 |
from:self |
|
1706 |
atEnd:endDragAction |
|
546 | 1707 |
|
1708 |
||
490 | 1709 |
! ! |
1710 |
||
468 | 1711 |
!SelectionInTreeView methodsFor:'private queries'! |
1712 |
||
1713 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
1714 |
"return the length (in characters) of the longest line in a line-range |
|
1715 |
" |
|
846 | 1716 |
^ self widthOfContents // fontWidth + 1 |
468 | 1717 |
! |
1718 |
||
848 | 1719 |
smallestLevelOfNodesBetween:start and:stop |
1720 |
"returns the smallest level of the nodes in a line range |
|
1721 |
" |
|
1722 |
|prevNode currParent nextParent |
|
1723 |
||
1724 |
lvl "{ Class:SmallInteger }" |
|
1725 |
min "{ Class:SmallInteger }" |
|
1726 |
end "{ Class:SmallInteger }" |
|
1727 |
beg "{ Class:SmallInteger }" |
|
1728 |
| |
|
1729 |
||
1730 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
|
1731 |
^ 0 |
|
1732 |
]. |
|
1733 |
||
1734 |
prevNode := listOfNodes at:start. |
|
1735 |
currParent := prevNode parent. |
|
1736 |
||
1737 |
currParent isNil ifTrue:[ |
|
1738 |
^ 1 |
|
1739 |
]. |
|
1740 |
||
1741 |
(min := prevNode level) == 2 ifTrue:[ |
|
1742 |
^ min |
|
1743 |
]. |
|
1744 |
beg := start + 1. |
|
1745 |
||
1746 |
listOfNodes from:beg to:end do:[:currNode| |
|
1747 |
(nextParent := currNode parent) == currParent ifFalse:[ |
|
1748 |
(currParent := nextParent) == prevNode ifFalse:[ |
|
1749 |
(lvl := currNode level) == 2 ifTrue:[ |
|
1750 |
^ 2 |
|
1751 |
]. |
|
1752 |
min := min min:lvl |
|
1753 |
] |
|
1754 |
]. |
|
1755 |
prevNode := currNode |
|
1756 |
]. |
|
1757 |
^ min |
|
1758 |
||
1759 |
||
1760 |
||
1761 |
||
1762 |
! |
|
1763 |
||
468 | 1764 |
widthOfContents |
1765 |
"return the width of the contents in pixels |
|
1766 |
- used for scrollbar interface" |
|
1767 |
||
846 | 1768 |
listOfNodes isNil ifTrue:[^ 0]. |
468 | 1769 |
|
1770 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
846 | 1771 |
widthOfWidestLine := self widthOfLongestLine |
468 | 1772 |
]. |
1773 |
^ widthOfWidestLine + (leftMargin * 2) |
|
1774 |
||
1775 |
! |
|
1776 |
||
846 | 1777 |
widthOfLongestLine |
1778 |
"return the width of the longest line in pixels |
|
468 | 1779 |
" |
848 | 1780 |
|parent pItem p |
846 | 1781 |
startX "{ Class: SmallInteger }" |
1782 |
deltaX "{ Class: SmallInteger }" |
|
838 | 1783 |
level "{ Class: SmallInteger }" |
1784 |
width "{ Class: SmallInteger }" |
|
1785 |
maxSz "{ Class: SmallInteger }"| |
|
468 | 1786 |
|
848 | 1787 |
buildInArray atAllPut:0. |
846 | 1788 |
parent := nil. |
1789 |
maxSz := 1. |
|
838 | 1790 |
level := 1. |
846 | 1791 |
|
1792 |
listOfNodes do:[:anItem| |
|
848 | 1793 |
(p := anItem parent) ~~ parent ifTrue:[ |
1794 |
buildInArray at:level put:maxSz. |
|
846 | 1795 |
|
848 | 1796 |
(parent := p) == pItem ifTrue:[level := level + 1] |
1797 |
ifFalse:[level := anItem level]. |
|
1798 |
||
1799 |
maxSz := buildInArray at:level. |
|
846 | 1800 |
]. |
1801 |
pItem := anItem. |
|
1802 |
maxSz := maxSz max:(anItem name size). |
|
1803 |
]. |
|
848 | 1804 |
buildInArray at:level put:maxSz. |
468 | 1805 |
|
846 | 1806 |
startX := self xOfStringLevel:1. |
1807 |
deltaX := imageInset + imageWidth. |
|
1808 |
width := '1' widthOn:self. |
|
1809 |
maxSz := 0. |
|
468 | 1810 |
|
848 | 1811 |
buildInArray do:[:el| |
846 | 1812 |
el == 0 ifTrue:[ ^ maxSz + leftOffset ]. |
1813 |
maxSz := maxSz max:(el * width + startX). |
|
1814 |
startX := startX + deltaX. |
|
468 | 1815 |
]. |
846 | 1816 |
! ! |
1817 |
||
1818 |
!SelectionInTreeView methodsFor:'private redefinitions'! |
|
1819 |
||
1820 |
expandTabs |
|
1821 |
"nothing to do |
|
1822 |
" |
|
838 | 1823 |
|
1824 |
||
468 | 1825 |
! |
1826 |
||
846 | 1827 |
list:aCollection expandTabs:expand scanForNonStrings:scan |
1828 |
||
1829 |
includesNonStrings := false. |
|
1830 |
self list:aCollection expandTabs:false scanForNonStrings:false includesNonStrings:false |
|
1831 |
! |
|
1832 |
||
468 | 1833 |
withoutRedrawAt:anIndex put:aString |
1834 |
"change a line without redisplay" |
|
1835 |
||
1836 |
|width| |
|
1837 |
||
1838 |
width := widthOfWidestLine. |
|
1839 |
widthOfWidestLine := nil. |
|
1840 |
super withoutRedrawAt:anIndex put:aString. |
|
846 | 1841 |
widthOfWidestLine := width. |
468 | 1842 |
|
846 | 1843 |
(widthOfWidestLine notNil and:[aString size ~~ 0]) ifTrue:[ |
1844 |
width := self xOfStringNode:(listOfNodes at:anIndex) |
|
1845 |
+ (aString widthOn:self) |
|
1846 |
+ leftOffset. |
|
1847 |
||
838 | 1848 |
widthOfWidestLine := widthOfWidestLine max:width. |
468 | 1849 |
]. |
1850 |
! ! |
|
1851 |
||
483 | 1852 |
!SelectionInTreeView methodsFor:'queries'! |
1853 |
||
1854 |
figureFor:aNode |
|
1855 |
"access figure for a node |
|
1856 |
" |
|
785 | 1857 |
|icon img| |
1858 |
||
1859 |
(icon := aNode icon) notNil ifTrue:[ |
|
1860 |
img := registeredImages at:icon ifAbsent:nil. |
|
773 | 1861 |
|
785 | 1862 |
img notNil ifTrue:[ |
1863 |
^ img |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1864 |
]. |
785 | 1865 |
icon isImage ifTrue:[ |
846 | 1866 |
img := self imageOnDevice:icon. |
785 | 1867 |
registeredImages at:icon put:img. |
1868 |
^ img |
|
1869 |
] |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1870 |
]. |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1871 |
|
846 | 1872 |
aNode hasChildren ifFalse:[ |
1873 |
^ imageItem |
|
1874 |
]. |
|
1875 |
^ aNode hidden ifTrue:[imageClosed] ifFalse:[imageOpened] |
|
785 | 1876 |
|
483 | 1877 |
! |
1878 |
||
1879 |
indexOfNode:aNode |
|
1880 |
"returns index of a node |
|
1881 |
" |
|
785 | 1882 |
^ listOfNodes identityIndexOf:aNode |
483 | 1883 |
! |
1884 |
||
494 | 1885 |
xOfFigureLevel:aLevel |
1886 |
"origin x where to draw the icon |
|
1887 |
" |
|
785 | 1888 |
|l "{ Class:SmallInteger }"| |
494 | 1889 |
|
785 | 1890 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
494 | 1891 |
|
659 | 1892 |
showDirectoryIndicator ifFalse:[ |
1893 |
l := l - 1 |
|
1894 |
] ifTrue:[ |
|
1895 |
showDirectoryIndicatorForRoot ifFalse:[ |
|
1896 |
l := l - 1 |
|
1897 |
] |
|
1898 |
]. |
|
494 | 1899 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
1900 |
||
1901 |
! |
|
1902 |
||
483 | 1903 |
xOfFigureNode:aNode |
1904 |
"origin x where to draw the icon |
|
1905 |
" |
|
494 | 1906 |
^ self xOfFigureLevel:(aNode level) |
1907 |
! |
|
490 | 1908 |
|
494 | 1909 |
xOfStringLevel:aLevel |
1910 |
"origin x where to draw the text( label ) |
|
1911 |
" |
|
1912 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 1913 |
|
1914 |
! |
|
1915 |
||
1916 |
xOfStringNode:aNode |
|
1917 |
"origin x where to draw the text( label ) |
|
1918 |
" |
|
494 | 1919 |
^ self xOfStringLevel:(aNode level) |
483 | 1920 |
|
1921 |
! ! |
|
1922 |
||
444 | 1923 |
!SelectionInTreeView methodsFor:'selection'! |
1924 |
||
468 | 1925 |
selectNode:aNode |
1926 |
"change selection to a node |
|
1927 |
" |
|
855 | 1928 |
|index| |
848 | 1929 |
|
860 | 1930 |
(index := aNode) notNil ifTrue:[ |
1931 |
index isNumber ifFalse:[ |
|
1932 |
(index := self indexOfNode:aNode) == 0 ifTrue:[ |
|
1933 |
model doMakeVisible:aNode. |
|
1934 |
index := self indexOfNode:aNode. |
|
1935 |
] |
|
855 | 1936 |
]. |
848 | 1937 |
index == 0 ifTrue:[ |
855 | 1938 |
index := nil |
848 | 1939 |
] |
1940 |
]. |
|
1941 |
self selection:index |
|
468 | 1942 |
|
1943 |
||
1944 |
! |
|
1945 |
||
456 | 1946 |
selectedIndex |
1947 |
"get single selected index or 0 |
|
1948 |
" |
|
483 | 1949 |
selection size == 1 ifTrue:[^ selection first]. |
1950 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 1951 |
^ 0 |
444 | 1952 |
! |
1953 |
||
1954 |
selectedNode |
|
1955 |
"get the single selected node or nil |
|
1956 |
" |
|
456 | 1957 |
|idx| |
1958 |
||
1959 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
1960 |
^ listOfNodes at:idx |
|
444 | 1961 |
]. |
1962 |
^ nil |
|
514 | 1963 |
! |
1964 |
||
1965 |
selectionChangedFrom:oldSelection |
|
1966 |
"update selectionHolder if not nil |
|
1967 |
" |
|
1968 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1969 |
"/ first change my selectionHolders value ... |
514 | 1970 |
selectionHolder notNil ifTrue:[ |
1971 |
self selectionToModel. |
|
1972 |
]. |
|
1973 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1974 |
"/ ... then make notifications. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1975 |
super selectionChangedFrom:oldSelection. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1976 |
|
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1977 |
|
444 | 1978 |
! ! |
1979 |
||
855 | 1980 |
!SelectionInTreeView methodsFor:'selection actions'! |
507 | 1981 |
|
1982 |
selectedNodeAdd:something |
|
1983 |
"add a node or collection of nodes after selected node |
|
1984 |
" |
|
1985 |
|node| |
|
1986 |
||
1987 |
something notNil ifTrue:[ |
|
1988 |
(node := self selectedNode) notNil ifTrue:[ |
|
1989 |
node parent notNil ifTrue:[ |
|
1990 |
node isCollapsable ifTrue:[ |
|
1991 |
model add:something beforeIndex:1 below:node |
|
1992 |
] ifFalse:[ |
|
1993 |
model add:something after:node |
|
1994 |
] |
|
1995 |
] ifFalse:[ |
|
1996 |
model add:something beforeIndex:1 below:(self root) |
|
1997 |
] |
|
1998 |
] |
|
1999 |
] |
|
2000 |
||
2001 |
! |
|
2002 |
||
2003 |
selectedNodeBecomeChildOfNext |
|
2004 |
"become node a child of followd node |
|
2005 |
" |
|
2006 |
|idx node cprt nprt| |
|
2007 |
||
2008 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
2009 |
idx := cprt indexOfChild:node. |
|
2010 |
||
2011 |
idx == cprt children size ifFalse:[ |
|
2012 |
nprt := cprt childAt:(idx + 1). |
|
2013 |
||
2014 |
nprt notNil ifTrue:[ |
|
855 | 2015 |
self setSelection:nil. |
2016 |
model remove:node. |
|
507 | 2017 |
model add:node beforeIndex:1 below:nprt. |
2018 |
self selectNode:node. |
|
2019 |
] |
|
2020 |
] |
|
2021 |
] |
|
2022 |
! |
|
2023 |
||
2024 |
selectedNodeBecomeSisterOfParent |
|
2025 |
"become node a sister of its current parent |
|
2026 |
" |
|
2027 |
|node cprt nprt| |
|
2028 |
||
2029 |
( (node := self selectedNode) isNil |
|
2030 |
or:[(cprt := node parent) isNil |
|
2031 |
or:[(nprt := cprt parent) isNil]] |
|
2032 |
) ifFalse:[ |
|
855 | 2033 |
self setSelection:nil. |
2034 |
model remove:node. |
|
507 | 2035 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
855 | 2036 |
self selectNode:node. |
507 | 2037 |
] |
2038 |
||
2039 |
! |
|
2040 |
||
2041 |
selectedNodeChangeSequenceOrder:anOffset |
|
2042 |
"move child 'anOffset' forward or backward in list of children |
|
2043 |
" |
|
2044 |
|idx node size parent| |
|
2045 |
||
2046 |
( (node := self selectedNode) notNil |
|
2047 |
and:[(parent := node parent) notNil |
|
2048 |
and:[(size := parent children size) > 1]] |
|
2049 |
) ifTrue:[ |
|
2050 |
idx := parent indexOfChild:node. |
|
855 | 2051 |
self setSelection:nil. |
2052 |
model remove:node. |
|
507 | 2053 |
|
2054 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
2055 |
idx := size |
|
2056 |
] ifFalse:[ |
|
2057 |
idx > size ifTrue:[idx := 1] |
|
2058 |
]. |
|
2059 |
model add:node beforeIndex:idx below:parent. |
|
2060 |
self selectNode:node. |
|
2061 |
] |
|
2062 |
! |
|
2063 |
||
2064 |
selectedNodeExpand:doExpand |
|
2065 |
"collapse or expand selected node |
|
2066 |
" |
|
855 | 2067 |
|node| |
507 | 2068 |
|
855 | 2069 |
(node := self selectedNode) notNil ifTrue:[ |
2070 |
doExpand ifTrue:[model doExpand:node] |
|
2071 |
ifFalse:[model doCollapse:node] |
|
2072 |
] |
|
507 | 2073 |
! |
2074 |
||
2075 |
selectedNodesRemove |
|
2076 |
"remove selected nodes |
|
2077 |
" |
|
855 | 2078 |
|selection| |
2079 |
||
2080 |
selection := self selection. |
|
507 | 2081 |
self selection:nil. |
855 | 2082 |
model remove:selection. |
507 | 2083 |
! ! |
2084 |
||
444 | 2085 |
!SelectionInTreeView class methodsFor:'documentation'! |
2086 |
||
2087 |
version |
|
908 | 2088 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.62 1998-06-03 14:33:55 ca Exp $' |
444 | 2089 |
! ! |