0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ListView subclass:#SelectionInListView
|
|
14 |
instanceVariableNames:'selection actionBlock enabled
|
|
15 |
hilightFgColor hilightBgColor
|
|
16 |
halfIntensityFgColor
|
|
17 |
doubleClickActionBlock
|
3
|
18 |
selectConditionBlock
|
0
|
19 |
listAttributes multipleSelectOk clickLine
|
7
|
20 |
listSymbol initialSelectionSymbol printItems oneItem
|
|
21 |
hilightLevel hilightFrameColor ignoreReselect'
|
22
|
22 |
classVariableNames: 'RightArrowShadowForm RightArrowLightForm RightArrowForm'
|
0
|
23 |
poolDictionaries:''
|
|
24 |
category:'Views-Text'
|
|
25 |
!
|
|
26 |
|
|
27 |
SelectionInListView comment:'
|
|
28 |
|
5
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
30 |
All Rights Reserved
|
7
|
31 |
'!
|
0
|
32 |
|
7
|
33 |
!SelectionInListView class methodsFor:'documentation'!
|
|
34 |
|
|
35 |
documentation
|
|
36 |
"
|
0
|
37 |
this one is a ListView with a selected line (which is shown highlighted)
|
|
38 |
If multipleSelectionsOk is true, it is also allowed to shift-click multiple entries.
|
|
39 |
|
24
|
40 |
$Header: /cvs/stx/stx/libwidg/SelectionInListView.st,v 1.7 1994-01-13 00:18:21 claus Exp $
|
0
|
41 |
|
|
42 |
written spring/summer 89 by claus
|
|
43 |
3D Jan 90 by claus
|
|
44 |
multiselect Jun 92 my claus
|
7
|
45 |
"
|
|
46 |
! !
|
0
|
47 |
|
22
|
48 |
!SelectionInListView class methodsFor:'defaults'!
|
|
49 |
|
|
50 |
rightArrowLightFormOn:aDevice
|
|
51 |
"return the form used for the right arrow light pixels (3D only)"
|
|
52 |
|
|
53 |
|f|
|
|
54 |
|
|
55 |
((aDevice == Display) and:[RightArrowLightForm notNil]) ifTrue:[
|
|
56 |
^ RightArrowLightForm
|
|
57 |
].
|
|
58 |
f := Form fromFile:'RightArrowLight.xbm' resolution:100 on:aDevice.
|
|
59 |
f isNil ifTrue:[
|
|
60 |
f := Form width:16 height:16 fromArray:#(2r00000000 2r00000000
|
|
61 |
2r00000000 2r00000000
|
|
62 |
2r00000000 2r00000000
|
|
63 |
2r00000110 2r00000000
|
|
64 |
2r00000101 2r00000000
|
|
65 |
2r00000100 2r10000000
|
|
66 |
2r00000100 2r01000000
|
|
67 |
2r00000100 2r00100000
|
|
68 |
2r00000100 2r00000000
|
|
69 |
2r00000100 2r00000000
|
|
70 |
2r00000100 2r00000000
|
|
71 |
2r00000100 2r00000000
|
|
72 |
2r00000100 2r00000000
|
|
73 |
2r00000100 2r00000000
|
|
74 |
2r00000000 2r00000000
|
|
75 |
2r00000000 2r00000000)
|
|
76 |
on:aDevice
|
|
77 |
].
|
|
78 |
(aDevice == Display) ifTrue:[
|
|
79 |
RightArrowLightForm := f
|
|
80 |
].
|
|
81 |
^ f
|
|
82 |
!
|
|
83 |
|
|
84 |
rightArrowShadowFormOn:aDevice
|
|
85 |
"return the form used for the right arrow light pixels (3D only)"
|
|
86 |
|
|
87 |
|f|
|
|
88 |
|
|
89 |
((aDevice == Display) and:[RightArrowShadowForm notNil]) ifTrue:[
|
|
90 |
^ RightArrowShadowForm
|
|
91 |
].
|
|
92 |
f := Form fromFile:'RightArrowShadow.xbm' resolution:100 on:aDevice.
|
|
93 |
f isNil ifTrue:[
|
|
94 |
f := Form width:16 height:16 fromArray:#(2r00000000 2r00000000
|
|
95 |
2r00000000 2r00000000
|
|
96 |
2r00000000 2r00000000
|
|
97 |
2r00000000 2r00000000
|
|
98 |
2r00000000 2r00000000
|
|
99 |
2r00000000 2r00000000
|
|
100 |
2r00000000 2r00000000
|
|
101 |
2r00000000 2r00000000
|
|
102 |
2r00000000 2r00010000
|
|
103 |
2r00000000 2r00100000
|
|
104 |
2r00000000 2r01000000
|
|
105 |
2r00000000 2r10000000
|
|
106 |
2r00000001 2r00000000
|
|
107 |
2r00000010 2r00000000
|
|
108 |
2r00000000 2r00000000
|
|
109 |
2r00000000 2r00000000)
|
|
110 |
on:aDevice
|
|
111 |
].
|
|
112 |
(aDevice == Display) ifTrue:[
|
|
113 |
RightArrowShadowForm := f
|
|
114 |
].
|
|
115 |
^ f
|
|
116 |
!
|
|
117 |
|
|
118 |
rightArrowFormOn:aDevice
|
|
119 |
"return the form used for the right arrow (non 3D)"
|
|
120 |
|
|
121 |
|f|
|
|
122 |
|
|
123 |
((aDevice == Display) and:[RightArrowForm notNil]) ifTrue:[
|
|
124 |
^ RightArrowForm
|
|
125 |
].
|
|
126 |
f := Form fromFile:'RightArrow.xbm' resolution:100 on:aDevice.
|
|
127 |
f isNil ifTrue:[
|
|
128 |
f := Form width:16 height:16 fromArray:#(2r00000000 2r00000000
|
|
129 |
2r00000000 2r00000000
|
|
130 |
2r00000000 2r00000000
|
|
131 |
2r00000110 2r00000000
|
|
132 |
2r00000101 2r00000000
|
|
133 |
2r00000100 2r10000000
|
|
134 |
2r00000100 2r01000000
|
|
135 |
2r00000100 2r00100000
|
|
136 |
2r00000100 2r00010000
|
|
137 |
2r00000100 2r00100000
|
|
138 |
2r00000100 2r01000000
|
|
139 |
2r00000100 2r10000000
|
|
140 |
2r00000101 2r00000000
|
|
141 |
2r00000110 2r00000000
|
|
142 |
2r00000000 2r00000000
|
|
143 |
2r00000000 2r00000000)
|
|
144 |
on:aDevice
|
|
145 |
].
|
|
146 |
(aDevice == Display) ifTrue:[
|
|
147 |
RightArrowForm := f
|
|
148 |
].
|
|
149 |
^ f
|
|
150 |
! !
|
|
151 |
|
0
|
152 |
!SelectionInListView class methodsFor:'instance creation'!
|
|
153 |
|
|
154 |
on:aModel printItems:print oneItem:one aspect:aspect
|
|
155 |
change:change list:list menu:menu
|
|
156 |
initialSelection:initial
|
|
157 |
|
|
158 |
"for ST-80 compatibility"
|
|
159 |
|
|
160 |
^ (self new) on:aModel printItems:print oneItem:one aspect:aspect
|
|
161 |
change:change list:list menu:menu
|
|
162 |
initialSelection:initial
|
|
163 |
! !
|
|
164 |
|
|
165 |
!SelectionInListView methodsFor:'initialization'!
|
|
166 |
|
|
167 |
initialize
|
|
168 |
super initialize.
|
|
169 |
|
|
170 |
fontHeight := font height + lineSpacing.
|
|
171 |
multipleSelectOk := false.
|
7
|
172 |
enabled := true.
|
|
173 |
ignoreReselect := true.
|
0
|
174 |
!
|
|
175 |
|
|
176 |
initStyle
|
|
177 |
super initStyle.
|
|
178 |
|
|
179 |
bgColor := viewBackground.
|
7
|
180 |
hilightFrameColor := nil.
|
|
181 |
hilightLevel := 0.
|
0
|
182 |
(style == #openwin) ifTrue:[
|
|
183 |
lineSpacing := 3
|
|
184 |
] ifFalse:[
|
|
185 |
lineSpacing := 2
|
|
186 |
].
|
|
187 |
|
|
188 |
(style == #next) ifTrue:[
|
|
189 |
device hasGreyscales ifTrue:[
|
|
190 |
hilightFgColor := fgColor.
|
7
|
191 |
hilightBgColor := White.
|
|
192 |
hilightFrameColor := fgColor
|
0
|
193 |
] ifFalse:[
|
|
194 |
hilightFgColor := White.
|
|
195 |
hilightBgColor := Black
|
|
196 |
]
|
|
197 |
] ifFalse:[
|
7
|
198 |
(style == #motif) ifTrue:[
|
0
|
199 |
device hasGreyscales ifTrue:[
|
|
200 |
hilightFgColor := fgColor.
|
7
|
201 |
hilightBgColor := bgColor.
|
|
202 |
hilightLevel := 2.
|
0
|
203 |
] ifFalse:[
|
|
204 |
hilightFgColor := White.
|
|
205 |
hilightBgColor := Black
|
|
206 |
]
|
|
207 |
] ifFalse:[
|
7
|
208 |
(style == #openwin) ifTrue:[
|
0
|
209 |
device hasGreyscales ifTrue:[
|
7
|
210 |
hilightFgColor := fgColor.
|
|
211 |
hilightBgColor := Color grey.
|
|
212 |
hilightLevel := -1.
|
0
|
213 |
] ifFalse:[
|
|
214 |
hilightFgColor := White.
|
|
215 |
hilightBgColor := Black
|
|
216 |
]
|
|
217 |
] ifFalse:[
|
7
|
218 |
(style == #iris) ifTrue:[
|
|
219 |
device hasGreyscales ifTrue:[
|
|
220 |
hilightFgColor := bgColor.
|
|
221 |
hilightBgColor := Black
|
0
|
222 |
] ifFalse:[
|
7
|
223 |
hilightFgColor := White.
|
0
|
224 |
hilightBgColor := Black
|
|
225 |
]
|
7
|
226 |
] ifFalse:[
|
|
227 |
self is3D ifTrue:[
|
|
228 |
device hasColors ifTrue:[
|
|
229 |
hilightFgColor := Color name:'yellow'
|
|
230 |
] ifFalse:[
|
|
231 |
hilightFgColor := White
|
|
232 |
].
|
|
233 |
device hasGreyscales ifTrue:[
|
|
234 |
hilightBgColor := viewBackground
|
|
235 |
] ifFalse:[
|
|
236 |
hilightBgColor := Black
|
|
237 |
]
|
|
238 |
]
|
0
|
239 |
]
|
|
240 |
]
|
|
241 |
]
|
|
242 |
].
|
|
243 |
|
|
244 |
hilightFgColor isNil ifTrue:[
|
|
245 |
hilightFgColor := bgColor.
|
|
246 |
hilightBgColor := fgColor
|
|
247 |
].
|
|
248 |
|
|
249 |
halfIntensityFgColor := Color darkGrey.
|
|
250 |
!
|
|
251 |
|
|
252 |
initCursor
|
|
253 |
"set the cursor - a hand"
|
|
254 |
|
|
255 |
cursor := Cursor hand
|
|
256 |
!
|
|
257 |
|
|
258 |
initEvents
|
|
259 |
super initEvents.
|
|
260 |
self enableButtonEvents
|
|
261 |
!
|
|
262 |
|
|
263 |
realize
|
|
264 |
super realize.
|
|
265 |
selection notNil ifTrue:[
|
|
266 |
self makeLineVisible:selection
|
|
267 |
]
|
|
268 |
! !
|
|
269 |
|
|
270 |
!SelectionInListView methodsFor:'accessing'!
|
|
271 |
|
|
272 |
multipleSelectOk:aBoolean
|
|
273 |
"allow/disallow multiple selections"
|
|
274 |
|
|
275 |
multipleSelectOk := aBoolean.
|
|
276 |
aBoolean ifTrue:[
|
|
277 |
self enableButtonMotionEvents
|
|
278 |
] ifFalse:[
|
|
279 |
self disableButtonMotionEvents
|
|
280 |
]
|
|
281 |
!
|
|
282 |
|
7
|
283 |
ignoreReselect:aBoolean
|
|
284 |
"set/clear the ignoreReselect flag - if set,
|
|
285 |
a click on an already selected entry is ignored.
|
|
286 |
Otherwise the notification is done, even if no
|
|
287 |
change in the selection occurs."
|
|
288 |
|
|
289 |
ignoreReselect := aBoolean
|
|
290 |
!
|
|
291 |
|
0
|
292 |
setList:aCollection
|
|
293 |
"set the list - redefined, since setting the list implies unselecting"
|
|
294 |
|
|
295 |
selection := nil.
|
|
296 |
super setList:aCollection
|
|
297 |
!
|
|
298 |
|
|
299 |
list:aCollection
|
|
300 |
"set the list - redefined, since setting the list implies unselecting"
|
|
301 |
|
7
|
302 |
"somewhat of a kludge: if selection is first line,
|
|
303 |
we have to remove the highlight frame by hand here"
|
|
304 |
|
|
305 |
(shown and:[hilightLevel ~~ 0]) ifTrue:[
|
|
306 |
selection == firstLineShown ifTrue:[
|
|
307 |
self paint:bgColor.
|
|
308 |
self fillRectangleX:margin y:margin
|
|
309 |
width:(width - (margin * 2))
|
|
310 |
height:(hilightLevel abs).
|
|
311 |
].
|
|
312 |
].
|
|
313 |
|
0
|
314 |
selection := nil.
|
|
315 |
super list:aCollection
|
|
316 |
!
|
|
317 |
|
|
318 |
attributes:aList
|
|
319 |
"set the attribute list"
|
|
320 |
|
|
321 |
listAttributes := attributes
|
|
322 |
!
|
|
323 |
|
|
324 |
attributeAt:index
|
|
325 |
"return the line attribute of list line index"
|
|
326 |
|
|
327 |
listAttributes isNil ifFalse:[
|
|
328 |
(index > listAttributes size) ifFalse:[
|
|
329 |
^ listAttributes at:index
|
|
330 |
]
|
|
331 |
].
|
|
332 |
^ nil
|
|
333 |
!
|
|
334 |
|
|
335 |
attributeAt:index put:aSymbol
|
|
336 |
"set a line attribute; currently attributes are:
|
|
337 |
#halfIntensity
|
|
338 |
"
|
|
339 |
|
|
340 |
(index > list size) ifFalse:[
|
|
341 |
listAttributes isNil ifTrue:[
|
|
342 |
listAttributes := VariableArray new:index
|
|
343 |
] ifFalse:[
|
|
344 |
(index > listAttributes size) ifTrue:[
|
|
345 |
listAttributes grow:index
|
|
346 |
]
|
|
347 |
].
|
|
348 |
aSymbol == (listAttributes at:index) ifFalse:[
|
|
349 |
listAttributes at:index put:aSymbol.
|
|
350 |
self redrawLine:index
|
|
351 |
]
|
|
352 |
]
|
|
353 |
!
|
|
354 |
|
7
|
355 |
removeIndexWithoutRedraw:lineNr
|
|
356 |
"delete line - no redraw;
|
|
357 |
return true, if something was really deleted.
|
|
358 |
Redefined since we have to care for selection"
|
|
359 |
|
|
360 |
self checkRemovingSelection:lineNr.
|
|
361 |
^ super removeIndexWithoutRedraw:lineNr
|
|
362 |
!
|
|
363 |
|
|
364 |
removeIndex:lineNr
|
|
365 |
"delete line - with redraw.
|
|
366 |
Redefined since we have to care for selection"
|
|
367 |
|
|
368 |
self checkRemovingSelection:lineNr.
|
|
369 |
^ super removeIndex:lineNr
|
|
370 |
!
|
|
371 |
|
0
|
372 |
action:aBlock
|
|
373 |
"set the action block to be performed on select"
|
|
374 |
|
|
375 |
actionBlock := aBlock
|
|
376 |
!
|
|
377 |
|
|
378 |
doubleClickAction:aBlock
|
|
379 |
"set the double click action block to be performed on select"
|
|
380 |
|
|
381 |
doubleClickActionBlock := aBlock
|
|
382 |
!
|
|
383 |
|
3
|
384 |
selectConditionBlock:aBlock
|
|
385 |
"set the conditionBlock; this block is evaluated before a selection
|
|
386 |
change is performed; the change will not be done, if the evaluation
|
|
387 |
returns false. For example, this allows confirmation queries in
|
|
388 |
the SystemBrowser"
|
|
389 |
|
|
390 |
selectConditionBlock := aBlock
|
|
391 |
!
|
7
|
392 |
|
|
393 |
numberOfSelections
|
|
394 |
"return the number of selected entries"
|
|
395 |
|
|
396 |
|sz|
|
|
397 |
|
|
398 |
selection isNil ifTrue:[^ 0].
|
|
399 |
sz := selection size.
|
|
400 |
sz > 0 ifTrue:[^ sz].
|
|
401 |
^ 1
|
|
402 |
!
|
|
403 |
|
0
|
404 |
selectionValue
|
7
|
405 |
"return the selection value i.e. the text in the selected line.
|
|
406 |
For multiple selections a collection containing the entries is returned."
|
0
|
407 |
|
|
408 |
selection isNil ifTrue:[^ nil].
|
7
|
409 |
(selection isKindOf:Collection) ifTrue:[
|
|
410 |
^ selection collect:[:nr | list at:nr]
|
|
411 |
].
|
0
|
412 |
^ list at:selection
|
|
413 |
!
|
|
414 |
|
|
415 |
selection
|
7
|
416 |
"return the selection line nr or collection of line numbers"
|
0
|
417 |
|
|
418 |
^ selection
|
|
419 |
!
|
|
420 |
|
|
421 |
deselect
|
|
422 |
"deselect"
|
|
423 |
|
|
424 |
self selection:nil
|
|
425 |
!
|
|
426 |
|
|
427 |
deselectWithoutRedraw
|
|
428 |
"deselect - no redraw"
|
|
429 |
|
|
430 |
selection := nil
|
|
431 |
!
|
|
432 |
|
|
433 |
enable
|
|
434 |
"enable selections"
|
|
435 |
|
|
436 |
enabled := true
|
|
437 |
!
|
|
438 |
|
|
439 |
disable
|
|
440 |
"disable selections"
|
|
441 |
|
|
442 |
enabled := false
|
|
443 |
!
|
|
444 |
|
|
445 |
selectElement:anObject
|
|
446 |
"select the element with same printString as the argument, anObject"
|
|
447 |
|
|
448 |
|lineNo|
|
|
449 |
|
|
450 |
list notNil ifTrue:[
|
|
451 |
lineNo := list indexOf:(anObject printString) ifAbsent:[^ self].
|
|
452 |
self selection:lineNo
|
|
453 |
]
|
|
454 |
!
|
|
455 |
|
|
456 |
selectWithoutScroll:aNumberOrNil
|
|
457 |
"select line, aNumber or deselect if argument is nil"
|
|
458 |
|
|
459 |
|prevSelection newSelection|
|
|
460 |
|
|
461 |
newSelection := aNumberOrNil.
|
|
462 |
newSelection notNil ifTrue:[
|
|
463 |
(self isValidSelection:newSelection) ifFalse:[
|
|
464 |
newSelection := nil
|
|
465 |
]
|
|
466 |
].
|
|
467 |
|
|
468 |
(newSelection == selection) ifTrue: [^ self].
|
|
469 |
|
|
470 |
selection notNil ifTrue: [
|
|
471 |
prevSelection := selection.
|
|
472 |
selection := nil.
|
|
473 |
(prevSelection isKindOf:Collection) ifTrue:[
|
|
474 |
prevSelection do:[:line |
|
|
475 |
self redrawElement:line
|
|
476 |
]
|
|
477 |
] ifFalse:[
|
|
478 |
self redrawElement:prevSelection
|
|
479 |
]
|
|
480 |
].
|
|
481 |
selection := newSelection.
|
|
482 |
selection notNil ifTrue:[
|
|
483 |
self redrawElement:selection
|
|
484 |
]
|
|
485 |
!
|
|
486 |
|
|
487 |
selection:aNumberOrNil
|
|
488 |
"select line, aNumber or deselect if argument is nil;
|
|
489 |
make the line visible"
|
|
490 |
|
|
491 |
self selectWithoutScroll:aNumberOrNil.
|
|
492 |
selection notNil ifTrue:[
|
|
493 |
shown ifTrue:[
|
|
494 |
self makeLineVisible:selection
|
|
495 |
]
|
|
496 |
]
|
|
497 |
!
|
|
498 |
|
7
|
499 |
addElementToSelection:anObject
|
|
500 |
"add the element with the same printstring as the argument, anObject
|
|
501 |
to the selection"
|
|
502 |
|
|
503 |
|lineNo|
|
|
504 |
lineNo := list indexOf:(anObject printString) ifAbsent:[^ self].
|
|
505 |
self addToSelection:lineNo
|
|
506 |
!
|
|
507 |
|
|
508 |
addToSelection:aNumber
|
|
509 |
"add line, aNumber to the selection"
|
|
510 |
|
|
511 |
selection isNil ifTrue:[^ self selectWithoutScroll:aNumber].
|
|
512 |
|
|
513 |
(self isValidSelection:aNumber) ifFalse:[^ self].
|
|
514 |
(selection isKindOf:Collection) ifTrue:[
|
|
515 |
(selection includes:aNumber) ifTrue:[^ self].
|
|
516 |
selection add:aNumber
|
|
517 |
] ifFalse:[
|
|
518 |
(aNumber == selection) ifTrue:[^ self].
|
|
519 |
selection := OrderedCollection with:selection with:aNumber
|
|
520 |
].
|
|
521 |
self redrawElement:aNumber
|
|
522 |
!
|
|
523 |
|
0
|
524 |
selectNext
|
|
525 |
"select next line or first if there is currrently no selection"
|
|
526 |
|
|
527 |
selection isNil ifTrue:[
|
|
528 |
self selection:1
|
|
529 |
] ifFalse:[
|
|
530 |
self selection:(selection + 1).
|
|
531 |
selection isNil ifTrue:[
|
|
532 |
self selection:1
|
|
533 |
]
|
|
534 |
]
|
|
535 |
!
|
|
536 |
|
|
537 |
selectPrevious
|
|
538 |
"select previous line or last if there is currently no selection"
|
|
539 |
|
|
540 |
selection isNil ifTrue:[
|
|
541 |
self selection:(list size)
|
|
542 |
] ifFalse:[
|
|
543 |
self selection:(selection - 1).
|
|
544 |
selection isNil ifTrue:[
|
|
545 |
self selection:(list size)
|
|
546 |
]
|
|
547 |
]
|
|
548 |
!
|
|
549 |
|
|
550 |
on:aModel printItems:print oneItem:one aspect:aspect
|
|
551 |
change:change list:list menu:menu
|
|
552 |
initialSelection:initial
|
|
553 |
|
|
554 |
"ST-80 compatibility"
|
|
555 |
|
|
556 |
aspectSymbol := aspect.
|
|
557 |
changeSymbol := change.
|
|
558 |
listSymbol := list.
|
|
559 |
menuSymbol := menu.
|
|
560 |
initialSelectionSymbol := initial.
|
|
561 |
printItems := print.
|
|
562 |
oneItem := one.
|
|
563 |
|
|
564 |
model := aModel.
|
|
565 |
|
|
566 |
listSymbol notNil ifTrue:[
|
|
567 |
self list:(aModel perform:listSymbol) asText
|
|
568 |
].
|
|
569 |
model addDependent:self
|
|
570 |
! !
|
|
571 |
|
|
572 |
!SelectionInListView methodsFor:'private'!
|
|
573 |
|
7
|
574 |
checkRemovingSelection:lineNr
|
|
575 |
"when a line is removed, we have to adjust selection"
|
|
576 |
|
|
577 |
|newSelection|
|
|
578 |
|
|
579 |
selection notNil ifTrue:[
|
|
580 |
(selection isKindOf:Collection) ifTrue:[
|
|
581 |
newSelection := OrderedCollection new.
|
|
582 |
selection do:[:sel |
|
|
583 |
sel < lineNr ifTrue:[
|
|
584 |
newSelection add:sel
|
|
585 |
] ifFalse:[
|
|
586 |
sel > lineNr ifTrue:[
|
|
587 |
newSelection add:(sel - 1)
|
|
588 |
]
|
|
589 |
]
|
|
590 |
].
|
|
591 |
newSelection size == 1 ifTrue:[
|
|
592 |
selection := newSelection first
|
|
593 |
] ifFalse:[
|
|
594 |
newSelection size == 0 ifTrue:[
|
|
595 |
selection := nil
|
|
596 |
] ifFalse:[
|
|
597 |
selection := newSelection
|
|
598 |
]
|
|
599 |
]
|
|
600 |
] ifFalse:[
|
|
601 |
selection == lineNr ifTrue:[
|
|
602 |
selection := nil
|
|
603 |
] ifFalse:[
|
|
604 |
selection > lineNr ifTrue:[
|
|
605 |
selection := selection - 1
|
|
606 |
]
|
|
607 |
]
|
|
608 |
]
|
|
609 |
]
|
|
610 |
!
|
|
611 |
|
0
|
612 |
isValidSelection:aNumber
|
7
|
613 |
"return true, if aNumber is ok for a selection lineNo"
|
0
|
614 |
|
|
615 |
aNumber isNil ifTrue:[^ false].
|
|
616 |
^ (aNumber between:1 and:list size)
|
|
617 |
!
|
|
618 |
|
|
619 |
isInSelection:aNumber
|
|
620 |
"return true, if line, aNumber is in the selection"
|
|
621 |
|
|
622 |
selection isNil ifTrue:[^ false].
|
|
623 |
(selection isKindOf:Collection) ifTrue:[
|
|
624 |
^ (selection includes:aNumber)
|
|
625 |
].
|
|
626 |
^ (aNumber == selection)
|
|
627 |
!
|
|
628 |
|
|
629 |
positionToSelectionX:x y:y
|
|
630 |
"given a click position, return the selection lineNo"
|
|
631 |
|
|
632 |
|visibleLine|
|
|
633 |
|
|
634 |
(x between:0 and:width) ifTrue:[
|
|
635 |
(y between:0 and:height) ifTrue:[
|
|
636 |
visibleLine := self visibleLineOfY:y.
|
|
637 |
^ self visibleLineToListLine:visibleLine
|
|
638 |
]
|
|
639 |
].
|
|
640 |
^ nil
|
|
641 |
!
|
|
642 |
|
|
643 |
widthForScrollBetween:start and:end
|
|
644 |
"has to be redefined since WHOLE line is inverted/modified sometimes"
|
|
645 |
|
|
646 |
| anySelectionInRange |
|
|
647 |
|
|
648 |
selection notNil ifTrue:[
|
|
649 |
(selection isKindOf:Collection) ifTrue:[
|
|
650 |
anySelectionInRange := false.
|
|
651 |
selection do:[:s |
|
|
652 |
(s between:start and:end) ifTrue:[
|
|
653 |
anySelectionInRange := true
|
|
654 |
]
|
|
655 |
]
|
|
656 |
] ifFalse:[
|
|
657 |
anySelectionInRange := selection between:start and:end
|
|
658 |
]
|
|
659 |
] ifFalse:[
|
|
660 |
anySelectionInRange := false
|
|
661 |
].
|
|
662 |
|
|
663 |
anySelectionInRange ifTrue:[
|
|
664 |
self is3D ifFalse:[
|
|
665 |
^ width
|
|
666 |
].
|
|
667 |
( #(next openwin) includes:style) ifTrue:[
|
|
668 |
^ width
|
|
669 |
].
|
|
670 |
viewBackground = background ifFalse:[
|
|
671 |
^ width
|
|
672 |
]
|
|
673 |
].
|
|
674 |
^ super widthForScrollBetween:start and:end
|
|
675 |
!
|
|
676 |
|
|
677 |
visibleLineNeedsSpecialCare:visLineNr
|
|
678 |
|listLine|
|
|
679 |
|
|
680 |
listLine := self visibleLineToListLine:visLineNr.
|
|
681 |
listLine isNil ifTrue:[^ false].
|
|
682 |
(self isInSelection:listLine) ifTrue:[^ true].
|
|
683 |
listAttributes notNil ifTrue:[
|
|
684 |
(listLine <= listAttributes size) ifTrue:[
|
|
685 |
^ (listAttributes at:listLine) notNil
|
|
686 |
]
|
|
687 |
].
|
|
688 |
^ false
|
|
689 |
!
|
|
690 |
|
|
691 |
removeFromSelection:aNumber
|
|
692 |
"remove line, aNumber from the selection"
|
|
693 |
|
|
694 |
selection isNil ifTrue:[^ self].
|
|
695 |
|
|
696 |
(selection isKindOf:Collection) ifTrue:[
|
|
697 |
(selection includes:aNumber) ifFalse:[^ self].
|
|
698 |
selection remove:aNumber.
|
|
699 |
(selection size == 1) ifTrue:[
|
|
700 |
selection := selection at:1
|
|
701 |
]
|
|
702 |
] ifFalse:[
|
|
703 |
(aNumber == selection) ifFalse:[^ self].
|
|
704 |
selection := nil
|
|
705 |
].
|
|
706 |
self redrawElement:aNumber
|
|
707 |
!
|
|
708 |
|
|
709 |
scrollSelectDown
|
|
710 |
"auto scroll action; scroll and reinstall timed-block"
|
|
711 |
|
7
|
712 |
Processor addTimedBlock:autoScrollBlock after:autoScrollDeltaT.
|
0
|
713 |
self scrollDown
|
|
714 |
!
|
|
715 |
|
|
716 |
scrollSelectUp
|
|
717 |
"auto scroll action; scroll and reinstall timed-block"
|
|
718 |
|
7
|
719 |
Processor addTimedBlock:autoScrollBlock after:autoScrollDeltaT.
|
0
|
720 |
self scrollUp
|
|
721 |
! !
|
|
722 |
|
|
723 |
!SelectionInListView methodsFor:'redrawing'!
|
|
724 |
|
22
|
725 |
drawRightArrowInVisibleLine:visLineNr
|
|
726 |
"draw a right arrow (for submenus).
|
|
727 |
This method is not used here, but provided for subclasses such
|
|
728 |
as menus or file-lists."
|
|
729 |
|
|
730 |
|w h y x l form|
|
|
731 |
|
|
732 |
x := width - 16.
|
|
733 |
y := (self yOfLine:visLineNr).
|
|
734 |
|
|
735 |
device depth == 1 ifTrue:[
|
|
736 |
form := self class rightArrowFormOn:device.
|
|
737 |
y := y + ((font height - form height) // 2).
|
|
738 |
self foreground:Black.
|
24
|
739 |
self displayForm:form x:x y:y.
|
22
|
740 |
] ifFalse:[
|
|
741 |
form := self class rightArrowLightFormOn:device.
|
|
742 |
y := y + ((font height - form height) // 2).
|
|
743 |
|
|
744 |
self foreground:lightColor.
|
24
|
745 |
self displayForm:form x:x y:y.
|
22
|
746 |
|
|
747 |
self foreground:shadowColor.
|
24
|
748 |
self displayForm:(self class rightArrowShadowFormOn:device) x:x y:y.
|
22
|
749 |
]
|
|
750 |
!
|
|
751 |
|
0
|
752 |
redrawElement:aNumber
|
|
753 |
"redraw an individual element"
|
|
754 |
|
|
755 |
^ self redrawLine:aNumber
|
|
756 |
!
|
|
757 |
|
|
758 |
redrawVisibleLine:visLineNr col:colNr
|
|
759 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[
|
|
760 |
^ self redrawVisibleLine:visLineNr
|
|
761 |
].
|
|
762 |
super redrawVisibleLine:visLineNr col:colNr
|
|
763 |
!
|
|
764 |
|
|
765 |
redrawVisibleLine:visLineNr from:startCol
|
|
766 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[
|
|
767 |
^ self redrawVisibleLine:visLineNr
|
|
768 |
].
|
|
769 |
super redrawVisibleLine:visLineNr from:startCol
|
|
770 |
!
|
|
771 |
|
|
772 |
redrawVisibleLine:visLineNr from:startCol to:endCol
|
|
773 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[
|
|
774 |
^ self redrawVisibleLine:visLineNr
|
|
775 |
].
|
|
776 |
super redrawVisibleLine:visLineNr from:startCol to:endCol
|
|
777 |
!
|
|
778 |
|
|
779 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr
|
|
780 |
|special sel
|
|
781 |
selNo "{ Class: SmallInteger }" |
|
|
782 |
|
|
783 |
((selection isKindOf:Collection) or:[listAttributes notNil]) ifTrue:[
|
|
784 |
startVisLineNr to:endVisLineNr do:[:visLine |
|
|
785 |
self redrawVisibleLine:visLine
|
|
786 |
].
|
|
787 |
^ self
|
|
788 |
].
|
|
789 |
|
|
790 |
special := true.
|
|
791 |
selection isNil ifTrue:[
|
|
792 |
special := false
|
|
793 |
] ifFalse:[
|
|
794 |
sel := self listLineToVisibleLine:selection.
|
|
795 |
sel isNil ifTrue:[
|
|
796 |
special := false
|
|
797 |
] ifFalse:[
|
|
798 |
special := (sel between:startVisLineNr and:endVisLineNr)
|
|
799 |
]
|
|
800 |
].
|
|
801 |
special ifFalse:[
|
|
802 |
^ super redrawFromVisibleLine:startVisLineNr
|
|
803 |
to:endVisLineNr
|
|
804 |
].
|
|
805 |
|
|
806 |
selNo := sel.
|
|
807 |
selNo > startVisLineNr ifTrue:[
|
|
808 |
super redrawFromVisibleLine:startVisLineNr to:(selNo - 1)
|
|
809 |
].
|
|
810 |
self redrawVisibleLine:selNo.
|
|
811 |
selNo < endVisLineNr ifTrue:[
|
|
812 |
super redrawFromVisibleLine:(selNo + 1) to:endVisLineNr
|
|
813 |
]
|
|
814 |
!
|
|
815 |
|
|
816 |
redrawVisibleLine:visLineNr
|
|
817 |
|listLine fg bg
|
|
818 |
y "{ Class: SmallInteger }" |
|
|
819 |
|
|
820 |
fg := fgColor.
|
|
821 |
bg := bgColor.
|
|
822 |
listLine := self visibleLineToListLine:visLineNr.
|
|
823 |
listLine notNil ifTrue:[
|
|
824 |
(self attributeAt:listLine) == #halfIntensity ifTrue:[
|
|
825 |
fg := halfIntensityFgColor
|
|
826 |
].
|
|
827 |
(self isInSelection:listLine) ifTrue:[
|
|
828 |
bg := hilightBgColor.
|
|
829 |
fg := hilightFgColor.
|
7
|
830 |
hilightFrameColor notNil ifTrue:[
|
0
|
831 |
self drawVisibleLine:visLineNr with:fg and:bg.
|
|
832 |
y := self yOfLine:visLineNr.
|
7
|
833 |
self paint:hilightFrameColor.
|
0
|
834 |
self displayLineFromX:0 y:y toX:width y:y.
|
|
835 |
y := y + fontHeight - 1.
|
|
836 |
self displayLineFromX:0 y:y toX:width y:y.
|
|
837 |
^ self
|
|
838 |
].
|
7
|
839 |
(hilightLevel ~~ 0) ifTrue:[
|
0
|
840 |
self drawVisibleLine:visLineNr with:fg and:bg.
|
|
841 |
y := self yOfLine:visLineNr.
|
7
|
842 |
self drawEdgesForX:0 y:y
|
|
843 |
width:width height:fontHeight
|
|
844 |
level:hilightLevel.
|
0
|
845 |
^ self
|
|
846 |
]
|
|
847 |
]
|
|
848 |
].
|
|
849 |
^ self drawVisibleLine:visLineNr with:fg and:bg
|
|
850 |
! !
|
|
851 |
|
|
852 |
!SelectionInListView methodsFor:'event handling'!
|
|
853 |
|
|
854 |
sizeChanged:how
|
|
855 |
"if there is a selection, make certain, its visible
|
|
856 |
after the sizechange"
|
|
857 |
|
|
858 |
|first|
|
|
859 |
|
|
860 |
super sizeChanged:how.
|
|
861 |
shown ifTrue:[
|
|
862 |
selection notNil ifTrue:[
|
|
863 |
(selection isKindOf:Collection) ifTrue:[
|
|
864 |
first := selection first
|
|
865 |
] ifFalse:[
|
|
866 |
first := selection
|
|
867 |
].
|
|
868 |
self makeLineVisible:first
|
|
869 |
]
|
|
870 |
]
|
|
871 |
!
|
|
872 |
|
|
873 |
keyPress:key x:x y:y
|
|
874 |
"handle keyboard input"
|
|
875 |
|
|
876 |
(keyboardHandler notNil
|
|
877 |
and:[keyboardHandler canHandle:key]) ifTrue:[
|
|
878 |
keyboardHandler keyPress:key x:x y:y.
|
|
879 |
^ self
|
|
880 |
].
|
|
881 |
(selection isKindOf:Collection) ifFalse:[
|
3
|
882 |
(key == #CursorUp) ifTrue:[
|
|
883 |
(selectConditionBlock isNil or:[selectConditionBlock value]) ifTrue:[
|
0
|
884 |
self selectPrevious.
|
|
885 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
886 |
].
|
3
|
887 |
^ self
|
|
888 |
].
|
|
889 |
(key == #CursorDown) ifTrue:[
|
|
890 |
(selectConditionBlock isNil or:[selectConditionBlock value]) ifTrue:[
|
0
|
891 |
self selectNext.
|
|
892 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
893 |
].
|
3
|
894 |
^ self
|
|
895 |
].
|
|
896 |
(key == #Home) ifTrue:[
|
|
897 |
(selectConditionBlock isNil or:[selectConditionBlock value]) ifTrue:[
|
0
|
898 |
self selection:1.
|
|
899 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
900 |
].
|
3
|
901 |
^ self
|
|
902 |
].
|
|
903 |
(key == #End) ifTrue:[
|
|
904 |
(selectConditionBlock isNil or:[selectConditionBlock value]) ifTrue:[
|
0
|
905 |
self selection:list size.
|
|
906 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
907 |
].
|
3
|
908 |
^ self
|
|
909 |
].
|
|
910 |
].
|
|
911 |
^ super keyPress:key x:x y:y
|
0
|
912 |
!
|
|
913 |
|
|
914 |
buttonPress:button x:x y:y
|
7
|
915 |
|oldSelection listLineNr|
|
0
|
916 |
|
|
917 |
(button == 1) ifTrue:[
|
|
918 |
enabled ifTrue:[
|
3
|
919 |
(selectConditionBlock isNil or:[selectConditionBlock value]) ifTrue:[
|
|
920 |
oldSelection := selection.
|
|
921 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y).
|
|
922 |
listLineNr notNil ifTrue: [
|
|
923 |
self selectWithoutScroll:listLineNr
|
|
924 |
].
|
7
|
925 |
((ignoreReselect not and:[selection notNil])
|
|
926 |
or:[selection ~= oldSelection]) ifTrue:[
|
3
|
927 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
928 |
"the ST-80 way of doing things"
|
|
929 |
model notNil ifTrue:[
|
|
930 |
model perform:changeSymbol with:(self selectionValue)
|
|
931 |
]
|
|
932 |
].
|
|
933 |
clickLine := listLineNr
|
|
934 |
]
|
0
|
935 |
]
|
|
936 |
] ifFalse:[
|
|
937 |
super buttonPress:button x:x y:y
|
|
938 |
]
|
|
939 |
!
|
|
940 |
|
|
941 |
buttonShiftPress:button x:x y:y
|
|
942 |
|oldSelection listLineNr|
|
|
943 |
|
|
944 |
(button == 1) ifTrue:[
|
|
945 |
enabled ifTrue:[
|
3
|
946 |
(selectConditionBlock isNil or:[selectConditionBlock value]) ifTrue:[
|
|
947 |
oldSelection := selection copy.
|
|
948 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y).
|
|
949 |
listLineNr notNil ifTrue: [
|
|
950 |
multipleSelectOk ifTrue:[
|
|
951 |
(self isInSelection:listLineNr) ifTrue:[
|
|
952 |
self removeFromSelection:listLineNr
|
|
953 |
] ifFalse:[
|
|
954 |
self addToSelection:listLineNr
|
|
955 |
]
|
0
|
956 |
] ifFalse:[
|
3
|
957 |
self selectWithoutScroll:listLineNr
|
0
|
958 |
]
|
3
|
959 |
].
|
|
960 |
(selection ~= oldSelection) ifTrue:[
|
|
961 |
actionBlock notNil ifTrue:[actionBlock value:selection].
|
|
962 |
"the ST-80 way of doing things"
|
|
963 |
model notNil ifTrue:[model perform:changeSymbol with:(self selectionValue)]
|
|
964 |
].
|
|
965 |
clickLine := listLineNr
|
|
966 |
]
|
0
|
967 |
]
|
|
968 |
] ifFalse:[
|
|
969 |
super buttonShiftPress:button x:x y:y
|
|
970 |
]
|
|
971 |
!
|
|
972 |
|
|
973 |
buttonMultiPress:button x:x y:y
|
|
974 |
(button == 1) ifTrue:[
|
|
975 |
doubleClickActionBlock isNil ifTrue:[
|
|
976 |
self buttonPress:button x:x y:y
|
|
977 |
] ifFalse:[
|
|
978 |
doubleClickActionBlock value:selection
|
|
979 |
]
|
|
980 |
] ifFalse:[
|
|
981 |
super buttonMultiPress:button x:x y:y
|
|
982 |
]
|
|
983 |
!
|
|
984 |
|
|
985 |
buttonRelease:button x:x y:y
|
|
986 |
"stop any autoscroll"
|
|
987 |
|
|
988 |
self stopAutoScroll
|
|
989 |
!
|
|
990 |
|
|
991 |
buttonMotion:button x:x y:y
|
|
992 |
"mouse-move while button was pressed - handle selection changes"
|
|
993 |
|
|
994 |
|movedVisibleLine movedLine delta oldSelection oldSelCount|
|
|
995 |
|
|
996 |
clickLine isNil ifTrue:[^ self].
|
|
997 |
|
|
998 |
"if moved outside of view, start autoscroll"
|
|
999 |
(y < 0) ifTrue:[
|
15
|
1000 |
self compressMotionEvents:false.
|
0
|
1001 |
self startScrollUp:y.
|
|
1002 |
^ self
|
|
1003 |
].
|
|
1004 |
(y > height) ifTrue:[
|
15
|
1005 |
self compressMotionEvents:false.
|
0
|
1006 |
self startScrollDown:(y - height).
|
|
1007 |
^ self
|
|
1008 |
].
|
|
1009 |
|
|
1010 |
"move inside - stop autoscroll if any"
|
|
1011 |
self stopAutoScroll.
|
|
1012 |
|
|
1013 |
movedVisibleLine := self visibleLineOfY:y.
|
|
1014 |
movedLine := self visibleLineToAbsoluteLine:movedVisibleLine.
|
|
1015 |
(movedLine == clickLine) ifTrue:[^ self].
|
|
1016 |
|
|
1017 |
multipleSelectOk ifTrue:[
|
|
1018 |
delta := (clickLine < movedLine) ifTrue:[1] ifFalse:[-1].
|
|
1019 |
|
|
1020 |
oldSelection := selection.
|
|
1021 |
oldSelCount := selection size.
|
|
1022 |
|
|
1023 |
(clickLine+delta) to:movedLine by:delta do:[:line |
|
|
1024 |
(self isInSelection:line) ifTrue:[
|
|
1025 |
self removeFromSelection:line
|
|
1026 |
] ifFalse:[
|
|
1027 |
self addToSelection:line
|
|
1028 |
]
|
|
1029 |
].
|
|
1030 |
((selection ~= oldSelection)
|
|
1031 |
or:[selection size ~~ oldSelCount]) ifTrue:[
|
|
1032 |
actionBlock notNil ifTrue:[actionBlock value:selection]
|
|
1033 |
]
|
|
1034 |
] ifFalse:[
|
|
1035 |
self selectWithoutScroll:movedLine
|
|
1036 |
].
|
|
1037 |
|
|
1038 |
clickLine := movedLine
|
|
1039 |
!
|
|
1040 |
|
|
1041 |
update:aParameter
|
|
1042 |
|newList|
|
|
1043 |
|
|
1044 |
(aParameter == initialSelectionSymbol) ifTrue:[
|
|
1045 |
self selectElement:(model perform:initialSelectionSymbol).
|
|
1046 |
^ self
|
|
1047 |
].
|
|
1048 |
(aParameter == listSymbol) ifTrue:[
|
|
1049 |
newList := (model perform:listSymbol) asText.
|
|
1050 |
(newList = list) ifFalse:[
|
|
1051 |
self list:newList
|
|
1052 |
]
|
|
1053 |
]
|
|
1054 |
! !
|