author | ps |
Fri, 14 Jan 2000 09:13:19 +0100 | |
changeset 1649 | 60cf82a7d585 |
parent 1644 | d35b53c3d7d5 |
child 1739 | 195eefc3656f |
permissions | -rw-r--r-- |
1431 | 1 |
" |
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
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 |
||
1390 | 14 |
ListModelView subclass:#SelectionInListModelView |
15 |
instanceVariableNames:'selection multipleSelectOk actionBlock doubleClickActionBlock |
|
1641 | 16 |
selectConditionBlock clickLine highlightMode useIndex |
17 |
hilightFgColor hilightBgColor hilightLevel hilightFrameColor |
|
18 |
hilightStyle dragAccessPoint dropTarget dropSource' |
|
1390 | 19 |
classVariableNames:'DefaultHilightStyle DefaultHilightBackgroundColor |
20 |
DefaultHilightForegroundColor DefaultHilightLevel |
|
21 |
DefaultHilightFrameColor' |
|
22 |
poolDictionaries:'' |
|
1430 | 23 |
category:'Views-Lists' |
1390 | 24 |
! |
25 |
||
26 |
!SelectionInListModelView class methodsFor:'documentation'! |
|
27 |
||
1431 | 28 |
copyright |
29 |
" |
|
30 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
31 |
All Rights Reserved |
|
32 |
||
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
||
41 |
! |
|
42 |
||
1390 | 43 |
documentation |
44 |
" |
|
45 |
SelectionInListModelView is mostly like SelectionInListView, |
|
46 |
but derives from the ListModelView and thus the list is kept |
|
47 |
by the model. |
|
48 |
||
49 |
[Instance variables:] |
|
50 |
selection <misc> the current selection. nil, a number or collection of numbers |
|
51 |
multipleSelectOk <Boolean> allow/disallow multiple selections( default:false ) |
|
52 |
actionBlock <Block> action evaluated on single click |
|
53 |
doubleClickActionBlock <Block> action evaluated on double click |
|
54 |
clickPosition <Point> internal use |
|
55 |
highlightMode <Symbol> how to draw the selection |
|
56 |
useIndex <Boolean> representation of the model selection |
|
57 |
hilightFgColor <Color> |
|
58 |
hilightBgColor <Color> how highlighted items are drawn |
|
59 |
hilightLevel <Integer> level to draw selections (i.e. for 3D effect) |
|
60 |
hilightFrameColor <Color> rectangle around highlighted items |
|
61 |
hilightStyle <Boolean> actions on widget are enabled/disabled |
|
62 |
||
63 |
[author:] |
|
64 |
Claus Atzkern |
|
65 |
||
66 |
[see also:] |
|
67 |
||
68 |
ListModelView |
|
69 |
HierarchicalListView |
|
70 |
" |
|
71 |
||
72 |
||
73 |
! |
|
74 |
||
75 |
examples |
|
76 |
" |
|
77 |
[exBegin] |
|
78 |
|top list view| |
|
79 |
||
80 |
list := List new. |
|
81 |
||
82 |
1 to:100 do:[:i| list add:('element: ', i printString) ]. |
|
83 |
top := StandardSystemView new; extent:300@300. |
|
84 |
view := ScrollableView for:SelectionInListModelView miniScroller:true |
|
85 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
86 |
view list:list. |
|
87 |
top open. |
|
88 |
[exEnd] |
|
89 |
||
90 |
||
91 |
[exBegin] |
|
92 |
|top list view item| |
|
93 |
||
94 |
list := HierarchicalList new. |
|
95 |
item := HierarchicalItem::Example labeled:'Test'. |
|
96 |
item expand. |
|
97 |
list showRoot:false. |
|
98 |
list root:item. |
|
99 |
||
100 |
top := StandardSystemView new; extent:300@300. |
|
101 |
view := ScrollableView for:SelectionInListModelView miniScroller:true |
|
102 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
103 |
||
104 |
view list:list. |
|
105 |
view doubleClickAction:[:i| (list at:i) toggleExpand ]. |
|
106 |
top open. |
|
107 |
[exEnd] |
|
108 |
||
109 |
" |
|
110 |
||
111 |
! ! |
|
112 |
||
113 |
!SelectionInListModelView class methodsFor:'defaults'! |
|
114 |
||
115 |
updateStyleCache |
|
116 |
"extract values from the styleSheet and cache them in class variables" |
|
117 |
||
118 |
<resource: #style ( |
|
119 |
#'selection.hilightForegroundColor' #'selection.hilightBackgroundColor' |
|
120 |
#'selection.hilightFrameColor' #'selection.hilightLevel' |
|
121 |
#'selection.foregroundColor' #'selection.backgroundColor' |
|
122 |
#'selection.shadowColor' #'selection.lightColor' |
|
123 |
#'selection.font' #'selection.hilightStyle' |
|
124 |
#'text.foregroundColor' |
|
125 |
)> |
|
126 |
||
127 |
DefaultHilightForegroundColor := StyleSheet colorAt:'selection.hilightForegroundColor'. |
|
128 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'selection.hilightBackgroundColor'. |
|
129 |
DefaultHilightFrameColor := StyleSheet colorAt:'selection.hilightFrameColor'. |
|
130 |
DefaultHilightLevel := StyleSheet at:'selection.hilightLevel' default:0. |
|
131 |
DefaultHilightStyle := StyleSheet at:'selection.hilightStyle' default:(StyleSheet name). |
|
132 |
DefaultForegroundColor := StyleSheet colorAt:'selection.foregroundColor'. |
|
133 |
DefaultBackgroundColor := StyleSheet colorAt:'selection.backgroundColor'. |
|
134 |
DefaultShadowColor := StyleSheet colorAt:'selection.shadowColor'. |
|
135 |
DefaultLightColor := StyleSheet colorAt:'selection.lightColor'. |
|
136 |
||
137 |
DefaultForegroundColor isNil ifTrue:[ |
|
138 |
DefaultForegroundColor := StyleSheet colorAt:'text.foregroundColor' default:Black |
|
139 |
]. |
|
140 |
" |
|
141 |
self updateStyleCache |
|
142 |
" |
|
143 |
||
144 |
||
145 |
! ! |
|
146 |
||
147 |
!SelectionInListModelView methodsFor:'accessing'! |
|
148 |
||
149 |
list:aList |
|
150 |
"get the status of <showRoot> from the list |
|
151 |
" |
|
1547 | 152 |
self deselectWithoutRedraw. |
1390 | 153 |
^ super list:aList |
154 |
! ! |
|
155 |
||
1641 | 156 |
!SelectionInListModelView methodsFor:'accessing actions'! |
157 |
||
158 |
action |
|
159 |
"get the action block to be performed on select |
|
160 |
" |
|
161 |
^ actionBlock |
|
162 |
! |
|
163 |
||
164 |
action:aOneArgAction |
|
165 |
"set the action block to be performed on select |
|
166 |
" |
|
167 |
actionBlock := aOneArgAction |
|
168 |
||
169 |
||
170 |
! |
|
171 |
||
172 |
doubleClickAction |
|
173 |
"get the action block to be performed on doubleclick |
|
174 |
" |
|
175 |
^ doubleClickActionBlock |
|
176 |
||
177 |
! |
|
178 |
||
179 |
doubleClickAction:aOneArgAction |
|
180 |
"set the action block to be performed on doubleclick |
|
181 |
" |
|
182 |
doubleClickActionBlock := aOneArgAction |
|
183 |
||
184 |
! |
|
185 |
||
186 |
selectConditionBlock |
|
187 |
"set the conditionBlock; this block is evaluated before a selection |
|
188 |
change is performed; the change will not be done, if the evaluation |
|
189 |
returns false |
|
190 |
" |
|
191 |
^ selectConditionBlock |
|
192 |
||
193 |
! |
|
194 |
||
195 |
selectConditionBlock:aOneArgBlock |
|
196 |
"set the conditionBlock; this block is evaluated before a selection |
|
197 |
change is performed; the change will not be done, if the evaluation |
|
198 |
returns false |
|
199 |
" |
|
200 |
selectConditionBlock := aOneArgBlock. |
|
201 |
||
202 |
||
203 |
||
204 |
! ! |
|
205 |
||
1390 | 206 |
!SelectionInListModelView methodsFor:'accessing behavior'! |
207 |
||
208 |
highlightMode |
|
209 |
"get the mode how to draw a selected line: |
|
210 |
#line draw whole line selected |
|
211 |
#label draw label selected |
|
212 |
" |
|
213 |
^ highlightMode |
|
214 |
||
215 |
||
216 |
! |
|
217 |
||
218 |
highlightMode:aMode |
|
219 |
"set the mode how to draw a selected line: |
|
220 |
#line draw whole line selected |
|
221 |
#label draw label selected |
|
222 |
" |
|
1561 | 223 |
highlightMode := aMode. |
1390 | 224 |
! |
225 |
||
226 |
multipleSelectOk |
|
227 |
"allow/disallow multiple selections; the default is false |
|
228 |
" |
|
229 |
^ multipleSelectOk |
|
230 |
||
231 |
||
232 |
! |
|
233 |
||
234 |
multipleSelectOk:aState |
|
235 |
"allow/disallow multiple selections; the default is false |
|
236 |
" |
|
1537 | 237 |
multipleSelectOk := aState ? false. |
1390 | 238 |
! |
239 |
||
240 |
useIndex |
|
241 |
"set/clear the useIndex flag. |
|
242 |
the selection writen to the model are the indices into the list |
|
243 |
or the elements selected. |
|
244 |
" |
|
245 |
^ useIndex |
|
246 |
||
247 |
||
248 |
! |
|
249 |
||
250 |
useIndex:aBoolean |
|
251 |
"set/clear the useIndex flag. |
|
252 |
the selection writen to the model are the indices into the list |
|
253 |
or the elements selected. |
|
254 |
" |
|
255 |
useIndex := aBoolean ? true |
|
256 |
||
257 |
||
258 |
! ! |
|
259 |
||
260 |
!SelectionInListModelView methodsFor:'change & update'! |
|
261 |
||
262 |
argForChangeMessage |
|
263 |
"return the argument for a selectionChange; |
|
264 |
depending on the setting of useIndex, this is either the numeric |
|
265 |
index of the selection or the value (i.e. the string) |
|
266 |
" |
|
1554 | 267 |
selection isNil ifTrue:[ |
268 |
multipleSelectOk ifTrue:[^ #()]. |
|
269 |
^ useIndex ifTrue:[0] ifFalse:[nil] |
|
1390 | 270 |
]. |
1564 | 271 |
useIndex ifTrue:[^ selection]. |
1554 | 272 |
|
273 |
multipleSelectOk ifFalse:[ |
|
274 |
^ list at:selection ifAbsent:nil |
|
1390 | 275 |
]. |
1554 | 276 |
^ selection collect:[:nr| list at:nr ifAbsent:nil ] |
1390 | 277 |
! |
278 |
||
279 |
listSizeChanged:aLnNr nLines:aDeltaLines |
|
280 |
"update selection |
|
281 |
" |
|
1563 | 282 |
|changed cnts| |
1390 | 283 |
|
284 |
super listSizeChanged:aLnNr nLines:aDeltaLines. |
|
285 |
||
286 |
selection isNil ifTrue:[^ self]. |
|
287 |
||
288 |
list size == 0 ifTrue:[ |
|
1563 | 289 |
selection := nil. |
290 |
^ self selectionChanged |
|
1390 | 291 |
]. |
292 |
||
1563 | 293 |
multipleSelectOk ifFalse:[ |
294 |
selection < aLnNr ifTrue:[^ self]. |
|
295 |
||
296 |
selection := selection + aDeltaLines. |
|
1390 | 297 |
|
1563 | 298 |
(aDeltaLines < 0 and:[selection < aLnNr]) ifTrue:[ |
299 |
selection := nil. |
|
300 |
^ self selectionChanged |
|
301 |
] |
|
302 |
] ifTrue:[ |
|
303 |
changed := false. |
|
1390 | 304 |
|
1563 | 305 |
aDeltaLines < 0 ifFalse:[ |
306 |
selection keysAndValuesDo:[:i :ln| |
|
307 |
ln >= aLnNr ifTrue:[ |
|
308 |
changed := true. |
|
309 |
selection at:i put:(ln + aDeltaLines) |
|
310 |
] |
|
1390 | 311 |
] |
1563 | 312 |
] ifTrue:[ |
313 |
cnts := 0. |
|
314 |
||
315 |
selection keysAndValuesDo:[:i :ln||new| |
|
316 |
ln >= aLnNr ifTrue:[ |
|
317 |
changed := true. |
|
318 |
||
319 |
(new := ln + aDeltaLines) < aLnNr ifTrue:[ |
|
320 |
cnts := cnts + 1. |
|
321 |
new := nil |
|
322 |
]. |
|
323 |
selection at:i put:new |
|
324 |
] |
|
325 |
]. |
|
326 |
cnts ~~ 0 ifTrue:[ |
|
327 |
cnts == selection size ifTrue:[ |
|
328 |
selection := nil |
|
329 |
] ifFalse:[ |
|
330 |
selection := selection select:[:ln| ln notNil] |
|
331 |
]. |
|
332 |
^ self selectionChanged. |
|
333 |
]. |
|
1390 | 334 |
]. |
1563 | 335 |
changed ifFalse:[^ self]. |
1390 | 336 |
]. |
337 |
||
1563 | 338 |
(useIndex and:[model notNil]) ifTrue:[ |
339 |
model setValue:(self argForChangeMessage) |
|
340 |
]. |
|
341 |
||
1390 | 342 |
|
343 |
! |
|
344 |
||
345 |
selectionChanged |
|
346 |
"selection has changed. Call actionblock and/or send changeMessage if defined |
|
347 |
" |
|
1554 | 348 |
|arg| |
1390 | 349 |
|
350 |
(model isNil and:[actionBlock isNil]) ifTrue:[ |
|
351 |
^ self |
|
352 |
]. |
|
353 |
||
354 |
arg := self argForChangeMessage. |
|
355 |
||
356 |
model notNil ifTrue:[ |
|
357 |
model removeDependent:self. |
|
358 |
self sendChangeMessage:#value: with:arg. |
|
359 |
model addDependent:self. |
|
360 |
]. |
|
361 |
||
362 |
actionBlock notNil ifTrue:[ |
|
363 |
(actionBlock numArgs) == 1 ifTrue:[ |
|
364 |
actionBlock value:arg |
|
365 |
] ifFalse:[ |
|
366 |
actionBlock value |
|
367 |
] |
|
368 |
]. |
|
369 |
||
370 |
! |
|
371 |
||
372 |
update:something with:aParameter from:changedObject |
|
1554 | 373 |
"check wether my model changed |
1390 | 374 |
" |
375 |
|newSelection| |
|
376 |
||
377 |
changedObject == model ifTrue:[ |
|
1554 | 378 |
self syncPushEvent:#updateFromModel |
1390 | 379 |
] ifFalse:[ |
380 |
super update:something with:aParameter from:changedObject |
|
381 |
]. |
|
1554 | 382 |
|
383 |
! |
|
384 |
||
385 |
updateFromModel |
|
386 |
"update selection from the model |
|
387 |
" |
|
1564 | 388 |
|value nsel| |
389 |
||
390 |
model isNil ifTrue:[ |
|
391 |
^ self |
|
392 |
]. |
|
393 |
||
394 |
self syncFlushEvent:#updateFromModel. |
|
395 |
||
396 |
value := model value. |
|
397 |
||
398 |
(useIndex or:[value isNil or:[value isNumber]]) ifFalse:[ |
|
399 |
multipleSelectOk ifFalse:[ |
|
400 |
value := list identityIndexOf:value |
|
401 |
] ifTrue:[ |
|
402 |
value isEmpty ifTrue:[ |
|
403 |
value := nil |
|
404 |
] ifFalse:[ |
|
405 |
nsel := OrderedCollection new. |
|
406 |
value do:[:e||i|(i := list identityIndexOf:e) ~~ 0 ifTrue:[nsel add:i]]. |
|
407 |
value := nsel notEmpty ifTrue:[nsel] ifFalse:[nil] |
|
408 |
] |
|
409 |
]. |
|
410 |
]. |
|
411 |
self setSelection:value. |
|
412 |
||
1390 | 413 |
! ! |
414 |
||
415 |
!SelectionInListModelView methodsFor:'drag & drop'! |
|
416 |
||
417 |
canDrag |
|
418 |
"returns true if dragging is enabled |
|
419 |
" |
|
420 |
^ dropSource notNil |
|
421 |
||
422 |
! |
|
423 |
||
424 |
dropSource |
|
425 |
"returns the dropSource or nil |
|
426 |
" |
|
427 |
^ dropSource |
|
428 |
||
429 |
! |
|
430 |
||
431 |
dropSource:aDropSourceOrNil |
|
432 |
"set the dropSource or nil |
|
433 |
" |
|
434 |
dropSource := aDropSourceOrNil. |
|
435 |
||
436 |
! |
|
437 |
||
438 |
dropTarget |
|
439 |
"returns the dropTarget or nil |
|
440 |
" |
|
441 |
^ dropTarget |
|
442 |
||
443 |
||
444 |
! |
|
445 |
||
446 |
dropTarget:aDropTragetOrNil |
|
447 |
"set the dropTarget or nil |
|
448 |
" |
|
449 |
dropTarget := aDropTragetOrNil. |
|
450 |
||
451 |
! |
|
452 |
||
453 |
startDragAt:aPoint |
|
454 |
"start drag at a point |
|
455 |
" |
|
456 |
dropSource notNil ifTrue:[ |
|
457 |
dropSource startDragSelector notNil ifTrue:[ |
|
458 |
dropSource startDragIn:self at:aPoint |
|
459 |
] ifFalse:[ |
|
460 |
DragAndDropManager new startDragFrom:self |
|
461 |
dropSource:dropSource |
|
462 |
offset:#center |
|
463 |
] |
|
464 |
] |
|
465 |
||
466 |
! ! |
|
467 |
||
468 |
!SelectionInListModelView methodsFor:'drawing'! |
|
469 |
||
1533 | 470 |
drawFrom:start to:stop x:x y:y w:w |
1390 | 471 |
"draw the lines between start to stop without clearing the background |
472 |
" |
|
1557 | 473 |
highlightMode notNil ifTrue:[ |
474 |
self selectionDo:[:lnNr| |
|
475 |
(lnNr between:start and:stop) ifTrue:[ |
|
476 |
self drawSelectionFrameAt:lnNr x:x w:w |
|
477 |
] |
|
1390 | 478 |
] |
479 |
]. |
|
1533 | 480 |
self drawElementsFrom:start to:stop x:x y:y w:w. |
1390 | 481 |
|
482 |
||
483 |
! |
|
484 |
||
1533 | 485 |
drawLabelAt:anIndex x:x y:y h:h |
1390 | 486 |
"draw the label at position x/y without clearing the background |
487 |
" |
|
1554 | 488 |
|item| |
489 |
||
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1468
diff
changeset
|
490 |
item := list at:anIndex ifAbsent:nil. |
1390 | 491 |
|
1557 | 492 |
item notNil ifTrue:[ |
493 |
(highlightMode notNil and:[self isInSelection:anIndex]) ifTrue:[ |
|
494 |
self paint:hilightFgColor on:hilightBgColor |
|
495 |
] ifFalse:[ |
|
496 |
self paint:fgColor on:bgColor. |
|
497 |
]. |
|
498 |
self displayElement:item x:x y:y h:h. |
|
499 |
] |
|
1390 | 500 |
|
501 |
||
502 |
! |
|
503 |
||
1554 | 504 |
drawSelectionFrameAt:lnNr x:x w:w |
505 |
"draw the background and foreground of the selection frame |
|
506 |
at a lineNr. |
|
1390 | 507 |
" |
1554 | 508 |
|item |
509 |
x0 "{ Class:SmallInteger }" |
|
1390 | 510 |
x1 "{ Class: SmallInteger }" |
1554 | 511 |
y0 "{ Class:SmallInteger }" |
512 |
y1 "{ Class:SmallInteger }" |
|
513 |
hL "{ Class:SmallInteger }" |
|
514 |
wL "{ Class:SmallInteger }" |
|
1390 | 515 |
| |
1554 | 516 |
(item := list at:lnNr ifAbsent:nil) isNil ifTrue:[ |
517 |
^ self |
|
518 |
]. |
|
519 |
||
520 |
"/ CLEAR THE BACKGROUND |
|
521 |
||
522 |
y0 := self yVisibleOfLine:lnNr. |
|
523 |
y1 := self yVisibleOfLine:(lnNr + 1). |
|
524 |
hL := y1 - y0. |
|
525 |
||
526 |
highlightMode == #line ifTrue:[ |
|
527 |
x0 := x. |
|
528 |
x1 := x0 + w. |
|
529 |
] ifFalse:[ |
|
530 |
highlightMode == #label ifFalse:[^ self]. |
|
531 |
x0 := (self xVisibleOfItem:item) - (textStartLeft // 2). |
|
532 |
x1 := x0 + (item widthOn:self) + textStartLeft. |
|
533 |
]. |
|
534 |
wL := x1 - x0. |
|
535 |
||
536 |
wL > 0 ifFalse:[^ self]. |
|
537 |
||
538 |
self paint:hilightBgColor. |
|
539 |
self fillRectangleX:x0 y:y0 width:wL height:hL. |
|
540 |
||
541 |
"/ DRAW THE FRAME |
|
1390 | 542 |
|
543 |
hilightFrameColor notNil ifTrue:[ |
|
544 |
hilightLevel == 0 ifTrue:[ |
|
545 |
self paint:hilightFrameColor. |
|
546 |
||
547 |
highlightMode == #line ifTrue:[ |
|
548 |
self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
|
1554 | 549 |
y1 := y0 + hL - 1. |
550 |
self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
|
1390 | 551 |
] ifFalse:[ |
1554 | 552 |
self displayRectangleX:x0 y:y0 width:wL height:hL |
1390 | 553 |
]. |
554 |
^ self. |
|
555 |
] |
|
556 |
] ifFalse:[ |
|
557 |
hilightStyle == #motif ifTrue:[ |
|
558 |
self paint:bgColor. |
|
1554 | 559 |
y1 := y0 + 1. |
1390 | 560 |
highlightMode == #line ifTrue:[ |
1554 | 561 |
self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
562 |
y1 := y0 + hL - 2. |
|
563 |
self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
|
1390 | 564 |
] ifFalse:[ |
1554 | 565 |
self displayRectangleX:x0 + 1 y:y1 width:wL - 2 height:hL - 2 |
1390 | 566 |
] |
567 |
] |
|
568 |
]. |
|
569 |
||
570 |
hilightLevel ~~ 0 ifTrue:[ |
|
571 |
"/ draw edge |
|
572 |
highlightMode == #line ifTrue:[ |
|
1554 | 573 |
x0 := margin. |
574 |
wL := width - x0 - x0. |
|
1390 | 575 |
]. |
1554 | 576 |
self drawEdgesForX:x0 y:y0 width:wL height:hL level:hilightLevel. |
1390 | 577 |
] |
578 |
||
579 |
! |
|
580 |
||
1554 | 581 |
redrawSelectionAt:aLineNr |
1569 | 582 |
"redraw a line which changed its selection status. |
583 |
optimized when drawing only the label. |
|
1390 | 584 |
" |
1569 | 585 |
|item |
586 |
y0 "{ Class:SmallInteger }" |
|
587 |
y1 "{ Class:SmallInteger }" |
|
588 |
yB "{ Class:SmallInteger }" |
|
589 |
x0 "{ Class:SmallInteger }" |
|
590 |
x1 "{ Class:SmallInteger }" |
|
591 |
| |
|
592 |
||
593 |
(shown and:[aLineNr notNil and:[highlightMode notNil]]) ifFalse:[ |
|
594 |
^ self |
|
1557 | 595 |
]. |
596 |
||
1569 | 597 |
yB := height - margin. |
598 |
y0 := (self yVisibleOfLine:aLineNr) max:margin. |
|
599 |
||
600 |
y0 >= yB ifTrue:[ |
|
601 |
^ self |
|
602 |
]. |
|
603 |
||
604 |
y1 := (self yVisibleOfLine:(aLineNr + 1)) min:yB. |
|
605 |
||
606 |
y1 <= margin ifTrue:[ |
|
607 |
^ self |
|
608 |
]. |
|
609 |
||
610 |
( highlightMode == #label |
|
611 |
and:[(item := list at:aLineNr ifAbsent:nil) notNil] |
|
612 |
) ifTrue:[ |
|
613 |
x0 := (self xVisibleOfItem:item) - (textStartLeft // 2). |
|
614 |
x1 := x0 + (item widthOn:self) + textStartLeft. |
|
615 |
x0 := x0 max:0. |
|
616 |
x1 := x1 min:width. |
|
617 |
||
618 |
x1 > x0 ifFalse:[^ self]. |
|
619 |
] ifFalse:[ |
|
620 |
x0 := 0. |
|
621 |
x1 := width. |
|
622 |
]. |
|
623 |
self invalidateX:x0 y:y0 width:(x1 - x0) height:(y1 - y0). |
|
1390 | 624 |
! ! |
625 |
||
626 |
!SelectionInListModelView methodsFor:'event handling'! |
|
627 |
||
628 |
buttonMotion:buttonMask x:x y:y |
|
629 |
"mouse-move while button was pressed - handle selection changes |
|
630 |
" |
|
1641 | 631 |
|p cY oY lnNr h changed| |
1390 | 632 |
|
1542
8607d072c319
accessing selection through to selector
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
633 |
(enabled and:[self hasSelection]) ifFalse:[^ self]. |
1390 | 634 |
|
635 |
dragAccessPoint notNil ifTrue:[ |
|
636 |
p := x @ y. |
|
637 |
||
638 |
(dragAccessPoint dist:p) > 5.0 ifTrue:[ |
|
639 |
dragAccessPoint := nil. |
|
640 |
self startDragAt:p |
|
641 |
]. |
|
642 |
^ self |
|
643 |
]. |
|
644 |
||
645 |
(multipleSelectOk and:[self sensor leftButtonPressed]) ifFalse:[ |
|
646 |
^ self |
|
647 |
]. |
|
648 |
||
649 |
clickLine isNil ifTrue:[ |
|
650 |
^ self |
|
651 |
]. |
|
652 |
cY := self yVisibleOfLine:clickLine. |
|
653 |
oY := cY. |
|
654 |
||
655 |
y < cY ifTrue:[ |
|
656 |
(lnNr := clickLine - 1) == 0 ifTrue:[^ self]. |
|
657 |
cY := self yVisibleOfLine:lnNr. |
|
658 |
h := oY - cY. |
|
659 |
] ifFalse:[ |
|
660 |
( (lnNr := clickLine + 1) > list size |
|
661 |
or:[(cY := self yVisibleOfLine:lnNr) > y] |
|
662 |
) ifTrue:[ |
|
663 |
^ self |
|
664 |
]. |
|
665 |
h := cY - oY. |
|
666 |
]. |
|
1641 | 667 |
(changed := self canSelectIndex:lnNr) ifTrue:[ |
668 |
self toggleSelection:lnNr |
|
669 |
]. |
|
1390 | 670 |
clickLine := lnNr. |
671 |
||
1542
8607d072c319
accessing selection through to selector
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
672 |
(cY between:margin and:(height - h)) ifFalse:[ |
1390 | 673 |
self scrollToLine:lnNr. |
674 |
]. |
|
1641 | 675 |
changed ifTrue:[ |
676 |
self selectionChanged. |
|
677 |
]. |
|
678 |
||
1390 | 679 |
! |
680 |
||
681 |
buttonMultiPress:button x:x y:y |
|
682 |
"button was pressed multiple - handle a doubleClick action |
|
683 |
" |
|
684 |
clickLine := nil. |
|
685 |
dragAccessPoint := nil. |
|
686 |
||
687 |
enabled ifFalse:[^ self]. |
|
688 |
||
689 |
((button == 1) or:[button == #select]) ifFalse:[ |
|
690 |
^ super buttonMultiPress:button x:x y:y |
|
691 |
]. |
|
692 |
self doubleClicked |
|
693 |
! |
|
694 |
||
695 |
buttonPress:button x:x y:y |
|
696 |
"a button was pressed - handle selection here |
|
697 |
" |
|
1644 | 698 |
|sensor nsel start step item menu appl isInSelection| |
1390 | 699 |
|
700 |
clickLine := nil. |
|
701 |
dragAccessPoint := nil. |
|
702 |
||
703 |
enabled ifFalse:[^ self]. |
|
704 |
||
1578 | 705 |
((button == 2) or:[button == #menu]) ifTrue:[ |
706 |
( (item := self selectedElement) notNil |
|
707 |
and:[(menu := item perform:#middleButtonMenu ifNotUnderstood:nil) notNil] |
|
708 |
) ifTrue:[ |
|
709 |
menu isCollection ifTrue:[ |
|
710 |
menu := Menu new fromLiteralArrayEncoding:menu. |
|
711 |
appl := self application. |
|
712 |
||
713 |
appl notNil ifTrue:[ |
|
714 |
menu findGuiResourcesIn:appl. |
|
715 |
menu receiver:appl |
|
716 |
] ifFalse:[ |
|
717 |
menu receiver:item |
|
718 |
] |
|
719 |
]. |
|
720 |
^ menu startUp |
|
721 |
]. |
|
1390 | 722 |
^ super buttonPress:button x:x y:y |
723 |
]. |
|
1578 | 724 |
|
1644 | 725 |
(clickLine := self yVisibleToLineNr:y) isNil ifTrue:[^ self]. |
726 |
||
727 |
isInSelection := self isInSelection:clickLine. |
|
1390 | 728 |
|
729 |
(multipleSelectOk and:[(sensor := self sensor) notNil]) ifTrue:[ |
|
730 |
sensor ctrlDown ifTrue:[ |
|
1644 | 731 |
(isInSelection or:[self canSelectIndex:clickLine]) ifTrue:[ |
732 |
self toggleSelection:clickLine. |
|
733 |
self selectionChanged |
|
734 |
]. |
|
735 |
^ self |
|
1390 | 736 |
]. |
1644 | 737 |
(self canSelectIndex:clickLine) ifFalse:[^ self]. |
1390 | 738 |
|
1545 | 739 |
(sensor shiftDown and:[(start := self firstInSelection) notNil]) ifTrue:[ |
740 |
step := clickLine < start ifTrue:[-1] ifFalse:[1]. |
|
741 |
nsel := OrderedCollection new. |
|
742 |
||
1641 | 743 |
start to:clickLine by:step do:[:i| |
744 |
(self canSelectIndex:i) ifTrue:[nsel add:i] |
|
745 |
]. |
|
1545 | 746 |
|
747 |
(self selectWithoutScroll:nsel redraw:true) ifTrue:[ |
|
1390 | 748 |
self selectionChanged |
749 |
]. |
|
750 |
^ self |
|
751 |
] |
|
1644 | 752 |
] ifFalse:[ |
753 |
(self canSelectIndex:clickLine) ifFalse:[^ self] |
|
1390 | 754 |
]. |
755 |
||
1644 | 756 |
(isInSelection and:[self canDrag]) ifTrue:[ |
1390 | 757 |
dragAccessPoint := x @ y |
758 |
] ifFalse:[ |
|
1545 | 759 |
(self selectWithoutScroll:clickLine redraw:true) ifTrue:[ |
1390 | 760 |
self selectionChanged |
761 |
] |
|
762 |
] |
|
1545 | 763 |
|
1390 | 764 |
! |
765 |
||
766 |
buttonRelease:button x:x y:y |
|
767 |
"a button was released |
|
768 |
" |
|
769 |
enabled ifTrue:[ |
|
770 |
(dragAccessPoint notNil and:[clickLine notNil]) ifTrue:[ |
|
1545 | 771 |
(self selectWithoutScroll:clickLine redraw:true) ifTrue:[ |
1390 | 772 |
self selectionChanged |
773 |
] |
|
774 |
] |
|
775 |
]. |
|
776 |
clickLine := nil. |
|
777 |
dragAccessPoint := nil. |
|
778 |
||
779 |
||
780 |
! |
|
781 |
||
782 |
characterPress:aKey x:x y:y |
|
783 |
" a character is pressed - lookup and change selection |
|
784 |
" |
|
785 |
|lnNr size idx sensor stp to1 fr2| |
|
786 |
||
787 |
(enabled and:[(size := self size) > 1]) ifFalse:[ |
|
788 |
^ self |
|
789 |
]. |
|
790 |
lnNr := self firstInSelection ? 0. |
|
791 |
||
792 |
((sensor := self sensor) notNil and:[sensor shiftDown]) ifTrue:[ |
|
793 |
stp := -1. "/ search backward |
|
794 |
to1 := 1. |
|
795 |
fr2 := size. |
|
796 |
] ifFalse:[ |
|
797 |
stp := 1. "/ search forward |
|
798 |
to1 := size. |
|
799 |
fr2 := 1. |
|
800 |
]. |
|
801 |
||
802 |
idx := self findLineFrom:lnNr+stp to:to1 by:stp startingWithCharacter:aKey. |
|
803 |
||
804 |
idx == 0 ifTrue:[ |
|
805 |
idx := self findLineFrom:fr2 to:lnNr-stp by:stp startingWithCharacter:aKey |
|
806 |
]. |
|
807 |
idx ~~ 0 ifTrue:[^ self selection:idx] |
|
808 |
! |
|
809 |
||
810 |
doubleClicked |
|
811 |
"handle a double click |
|
812 |
" |
|
813 |
(doubleClickActionBlock notNil and:[self numberOfSelections == 1]) ifTrue:[ |
|
814 |
(doubleClickActionBlock numArgs == 1) ifTrue:[ |
|
815 |
doubleClickActionBlock value:(self selectedIndex) |
|
816 |
] ifFalse:[ |
|
817 |
doubleClickActionBlock value |
|
818 |
] |
|
819 |
] |
|
820 |
||
821 |
! |
|
822 |
||
823 |
findLineFrom:aStart to:aStop by:aStep startingWithCharacter:aCharacter |
|
824 |
"find a line starting with a character |
|
825 |
" |
|
826 |
|item char lbl cmp |
|
827 |
size "{ Class:SmallInteger }" |
|
828 |
start "{ Class:SmallInteger }" |
|
829 |
stop "{ Class:SmallInteger }" |
|
830 |
| |
|
831 |
(size := list size) ~~ 0 ifTrue:[ |
|
832 |
aStep > 0 ifTrue:[ |
|
833 |
aStart > aStop ifTrue:[^ 0]. |
|
834 |
] ifFalse:[ |
|
835 |
(aStep == 0 or:[aStop > aStart]) ifTrue:[^ 0] |
|
836 |
]. |
|
837 |
||
838 |
start := aStart < 0 ifTrue:[1] ifFalse:[aStart min:size]. |
|
839 |
stop := aStop < 0 ifTrue:[1] ifFalse:[aStop min:size]. |
|
840 |
char := aCharacter asUppercase. |
|
841 |
||
842 |
start to:stop by:aStep do:[:anIndex| |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1468
diff
changeset
|
843 |
item := list at:anIndex ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1468
diff
changeset
|
844 |
item isNil ifTrue:[^ 0]. "/ list changed |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1468
diff
changeset
|
845 |
|
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1468
diff
changeset
|
846 |
lbl := item perform:#string ifNotUnderstood:nil. |
1390 | 847 |
|
848 |
lbl notNil ifTrue:[ |
|
849 |
cmp := lbl string at:1 ifAbsent:nil. |
|
850 |
||
851 |
cmp notNil ifTrue:[ |
|
852 |
(char == cmp or:[char == cmp asUppercase]) ifTrue:[ |
|
853 |
^ anIndex |
|
854 |
] |
|
855 |
] |
|
856 |
] |
|
857 |
] |
|
858 |
]. |
|
859 |
^ 0 |
|
860 |
||
861 |
||
862 |
! |
|
863 |
||
864 |
keyPress:aKey x:x y:y |
|
865 |
"a key was pressed - handle page-keys here |
|
866 |
" |
|
867 |
<resource: #keyboard( #Return #CursorUp #CursorDown )> |
|
868 |
||
869 |
|sensor n size lineNr| |
|
870 |
||
871 |
enabled ifFalse:[ |
|
872 |
^ super keyPress:aKey x:x y:y |
|
873 |
]. |
|
874 |
aKey == #Return ifTrue:[ |
|
875 |
self numberOfSelections == 1 ifTrue:[self doubleClicked]. |
|
876 |
^ self |
|
877 |
]. |
|
878 |
||
879 |
aKey isCharacter ifTrue:[ |
|
880 |
^ self characterPress:aKey x:x y:y |
|
881 |
]. |
|
882 |
||
883 |
(aKey == #CursorUp or:[aKey == #CursorDown]) ifFalse:[ |
|
884 |
^ super keyPress:aKey x:x y:y |
|
885 |
]. |
|
886 |
||
887 |
(size := self size) == 0 ifTrue:[ |
|
888 |
^ self |
|
889 |
]. |
|
890 |
||
891 |
lineNr := self selectedIndex. |
|
892 |
sensor := self sensor. |
|
893 |
||
894 |
sensor notNil ifTrue:[ |
|
895 |
n := (1 + (sensor compressKeyPressEventsWithKey:aKey)) \\ size. |
|
896 |
n == 0 ifTrue:[^ self]. |
|
897 |
] ifFalse:[ |
|
898 |
n := 1 |
|
899 |
]. |
|
900 |
||
901 |
aKey == #CursorUp ifTrue:[ |
|
902 |
lineNr == 0 ifTrue:[lineNr := size + 1]. |
|
903 |
(n := lineNr - n) <= 0 ifTrue:[n := size + n] |
|
904 |
] ifFalse:[ |
|
905 |
(n := lineNr + n) > size ifTrue:[n := n - size] |
|
906 |
]. |
|
907 |
self selection:n |
|
908 |
! ! |
|
909 |
||
1421 | 910 |
!SelectionInListModelView methodsFor:'focus handling'! |
911 |
||
912 |
wantsFocusWithPointerEnter |
|
913 |
"return true, if I want the focus when |
|
914 |
the mouse pointer enters" |
|
915 |
||
916 |
|pref| |
|
917 |
||
918 |
pref := UserPreferences current focusFollowsMouse. |
|
919 |
(pref ~~ false |
|
920 |
and:[(styleSheet at:#'selection.requestFocusOnPointerEnter' default:true) |
|
921 |
]) ifTrue:[ |
|
922 |
^ true |
|
923 |
]. |
|
924 |
^ false |
|
925 |
||
926 |
||
927 |
! ! |
|
928 |
||
1390 | 929 |
!SelectionInListModelView methodsFor:'initialize / release'! |
930 |
||
931 |
fetchResources |
|
932 |
"fetch device colors and ..., to avoid reallocation at redraw time; |
|
933 |
*** called after a create or snapin to fetch all device resources |
|
934 |
" |
|
935 |
||
936 |
super fetchResources. |
|
937 |
||
938 |
hilightFgColor := self colorOnDevice:hilightFgColor. |
|
939 |
hilightBgColor := self colorOnDevice:hilightBgColor. |
|
940 |
hilightFrameColor := self colorOnDevice:hilightFrameColor. |
|
941 |
! |
|
942 |
||
943 |
initStyle |
|
944 |
"setup viewStyle specifics |
|
945 |
" |
|
946 |
|h| |
|
947 |
||
948 |
super initStyle. |
|
949 |
||
1595 | 950 |
DefaultHilightLevel isNil ifTrue:[ |
951 |
self updateStyleCache |
|
952 |
]. |
|
953 |
||
1390 | 954 |
hilightFrameColor := nil. |
955 |
hilightLevel := 0. |
|
956 |
hilightStyle := DefaultHilightStyle. |
|
1557 | 957 |
highlightMode := #label. |
1390 | 958 |
textStartLeft := 4. |
959 |
||
960 |
device hasGrayscales ifTrue:[ |
|
961 |
" |
|
962 |
must get rid of these hard codings |
|
963 |
" |
|
964 |
(hilightStyle == #next) ifTrue:[ |
|
965 |
hilightFgColor := fgColor. |
|
966 |
hilightBgColor := White. |
|
967 |
hilightFrameColor := fgColor |
|
968 |
] ifFalse:[ |
|
969 |
(hilightStyle == #motif) ifTrue:[ |
|
970 |
fgColor := White. |
|
971 |
bgColor := Grey. |
|
972 |
viewBackground := bgColor. |
|
973 |
hilightFgColor := bgColor. |
|
974 |
hilightBgColor := fgColor. |
|
975 |
] ifFalse:[ |
|
976 |
(hilightStyle == #openwin) ifTrue:[ |
|
977 |
hilightFgColor := fgColor. |
|
978 |
hilightBgColor := Color grey. |
|
979 |
] |
|
980 |
] |
|
981 |
] |
|
982 |
]. |
|
983 |
||
984 |
hilightFgColor isNil ifTrue:[ |
|
985 |
hilightFgColor := bgColor. |
|
986 |
]. |
|
987 |
hilightBgColor isNil ifTrue:[ |
|
988 |
hilightBgColor := fgColor. |
|
989 |
]. |
|
990 |
DefaultForegroundColor notNil ifTrue:[ |
|
991 |
fgColor := DefaultForegroundColor |
|
992 |
]. |
|
993 |
DefaultBackgroundColor notNil ifTrue:[ |
|
994 |
bgColor := viewBackground := DefaultBackgroundColor |
|
995 |
]. |
|
996 |
||
997 |
DefaultHilightForegroundColor notNil ifTrue:[ |
|
998 |
hilightFgColor := DefaultHilightForegroundColor |
|
999 |
]. |
|
1000 |
DefaultHilightBackgroundColor notNil ifTrue:[ |
|
1001 |
hilightBgColor := DefaultHilightBackgroundColor |
|
1002 |
]. |
|
1003 |
DefaultHilightFrameColor notNil ifTrue:[ |
|
1004 |
hilightFrameColor := DefaultHilightFrameColor |
|
1005 |
]. |
|
1006 |
DefaultHilightLevel notNil ifTrue:[ |
|
1007 |
hilightLevel := DefaultHilightLevel |
|
1008 |
]. |
|
1009 |
lineSpacing := 2 * (hilightLevel abs). |
|
1010 |
||
1011 |
(hilightStyle == #motif) ifTrue:[ |
|
1012 |
lineSpacing := lineSpacing max:6. |
|
1013 |
] ifFalse:[ |
|
1014 |
lineSpacing := lineSpacing max:4. |
|
1015 |
]. |
|
1016 |
hilightFgColor isNil ifTrue:[ |
|
1017 |
hilightFgColor := bgColor. |
|
1018 |
hilightBgColor := fgColor |
|
1019 |
]. |
|
1020 |
! |
|
1021 |
||
1022 |
initialize |
|
1023 |
"setup default attributes/behavior |
|
1024 |
" |
|
1025 |
super initialize. |
|
1026 |
||
1027 |
multipleSelectOk := false. |
|
1028 |
useIndex := true. |
|
1029 |
||
1030 |
! |
|
1031 |
||
1032 |
realize |
|
1033 |
"get selection from model; scroll to selection |
|
1034 |
" |
|
1554 | 1035 |
self updateFromModel. |
1390 | 1036 |
super realize. |
1545 | 1037 |
self makeSelectionVisible. |
1390 | 1038 |
|
1039 |
! ! |
|
1040 |
||
1041 |
!SelectionInListModelView methodsFor:'protocol'! |
|
1042 |
||
1533 | 1043 |
drawElementsFrom:start to:stop x:x y:y w:w |
1390 | 1044 |
"draw the items between start to stop without clearing the background |
1045 |
" |
|
1046 |
|y0 "{ Class:SmallInteger }" |
|
1047 |
y1 "{ Class:SmallInteger }" |
|
1048 |
x0 "{ Class:SmallInteger }" |
|
1049 |
| |
|
1050 |
x0 := textStartLeft - viewOrigin x. |
|
1533 | 1051 |
y1 := y. |
1390 | 1052 |
|
1053 |
start to:stop do:[:i| |
|
1054 |
y0 := y1. |
|
1055 |
y1 := self yVisibleOfLine:(i + 1). |
|
1533 | 1056 |
self drawLabelAt:i x:x0 y:y0 h:(y1 - y0) |
1390 | 1057 |
]. |
1058 |
||
1059 |
||
1060 |
! |
|
1061 |
||
1458 | 1062 |
lostSynchronisation |
1063 |
"called when the changes derived from the model are faster than the handling |
|
1064 |
" |
|
1547 | 1065 |
self deselectWithoutRedraw. |
1458 | 1066 |
super lostSynchronisation. |
1554 | 1067 |
! |
1068 |
||
1069 |
xVisibleOfItem:anItem |
|
1070 |
"returns the visible x of the labeled text |
|
1071 |
" |
|
1072 |
^ textStartLeft - viewOrigin x |
|
1073 |
||
1074 |
||
1390 | 1075 |
! ! |
1076 |
||
1077 |
!SelectionInListModelView methodsFor:'selection'! |
|
1078 |
||
1079 |
deselect |
|
1080 |
"clear selection |
|
1081 |
" |
|
1082 |
self selection:nil |
|
1083 |
||
1084 |
! |
|
1085 |
||
1086 |
firstInSelection |
|
1087 |
"returns line number of first element selected or nil |
|
1088 |
" |
|
1545 | 1089 |
multipleSelectOk ifFalse:[ |
1090 |
^ selection |
|
1390 | 1091 |
]. |
1545 | 1092 |
^ selection isNil ifTrue:[nil] ifFalse:[selection at:1] |
1390 | 1093 |
! |
1094 |
||
1095 |
hasSelection |
|
1096 |
"returns true if a selection exists |
|
1097 |
" |
|
1098 |
^ selection notNil |
|
1099 |
||
1100 |
! |
|
1101 |
||
1102 |
isInSelection:aNumber |
|
1103 |
"return true, if line, aNumber is in the selection |
|
1104 |
" |
|
1545 | 1105 |
multipleSelectOk ifFalse:[ |
1106 |
^ aNumber == selection |
|
1107 |
]. |
|
1108 |
^ selection isNil ifTrue:[false] |
|
1109 |
ifFalse:[selection includesIdentical:aNumber] |
|
1390 | 1110 |
! |
1111 |
||
1112 |
numberOfSelections |
|
1113 |
"return the number of selected items |
|
1114 |
" |
|
1545 | 1115 |
selection notNil ifTrue:[ |
1116 |
^ multipleSelectOk ifFalse:[1] ifTrue:[selection size] |
|
1117 |
]. |
|
1118 |
^ 0 |
|
1390 | 1119 |
|
1120 |
! |
|
1121 |
||
1122 |
selectElement:anElement |
|
1123 |
"select the element. Scroll to make the new selection visible. |
|
1124 |
Model and/or actionBlock notification IS done. |
|
1125 |
" |
|
1545 | 1126 |
self selection:(list identityIndexOf:anElement) |
1390 | 1127 |
! |
1128 |
||
1129 |
selectedElement |
|
1130 |
"return the single selected item or nil |
|
1131 |
" |
|
1545 | 1132 |
|index| |
1390 | 1133 |
|
1545 | 1134 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
1135 |
^ list at:index ifAbsent:nil |
|
1136 |
]. |
|
1137 |
^ nil |
|
1390 | 1138 |
! |
1139 |
||
1140 |
selectedIndex |
|
1141 |
"returns the index of the selected line or 0. If more |
|
1142 |
lines are selected, 0 is returned |
|
1143 |
" |
|
1545 | 1144 |
self numberOfSelections == 1 ifTrue:[ |
1145 |
^ self firstInSelection |
|
1146 |
]. |
|
1147 |
^ 0 |
|
1390 | 1148 |
! |
1149 |
||
1150 |
selection |
|
1151 |
"return the selection index or collection of indices |
|
1152 |
in case of multiple selection enabled |
|
1153 |
" |
|
1154 |
^ selection |
|
1155 |
||
1156 |
! |
|
1157 |
||
1545 | 1158 |
selection:something |
1159 |
"select something or deselect if the argument is nil; |
|
1390 | 1160 |
scroll to make the selected line visible. |
1161 |
The model and/or actionBlock IS notified. |
|
1162 |
" |
|
1545 | 1163 |
(self selectWithoutScroll:something redraw:true) ifTrue:[ |
1164 |
self makeSelectionVisible. |
|
1390 | 1165 |
self selectionChanged |
1545 | 1166 |
]. |
1390 | 1167 |
|
1168 |
! |
|
1169 |
||
1170 |
selectionDo:aBlock |
|
1171 |
"perform aBlock for each nr in the selection. |
|
1172 |
For single selection, it is called once for the items nr. |
|
1173 |
For multiple selections, it is called for each. |
|
1174 |
" |
|
1175 |
selection notNil ifTrue:[ |
|
1176 |
multipleSelectOk ifTrue:[ |
|
1177 |
selection do:aBlock |
|
1178 |
] ifFalse:[ |
|
1179 |
aBlock value:selection |
|
1180 |
]. |
|
1181 |
]. |
|
1182 |
||
1183 |
||
1184 |
! |
|
1185 |
||
1542
8607d072c319
accessing selection through to selector
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
1186 |
setSelection:something |
1545 | 1187 |
"select something or deselect if the argument is nil; |
1390 | 1188 |
scroll to make the selected line visible. |
1189 |
*** No model and/or actionBlock notification is done here. |
|
1190 |
" |
|
1545 | 1191 |
(self selectWithoutScroll:something redraw:true) ifTrue:[ |
1390 | 1192 |
self makeSelectionVisible |
1193 |
] |
|
1194 |
||
1195 |
! ! |
|
1196 |
||
1197 |
!SelectionInListModelView methodsFor:'selection private'! |
|
1198 |
||
1641 | 1199 |
canSelectIndex:anIndex |
1200 |
"return true, if the object identified by its index is selectable |
|
1201 |
" |
|
1649 | 1202 |
|item| |
1203 |
||
1204 |
selectConditionBlock notNil ifTrue:[ |
|
1205 |
(selectConditionBlock value:anIndex) ifFalse:[ |
|
1206 |
^ false |
|
1207 |
] |
|
1641 | 1208 |
]. |
1209 |
||
1649 | 1210 |
supportsDisplayInRange ifTrue:[ |
1211 |
item := list at:anIndex ifAbsent:nil. |
|
1212 |
item isNil ifTrue:[^ false]. |
|
1213 |
^ item isSelectable |
|
1214 |
]. |
|
1215 |
^ true |
|
1641 | 1216 |
! |
1217 |
||
1547 | 1218 |
deselectWithoutRedraw |
1219 |
"clear the selection without redraw and scrolling; |
|
1220 |
the model and/or actionBlock is notified |
|
1221 |
" |
|
1222 |
(self selectWithoutScroll:nil redraw:false) ifTrue:[ |
|
1223 |
self selectionChanged |
|
1224 |
] |
|
1225 |
! |
|
1226 |
||
1390 | 1227 |
makeSelectionVisible |
1228 |
"scroll to make the selection line visible |
|
1229 |
" |
|
1230 |
|lineNr| |
|
1231 |
||
1564 | 1232 |
lineNr := self firstInSelection. |
1233 |
||
1234 |
lineNr notNil ifTrue:[ |
|
1235 |
self scrollToLine:lineNr |
|
1390 | 1236 |
] |
1237 |
||
1238 |
! |
|
1239 |
||
1545 | 1240 |
selectWithoutScroll:something redraw:doRedraw |
1241 |
"change selection to something; returns true if selection changed |
|
1390 | 1242 |
" |
1243 |
|oldSelect| |
|
1244 |
||
1554 | 1245 |
selection = something ifTrue:[^ false]. |
1246 |
||
1390 | 1247 |
oldSelect := selection. |
1248 |
||
1545 | 1249 |
(something isNil or:[something == 0]) ifTrue:[ |
1250 |
selection := nil |
|
1251 |
] ifFalse:[ |
|
1252 |
something isNumber ifTrue:[ |
|
1564 | 1253 |
selection := multipleSelectOk ifTrue:[Array with:something] |
1254 |
ifFalse:[something] |
|
1545 | 1255 |
] ifFalse:[ |
1256 |
something size == 0 ifTrue:[ |
|
1257 |
selection := nil |
|
1258 |
] ifFalse:[ |
|
1259 |
selection := multipleSelectOk ifTrue:[something] |
|
1260 |
ifFalse:[something at:1] |
|
1261 |
] |
|
1262 |
] |
|
1263 |
]. |
|
1264 |
selection = oldSelect ifTrue:[^ false]. |
|
1265 |
||
1266 |
(doRedraw and:[shown]) ifFalse:[ |
|
1267 |
^ true |
|
1390 | 1268 |
]. |
1269 |
||
1270 |
multipleSelectOk ifFalse:[ |
|
1271 |
oldSelect notNil ifTrue:[self redrawSelectionAt:oldSelect]. |
|
1272 |
selection notNil ifTrue:[self redrawSelectionAt:selection]. |
|
1273 |
] ifTrue:[ |
|
1545 | 1274 |
(selection notNil and:[oldSelect notNil]) ifTrue:[ |
1275 |
selection do:[:i|(oldSelect includesIdentical:i) ifFalse:[self redrawSelectionAt:i]]. |
|
1276 |
oldSelect do:[:i|(selection includesIdentical:i) ifFalse:[self redrawSelectionAt:i]]. |
|
1390 | 1277 |
] ifFalse:[ |
1545 | 1278 |
oldSelect isNil ifTrue:[oldSelect := selection]. |
1279 |
oldSelect do:[:i|self redrawSelectionAt:i] |
|
1390 | 1280 |
] |
1281 |
]. |
|
1545 | 1282 |
^ true |
1390 | 1283 |
|
1284 |
||
1561 | 1285 |
! |
1286 |
||
1287 |
toggleSelection:aNumber |
|
1288 |
"add a number to the selection. No scrolling is done. |
|
1289 |
*** No model and/or actionBlock notification is done here. |
|
1290 |
" |
|
1291 |
|newSelect oldSelect doRemove| |
|
1292 |
||
1293 |
multipleSelectOk ifFalse:[ |
|
1294 |
aNumber == selection ifTrue:[ "/ remove from selection |
|
1295 |
selection := nil. |
|
1296 |
] ifFalse:[ "/ add to selection |
|
1297 |
oldSelect := selection. |
|
1298 |
selection := aNumber. |
|
1299 |
||
1300 |
oldSelect notNil ifTrue:[ |
|
1301 |
self redrawSelectionAt:oldSelect |
|
1302 |
] |
|
1303 |
]. |
|
1304 |
self redrawSelectionAt:aNumber. |
|
1305 |
^ self |
|
1306 |
]. |
|
1307 |
||
1308 |
selection isNil ifTrue:[ "/ add to empty selection |
|
1309 |
selection := OrderedCollection with:aNumber. |
|
1310 |
self redrawSelectionAt:aNumber. |
|
1311 |
^ self |
|
1312 |
]. |
|
1313 |
||
1314 |
doRemove := selection includesIdentical:aNumber. |
|
1315 |
||
1316 |
(doRemove and:[selection size == 1]) ifTrue:[ "/ remove selection |
|
1317 |
selection := nil. |
|
1318 |
self redrawSelectionAt:aNumber. |
|
1319 |
^ self |
|
1320 |
]. |
|
1321 |
||
1322 |
selection := selection asOrderedCollection. |
|
1323 |
||
1324 |
doRemove ifTrue:[ |
|
1325 |
selection removeIdentical:aNumber. |
|
1326 |
] ifFalse:[ |
|
1327 |
selection add:aNumber. |
|
1328 |
]. |
|
1329 |
self redrawSelectionAt:aNumber. |
|
1330 |
||
1331 |
||
1332 |
||
1390 | 1333 |
! ! |
1334 |
||
1335 |
!SelectionInListModelView class methodsFor:'documentation'! |
|
1336 |
||
1337 |
version |
|
1649 | 1338 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.29 2000-01-14 08:13:19 ps Exp $' |
1390 | 1339 |
! ! |