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