0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
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 |
ListView subclass:#SelectionInListView
|
|
14 |
instanceVariableNames:'selection actionBlock enabled
|
59
|
15 |
hilightFgColor hilightBgColor
|
|
16 |
halfIntensityFgColor
|
|
17 |
doubleClickActionBlock
|
|
18 |
selectConditionBlock
|
|
19 |
listAttributes multipleSelectOk clickLine
|
|
20 |
listSymbol initialSelectionSymbol printItems oneItem
|
|
21 |
hilightLevel hilightFrameColor ignoreReselect
|
|
22 |
arrowLevel smallArrow keyActionStyle'
|
|
23 |
classVariableNames:'RightArrowShadowForm RightArrowLightForm RightArrowForm
|
|
24 |
SmallRightArrowShadowForm SmallRightArrowLightForm
|
|
25 |
DefaultForegroundColor DefaultBackgroundColor
|
|
26 |
DefaultHilightForegroundColor DefaultHilightBackgroundColor
|
|
27 |
DefaultHilightFrameColor DefaultHilightLevel DefaultFont
|
|
28 |
DefaultRightArrowStyle DefaultRightArrowLevel
|
|
29 |
DefaultDisabledForegroundColor
|
|
30 |
DefaultShadowColor DefaultLightColor'
|
0
|
31 |
poolDictionaries:''
|
|
32 |
category:'Views-Text'
|
|
33 |
!
|
|
34 |
|
|
35 |
SelectionInListView comment:'
|
5
|
36 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
37 |
All Rights Reserved
|
38
|
38 |
|
60
|
39 |
$Header: /cvs/stx/stx/libwidg/Attic/SelListV.st,v 1.12 1994-10-28 03:25:26 claus Exp $
|
7
|
40 |
'!
|
0
|
41 |
|
7
|
42 |
!SelectionInListView class methodsFor:'documentation'!
|
|
43 |
|
38
|
44 |
copyright
|
|
45 |
"
|
|
46 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
47 |
All Rights Reserved
|
38
|
48 |
|
|
49 |
This software is furnished under a license and may be used
|
|
50 |
only in accordance with the terms of that license and with the
|
|
51 |
inclusion of the above copyright notice. This software may not
|
|
52 |
be provided or otherwise made available to, or used by, any
|
|
53 |
other person. No title to or ownership of the software is
|
|
54 |
hereby transferred.
|
|
55 |
"
|
|
56 |
!
|
|
57 |
|
|
58 |
version
|
|
59 |
"
|
60
|
60 |
$Header: /cvs/stx/stx/libwidg/Attic/SelListV.st,v 1.12 1994-10-28 03:25:26 claus Exp $
|
38
|
61 |
"
|
|
62 |
!
|
|
63 |
|
7
|
64 |
documentation
|
|
65 |
"
|
31
|
66 |
this one is a ListView with a selected line (which is shown highlighted)
|
38
|
67 |
If multipleSelectionsOk is true, it is also allowed to shift-click multiple
|
|
68 |
entries.
|
31
|
69 |
|
38
|
70 |
Whenever the selection changes, an action-block is evaluated, passing the
|
|
71 |
current selection as argument.
|
|
72 |
Currently, the selection can be nil, aNumber or a collection of numbers;
|
|
73 |
this will change to be either nil or a collection, making selection handling
|
|
74 |
easier in the future.
|
59
|
75 |
The actionBlock is called with the current selection (single number or
|
|
76 |
collection of numbers) as argument.
|
|
77 |
|
|
78 |
Also, to support ST-80 MVC-style use, the model (if nonNil) is notified
|
|
79 |
by the change mechanism (performs changeSymbol).
|
|
80 |
|
60
|
81 |
Before actually adding entries to the the selection, a checkBlock (if non-nil) is evaluated
|
|
82 |
passing the number of the entry whch is about to be selected as argument.
|
|
83 |
The select change operation is only done if this returns true. This allows
|
59
|
84 |
interception of select, for example to query the user if he/she wants to save
|
60
|
85 |
the old contents before (see uses in SystemBrowser and FileBrowser), or to
|
|
86 |
disable individual entries.
|
31
|
87 |
|
38
|
88 |
It is also possible to select entries with the keyboard; use the cursor up/
|
|
89 |
down keys to select prev/next, Home- and End-keys to select first/last.
|
|
90 |
Use the return key to apply the double-click-action to the current selection.
|
|
91 |
Also, alphabetic keys will select the next entry starting with that key.
|
|
92 |
|
|
93 |
The keyboard behavior can be further controlled with the keyActionStyle
|
|
94 |
instance variable (see SelectionInListView>>keyActionStyle:).
|
|
95 |
|
59
|
96 |
Finally, ignoreReselect controls if pressing on an already selected item
|
|
97 |
triggers the action or not. For some applications it is useful to allow
|
|
98 |
reselects (for example, the SystemBrowsers method-list updates the
|
|
99 |
source code in this case).
|
38
|
100 |
|
60
|
101 |
Currently, some limited form of line attributes are supported. These
|
|
102 |
are kept in the instance variable lineAttributes.
|
|
103 |
This may change (using mechanisms similar to MultiColListEntry), so
|
|
104 |
be prepared. (dont use attributes, if possible - use MultiColListEntry or
|
|
105 |
subclasses of it).
|
|
106 |
|
31
|
107 |
InstanceVariables:
|
59
|
108 |
selection <misc> the current selection. nil, a number or collection of numbers
|
31
|
109 |
|
59
|
110 |
actionBlock <Block> block to be evaluated on selection changes
|
31
|
111 |
|
59
|
112 |
enabled <Boolean> true: selection changes allowed; false: ignore clicks
|
31
|
113 |
|
59
|
114 |
hilightFgColor
|
|
115 |
hilightBgColor <Color> how highlighted items are drawn
|
31
|
116 |
|
59
|
117 |
halfIntensityColor <Color> foreground for disabled items
|
31
|
118 |
|
59
|
119 |
selectConditionBlock <Block> if non-nil, this nlock can decide if selection is ok
|
0
|
120 |
|
59
|
121 |
doubleClickActionBlock <Block> action to perform on double-click
|
31
|
122 |
|
59
|
123 |
listAttributes dont use - will vanish
|
31
|
124 |
|
59
|
125 |
multipleSelectOk <Boolean> if true, multiple selections (with shift) are ok
|
|
126 |
hilightLevel <Integer> level to draw selections (i.e. for 3D effect)
|
|
127 |
hilightFrameColor <Color> rectangle around highlighted items
|
31
|
128 |
|
59
|
129 |
ignoreReselect <Boolean> if true, selecting same again does not trigger action;
|
|
130 |
if false, every select triggers it
|
0
|
131 |
|
59
|
132 |
arrowLevel <Integer> level to draw right-arrows (for submenus etc.)
|
|
133 |
smallArrow <Boolean> if true, uses a small arrow bitmap
|
31
|
134 |
|
59
|
135 |
listSymbol if non-nil, use ST-80 style (model-access)
|
|
136 |
initialSelectionSymbol
|
|
137 |
printItems
|
|
138 |
oneItem
|
31
|
139 |
|
59
|
140 |
keyActionStyle <Symbol> controls how to respond to keyboard selects
|
31
|
141 |
|
|
142 |
written spring/summer 89 by claus
|
|
143 |
3D Jan 90 by claus
|
38
|
144 |
multiselect Jun 92 by claus
|
|
145 |
keyboard-select jun 94 by claus
|
7
|
146 |
"
|
|
147 |
! !
|
0
|
148 |
|
22
|
149 |
!SelectionInListView class methodsFor:'defaults'!
|
|
150 |
|
59
|
151 |
updateStyleCache
|
60
|
152 |
DefaultDisabledForegroundColor := StyleSheet colorAt:'selectionDisabledForegroundColor'.
|
|
153 |
DefaultHilightForegroundColor := StyleSheet colorAt:'selectionHilightForegroundColor'.
|
|
154 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'selectionHilightBackgroundColor'.
|
|
155 |
DefaultHilightFrameColor := StyleSheet colorAt:'selectionHilightFrameColor'.
|
59
|
156 |
DefaultHilightLevel := StyleSheet at:'selectionHilightLevel' default:0.
|
|
157 |
DefaultRightArrowStyle := StyleSheet at:'selectionRightArrowStyle'.
|
|
158 |
DefaultRightArrowLevel := StyleSheet at:'selectionRightArrowLevel'.
|
60
|
159 |
DefaultForegroundColor := StyleSheet colorAt:'selectionForegroundColor'.
|
|
160 |
DefaultBackgroundColor := StyleSheet colorAt:'selectionBackgroundColor'.
|
|
161 |
DefaultShadowColor := StyleSheet colorAt:'selectionShadowColor'.
|
|
162 |
DefaultLightColor := StyleSheet colorAt:'selectionLightColor'.
|
|
163 |
DefaultFont := StyleSheet fontAt:'selectionFont'.
|
59
|
164 |
|
|
165 |
"
|
|
166 |
self updateStyleCache
|
|
167 |
"
|
|
168 |
!
|
|
169 |
|
22
|
170 |
rightArrowLightFormOn:aDevice
|
|
171 |
"return the form used for the right arrow light pixels (3D only)"
|
|
172 |
|
|
173 |
|f|
|
|
174 |
|
|
175 |
((aDevice == Display) and:[RightArrowLightForm notNil]) ifTrue:[
|
59
|
176 |
^ RightArrowLightForm
|
22
|
177 |
].
|
|
178 |
f := Form fromFile:'RightArrowLight.xbm' resolution:100 on:aDevice.
|
|
179 |
f isNil ifTrue:[
|
59
|
180 |
f := Form width:16 height:16 fromArray:#[2r00000000 2r00000000
|
|
181 |
2r00000000 2r00000000
|
|
182 |
2r00000000 2r00000000
|
|
183 |
2r00000110 2r00000000
|
|
184 |
2r00000101 2r00000000
|
|
185 |
2r00000100 2r10000000
|
|
186 |
2r00000100 2r01000000
|
|
187 |
2r00000100 2r00100000
|
|
188 |
2r00000100 2r00000000
|
|
189 |
2r00000100 2r00000000
|
|
190 |
2r00000100 2r00000000
|
|
191 |
2r00000100 2r00000000
|
|
192 |
2r00000100 2r00000000
|
|
193 |
2r00000100 2r00000000
|
|
194 |
2r00000000 2r00000000
|
|
195 |
2r00000000 2r00000000]
|
|
196 |
on:aDevice
|
22
|
197 |
].
|
|
198 |
(aDevice == Display) ifTrue:[
|
59
|
199 |
RightArrowLightForm := f
|
22
|
200 |
].
|
|
201 |
^ f
|
|
202 |
!
|
|
203 |
|
|
204 |
rightArrowShadowFormOn:aDevice
|
|
205 |
"return the form used for the right arrow light pixels (3D only)"
|
|
206 |
|
|
207 |
|f|
|
|
208 |
|
|
209 |
((aDevice == Display) and:[RightArrowShadowForm notNil]) ifTrue:[
|
59
|
210 |
^ RightArrowShadowForm
|
22
|
211 |
].
|
|
212 |
f := Form fromFile:'RightArrowShadow.xbm' resolution:100 on:aDevice.
|
|
213 |
f isNil ifTrue:[
|
59
|
214 |
f := Form width:16 height:16 fromArray:#[2r00000000 2r00000000
|
|
215 |
2r00000000 2r00000000
|
|
216 |
2r00000000 2r00000000
|
|
217 |
2r00000000 2r00000000
|
|
218 |
2r00000000 2r00000000
|
|
219 |
2r00000000 2r00000000
|
|
220 |
2r00000000 2r00000000
|
|
221 |
2r00000000 2r00000000
|
|
222 |
2r00000000 2r00010000
|
|
223 |
2r00000000 2r00100000
|
|
224 |
2r00000000 2r01000000
|
|
225 |
2r00000000 2r10000000
|
|
226 |
2r00000001 2r00000000
|
|
227 |
2r00000010 2r00000000
|
|
228 |
2r00000000 2r00000000
|
|
229 |
2r00000000 2r00000000]
|
|
230 |
on:aDevice
|
22
|
231 |
].
|
|
232 |
(aDevice == Display) ifTrue:[
|
59
|
233 |
RightArrowShadowForm := f
|
22
|
234 |
].
|
|
235 |
^ f
|
|
236 |
!
|
|
237 |
|
|
238 |
rightArrowFormOn:aDevice
|
|
239 |
"return the form used for the right arrow (non 3D)"
|
|
240 |
|
|
241 |
|f|
|
|
242 |
|
|
243 |
((aDevice == Display) and:[RightArrowForm notNil]) ifTrue:[
|
59
|
244 |
^ RightArrowForm
|
22
|
245 |
].
|
|
246 |
f := Form fromFile:'RightArrow.xbm' resolution:100 on:aDevice.
|
|
247 |
f isNil ifTrue:[
|
59
|
248 |
f := Form width:16 height:16 fromArray:#[2r00000000 2r00000000
|
|
249 |
2r00000000 2r00000000
|
|
250 |
2r00000000 2r00000000
|
|
251 |
2r00000110 2r00000000
|
|
252 |
2r00000101 2r00000000
|
|
253 |
2r00000100 2r10000000
|
|
254 |
2r00000100 2r01000000
|
|
255 |
2r00000100 2r00100000
|
|
256 |
2r00000100 2r00010000
|
|
257 |
2r00000100 2r00100000
|
|
258 |
2r00000100 2r01000000
|
|
259 |
2r00000100 2r10000000
|
|
260 |
2r00000101 2r00000000
|
|
261 |
2r00000110 2r00000000
|
|
262 |
2r00000000 2r00000000
|
|
263 |
2r00000000 2r00000000]
|
|
264 |
on:aDevice
|
22
|
265 |
].
|
|
266 |
(aDevice == Display) ifTrue:[
|
59
|
267 |
RightArrowForm := f
|
22
|
268 |
].
|
|
269 |
^ f
|
31
|
270 |
!
|
|
271 |
|
|
272 |
smallRightArrowLightFormOn:aDevice
|
|
273 |
"return the form used for the small right arrow light pixels (3D only)"
|
|
274 |
|
|
275 |
|f|
|
|
276 |
|
|
277 |
((aDevice == Display) and:[SmallRightArrowLightForm notNil]) ifTrue:[
|
59
|
278 |
^ SmallRightArrowLightForm
|
31
|
279 |
].
|
|
280 |
f := Form fromFile:'SmallRightArrowLight.xbm' resolution:100 on:aDevice.
|
|
281 |
f isNil ifTrue:[
|
59
|
282 |
f := Form width:9 height:9 fromArray:#[2r00000000 2r00000000
|
|
283 |
2r01100000 2r00000000
|
|
284 |
2r01011000 2r00000000
|
|
285 |
2r01000110 2r00000000
|
|
286 |
2r01000000 2r00000000
|
|
287 |
2r01000000 2r00000000
|
|
288 |
2r01000000 2r00000000
|
|
289 |
2r01000000 2r00000000
|
|
290 |
2r00000000 2r00000000]
|
|
291 |
on:aDevice
|
31
|
292 |
].
|
|
293 |
(aDevice == Display) ifTrue:[
|
59
|
294 |
SmallRightArrowLightForm := f
|
31
|
295 |
].
|
|
296 |
^ f
|
|
297 |
!
|
|
298 |
|
|
299 |
smallRightArrowShadowFormOn:aDevice
|
|
300 |
"return the form used for the small right arrow light pixels (3D only)"
|
|
301 |
|
|
302 |
|f|
|
|
303 |
|
|
304 |
((aDevice == Display) and:[SmallRightArrowShadowForm notNil]) ifTrue:[
|
59
|
305 |
^ SmallRightArrowShadowForm
|
31
|
306 |
].
|
|
307 |
f := Form fromFile:'SmallRightArrowShadow.xbm' resolution:100 on:aDevice.
|
|
308 |
f isNil ifTrue:[
|
59
|
309 |
f := Form width:9 height:9 fromArray:#[2r00000000 2r00000000
|
|
310 |
2r00000000 2r00000000
|
|
311 |
2r00000000 2r00000000
|
|
312 |
2r00000000 2r00000000
|
|
313 |
2r00000001 2r00000000
|
|
314 |
2r00000110 2r00000000
|
|
315 |
2r00011000 2r00000000
|
|
316 |
2r00100000 2r00000000
|
|
317 |
2r00000000 2r00000000]
|
|
318 |
on:aDevice
|
31
|
319 |
].
|
|
320 |
(aDevice == Display) ifTrue:[
|
59
|
321 |
SmallRightArrowShadowForm := f
|
31
|
322 |
].
|
|
323 |
^ f
|
22
|
324 |
! !
|
|
325 |
|
0
|
326 |
!SelectionInListView class methodsFor:'instance creation'!
|
|
327 |
|
|
328 |
on:aModel printItems:print oneItem:one aspect:aspect
|
59
|
329 |
change:change list:list menu:menu
|
|
330 |
initialSelection:initial
|
0
|
331 |
|
|
332 |
"for ST-80 compatibility"
|
|
333 |
|
|
334 |
^ (self new) on:aModel printItems:print oneItem:one aspect:aspect
|
59
|
335 |
change:change list:list menu:menu
|
|
336 |
initialSelection:initial
|
0
|
337 |
! !
|
|
338 |
|
|
339 |
!SelectionInListView methodsFor:'initialization'!
|
|
340 |
|
|
341 |
initialize
|
|
342 |
super initialize.
|
|
343 |
|
|
344 |
fontHeight := font height + lineSpacing.
|
|
345 |
multipleSelectOk := false.
|
7
|
346 |
enabled := true.
|
|
347 |
ignoreReselect := true.
|
38
|
348 |
keyActionStyle := #select.
|
0
|
349 |
!
|
|
350 |
|
|
351 |
initStyle
|
59
|
352 |
|nm|
|
|
353 |
|
0
|
354 |
super initStyle.
|
|
355 |
|
59
|
356 |
DefaultFont notNil ifTrue:[
|
|
357 |
font := DefaultFont on:device
|
|
358 |
].
|
|
359 |
|
0
|
360 |
bgColor := viewBackground.
|
7
|
361 |
hilightFrameColor := nil.
|
|
362 |
hilightLevel := 0.
|
31
|
363 |
arrowLevel := 1.
|
|
364 |
smallArrow := false.
|
0
|
365 |
|
59
|
366 |
device hasGreyscales ifTrue:[
|
|
367 |
"
|
|
368 |
must get rid of these explicit name-checks
|
|
369 |
"
|
|
370 |
nm := StyleSheet name asSymbol.
|
|
371 |
(nm == #next) ifTrue:[
|
|
372 |
hilightFgColor := fgColor.
|
|
373 |
hilightBgColor := White.
|
|
374 |
hilightFrameColor := fgColor
|
|
375 |
] ifFalse:[
|
|
376 |
(nm == #motif) ifTrue:[
|
|
377 |
fgColor := White.
|
|
378 |
bgColor := Grey.
|
|
379 |
viewBackground := bgColor.
|
|
380 |
hilightFgColor := bgColor "fgColor" "White".
|
|
381 |
hilightBgColor := fgColor "bgColor lightened" "darkened".
|
|
382 |
] ifFalse:[
|
|
383 |
(nm == #openwin) ifTrue:[
|
|
384 |
hilightFgColor := fgColor.
|
|
385 |
hilightBgColor := Color grey.
|
|
386 |
smallArrow := true.
|
|
387 |
]
|
|
388 |
]
|
|
389 |
]
|
|
390 |
].
|
|
391 |
|
|
392 |
hilightFgColor isNil ifTrue:[
|
|
393 |
hilightFgColor := bgColor.
|
|
394 |
].
|
|
395 |
hilightBgColor isNil ifTrue:[
|
|
396 |
hilightBgColor := fgColor.
|
|
397 |
].
|
|
398 |
DefaultForegroundColor notNil ifTrue:[
|
|
399 |
fgColor := DefaultForegroundColor
|
|
400 |
].
|
|
401 |
DefaultBackgroundColor notNil ifTrue:[
|
|
402 |
bgColor := DefaultBackgroundColor
|
|
403 |
].
|
|
404 |
DefaultHilightForegroundColor notNil ifTrue:[
|
|
405 |
hilightFgColor := DefaultHilightForegroundColor
|
|
406 |
].
|
|
407 |
DefaultHilightBackgroundColor notNil ifTrue:[
|
|
408 |
hilightBgColor := DefaultHilightBackgroundColor
|
|
409 |
].
|
|
410 |
DefaultHilightFrameColor notNil ifTrue:[
|
|
411 |
hilightFrameColor := DefaultHilightFrameColor
|
|
412 |
].
|
|
413 |
DefaultHilightLevel notNil ifTrue:[
|
|
414 |
hilightLevel := DefaultHilightLevel
|
|
415 |
].
|
|
416 |
DefaultRightArrowLevel notNil ifTrue:[
|
|
417 |
arrowLevel := DefaultRightArrowLevel
|
|
418 |
].
|
|
419 |
|
|
420 |
DefaultShadowColor notNil ifTrue:[
|
|
421 |
shadowColor := DefaultShadowColor on:device
|
|
422 |
].
|
|
423 |
DefaultLightColor notNil ifTrue:[
|
|
424 |
lightColor := DefaultLightColor on:device
|
0
|
425 |
].
|
|
426 |
|
31
|
427 |
(hilightLevel abs > 0) ifTrue:[
|
59
|
428 |
lineSpacing := 3
|
31
|
429 |
] ifFalse:[
|
59
|
430 |
lineSpacing := 2
|
31
|
431 |
].
|
|
432 |
|
0
|
433 |
hilightFgColor isNil ifTrue:[
|
59
|
434 |
hilightFgColor := bgColor.
|
|
435 |
hilightBgColor := fgColor
|
0
|
436 |
].
|
|
437 |
|
59
|
438 |
DefaultDisabledForegroundColor notNil ifTrue:[
|
|
439 |
halfIntensityFgColor := DefaultDisabledForegroundColor
|
|
440 |
] ifFalse:[
|
|
441 |
halfIntensityFgColor := Color darkGrey.
|
|
442 |
].
|
|
443 |
|
|
444 |
fgColor := fgColor on:device.
|
|
445 |
bgColor := bgColor on:device.
|
|
446 |
halfIntensityFgColor := halfIntensityFgColor on:device.
|
|
447 |
hilightFrameColor notNil ifTrue:[hilightFrameColor := hilightFrameColor on:device].
|
|
448 |
hilightFgColor := hilightFgColor on:device.
|
|
449 |
hilightBgColor := hilightBgColor on:device.
|
0
|
450 |
!
|
|
451 |
|
|
452 |
initCursor
|
|
453 |
"set the cursor - a hand"
|
|
454 |
|
|
455 |
cursor := Cursor hand
|
|
456 |
!
|
|
457 |
|
|
458 |
initEvents
|
|
459 |
super initEvents.
|
|
460 |
self enableButtonEvents
|
|
461 |
!
|
|
462 |
|
|
463 |
realize
|
|
464 |
super realize.
|
|
465 |
selection notNil ifTrue:[
|
59
|
466 |
self makeLineVisible:selection
|
0
|
467 |
]
|
|
468 |
! !
|
|
469 |
|
|
470 |
!SelectionInListView methodsFor:'accessing'!
|
|
471 |
|
38
|
472 |
keyActionStyle:aSymbol
|
|
473 |
"defines how the view should respond to alpha-keys pressed.
|
|
474 |
Possible values are:
|
59
|
475 |
#select -> will select next entry starting with that
|
|
476 |
character and perform the click-action
|
38
|
477 |
|
59
|
478 |
#selectAndDoubleclick -> will select next & perform double-click action
|
38
|
479 |
|
59
|
480 |
#pass -> will pass key to superclass (i.e. no special treatment)
|
38
|
481 |
|
59
|
482 |
nil -> will ignore key
|
38
|
483 |
"
|
|
484 |
|
|
485 |
keyActionStyle := aSymbol
|
|
486 |
!
|
|
487 |
|
0
|
488 |
setList:aCollection
|
|
489 |
"set the list - redefined, since setting the list implies unselecting"
|
|
490 |
|
|
491 |
selection := nil.
|
|
492 |
super setList:aCollection
|
|
493 |
!
|
|
494 |
|
|
495 |
list:aCollection
|
|
496 |
"set the list - redefined, since setting the list implies unselecting"
|
|
497 |
|
7
|
498 |
"somewhat of a kludge: if selection is first line,
|
|
499 |
we have to remove the highlight frame by hand here"
|
|
500 |
|
|
501 |
(shown and:[hilightLevel ~~ 0]) ifTrue:[
|
59
|
502 |
selection == firstLineShown ifTrue:[
|
|
503 |
self paint:bgColor.
|
|
504 |
self fillRectangleX:margin y:margin
|
|
505 |
width:(width - (margin * 2))
|
|
506 |
height:(hilightLevel abs).
|
|
507 |
].
|
7
|
508 |
].
|
|
509 |
|
0
|
510 |
selection := nil.
|
|
511 |
super list:aCollection
|
|
512 |
!
|
|
513 |
|
|
514 |
attributes:aList
|
|
515 |
"set the attribute list"
|
|
516 |
|
|
517 |
listAttributes := attributes
|
|
518 |
!
|
|
519 |
|
|
520 |
attributeAt:index
|
|
521 |
"return the line attribute of list line index"
|
|
522 |
|
|
523 |
listAttributes isNil ifFalse:[
|
59
|
524 |
(index > listAttributes size) ifFalse:[
|
|
525 |
^ listAttributes at:index
|
|
526 |
]
|
0
|
527 |
].
|
|
528 |
^ nil
|
|
529 |
!
|
|
530 |
|
60
|
531 |
attributeAt:index put:aSymbolOrCollectionOfSymbolsOrNil
|
|
532 |
"set a line attribute;
|
|
533 |
currently supported are:
|
|
534 |
#halfIntensity
|
|
535 |
#disabled
|
0
|
536 |
"
|
|
537 |
|
|
538 |
(index > list size) ifFalse:[
|
59
|
539 |
listAttributes isNil ifTrue:[
|
|
540 |
listAttributes := VariableArray new:index
|
|
541 |
] ifFalse:[
|
|
542 |
(index > listAttributes size) ifTrue:[
|
|
543 |
listAttributes grow:index
|
|
544 |
]
|
|
545 |
].
|
60
|
546 |
aSymbolOrCollectionOfSymbolsOrNil = (listAttributes at:index) ifFalse:[
|
|
547 |
listAttributes at:index put:aSymbolOrCollectionOfSymbolsOrNil.
|
59
|
548 |
self redrawLine:index
|
|
549 |
]
|
0
|
550 |
]
|
|
551 |
!
|
|
552 |
|
60
|
553 |
line:lineNr hasAttribute:aSymbol
|
|
554 |
"return true, if line nr has attribute, aSymbol;
|
|
555 |
currently suppoerted attributes are:
|
|
556 |
#halfIntensity
|
|
557 |
#disabled
|
|
558 |
"
|
|
559 |
|
|
560 |
|attr|
|
|
561 |
|
|
562 |
(lineNr > listAttributes size) ifTrue:[^ false].
|
|
563 |
attr := listAttributes at:lineNr.
|
|
564 |
attr isNil ifTrue:[^ false].
|
|
565 |
attr isSymbol ifTrue:[^ attr == aSymbol].
|
|
566 |
^ (attr includes:aSymbol)
|
|
567 |
!
|
|
568 |
|
7
|
569 |
removeIndexWithoutRedraw:lineNr
|
|
570 |
"delete line - no redraw;
|
|
571 |
return true, if something was really deleted.
|
|
572 |
Redefined since we have to care for selection"
|
|
573 |
|
|
574 |
self checkRemovingSelection:lineNr.
|
|
575 |
^ super removeIndexWithoutRedraw:lineNr
|
|
576 |
!
|
|
577 |
|
|
578 |
removeIndex:lineNr
|
|
579 |
"delete line - with redraw.
|
|
580 |
Redefined since we have to care for selection"
|
|
581 |
|
|
582 |
self checkRemovingSelection:lineNr.
|
|
583 |
^ super removeIndex:lineNr
|
|
584 |
!
|
|
585 |
|
0
|
586 |
action:aBlock
|
|
587 |
"set the action block to be performed on select"
|
|
588 |
|
|
589 |
actionBlock := aBlock
|
|
590 |
!
|
|
591 |
|
|
592 |
doubleClickAction:aBlock
|
|
593 |
"set the double click action block to be performed on select"
|
|
594 |
|
|
595 |
doubleClickActionBlock := aBlock
|
|
596 |
!
|
|
597 |
|
59
|
598 |
on:aModel printItems:print oneItem:one aspect:aspect
|
|
599 |
change:change list:list menu:menu
|
|
600 |
initialSelection:initial
|
|
601 |
|
|
602 |
"ST-80 compatibility"
|
|
603 |
|
|
604 |
aspectSymbol := aspect.
|
|
605 |
changeSymbol := change.
|
|
606 |
listSymbol := list.
|
|
607 |
menuSymbol := menu.
|
|
608 |
initialSelectionSymbol := initial.
|
|
609 |
printItems := print.
|
|
610 |
oneItem := one.
|
|
611 |
|
|
612 |
model := aModel.
|
|
613 |
|
|
614 |
listSymbol notNil ifTrue:[
|
|
615 |
self list:(aModel perform:listSymbol) asText
|
|
616 |
].
|
|
617 |
model addDependent:self
|
|
618 |
! !
|
|
619 |
|
|
620 |
!SelectionInListView methodsFor:'selections'!
|
|
621 |
|
|
622 |
multipleSelectOk:aBoolean
|
|
623 |
"allow/disallow multiple selections"
|
|
624 |
|
|
625 |
multipleSelectOk := aBoolean.
|
|
626 |
aBoolean ifTrue:[
|
|
627 |
self enableButtonMotionEvents
|
|
628 |
] ifFalse:[
|
|
629 |
self disableButtonMotionEvents
|
|
630 |
]
|
|
631 |
!
|
|
632 |
|
|
633 |
ignoreReselect:aBoolean
|
|
634 |
"set/clear the ignoreReselect flag -
|
|
635 |
if set, a click on an already selected entry is ignored.
|
|
636 |
Otherwise the notification is done, even if no
|
|
637 |
change in the selection occurs.
|
|
638 |
(for example, in browser to update a method)"
|
|
639 |
|
|
640 |
ignoreReselect := aBoolean
|
|
641 |
!
|
|
642 |
|
|
643 |
enable
|
|
644 |
"enable selections"
|
|
645 |
|
|
646 |
enabled := true
|
|
647 |
!
|
|
648 |
|
|
649 |
disable
|
|
650 |
"disable selections"
|
|
651 |
|
|
652 |
enabled := false
|
|
653 |
!
|
|
654 |
|
3
|
655 |
selectConditionBlock:aBlock
|
|
656 |
"set the conditionBlock; this block is evaluated before a selection
|
|
657 |
change is performed; the change will not be done, if the evaluation
|
|
658 |
returns false. For example, this allows confirmation queries in
|
|
659 |
the SystemBrowser"
|
|
660 |
|
|
661 |
selectConditionBlock := aBlock
|
|
662 |
!
|
7
|
663 |
|
|
664 |
numberOfSelections
|
|
665 |
"return the number of selected entries"
|
|
666 |
|
|
667 |
|sz|
|
|
668 |
|
|
669 |
selection isNil ifTrue:[^ 0].
|
|
670 |
sz := selection size.
|
|
671 |
sz > 0 ifTrue:[^ sz].
|
|
672 |
^ 1
|
|
673 |
!
|
|
674 |
|
60
|
675 |
hasSelection
|
|
676 |
^ selection isNil
|
|
677 |
!
|
|
678 |
|
0
|
679 |
selectionValue
|
7
|
680 |
"return the selection value i.e. the text in the selected line.
|
|
681 |
For multiple selections a collection containing the entries is returned."
|
0
|
682 |
|
|
683 |
selection isNil ifTrue:[^ nil].
|
7
|
684 |
(selection isKindOf:Collection) ifTrue:[
|
59
|
685 |
^ selection collect:[:nr | list at:nr]
|
7
|
686 |
].
|
0
|
687 |
^ list at:selection
|
|
688 |
!
|
|
689 |
|
|
690 |
selection
|
7
|
691 |
"return the selection line nr or collection of line numbers"
|
0
|
692 |
|
|
693 |
^ selection
|
|
694 |
!
|
|
695 |
|
|
696 |
deselect
|
|
697 |
"deselect"
|
|
698 |
|
|
699 |
self selection:nil
|
|
700 |
!
|
|
701 |
|
|
702 |
deselectWithoutRedraw
|
|
703 |
"deselect - no redraw"
|
|
704 |
|
|
705 |
selection := nil
|
|
706 |
!
|
|
707 |
|
59
|
708 |
selectElementWithoutScroll:anObject
|
|
709 |
"select the element with same printString as the argument, anObject.
|
|
710 |
Do not scroll."
|
0
|
711 |
|
|
712 |
|lineNo|
|
|
713 |
|
|
714 |
list notNil ifTrue:[
|
59
|
715 |
lineNo := list indexOf:(anObject printString) ifAbsent:[0].
|
|
716 |
lineNo ~~ 0 ifTrue:[self selectWithoutScroll:lineNo]
|
|
717 |
]
|
|
718 |
!
|
|
719 |
|
|
720 |
selectElement:anObject
|
|
721 |
"select the element with same printString as the argument, anObject.
|
|
722 |
Scroll to make the new selection visible."
|
|
723 |
|
|
724 |
|lineNo|
|
|
725 |
|
|
726 |
list notNil ifTrue:[
|
|
727 |
lineNo := list indexOf:(anObject printString) ifAbsent:[0].
|
|
728 |
lineNo ~~ 0 ifTrue:[self selection:lineNo]
|
0
|
729 |
]
|
|
730 |
!
|
|
731 |
|
|
732 |
selectWithoutScroll:aNumberOrNil
|
|
733 |
"select line, aNumber or deselect if argument is nil"
|
|
734 |
|
|
735 |
|prevSelection newSelection|
|
|
736 |
|
|
737 |
newSelection := aNumberOrNil.
|
|
738 |
newSelection notNil ifTrue:[
|
59
|
739 |
(self isValidSelection:newSelection) ifFalse:[
|
|
740 |
newSelection := nil
|
|
741 |
]
|
0
|
742 |
].
|
|
743 |
|
|
744 |
(newSelection == selection) ifTrue: [^ self].
|
|
745 |
|
|
746 |
selection notNil ifTrue: [
|
59
|
747 |
prevSelection := selection.
|
|
748 |
selection := nil.
|
|
749 |
(prevSelection isKindOf:Collection) ifTrue:[
|
|
750 |
prevSelection do:[:line |
|
|
751 |
self redrawElement:line
|
|
752 |
]
|
|
753 |
] ifFalse:[
|
|
754 |
self redrawElement:prevSelection
|
|
755 |
]
|
0
|
756 |
].
|
|
757 |
selection := newSelection.
|
|
758 |
selection notNil ifTrue:[
|
59
|
759 |
self redrawElement:selection
|
0
|
760 |
]
|
|
761 |
!
|
|
762 |
|
|
763 |
selection:aNumberOrNil
|
|
764 |
"select line, aNumber or deselect if argument is nil;
|
59
|
765 |
scroll to make the selected line visible"
|
0
|
766 |
|
|
767 |
self selectWithoutScroll:aNumberOrNil.
|
|
768 |
selection notNil ifTrue:[
|
59
|
769 |
shown ifTrue:[
|
|
770 |
self makeLineVisible:selection
|
|
771 |
]
|
0
|
772 |
]
|
|
773 |
!
|
|
774 |
|
7
|
775 |
addElementToSelection:anObject
|
|
776 |
"add the element with the same printstring as the argument, anObject
|
59
|
777 |
to the selection. No scrolling is done"
|
7
|
778 |
|
|
779 |
|lineNo|
|
59
|
780 |
|
|
781 |
lineNo := list indexOf:(anObject printString) ifAbsent:[0].
|
|
782 |
lineNo ~~ 0 ifTrue:[self addToSelection:lineNo]
|
7
|
783 |
!
|
|
784 |
|
|
785 |
addToSelection:aNumber
|
59
|
786 |
"add line, aNumber to the selection. No scrolling is done."
|
7
|
787 |
|
|
788 |
selection isNil ifTrue:[^ self selectWithoutScroll:aNumber].
|
|
789 |
|
|
790 |
(self isValidSelection:aNumber) ifFalse:[^ self].
|
|
791 |
(selection isKindOf:Collection) ifTrue:[
|
59
|
792 |
(selection includes:aNumber) ifTrue:[^ self].
|
|
793 |
selection add:aNumber
|
7
|
794 |
] ifFalse:[
|
59
|
795 |
(aNumber == selection) ifTrue:[^ self].
|
|
796 |
selection := OrderedCollection with:selection with:aNumber
|
7
|
797 |
].
|
|
798 |
self redrawElement:aNumber
|
|
799 |
!
|
|
800 |
|
60
|
801 |
nextAfterSelection
|
|
802 |
"return the number of the next selectable entry after the selection.
|
59
|
803 |
Wrap at end."
|
|
804 |
|
|
805 |
|next|
|
0
|
806 |
|
|
807 |
selection isNil ifTrue:[
|
59
|
808 |
next := firstLineShown
|
0
|
809 |
] ifFalse:[
|
59
|
810 |
selection size ~~ 0 ifTrue:[
|
|
811 |
next := selection max + 1
|
|
812 |
] ifFalse:[
|
|
813 |
next := selection + 1
|
|
814 |
].
|
|
815 |
].
|
60
|
816 |
(self isValidSelection:next) ifFalse:[
|
|
817 |
next := 1
|
|
818 |
].
|
|
819 |
(self isValidSelection:next) ifFalse:[
|
|
820 |
next := nil
|
|
821 |
].
|
|
822 |
^ next
|
0
|
823 |
!
|
|
824 |
|
60
|
825 |
selectNext
|
|
826 |
"select next line or first visible if there is currrently no selection.
|
|
827 |
Wrap at end."
|
|
828 |
|
|
829 |
self selection:(self nextAfterSelection)
|
|
830 |
!
|
|
831 |
|
|
832 |
previousBeforeSelection
|
|
833 |
"return the number of the previous selectable entry before the selection.
|
59
|
834 |
Wrap at beginning."
|
|
835 |
|
|
836 |
|prev|
|
0
|
837 |
|
|
838 |
selection isNil ifTrue:[
|
59
|
839 |
prev := firstLineShown - 1
|
0
|
840 |
] ifFalse:[
|
59
|
841 |
selection size ~~ 0 ifTrue:[
|
|
842 |
prev := selection min - 1
|
|
843 |
] ifFalse:[
|
|
844 |
prev := selection - 1
|
|
845 |
].
|
|
846 |
].
|
60
|
847 |
(self isValidSelection:prev) ifFalse:[
|
|
848 |
prev := list size
|
|
849 |
].
|
|
850 |
(self isValidSelection:prev) ifFalse:[
|
|
851 |
prev := nil
|
|
852 |
].
|
|
853 |
^ prev
|
|
854 |
!
|
|
855 |
|
|
856 |
selectPrevious
|
|
857 |
"select previous line or previous visible if there is currently no selection.
|
|
858 |
Wrap at beginning."
|
|
859 |
|
|
860 |
self selection:(self previouseBeforeSelection).
|
0
|
861 |
! !
|
|
862 |
|
|
863 |
!SelectionInListView methodsFor:'private'!
|
|
864 |
|
7
|
865 |
checkRemovingSelection:lineNr
|
|
866 |
"when a line is removed, we have to adjust selection"
|
|
867 |
|
|
868 |
|newSelection|
|
|
869 |
|
|
870 |
selection notNil ifTrue:[
|
59
|
871 |
(selection size > 0) ifTrue:[
|
|
872 |
newSelection := OrderedCollection new.
|
|
873 |
selection do:[:sel |
|
|
874 |
sel < lineNr ifTrue:[
|
|
875 |
newSelection add:sel
|
|
876 |
] ifFalse:[
|
|
877 |
sel > lineNr ifTrue:[
|
|
878 |
newSelection add:(sel - 1)
|
|
879 |
]
|
|
880 |
"otherwise remove it from the selection"
|
|
881 |
]
|
|
882 |
].
|
|
883 |
newSelection size == 1 ifTrue:[
|
|
884 |
selection := newSelection first
|
|
885 |
] ifFalse:[
|
|
886 |
newSelection size == 0 ifTrue:[
|
|
887 |
selection := nil
|
|
888 |
] ifFalse:[
|
|
889 |
selection := newSelection
|
|
890 |
]
|
|
891 |
]
|
|
892 |
] ifFalse:[
|
|
893 |
selection == lineNr ifTrue:[
|
|
894 |
selection := nil
|
|
895 |
] ifFalse:[
|
|
896 |
selection > lineNr ifTrue:[
|
|
897 |
selection := selection - 1
|
|
898 |
]
|
|
899 |
]
|
|
900 |
]
|
7
|
901 |
]
|
|
902 |
!
|
|
903 |
|
0
|
904 |
isValidSelection:aNumber
|
7
|
905 |
"return true, if aNumber is ok for a selection lineNo"
|
0
|
906 |
|
|
907 |
aNumber isNil ifTrue:[^ false].
|
|
908 |
^ (aNumber between:1 and:list size)
|
|
909 |
!
|
|
910 |
|
|
911 |
isInSelection:aNumber
|
|
912 |
"return true, if line, aNumber is in the selection"
|
|
913 |
|
|
914 |
selection isNil ifTrue:[^ false].
|
|
915 |
(selection isKindOf:Collection) ifTrue:[
|
59
|
916 |
^ (selection includes:aNumber)
|
0
|
917 |
].
|
|
918 |
^ (aNumber == selection)
|
|
919 |
!
|
|
920 |
|
|
921 |
positionToSelectionX:x y:y
|
|
922 |
"given a click position, return the selection lineNo"
|
|
923 |
|
|
924 |
|visibleLine|
|
|
925 |
|
|
926 |
(x between:0 and:width) ifTrue:[
|
59
|
927 |
(y between:0 and:height) ifTrue:[
|
|
928 |
visibleLine := self visibleLineOfY:y.
|
|
929 |
^ self visibleLineToListLine:visibleLine
|
|
930 |
]
|
0
|
931 |
].
|
|
932 |
^ nil
|
|
933 |
!
|
|
934 |
|
|
935 |
widthForScrollBetween:start and:end
|
|
936 |
"has to be redefined since WHOLE line is inverted/modified sometimes"
|
|
937 |
|
|
938 |
| anySelectionInRange |
|
|
939 |
|
|
940 |
selection notNil ifTrue:[
|
59
|
941 |
(selection isKindOf:Collection) ifTrue:[
|
|
942 |
anySelectionInRange := false.
|
|
943 |
selection do:[:s |
|
|
944 |
(s between:start and:end) ifTrue:[
|
|
945 |
anySelectionInRange := true
|
|
946 |
]
|
|
947 |
]
|
|
948 |
] ifFalse:[
|
|
949 |
anySelectionInRange := selection between:start and:end
|
|
950 |
]
|
0
|
951 |
] ifFalse:[
|
59
|
952 |
anySelectionInRange := false
|
0
|
953 |
].
|
|
954 |
|
|
955 |
anySelectionInRange ifTrue:[
|
59
|
956 |
^ width
|
31
|
957 |
"
|
59
|
958 |
self is3D ifFalse:[
|
|
959 |
^ width
|
|
960 |
].
|
|
961 |
( #(next openwin) includes:style) ifTrue:[
|
|
962 |
^ width
|
|
963 |
].
|
|
964 |
viewBackground = background ifFalse:[
|
|
965 |
^ width
|
|
966 |
]
|
31
|
967 |
"
|
0
|
968 |
].
|
|
969 |
^ super widthForScrollBetween:start and:end
|
|
970 |
!
|
|
971 |
|
|
972 |
visibleLineNeedsSpecialCare:visLineNr
|
|
973 |
|listLine|
|
|
974 |
|
|
975 |
listLine := self visibleLineToListLine:visLineNr.
|
|
976 |
listLine isNil ifTrue:[^ false].
|
|
977 |
(self isInSelection:listLine) ifTrue:[^ true].
|
|
978 |
listAttributes notNil ifTrue:[
|
59
|
979 |
(listLine <= listAttributes size) ifTrue:[
|
|
980 |
^ (listAttributes at:listLine) notNil
|
|
981 |
]
|
0
|
982 |
].
|
|
983 |
^ false
|
|
984 |
!
|
|
985 |
|
|
986 |
removeFromSelection:aNumber
|
|
987 |
"remove line, aNumber from the selection"
|
|
988 |
|
|
989 |
selection isNil ifTrue:[^ self].
|
|
990 |
|
|
991 |
(selection isKindOf:Collection) ifTrue:[
|
59
|
992 |
(selection includes:aNumber) ifFalse:[^ self].
|
|
993 |
selection remove:aNumber.
|
|
994 |
(selection size == 1) ifTrue:[
|
|
995 |
selection := selection at:1
|
|
996 |
]
|
0
|
997 |
] ifFalse:[
|
59
|
998 |
(aNumber == selection) ifFalse:[^ self].
|
|
999 |
selection := nil
|
0
|
1000 |
].
|
|
1001 |
self redrawElement:aNumber
|
|
1002 |
!
|
|
1003 |
|
|
1004 |
scrollSelectDown
|
|
1005 |
"auto scroll action; scroll and reinstall timed-block"
|
|
1006 |
|
38
|
1007 |
self scrollDown.
|
|
1008 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
|
0
|
1009 |
!
|
|
1010 |
|
|
1011 |
scrollSelectUp
|
|
1012 |
"auto scroll action; scroll and reinstall timed-block"
|
|
1013 |
|
38
|
1014 |
self scrollUp.
|
|
1015 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT.
|
0
|
1016 |
! !
|
|
1017 |
|
|
1018 |
!SelectionInListView methodsFor:'redrawing'!
|
|
1019 |
|
22
|
1020 |
drawRightArrowInVisibleLine:visLineNr
|
|
1021 |
"draw a right arrow (for submenus).
|
|
1022 |
This method is not used here, but provided for subclasses such
|
|
1023 |
as menus or file-lists."
|
|
1024 |
|
38
|
1025 |
|y x form form2 topLeftColor botRightColor t|
|
22
|
1026 |
|
|
1027 |
x := width - 16.
|
59
|
1028 |
y := (self yOfVisibleLine:visLineNr).
|
22
|
1029 |
|
|
1030 |
device depth == 1 ifTrue:[
|
59
|
1031 |
form := self class rightArrowFormOn:device.
|
|
1032 |
y := y + ((font height - form height) // 2).
|
|
1033 |
self foreground:Black.
|
|
1034 |
self displayForm:form x:x y:y.
|
22
|
1035 |
] ifFalse:[
|
59
|
1036 |
smallArrow ifTrue:[
|
|
1037 |
form := self class smallRightArrowLightFormOn:device.
|
|
1038 |
form2 := self class smallRightArrowShadowFormOn:device.
|
|
1039 |
] ifFalse:[
|
|
1040 |
form := self class rightArrowLightFormOn:device.
|
|
1041 |
form2 := self class rightArrowShadowFormOn:device.
|
|
1042 |
].
|
|
1043 |
y := y + ((font height - form height) // 2).
|
22
|
1044 |
|
59
|
1045 |
topLeftColor := lightColor.
|
|
1046 |
botRightColor := shadowColor.
|
22
|
1047 |
|
59
|
1048 |
"openwin arrow stays down"
|
|
1049 |
style ~~ #openwin ifTrue:[
|
|
1050 |
(self isInSelection:(self visibleLineToListLine:visLineNr)) ifTrue:[
|
|
1051 |
t := topLeftColor.
|
|
1052 |
topLeftColor := botRightColor.
|
|
1053 |
botRightColor := t.
|
|
1054 |
]
|
|
1055 |
].
|
|
1056 |
arrowLevel < 0 ifTrue:[
|
|
1057 |
t := topLeftColor.
|
|
1058 |
topLeftColor := botRightColor.
|
|
1059 |
botRightColor := t.
|
|
1060 |
].
|
31
|
1061 |
|
59
|
1062 |
"/ self foreground:topLeftColor.
|
|
1063 |
self paint:topLeftColor.
|
|
1064 |
self displayForm:form x:x y:y.
|
|
1065 |
"/ self foreground:botRightColor.
|
|
1066 |
self paint:botRightColor.
|
|
1067 |
self displayForm:form2 x:x y:y.
|
22
|
1068 |
]
|
|
1069 |
!
|
|
1070 |
|
0
|
1071 |
redrawElement:aNumber
|
|
1072 |
"redraw an individual element"
|
|
1073 |
|
|
1074 |
^ self redrawLine:aNumber
|
|
1075 |
!
|
|
1076 |
|
|
1077 |
redrawVisibleLine:visLineNr col:colNr
|
31
|
1078 |
"redraw a single character.
|
|
1079 |
Must check, if its in the selection and handle this case."
|
|
1080 |
|
0
|
1081 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[
|
59
|
1082 |
^ self redrawVisibleLine:visLineNr
|
0
|
1083 |
].
|
|
1084 |
super redrawVisibleLine:visLineNr col:colNr
|
|
1085 |
!
|
|
1086 |
|
|
1087 |
redrawVisibleLine:visLineNr from:startCol
|
31
|
1088 |
"redraw from a col to the right end.
|
|
1089 |
Must check, if its in the selection and handle this case."
|
|
1090 |
|
0
|
1091 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[
|
59
|
1092 |
^ self redrawVisibleLine:visLineNr
|
0
|
1093 |
].
|
|
1094 |
super redrawVisibleLine:visLineNr from:startCol
|
|
1095 |
!
|
|
1096 |
|
|
1097 |
redrawVisibleLine:visLineNr from:startCol to:endCol
|
31
|
1098 |
"redraw from a startCol to endCol.
|
|
1099 |
Must check, if its in the selection and handle this case."
|
|
1100 |
|
0
|
1101 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[
|
59
|
1102 |
^ self redrawVisibleLine:visLineNr
|
0
|
1103 |
].
|
|
1104 |
super redrawVisibleLine:visLineNr from:startCol to:endCol
|
|
1105 |
!
|
|
1106 |
|
|
1107 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr
|
31
|
1108 |
"redraw a range of lines.
|
|
1109 |
Must check, if any is in the selection and handle this case.
|
|
1110 |
Otherwise draw it en-bloque using supers method."
|
|
1111 |
|
0
|
1112 |
|special sel
|
|
1113 |
selNo "{ Class: SmallInteger }" |
|
|
1114 |
|
|
1115 |
((selection isKindOf:Collection) or:[listAttributes notNil]) ifTrue:[
|
59
|
1116 |
startVisLineNr to:endVisLineNr do:[:visLine |
|
|
1117 |
self redrawVisibleLine:visLine
|
|
1118 |
].
|
|
1119 |
^ self
|
0
|
1120 |
].
|
|
1121 |
|
31
|
1122 |
"XXX only if -1/+1"
|
|
1123 |
"/ hilightLevel ~~ 0 ifTrue:[
|
|
1124 |
"/ self paint:bgColor.
|
59
|
1125 |
"/ self fillRectangleX:0 y:(self yOfVisibleLine:startVisLineNr)-1 width:width height:1
|
31
|
1126 |
"/ ].
|
0
|
1127 |
special := true.
|
|
1128 |
selection isNil ifTrue:[
|
59
|
1129 |
special := false
|
0
|
1130 |
] ifFalse:[
|
59
|
1131 |
sel := self listLineToVisibleLine:selection.
|
|
1132 |
sel isNil ifTrue:[
|
|
1133 |
special := false
|
|
1134 |
] ifFalse:[
|
|
1135 |
special := (sel between:startVisLineNr and:endVisLineNr)
|
|
1136 |
]
|
0
|
1137 |
].
|
|
1138 |
special ifFalse:[
|
|
1139 |
^ super redrawFromVisibleLine:startVisLineNr
|
59
|
1140 |
to:endVisLineNr
|
0
|
1141 |
].
|
|
1142 |
|
|
1143 |
selNo := sel.
|
|
1144 |
selNo > startVisLineNr ifTrue:[
|
59
|
1145 |
super redrawFromVisibleLine:startVisLineNr to:(selNo - 1)
|
0
|
1146 |
].
|
|
1147 |
self redrawVisibleLine:selNo.
|
|
1148 |
selNo < endVisLineNr ifTrue:[
|
59
|
1149 |
super redrawFromVisibleLine:(selNo + 1) to:endVisLineNr
|
0
|
1150 |
]
|
|
1151 |
!
|
|
1152 |
|
|
1153 |
redrawVisibleLine:visLineNr
|
31
|
1154 |
"redraw a single line.
|
|
1155 |
Must check, if any is in the selection and handle this case.
|
|
1156 |
Otherwise draw using supers method."
|
|
1157 |
|
60
|
1158 |
|listLine fg bg attr|
|
0
|
1159 |
|
|
1160 |
fg := fgColor.
|
|
1161 |
bg := bgColor.
|
|
1162 |
listLine := self visibleLineToListLine:visLineNr.
|
|
1163 |
listLine notNil ifTrue:[
|
59
|
1164 |
(self isInSelection:listLine) ifTrue:[
|
|
1165 |
^ self drawVisibleLineSelected:visLineNr
|
|
1166 |
].
|
60
|
1167 |
attr := self attributeAt:listLine.
|
|
1168 |
attr notNil ifTrue:[
|
|
1169 |
(attr == #halfIntensity
|
|
1170 |
or:[attr isSymbol not and:[attr includes:#halfIntensity]]) ifTrue:[
|
|
1171 |
fg := halfIntensityFgColor
|
|
1172 |
].
|
|
1173 |
(attr == #disbled
|
|
1174 |
or:[attr isSymbol not and:[attr includes:#disabled]]) ifTrue:[
|
|
1175 |
fg := halfIntensityFgColor
|
|
1176 |
]
|
59
|
1177 |
].
|
31
|
1178 |
].
|
|
1179 |
^ self drawVisibleLine:visLineNr with:fg and:bg
|
|
1180 |
!
|
|
1181 |
|
|
1182 |
drawVisibleLineSelected:visLineNr
|
|
1183 |
"redraw a single line as selected."
|
|
1184 |
|
|
1185 |
|listLine fg bg
|
|
1186 |
y "{ Class: SmallInteger }"
|
|
1187 |
wEdge|
|
|
1188 |
|
|
1189 |
bg := hilightBgColor.
|
|
1190 |
fg := hilightFgColor.
|
|
1191 |
listLine := self visibleLineToListLine:visLineNr.
|
|
1192 |
listLine notNil ifTrue:[
|
|
1193 |
"XXX only if -1/+1"
|
|
1194 |
"/ hilightLevel ~~ 0 ifTrue:[
|
|
1195 |
"/ self paint:bg.
|
59
|
1196 |
"/ self fillRectangleX:0 y:(self yOfVisibleLine:visLineNr)-1 width:width height:1
|
31
|
1197 |
"/ ].
|
|
1198 |
|
59
|
1199 |
self drawVisibleLine:visLineNr with:fg and:bg.
|
|
1200 |
y := self yOfVisibleLine:visLineNr.
|
31
|
1201 |
|
59
|
1202 |
"
|
|
1203 |
a line above and below
|
|
1204 |
"
|
|
1205 |
hilightFrameColor notNil ifTrue:[
|
|
1206 |
self paint:hilightFrameColor.
|
|
1207 |
self displayLineFromX:0 y:y toX:width y:y.
|
|
1208 |
y := y + fontHeight - 1.
|
|
1209 |
self displayLineFromX:0 y:y toX:width y:y.
|
|
1210 |
^ self
|
|
1211 |
].
|
31
|
1212 |
|
59
|
1213 |
"
|
|
1214 |
an edge it around
|
|
1215 |
"
|
|
1216 |
(hilightLevel ~~ 0) ifTrue:[
|
31
|
1217 |
"XXX the -1/+1 need some more work"
|
|
1218 |
"/ self drawEdgesForX:0 y:y-1
|
|
1219 |
"/ width:width height:fontHeight+1
|
|
1220 |
"/ level:hilightLevel.
|
|
1221 |
|
59
|
1222 |
"
|
|
1223 |
let edge start at left, extending to the full width
|
|
1224 |
XXX: widthOfContents should be cached in ListView
|
60
|
1225 |
(instead of recomputing all over)
|
59
|
1226 |
"
|
|
1227 |
wEdge := width-(2 * margin).
|
60
|
1228 |
includesNonStrings ifFalse:[
|
59
|
1229 |
wEdge := wEdge max:(self widthOfContents).
|
60
|
1230 |
].
|
59
|
1231 |
self drawEdgesForX:(margin - leftOffset) y:y
|
|
1232 |
width:wEdge height:fontHeight
|
|
1233 |
level:hilightLevel.
|
31
|
1234 |
|
|
1235 |
|
59
|
1236 |
^ self
|
|
1237 |
]
|
0
|
1238 |
].
|
31
|
1239 |
^ super drawVisibleLine:visLineNr with:fg and:bg
|
0
|
1240 |
! !
|
|
1241 |
|
|
1242 |
!SelectionInListView methodsFor:'event handling'!
|
|
1243 |
|
|
1244 |
sizeChanged:how
|
|
1245 |
"if there is a selection, make certain, its visible
|
|
1246 |
after the sizechange"
|
|
1247 |
|
|
1248 |
|first|
|
|
1249 |
|
|
1250 |
super sizeChanged:how.
|
|
1251 |
shown ifTrue:[
|
59
|
1252 |
selection notNil ifTrue:[
|
|
1253 |
(selection isKindOf:Collection) ifTrue:[
|
|
1254 |
first := selection first
|
|
1255 |
] ifFalse:[
|
|
1256 |
first := selection
|
|
1257 |
].
|
|
1258 |
self makeLineVisible:first
|
|
1259 |
]
|
0
|
1260 |
]
|
|
1261 |
!
|
|
1262 |
|
38
|
1263 |
key:key select:selectAction x:x y:y
|
|
1264 |
"perform keyaction after a key-select"
|
|
1265 |
|
|
1266 |
keyActionStyle notNil ifTrue:[
|
59
|
1267 |
keyActionStyle == #pass ifTrue:[
|
|
1268 |
^ super keyPress:key x:x y:y
|
|
1269 |
].
|
|
1270 |
selectAction value.
|
|
1271 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
1272 |
keyActionStyle == #selectAndDoubleClick ifTrue:[
|
|
1273 |
doubleClickActionBlock notNil ifTrue:[doubleClickActionBlock value:selection].
|
|
1274 |
]
|
38
|
1275 |
].
|
|
1276 |
!
|
|
1277 |
|
0
|
1278 |
keyPress:key x:x y:y
|
|
1279 |
"handle keyboard input"
|
|
1280 |
|
38
|
1281 |
|index startSearch|
|
|
1282 |
|
0
|
1283 |
(keyboardHandler notNil
|
|
1284 |
and:[keyboardHandler canHandle:key]) ifTrue:[
|
59
|
1285 |
keyboardHandler keyPress:key x:x y:y.
|
|
1286 |
^ self
|
|
1287 |
].
|
|
1288 |
(key == #CursorUp) ifTrue:[
|
60
|
1289 |
index := self previousBeforeSelection.
|
|
1290 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[
|
|
1291 |
self key:key select:[self selection:index] x:x y:y
|
59
|
1292 |
].
|
|
1293 |
^ self
|
0
|
1294 |
].
|
59
|
1295 |
(key == #CursorDown) ifTrue:[
|
60
|
1296 |
index := self nextAfterSelection.
|
|
1297 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[
|
|
1298 |
self key:key select:[self selection:index] x:x y:y
|
59
|
1299 |
].
|
|
1300 |
^ self
|
|
1301 |
].
|
|
1302 |
(key == #Home) ifTrue:[
|
60
|
1303 |
(selectConditionBlock isNil or:[selectConditionBlock value:1]) ifTrue:[
|
59
|
1304 |
self key:key select:[self selection:1] x:x y:y
|
|
1305 |
].
|
|
1306 |
^ self
|
|
1307 |
].
|
|
1308 |
(key == #End) ifTrue:[
|
60
|
1309 |
index := list size.
|
|
1310 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[
|
|
1311 |
self key:key select:[self selection:index] x:x y:y
|
59
|
1312 |
].
|
|
1313 |
^ self
|
38
|
1314 |
].
|
|
1315 |
key == #Return ifTrue:[
|
59
|
1316 |
selection notNil ifTrue:[
|
|
1317 |
doubleClickActionBlock notNil ifTrue:[
|
|
1318 |
doubleClickActionBlock value:selection
|
|
1319 |
].
|
|
1320 |
^ self
|
|
1321 |
]
|
38
|
1322 |
].
|
|
1323 |
"
|
|
1324 |
alphabetic keys: search for next entry
|
|
1325 |
starting with keys character
|
|
1326 |
"
|
|
1327 |
list size > 0 ifTrue:[
|
59
|
1328 |
key isCharacter ifTrue:[
|
|
1329 |
key isLetter ifTrue:[
|
|
1330 |
keyActionStyle isNil ifTrue:[^ self].
|
|
1331 |
keyActionStyle == #pass ifFalse:[
|
|
1332 |
selection notNil ifTrue:[
|
|
1333 |
selection size > 0 ifTrue:[
|
|
1334 |
startSearch := selection last + 1
|
|
1335 |
] ifFalse:[
|
|
1336 |
startSearch := selection + 1
|
|
1337 |
]
|
|
1338 |
] ifFalse:[
|
|
1339 |
startSearch := 1
|
|
1340 |
].
|
|
1341 |
startSearch > list size ifTrue:[
|
|
1342 |
startSearch := 1.
|
|
1343 |
].
|
|
1344 |
index := startSearch.
|
|
1345 |
[true] whileTrue:[
|
|
1346 |
(((list at:index) asString at:1) asLowercase == key asLowercase) ifTrue:[
|
|
1347 |
^ self key:key select:[self selection:index] x:x y:y
|
|
1348 |
].
|
|
1349 |
index := index + 1.
|
|
1350 |
index > list size ifTrue:[
|
|
1351 |
index := 1
|
|
1352 |
].
|
|
1353 |
index == startSearch ifTrue:[
|
|
1354 |
^ self
|
|
1355 |
]
|
|
1356 |
]
|
|
1357 |
]
|
|
1358 |
]
|
|
1359 |
].
|
3
|
1360 |
].
|
|
1361 |
^ super keyPress:key x:x y:y
|
0
|
1362 |
!
|
|
1363 |
|
|
1364 |
buttonPress:button x:x y:y
|
7
|
1365 |
|oldSelection listLineNr|
|
0
|
1366 |
|
31
|
1367 |
((button == 1) or:[button == #select]) ifTrue:[
|
59
|
1368 |
enabled ifTrue:[
|
60
|
1369 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y).
|
|
1370 |
listLineNr notNil ifTrue:[
|
|
1371 |
(self line:listLineNr hasAttribute:#disabled) ifTrue:[^ self].
|
|
1372 |
|
|
1373 |
(selectConditionBlock notNil
|
|
1374 |
and:[(selectConditionBlock value:listLineNr) not]) ifTrue:[^ self].
|
|
1375 |
].
|
|
1376 |
|
|
1377 |
oldSelection := selection.
|
|
1378 |
listLineNr notNil ifTrue: [
|
|
1379 |
self selectWithoutScroll:listLineNr
|
|
1380 |
].
|
|
1381 |
((ignoreReselect not and:[selection notNil])
|
|
1382 |
or:[selection ~= oldSelection]) ifTrue:[
|
|
1383 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
1384 |
"the ST-80 way of doing things"
|
|
1385 |
model notNil ifTrue:[
|
|
1386 |
model perform:changeSymbol with:(self selectionValue)
|
|
1387 |
]
|
|
1388 |
].
|
|
1389 |
clickLine := listLineNr
|
59
|
1390 |
]
|
0
|
1391 |
] ifFalse:[
|
59
|
1392 |
super buttonPress:button x:x y:y
|
0
|
1393 |
]
|
|
1394 |
!
|
|
1395 |
|
|
1396 |
buttonShiftPress:button x:x y:y
|
|
1397 |
|oldSelection listLineNr|
|
|
1398 |
|
31
|
1399 |
((button == 1) or:[button == #select]) ifTrue:[
|
59
|
1400 |
enabled ifTrue:[
|
60
|
1401 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y).
|
|
1402 |
listLineNr notNil ifTrue:[
|
|
1403 |
(self line:listLineNr hasAttribute:#disabled) ifTrue:[^ self].
|
|
1404 |
|
|
1405 |
(selectConditionBlock notNil
|
|
1406 |
and:[(selectConditionBlock value:listLineNr) not]) ifTrue:[^ self].
|
|
1407 |
].
|
|
1408 |
oldSelection := selection copy.
|
|
1409 |
listLineNr notNil ifTrue: [
|
|
1410 |
multipleSelectOk ifTrue:[
|
|
1411 |
(self isInSelection:listLineNr) ifTrue:[
|
|
1412 |
self removeFromSelection:listLineNr
|
59
|
1413 |
] ifFalse:[
|
60
|
1414 |
self addToSelection:listLineNr
|
59
|
1415 |
]
|
60
|
1416 |
] ifFalse:[
|
|
1417 |
self selectWithoutScroll:listLineNr
|
|
1418 |
]
|
|
1419 |
].
|
|
1420 |
(selection ~= oldSelection) ifTrue:[
|
|
1421 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
1422 |
"the ST-80 way of doing things"
|
|
1423 |
(model notNil and:[changeSymbol notNil]) ifTrue:[
|
|
1424 |
model perform:changeSymbol with:(self selectionValue)
|
|
1425 |
]
|
|
1426 |
].
|
|
1427 |
clickLine := listLineNr
|
59
|
1428 |
]
|
0
|
1429 |
] ifFalse:[
|
59
|
1430 |
super buttonShiftPress:button x:x y:y
|
0
|
1431 |
]
|
|
1432 |
!
|
|
1433 |
|
|
1434 |
buttonMultiPress:button x:x y:y
|
31
|
1435 |
((button == 1) or:[button == #select]) ifTrue:[
|
59
|
1436 |
doubleClickActionBlock isNil ifTrue:[
|
|
1437 |
self buttonPress:button x:x y:y
|
|
1438 |
] ifFalse:[
|
|
1439 |
doubleClickActionBlock value:selection
|
|
1440 |
]
|
0
|
1441 |
] ifFalse:[
|
59
|
1442 |
super buttonMultiPress:button x:x y:y
|
0
|
1443 |
]
|
|
1444 |
!
|
|
1445 |
|
|
1446 |
buttonRelease:button x:x y:y
|
|
1447 |
"stop any autoscroll"
|
|
1448 |
|
|
1449 |
self stopAutoScroll
|
|
1450 |
!
|
|
1451 |
|
|
1452 |
buttonMotion:button x:x y:y
|
|
1453 |
"mouse-move while button was pressed - handle selection changes"
|
|
1454 |
|
|
1455 |
|movedVisibleLine movedLine delta oldSelection oldSelCount|
|
|
1456 |
|
|
1457 |
clickLine isNil ifTrue:[^ self].
|
|
1458 |
|
|
1459 |
"if moved outside of view, start autoscroll"
|
|
1460 |
(y < 0) ifTrue:[
|
59
|
1461 |
self compressMotionEvents:false.
|
|
1462 |
self startAutoScrollUp:y.
|
|
1463 |
^ self
|
0
|
1464 |
].
|
|
1465 |
(y > height) ifTrue:[
|
59
|
1466 |
self compressMotionEvents:false.
|
|
1467 |
self startAutoScrollDown:(y - height).
|
|
1468 |
^ self
|
0
|
1469 |
].
|
|
1470 |
|
|
1471 |
"move inside - stop autoscroll if any"
|
|
1472 |
self stopAutoScroll.
|
|
1473 |
|
|
1474 |
movedVisibleLine := self visibleLineOfY:y.
|
|
1475 |
movedLine := self visibleLineToAbsoluteLine:movedVisibleLine.
|
|
1476 |
(movedLine == clickLine) ifTrue:[^ self].
|
|
1477 |
|
|
1478 |
multipleSelectOk ifTrue:[
|
59
|
1479 |
delta := (clickLine < movedLine) ifTrue:[1] ifFalse:[-1].
|
0
|
1480 |
|
59
|
1481 |
oldSelection := selection.
|
|
1482 |
oldSelCount := selection size.
|
0
|
1483 |
|
59
|
1484 |
(clickLine+delta) to:movedLine by:delta do:[:line |
|
|
1485 |
(self isInSelection:line) ifTrue:[
|
|
1486 |
self removeFromSelection:line
|
|
1487 |
] ifFalse:[
|
|
1488 |
self addToSelection:line
|
|
1489 |
]
|
|
1490 |
].
|
|
1491 |
((selection ~= oldSelection)
|
|
1492 |
or:[selection size ~~ oldSelCount]) ifTrue:[
|
|
1493 |
actionBlock notNil ifTrue:[actionBlock value:selection]
|
|
1494 |
]
|
0
|
1495 |
] ifFalse:[
|
59
|
1496 |
self selectWithoutScroll:movedLine
|
0
|
1497 |
].
|
|
1498 |
|
|
1499 |
clickLine := movedLine
|
|
1500 |
!
|
|
1501 |
|
|
1502 |
update:aParameter
|
|
1503 |
|newList|
|
|
1504 |
|
|
1505 |
(aParameter == initialSelectionSymbol) ifTrue:[
|
59
|
1506 |
self selectElement:(model perform:initialSelectionSymbol).
|
|
1507 |
^ self
|
0
|
1508 |
].
|
|
1509 |
(aParameter == listSymbol) ifTrue:[
|
59
|
1510 |
newList := (model perform:listSymbol) asText.
|
|
1511 |
(newList = list) ifFalse:[
|
|
1512 |
self list:newList
|
|
1513 |
]
|
0
|
1514 |
]
|
|
1515 |
! !
|