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