author | claus |
Tue, 09 May 1995 03:57:16 +0200 | |
changeset 125 | 3ffa271732f7 |
parent 124 | 7abd3a234296 |
child 128 | 06a050529335 |
permissions | -rw-r--r-- |
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 |
||
125 | 13 |
'From Smalltalk/X, Version:2.10.5 on 8-may-1995 at 11:59:03 am'! |
105 | 14 |
|
0 | 15 |
ListView subclass:#SelectionInListView |
105 | 16 |
instanceVariableNames:'selection actionBlock enabled hilightFgColor hilightBgColor |
125 | 17 |
halfIntensityFgColor doubleClickActionBlock selectConditionBlock |
18 |
listAttributes multipleSelectOk clickLine initialSelectionMsg |
|
19 |
printItems oneItem useIndex hilightLevel hilightFrameColor |
|
20 |
ignoreReselect arrowLevel smallArrow keyActionStyle |
|
21 |
returnKeyActionStyle toggleSelect strikeOut iSearchString items |
|
22 |
doubleClickMsg' |
|
59 | 23 |
classVariableNames:'RightArrowShadowForm RightArrowLightForm RightArrowForm |
125 | 24 |
SmallRightArrowShadowForm SmallRightArrowLightForm |
25 |
DefaultForegroundColor DefaultBackgroundColor |
|
26 |
DefaultHilightForegroundColor DefaultHilightBackgroundColor |
|
27 |
DefaultHilightFrameColor DefaultHilightLevel DefaultFont |
|
28 |
DefaultRightArrowStyle DefaultRightArrowLevel |
|
29 |
DefaultDisabledForegroundColor DefaultShadowColor |
|
30 |
DefaultLightColor' |
|
105 | 31 |
poolDictionaries:'' |
32 |
category:'Views-Text' |
|
0 | 33 |
! |
34 |
||
35 |
SelectionInListView comment:' |
|
5 | 36 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 37 |
All Rights Reserved |
38 | 38 |
|
125 | 39 |
$Header: /cvs/stx/stx/libwidg/SelectionInListView.st,v 1.32 1995-05-09 01:56:42 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 |
" |
|
125 | 60 |
$Header: /cvs/stx/stx/libwidg/SelectionInListView.st,v 1.32 1995-05-09 01:56:42 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. |
|
63 | 69 |
If toggleSelect is true, clicking toggles (i.e. click on a seleted item |
70 |
will deselect). |
|
31 | 71 |
|
38 | 72 |
Whenever the selection changes, an action-block is evaluated, passing the |
73 |
current selection as argument. |
|
74 |
Currently, the selection can be nil, aNumber or a collection of numbers; |
|
75 |
this will change to be either nil or a collection, making selection handling |
|
70 | 76 |
easier in the future. (this stupid behavior is due to the multiple |
77 |
select feature being added later - the first implementation used to support |
|
78 |
only single selections). |
|
79 |
||
59 | 80 |
The actionBlock is called with the current selection (single number or |
81 |
collection of numbers) as argument. |
|
82 |
||
83 |
Also, to support ST-80 MVC-style use, the model (if nonNil) is notified |
|
119 | 84 |
by the change mechanism (performs changeMsg). |
59 | 85 |
|
60 | 86 |
Before actually adding entries to the the selection, a checkBlock (if non-nil) is evaluated |
87 |
passing the number of the entry whch is about to be selected as argument. |
|
88 |
The select change operation is only done if this returns true. This allows |
|
59 | 89 |
interception of select, for example to query the user if he/she wants to save |
60 | 90 |
the old contents before (see uses in SystemBrowser and FileBrowser), or to |
91 |
disable individual entries. |
|
31 | 92 |
|
38 | 93 |
It is also possible to select entries with the keyboard; use the cursor up/ |
94 |
down keys to select prev/next, Home- and End-keys to select first/last. |
|
95 |
Use the return key to apply the double-click-action to the current selection. |
|
96 |
Also, alphabetic keys will select the next entry starting with that key. |
|
97 |
||
98 |
The keyboard behavior can be further controlled with the keyActionStyle |
|
99 |
instance variable (see SelectionInListView>>keyActionStyle:). |
|
100 |
||
59 | 101 |
Finally, ignoreReselect controls if pressing on an already selected item |
102 |
triggers the action or not. For some applications it is useful to allow |
|
103 |
reselects (for example, the SystemBrowsers method-list updates the |
|
104 |
source code in this case). |
|
38 | 105 |
|
60 | 106 |
Currently, some limited form of line attributes are supported. These |
107 |
are kept in the instance variable lineAttributes. |
|
108 |
This may change (using mechanisms similar to MultiColListEntry), so |
|
63 | 109 |
be prepared. (dont use the listAttributes instvar directly; if possible, |
110 |
use MultiColListEntry or subclasses of it. |
|
120 | 111 |
|
63 | 112 |
Although currently based on the listAttributes instVar, the implementation of |
120 | 113 |
text attributes will be changed in the near future (when Text/DisplayText are |
114 |
available). |
|
115 |
However, the protocol will probably be kept for backward compatibility |
|
116 |
(i.e. use #attributeAt: / #attributeAt:put etc. - at least, these are easy to find |
|
117 |
when migrating to the new attributed text handling). |
|
60 | 118 |
|
31 | 119 |
InstanceVariables: |
59 | 120 |
selection <misc> the current selection. nil, a number or collection of numbers |
31 | 121 |
|
59 | 122 |
actionBlock <Block> block to be evaluated on selection changes |
31 | 123 |
|
59 | 124 |
enabled <Boolean> true: selection changes allowed; false: ignore clicks |
31 | 125 |
|
59 | 126 |
hilightFgColor |
127 |
hilightBgColor <Color> how highlighted items are drawn |
|
31 | 128 |
|
59 | 129 |
halfIntensityColor <Color> foreground for disabled items |
31 | 130 |
|
59 | 131 |
selectConditionBlock <Block> if non-nil, this nlock can decide if selection is ok |
0 | 132 |
|
59 | 133 |
doubleClickActionBlock <Block> action to perform on double-click |
31 | 134 |
|
59 | 135 |
listAttributes dont use - will vanish |
31 | 136 |
|
59 | 137 |
hilightLevel <Integer> level to draw selections (i.e. for 3D effect) |
138 |
hilightFrameColor <Color> rectangle around highlighted items |
|
31 | 139 |
|
63 | 140 |
multipleSelectOk <Boolean> if true, multiple selections (with shift) are ok. |
141 |
default: false |
|
142 |
||
59 | 143 |
ignoreReselect <Boolean> if true, selecting same again does not trigger action; |
63 | 144 |
if false, every select triggers it. |
145 |
default: true |
|
146 |
||
147 |
toggleSelect <Boolean> if true, click toggles; |
|
148 |
if false, click selects. |
|
149 |
default: false |
|
0 | 150 |
|
59 | 151 |
arrowLevel <Integer> level to draw right-arrows (for submenus etc.) |
152 |
smallArrow <Boolean> if true, uses a small arrow bitmap |
|
31 | 153 |
|
119 | 154 |
listMsg if non-nil, use ST-80 style (model-access) |
155 |
initialSelectionMsg |
|
59 | 156 |
printItems |
157 |
oneItem |
|
31 | 158 |
|
59 | 159 |
keyActionStyle <Symbol> controls how to respond to keyboard selects |
31 | 160 |
|
125 | 161 |
returnKeyActionStyle <Symbol> controls how to respond to return key |
162 |
||
31 | 163 |
written spring/summer 89 by claus |
164 |
3D Jan 90 by claus |
|
38 | 165 |
multiselect Jun 92 by claus |
166 |
keyboard-select jun 94 by claus |
|
7 | 167 |
" |
119 | 168 |
! |
169 |
||
170 |
examples |
|
171 |
" |
|
172 |
SelectionInListView can be used both in the ST/X way, using action blocks |
|
173 |
or in the traditional mvc way. |
|
174 |
with actions: |
|
175 |
||
125 | 176 |
basic interface: |
177 |
||
178 |
|top slv| |
|
179 |
||
180 |
top := StandardSystemView new |
|
181 |
label:'select'; |
|
182 |
minExtent:100@100; |
|
183 |
maxExtent:300@400; |
|
184 |
extent:200@200. |
|
185 |
||
186 |
slv := SelectionInListView new. |
|
187 |
slv list:#('one' 'two' 'three'). |
|
188 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
189 |
||
190 |
top add:slv in:(0.0@0.0 corner:1.0@1.0). |
|
191 |
top open |
|
192 |
||
193 |
||
194 |
get element instead of index: |
|
195 |
||
196 |
|top slv| |
|
197 |
||
198 |
top := StandardSystemView new |
|
199 |
label:'select'; |
|
200 |
minExtent:100@100; |
|
201 |
maxExtent:300@400; |
|
202 |
extent:200@200. |
|
203 |
||
204 |
slv := SelectionInListView new. |
|
205 |
slv list:#('one' 'two' 'three'). |
|
206 |
slv action:[:element | Transcript showCr:'selected ' , element printString]. |
|
207 |
slv useIndex:false. |
|
208 |
||
209 |
top add:slv in:(0.0@0.0 corner:1.0@1.0). |
|
210 |
top open |
|
211 |
||
212 |
||
213 |
concrete example; show filenames: |
|
214 |
(notice: normally, you would use a FileSelectionList) |
|
215 |
||
216 |
|top slv| |
|
217 |
||
218 |
top := StandardSystemView new |
|
219 |
label:'select'; |
|
220 |
minExtent:100@100; |
|
221 |
maxExtent:300@400; |
|
222 |
extent:200@200. |
|
223 |
||
224 |
slv := SelectionInListView new. |
|
225 |
slv list:(Filename currentDirectory directoryContents). |
|
226 |
slv action:[:index | |
|
227 |
Transcript showCr:'selected ' , index printString. |
|
228 |
Transcript showCr:' the value is: ', slv selectionValue]. |
|
229 |
||
230 |
top add:slv in:(0.0@0.0 corner:1.0@1.0). |
|
231 |
top open |
|
232 |
||
119 | 233 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
234 |
add a scrollbar: |
119 | 235 |
|
125 | 236 |
|top slv| |
237 |
||
238 |
top := StandardSystemView new |
|
239 |
label:'select'; |
|
240 |
minExtent:100@100; |
|
241 |
maxExtent:300@400; |
|
242 |
extent:200@200. |
|
243 |
||
244 |
slv := SelectionInListView new. |
|
245 |
slv list:(Filename currentDirectory directoryContents). |
|
246 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
247 |
||
248 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
249 |
top open |
|
250 |
||
119 | 251 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
252 |
allow reselect (clicking on already selected entry): |
119 | 253 |
|
125 | 254 |
|top slv| |
255 |
||
256 |
top := StandardSystemView new |
|
257 |
label:'select'; |
|
258 |
minExtent:100@100; |
|
259 |
maxExtent:300@400; |
|
260 |
extent:200@200. |
|
261 |
||
262 |
slv := SelectionInListView new. |
|
263 |
slv list:(Filename currentDirectory directoryContents). |
|
264 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
265 |
slv ignoreReselect:false. |
|
266 |
||
267 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
268 |
top open |
|
269 |
||
119 | 270 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
271 |
allow multiple selections: |
119 | 272 |
|
125 | 273 |
|top slv| |
274 |
||
275 |
top := StandardSystemView new |
|
276 |
label:'select'; |
|
277 |
minExtent:100@100; |
|
278 |
maxExtent:300@400; |
|
279 |
extent:200@200. |
|
280 |
||
281 |
slv := SelectionInListView new. |
|
282 |
slv list:(Filename currentDirectory directoryContents). |
|
283 |
slv action:[:indexList | Transcript showCr:'selected ' , indexList printString]. |
|
284 |
slv multipleSelectOk:true. |
|
285 |
||
286 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
287 |
top open |
|
288 |
||
289 |
||
290 |
same, not using index: |
|
291 |
||
292 |
|top slv| |
|
293 |
||
294 |
top := StandardSystemView new |
|
295 |
label:'select'; |
|
296 |
minExtent:100@100; |
|
297 |
maxExtent:300@400; |
|
298 |
extent:200@200. |
|
299 |
||
300 |
slv := SelectionInListView new. |
|
301 |
slv list:(Filename currentDirectory directoryContents). |
|
302 |
slv action:[:indexList | Transcript showCr:'selected ' , indexList printString]. |
|
303 |
slv multipleSelectOk:true; useIndex:false. |
|
304 |
||
305 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
306 |
top open |
|
307 |
||
119 | 308 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
309 |
strikeout mode (single): |
119 | 310 |
|
125 | 311 |
|top slv| |
312 |
||
313 |
top := StandardSystemView new |
|
314 |
label:'select'; |
|
315 |
minExtent:100@100; |
|
316 |
maxExtent:300@400; |
|
317 |
extent:200@200. |
|
318 |
||
319 |
slv := SelectionInListView new. |
|
320 |
slv list:(Filename currentDirectory directoryContents). |
|
321 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
322 |
slv strikeOut:true. |
|
323 |
||
324 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
325 |
top open |
|
326 |
||
119 | 327 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
328 |
strikeout mode (multiple): |
119 | 329 |
|
125 | 330 |
|top slv| |
331 |
||
332 |
top := StandardSystemView new |
|
333 |
label:'select'; |
|
334 |
minExtent:100@100; |
|
335 |
maxExtent:300@400; |
|
336 |
extent:200@200. |
|
337 |
||
338 |
slv := SelectionInListView new. |
|
339 |
slv list:(Filename currentDirectory directoryContents). |
|
340 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
341 |
slv strikeOut:true; multipleSelectOk:true. |
|
342 |
||
343 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
344 |
top open |
|
345 |
||
119 | 346 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
347 |
define what to do on double-click: |
119 | 348 |
|
125 | 349 |
|top slv| |
350 |
||
351 |
top := StandardSystemView new |
|
352 |
label:'select'; |
|
353 |
minExtent:100@100; |
|
354 |
maxExtent:300@400; |
|
355 |
extent:200@200. |
|
356 |
||
357 |
slv := SelectionInListView new. |
|
358 |
slv list:(Filename currentDirectory directoryContents). |
|
359 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
360 |
slv doubleClickAction:[:index | Transcript showCr:'doubleclick on ' , index printString]. |
|
361 |
||
362 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
363 |
top open |
|
119 | 364 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
365 |
|
119 | 366 |
using a Model: |
367 |
||
125 | 368 |
|top slv model| |
369 |
||
370 |
model := Plug new. |
|
371 |
model respondTo:#getList with:[#('foo' 'bar' 'baz' 'hello')]. |
|
372 |
model respondTo:#initial with:[1]. |
|
373 |
model respondTo:#setSelection: with:[:arg | Transcript showCr:'model selected:', arg printString]. |
|
374 |
||
375 |
top := StandardSystemView new |
|
376 |
label:'select'; |
|
377 |
minExtent:100@100; |
|
378 |
maxExtent:300@400; |
|
379 |
extent:200@200. |
|
380 |
||
381 |
slv := SelectionInListView |
|
382 |
on:model |
|
383 |
aspect:#someAspect |
|
384 |
change:#setSelection: |
|
385 |
list:#getList |
|
386 |
initialSelection:#initial. |
|
387 |
||
388 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
389 |
top open |
|
119 | 390 |
|
391 |
notice, that the ST-80 behavaior on reselect is to send a selection change |
|
392 |
with an index of 0. |
|
393 |
||
394 |
||
125 | 395 |
same, with useIndex false: |
396 |
||
397 |
|top slv model| |
|
398 |
||
399 |
model := Plug new. |
|
400 |
model respondTo:#getList with:[#('foo' 'bar' 'baz' 'hello')]. |
|
401 |
model respondTo:#initial with:['bar']. |
|
402 |
model respondTo:#setSelection: with:[:arg | Transcript showCr:'model selected:', arg printString]. |
|
403 |
||
404 |
top := StandardSystemView new |
|
405 |
label:'select'; |
|
406 |
minExtent:100@100; |
|
407 |
maxExtent:300@400; |
|
408 |
extent:200@200. |
|
409 |
||
410 |
slv := SelectionInListView |
|
411 |
on:model |
|
412 |
aspect:#someAspect |
|
413 |
change:#setSelection: |
|
414 |
list:#getList |
|
415 |
initialSelection:#initial. |
|
416 |
slv useIndex:false. |
|
417 |
||
418 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
419 |
top open |
|
420 |
||
421 |
||
119 | 422 |
using a SelectionInList-Model: |
423 |
(see how changes in the model (via list:...) are reflected in the view) |
|
424 |
||
125 | 425 |
|top slv model| |
426 |
||
427 |
model := SelectionInList with:#('foo' 'bar' 'baz' 'hello'). |
|
428 |
model selection:'bar'. |
|
429 |
||
430 |
top := StandardSystemView new |
|
431 |
label:'select'; |
|
432 |
minExtent:100@100; |
|
433 |
maxExtent:300@400; |
|
434 |
extent:200@200. |
|
435 |
||
436 |
slv := SelectionInListView on:model. |
|
437 |
||
438 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
439 |
top open. |
|
440 |
||
441 |
model inspect |
|
442 |
||
443 |
||
444 |
two selectionInListViews on the same selectionInList model: |
|
445 |
||
446 |
|top1 slv1 top2 slv2 model| |
|
447 |
||
448 |
model := SelectionInList with:#('foo' 'bar' 'baz' 'hello'). |
|
449 |
||
450 |
top1 := StandardSystemView new |
|
451 |
label:'select'; |
|
452 |
minExtent:100@100; |
|
453 |
maxExtent:300@400; |
|
454 |
extent:200@200. |
|
455 |
||
456 |
slv1 := SelectionInListView on:model. |
|
457 |
||
458 |
top1 add:(ScrollableView forView:slv1) in:(0.0@0.0 corner:1.0@1.0). |
|
459 |
top1 open. |
|
460 |
||
461 |
top2 := StandardSystemView new |
|
462 |
label:'select'; |
|
463 |
minExtent:100@100; |
|
464 |
maxExtent:300@400; |
|
465 |
extent:200@200. |
|
466 |
||
467 |
slv2 := SelectionInListView on:model. |
|
468 |
||
469 |
top2 add:(ScrollableView forView:slv2) in:(0.0@0.0 corner:1.0@1.0). |
|
470 |
top2 open. |
|
119 | 471 |
" |
7 | 472 |
! ! |
0 | 473 |
|
105 | 474 |
!SelectionInListView class methodsFor:'instance creation'! |
475 |
||
476 |
on:aModel printItems:print oneItem:one aspect:aspect change:change |
|
477 |
list:list menu:menu initialSelection:initial useIndex:useIndex |
|
478 |
||
479 |
"for ST-80 compatibility" |
|
480 |
||
481 |
^ (self new) on:aModel |
|
482 |
printItems:print |
|
483 |
oneItem:one |
|
484 |
aspect:aspect |
|
485 |
change:change |
|
486 |
list:list |
|
487 |
menu:menu |
|
488 |
initialSelection:initial |
|
489 |
useIndex:useIndex |
|
490 |
! |
|
491 |
||
125 | 492 |
on:aModel aspect:aspect change:change list:list initialSelection:initial |
493 |
^ self on:aModel |
|
494 |
printItems:true |
|
495 |
oneItem:false |
|
496 |
aspect:aspect |
|
497 |
change:change |
|
498 |
list:list |
|
499 |
menu:nil |
|
500 |
initialSelection:initial |
|
501 |
useIndex:true |
|
502 |
! |
|
503 |
||
105 | 504 |
on:aModel printItems:print oneItem:one aspect:aspect |
505 |
change:change list:list menu:menu initialSelection:initial |
|
506 |
||
507 |
"for ST-80 compatibility" |
|
508 |
||
119 | 509 |
^ self on:aModel |
105 | 510 |
printItems:print |
511 |
oneItem:one |
|
512 |
aspect:aspect |
|
513 |
change:change |
|
514 |
list:list |
|
515 |
menu:menu |
|
516 |
initialSelection:initial |
|
517 |
useIndex:false |
|
119 | 518 |
! |
519 |
||
520 |
on:aModel aspect:aspect change:change list:list menu:menu initialSelection:initial |
|
521 |
^ self on:aModel |
|
522 |
printItems:true |
|
523 |
oneItem:false |
|
524 |
aspect:aspect |
|
525 |
change:change |
|
526 |
list:list |
|
527 |
menu:menu |
|
528 |
initialSelection:initial |
|
529 |
useIndex:true |
|
105 | 530 |
! ! |
531 |
||
22 | 532 |
!SelectionInListView class methodsFor:'defaults'! |
533 |
||
125 | 534 |
defaultListMessage |
535 |
^ #list |
|
536 |
! |
|
537 |
||
538 |
defaultChangeMessage |
|
539 |
^ #selectionIndex: |
|
540 |
! |
|
541 |
||
542 |
defaultAspectMessage |
|
543 |
^ nil |
|
544 |
! |
|
545 |
||
546 |
defaultSelectionMessage |
|
547 |
^ #selectionIndex |
|
548 |
! |
|
549 |
||
105 | 550 |
rightArrowShadowFormOn:aDevice |
551 |
"return the form used for the right arrow light pixels (3D only)" |
|
552 |
||
553 |
|f| |
|
59 | 554 |
|
105 | 555 |
((aDevice == Display) and:[RightArrowShadowForm notNil]) ifTrue:[ |
556 |
^ RightArrowShadowForm |
|
557 |
]. |
|
558 |
f := Form fromFile:'RightArrowShadow.xbm' resolution:100 on:aDevice. |
|
559 |
f isNil ifTrue:[ |
|
560 |
f := Form width:16 height:16 fromArray:#[2r00000000 2r00000000 |
|
561 |
2r00000000 2r00000000 |
|
562 |
2r00000000 2r00000000 |
|
563 |
2r00000000 2r00000000 |
|
564 |
2r00000000 2r00000000 |
|
565 |
2r00000000 2r00000000 |
|
566 |
2r00000000 2r00000000 |
|
567 |
2r00000000 2r00000000 |
|
568 |
2r00000000 2r00010000 |
|
569 |
2r00000000 2r00100000 |
|
570 |
2r00000000 2r01000000 |
|
571 |
2r00000000 2r10000000 |
|
572 |
2r00000001 2r00000000 |
|
573 |
2r00000010 2r00000000 |
|
574 |
2r00000000 2r00000000 |
|
575 |
2r00000000 2r00000000] |
|
576 |
on:aDevice |
|
577 |
]. |
|
578 |
(aDevice == Display) ifTrue:[ |
|
579 |
RightArrowShadowForm := f |
|
580 |
]. |
|
581 |
^ f |
|
59 | 582 |
! |
583 |
||
22 | 584 |
rightArrowLightFormOn:aDevice |
585 |
"return the form used for the right arrow light pixels (3D only)" |
|
586 |
||
587 |
|f| |
|
588 |
||
589 |
((aDevice == Display) and:[RightArrowLightForm notNil]) ifTrue:[ |
|
59 | 590 |
^ RightArrowLightForm |
22 | 591 |
]. |
592 |
f := Form fromFile:'RightArrowLight.xbm' resolution:100 on:aDevice. |
|
593 |
f isNil ifTrue:[ |
|
59 | 594 |
f := Form width:16 height:16 fromArray:#[2r00000000 2r00000000 |
595 |
2r00000000 2r00000000 |
|
596 |
2r00000000 2r00000000 |
|
597 |
2r00000110 2r00000000 |
|
598 |
2r00000101 2r00000000 |
|
599 |
2r00000100 2r10000000 |
|
600 |
2r00000100 2r01000000 |
|
601 |
2r00000100 2r00100000 |
|
602 |
2r00000100 2r00000000 |
|
603 |
2r00000100 2r00000000 |
|
604 |
2r00000100 2r00000000 |
|
605 |
2r00000100 2r00000000 |
|
606 |
2r00000100 2r00000000 |
|
607 |
2r00000100 2r00000000 |
|
608 |
2r00000000 2r00000000 |
|
609 |
2r00000000 2r00000000] |
|
610 |
on:aDevice |
|
22 | 611 |
]. |
612 |
(aDevice == Display) ifTrue:[ |
|
59 | 613 |
RightArrowLightForm := f |
22 | 614 |
]. |
615 |
^ f |
|
616 |
! |
|
617 |
||
105 | 618 |
updateStyleCache |
619 |
DefaultDisabledForegroundColor := StyleSheet colorAt:'selectionDisabledForegroundColor'. |
|
620 |
DefaultHilightForegroundColor := StyleSheet colorAt:'selectionHilightForegroundColor'. |
|
621 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'selectionHilightBackgroundColor'. |
|
622 |
DefaultHilightFrameColor := StyleSheet colorAt:'selectionHilightFrameColor'. |
|
623 |
DefaultHilightLevel := StyleSheet at:'selectionHilightLevel' default:0. |
|
624 |
DefaultRightArrowStyle := StyleSheet at:'selectionRightArrowStyle'. |
|
625 |
DefaultRightArrowLevel := StyleSheet at:'selectionRightArrowLevel'. |
|
626 |
DefaultForegroundColor := StyleSheet colorAt:'selectionForegroundColor'. |
|
627 |
DefaultBackgroundColor := StyleSheet colorAt:'selectionBackgroundColor'. |
|
628 |
DefaultShadowColor := StyleSheet colorAt:'selectionShadowColor'. |
|
629 |
DefaultLightColor := StyleSheet colorAt:'selectionLightColor'. |
|
630 |
DefaultFont := StyleSheet fontAt:'selectionFont'. |
|
22 | 631 |
|
105 | 632 |
" |
633 |
self updateStyleCache |
|
634 |
" |
|
22 | 635 |
! |
636 |
||
637 |
rightArrowFormOn:aDevice |
|
638 |
"return the form used for the right arrow (non 3D)" |
|
639 |
||
640 |
|f| |
|
641 |
||
642 |
((aDevice == Display) and:[RightArrowForm notNil]) ifTrue:[ |
|
59 | 643 |
^ RightArrowForm |
22 | 644 |
]. |
645 |
f := Form fromFile:'RightArrow.xbm' resolution:100 on:aDevice. |
|
646 |
f isNil ifTrue:[ |
|
59 | 647 |
f := Form width:16 height:16 fromArray:#[2r00000000 2r00000000 |
648 |
2r00000000 2r00000000 |
|
649 |
2r00000000 2r00000000 |
|
650 |
2r00000110 2r00000000 |
|
651 |
2r00000101 2r00000000 |
|
652 |
2r00000100 2r10000000 |
|
653 |
2r00000100 2r01000000 |
|
654 |
2r00000100 2r00100000 |
|
655 |
2r00000100 2r00010000 |
|
656 |
2r00000100 2r00100000 |
|
657 |
2r00000100 2r01000000 |
|
658 |
2r00000100 2r10000000 |
|
659 |
2r00000101 2r00000000 |
|
660 |
2r00000110 2r00000000 |
|
661 |
2r00000000 2r00000000 |
|
662 |
2r00000000 2r00000000] |
|
663 |
on:aDevice |
|
22 | 664 |
]. |
665 |
(aDevice == Display) ifTrue:[ |
|
59 | 666 |
RightArrowForm := f |
22 | 667 |
]. |
668 |
^ f |
|
31 | 669 |
! |
670 |
||
671 |
smallRightArrowLightFormOn:aDevice |
|
672 |
"return the form used for the small right arrow light pixels (3D only)" |
|
673 |
||
674 |
|f| |
|
675 |
||
676 |
((aDevice == Display) and:[SmallRightArrowLightForm notNil]) ifTrue:[ |
|
59 | 677 |
^ SmallRightArrowLightForm |
31 | 678 |
]. |
679 |
f := Form fromFile:'SmallRightArrowLight.xbm' resolution:100 on:aDevice. |
|
680 |
f isNil ifTrue:[ |
|
59 | 681 |
f := Form width:9 height:9 fromArray:#[2r00000000 2r00000000 |
682 |
2r01100000 2r00000000 |
|
683 |
2r01011000 2r00000000 |
|
684 |
2r01000110 2r00000000 |
|
685 |
2r01000000 2r00000000 |
|
686 |
2r01000000 2r00000000 |
|
687 |
2r01000000 2r00000000 |
|
688 |
2r01000000 2r00000000 |
|
689 |
2r00000000 2r00000000] |
|
690 |
on:aDevice |
|
31 | 691 |
]. |
692 |
(aDevice == Display) ifTrue:[ |
|
59 | 693 |
SmallRightArrowLightForm := f |
31 | 694 |
]. |
695 |
^ f |
|
696 |
! |
|
697 |
||
698 |
smallRightArrowShadowFormOn:aDevice |
|
699 |
"return the form used for the small right arrow light pixels (3D only)" |
|
700 |
||
701 |
|f| |
|
702 |
||
703 |
((aDevice == Display) and:[SmallRightArrowShadowForm notNil]) ifTrue:[ |
|
59 | 704 |
^ SmallRightArrowShadowForm |
31 | 705 |
]. |
706 |
f := Form fromFile:'SmallRightArrowShadow.xbm' resolution:100 on:aDevice. |
|
707 |
f isNil ifTrue:[ |
|
59 | 708 |
f := Form width:9 height:9 fromArray:#[2r00000000 2r00000000 |
709 |
2r00000000 2r00000000 |
|
710 |
2r00000000 2r00000000 |
|
711 |
2r00000000 2r00000000 |
|
712 |
2r00000001 2r00000000 |
|
713 |
2r00000110 2r00000000 |
|
714 |
2r00011000 2r00000000 |
|
715 |
2r00100000 2r00000000 |
|
716 |
2r00000000 2r00000000] |
|
717 |
on:aDevice |
|
31 | 718 |
]. |
719 |
(aDevice == Display) ifTrue:[ |
|
59 | 720 |
SmallRightArrowShadowForm := f |
31 | 721 |
]. |
722 |
^ f |
|
22 | 723 |
! ! |
724 |
||
125 | 725 |
!SelectionInListView methodsFor:'selections'! |
726 |
||
727 |
isInSelection:aNumber |
|
728 |
"return true, if line, aNumber is in the selection" |
|
729 |
||
730 |
selection isNil ifTrue:[^ false]. |
|
731 |
multipleSelectOk ifTrue:[ |
|
732 |
^ (selection includes:aNumber) |
|
733 |
]. |
|
734 |
^ (aNumber == selection) |
|
735 |
! |
|
736 |
||
737 |
selectWithoutScroll:aNumberOrNilOrCollection |
|
738 |
"select line, aNumber or deselect if argument is nil" |
|
739 |
||
740 |
|prevSelection newSelection| |
|
741 |
||
742 |
newSelection := aNumberOrNilOrCollection. |
|
743 |
newSelection notNil ifTrue:[ |
|
744 |
(self isValidSelection:newSelection) ifFalse:[ |
|
745 |
newSelection := nil |
|
746 |
] |
|
747 |
]. |
|
748 |
||
749 |
(newSelection = selection) ifTrue: [^ self]. |
|
750 |
||
751 |
" |
|
752 |
redraw old selection unhighlighted |
|
753 |
" |
|
754 |
selection notNil ifTrue: [ |
|
755 |
prevSelection := selection. |
|
756 |
selection := nil. |
|
757 |
multipleSelectOk ifTrue:[ |
|
758 |
prevSelection do:[:line | |
|
759 |
self redrawElement:line |
|
760 |
] |
|
761 |
] ifFalse:[ |
|
762 |
self redrawElement:prevSelection |
|
763 |
] |
|
764 |
]. |
|
765 |
||
766 |
selection := newSelection. |
|
767 |
||
768 |
" |
|
769 |
redraw new selection unhighlighted |
|
770 |
" |
|
771 |
newSelection notNil ifTrue:[ |
|
772 |
multipleSelectOk ifTrue:[ |
|
773 |
newSelection isCollection ifFalse:[ |
|
774 |
selection := OrderedCollection with:newSelection. |
|
775 |
]. |
|
776 |
selection do:[:line | |
|
777 |
self redrawElement:line |
|
778 |
] |
|
779 |
] ifFalse:[ |
|
780 |
self redrawElement:selection |
|
781 |
] |
|
782 |
] |
|
783 |
||
784 |
! |
|
785 |
||
786 |
makeSelectionVisible |
|
787 |
"scroll to make the selection line visible" |
|
788 |
||
789 |
|line| |
|
790 |
||
791 |
selection notNil ifTrue:[ |
|
792 |
multipleSelectOk ifTrue:[ |
|
793 |
line := selection first. |
|
794 |
] ifFalse:[ |
|
795 |
line := selection |
|
796 |
]. |
|
797 |
self makeLineVisible:line |
|
798 |
] |
|
799 |
! |
|
800 |
||
801 |
selection:aNumberOrNil |
|
802 |
"select line, aNumber or deselect if argument is nil; |
|
803 |
scroll to make the selected line visible" |
|
804 |
||
805 |
self selectWithoutScroll:aNumberOrNil. |
|
806 |
selection notNil ifTrue:[self makeSelectionVisible] |
|
807 |
! |
|
808 |
||
809 |
selectionValue |
|
810 |
"return the selection value i.e. the text in the selected line. |
|
811 |
For multiple selections a collection containing the entries is returned." |
|
812 |
||
813 |
selection isNil ifTrue:[^ nil]. |
|
814 |
||
815 |
multipleSelectOk ifTrue:[ |
|
816 |
^ selection collect:[:nr | self at:nr] |
|
817 |
]. |
|
818 |
^ self at:selection |
|
819 |
||
820 |
! |
|
821 |
||
822 |
hasSelection |
|
823 |
"return true, if the view has a selection" |
|
824 |
||
825 |
^ selection notNil |
|
826 |
! |
|
827 |
||
828 |
selectElement:anObject |
|
829 |
"select the element with same printString as the argument, anObject. |
|
830 |
Scroll to make the new selection visible." |
|
831 |
||
832 |
|lineNo| |
|
833 |
||
834 |
list notNil ifTrue:[ |
|
835 |
items notNil ifTrue:[ |
|
836 |
lineNo := items indexOf:anObject ifAbsent:nil |
|
837 |
] ifFalse:[ |
|
838 |
lineNo := list indexOf:(anObject printString) ifAbsent:nil. |
|
839 |
]. |
|
840 |
lineNo notNil ifTrue:[self selection:lineNo] |
|
841 |
] |
|
842 |
! |
|
843 |
||
844 |
selection |
|
845 |
"return the selection index or collection of indices (if multipleSelect is on)" |
|
846 |
||
847 |
^ selection |
|
848 |
! |
|
849 |
||
850 |
selectionChangedFrom:oldSelection |
|
851 |
"selection has changed. Call actionblock and/or send changeMessage if defined" |
|
852 |
||
853 |
|arg| |
|
854 |
||
855 |
arg := self argForChangeMessage. |
|
856 |
" |
|
857 |
the ST/X way of doing things - perform actionBlock |
|
858 |
" |
|
859 |
actionBlock notNil ifTrue:[actionBlock value:arg]. |
|
860 |
" |
|
861 |
the ST-80 way of doing things - notify model via changeMsg |
|
862 |
" |
|
863 |
"/ ST80 sends 0 as index, if the same selection is reselected ... |
|
864 |
selection == oldSelection ifTrue:[ |
|
865 |
arg := 0 |
|
866 |
]. |
|
867 |
self sendChangeMessageWith:arg |
|
868 |
! |
|
869 |
||
870 |
deselect |
|
871 |
"deselect" |
|
872 |
||
873 |
self selection:nil |
|
874 |
! |
|
875 |
||
876 |
deselectWithoutRedraw |
|
877 |
"deselect - no redraw" |
|
878 |
||
879 |
selection := nil |
|
880 |
! |
|
881 |
||
882 |
numberOfSelections |
|
883 |
"return the number of selected entries" |
|
884 |
||
885 |
|sz| |
|
886 |
||
887 |
selection isNil ifTrue:[^ 0]. |
|
888 |
sz := selection size. |
|
889 |
sz > 0 ifTrue:[^ sz]. |
|
890 |
^ 1 |
|
891 |
! |
|
892 |
||
893 |
valueIsInSelection:someString |
|
894 |
"return true, if someString is in the selection" |
|
895 |
||
896 |
|sel| |
|
897 |
||
898 |
selection isNil ifTrue:[^ false]. |
|
899 |
sel := self selectionValue. |
|
900 |
self numberOfSelections > 1 ifTrue:[ |
|
901 |
^ (sel includes:someString) |
|
902 |
]. |
|
903 |
^ (someString = sel) |
|
904 |
! |
|
905 |
||
906 |
selectElementWithoutScroll:anObject |
|
907 |
"select the element with same printString as the argument, anObject. |
|
908 |
Do not scroll." |
|
909 |
||
910 |
|lineNo| |
|
911 |
||
912 |
list notNil ifTrue:[ |
|
913 |
items notNil ifTrue:[ |
|
914 |
lineNo := items indexOf:anObject ifAbsent:nil |
|
915 |
] ifFalse:[ |
|
916 |
lineNo := list indexOf:(anObject printString) ifAbsent:nil. |
|
917 |
]. |
|
918 |
lineNo notNil ifTrue:[self selectWithoutScroll:lineNo] |
|
919 |
] |
|
920 |
! |
|
921 |
||
922 |
nextAfterSelection |
|
923 |
"return the index of the next selectable entry after the selection. |
|
924 |
Wrap at end." |
|
925 |
||
926 |
|next| |
|
927 |
||
928 |
selection isNil ifTrue:[ |
|
929 |
next := firstLineShown |
|
930 |
] ifFalse:[ |
|
931 |
selection size ~~ 0 ifTrue:[ |
|
932 |
next := selection max + 1 |
|
933 |
] ifFalse:[ |
|
934 |
next := selection + 1 |
|
935 |
]. |
|
936 |
]. |
|
937 |
(self isValidSelection:next) ifFalse:[ |
|
938 |
next > self size ifTrue:[ |
|
939 |
next := 1. |
|
940 |
] ifFalse:[ |
|
941 |
[next <= self size |
|
942 |
and:[(self isValidSelection:next) not]] whileTrue:[ |
|
943 |
next := next + 1 |
|
944 |
]. |
|
945 |
]. |
|
946 |
]. |
|
947 |
(self isValidSelection:next) ifFalse:[ |
|
948 |
next := nil |
|
949 |
]. |
|
950 |
^ next |
|
951 |
! |
|
952 |
||
953 |
previousBeforeSelection |
|
954 |
"return the index of the previous selectable entry before the selection. |
|
955 |
Wrap at beginning." |
|
956 |
||
957 |
|prev| |
|
958 |
||
959 |
selection isNil ifTrue:[ |
|
960 |
prev := firstLineShown - 1 |
|
961 |
] ifFalse:[ |
|
962 |
selection size ~~ 0 ifTrue:[ |
|
963 |
prev := selection min - 1 |
|
964 |
] ifFalse:[ |
|
965 |
prev := selection - 1 |
|
966 |
]. |
|
967 |
]. |
|
968 |
(self isValidSelection:prev) ifFalse:[ |
|
969 |
prev < 1 ifTrue:[ |
|
970 |
prev := self size. |
|
971 |
] ifFalse:[ |
|
972 |
[prev >= 1 |
|
973 |
and:[(self isValidSelection:prev) not]] whileTrue:[ |
|
974 |
prev := prev - 1 |
|
975 |
]. |
|
976 |
]. |
|
977 |
]. |
|
978 |
(self isValidSelection:prev) ifFalse:[ |
|
979 |
prev := nil |
|
980 |
]. |
|
981 |
^ prev |
|
982 |
||
983 |
! |
|
984 |
||
985 |
selectAll |
|
986 |
"select all entries." |
|
987 |
||
988 |
|oldSelection| |
|
989 |
||
990 |
multipleSelectOk ifTrue:[ |
|
991 |
oldSelection := selection. |
|
992 |
selection := OrderedCollection withAll:(1 to:self size). |
|
993 |
shown ifTrue:[self redraw]. |
|
994 |
self selectionChangedFrom:oldSelection. |
|
995 |
] |
|
996 |
! |
|
997 |
||
998 |
toggleSelection:aNumber |
|
999 |
"toggle selection-state of entry, aNumber" |
|
1000 |
||
1001 |
(self isInSelection:aNumber) ifTrue:[ |
|
1002 |
self removeFromSelection:aNumber |
|
1003 |
] ifFalse:[ |
|
1004 |
self addToSelection:aNumber |
|
1005 |
] |
|
1006 |
! |
|
1007 |
||
1008 |
selectNext |
|
1009 |
"select next line or first visible if there is currrently no selection. |
|
1010 |
Wrap at end." |
|
1011 |
||
1012 |
self selection:(self nextAfterSelection) |
|
1013 |
! |
|
1014 |
||
1015 |
selectPrevious |
|
1016 |
"select previous line or previous visible if there is currently no selection. |
|
1017 |
Wrap at beginning." |
|
1018 |
||
1019 |
self selection:(self previouseBeforeSelection). |
|
1020 |
! |
|
1021 |
||
1022 |
selectionDo:aBlock |
|
1023 |
"perform aBlock for each nr in the selection. |
|
1024 |
For single selection, it is called once for the items nr. |
|
1025 |
For multiple selections, it is called for each." |
|
1026 |
||
1027 |
selection notNil ifTrue:[ |
|
1028 |
multipleSelectOk ifTrue:[ |
|
1029 |
selection do:aBlock |
|
1030 |
] ifFalse:[ |
|
1031 |
aBlock value:selection |
|
1032 |
]. |
|
1033 |
]. |
|
1034 |
||
1035 |
! |
|
1036 |
||
1037 |
selectionAsCollection |
|
1038 |
"return the selection as a collection of line numbers. |
|
1039 |
This allows users of this class to enumerate independent of |
|
1040 |
the multipleSelect style." |
|
1041 |
||
1042 |
selection isNil ifTrue:[^ #()]. |
|
1043 |
||
1044 |
multipleSelectOk ifTrue:[ |
|
1045 |
^ (OrderedCollection new) add:selection; yourself. |
|
1046 |
]. |
|
1047 |
^ selection |
|
1048 |
! ! |
|
1049 |
||
0 | 1050 |
!SelectionInListView methodsFor:'redrawing'! |
1051 |
||
1052 |
redrawVisibleLine:visLineNr |
|
31 | 1053 |
"redraw a single line. |
1054 |
Must check, if any is in the selection and handle this case. |
|
1055 |
Otherwise draw using supers method." |
|
1056 |
||
90 | 1057 |
|listLine fg bg newFont| |
0 | 1058 |
|
1059 |
fg := fgColor. |
|
1060 |
bg := bgColor. |
|
1061 |
listLine := self visibleLineToListLine:visLineNr. |
|
1062 |
listLine notNil ifTrue:[ |
|
59 | 1063 |
(self isInSelection:listLine) ifTrue:[ |
1064 |
^ self drawVisibleLineSelected:visLineNr |
|
1065 |
]. |
|
125 | 1066 |
|
1067 |
listAttributes notNil ifTrue:[ |
|
1068 |
(self line:listLine hasAttribute:#halfIntensity) ifTrue:[ |
|
60 | 1069 |
fg := halfIntensityFgColor |
125 | 1070 |
] ifFalse:[ |
1071 |
(self line:listLine hasAttribute:#disabled) ifTrue:[ |
|
1072 |
fg := halfIntensityFgColor |
|
1073 |
]. |
|
65 | 1074 |
]. |
125 | 1075 |
(self line:listLine hasAttribute:#bold) ifTrue:[ |
1076 |
font bold ifTrue:[ |
|
1077 |
" |
|
1078 |
mhmh - what can be done, if the font is already bold ? |
|
1079 |
" |
|
1080 |
newFont := font. |
|
1081 |
fgColor brightness > 0.5 ifTrue:[ |
|
1082 |
fg := fgColor darkened "darkened". |
|
1083 |
] ifFalse:[ |
|
1084 |
fg := fgColor lightened "lightened" |
|
1085 |
]. |
|
1086 |
(fg brightness - bg brightness) abs < 0.25 ifTrue:[ |
|
1087 |
bgColor brightness > 0.5 ifTrue:[ |
|
1088 |
fg := fg darkened. |
|
1089 |
] ifFalse:[ |
|
1090 |
fg := fg lightened |
|
1091 |
]. |
|
1092 |
] |
|
77 | 1093 |
] ifFalse:[ |
125 | 1094 |
newFont := font asBold |
77 | 1095 |
]. |
125 | 1096 |
device setFont:(newFont on:device) fontId in:gcId. |
1097 |
self drawVisibleLine:visLineNr with:fg and:bg. |
|
1098 |
device setFont:(font on:device) fontId in:gcId. |
|
1099 |
^ self |
|
1100 |
] |
|
63 | 1101 |
] |
31 | 1102 |
]. |
1103 |
^ self drawVisibleLine:visLineNr with:fg and:bg |
|
1104 |
! |
|
1105 |
||
125 | 1106 |
redrawElement:aNumber |
1107 |
"redraw an individual element" |
|
1108 |
||
1109 |
^ self redrawLine:aNumber |
|
1110 |
! |
|
1111 |
||
31 | 1112 |
drawVisibleLineSelected:visLineNr |
1113 |
"redraw a single line as selected." |
|
1114 |
||
1115 |
|listLine fg bg |
|
1116 |
y "{ Class: SmallInteger }" |
|
1117 |
wEdge| |
|
1118 |
||
1119 |
bg := hilightBgColor. |
|
1120 |
fg := hilightFgColor. |
|
1121 |
listLine := self visibleLineToListLine:visLineNr. |
|
1122 |
listLine notNil ifTrue:[ |
|
1123 |
"XXX only if -1/+1" |
|
1124 |
"/ hilightLevel ~~ 0 ifTrue:[ |
|
1125 |
"/ self paint:bg. |
|
59 | 1126 |
"/ self fillRectangleX:0 y:(self yOfVisibleLine:visLineNr)-1 width:width height:1 |
31 | 1127 |
"/ ]. |
1128 |
||
63 | 1129 |
strikeOut ifTrue:[ |
1130 |
self drawVisibleLine:visLineNr with:fgColor and:bgColor. |
|
1131 |
y := self yOfVisibleLine:visLineNr. |
|
1132 |
||
1133 |
self paint:fgColor. |
|
1134 |
y := y + (fontHeight // 2). |
|
1135 |
self displayLineFromX:0 y:y toX:width y:y. |
|
1136 |
^ self |
|
1137 |
]. |
|
1138 |
||
59 | 1139 |
self drawVisibleLine:visLineNr with:fg and:bg. |
1140 |
y := self yOfVisibleLine:visLineNr. |
|
31 | 1141 |
|
59 | 1142 |
" |
1143 |
a line above and below |
|
1144 |
" |
|
1145 |
hilightFrameColor notNil ifTrue:[ |
|
1146 |
self paint:hilightFrameColor. |
|
1147 |
self displayLineFromX:0 y:y toX:width y:y. |
|
1148 |
y := y + fontHeight - 1. |
|
1149 |
self displayLineFromX:0 y:y toX:width y:y. |
|
1150 |
^ self |
|
1151 |
]. |
|
31 | 1152 |
|
59 | 1153 |
" |
1154 |
an edge it around |
|
1155 |
" |
|
1156 |
(hilightLevel ~~ 0) ifTrue:[ |
|
31 | 1157 |
"XXX the -1/+1 need some more work" |
1158 |
"/ self drawEdgesForX:0 y:y-1 |
|
1159 |
"/ width:width height:fontHeight+1 |
|
1160 |
"/ level:hilightLevel. |
|
1161 |
||
59 | 1162 |
" |
1163 |
let edge start at left, extending to the full width |
|
1164 |
XXX: widthOfContents should be cached in ListView |
|
60 | 1165 |
(instead of recomputing all over) |
59 | 1166 |
" |
1167 |
wEdge := width-(2 * margin). |
|
60 | 1168 |
includesNonStrings ifFalse:[ |
59 | 1169 |
wEdge := wEdge max:(self widthOfContents). |
60 | 1170 |
]. |
59 | 1171 |
self drawEdgesForX:(margin - leftOffset) y:y |
1172 |
width:wEdge height:fontHeight |
|
1173 |
level:hilightLevel. |
|
31 | 1174 |
|
1175 |
||
59 | 1176 |
^ self |
1177 |
] |
|
0 | 1178 |
]. |
31 | 1179 |
^ super drawVisibleLine:visLineNr with:fg and:bg |
105 | 1180 |
! |
1181 |
||
1182 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
1183 |
"redraw a range of lines. |
|
1184 |
Must check, if any is in the selection and handle this case. |
|
1185 |
Otherwise draw it en-bloque using supers method." |
|
1186 |
||
1187 |
|special sel |
|
1188 |
selNo "{ Class: SmallInteger }" | |
|
1189 |
||
1190 |
((selection isCollection) or:[listAttributes notNil]) ifTrue:[ |
|
1191 |
startVisLineNr to:endVisLineNr do:[:visLine | |
|
1192 |
self redrawVisibleLine:visLine |
|
1193 |
]. |
|
1194 |
^ self |
|
1195 |
]. |
|
1196 |
||
1197 |
"XXX only if -1/+1" |
|
1198 |
"/ hilightLevel ~~ 0 ifTrue:[ |
|
1199 |
"/ self paint:bgColor. |
|
1200 |
"/ self fillRectangleX:0 y:(self yOfVisibleLine:startVisLineNr)-1 width:width height:1 |
|
1201 |
"/ ]. |
|
1202 |
special := true. |
|
1203 |
selection isNil ifTrue:[ |
|
1204 |
special := false |
|
1205 |
] ifFalse:[ |
|
1206 |
sel := self listLineToVisibleLine:selection. |
|
1207 |
sel isNil ifTrue:[ |
|
1208 |
special := false |
|
1209 |
] ifFalse:[ |
|
1210 |
special := (sel between:startVisLineNr and:endVisLineNr) |
|
1211 |
] |
|
1212 |
]. |
|
1213 |
special ifFalse:[ |
|
1214 |
^ super redrawFromVisibleLine:startVisLineNr |
|
1215 |
to:endVisLineNr |
|
1216 |
]. |
|
1217 |
||
1218 |
selNo := sel. |
|
1219 |
selNo > startVisLineNr ifTrue:[ |
|
1220 |
super redrawFromVisibleLine:startVisLineNr to:(selNo - 1) |
|
1221 |
]. |
|
1222 |
self redrawVisibleLine:selNo. |
|
1223 |
selNo < endVisLineNr ifTrue:[ |
|
1224 |
super redrawFromVisibleLine:(selNo + 1) to:endVisLineNr |
|
1225 |
] |
|
1226 |
! |
|
1227 |
||
125 | 1228 |
redrawVisibleLine:visLineNr from:startCol to:endCol |
1229 |
"redraw from a startCol to endCol. |
|
1230 |
Must check, if its in the selection and handle this case." |
|
1231 |
||
1232 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[ |
|
1233 |
^ self redrawVisibleLine:visLineNr |
|
1234 |
]. |
|
1235 |
super redrawVisibleLine:visLineNr from:startCol to:endCol |
|
1236 |
! |
|
1237 |
||
105 | 1238 |
drawRightArrowInVisibleLine:visLineNr |
1239 |
"draw a right arrow (for submenus). |
|
1240 |
This method is not used here, but provided for subclasses such |
|
1241 |
as menus or file-lists." |
|
1242 |
||
1243 |
|y x form form2 topLeftColor botRightColor t| |
|
1244 |
||
1245 |
x := width - 16. |
|
1246 |
y := (self yOfVisibleLine:visLineNr). |
|
1247 |
||
1248 |
device depth == 1 ifTrue:[ |
|
1249 |
form := self class rightArrowFormOn:device. |
|
1250 |
y := y + ((font height - form height) // 2). |
|
1251 |
self foreground:Black. |
|
1252 |
self displayForm:form x:x y:y. |
|
1253 |
] ifFalse:[ |
|
1254 |
smallArrow ifTrue:[ |
|
1255 |
form := self class smallRightArrowLightFormOn:device. |
|
1256 |
form2 := self class smallRightArrowShadowFormOn:device. |
|
1257 |
] ifFalse:[ |
|
1258 |
form := self class rightArrowLightFormOn:device. |
|
1259 |
form2 := self class rightArrowShadowFormOn:device. |
|
1260 |
]. |
|
1261 |
y := y + ((font height - form height) // 2). |
|
1262 |
||
1263 |
topLeftColor := lightColor. |
|
1264 |
botRightColor := shadowColor. |
|
1265 |
||
1266 |
"openwin arrow stays down" |
|
1267 |
style ~~ #openwin ifTrue:[ |
|
1268 |
(self isInSelection:(self visibleLineToListLine:visLineNr)) ifTrue:[ |
|
1269 |
t := topLeftColor. |
|
1270 |
topLeftColor := botRightColor. |
|
1271 |
botRightColor := t. |
|
1272 |
] |
|
1273 |
]. |
|
1274 |
arrowLevel < 0 ifTrue:[ |
|
1275 |
t := topLeftColor. |
|
1276 |
topLeftColor := botRightColor. |
|
1277 |
botRightColor := t. |
|
1278 |
]. |
|
1279 |
||
1280 |
"/ self foreground:topLeftColor. |
|
1281 |
self paint:topLeftColor. |
|
1282 |
self displayForm:form x:x y:y. |
|
1283 |
"/ self foreground:botRightColor. |
|
1284 |
self paint:botRightColor. |
|
1285 |
self displayForm:form2 x:x y:y. |
|
1286 |
] |
|
1287 |
! |
|
1288 |
||
1289 |
redrawVisibleLine:visLineNr col:colNr |
|
1290 |
"redraw a single character. |
|
1291 |
Must check, if its in the selection and handle this case." |
|
1292 |
||
1293 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[ |
|
1294 |
^ self redrawVisibleLine:visLineNr |
|
1295 |
]. |
|
1296 |
super redrawVisibleLine:visLineNr col:colNr |
|
1297 |
! |
|
1298 |
||
1299 |
redrawVisibleLine:visLineNr from:startCol |
|
1300 |
"redraw from a col to the right end. |
|
1301 |
Must check, if its in the selection and handle this case." |
|
1302 |
||
1303 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[ |
|
1304 |
^ self redrawVisibleLine:visLineNr |
|
1305 |
]. |
|
1306 |
super redrawVisibleLine:visLineNr from:startCol |
|
1307 |
! ! |
|
1308 |
||
1309 |
!SelectionInListView methodsFor:'private'! |
|
1310 |
||
1311 |
getListFromModel |
|
119 | 1312 |
"if I have a model and a listMsg, get my list from it" |
1313 |
||
105 | 1314 |
|text| |
1315 |
||
119 | 1316 |
model notNil ifTrue:[ |
1317 |
listMsg notNil ifTrue:[ |
|
1318 |
items := model perform:listMsg. |
|
1319 |
items notNil ifTrue:[ |
|
1320 |
printItems ifTrue:[ |
|
1321 |
text := items collect:[:element | element printString] |
|
1322 |
] ifFalse:[ |
|
1323 |
text := items |
|
1324 |
]. |
|
1325 |
text notNil ifTrue:[ |
|
1326 |
text := text asStringCollection. |
|
1327 |
] |
|
1328 |
]. |
|
1329 |
self list:text |
|
1330 |
]. |
|
1331 |
]. |
|
1332 |
! |
|
1333 |
||
1334 |
getSelectionFromModel |
|
1335 |
"if I have a model and an initialSelectionMsg, get my selection from it" |
|
1336 |
||
1337 |
|sel| |
|
1338 |
||
1339 |
model notNil ifTrue:[ |
|
1340 |
initialSelectionMsg notNil ifTrue:[ |
|
1341 |
sel := model perform:initialSelectionMsg. |
|
1342 |
useIndex ifTrue:[ |
|
1343 |
self selection:sel |
|
105 | 1344 |
] ifFalse:[ |
119 | 1345 |
self selectElement:sel. |
105 | 1346 |
]. |
119 | 1347 |
] |
105 | 1348 |
]. |
125 | 1349 |
! |
1350 |
||
1351 |
argForChangeMessage |
|
1352 |
"return the argument for a selectionChange; |
|
1353 |
depending on the setting of useIndex, this is either the numeric |
|
1354 |
index of the selection or the value (i.e. the string)" |
|
1355 |
||
1356 |
useIndex ~~ false ifTrue:[ "/ i.e. everything except false |
|
1357 |
^ selection |
|
1358 |
]. |
|
1359 |
||
1360 |
printItems ifFalse:[ |
|
1361 |
^ self selectionValue |
|
1362 |
]. |
|
1363 |
||
1364 |
items notNil ifTrue:[ |
|
1365 |
multipleSelectOk ifTrue:[ |
|
1366 |
^ selection collect:[:nr | items at:nr] |
|
1367 |
]. |
|
1368 |
^ items at:selection |
|
1369 |
]. |
|
1370 |
||
1371 |
^ nil "/ cannot happen |
|
1372 |
! |
|
1373 |
||
1374 |
isValidSelection:aNumberOrCollection |
|
1375 |
"return true, if aNumber is ok as a selection index" |
|
1376 |
||
1377 |
aNumberOrCollection isNil ifTrue:[^ false]. |
|
1378 |
||
1379 |
(aNumberOrCollection isCollection) ifTrue:[ |
|
1380 |
multipleSelectOk ifFalse:[^ false]. |
|
1381 |
aNumberOrCollection do:[:index | |
|
1382 |
(index between:1 and:self size) ifFalse:[^ false]. |
|
1383 |
]. |
|
1384 |
^ true. |
|
1385 |
] ifFalse:[ |
|
1386 |
^ (aNumberOrCollection between:1 and:self size). |
|
1387 |
]. |
|
1388 |
||
1389 |
! |
|
1390 |
||
1391 |
positionToSelectionX:x y:y |
|
1392 |
"given a click position, return the selection lineNo" |
|
1393 |
||
1394 |
|visibleLine| |
|
1395 |
||
1396 |
(x between:0 and:width) ifTrue:[ |
|
1397 |
(y between:0 and:height) ifTrue:[ |
|
1398 |
visibleLine := self visibleLineOfY:y. |
|
1399 |
^ self visibleLineToListLine:visibleLine |
|
1400 |
] |
|
1401 |
]. |
|
1402 |
^ nil |
|
1403 |
! |
|
1404 |
||
1405 |
widthForScrollBetween:start and:end |
|
1406 |
"has to be redefined since WHOLE line is inverted/modified sometimes" |
|
1407 |
||
1408 |
| anySelectionInRange | |
|
1409 |
||
1410 |
selection notNil ifTrue:[ |
|
1411 |
multipleSelectOk ifTrue:[ |
|
1412 |
anySelectionInRange := false. |
|
1413 |
selection do:[:s | |
|
1414 |
(s between:start and:end) ifTrue:[ |
|
1415 |
anySelectionInRange := true |
|
1416 |
] |
|
1417 |
] |
|
1418 |
] ifFalse:[ |
|
1419 |
anySelectionInRange := selection between:start and:end |
|
1420 |
] |
|
1421 |
] ifFalse:[ |
|
1422 |
anySelectionInRange := false |
|
1423 |
]. |
|
1424 |
||
1425 |
anySelectionInRange ifTrue:[ |
|
1426 |
^ width |
|
1427 |
" |
|
1428 |
self is3D ifFalse:[ |
|
1429 |
^ width |
|
1430 |
]. |
|
1431 |
( #(next openwin) includes:style) ifTrue:[ |
|
1432 |
^ width |
|
1433 |
]. |
|
1434 |
viewBackground = background ifFalse:[ |
|
1435 |
^ width |
|
1436 |
] |
|
1437 |
" |
|
1438 |
]. |
|
1439 |
^ super widthForScrollBetween:start and:end |
|
1440 |
! |
|
1441 |
||
1442 |
visibleLineNeedsSpecialCare:visLineNr |
|
1443 |
|listLine| |
|
1444 |
||
1445 |
listLine := self visibleLineToListLine:visLineNr. |
|
1446 |
listLine isNil ifTrue:[^ false]. |
|
1447 |
(self isInSelection:listLine) ifTrue:[^ true]. |
|
1448 |
listAttributes notNil ifTrue:[ |
|
1449 |
(listLine <= listAttributes size) ifTrue:[ |
|
1450 |
^ (listAttributes at:listLine) notNil |
|
1451 |
] |
|
1452 |
]. |
|
1453 |
^ false |
|
1454 |
! |
|
1455 |
||
1456 |
checkRemovingSelection:lineNr |
|
1457 |
"when a line is removed, we have to adjust selection" |
|
1458 |
||
1459 |
|newSelection| |
|
1460 |
||
1461 |
selection notNil ifTrue:[ |
|
1462 |
multipleSelectOk ifTrue:[ |
|
1463 |
newSelection := OrderedCollection new. |
|
1464 |
selection do:[:sel | |
|
1465 |
sel < lineNr ifTrue:[ |
|
1466 |
newSelection add:sel |
|
1467 |
] ifFalse:[ |
|
1468 |
sel > lineNr ifTrue:[ |
|
1469 |
newSelection add:(sel - 1) |
|
1470 |
] |
|
1471 |
"otherwise remove it from the selection" |
|
1472 |
] |
|
1473 |
]. |
|
1474 |
newSelection size == 0 ifTrue:[ |
|
1475 |
selection := nil |
|
1476 |
] ifFalse:[ |
|
1477 |
selection := newSelection |
|
1478 |
] |
|
1479 |
] ifFalse:[ |
|
1480 |
selection == lineNr ifTrue:[ |
|
1481 |
selection := nil |
|
1482 |
] ifFalse:[ |
|
1483 |
selection > lineNr ifTrue:[ |
|
1484 |
selection := selection - 1 |
|
1485 |
] |
|
1486 |
] |
|
1487 |
] |
|
1488 |
] |
|
1489 |
! |
|
1490 |
||
1491 |
scrollSelectDown |
|
1492 |
"auto scroll action; scroll and reinstall timed-block" |
|
1493 |
||
1494 |
self scrollDown. |
|
1495 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT. |
|
1496 |
! |
|
1497 |
||
1498 |
scrollSelectUp |
|
1499 |
"auto scroll action; scroll and reinstall timed-block" |
|
1500 |
||
1501 |
self scrollUp. |
|
1502 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT. |
|
1503 |
! ! |
|
1504 |
||
1505 |
!SelectionInListView methodsFor:'event handling'! |
|
1506 |
||
1507 |
buttonRelease:button x:x y:y |
|
1508 |
"stop any autoscroll" |
|
1509 |
||
1510 |
self stopAutoScroll |
|
1511 |
! |
|
1512 |
||
1513 |
buttonPress:button x:x y:y |
|
1514 |
|oldSelection listLineNr| |
|
1515 |
||
1516 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
1517 |
enabled ifTrue:[ |
|
1518 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y). |
|
1519 |
listLineNr notNil ifTrue:[ |
|
1520 |
(toggleSelect |
|
1521 |
and:[self isInSelection:listLineNr]) ifTrue:[ |
|
1522 |
oldSelection := selection copy. |
|
1523 |
self removeFromSelection:listLineNr |
|
1524 |
] ifFalse:[ |
|
1525 |
(self line:listLineNr hasAttribute:#disabled) ifTrue:[^ self]. |
|
1526 |
||
1527 |
(selectConditionBlock notNil |
|
1528 |
and:[(selectConditionBlock value:listLineNr) not]) ifTrue:[^ self]. |
|
1529 |
||
1530 |
(toggleSelect and:[multipleSelectOk]) ifTrue:[ |
|
1531 |
oldSelection := selection copy. |
|
1532 |
self addToSelection:listLineNr |
|
1533 |
] ifFalse:[ |
|
1534 |
oldSelection := selection copy. |
|
1535 |
self selectWithoutScroll:listLineNr. |
|
1536 |
]. |
|
1537 |
]. |
|
1538 |
((ignoreReselect not and:[selection notNil]) |
|
1539 |
or:[selection ~= oldSelection]) ifTrue:[ |
|
1540 |
self selectionChangedFrom:oldSelection. |
|
1541 |
]. |
|
1542 |
clickLine := listLineNr |
|
1543 |
]. |
|
1544 |
] |
|
1545 |
] ifFalse:[ |
|
1546 |
super buttonPress:button x:x y:y |
|
1547 |
] |
|
1548 |
! |
|
1549 |
||
1550 |
sizeChanged:how |
|
1551 |
"if there is a selection, make certain, its visible |
|
1552 |
after the sizechange" |
|
1553 |
||
1554 |
|first wasAtEnd| |
|
1555 |
||
1556 |
wasAtEnd := (firstLineShown + nFullLinesShown) >= self size. |
|
1557 |
||
1558 |
super sizeChanged:how. |
|
1559 |
||
1560 |
shown ifTrue:[ |
|
1561 |
selection notNil ifTrue:[ |
|
1562 |
multipleSelectOk ifTrue:[ |
|
1563 |
first := selection first |
|
1564 |
] ifFalse:[ |
|
1565 |
first := selection |
|
1566 |
]. |
|
1567 |
first notNil ifTrue:[self makeLineVisible:first] |
|
1568 |
] ifFalse:[ |
|
1569 |
" |
|
1570 |
if we where at the end before, move to the end again. |
|
1571 |
Still to be seen, if this is better in real life ... |
|
1572 |
" |
|
1573 |
wasAtEnd ifTrue:[ |
|
1574 |
"at end" |
|
1575 |
self scrollToBottom |
|
1576 |
] |
|
1577 |
] |
|
1578 |
] |
|
1579 |
! |
|
1580 |
||
1581 |
keyPress:key x:x y:y |
|
1582 |
"handle keyboard input" |
|
1583 |
||
1584 |
|index startSearch backSearch searchPrefix| |
|
1585 |
||
1586 |
(key == #CursorUp) ifTrue:[ |
|
1587 |
index := self previousBeforeSelection. |
|
1588 |
self key:key select:index x:x y:y. |
|
1589 |
^ self |
|
1590 |
]. |
|
1591 |
(key == #CursorDown) ifTrue:[ |
|
1592 |
index := self nextAfterSelection. |
|
1593 |
self key:key select:index x:x y:y. |
|
1594 |
^ self |
|
1595 |
]. |
|
1596 |
"/ |
|
1597 |
"/ stupid: Home and End are cought in ScrollableView |
|
1598 |
"/ we normally do not get them ... |
|
1599 |
"/ (need to call handlesKey: from there ... |
|
1600 |
"/ ... and implement it here) |
|
1601 |
"/ |
|
1602 |
(key == #Home) ifTrue:[ |
|
1603 |
self key:key select:1 x:x y:y. |
|
1604 |
^ self |
|
1605 |
]. |
|
1606 |
(key == #End) ifTrue:[ |
|
1607 |
index := self size. |
|
1608 |
self key:key select:index x:x y:y. |
|
1609 |
^ self |
|
1610 |
]. |
|
1611 |
key == #Return ifTrue:[ |
|
1612 |
returnKeyActionStyle == #doubleClick ifTrue:[ |
|
1613 |
selection notNil ifTrue:[ |
|
1614 |
self doubleClicked |
|
1615 |
]. |
|
1616 |
^ self |
|
1617 |
]. |
|
1618 |
returnKeyActionStyle ~~ #pass ifTrue:[ |
|
1619 |
^ self |
|
1620 |
]. |
|
1621 |
]. |
|
1622 |
||
1623 |
" |
|
1624 |
alphabetic keys: search for next entry |
|
1625 |
starting with keys character. If shift is pressed, search backward |
|
1626 |
" |
|
1627 |
(self size > 0 |
|
1628 |
and:[key isCharacter |
|
1629 |
and:[key isLetter]]) ifTrue:[ |
|
1630 |
keyActionStyle isNil ifTrue:[^ self]. |
|
1631 |
keyActionStyle == #pass ifFalse:[ |
|
1632 |
searchPrefix := key asLowercase asString. |
|
1633 |
||
1634 |
"/ ... isISearch... ifFalse:[ |
|
1635 |
"/ iSearchString := '' |
|
1636 |
"/ ] ifTrue:[ |
|
1637 |
"/ iSearchString := iSearchString , searchPrefix. |
|
1638 |
"/ searchPrefix := iSearchString |
|
1639 |
"/ ]. |
|
1640 |
||
1641 |
backSearch := device shiftDown. |
|
1642 |
backSearch ifTrue:[ |
|
1643 |
selection notNil ifTrue:[ |
|
1644 |
selection size > 0 ifTrue:[ |
|
1645 |
startSearch := selection first - 1 |
|
1646 |
] ifFalse:[ |
|
1647 |
startSearch := selection - 1 |
|
1648 |
] |
|
1649 |
] ifFalse:[ |
|
1650 |
startSearch := self size |
|
1651 |
]. |
|
1652 |
startSearch < 1 ifTrue:[ |
|
1653 |
startSearch := self size. |
|
1654 |
]. |
|
1655 |
] ifFalse:[ |
|
1656 |
selection notNil ifTrue:[ |
|
1657 |
selection size > 0 ifTrue:[ |
|
1658 |
startSearch := selection last + 1 |
|
1659 |
] ifFalse:[ |
|
1660 |
startSearch := selection + 1 |
|
1661 |
] |
|
1662 |
] ifFalse:[ |
|
1663 |
startSearch := 1 |
|
1664 |
]. |
|
1665 |
startSearch > self size ifTrue:[ |
|
1666 |
startSearch := 1. |
|
1667 |
]. |
|
1668 |
]. |
|
1669 |
index := startSearch. |
|
1670 |
[true] whileTrue:[ |
|
1671 |
(((self at:index) asString) asLowercase startsWith:searchPrefix) ifTrue:[ |
|
1672 |
index = selection ifTrue:[^ self]. |
|
1673 |
^ self key:key select:index x:x y:y |
|
1674 |
]. |
|
1675 |
backSearch ifTrue:[ |
|
1676 |
index := index - 1. |
|
1677 |
index < 1 ifTrue:[index := self size] |
|
1678 |
] ifFalse:[ |
|
1679 |
index := index + 1. |
|
1680 |
index > self size ifTrue:[index := 1]. |
|
1681 |
]. |
|
1682 |
index == startSearch ifTrue:[ |
|
1683 |
^ self |
|
1684 |
] |
|
1685 |
] |
|
1686 |
]. |
|
1687 |
]. |
|
1688 |
^ super keyPress:key x:x y:y |
|
1689 |
! |
|
1690 |
||
1691 |
buttonMotion:buttonMask x:x y:y |
|
1692 |
"mouse-move while button was pressed - handle selection changes" |
|
1693 |
||
1694 |
|movedVisibleLine movedLine delta oldSelection oldSelCount| |
|
1695 |
||
1696 |
"is it the select or 1-button ?" |
|
1697 |
(device buttonMotionMask:buttonMask includesButton:#select) ifFalse:[ |
|
1698 |
(device buttonMotionMask:buttonMask includesButton:1) ifFalse:[ |
|
1699 |
^ self |
|
1700 |
]. |
|
1701 |
]. |
|
1702 |
||
1703 |
clickLine isNil ifTrue:[^ self]. |
|
1704 |
||
1705 |
"if moved outside of view, start autoscroll" |
|
1706 |
(y < 0) ifTrue:[ |
|
1707 |
self compressMotionEvents:false. |
|
1708 |
self startAutoScrollUp:y. |
|
1709 |
^ self |
|
1710 |
]. |
|
1711 |
(y > height) ifTrue:[ |
|
1712 |
self compressMotionEvents:false. |
|
1713 |
self startAutoScrollDown:(y - height). |
|
1714 |
^ self |
|
1715 |
]. |
|
1716 |
||
1717 |
"move inside - stop autoscroll if any" |
|
1718 |
self stopAutoScroll. |
|
1719 |
||
1720 |
movedVisibleLine := self visibleLineOfY:y. |
|
1721 |
movedLine := self visibleLineToAbsoluteLine:movedVisibleLine. |
|
1722 |
(movedLine == clickLine) ifTrue:[^ self]. |
|
1723 |
||
1724 |
multipleSelectOk ifTrue:[ |
|
1725 |
delta := (clickLine < movedLine) ifTrue:[1] ifFalse:[-1]. |
|
1726 |
||
1727 |
oldSelection := selection. |
|
1728 |
oldSelCount := selection size. |
|
1729 |
||
1730 |
(clickLine+delta) to:movedLine by:delta do:[:line | |
|
1731 |
(self isInSelection:line) ifTrue:[ |
|
1732 |
self removeFromSelection:line |
|
1733 |
] ifFalse:[ |
|
1734 |
self addToSelection:line |
|
1735 |
] |
|
1736 |
]. |
|
1737 |
((selection ~= oldSelection) |
|
1738 |
or:[selection size ~~ oldSelCount]) ifTrue:[ |
|
1739 |
self selectionChangedFrom:oldSelection. |
|
1740 |
] |
|
1741 |
] ifFalse:[ |
|
1742 |
"/ self selectWithoutScroll:movedLine |
|
1743 |
]. |
|
1744 |
||
1745 |
clickLine := movedLine |
|
1746 |
! |
|
1747 |
||
1748 |
key:key select:index x:x y:y |
|
1749 |
"select an entry by a keyboard action. |
|
1750 |
This is treated like a doubleClick on that entry" |
|
1751 |
||
1752 |
|oldSelection| |
|
1753 |
||
1754 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[ |
|
1755 |
keyActionStyle notNil ifTrue:[ |
|
1756 |
keyActionStyle == #pass ifTrue:[ |
|
1757 |
^ super keyPress:key x:x y:y |
|
1758 |
]. |
|
1759 |
oldSelection := selection. |
|
1760 |
self selection:index. |
|
1761 |
self selectionChangedFrom:oldSelection. |
|
1762 |
keyActionStyle == #selectAndDoubleClick ifTrue:[ |
|
1763 |
self doubleClicked |
|
1764 |
] |
|
1765 |
] |
|
1766 |
]. |
|
1767 |
! |
|
1768 |
||
1769 |
buttonMultiPress:button x:x y:y |
|
1770 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
1771 |
"/ doubleClickActionBlock isNil ifTrue:[ |
|
1772 |
"/ self buttonPress:button x:x y:y |
|
1773 |
"/ ]. |
|
1774 |
self doubleClicked. |
|
1775 |
] ifFalse:[ |
|
1776 |
super buttonMultiPress:button x:x y:y |
|
1777 |
] |
|
1778 |
! |
|
1779 |
||
1780 |
buttonShiftPress:button x:x y:y |
|
1781 |
"add to the selection (if multipleSelectOk); otherwise, |
|
1782 |
behave like normal select" |
|
1783 |
||
1784 |
|oldSelection listLineNr| |
|
1785 |
||
1786 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
1787 |
toggleSelect ifTrue:[ |
|
1788 |
^ self buttonPress:button x:x y:y |
|
1789 |
]. |
|
1790 |
enabled ifTrue:[ |
|
1791 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y). |
|
1792 |
listLineNr notNil ifTrue:[ |
|
1793 |
(self line:listLineNr hasAttribute:#disabled) ifTrue:[^ self]. |
|
1794 |
||
1795 |
(selectConditionBlock notNil |
|
1796 |
and:[(selectConditionBlock value:listLineNr) not]) ifTrue:[^ self]. |
|
1797 |
]. |
|
1798 |
oldSelection := selection copy. |
|
1799 |
listLineNr notNil ifTrue: [ |
|
1800 |
multipleSelectOk ifTrue:[ |
|
1801 |
(self isInSelection:listLineNr) ifTrue:[ |
|
1802 |
self removeFromSelection:listLineNr |
|
1803 |
] ifFalse:[ |
|
1804 |
self addToSelection:listLineNr |
|
1805 |
] |
|
1806 |
] ifFalse:[ |
|
1807 |
self selectWithoutScroll:listLineNr |
|
1808 |
] |
|
1809 |
]. |
|
1810 |
((ignoreReselect not and:[selection notNil]) |
|
1811 |
or:[selection ~= oldSelection]) ifTrue:[ |
|
1812 |
self selectionChangedFrom:oldSelection. |
|
1813 |
]. |
|
1814 |
clickLine := listLineNr |
|
1815 |
] |
|
1816 |
] ifFalse:[ |
|
1817 |
super buttonShiftPress:button x:x y:y |
|
1818 |
] |
|
1819 |
! |
|
1820 |
||
1821 |
doubleClicked |
|
1822 |
doubleClickActionBlock notNil ifTrue:[doubleClickActionBlock value:selection]. |
|
1823 |
(model notNil and:[doubleClickMsg notNil]) ifTrue:[ |
|
1824 |
self sendChangeMessage:doubleClickMsg with:(self argForChangeMessage). |
|
1825 |
]. |
|
1826 |
! ! |
|
1827 |
||
1828 |
!SelectionInListView methodsFor:'accessing-actions'! |
|
1829 |
||
1830 |
action:aBlock |
|
1831 |
"set the action block to be performed on select" |
|
1832 |
||
1833 |
actionBlock := aBlock |
|
1834 |
! |
|
1835 |
||
1836 |
doubleClickAction:aBlock |
|
1837 |
"set the double click action block to be performed on select" |
|
1838 |
||
1839 |
doubleClickActionBlock := aBlock |
|
1840 |
! |
|
1841 |
||
1842 |
selectConditionBlock:aBlock |
|
1843 |
"set the conditionBlock; this block is evaluated before a selection |
|
1844 |
change is performed; the change will not be done, if the evaluation |
|
1845 |
returns false. For example, this allows confirmation queries in |
|
1846 |
the SystemBrowser" |
|
1847 |
||
1848 |
selectConditionBlock := aBlock |
|
1849 |
! |
|
1850 |
||
1851 |
useIndex:aBoolean |
|
1852 |
"set/clear the useIndex flag. If set, both actionBlock and change-messages |
|
1853 |
are passed the index(indices) of the selection as argument. |
|
1854 |
If clear, the value(s) (i.e. the selected string) is passed. |
|
1855 |
Default is true." |
|
1856 |
||
1857 |
useIndex := aBoolean |
|
1858 |
! |
|
1859 |
||
1860 |
keyActionStyle:aSymbol |
|
1861 |
"defines how the view should respond to alpha-keys pressed. |
|
1862 |
Possible values are: |
|
1863 |
#select -> will select next entry starting with that |
|
1864 |
character and perform the click-action |
|
1865 |
||
1866 |
#selectAndDoubleclick -> will select next & perform double-click action |
|
1867 |
||
1868 |
#pass -> will pass key to superclass (i.e. no special treatment) |
|
1869 |
||
1870 |
nil -> will ignore key |
|
1871 |
||
1872 |
the default (set in #initialize) is #select |
|
1873 |
" |
|
1874 |
||
1875 |
keyActionStyle := aSymbol |
|
1876 |
! |
|
1877 |
||
1878 |
returnKeyActionStyle:aSymbol |
|
1879 |
"defines how the view should respond to a return key pressed. |
|
1880 |
Possible values are: |
|
1881 |
#doubleClick -> perform double-click action |
|
1882 |
||
1883 |
#pass -> will pass key to superclass (i.e. no special treatment) |
|
1884 |
||
1885 |
nil -> will ignore key |
|
1886 |
||
1887 |
the default (set in #initialize) is #doubleClick |
|
1888 |
" |
|
1889 |
||
1890 |
returnKeyActionStyle := aSymbol |
|
1891 |
! ! |
|
1892 |
||
1893 |
!SelectionInListView methodsFor:'accessing-attributes'! |
|
1894 |
||
1895 |
line:lineNr hasAttribute:aSymbol |
|
1896 |
"return true, if line nr has attribute, aSymbol; |
|
1897 |
currently supported attributes are: |
|
1898 |
#halfIntensity |
|
1899 |
#disabled |
|
1900 |
#bold |
|
1901 |
" |
|
1902 |
||
1903 |
|attr| |
|
1904 |
||
1905 |
listAttributes isNil ifTrue:[^ false]. |
|
1906 |
(lineNr > listAttributes size) ifTrue:[^ false]. |
|
1907 |
attr := listAttributes at:lineNr. |
|
1908 |
attr isNil ifTrue:[^ false]. |
|
1909 |
attr isSymbol ifTrue:[^ attr == aSymbol]. |
|
1910 |
^ (attr includes:aSymbol) |
|
1911 |
! |
|
1912 |
||
1913 |
setAttributes:aList |
|
1914 |
"set the attribute list. |
|
1915 |
No redraw is done - the caller should make sure to redraw afterwards |
|
1916 |
(or use this only before the view is visible)." |
|
1917 |
||
1918 |
listAttributes := aList |
|
1919 |
! |
|
1920 |
||
1921 |
attributeAt:index put:aSymbolOrCollectionOfSymbolsOrNil |
|
1922 |
"set a lines attribute(s); |
|
1923 |
currently supported are: |
|
1924 |
#halfIntensity |
|
1925 |
#disabled |
|
1926 |
#bold |
|
1927 |
" |
|
1928 |
||
1929 |
(index > self size) ifFalse:[ |
|
1930 |
listAttributes isNil ifTrue:[ |
|
1931 |
listAttributes := (OrderedCollection new:index) grow:index |
|
1932 |
] ifFalse:[ |
|
1933 |
(index > listAttributes size) ifTrue:[ |
|
1934 |
listAttributes grow:index |
|
1935 |
] |
|
1936 |
]. |
|
1937 |
aSymbolOrCollectionOfSymbolsOrNil = (listAttributes at:index) ifFalse:[ |
|
1938 |
listAttributes at:index put:aSymbolOrCollectionOfSymbolsOrNil. |
|
1939 |
self redrawLine:index |
|
1940 |
] |
|
1941 |
] |
|
1942 |
||
1943 |
! |
|
1944 |
||
1945 |
strikeOut:aBoolean |
|
1946 |
"turn on/off strikeOut mode" |
|
1947 |
||
1948 |
strikeOut := aBoolean. |
|
1949 |
! |
|
1950 |
||
1951 |
attributeAt:index |
|
1952 |
"return the line attribute of list line index. |
|
1953 |
currently supported are: |
|
1954 |
#halfIntensity |
|
1955 |
#disabled |
|
1956 |
#bold |
|
1957 |
" |
|
1958 |
||
1959 |
listAttributes isNil ifFalse:[ |
|
1960 |
(index > listAttributes size) ifFalse:[ |
|
1961 |
^ listAttributes at:index |
|
1962 |
] |
|
1963 |
]. |
|
1964 |
^ nil |
|
1965 |
! |
|
1966 |
||
1967 |
attributeAt:index add:aSymbolOrCollectionOfSymbols |
|
1968 |
"add to a lines attribute(s); |
|
1969 |
currently supported are: |
|
1970 |
#halfIntensity |
|
1971 |
#disabled |
|
1972 |
#bold |
|
1973 |
" |
|
1974 |
||
1975 |
|current| |
|
1976 |
||
1977 |
current := self attributeAt:index. |
|
1978 |
current isNil ifTrue:[ |
|
1979 |
current := Set new. |
|
1980 |
] ifFalse:[ |
|
1981 |
current isSymbol ifTrue:[ |
|
1982 |
current == aSymbolOrCollectionOfSymbols ifTrue:[^ self]. |
|
1983 |
current := Set with:current |
|
1984 |
] |
|
1985 |
]. |
|
1986 |
||
1987 |
aSymbolOrCollectionOfSymbols isSymbol ifTrue:[ |
|
1988 |
current := current add:aSymbolOrCollectionOfSymbols |
|
1989 |
] ifFalse:[ |
|
1990 |
(current includes:aSymbolOrCollectionOfSymbols) ifTrue:[^ self]. |
|
1991 |
current addAll:aSymbolOrCollectionOfSymbols |
|
1992 |
]. |
|
1993 |
self attributeAt:index put:current |
|
1994 |
! |
|
1995 |
||
1996 |
attributeAt:index remove:aSymbolOrCollectionOfSymbols |
|
1997 |
"remove a line attribute; |
|
1998 |
currently supported are: |
|
1999 |
#halfIntensity |
|
2000 |
#disabled |
|
2001 |
#bold |
|
2002 |
" |
|
2003 |
||
2004 |
|current| |
|
2005 |
||
2006 |
current := self attributeAt:index. |
|
2007 |
current isNil ifTrue:[^ self]. |
|
2008 |
current isSymbol ifTrue:[ |
|
2009 |
aSymbolOrCollectionOfSymbols isSymbol ifTrue:[ |
|
2010 |
current == aSymbolOrCollectionOfSymbols ifTrue:[current := nil] |
|
2011 |
] ifFalse:[ |
|
2012 |
(aSymbolOrCollectionOfSymbols includes:current) ifTrue:[ |
|
2013 |
current := nil |
|
2014 |
] |
|
2015 |
] |
|
2016 |
] ifFalse:[ |
|
2017 |
aSymbolOrCollectionOfSymbols isSymbol ifTrue:[ |
|
2018 |
current := current remove:aSymbolOrCollectionOfSymbols ifAbsent:[] |
|
2019 |
] ifFalse:[ |
|
2020 |
aSymbolOrCollectionOfSymbols removeAll:aSymbolOrCollectionOfSymbols |
|
2021 |
] |
|
2022 |
]. |
|
2023 |
self attributeAt:index put:current |
|
2024 |
! ! |
|
2025 |
||
2026 |
!SelectionInListView methodsFor:'accessing-behavior'! |
|
2027 |
||
2028 |
ignoreReselect:aBoolean |
|
2029 |
"set/clear the ignoreReselect flag - |
|
2030 |
if set, a click on an already selected entry is ignored. |
|
2031 |
Otherwise the notification is done, even if no |
|
2032 |
change in the selection occurs. |
|
2033 |
(for example, in browser to update a method)" |
|
2034 |
||
2035 |
ignoreReselect := aBoolean |
|
2036 |
! |
|
2037 |
||
2038 |
toggleSelect:aBoolean |
|
2039 |
"turn on/off toggle select. If true, clicking on a selected entry |
|
2040 |
unselects it and vice versa. The default is false." |
|
2041 |
||
2042 |
toggleSelect := aBoolean. |
|
2043 |
! |
|
2044 |
||
2045 |
multipleSelectOk:aBoolean |
|
2046 |
"allow/disallow multiple selections" |
|
2047 |
||
2048 |
multipleSelectOk := aBoolean. |
|
2049 |
aBoolean ifTrue:[ |
|
2050 |
self enableButtonMotionEvents |
|
2051 |
] ifFalse:[ |
|
2052 |
self disableButtonMotionEvents |
|
2053 |
] |
|
2054 |
! |
|
2055 |
||
2056 |
enable |
|
2057 |
"enable the view - selection changes are allowed" |
|
2058 |
||
2059 |
enabled := true |
|
2060 |
! |
|
2061 |
||
2062 |
disable |
|
2063 |
"disable the view - no selection changes are allowed" |
|
2064 |
||
2065 |
enabled := false |
|
2066 |
! ! |
|
2067 |
||
2068 |
!SelectionInListView methodsFor:'accessing-contents'! |
|
2069 |
||
2070 |
list:aCollection |
|
2071 |
"set the list - redefined, since setting the list implies unselecting |
|
2072 |
and clearing attributes." |
|
2073 |
||
2074 |
"somewhat of a kludge: if selection is first line, |
|
2075 |
we have to remove the highlight frame by hand here" |
|
2076 |
||
2077 |
(shown and:[hilightLevel ~~ 0]) ifTrue:[ |
|
2078 |
selection == firstLineShown ifTrue:[ |
|
2079 |
self paint:bgColor. |
|
2080 |
self fillRectangleX:margin y:margin |
|
2081 |
width:(width - (margin * 2)) |
|
2082 |
height:(hilightLevel abs). |
|
2083 |
]. |
|
2084 |
]. |
|
2085 |
||
2086 |
selection := nil. |
|
2087 |
listAttributes := nil. |
|
2088 |
super list:aCollection. |
|
2089 |
! |
|
2090 |
||
2091 |
setList:aCollection |
|
2092 |
"set the list - redefined, since setting the list implies unselecting |
|
2093 |
and clearing attributes. |
|
2094 |
No redraw is done - the caller should make sure to redraw afterwards |
|
2095 |
(or use this only before the view is visible)." |
|
2096 |
||
2097 |
selection := nil. |
|
2098 |
listAttributes := nil. |
|
2099 |
super setList:aCollection. |
|
2100 |
! |
|
2101 |
||
2102 |
removeIndexWithoutRedraw:lineNr |
|
2103 |
"delete line - no redraw; |
|
2104 |
return true, if something was really deleted. |
|
2105 |
Redefined since we have to care for selection" |
|
2106 |
||
2107 |
self checkRemovingSelection:lineNr. |
|
2108 |
^ super removeIndexWithoutRedraw:lineNr |
|
2109 |
! |
|
2110 |
||
2111 |
removeIndex:lineNr |
|
2112 |
"delete line - with redraw. |
|
2113 |
Redefined since we have to care for selection" |
|
2114 |
||
2115 |
self checkRemovingSelection:lineNr. |
|
2116 |
^ super removeIndex:lineNr |
|
2117 |
! |
|
2118 |
||
2119 |
add:aValue beforeIndex:index |
|
2120 |
"must recompute our current selections" |
|
2121 |
||
2122 |
selection notNil ifTrue:[ |
|
2123 |
multipleSelectOk ifTrue:[ |
|
2124 |
selection := selection collect:[ :sel | |
|
2125 |
sel >= index ifTrue:[ |
|
2126 |
sel + 1 |
|
2127 |
] ifFalse:[ |
|
2128 |
sel |
|
2129 |
] |
|
2130 |
]. |
|
2131 |
] ifFalse:[ |
|
2132 |
selection >= index ifTrue:[ |
|
2133 |
selection := selection + 1. |
|
2134 |
]. |
|
2135 |
]. |
|
2136 |
]. |
|
2137 |
^ super add:aValue beforeIndex:index. |
|
105 | 2138 |
! ! |
2139 |
||
2140 |
!SelectionInListView methodsFor:'initialization'! |
|
2141 |
||
2142 |
initCursor |
|
2143 |
"set the cursor - a hand" |
|
2144 |
||
2145 |
cursor := Cursor hand |
|
2146 |
! |
|
2147 |
||
2148 |
initialize |
|
2149 |
super initialize. |
|
2150 |
||
2151 |
fontHeight := font height + lineSpacing. |
|
2152 |
enabled := true. |
|
2153 |
ignoreReselect := true. |
|
125 | 2154 |
multipleSelectOk := toggleSelect := strikeOut := printItems := false. |
2155 |
useIndex := true. |
|
2156 |
||
105 | 2157 |
keyActionStyle := #select. |
125 | 2158 |
returnKeyActionStyle := #doubleClick. |
2159 |
||
2160 |
listMsg := self class defaultListMessage. |
|
2161 |
initialSelectionMsg := self class defaultSelectionMessage. |
|
2162 |
||
2163 |
! |
|
2164 |
||
2165 |
realize |
|
2166 |
super realize. |
|
2167 |
||
2168 |
self getListFromModel. |
|
2169 |
self getSelectionFromModel. |
|
2170 |
||
2171 |
selection notNil ifTrue:[ |
|
2172 |
self makeLineVisible:selection |
|
2173 |
]. |
|
105 | 2174 |
! |
2175 |
||
2176 |
initStyle |
|
2177 |
|nm| |
|
2178 |
||
2179 |
super initStyle. |
|
2180 |
||
2181 |
DefaultFont notNil ifTrue:[ |
|
2182 |
font := DefaultFont on:device |
|
2183 |
]. |
|
2184 |
||
2185 |
bgColor := viewBackground. |
|
2186 |
hilightFrameColor := nil. |
|
2187 |
hilightLevel := 0. |
|
2188 |
arrowLevel := 1. |
|
2189 |
smallArrow := false. |
|
2190 |
||
2191 |
device hasGreyscales ifTrue:[ |
|
2192 |
" |
|
2193 |
must get rid of these hard codings |
|
2194 |
" |
|
2195 |
nm := StyleSheet name asSymbol. |
|
2196 |
(nm == #next) ifTrue:[ |
|
2197 |
hilightFgColor := fgColor. |
|
2198 |
hilightBgColor := White. |
|
2199 |
hilightFrameColor := fgColor |
|
2200 |
] ifFalse:[ |
|
2201 |
(nm == #motif) ifTrue:[ |
|
2202 |
fgColor := White. |
|
2203 |
bgColor := Grey. |
|
2204 |
viewBackground := bgColor. |
|
2205 |
hilightFgColor := bgColor "fgColor" "White". |
|
2206 |
hilightBgColor := fgColor "bgColor lightened" "darkened". |
|
2207 |
] ifFalse:[ |
|
2208 |
(nm == #openwin) ifTrue:[ |
|
2209 |
hilightFgColor := fgColor. |
|
2210 |
hilightBgColor := Color grey. |
|
2211 |
smallArrow := true. |
|
2212 |
] |
|
2213 |
] |
|
2214 |
] |
|
2215 |
]. |
|
2216 |
||
2217 |
hilightFgColor isNil ifTrue:[ |
|
2218 |
hilightFgColor := bgColor. |
|
2219 |
]. |
|
2220 |
hilightBgColor isNil ifTrue:[ |
|
2221 |
hilightBgColor := fgColor. |
|
2222 |
]. |
|
2223 |
DefaultForegroundColor notNil ifTrue:[ |
|
2224 |
fgColor := DefaultForegroundColor |
|
2225 |
]. |
|
2226 |
DefaultBackgroundColor notNil ifTrue:[ |
|
2227 |
bgColor := viewBackground := DefaultBackgroundColor |
|
2228 |
]. |
|
2229 |
DefaultHilightForegroundColor notNil ifTrue:[ |
|
2230 |
hilightFgColor := DefaultHilightForegroundColor |
|
2231 |
]. |
|
2232 |
DefaultHilightBackgroundColor notNil ifTrue:[ |
|
2233 |
hilightBgColor := DefaultHilightBackgroundColor |
|
2234 |
]. |
|
2235 |
DefaultHilightFrameColor notNil ifTrue:[ |
|
2236 |
hilightFrameColor := DefaultHilightFrameColor |
|
2237 |
]. |
|
2238 |
DefaultHilightLevel notNil ifTrue:[ |
|
2239 |
hilightLevel := DefaultHilightLevel |
|
2240 |
]. |
|
2241 |
DefaultRightArrowLevel notNil ifTrue:[ |
|
2242 |
arrowLevel := DefaultRightArrowLevel |
|
2243 |
]. |
|
2244 |
||
2245 |
DefaultShadowColor notNil ifTrue:[ |
|
2246 |
shadowColor := DefaultShadowColor on:device |
|
2247 |
]. |
|
2248 |
DefaultLightColor notNil ifTrue:[ |
|
2249 |
lightColor := DefaultLightColor on:device |
|
2250 |
]. |
|
2251 |
||
2252 |
(hilightLevel abs > 0) ifTrue:[ |
|
2253 |
lineSpacing := 3 |
|
2254 |
] ifFalse:[ |
|
2255 |
lineSpacing := 2 |
|
2256 |
]. |
|
2257 |
||
2258 |
hilightFgColor isNil ifTrue:[ |
|
2259 |
hilightFgColor := bgColor. |
|
2260 |
hilightBgColor := fgColor |
|
2261 |
]. |
|
2262 |
||
2263 |
DefaultDisabledForegroundColor notNil ifTrue:[ |
|
2264 |
halfIntensityFgColor := DefaultDisabledForegroundColor |
|
2265 |
] ifFalse:[ |
|
2266 |
halfIntensityFgColor := Color darkGrey. |
|
2267 |
]. |
|
2268 |
||
2269 |
fgColor := fgColor on:device. |
|
2270 |
bgColor := bgColor on:device. |
|
2271 |
halfIntensityFgColor := halfIntensityFgColor on:device. |
|
2272 |
hilightFrameColor notNil ifTrue:[hilightFrameColor := hilightFrameColor on:device]. |
|
2273 |
hilightFgColor := hilightFgColor on:device. |
|
2274 |
hilightBgColor := hilightBgColor on:device. |
|
0 | 2275 |
! ! |
2276 |
||
125 | 2277 |
!SelectionInListView methodsFor:'change & update'! |
0 | 2278 |
|
105 | 2279 |
update:something with:aParameter from:changedObject |
2280 |
changedObject == model ifTrue:[ |
|
125 | 2281 |
something == aspectMsg ifTrue:[ |
2282 |
self getListFromModel. |
|
2283 |
self getSelectionFromModel. |
|
2284 |
^ self |
|
2285 |
]. |
|
2286 |
something == listMsg ifTrue:[ |
|
2287 |
self getListFromModel. |
|
2288 |
^ self |
|
2289 |
]. |
|
2290 |
something == initialSelectionMsg ifTrue:[ |
|
2291 |
self getSelectionFromModel. |
|
2292 |
^ self |
|
2293 |
]. |
|
2294 |
something == #empty ifTrue:[ |
|
2295 |
self list:nil. |
|
2296 |
^ self |
|
2297 |
]. |
|
105 | 2298 |
]. |
2299 |
^ super update:something with:aParameter from:changedObject |
|
125 | 2300 |
! ! |
2301 |
||
2302 |
!SelectionInListView methodsFor:'accessing-selection'! |
|
2303 |
||
2304 |
addToSelection:aNumber |
|
2305 |
"add entry, aNumber to the selection. No scrolling is done." |
|
2306 |
||
2307 |
(self isValidSelection:aNumber) ifFalse:[^ self]. |
|
2308 |
||
2309 |
selection isNil ifTrue:[^ self selectWithoutScroll:aNumber]. |
|
2310 |
selection isCollection ifTrue:[ |
|
2311 |
(selection includes:aNumber) ifTrue:[^ self]. |
|
2312 |
(selectConditionBlock notNil |
|
2313 |
and:[(selectConditionBlock value:aNumber) not]) ifTrue:[^ self]. |
|
2314 |
selection add:aNumber |
|
2315 |
] ifFalse:[ |
|
2316 |
(aNumber == selection) ifTrue:[^ self]. |
|
2317 |
(selectConditionBlock notNil |
|
2318 |
and:[(selectConditionBlock value:aNumber) not]) ifTrue:[^ self]. |
|
2319 |
selection := OrderedCollection with:selection with:aNumber |
|
63 | 2320 |
]. |
125 | 2321 |
self redrawElement:aNumber |
2322 |
! |
|
2323 |
||
2324 |
addElementToSelection:anObject |
|
2325 |
"add the element with the same printstring as the argument, anObject |
|
2326 |
to the selection. The entry is searched by comparing printStrings. |
|
2327 |
No scrolling is done. Returns true, if ok, false if no such entry |
|
2328 |
was found." |
|
2329 |
||
2330 |
|lineNo str| |
|
2331 |
||
2332 |
str := anObject printString. |
|
2333 |
lineNo := list findFirst:[:entry | str = entry printString]. |
|
2334 |
lineNo ~~ 0 ifTrue:[ |
|
2335 |
self addToSelection:lineNo. |
|
2336 |
^ true |
|
0 | 2337 |
]. |
125 | 2338 |
^ false |
2339 |
! |
|
2340 |
||
2341 |
removeFromSelection:aNumber |
|
2342 |
"remove entry, aNumber from the selection." |
|
2343 |
||
2344 |
selection isNil ifTrue:[^ self]. |
|
0 | 2345 |
|
2346 |
multipleSelectOk ifTrue:[ |
|
125 | 2347 |
(selection includes:aNumber) ifFalse:[^ self]. |
2348 |
selection remove:aNumber. |
|
2349 |
selection size == 0 ifTrue:[ |
|
2350 |
selection := nil |
|
59 | 2351 |
] |
0 | 2352 |
] ifFalse:[ |
125 | 2353 |
(aNumber == selection) ifFalse:[^ self]. |
2354 |
selection := nil |
|
0 | 2355 |
]. |
125 | 2356 |
self redrawElement:aNumber |
0 | 2357 |
! ! |
125 | 2358 |
|
2359 |
!SelectionInListView methodsFor:'accessing-mvc'! |
|
2360 |
||
2361 |
on:aModel printItems:print oneItem:one aspect:aspectSymbol change:changeSymbol |
|
2362 |
list:listSymbol menu:menuSymbol initialSelection:initialSymbol useIndex:use |
|
2363 |
||
2364 |
"ST-80 compatibility" |
|
2365 |
||
2366 |
aspectMsg := aspectSymbol. |
|
2367 |
changeMsg := changeSymbol. |
|
2368 |
listMsg := listSymbol. |
|
2369 |
menuMsg := menuSymbol. |
|
2370 |
initialSelectionMsg := initialSymbol. |
|
2371 |
printItems := print. |
|
2372 |
oneItem := one. |
|
2373 |
useIndex := use. |
|
2374 |
ignoreReselect := false. "/ ST80 behavior |
|
2375 |
self model:aModel. |
|
2376 |
! |
|
2377 |
||
2378 |
doubleClickMessage |
|
2379 |
"return the symbol with which the model (if any) is informed about |
|
2380 |
double-click. If nil (which is the default), it is not informed." |
|
2381 |
||
2382 |
^ doubleClickMsg |
|
2383 |
! |
|
2384 |
||
2385 |
doubleClickMessage:aSymbol |
|
2386 |
"set the symbol with which the model (if any) is informed about double-click. |
|
2387 |
If nil (which is the default), it is not informed." |
|
2388 |
||
2389 |
doubleClickMsg := aSymbol |
|
2390 |
! |
|
2391 |
||
2392 |
doubleClick:aSymbol |
|
2393 |
"set the symbol with which the model is informed about double-click. |
|
2394 |
OBSOLETE: please use #doubleClickMessage:" |
|
2395 |
||
2396 |
self obsoleteMethodWarning:'please use #doubleClickMessage:'. |
|
2397 |
doubleClickMsg := aSymbol |
|
2398 |
! |
|
2399 |
||
2400 |
initialSelectionMessage |
|
2401 |
"return the symbol by which the model informes me about a changed |
|
2402 |
selectionIndex. This is used both in change notification and to |
|
2403 |
actually aquire a new selection value." |
|
2404 |
||
2405 |
^ initialSelectionMsg |
|
2406 |
! |
|
2407 |
||
2408 |
initialSelectionMessage:aSymbol |
|
2409 |
"set the symbol by which the model informes me about a changed |
|
2410 |
selectionIndex. This is used both in change notification and to |
|
2411 |
actually aquire a new selection value." |
|
2412 |
||
2413 |
initialSelectionMsg := aSymbol |
|
2414 |
! |
|
2415 |
||
2416 |
addModelInterfaceTo:aDictionary |
|
2417 |
"see comment in View>>modelInterface" |
|
2418 |
||
2419 |
super addModelInterfaceTo:aDictionary. |
|
2420 |
aDictionary at:#doubleClickMessage put:doubleClickMsg. |
|
2421 |
aDictionary at:#initialSelectionMessage put:initialSelectionMsg. |
|
2422 |
||
2423 |
" |
|
2424 |
SelectionInListView new modelInterface |
|
2425 |
" |
|
2426 |
! ! |
|
2427 |