author | tz |
Sat, 18 Jul 1998 17:12:58 +0200 | |
changeset 988 | d077faaade27 |
parent 896 | aa07612a7c04 |
child 989 | 70fd16dd0085 |
permissions | -rw-r--r-- |
542 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by Claus Gittinger / 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 |
||
14 |
||
15 |
||
16 |
View subclass:#DSVColumnView |
|
607 | 17 |
instanceVariableNames:'editValue editView multipleSelectOk selectedColIndex |
637 | 18 |
selectedRowIndex rowHeight columnDescriptors viewOrigin colorMap |
618 | 19 |
lockRowIndex rowIfAbsentBlock columnHolder registererImages list |
647 | 20 |
fgColor canFit separatorSize catchChangeEvents beDependentOfRows |
892 | 21 |
bgColor hgLgFgColor hgLgBgColor actionBlock builder |
809 | 22 |
doubleClickActionBlock verticalSpacing horizontalSpacing |
824 | 23 |
rowSelectorForm buttonLightColor buttonShadowColor |
24 |
buttonHalfLightColor buttonHalfShadowColor checkToggleExtent |
|
25 |
checkToggleForm checkToggleLevel comboButtonExtent |
|
26 |
comboButtonForm comboButtonLevel clickPosition dragAccessPoint |
|
27 |
dragIsActive dropTarget dropSource' |
|
542 | 28 |
classVariableNames:'DefaultForegroundColor DefaultBackgroundColor |
29 |
DefaultHilightForegroundColor DefaultHilightBackgroundColor |
|
809 | 30 |
RowSelector ButtonLightColor ButtonShadowColor |
31 |
ButtonHalfLightColor ButtonHalfShadowColor ButtonEdgeStyle' |
|
542 | 32 |
poolDictionaries:'' |
33 |
category:'Views-DataSet' |
|
34 |
! |
|
35 |
||
36 |
!DSVColumnView class methodsFor:'documentation'! |
|
37 |
||
38 |
copyright |
|
39 |
" |
|
40 |
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG |
|
41 |
All Rights Reserved |
|
42 |
||
43 |
This software is furnished under a license and may be used |
|
44 |
only in accordance with the terms of that license and with the |
|
45 |
inclusion of the above copyright notice. This software may not |
|
46 |
be provided or otherwise made available to, or used by, any |
|
47 |
other person. No title to or ownership of the software is |
|
48 |
hereby transferred. |
|
49 |
" |
|
50 |
||
51 |
||
52 |
||
53 |
! |
|
54 |
||
55 |
documentation |
|
56 |
" |
|
57 |
implements a scrollable selection view based on rows and columns |
|
58 |
||
59 |
[Instance variables:] |
|
60 |
||
61 |
editValue <Model> current editing model |
|
62 |
editView <View> current editing component |
|
63 |
selectedColIndex <Integer> selected column index or 0 |
|
64 |
selectedRowIndex <Integer> selected row index or 0 |
|
65 |
rowHeight <Integer> maximum height of any row |
|
66 |
columnDescriptors <SequancableCollection> list of column descriptors |
|
67 |
list <SequancableCollection> list of rows |
|
68 |
fgColor <Color> foreground color |
|
69 |
registererImages <IdentityDictionary> list of images registered on the device |
|
567 | 70 |
beDependentOfRows <Coolean> keep rows dependent; on default is disabled. |
71 |
in case of enabled a row can raise a change |
|
72 |
notification whithout a parameter which |
|
73 |
will force a redraw of the row or the |
|
74 |
readSelector of the column which will |
|
75 |
redraw the cell in the row only. |
|
542 | 76 |
|
77 |
[author:] |
|
78 |
Claus Atzkern |
|
79 |
||
80 |
[see also:] |
|
81 |
DataSetColumnSpec |
|
82 |
DataSetColumn |
|
83 |
DataSetView |
|
84 |
" |
|
85 |
||
86 |
! ! |
|
87 |
||
647 | 88 |
!DSVColumnView class methodsFor:'accessing forms'! |
89 |
||
90 |
rowSelector |
|
91 |
||
92 |
RowSelector isNil ifTrue:[ |
|
93 |
RowSelector := Form |
|
607 | 94 |
width:8 |
95 |
height:11 |
|
96 |
fromArray:#[2r01000000 |
|
97 |
2r01100000 |
|
98 |
2r01110000 |
|
99 |
2r01111000 |
|
100 |
2r01111100 |
|
101 |
2r01111110 |
|
102 |
2r01111100 |
|
103 |
2r01111000 |
|
104 |
2r01110000 |
|
105 |
2r01100000 |
|
106 |
2r01000000] |
|
107 |
on:Display. |
|
108 |
||
647 | 109 |
RowSelector := RowSelector asImage. |
607 | 110 |
]. |
647 | 111 |
^ RowSelector |
112 |
||
113 |
! ! |
|
114 |
||
115 |
!DSVColumnView class methodsFor:'defaults'! |
|
607 | 116 |
|
563 | 117 |
horizontalSpacing |
118 |
^ 4 |
|
119 |
||
120 |
! |
|
121 |
||
542 | 122 |
updateStyleCache |
123 |
"extract values from the styleSheet and cache them in class variables |
|
124 |
" |
|
582 | 125 |
<resource: #style (#textForegroundColor #'scrollableView.backgroundColor' |
126 |
#'selection.hilightForegroundColor' |
|
127 |
#'selection.hilightBackgroundColor' )> |
|
542 | 128 |
|
129 |
DefaultForegroundColor := StyleSheet colorAt:'textForegroundColor' default:(Color black). |
|
809 | 130 |
DefaultBackgroundColor := StyleSheet colorAt:'scrollableView.backgroundColor' default:DefaultViewBackgroundColor. |
542 | 131 |
|
988 | 132 |
DefaultHilightForegroundColor := StyleSheet colorAt:'selection.hilightForegroundColor' default:DefaultBackgroundColor. |
133 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'selection.hilightBackgroundColor' default:DefaultForegroundColor. |
|
607 | 134 |
|
647 | 135 |
DefaultHilightForegroundColor = DefaultHilightBackgroundColor ifTrue:[ |
988 | 136 |
DefaultHilightBackgroundColor := Color black |
647 | 137 |
]. |
809 | 138 |
ButtonLightColor := StyleSheet colorAt:'button.lightColor'. |
139 |
ButtonShadowColor := StyleSheet colorAt:'button.shadowColor'. |
|
140 |
ButtonHalfLightColor := StyleSheet colorAt:'button.halfLightColor'. |
|
141 |
ButtonHalfShadowColor := StyleSheet colorAt:'button.halfShadowColor'. |
|
142 |
ButtonEdgeStyle := StyleSheet at:'button.edgeStyle'. |
|
647 | 143 |
|
542 | 144 |
" |
145 |
self updateStyleCache. |
|
146 |
" |
|
147 |
||
582 | 148 |
"Modified: / 26.10.1997 / 17:09:07 / cg" |
563 | 149 |
! |
150 |
||
151 |
verticalSpacing |
|
152 |
^ 2 |
|
153 |
||
542 | 154 |
! ! |
155 |
||
809 | 156 |
!DSVColumnView class methodsFor:'resources'! |
157 |
||
158 |
dragIconMulti |
|
988 | 159 |
"This resource specification was automatically generated |
160 |
by the ImageEditor of ST/X." |
|
161 |
||
162 |
"Do not manually edit this!! If it is corrupted, |
|
163 |
the ImageEditor may not be able to read the specification." |
|
164 |
||
809 | 165 |
" |
988 | 166 |
self dragIconMulti inspect |
167 |
ImageEditor openOnClass:self andSelector:#dragIconMulti |
|
809 | 168 |
" |
169 |
||
170 |
<resource: #image> |
|
171 |
||
172 |
^Icon |
|
173 |
constantNamed:#'DSVColumnView dragIconMulti' |
|
988 | 174 |
ifAbsentPut:[(Depth1Image new) width: 32; height: 32; photometric:(#palette); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O?<0@C??L@@<@@@@O@@@@C3??L@<??3@OO?<<C3??O@<??0@OO?<@C3???0<???<OO???C3???0<???<OO???@C???0@???<@O???@C???0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@b') ; colorMapFromArray:#[0 0 0 255 255 255]; mask:((ImageMask new) width: 32; height: 32; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@@@@@@@@@O??<@C???@@???<@O???@C????@????0O????C????0?????O????3?????????????????????????????????????????????????????@????0O???<C????@????0@@@@@@@@@@@@@@@@@@@@@b') ; yourself); yourself]! |
809 | 175 |
|
176 |
dragIconSingle |
|
988 | 177 |
"This resource specification was automatically generated |
178 |
by the ImageEditor of ST/X." |
|
179 |
||
180 |
"Do not manually edit this!! If it is corrupted, |
|
181 |
the ImageEditor may not be able to read the specification." |
|
182 |
||
809 | 183 |
" |
988 | 184 |
self dragIconSingle inspect |
185 |
ImageEditor openOnClass:self andSelector:#dragIconSingle |
|
809 | 186 |
" |
187 |
||
188 |
<resource: #image> |
|
189 |
||
190 |
^Icon |
|
191 |
constantNamed:#'DSVColumnView dragIconSingle' |
|
988 | 192 |
ifAbsentPut:[(Depth1Image new) width: 32; height: 32; photometric:(#palette); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O?<0@C??L@@??30@O?<<@C??@@@??0@@O???@C???0@???<@O???@C???0@???<@O???@C???0@???<@O???@C???0@???<@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@b') ; colorMapFromArray:#[0 0 0 255 255 255]; mask:((ImageMask new) width: 32; height: 32; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@@@@@@@@@@O??<@C???@@???<@O???@C???<@????@O???<C????@????0O???<C????@????0O???<C????@????0O???<C????@????0O???<C????@????0O???<@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@b') ; yourself); yourself]! ! |
809 | 193 |
|
886 | 194 |
!DSVColumnView methodsFor:'accessing'! |
195 |
||
196 |
columnView |
|
197 |
^ self |
|
198 |
! ! |
|
199 |
||
809 | 200 |
!DSVColumnView methodsFor:'accessing actions'! |
542 | 201 |
|
202 |
action:aOneArgAction |
|
607 | 203 |
"set the action block to be performed on select |
204 |
" |
|
542 | 205 |
actionBlock := aOneArgAction |
206 |
||
207 |
||
208 |
! |
|
209 |
||
809 | 210 |
doubleClickAction:aOneArgAction |
211 |
"set the action block to be performed on doubleclick |
|
212 |
" |
|
213 |
doubleClickActionBlock := aOneArgAction |
|
214 |
||
215 |
||
216 |
! |
|
217 |
||
218 |
rowIfAbsent:aOneArgAction |
|
219 |
"set the action block to be performed on each 'nil' entry into the |
|
220 |
list. The argument to the block is the index into the list. The |
|
221 |
block returns the row which is put to the list |
|
222 |
" |
|
223 |
rowIfAbsentBlock := aOneArgAction |
|
224 |
||
225 |
||
226 |
! ! |
|
227 |
||
228 |
!DSVColumnView methodsFor:'accessing behavior'! |
|
229 |
||
542 | 230 |
beDependentOfRows |
231 |
"make myself dependent of any row; in this case any change notification |
|
232 |
raised by a row is catched and the cell identified by the 'readSelector' |
|
233 |
is redrawn. In case of a nil readSelector, the whole raw is redrawn. |
|
234 |
-> row changed:'what' |
|
235 |
On default the attribute is set to true (enabled). |
|
236 |
" |
|
237 |
^ beDependentOfRows |
|
238 |
! |
|
239 |
||
240 |
beDependentOfRows:aBool |
|
241 |
"make myself dependent of any row; in this case any change notification |
|
242 |
raised by a row is catched and the cell identified by the 'readSelector' |
|
243 |
is redrawn. In case of a nil readSelector, the whole raw is redrawn. |
|
244 |
-> row changed:'what' |
|
245 |
On default the attribute is set to true (enabled). |
|
246 |
" |
|
247 |
aBool ~~ beDependentOfRows ifTrue:[ |
|
618 | 248 |
beDependentOfRows := aBool. |
249 |
||
250 |
self size ~~ 0 ifTrue:[ |
|
251 |
list do:[:aRow| aRow notNil ifTrue:[ |
|
252 |
beDependentOfRows ifTrue:[aRow addDependent:self] |
|
253 |
ifFalse:[aRow removeDependent:self] |
|
254 |
] |
|
255 |
] |
|
542 | 256 |
] |
618 | 257 |
] |
607 | 258 |
! |
259 |
||
260 |
multipleSelectOk |
|
261 |
"allow/disallow multiple row selections; the default is false |
|
262 |
" |
|
263 |
^ multipleSelectOk |
|
264 |
! |
|
265 |
||
266 |
multipleSelectOk:aState |
|
267 |
"allow/disallow multiple row selections; the default is false |
|
268 |
" |
|
269 |
aState == multipleSelectOk ifFalse:[ |
|
270 |
multipleSelectOk := aState. |
|
271 |
self deselect |
|
272 |
] |
|
542 | 273 |
! ! |
274 |
||
824 | 275 |
!DSVColumnView methodsFor:'accessing colors'! |
276 |
||
277 |
backgroundColor |
|
278 |
"get the background color of the rows |
|
279 |
" |
|
280 |
^ bgColor |
|
281 |
||
282 |
||
283 |
! |
|
284 |
||
285 |
backgroundColor:aColor |
|
286 |
"set the background color of the rows |
|
287 |
" |
|
288 |
bgColor ~~ aColor ifTrue:[ |
|
289 |
super viewBackground:bgColor. |
|
290 |
||
291 |
self realized ifTrue:[ |
|
292 |
bgColor := aColor on:device. |
|
293 |
self invalidate |
|
294 |
] ifFalse:[ |
|
295 |
bgColor := aColor |
|
296 |
] |
|
297 |
] |
|
298 |
! |
|
299 |
||
300 |
foregroundColor |
|
301 |
"return the foreground color of the rows |
|
302 |
" |
|
303 |
^ fgColor |
|
304 |
||
305 |
! |
|
306 |
||
307 |
foregroundColor:aColor |
|
308 |
"set the foreground color of the rows |
|
309 |
" |
|
310 |
fgColor ~~ aColor ifTrue:[ |
|
311 |
self realized ifTrue:[ |
|
312 |
fgColor := aColor on:device. |
|
313 |
self invalidate |
|
314 |
] ifFalse:[ |
|
315 |
fgColor := aColor |
|
316 |
] |
|
317 |
] |
|
318 |
||
319 |
! |
|
320 |
||
321 |
hgLgBgColor |
|
322 |
"returns the background color of a selected row |
|
323 |
" |
|
324 |
^ hgLgBgColor |
|
325 |
! |
|
326 |
||
327 |
hgLgFgColor |
|
328 |
"returns the foreground color of a selected row |
|
329 |
" |
|
330 |
^ hgLgFgColor |
|
331 |
! |
|
332 |
||
333 |
separatorDarkColor |
|
334 |
"returns the dark color used for drawing a shadowed separator (3D) |
|
335 |
" |
|
336 |
^ shadowColor |
|
337 |
||
338 |
||
339 |
! |
|
340 |
||
341 |
separatorLightColor |
|
342 |
"returns the light color used for drawing a shadowed separator (3D) |
|
343 |
" |
|
344 |
^ lightColor |
|
345 |
||
346 |
||
347 |
! ! |
|
348 |
||
542 | 349 |
!DSVColumnView methodsFor:'accessing columns'! |
350 |
||
351 |
columnAt:anIndex |
|
607 | 352 |
"returns the column at an index |
542 | 353 |
" |
354 |
^ columnDescriptors at:anIndex |
|
355 |
! |
|
356 |
||
886 | 357 |
columnDescriptors |
358 |
"returns list of column descriptors |
|
359 |
" |
|
360 |
^ columnDescriptors collect:[:aCol| aCol description ] |
|
361 |
! |
|
362 |
||
363 |
columnDescriptors:aColumnDescriptionList |
|
542 | 364 |
"set the columnDescriptors |
365 |
" |
|
612 | 366 |
|id sz| |
367 |
||
886 | 368 |
self deselect. |
369 |
||
370 |
(sz := aColumnDescriptionList size) ~~ 0 ifTrue:[ |
|
607 | 371 |
id := 0. |
372 |
||
886 | 373 |
columnDescriptors := aColumnDescriptionList collect:[:aCol||column| |
374 |
(column := aCol) isSequenceable ifTrue:[ |
|
375 |
column := DataSetColumnSpec new fromLiteralArrayEncoding:aCol |
|
376 |
]. |
|
607 | 377 |
id := id + 1. |
886 | 378 |
DataSetColumn new on:self description:column columnNumber:id |
542 | 379 |
] |
380 |
] ifFalse:[ |
|
381 |
columnDescriptors := #() |
|
382 |
]. |
|
886 | 383 |
catchChangeEvents := true. |
542 | 384 |
canFit := (columnDescriptors findFirst:[:aCol|aCol canResize]) ~~ 0. |
385 |
preferredExtent := nil. |
|
386 |
||
612 | 387 |
shown ifTrue:[ |
556 | 388 |
self fitColumns ifFalse:[ |
389 |
self invalidate. |
|
390 |
self contentsChanged. |
|
859 | 391 |
] ifTrue:[ |
392 |
self preferredExtentChanged. |
|
556 | 393 |
] |
563 | 394 |
]. |
859 | 395 |
catchChangeEvents := false. |
563 | 396 |
self changed:#sizeOfColumns. |
542 | 397 |
|
398 |
||
399 |
! |
|
400 |
||
401 |
firstColumn |
|
607 | 402 |
"returns the first column |
542 | 403 |
" |
404 |
^ columnDescriptors at:1 |
|
405 |
||
406 |
! |
|
407 |
||
408 |
lastColumn |
|
607 | 409 |
"returns the last column |
542 | 410 |
" |
411 |
^ columnDescriptors last |
|
412 |
||
413 |
! ! |
|
414 |
||
809 | 415 |
!DSVColumnView methodsFor:'accessing interactors'! |
416 |
||
417 |
checkToggleExtent |
|
418 |
^ checkToggleExtent |
|
419 |
! |
|
420 |
||
421 |
checkToggleForm |
|
422 |
^ checkToggleForm |
|
423 |
! |
|
424 |
||
425 |
checkToggleLevel |
|
426 |
^ checkToggleLevel |
|
427 |
! |
|
428 |
||
429 |
comboButtonExtent |
|
430 |
^ comboButtonExtent |
|
431 |
! |
|
432 |
||
433 |
comboButtonForm |
|
434 |
^ comboButtonForm |
|
435 |
! |
|
436 |
||
437 |
comboButtonLevel |
|
438 |
^ comboButtonLevel |
|
439 |
! |
|
440 |
||
441 |
rowSelectorExtent |
|
442 |
"returns the bitmap of a selected row |
|
443 |
" |
|
444 |
^ rowSelectorForm extent |
|
445 |
! |
|
446 |
||
447 |
rowSelectorForm |
|
448 |
"returns the bitmap of a selected row |
|
449 |
" |
|
450 |
rowSelectorForm isNil ifTrue:[ |
|
451 |
rowSelectorForm := (self class rowSelector) on:device |
|
452 |
]. |
|
453 |
^ rowSelectorForm |
|
454 |
! ! |
|
455 |
||
612 | 456 |
!DSVColumnView methodsFor:'accessing mvc'! |
457 |
||
458 |
columnHolder |
|
459 |
^ columnHolder |
|
460 |
||
461 |
! |
|
462 |
||
463 |
columnHolder:aValueHolder |
|
464 |
|columns| |
|
465 |
||
466 |
columnHolder notNil ifTrue:[ |
|
467 |
columnHolder removeDependent:self |
|
468 |
]. |
|
469 |
||
470 |
(columnHolder := aValueHolder) notNil ifTrue:[ |
|
471 |
columnHolder addDependent:self. |
|
472 |
columns := columnHolder value. |
|
473 |
||
474 |
columns notNil ifTrue:[ |
|
475 |
self columnDescriptors:columns |
|
476 |
] |
|
477 |
]. |
|
478 |
||
479 |
! ! |
|
480 |
||
542 | 481 |
!DSVColumnView methodsFor:'accessing rows'! |
482 |
||
483 |
at:aRowNr |
|
484 |
"return the row at an index, aRowNr |
|
485 |
" |
|
618 | 486 |
|row| |
487 |
||
488 |
(row := list at:aRowNr) isNil ifTrue:[ |
|
489 |
lockRowIndex := aRowNr. |
|
490 |
||
491 |
(row := rowIfAbsentBlock value:aRowNr) notNil ifTrue:[ |
|
492 |
list at:aRowNr put:row. |
|
493 |
beDependentOfRows ifTrue:[row addDependent:self]. |
|
494 |
]. |
|
495 |
||
496 |
lockRowIndex := 0 |
|
497 |
]. |
|
498 |
^ row |
|
542 | 499 |
! |
500 |
||
501 |
at:aRowNr ifAbsent:exceptionBlock |
|
607 | 502 |
"return the row at a aRowNr. If the index is invalid, return the |
542 | 503 |
result of evaluating the exceptionblock |
504 |
" |
|
618 | 505 |
(aRowNr between:1 and:self size) ifTrue:[ |
506 |
^ self at:aRowNr |
|
507 |
]. |
|
508 |
^ exceptionBlock value |
|
542 | 509 |
! |
510 |
||
511 |
at:aRowNr put:aRow |
|
512 |
"change the row at an index. The added row is returned |
|
513 |
" |
|
618 | 514 |
|row| |
515 |
||
516 |
lockRowIndex == aRowNr ifTrue:[ |
|
517 |
^ self |
|
518 |
]. |
|
519 |
row := list at:aRowNr. |
|
520 |
row == aRow ifTrue:[ |
|
521 |
^ self |
|
522 |
]. |
|
523 |
||
542 | 524 |
beDependentOfRows ifTrue:[ |
618 | 525 |
(row := list at:aRowNr) notNil ifTrue:[ |
526 |
row removeDependent:self |
|
527 |
] |
|
542 | 528 |
]. |
618 | 529 |
|
607 | 530 |
list at:aRowNr put:aRow. |
618 | 531 |
|
532 |
aRow notNil ifTrue:[ "/ free list |
|
533 |
beDependentOfRows ifTrue:[ |
|
534 |
aRow addDependent:self |
|
535 |
]. |
|
536 |
self redrawRowAt:aRowNr |
|
537 |
]. |
|
542 | 538 |
^ aRow. |
539 |
! |
|
540 |
||
541 |
first |
|
542 |
"return the first row |
|
543 |
" |
|
618 | 544 |
^ self at:1 |
545 |
! |
|
546 |
||
547 |
identityIndexOfRow:aRow |
|
548 |
"returns index of a row or 0 |
|
549 |
" |
|
550 |
(list size ~~ 0 and:[aRow notNil]) ifTrue:[ |
|
551 |
^ list identityIndexOf:aRow |
|
552 |
]. |
|
553 |
^ 0 |
|
542 | 554 |
! |
555 |
||
556 |
last |
|
557 |
"return the last row |
|
558 |
" |
|
618 | 559 |
^ self at:(self size) |
542 | 560 |
! |
561 |
||
562 |
list |
|
563 |
"get the list of rows |
|
564 |
" |
|
565 |
^ list |
|
566 |
||
567 |
||
568 |
||
569 |
! |
|
570 |
||
571 |
list:aList |
|
572 |
"set the list of rows |
|
573 |
" |
|
656 | 574 |
|makeDependent| |
575 |
||
618 | 576 |
"/ remove selection without redraw |
622 | 577 |
|
578 |
editValue notNil ifTrue:[ |
|
579 |
editValue removeDependent:self. |
|
580 |
editValue := nil |
|
581 |
]. |
|
582 |
||
618 | 583 |
editView notNil ifTrue:[ |
584 |
editView destroy. |
|
585 |
editView := nil. |
|
586 |
]. |
|
622 | 587 |
|
618 | 588 |
selectedColIndex := 0. |
589 |
selectedRowIndex := multipleSelectOk ifTrue:[nil] ifFalse:[0]. |
|
542 | 590 |
|
612 | 591 |
shown ifFalse:[ |
592 |
preferredExtent := nil |
|
593 |
] ifTrue:[ |
|
594 |
aList size ~~ 0 ifTrue:[ "/ otherwise keep old values |
|
595 |
self columnsDo:[:aCol| aCol invalidate ]. |
|
596 |
preferredExtent := nil. |
|
618 | 597 |
] |
542 | 598 |
]. |
599 |
||
656 | 600 |
(makeDependent := beDependentOfRows) ifTrue:[ |
601 |
self beDependentOfRows:false. |
|
602 |
]. |
|
643 | 603 |
|
604 |
aList size ~~ 0 ifTrue:[ |
|
605 |
list := OrderedCollection new:(aList size). |
|
645
53c78cc2ee08
redraw twice in case of expose event during adding a new entry
ca
parents:
643
diff
changeset
|
606 |
aList do:[:el| list add:el ]. |
542 | 607 |
] ifFalse:[ |
643 | 608 |
list := nil |
542 | 609 |
]. |
656 | 610 |
self beDependentOfRows:makeDependent. |
542 | 611 |
|
612 | 612 |
shown ifTrue:[ |
542 | 613 |
list size ~~ 0 ifTrue:[ |
614 |
self fitColumns ifTrue:[^ self ]. |
|
615 |
]. |
|
713 | 616 |
self recomputeHeightOfContents. |
637 | 617 |
self invalidate. |
618 |
self contentsChanged. |
|
619 |
]. |
|
620 |
||
542 | 621 |
|
622 |
||
623 |
||
624 |
! ! |
|
625 |
||
626 |
!DSVColumnView methodsFor:'accessing visibility'! |
|
627 |
||
628 |
font:aFont |
|
629 |
"set the font for all shown rows. |
|
630 |
" |
|
631 |
(aFont notNil and:[aFont ~~ font]) ifTrue:[ |
|
632 |
super font:(aFont on:device). |
|
633 |
self columnsDo:[:aCol| aCol invalidate ]. |
|
634 |
self preferredExtentChanged. |
|
635 |
||
636 |
realized ifTrue:[ |
|
637 |
self invalidate. |
|
638 |
self contentsChanged |
|
643 | 639 |
] |
542 | 640 |
] |
641 |
||
642 |
! |
|
643 |
||
607 | 644 |
has3Dseparators |
645 |
"returns true if shown in 3D mode |
|
646 |
" |
|
647 |
^ separatorSize ~~ 1 |
|
542 | 648 |
! |
649 |
||
607 | 650 |
has3Dseparators:aBool |
651 |
"enable or disable 3D mode |
|
652 |
" |
|
653 |
|newSepSize| |
|
542 | 654 |
|
637 | 655 |
newSepSize := aBool ifTrue:[2] ifFalse:[1]. |
607 | 656 |
|
657 |
newSepSize ~~ separatorSize ifTrue:[ |
|
658 |
separatorSize := newSepSize. |
|
659 |
||
542 | 660 |
self columnsDo:[:aCol| aCol invalidate ]. |
661 |
self preferredExtentChanged. |
|
662 |
||
663 |
realized ifTrue:[ |
|
664 |
self invalidate. |
|
665 |
self contentsChanged |
|
647 | 666 |
] |
542 | 667 |
] |
668 |
||
669 |
||
670 |
! |
|
671 |
||
672 |
horizontalSpacing |
|
673 |
"horizontal spacing used by columns |
|
674 |
" |
|
563 | 675 |
^ horizontalSpacing |
676 |
! |
|
677 |
||
678 |
horizontalSpacing:aNumber |
|
679 |
"horizontal spacing used by columns |
|
680 |
" |
|
681 |
horizontalSpacing ~~ aNumber ifTrue:[ |
|
682 |
horizontalSpacing := aNumber. |
|
683 |
self preferredExtentChanged. |
|
684 |
]. |
|
542 | 685 |
! |
686 |
||
687 |
verticalSpacing |
|
688 |
"vertical spacing used by columns |
|
689 |
" |
|
563 | 690 |
^ verticalSpacing |
691 |
! |
|
692 |
||
693 |
verticalSpacing:aNumber |
|
694 |
"vertical spacing used by columns |
|
695 |
" |
|
696 |
verticalSpacing ~~ aNumber ifTrue:[ |
|
697 |
verticalSpacing := aNumber. |
|
698 |
self preferredExtentChanged. |
|
699 |
]. |
|
542 | 700 |
! ! |
701 |
||
702 |
!DSVColumnView methodsFor:'adding & removing rows'! |
|
703 |
||
704 |
add:aRow |
|
618 | 705 |
"insert row at end |
542 | 706 |
" |
618 | 707 |
^ self add:aRow beforeIndex:(1 + self size) |
542 | 708 |
! |
709 |
||
710 |
add:aRow afterIndex:aRowNr |
|
711 |
"add a new row after slot aRowNr and redisplay; returns nil in case |
|
618 | 712 |
of an invalid index or the row |
542 | 713 |
" |
714 |
^ self add:aRow beforeIndex:(aRowNr + 1) |
|
715 |
! |
|
716 |
||
717 |
add:aRow beforeIndex:aRowNr |
|
718 |
"add a new row before slot aRowNr and redisplay; returns nil in case |
|
618 | 719 |
of an invalid index or the row |
542 | 720 |
" |
861 | 721 |
self addAll:(Array with:aRow) beforeIndex:aRowNr. |
722 |
^ aRow. |
|
723 |
! |
|
724 |
||
725 |
addAll:aList beforeIndex:start |
|
726 |
"add a collection of rows before slot start and redisplay |
|
727 |
" |
|
728 |
|y0 y1 yD h dH size noSel| |
|
729 |
||
730 |
(size := aList size) == 0 ifTrue:[ |
|
731 |
^ self |
|
732 |
]. |
|
733 |
||
734 |
self size == 0 ifTrue:[ |
|
735 |
^ self list:aList |
|
618 | 736 |
]. |
643 | 737 |
|
618 | 738 |
beDependentOfRows ifTrue:[ |
861 | 739 |
aList do:[:aRow| aRow notNil ifTrue:[aRow addDependent:self]] |
542 | 740 |
]. |
637 | 741 |
|
861 | 742 |
noSel := self numberOfSelections. |
743 |
||
744 |
noSel ~~ 0 ifTrue:[ |
|
745 |
multipleSelectOk ifFalse:[ |
|
746 |
selectedRowIndex >= start ifTrue:[ |
|
747 |
selectedRowIndex := selectedRowIndex + size |
|
748 |
] |
|
749 |
] ifTrue:[ |
|
750 |
1 to:noSel do:[:i||v| |
|
751 |
(v := selectedRowIndex at:i) >= start ifTrue:[ |
|
752 |
selectedRowIndex at:i put:(v + size) |
|
607 | 753 |
] |
754 |
] |
|
755 |
] |
|
542 | 756 |
]. |
861 | 757 |
list addAll:aList beforeIndex:start. |
758 |
self recomputeHeightOfContents. |
|
759 |
||
760 |
y0 := (start - 1) * rowHeight. |
|
761 |
yD := size * rowHeight. |
|
762 |
y1 := y0 + yD. |
|
542 | 763 |
|
764 |
y0 < viewOrigin y ifTrue:[ |
|
765 |
self originWillChange. |
|
861 | 766 |
viewOrigin y:(yD + viewOrigin y). |
767 |
self originChanged:(0 @ yD). |
|
768 |
]. |
|
769 |
||
770 |
(shown not or:[self sensor hasDamageFor:self]) ifTrue:[ |
|
771 |
^ self contentsChanged. |
|
542 | 772 |
]. |
645
53c78cc2ee08
redraw twice in case of expose event during adding a new entry
ca
parents:
643
diff
changeset
|
773 |
|
861 | 774 |
y0 := self yVisibleOfRowNr:start. |
775 |
y1 := y0 + yD. |
|
776 |
||
777 |
(y1 > margin and:[y0 < (h := height - margin)]) ifTrue:[ |
|
778 |
h := h - y1. |
|
779 |
y0 := y0 max:margin. |
|
780 |
dH := y1 - y0. |
|
781 |
||
782 |
start == list size ifFalse:[ |
|
783 |
self catchExpose. |
|
784 |
||
785 |
self copyFrom:self x:0 y:y0 |
|
786 |
toX:0 y:y1 |
|
787 |
width:width height:h async:true. |
|
788 |
||
789 |
self waitForExpose |
|
790 |
]. |
|
791 |
self redrawX:margin y:y0 width:width - margin - margin height:dH. |
|
542 | 792 |
]. |
793 |
self contentsChanged. |
|
861 | 794 |
|
567 | 795 |
! |
796 |
||
542 | 797 |
addFirst:aRow |
618 | 798 |
"insert a row at start |
542 | 799 |
" |
800 |
^ self add:aRow beforeIndex:1 |
|
801 |
! |
|
802 |
||
803 |
removeFirst |
|
804 |
"remove first row; returns the removed row |
|
805 |
" |
|
806 |
self removeIndex:1 |
|
807 |
! |
|
808 |
||
861 | 809 |
removeFrom:startIndex to:stopIndex |
810 |
"remove rows from start to stop |
|
542 | 811 |
" |
861 | 812 |
|coll noRedraw |
813 |
noSel "{ Class: SmallInteger }" |
|
814 |
size "{ Class: SmallInteger }" |
|
815 |
start "{ Class: SmallInteger }" |
|
816 |
stop "{ Class: SmallInteger }" |
|
817 |
y0 "{ Class: SmallInteger }" |
|
818 |
y1 "{ Class: SmallInteger }" |
|
819 |
oY "{ Class: SmallInteger }" |
|
820 |
dY "{ Class: SmallInteger }" |
|
821 |
yB "{ Class: SmallInteger }" |
|
822 |
h "{ Class: SmallInteger }" |
|
823 |
| |
|
824 |
||
825 |
( (start := startIndex) < 1 |
|
826 |
or:[(stop := stopIndex) > list size] |
|
827 |
) ifTrue:[ |
|
828 |
^ self subscriptBoundsError:start |
|
618 | 829 |
]. |
861 | 830 |
size := stop - start + 1. |
831 |
||
832 |
beDependentOfRows ifTrue:[ |
|
833 |
list from:start to:stop do:[:r| r notNil ifTrue:[r removeDependent:self]]. |
|
834 |
]. |
|
835 |
noSel := self numberOfSelections. |
|
836 |
||
837 |
noSel ~~ 0 ifTrue:[ |
|
838 |
noSel == 1 ifTrue:[ |
|
839 |
noSel := self firstIndexSelected. |
|
840 |
||
841 |
noSel < start ifFalse:[ |
|
842 |
noSel > stop ifTrue:[ |
|
843 |
noSel := noSel - size. |
|
844 |
||
845 |
multipleSelectOk ifFalse:[selectedRowIndex := noSel] |
|
846 |
ifTrue:[selectedRowIndex at:1 put:noSel] |
|
847 |
] ifFalse:[ |
|
637 | 848 |
editValue notNil ifTrue:[ |
849 |
editValue removeDependent:self. |
|
850 |
editValue := nil. |
|
851 |
]. |
|
861 | 852 |
self deselect. |
637 | 853 |
] |
607 | 854 |
] |
855 |
] ifFalse:[ |
|
861 | 856 |
coll := OrderedCollection new:noSel. |
857 |
||
858 |
selectedRowIndex do:[:i| |
|
859 |
i < start ifTrue:[ |
|
860 |
coll add:i |
|
861 |
] ifFalse:[ |
|
862 |
i > stop ifTrue:[ |
|
863 |
coll add:(i - size) |
|
864 |
] |
|
865 |
] |
|
866 |
]. |
|
867 |
coll size == 0 ifTrue:[ |
|
868 |
self deselect |
|
869 |
] ifFalse:[ |
|
870 |
selectedRowIndex := coll |
|
871 |
] |
|
542 | 872 |
] |
873 |
]. |
|
861 | 874 |
list removeFrom:start to:stop. |
875 |
||
876 |
y0 := start - 1 * rowHeight. |
|
877 |
dY := size * rowHeight. |
|
878 |
y1 := dY + y0. |
|
542 | 879 |
yB := y1 + margin - viewOrigin y. |
880 |
self recomputeHeightOfContents. |
|
881 |
||
882 |
y0 < (oY := viewOrigin y) ifTrue:[ |
|
883 |
(noRedraw := y1 <= oY) ifFalse:[dY := y0 - oY] |
|
861 | 884 |
ifTrue:[dY := dY negated]. |
542 | 885 |
self originWillChange. |
886 |
viewOrigin y:(dY + oY). |
|
887 |
self originChanged:(0 @ dY). |
|
888 |
] ifFalse:[ |
|
889 |
noRedraw := y0 > (height + viewOrigin y) |
|
890 |
]. |
|
891 |
||
892 |
(noRedraw or:[shown not]) ifFalse:[ |
|
893 |
y1 := yB. |
|
861 | 894 |
y0 := self yVisibleOfRowNr:start. |
542 | 895 |
h := height - margin - yB. |
896 |
y0 := y0 max:margin. |
|
897 |
||
561 | 898 |
h > 0 ifTrue:[ |
899 |
self catchExpose. |
|
900 |
self copyFrom:self x:0 y:yB toX:0 y:y0 width:width height:h async:true. |
|
901 |
self waitForExpose. |
|
902 |
]. |
|
542 | 903 |
y0 := y0 + h. |
643 | 904 |
self redrawX:margin y:y0 width:width - margin - margin height:(height - y0). |
542 | 905 |
]. |
906 |
self contentsChanged. |
|
861 | 907 |
|
908 |
! |
|
909 |
||
910 |
removeIndex:aRowNr |
|
911 |
"remove row at an index; returns the removed row |
|
912 |
" |
|
913 |
|row| |
|
914 |
||
915 |
row := list at:aRowNr ifAbsent:nil. |
|
916 |
self removeFrom:aRowNr to:aRowNr. |
|
917 |
^ row |
|
542 | 918 |
! |
919 |
||
920 |
removeLast |
|
921 |
"remove last row; the row is returned |
|
922 |
" |
|
618 | 923 |
^ self removeIndex:self size |
542 | 924 |
! ! |
925 |
||
892 | 926 |
!DSVColumnView methodsFor:'builder'! |
927 |
||
928 |
builder |
|
929 |
^ builder |
|
930 |
! |
|
931 |
||
932 |
builder:aBuilder |
|
933 |
builder := aBuilder |
|
934 |
! ! |
|
935 |
||
542 | 936 |
!DSVColumnView methodsFor:'change & update'! |
937 |
||
859 | 938 |
changed:aParameter with:anArgument |
939 |
"notify all dependents that the receiver has changed somehow. |
|
940 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
941 |
and anArgument as arguments." |
|
942 |
||
943 |
catchChangeEvents ifTrue:[ |
|
944 |
( aParameter == #sizeOfColumns |
|
945 |
or:[aParameter == #columnsLayout] |
|
946 |
) ifTrue:[ |
|
947 |
^ self |
|
948 |
] |
|
949 |
]. |
|
950 |
super changed:aParameter with:anArgument |
|
951 |
||
952 |
! |
|
953 |
||
542 | 954 |
update:something with:aParameter from:changedObject |
955 |
"one of my rows/cells changed its value |
|
956 |
" |
|
618 | 957 |
|row| |
542 | 958 |
|
612 | 959 |
changedObject == columnHolder ifTrue:[ |
960 |
^ self columnDescriptors:(columnHolder value) |
|
622 | 961 |
]. |
962 |
||
963 |
changedObject == editValue ifTrue:[ |
|
964 |
^ self selectedColumn at:(self firstIndexSelected) put:(editValue value) |
|
965 |
]. |
|
966 |
||
967 |
row := (something isNumber) ifTrue:[something] ifFalse:[changedObject]. |
|
809 | 968 |
self redrawVisibleRow:row readSelector:aParameter. |
969 |
||
970 |
! ! |
|
971 |
||
972 |
!DSVColumnView methodsFor:'defaults'! |
|
973 |
||
974 |
updateStyleCache |
|
975 |
"extract values from the styleSheet and cache them in class variables |
|
976 |
" |
|
977 |
<resource: #style (#textForegroundColor #'scrollableView.backgroundColor' |
|
978 |
#'selection.hilightForegroundColor' |
|
979 |
#'selection.hilightBackgroundColor' )> |
|
980 |
||
981 |
DefaultForegroundColor := StyleSheet colorAt:'textForegroundColor' default:(Color black). |
|
982 |
DefaultBackgroundColor := StyleSheet at:'scrollableView.backgroundColor' default:DefaultViewBackgroundColor. |
|
983 |
||
984 |
DefaultHilightForegroundColor := StyleSheet colorAt:'selection.hilightForegroundColor' default:DefaultForegroundColor. |
|
985 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'selection.hilightBackgroundColor' default:(Color veryLightGrey). |
|
986 |
||
987 |
DefaultHilightForegroundColor = DefaultHilightBackgroundColor ifTrue:[ |
|
988 |
DefaultHilightBackgroundColor := Color veryLightGrey |
|
989 |
]. |
|
990 |
||
991 |
ButtonLightColor := StyleSheet at:'button.lightColor'. |
|
992 |
ButtonShadowColor := StyleSheet at:'button.shadowColor'. |
|
993 |
ButtonEdgeStyle := StyleSheet at:'button.edgeStyle'. |
|
994 |
||
995 |
" |
|
996 |
self updateStyleCache. |
|
997 |
" |
|
998 |
||
999 |
"Modified: / 26.10.1997 / 17:09:07 / cg" |
|
1000 |
! ! |
|
1001 |
||
1002 |
!DSVColumnView methodsFor:'drag & drop'! |
|
1003 |
||
824 | 1004 |
canDrag |
1005 |
"returns true if dragging is enabled |
|
1006 |
" |
|
1007 |
^ dropSource notNil |
|
1008 |
||
1009 |
! |
|
1010 |
||
1011 |
dropSource |
|
1012 |
"returns the dropSource or nil |
|
809 | 1013 |
" |
824 | 1014 |
^ dropSource |
1015 |
||
1016 |
||
1017 |
! |
|
1018 |
||
1019 |
dropSource:aDropSourceOrNil |
|
1020 |
"set the dropSource or nil |
|
1021 |
" |
|
1022 |
dropSource := aDropSourceOrNil. |
|
1023 |
||
809 | 1024 |
|
1025 |
! |
|
1026 |
||
824 | 1027 |
dropTarget |
1028 |
"returns the dropTarget or nil |
|
809 | 1029 |
" |
824 | 1030 |
^ dropTarget |
1031 |
||
1032 |
! |
|
1033 |
||
1034 |
dropTarget:aDropTragetOrNil |
|
1035 |
"set the dropTarget or nil |
|
1036 |
" |
|
1037 |
dropTarget := aDropTragetOrNil. |
|
1038 |
||
1039 |
! |
|
1040 |
||
1041 |
startDragAt:aPoint |
|
1042 |
(dragIsActive not and:[dropSource notNil]) ifTrue:[ |
|
809 | 1043 |
dragIsActive := true. |
824 | 1044 |
dropSource startDragIn:self at:aPoint |
809 | 1045 |
] |
824 | 1046 |
|
542 | 1047 |
! ! |
1048 |
||
637 | 1049 |
!DSVColumnView methodsFor:'drawing'! |
1050 |
||
1051 |
colorOnDevice:aColor |
|
1052 |
"returns color on device |
|
1053 |
" |
|
1054 |
|col| |
|
1055 |
||
641 | 1056 |
aColor = Color noColor ifFalse:[ |
1057 |
col := colorMap at:aColor ifAbsent:nil. |
|
637 | 1058 |
|
641 | 1059 |
col isNil ifTrue:[ |
1060 |
colorMap at:aColor put:(col := aColor on:device) |
|
1061 |
]. |
|
1062 |
^ col |
|
637 | 1063 |
]. |
641 | 1064 |
^ bgColor |
637 | 1065 |
! |
1066 |
||
809 | 1067 |
drawEdgesAtX:x y:y width:w height:h level:aLevel |
1068 |
"draw edges |
|
1069 |
" |
|
824 | 1070 |
self drawEdgesAtX:x y:y width:w height:h level:aLevel on:self |
1071 |
! |
|
1072 |
||
1073 |
drawEdgesAtX:x y:y width:w height:h level:aLevel on:aGC |
|
1074 |
"draw edges |
|
1075 |
" |
|
1076 |
aGC drawEdgesForX:x |
|
809 | 1077 |
y:y |
1078 |
width:w |
|
1079 |
height:h |
|
1080 |
level:aLevel |
|
1081 |
shadow:buttonShadowColor |
|
1082 |
light:buttonLightColor |
|
1083 |
halfShadow:buttonHalfShadowColor |
|
1084 |
halfLight:buttonHalfLightColor |
|
1085 |
style:ButtonEdgeStyle. |
|
1086 |
||
1087 |
! |
|
1088 |
||
637 | 1089 |
forceRedraw |
1090 |
"a redraw forced by any other component |
|
1091 |
" |
|
1092 |
self redraw |
|
1093 |
! |
|
1094 |
||
1095 |
invalidate |
|
1096 |
"recompute extent before repair range |
|
1097 |
" |
|
1098 |
self recomputeHeightOfContents. |
|
1099 |
super invalidate. |
|
1100 |
||
1101 |
||
1102 |
! |
|
1103 |
||
1104 |
redraw |
|
1105 |
"redraw complete view |
|
1106 |
" |
|
1107 |
self redrawX:0 y:0 width:width height:height. |
|
1108 |
||
1109 |
! |
|
1110 |
||
1111 |
redrawRowAt:aRowNr |
|
1112 |
"redraw total row at an index |
|
1113 |
" |
|
1114 |
self redrawRowAt:aRowNr colAt:0 |
|
1115 |
! |
|
1116 |
||
1117 |
redrawRowAt:aRowNr colAt:aColNr |
|
1118 |
"redraw visible row in case of aColNr == 0 or the column in a row; |
|
1119 |
in case that the row/column is hidden no redraw is done |
|
1120 |
" |
|
1121 |
|x y h w| |
|
1122 |
||
886 | 1123 |
aRowNr isNil ifTrue:[ |
1124 |
^ self |
|
1125 |
]. |
|
1126 |
||
637 | 1127 |
(shown and:[aRowNr between:1 and:self size]) ifTrue:[ |
1128 |
h := rowHeight - 1. |
|
1129 |
||
1130 |
(y := self yVisibleOfRowNr:aRowNr) < margin ifTrue:[ |
|
1131 |
(h := h + y) <= margin ifTrue:[ |
|
1132 |
^ self |
|
1133 |
]. "/ row not visible |
|
1134 |
h := h - margin. |
|
1135 |
y := margin. |
|
1136 |
] ifFalse:[ |
|
1137 |
y >= height ifTrue:[^ self]. |
|
1138 |
]. |
|
1139 |
aColNr ~~ 0 ifTrue:[ "/ redraw column in row |
|
1140 |
w := (self columnAt:aColNr) width. |
|
1141 |
||
1142 |
(x := self xVisibleOfColNr:aColNr) < margin ifTrue:[ |
|
1143 |
(w := w + x) <= margin ifTrue:[ |
|
1144 |
^ self |
|
1145 |
]. "/ column not visible |
|
1146 |
w := w - margin. |
|
1147 |
x := margin. |
|
1148 |
] ifFalse:[ |
|
1149 |
x >= width ifTrue:[^ self]. |
|
1150 |
] |
|
1151 |
] ifFalse:[ "/ redraw whole row |
|
1152 |
x := margin. |
|
1153 |
w := width. |
|
1154 |
]. |
|
1155 |
self redrawX:x y:y width:w height:h |
|
1156 |
] |
|
1157 |
! |
|
1158 |
||
1159 |
redrawVisibleRow:aRow |
|
1160 |
"redraw row if visible |
|
1161 |
" |
|
809 | 1162 |
self redrawVisibleRow:aRow colAt:0 |
1163 |
||
1164 |
! |
|
1165 |
||
1166 |
redrawVisibleRow:aRow colAt:aColNr |
|
1167 |
"redraw row if visible |
|
1168 |
" |
|
637 | 1169 |
|start "{ Class:SmallInteger }" |
1170 |
stop "{ Class:SmallInteger }" |
|
1171 |
| |
|
1172 |
||
1173 |
(start := self indexOfFirstRowShown) ~~ 0 ifTrue:[ |
|
1174 |
stop := (start + (height // rowHeight)) min:(self size). |
|
1175 |
||
1176 |
aRow isNumber ifTrue:[ |
|
1177 |
(aRow between:start and:stop) ifTrue:[ |
|
809 | 1178 |
self redrawRowAt:aRow colAt:aColNr |
637 | 1179 |
] |
1180 |
] ifFalse:[ |
|
1181 |
start to:stop do:[:i| |
|
1182 |
(self at:i) == aRow ifTrue:[ |
|
809 | 1183 |
^ self redrawRowAt:i colAt:aColNr |
637 | 1184 |
] |
1185 |
] |
|
1186 |
] |
|
1187 |
] |
|
809 | 1188 |
|
1189 |
||
1190 |
! |
|
1191 |
||
1192 |
redrawVisibleRow:aRow readSelector:aSelector |
|
1193 |
"redraw a column identified by its read selector; if no column with |
|
1194 |
the specified read selector is detected, the whole line is drawn. |
|
1195 |
" |
|
1196 |
|row idx| |
|
1197 |
||
1198 |
aSelector isNil ifTrue:[ |
|
1199 |
idx := 0 |
|
1200 |
] ifFalse:[ |
|
1201 |
(row := aRow) isNumber ifTrue:[ |
|
1202 |
(row := self at:aRow) isNil ifTrue:[ ^ self ] |
|
1203 |
]. |
|
1204 |
idx := columnDescriptors findFirst:[:aCol||desc| |
|
1205 |
aCol description readSelector == aSelector |
|
1206 |
] |
|
1207 |
]. |
|
1208 |
self redrawVisibleRow:aRow colAt:idx |
|
1209 |
||
1210 |
||
1211 |
||
1212 |
||
637 | 1213 |
! |
1214 |
||
1215 |
redrawX:x y:y width:w height:h |
|
1216 |
"redraw part of myself immediately, given logical coordinates |
|
1217 |
" |
|
859 | 1218 |
|c0 savClip |
637 | 1219 |
start "{ Class:SmallInteger }" |
1220 |
stop "{ Class:SmallInteger }" |
|
1221 |
x0 "{ Class:SmallInteger }" |
|
1222 |
x1 "{ Class:SmallInteger }" |
|
1223 |
maxX "{ Class:SmallInteger }" |
|
643 | 1224 |
minX "{ Class:SmallInteger }" |
637 | 1225 |
yTop "{ Class:SmallInteger }" |
1226 |
yBot "{ Class:SmallInteger }" |
|
1227 |
times "{ Class:SmallInteger }" |
|
641 | 1228 |
yMax "{ Class:SmallInteger }" |
637 | 1229 |
| |
1230 |
||
1231 |
shown ifFalse:[^ self]. |
|
859 | 1232 |
|
637 | 1233 |
self paint:bgColor. |
1234 |
self fillRectangleX:x y:y width:w height:h. |
|
1235 |
||
765
dfd884a8820f
#// has been fixed to round toward negative infinity.
Stefan Vogel <sv@exept.de>
parents:
732
diff
changeset
|
1236 |
columnDescriptors size ~~ 0 ifTrue:[ |
dfd884a8820f
#// has been fixed to round toward negative infinity.
Stefan Vogel <sv@exept.de>
parents:
732
diff
changeset
|
1237 |
yTop := margin - viewOrigin y. |
dfd884a8820f
#// has been fixed to round toward negative infinity.
Stefan Vogel <sv@exept.de>
parents:
732
diff
changeset
|
1238 |
c0 := y - yTop max:0. |
637 | 1239 |
start := (c0 // rowHeight) + 1. |
643 | 1240 |
stop := (c0 + h - 1 // rowHeight + 1) min:(list size). |
637 | 1241 |
|
1242 |
(times := stop - start + 1) > 0 ifTrue:[ |
|
874 | 1243 |
savClip := clipRect. |
1244 |
||
643 | 1245 |
maxX := (x + w) min:(width - margin). |
637 | 1246 |
x0 := margin - viewOrigin x. |
1247 |
yTop := yTop + ((start - 1) * rowHeight). |
|
1248 |
yBot := yTop + (times * rowHeight). |
|
642 | 1249 |
yMax := height - margin - margin. |
643 | 1250 |
minX := x max:margin. |
1251 |
||
874 | 1252 |
columnDescriptors do:[:aCol||rW| |
643 | 1253 |
x1 := x0 + aCol width. |
637 | 1254 |
|
1255 |
(x1 > x and:[x0 < maxX]) ifTrue:[ |
|
874 | 1256 |
rW := (x1 min:maxX) - x. |
1257 |
||
1258 |
self clippingRectangle:(Rectangle left:x top:y width:rW height:h). |
|
637 | 1259 |
aCol drawFrom:start times:times x0:x0 yTop:yTop yBot:yBot with:fgColor and:bgColor. |
1260 |
]. |
|
1261 |
x0 := x1 |
|
874 | 1262 |
]. |
1263 |
self clippingRectangle:savClip. |
|
1264 |
] |
|
859 | 1265 |
]. |
637 | 1266 |
! ! |
1267 |
||
542 | 1268 |
!DSVColumnView methodsFor:'enumerating columns'! |
1269 |
||
1270 |
columnsDo:aOneArgBlock |
|
1271 |
"evaluate the argument, aOneArgBlock for every column |
|
1272 |
" |
|
1273 |
columnDescriptors do:aOneArgBlock |
|
1274 |
||
1275 |
||
1276 |
! |
|
1277 |
||
1278 |
columnsFrom:start to:stop do:aOneArgBlock |
|
1279 |
"evaluate the argument, aOneArgBlock for the columns with index start to |
|
1280 |
stop in the collection of column descriptors |
|
1281 |
" |
|
1282 |
columnDescriptors from:start to:stop do:aOneArgBlock |
|
1283 |
||
1284 |
||
1285 |
! ! |
|
1286 |
||
1287 |
!DSVColumnView methodsFor:'event handling'! |
|
1288 |
||
607 | 1289 |
buttonMotion:buttonMask x:x y:y |
1290 |
"mouse-move while button was pressed - handle multiple selection changes |
|
1291 |
" |
|
824 | 1292 |
|idx size scr p| |
607 | 1293 |
|
809 | 1294 |
dragAccessPoint notNil ifTrue:[ |
1295 |
dragIsActive ifFalse:[ |
|
824 | 1296 |
p := x @ y. |
1297 |
(clickPosition dist:p) > 5.0 ifTrue:[ self startDragAt:p ] |
|
809 | 1298 |
]. |
1299 |
^ self |
|
1300 |
]. |
|
607 | 1301 |
self sensor ctrlDown ifTrue:[^ self ]. |
1302 |
||
1303 |
(multipleSelectOk and:[selectedColIndex == 0 and:[selectedRowIndex notNil]]) ifFalse:[ |
|
1304 |
^ self |
|
1305 |
]. |
|
1306 |
"is it the select or 1-button ?" |
|
1307 |
||
1308 |
(device buttonMotionMask:buttonMask includesButton:#select) ifFalse:[ |
|
1309 |
(device buttonMotionMask:buttonMask includesButton:1) ifFalse:[ |
|
1310 |
^ self |
|
1311 |
]. |
|
1312 |
]. |
|
1313 |
scr := 0. |
|
1314 |
||
1315 |
y > height ifTrue:[ |
|
1316 |
scr := rowHeight. |
|
1317 |
idx := self yVisibleToRowNr:(height + rowHeight). |
|
1318 |
] ifFalse:[ |
|
1319 |
y < 0 ifTrue:[ |
|
1320 |
scr := rowHeight negated. |
|
1321 |
idx := self yVisibleToRowNr:scr. |
|
1322 |
] ifFalse:[ |
|
1323 |
idx := self yVisibleToRowNr:y. |
|
1324 |
] |
|
1325 |
]. |
|
643 | 1326 |
(idx isNil or:[idx < 1 or:[self isInSelection:idx]]) ifTrue:[ |
607 | 1327 |
^ self |
1328 |
]. |
|
1329 |
selectedRowIndex := selectedRowIndex asOrderedCollection. |
|
643 | 1330 |
|
1331 |
clickPosition notNil ifTrue:[ |
|
1332 |
(clickPosition - idx) abs > 1 ifTrue:[|s e| |
|
1333 |
clickPosition < idx ifTrue:[ |
|
1334 |
s := clickPosition + 1. |
|
1335 |
e := idx - 1. |
|
1336 |
] ifFalse:[ |
|
1337 |
s := idx + 1. |
|
1338 |
e := clickPosition - 1. |
|
1339 |
]. |
|
1340 |
s to:e do:[:i| |
|
1341 |
(self isInSelection:i) ifFalse:[ |
|
1342 |
selectedRowIndex add:i. |
|
1343 |
self redrawRowAt:i colAt:0. |
|
1344 |
] |
|
1345 |
] |
|
1346 |
] |
|
1347 |
]. |
|
1348 |
selectedRowIndex add:(clickPosition := idx). |
|
607 | 1349 |
|
1350 |
scr == 0 ifTrue:[ |
|
861 | 1351 |
self redrawRowAt:idx colAt:0. |
607 | 1352 |
] ifFalse:[ |
1353 |
self scrollTo:(viewOrigin + (0 @ scr)) redraw:true |
|
1354 |
]. |
|
1355 |
! |
|
1356 |
||
542 | 1357 |
buttonMultiPress:button x:x y:y |
1358 |
"a button was pressed twice - handle doubleclick here |
|
1359 |
" |
|
1360 |
((button == 1) or:[button == #select]) ifFalse:[ |
|
1361 |
^ super buttonMultiPress:button x:x y:y |
|
1362 |
]. |
|
607 | 1363 |
self numberOfSelections == 1 ifTrue:[ |
1364 |
self firstIndexSelected == (self yVisibleToRowNr:y) ifTrue:[ |
|
1365 |
( selectedColIndex == 0 |
|
1366 |
or:[selectedColIndex == (self xVisibleToColNr:x)] |
|
1367 |
) ifTrue:[ |
|
1368 |
self doubleClicked |
|
1369 |
] |
|
542 | 1370 |
] |
1371 |
] |
|
1372 |
||
1373 |
||
1374 |
||
1375 |
||
1376 |
! |
|
1377 |
||
1378 |
buttonPress:button x:x y:y |
|
1379 |
"a button was pressed - handle selection here |
|
1380 |
" |
|
637 | 1381 |
|rowNr colNr menu col sz view point| |
542 | 1382 |
|
809 | 1383 |
clickPosition := nil. |
1384 |
dragAccessPoint := nil. |
|
1385 |
dragIsActive := false. |
|
1386 |
||
667 | 1387 |
((button == 2) or:[button == #menu]) ifTrue:[ |
1388 |
(menu := self findMenuForSelection) notNil ifTrue:[ |
|
1389 |
^ menu startUp |
|
1390 |
] |
|
1391 |
] ifFalse:[ |
|
1392 |
( (button == 1 or:[button == #select]) |
|
1393 |
and:[(rowNr := self yVisibleToRowNr:y) notNil |
|
1394 |
and:[(colNr := self xVisibleToColNr:x) notNil]] |
|
1395 |
) ifTrue:[ |
|
1396 |
(multipleSelectOk not or:[self sensor ctrlDown not]) ifFalse:[ |
|
1397 |
selectedColIndex ~~ 0 ifTrue:[ |
|
1398 |
colNr := 0 |
|
1399 |
] ifFalse:[ |
|
1400 |
(sz := self numberOfSelections == 0) ifFalse:[ |
|
1401 |
(self isInSelection:rowNr) ifTrue:[ |
|
1402 |
sz == 1 ifTrue:[ |
|
1403 |
self selectColIndex:0 rowIndex:nil. |
|
1404 |
^ self sensor flushMotionEventsFor:self. |
|
1405 |
]. |
|
1406 |
selectedRowIndex remove:rowNr. |
|
1407 |
] ifFalse:[ |
|
1408 |
selectedRowIndex add:rowNr |
|
1409 |
]. |
|
1410 |
self redrawRowAt:rowNr. |
|
1411 |
self selectionChanged. |
|
1412 |
^ self sensor flushMotionEventsFor:self. |
|
607 | 1413 |
] |
667 | 1414 |
] |
1415 |
]. |
|
824 | 1416 |
(self canDrag and:[self isSelected:rowNr inColumn:colNr]) ifTrue:[ |
1417 |
clickPosition := x @ y. |
|
809 | 1418 |
dragAccessPoint := (colNr @ rowNr). |
1419 |
] ifFalse:[ |
|
1420 |
self selectRowAt:rowNr colAt:colNr atPoint:(x @ y) |
|
667 | 1421 |
]. |
1422 |
^ self |
|
542 | 1423 |
] |
1424 |
]. |
|
667 | 1425 |
super buttonPress:button x:x y:y |
1426 |
||
542 | 1427 |
|
1428 |
||
1429 |
! |
|
1430 |
||
643 | 1431 |
buttonRelease:button x:x y:y |
1432 |
||
1433 |
clickPosition notNil ifTrue:[ |
|
809 | 1434 |
dragAccessPoint notNil ifTrue:[ |
1435 |
dragIsActive ifFalse:[ |
|
1436 |
self selectRowAt:(dragAccessPoint y) |
|
1437 |
colAt:(dragAccessPoint x) |
|
1438 |
atPoint:clickPosition |
|
1439 |
]. |
|
1440 |
dragAccessPoint := nil. |
|
824 | 1441 |
dragIsActive := false. |
809 | 1442 |
] ifFalse:[ |
1443 |
self selectionChanged |
|
1444 |
]. |
|
643 | 1445 |
clickPosition := nil. |
1446 |
]. |
|
1447 |
super buttonRelease:button x:x y:y |
|
1448 |
||
1449 |
||
1450 |
! |
|
1451 |
||
809 | 1452 |
characterPress:aChar x:x y:y |
1453 |
"search row in column at x/y starting its printable label with cahracter. |
|
1454 |
" |
|
1455 |
|colNr rowNr lsize found column| |
|
1456 |
||
872
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1457 |
(rowIfAbsentBlock notNil |
896
aa07612a7c04
care for redirected messages in characterPress:
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
1458 |
or:[x isNil |
aa07612a7c04
care for redirected messages in characterPress:
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
1459 |
or:[(colNr := self xVisibleToColNr:x) isNil]]) ifTrue:[ |
809 | 1460 |
^ self |
1461 |
]. |
|
1462 |
rowNr := self lastIndexSelected. |
|
1463 |
lsize := self size. |
|
1464 |
column := self columnAt:colNr. |
|
1465 |
found := 0. |
|
1466 |
||
1467 |
lsize > rowNr ifTrue:[ |
|
1468 |
"/ search to end |
|
1469 |
found := column findRowNrStartingWithChar:aChar start:(rowNr + 1) stop:lsize. |
|
1470 |
]. |
|
1471 |
||
1472 |
(found == 0 and:[rowNr > 1]) ifTrue:[ |
|
1473 |
"/ search from begin |
|
1474 |
found := column findRowNrStartingWithChar:aChar start:1 stop:(rowNr - 1) |
|
1475 |
]. |
|
1476 |
found ~~ 0 ifTrue:[ |
|
1477 |
self selectColIndex:colNr rowIndex:found. |
|
1478 |
]. |
|
1479 |
||
896
aa07612a7c04
care for redirected messages in characterPress:
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
1480 |
"Modified: / 21.5.1998 / 03:30:22 / cg" |
809 | 1481 |
! |
1482 |
||
542 | 1483 |
contentsChanged |
1484 |
"contents changed - move origin up if possible |
|
1485 |
" |
|
1486 |
|y| |
|
1487 |
||
1488 |
shown ifTrue:[ |
|
1489 |
self recomputeHeightOfContents. |
|
1490 |
y := self maxViewOriginY. |
|
1491 |
||
1492 |
viewOrigin y > y ifTrue:[ |
|
1493 |
self scrollTo:(viewOrigin x @ y) |
|
1494 |
] ifFalse:[ |
|
1495 |
self updateEditViewOrigin. |
|
1496 |
] |
|
1497 |
]. |
|
1498 |
super contentsChanged |
|
1499 |
||
1500 |
||
1501 |
! |
|
1502 |
||
1503 |
doubleClicked |
|
1504 |
"handle a double click |
|
1505 |
" |
|
637 | 1506 |
|col sel idx| |
1507 |
||
1508 |
self hasSelection ifTrue:[ |
|
1509 |
idx := self firstIndexSelected. |
|
1510 |
col := self selectedColumn. |
|
1511 |
(col notNil and:[(sel := col doubleClickedSelector) notNil]) ifTrue:[ |
|
1512 |
(self at:idx) perform:sel |
|
1513 |
] ifFalse:[ |
|
1514 |
doubleClickActionBlock notNil ifTrue:[ |
|
1515 |
doubleClickActionBlock value:idx |
|
1516 |
] |
|
1517 |
] |
|
1518 |
] |
|
542 | 1519 |
! |
1520 |
||
667 | 1521 |
findMenuForSelection |
1522 |
"find the middle button menu for the current selection; returns the menu or nil |
|
1523 |
" |
|
1524 |
|col row menu| |
|
1525 |
||
1526 |
self numberOfSelections == 1 ifTrue:[ |
|
1527 |
row := self at:(self firstIndexSelected). |
|
1528 |
col := self selectedColumn. |
|
1529 |
||
1530 |
(col notNil and:[(menu := col menuForRow:row) notNil]) ifTrue:[ |
|
1531 |
^ menu |
|
1532 |
]. |
|
1533 |
col := columnDescriptors detect:[:c| c rendererType == #rowSelector] |
|
1534 |
ifNone:[nil]. |
|
1535 |
||
1536 |
col notNil ifTrue:[ |
|
1537 |
^ col menuForRow:row |
|
1538 |
] |
|
1539 |
]. |
|
1540 |
^ nil |
|
1541 |
! |
|
1542 |
||
542 | 1543 |
keyPress:key x:x y:y |
1544 |
"a key was pressed - handle page-keys here |
|
1545 |
" |
|
1546 |
<resource: #keyboard (#PreviousPage #NextPage #HalfPageUp #HalfPageDown |
|
809 | 1547 |
#BeginOfText #EndOfText #ScrollUp #ScrollDown |
542 | 1548 |
#CursorUp #CursorDown #CursorRight #CursorLeft)> |
1549 |
||
607 | 1550 |
|sensor n max idx col selRowNr| |
542 | 1551 |
|
809 | 1552 |
(key == #PreviousPage) ifTrue:[^ self pageUp]. |
1553 |
(key == #NextPage) ifTrue:[^ self pageDown]. |
|
1554 |
(key == #HalfPageUp) ifTrue:[^ self halfPageUp]. |
|
1555 |
(key == #HalfPageDown) ifTrue:[^ self halfPageDown]. |
|
1556 |
(key == #BeginOfText) ifTrue:[^ self scrollToTop]. |
|
1557 |
(key == #EndOfText) ifTrue:[^ self scrollToBottom]. |
|
1558 |
||
1559 |
(key isCharacter) ifTrue:[^ self characterPress:key x:x y:y ]. |
|
542 | 1560 |
|
1561 |
sensor := self sensor. |
|
1562 |
||
1563 |
(key == #ScrollUp) ifTrue:[ |
|
1564 |
sensor isNil ifTrue:[ |
|
1565 |
n := 1 |
|
1566 |
] ifFalse:[ |
|
1567 |
n := 1 + (sensor compressKeyPressEventsWithKey:#ScrollUp). |
|
1568 |
]. |
|
1569 |
^ self scrollUp:(n * self verticalScrollStep) |
|
1570 |
]. |
|
1571 |
(key == #ScrollDown) ifTrue:[ |
|
1572 |
sensor isNil ifTrue:[ |
|
1573 |
n := 1 |
|
1574 |
] ifFalse:[ |
|
1575 |
n := 1 + (sensor compressKeyPressEventsWithKey:#ScrollDown). |
|
1576 |
]. |
|
1577 |
^ self scrollDown:(n * self verticalScrollStep) |
|
1578 |
]. |
|
872
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1579 |
self numberOfSelections == 1 ifFalse:[ |
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1580 |
super keyPress:key x:x y:y. |
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1581 |
^ self |
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1582 |
]. |
607 | 1583 |
selRowNr := self firstIndexSelected. |
542 | 1584 |
|
1585 |
key == #Return ifTrue:[ |
|
1586 |
^ self doubleClicked |
|
1587 |
]. |
|
618 | 1588 |
max := self size. |
542 | 1589 |
|
1590 |
(key == #CursorUp or:[key == #CursorDown]) ifTrue:[ |
|
1591 |
sensor isNil ifTrue:[ |
|
1592 |
n := 1 |
|
1593 |
] ifFalse:[ |
|
1594 |
n := 1 + (sensor compressKeyPressEventsWithKey:key). |
|
1595 |
]. |
|
1596 |
(n := n \\ max) == 0 ifTrue:[^ self ]. |
|
1597 |
||
1598 |
key == #CursorUp ifTrue:[ |
|
607 | 1599 |
(n := selRowNr - n) <= 0 ifTrue:[n := max + n] |
542 | 1600 |
] ifFalse:[ |
607 | 1601 |
(n := selRowNr + n) > max ifTrue:[n := n - max] |
542 | 1602 |
]. |
1603 |
^ self selectColIndex:selectedColIndex rowIndex:n. |
|
1604 |
]. |
|
1605 |
||
809 | 1606 |
selectedColIndex == 0 ifTrue:[ "/ line is selected |
872
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1607 |
super keyPress:key x:x y:y. |
612 | 1608 |
^ self |
1609 |
]. |
|
1610 |
||
542 | 1611 |
(key == #CursorRight or:[key == #CursorLeft]) ifTrue:[ |
1612 |
sensor isNil ifTrue:[ |
|
1613 |
n := 1 |
|
1614 |
] ifFalse:[ |
|
1615 |
n := 1 + (sensor compressKeyPressEventsWithKey:key). |
|
1616 |
]. |
|
1617 |
idx := selectedColIndex. |
|
1618 |
max := self numberOfColumns. |
|
1619 |
||
1620 |
key == #CursorLeft ifTrue:[ |
|
1621 |
[n ~~ 0] whileTrue:[ |
|
1622 |
(idx := idx - 1) == 0 ifTrue:[idx := max]. |
|
607 | 1623 |
((self columnAt:idx) canSelect:selRowNr) ifTrue:[n := n - 1] |
542 | 1624 |
] |
1625 |
] ifFalse:[ |
|
1626 |
[n ~~ 0] whileTrue:[ |
|
1627 |
idx == max ifTrue:[idx := 1] |
|
1628 |
ifFalse:[idx := idx + 1]. |
|
607 | 1629 |
((self columnAt:idx) canSelect:selRowNr) ifTrue:[n := n - 1] |
542 | 1630 |
] |
1631 |
]. |
|
1632 |
||
607 | 1633 |
^ self selectColIndex:idx rowIndex:selRowNr. |
542 | 1634 |
]. |
1635 |
||
872
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1636 |
super keyPress:key x:x y:y |
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1637 |
|
ad92183a6e6b
pass unhandled keys up (for focus control)
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
1638 |
"Modified: / 21.4.1998 / 20:43:47 / cg" |
542 | 1639 |
! |
1640 |
||
1641 |
originChanged:delta |
|
1642 |
"this one is sent, after the origin of my contents has changed - |
|
1643 |
tell dependents (i.e. scrollers) about this |
|
1644 |
" |
|
1645 |
super originChanged:delta. |
|
1646 |
self updateEditViewOrigin. |
|
1647 |
! |
|
1648 |
||
1649 |
sizeChanged:how |
|
1650 |
"size changed - move origin up if possible |
|
1651 |
" |
|
1652 |
super sizeChanged:how. |
|
1653 |
||
1654 |
(shown and:[self numberOfColumns ~~ 0 and:[self fitColumns not]]) ifTrue:[ |
|
1655 |
self scrollTo:viewOrigin. "/ validates viewOrigin |
|
1656 |
self invalidate. |
|
1657 |
self scrollToSelection |
|
1658 |
] |
|
1659 |
||
1660 |
! ! |
|
1661 |
||
1662 |
!DSVColumnView methodsFor:'gc operations'! |
|
1663 |
||
1664 |
registerImage:anImage key:aKey |
|
1665 |
"any row can register an image with a unique identifier a key symbol |
|
1666 |
" |
|
1667 |
|img| |
|
1668 |
||
1669 |
(img := registererImages at:aKey ifAbsent:nil) notNil ifTrue:[ |
|
1670 |
^ img |
|
1671 |
]. |
|
567 | 1672 |
img := anImage onDevice:device. |
1673 |
img clearMaskedPixels. |
|
1674 |
registererImages at:aKey put:img. |
|
1675 |
^ img |
|
542 | 1676 |
! |
1677 |
||
1678 |
registeredImageAt:aKey |
|
1679 |
"any row can register an image with a unique identifier |
|
1680 |
" |
|
1681 |
^ registererImages at:aKey ifAbsent:nil |
|
1682 |
! |
|
1683 |
||
1684 |
releaseAllRegisteredImages |
|
1685 |
"release all registered images |
|
1686 |
" |
|
1687 |
registererImages := IdentityDictionary new. |
|
1688 |
! ! |
|
1689 |
||
1690 |
!DSVColumnView methodsFor:'initialization'! |
|
1691 |
||
1692 |
create |
|
607 | 1693 |
"set color on device |
542 | 1694 |
" |
1695 |
super create. |
|
1696 |
fgColor := fgColor on:device. |
|
1697 |
bgColor := bgColor on:device. |
|
1698 |
hgLgFgColor := hgLgFgColor on:device. |
|
1699 |
hgLgBgColor := hgLgBgColor on:device. |
|
809 | 1700 |
|
1701 |
buttonShadowColor := buttonShadowColor on:device. |
|
1702 |
buttonLightColor := buttonLightColor on:device. |
|
1703 |
||
1704 |
buttonHalfShadowColor notNil ifTrue:[ |
|
1705 |
buttonHalfShadowColor := buttonHalfShadowColor on:device |
|
1706 |
]. |
|
1707 |
||
1708 |
buttonHalfLightColor notNil ifTrue:[ |
|
1709 |
buttonHalfLightColor := buttonHalfLightColor on:device |
|
1710 |
]. |
|
542 | 1711 |
! |
1712 |
||
1713 |
destroy |
|
1714 |
"remove dependencies |
|
1715 |
" |
|
618 | 1716 |
self columnHolder:nil. |
1717 |
self beDependentOfRows:false. |
|
542 | 1718 |
super destroy |
1719 |
! |
|
1720 |
||
1721 |
initStyle |
|
607 | 1722 |
"setup colors |
1723 |
" |
|
809 | 1724 |
|v b| |
1725 |
||
542 | 1726 |
super initStyle. |
1727 |
||
1728 |
DefaultForegroundColor isNil ifTrue:[ |
|
1729 |
self class updateStyleCache |
|
1730 |
]. |
|
1731 |
fgColor := DefaultForegroundColor. |
|
1732 |
bgColor := DefaultBackgroundColor. |
|
1733 |
hgLgFgColor := DefaultHilightForegroundColor. |
|
1734 |
hgLgBgColor := DefaultHilightBackgroundColor. |
|
809 | 1735 |
|
1736 |
shadowColor isNil ifTrue:[ |
|
1737 |
shadowColor := Color grayPercent:40. |
|
1738 |
]. |
|
1739 |
||
1740 |
lightColor isNil ifTrue:[ |
|
1741 |
lightColor := Color grayPercent:75 |
|
1742 |
]. |
|
1743 |
||
1744 |
buttonLightColor := ButtonLightColor ? lightColor. |
|
1745 |
buttonShadowColor := ButtonShadowColor ? shadowColor. |
|
1746 |
||
1747 |
(ButtonEdgeStyle == #soft) ifTrue:[ |
|
1748 |
buttonHalfShadowColor := ButtonHalfShadowColor. |
|
1749 |
buttonHalfLightColor := ButtonHalfLightColor. |
|
1750 |
||
1751 |
buttonHalfShadowColor isNil ifTrue:[ |
|
1752 |
buttonHalfShadowColor := buttonShadowColor lightened |
|
1753 |
] |
|
1754 |
]. |
|
1755 |
||
1756 |
v := ComboBoxView new. |
|
1757 |
b := v menuButton. |
|
1758 |
||
1759 |
(comboButtonForm := b label) isImage ifTrue:[ |
|
1760 |
comboButtonForm clearMaskedPixels |
|
1761 |
]. |
|
1762 |
||
1763 |
comboButtonLevel := b offLevel. |
|
1764 |
comboButtonExtent := (b preferredExtent x) @ (v preferredExtent y). |
|
1765 |
||
1766 |
b := CheckToggle new. |
|
1767 |
||
1768 |
(checkToggleForm := CheckToggle checkFormOn:device) isImage ifTrue:[ |
|
1769 |
checkToggleForm clearMaskedPixels |
|
1770 |
]. |
|
1771 |
checkToggleLevel := b offLevel. |
|
1772 |
checkToggleExtent := b preferredExtent. |
|
1773 |
||
1774 |
||
1775 |
||
1776 |
||
1777 |
||
1778 |
||
1779 |
||
1780 |
||
1781 |
||
1782 |
||
1783 |
||
1784 |
||
542 | 1785 |
! |
1786 |
||
1787 |
initialize |
|
1788 |
"set default attributes |
|
1789 |
" |
|
1790 |
super initialize. |
|
1791 |
||
607 | 1792 |
viewOrigin := 0@0. |
1793 |
font := font on:device. |
|
1794 |
rowHeight := font height. |
|
1795 |
multipleSelectOk := false. |
|
1796 |
selectedRowIndex := selectedColIndex := 0. |
|
1797 |
registererImages := IdentityDictionary new. |
|
1798 |
separatorSize := 1. |
|
542 | 1799 |
columnDescriptors := #(). |
567 | 1800 |
beDependentOfRows := false. |
563 | 1801 |
verticalSpacing := self class verticalSpacing. |
1802 |
horizontalSpacing := self class horizontalSpacing. |
|
637 | 1803 |
colorMap := Dictionary new. |
647 | 1804 |
catchChangeEvents := false. |
809 | 1805 |
dragIsActive := false. |
637 | 1806 |
|
610 | 1807 |
self lineWidth:0. |
542 | 1808 |
! |
1809 |
||
705 | 1810 |
mapped |
1811 |
"set selection if exists after mapping |
|
1812 |
" |
|
1813 |
|idx| |
|
1814 |
||
1815 |
super mapped. |
|
1816 |
||
1817 |
idx := self firstIndexSelected. |
|
1818 |
||
1819 |
idx ~~ 0 ifTrue:[ |
|
1820 |
self scrollToRowAt:idx colAt:0. |
|
1821 |
]. |
|
1822 |
! |
|
1823 |
||
542 | 1824 |
realize |
607 | 1825 |
"recompute contents and fit columns to view |
542 | 1826 |
" |
607 | 1827 |
self bitGravity:#NorthWest. |
542 | 1828 |
self recomputeHeightOfContents. |
1829 |
super realize. |
|
607 | 1830 |
self fitColumns. |
1831 |
! ! |
|
1832 |
||
1833 |
!DSVColumnView methodsFor:'obsolete'! |
|
1834 |
||
1835 |
has3Dsepartors |
|
1836 |
"shouldn't be used any more |
|
1837 |
" |
|
1838 |
^ self has3Dseparators |
|
1839 |
! |
|
1840 |
||
1841 |
has3Dsepartors:aBool |
|
1842 |
"shouldn't be used any more |
|
1843 |
" |
|
1844 |
self has3Dseparators:aBool |
|
542 | 1845 |
|
1846 |
! ! |
|
1847 |
||
1848 |
!DSVColumnView methodsFor:'private'! |
|
1849 |
||
637 | 1850 |
detectViewAt:aPoint in:aView |
1851 |
|p| |
|
1852 |
||
1853 |
(aView notNil and:[aView subViews notNil]) ifTrue:[ |
|
1854 |
aView subViews do:[:sv| |
|
1855 |
p := device translatePoint:aPoint from:(self id) to:(sv id). |
|
1856 |
||
1857 |
(p x >= 0 and:[p y >= 0 and:[p x <= sv width and:[p y <= sv height]]]) ifTrue:[ |
|
1858 |
^ self detectViewAt:aPoint in:sv |
|
1859 |
] |
|
1860 |
] |
|
1861 |
]. |
|
1862 |
^ aView |
|
1863 |
! |
|
1864 |
||
542 | 1865 |
fitColumns |
1866 |
"fit columns to view |
|
1867 |
" |
|
859 | 1868 |
|raiseNotify lastColumn dX sz expand resizables deltaWidth| |
542 | 1869 |
|
1870 |
self canFit ifFalse:[^ false ]. |
|
647 | 1871 |
|
859 | 1872 |
resizables := 0. |
1873 |
deltaWidth := 0. |
|
1874 |
||
1875 |
preferredExtent isNil ifTrue:[ |
|
1876 |
raiseNotify := catchChangeEvents. |
|
1877 |
catchChangeEvents := true. |
|
647 | 1878 |
self preferredExtent. |
859 | 1879 |
catchChangeEvents := raiseNotify. |
1880 |
raiseNotify := raiseNotify not. |
|
1881 |
] ifFalse:[ |
|
1882 |
raiseNotify := false |
|
647 | 1883 |
]. |
542 | 1884 |
|
1885 |
self columnsDo:[:aCol| |
|
1886 |
aCol canResize ifTrue:[ |
|
1887 |
resizables := resizables + 1. |
|
1888 |
deltaWidth := aCol setMinWidth. |
|
1889 |
lastColumn := aCol. |
|
1890 |
] |
|
1891 |
]. |
|
647 | 1892 |
|
1893 |
resizables == 0 ifFalse:[ |
|
1894 |
sz := self widthOfContents. |
|
1895 |
||
1896 |
(expand := sz < width) ifTrue:[ |
|
1897 |
deltaWidth := width - sz + margin + margin |
|
1898 |
] |
|
1899 |
]. |
|
1900 |
||
1901 |
deltaWidth == 0 ifTrue:[ |
|
859 | 1902 |
raiseNotify ifTrue:[ self changed:#columnsLayout ]. |
647 | 1903 |
^ false |
542 | 1904 |
]. |
1905 |
||
1906 |
expand ifTrue:[ |
|
1907 |
(dX := deltaWidth // resizables) ~~ 0 ifTrue:[ |
|
1908 |
self columnsDo:[:aCol|aCol canResize ifTrue:[aCol growWidth:dX]] |
|
1909 |
]. |
|
1910 |
lastColumn growWidth:(deltaWidth - (dX * resizables)). |
|
1911 |
]. |
|
732 | 1912 |
|
542 | 1913 |
self preferredExtentChanged. |
612 | 1914 |
|
1915 |
shown ifTrue:[ |
|
1916 |
self invalidate. |
|
542 | 1917 |
|
612 | 1918 |
self hasSelection ifTrue:[ |
1919 |
editView notNil ifTrue:[ |
|
1920 |
editView width:(self selectedColumn width - separatorSize) |
|
1921 |
]. |
|
1922 |
self scrollToSelection. |
|
542 | 1923 |
]. |
732 | 1924 |
self contentsChanged. |
542 | 1925 |
]. |
647 | 1926 |
|
1927 |
self changed:#columnsLayout. |
|
732 | 1928 |
^ true. |
542 | 1929 |
|
1930 |
||
1931 |
! |
|
1932 |
||
1933 |
maxViewOriginY |
|
1934 |
"returns the maximum possible y of the view origin |
|
1935 |
" |
|
1936 |
|y| |
|
1937 |
||
1938 |
y := self heightOfContents - self innerHeight. |
|
1939 |
^ y max:0 |
|
1940 |
||
1941 |
! |
|
1942 |
||
1943 |
updateEditViewOrigin |
|
1944 |
"update origin of the editView |
|
1945 |
" |
|
1946 |
|x y| |
|
1947 |
||
1948 |
editView notNil ifTrue:[ |
|
607 | 1949 |
y := self yVisibleOfRowNr:(self firstIndexSelected). |
1950 |
x := self xVisibleOfColNr:(self selectedColIndex). |
|
542 | 1951 |
|
1952 |
editView origin:(x @ y). |
|
1953 |
]. |
|
1954 |
||
1955 |
! |
|
1956 |
||
1957 |
xVisibleOfColNr:aColNr |
|
1958 |
"returns visible x assigned to a column number |
|
1959 |
" |
|
1960 |
|x| |
|
1961 |
||
1962 |
x := margin - viewOrigin x. |
|
1963 |
self columnsFrom:1 to:(aColNr - 1) do:[:aCol| x := x + aCol width ]. |
|
1964 |
^ x |
|
1965 |
||
1966 |
! |
|
1967 |
||
1968 |
xVisibleToColNr:x |
|
607 | 1969 |
"returns the column number assigned to a physical x or nil |
1970 |
" |
|
542 | 1971 |
|x0 nr| |
1972 |
||
1973 |
x0 := x + viewOrigin x - margin. |
|
1974 |
nr := 1. |
|
1975 |
||
1976 |
self columnsDo:[:aCol| |
|
1977 |
(x0 := x0 - aCol width) <= 0 ifTrue:[^ nr]. |
|
1978 |
nr := nr + 1. |
|
1979 |
]. |
|
1980 |
^ nil. |
|
1981 |
||
1982 |
! |
|
1983 |
||
1984 |
yVisibleOfRowNr:aRowNr |
|
1985 |
"returns visible y assigned to the row number |
|
1986 |
" |
|
1987 |
^ (aRowNr - 1) * rowHeight + margin - viewOrigin y |
|
1988 |
||
1989 |
! |
|
1990 |
||
1991 |
yVisibleToRowNr:y |
|
607 | 1992 |
"returns the row number assigned to a physical y or nil |
542 | 1993 |
" |
1994 |
|y0| |
|
1995 |
||
1996 |
y0 := (y + viewOrigin y - margin) // rowHeight + 1. |
|
618 | 1997 |
^ (y0 <= self size) ifTrue:[y0] ifFalse:[nil] |
542 | 1998 |
|
1999 |
! ! |
|
2000 |
||
2001 |
!DSVColumnView methodsFor:'queries'! |
|
2002 |
||
2003 |
canFit |
|
2004 |
"returns true if columns can be fit to view |
|
2005 |
" |
|
2006 |
^ canFit |
|
2007 |
! |
|
2008 |
||
563 | 2009 |
indexOfFirstRowShown |
2010 |
"returns index of first row shown |
|
2011 |
" |
|
2012 |
|idx| |
|
2013 |
||
2014 |
idx := (self yOriginOfContents // rowHeight) + 1. |
|
618 | 2015 |
^ (idx <= self size) ifTrue:[idx] ifFalse:[0] |
563 | 2016 |
|
2017 |
! |
|
2018 |
||
542 | 2019 |
numberOfColumns |
2020 |
"returns number of columns |
|
2021 |
" |
|
2022 |
^ columnDescriptors size |
|
2023 |
||
2024 |
! |
|
2025 |
||
2026 |
numberOfRows |
|
2027 |
"returns number of raws |
|
2028 |
" |
|
618 | 2029 |
^ self size |
542 | 2030 |
|
2031 |
! |
|
2032 |
||
2033 |
rowHeight |
|
2034 |
"get the height of the highest row in pixels |
|
2035 |
" |
|
2036 |
^ rowHeight |
|
2037 |
||
2038 |
! |
|
2039 |
||
2040 |
separatorSize |
|
2041 |
"returns vertical/horizontal size of a separator dependent on the |
|
2042 |
3D effect. |
|
2043 |
" |
|
607 | 2044 |
^ separatorSize |
542 | 2045 |
|
2046 |
! |
|
2047 |
||
2048 |
size |
|
2049 |
"returns number of raws |
|
2050 |
" |
|
2051 |
^ list size |
|
2052 |
||
2053 |
! ! |
|
2054 |
||
2055 |
!DSVColumnView methodsFor:'recomputation'! |
|
2056 |
||
647 | 2057 |
hasPreferredExtent |
2058 |
"returns true if preferred extent is accumulated |
|
2059 |
" |
|
2060 |
^ preferredExtent notNil |
|
2061 |
! |
|
2062 |
||
542 | 2063 |
preferredExtent |
647 | 2064 |
"recompute preferred extent; raise notification |
542 | 2065 |
" |
2066 |
|x| |
|
2067 |
||
2068 |
preferredExtent notNil ifTrue:[ |
|
2069 |
^ preferredExtent |
|
2070 |
]. |
|
2071 |
x := 3. |
|
2072 |
rowHeight := 0. |
|
2073 |
||
2074 |
self columnsDo:[:aCol| |
|
2075 |
rowHeight := (aCol heightOfHighestRow) max:rowHeight. |
|
2076 |
x := x + (aCol minWidth). |
|
2077 |
]. |
|
647 | 2078 |
rowHeight := (rowHeight + separatorSize + verticalSpacing + verticalSpacing + 1) // 2 * 2. |
618 | 2079 |
preferredExtent := (x + margin + margin) @ (self size * rowHeight). |
542 | 2080 |
|
607 | 2081 |
x := (rowHeight - separatorSize - font height) // 2 + font ascent. |
542 | 2082 |
self columnsDo:[:aCol|aCol textInsetChanged:x]. |
859 | 2083 |
self changed:#columnsLayout. |
542 | 2084 |
^ preferredExtent |
2085 |
||
2086 |
||
2087 |
! |
|
2088 |
||
2089 |
preferredExtentChanged |
|
2090 |
|y x| |
|
2091 |
||
2092 |
y := viewOrigin y. |
|
2093 |
x := viewOrigin x. |
|
2094 |
||
2095 |
(y ~~ 0 or:[x ~~ 0]) ifTrue:[ |
|
2096 |
self originWillChange. |
|
2097 |
viewOrigin := 0 @ 0. |
|
2098 |
preferredExtent := nil. |
|
2099 |
self originChanged:(x negated @ y negated). |
|
2100 |
] |
|
2101 |
! |
|
2102 |
||
2103 |
recomputeHeightOfContents |
|
2104 |
||
2105 |
preferredExtent notNil ifTrue:[ |
|
618 | 2106 |
preferredExtent y:(rowHeight * self size) |
542 | 2107 |
] ifFalse:[ |
2108 |
self preferredExtent |
|
2109 |
]. |
|
2110 |
! ! |
|
2111 |
||
2112 |
!DSVColumnView methodsFor:'scroller interface'! |
|
2113 |
||
2114 |
heightOfContents |
|
2115 |
"return the height of the contents in pixels |
|
2116 |
" |
|
2117 |
^ self preferredExtent y |
|
2118 |
||
2119 |
||
2120 |
! |
|
2121 |
||
2122 |
innerHeight |
|
2123 |
"returns the inner height of the contents shown |
|
2124 |
" |
|
2125 |
^ height - margin - margin |
|
2126 |
||
2127 |
! |
|
2128 |
||
2129 |
innerWidth |
|
2130 |
"returns the inner width of the contents shown |
|
2131 |
" |
|
2132 |
^ width - margin - margin |
|
2133 |
||
2134 |
! |
|
2135 |
||
2136 |
verticalScrollStep |
|
2137 |
"return the amount to scroll when stepping up/down. |
|
2138 |
" |
|
2139 |
^ rowHeight |
|
2140 |
||
2141 |
||
2142 |
||
2143 |
! |
|
2144 |
||
2145 |
viewOrigin |
|
2146 |
"return the viewOrigin; thats the coordinate of the contents |
|
2147 |
which is shown topLeft in the view. |
|
2148 |
" |
|
2149 |
^ viewOrigin |
|
2150 |
||
2151 |
! |
|
2152 |
||
2153 |
widthOfContents |
|
2154 |
"return the width of the contents in pixels |
|
2155 |
" |
|
647 | 2156 |
preferredExtent isNil ifTrue:[ |
2157 |
self preferredExtent |
|
2158 |
]. |
|
2159 |
^ preferredExtent x |
|
542 | 2160 |
|
2161 |
! |
|
2162 |
||
2163 |
xOriginOfContents |
|
2164 |
"return the horizontal origin of the contents in pixels |
|
2165 |
" |
|
2166 |
^ viewOrigin x |
|
2167 |
||
2168 |
! |
|
2169 |
||
2170 |
yOriginOfContents |
|
2171 |
"return the vertical origin of the contents in pixels |
|
2172 |
" |
|
2173 |
^ viewOrigin y |
|
2174 |
||
2175 |
! ! |
|
2176 |
||
2177 |
!DSVColumnView methodsFor:'scrolling'! |
|
2178 |
||
2179 |
halfPageDown |
|
2180 |
"scroll down half a page |
|
2181 |
" |
|
2182 |
self scrollDown:(self innerHeight // 2) |
|
2183 |
||
2184 |
||
2185 |
! |
|
2186 |
||
2187 |
halfPageUp |
|
2188 |
"scroll up half a page |
|
2189 |
" |
|
2190 |
self scrollUp:(self innerHeight // 2) |
|
2191 |
||
2192 |
! |
|
2193 |
||
2194 |
scrollTo:anOrigin redraw:doRedraw |
|
2195 |
"change origin to have newOrigin be visible at the top-left. |
|
2196 |
" |
|
2197 |
|x y dX dY newOrg dltOrg h innerWT innerHG| |
|
2198 |
||
2199 |
shown ifFalse:[ |
|
2200 |
^ self |
|
2201 |
]. |
|
612 | 2202 |
|
542 | 2203 |
[self sensor hasExposeEventFor:nil] whileTrue:[ |
2204 |
self windowGroup processExposeEvents |
|
2205 |
]. |
|
612 | 2206 |
|
542 | 2207 |
innerWT := self innerWidth. |
2208 |
innerHG := self innerHeight. |
|
2209 |
||
2210 |
h := viewOrigin y. |
|
2211 |
||
2212 |
(y := anOrigin y) > h ifTrue:[ "/ end of contents |
|
2213 |
y > (dY := self maxViewOriginY) ifTrue:[ |
|
2214 |
y := dY max:h |
|
2215 |
] |
|
2216 |
] ifFalse:[ |
|
2217 |
y := y max:0. |
|
2218 |
]. |
|
2219 |
||
2220 |
(x := anOrigin x) > 0 ifTrue:[ |
|
2221 |
x := x min:(self widthOfContents - innerWT). |
|
2222 |
]. |
|
2223 |
x := x max:0. |
|
2224 |
newOrg := (x @ y). |
|
2225 |
dltOrg := newOrg - viewOrigin. |
|
2226 |
dX := dltOrg x. |
|
2227 |
dY := dltOrg y. |
|
2228 |
||
2229 |
(dX == 0 and:[dY == 0]) ifTrue:[ |
|
2230 |
^ self |
|
2231 |
]. |
|
2232 |
self originWillChange. |
|
2233 |
viewOrigin := newOrg. |
|
2234 |
||
2235 |
doRedraw ifFalse:[ |
|
2236 |
^ self originChanged:dltOrg |
|
2237 |
]. |
|
2238 |
||
2239 |
dY ~~ 0 ifTrue:[ "/ SCROLL VERTICAL |
|
2240 |
dY := dY abs. |
|
2241 |
||
2242 |
(dX ~~ 0 or:[innerHG - dY < 20]) ifTrue:[ |
|
2243 |
self redraw. |
|
2244 |
] ifFalse:[ "/ COPY VERTICAL |
|
2245 |
|y0 y1| |
|
2246 |
||
2247 |
y0 := y1 := margin + dY. |
|
2248 |
h := innerHG - dY. |
|
2249 |
||
2250 |
dltOrg y < 0 ifTrue:[y0 := margin. y := y0] |
|
2251 |
ifFalse:[y1 := margin. y := y1 + h]. |
|
2252 |
||
2253 |
self catchExpose. |
|
643 | 2254 |
self copyFrom:self x:margin y:y0 toX:margin y:y1 width:innerWT height:h async:true. |
542 | 2255 |
self waitForExpose. |
643 | 2256 |
self redrawX:margin y:y width:innerWT height:(innerHG - h). |
542 | 2257 |
] |
2258 |
] ifFalse:[ "/ SCROLL HORIZONTAL |
|
2259 |
dX := dX abs. |
|
2260 |
||
2261 |
innerWT - dX < 20 ifTrue:[ |
|
2262 |
self redraw. |
|
2263 |
] ifFalse:[ "/ COPY HORIZONTAL |
|
2264 |
|x0 x1 w| |
|
2265 |
||
643 | 2266 |
x0 := x1 := dX + margin. |
542 | 2267 |
w := width - dX - margin. |
2268 |
||
643 | 2269 |
dltOrg x < 0 ifTrue:[x0 := x := margin ] |
2270 |
ifFalse:[x1 := margin. x := w]. |
|
542 | 2271 |
|
2272 |
self catchExpose. |
|
643 | 2273 |
self copyFrom:self x:x0 y:margin toX:x1 y:margin width:w height:innerHG async:true. |
542 | 2274 |
self waitForExpose. |
643 | 2275 |
self redrawX:x y:margin width:(width - w) height:innerHG. |
542 | 2276 |
] |
2277 |
]. |
|
2278 |
self originChanged:dltOrg. |
|
2279 |
! |
|
2280 |
||
2281 |
scrollToRowAt:aRowNr colAt:aColNr |
|
2282 |
"make row at a row number in column at a column number visible |
|
2283 |
" |
|
2284 |
|x y l dY dX| |
|
2285 |
||
618 | 2286 |
( (aRowNr between:1 and:(self size)) |
542 | 2287 |
and:[aColNr between:0 and:(self numberOfColumns)] |
2288 |
) ifFalse:[ |
|
2289 |
^ self |
|
2290 |
]. |
|
2291 |
||
2292 |
dY := dX := 0. |
|
2293 |
y := self yVisibleOfRowNr:aRowNr. |
|
2294 |
||
2295 |
y < margin ifTrue:[ |
|
2296 |
dY := margin - y. |
|
2297 |
] ifFalse:[ |
|
2298 |
y := y + rowHeight. |
|
2299 |
l := height - margin. |
|
2300 |
y > l ifTrue:[dY := l - y] |
|
2301 |
]. |
|
2302 |
||
2303 |
aColNr == 0 ifTrue:[ |
|
2304 |
dY == 0 ifTrue:[^ self]. |
|
2305 |
dX := 0. |
|
2306 |
] ifFalse:[ |
|
2307 |
x := self xVisibleOfColNr:aColNr. |
|
2308 |
||
2309 |
x < margin ifTrue:[ |
|
2310 |
dX := margin - x |
|
2311 |
] ifFalse:[ |
|
2312 |
x := x + (self columnAt:aColNr) width. |
|
2313 |
l := width - margin. |
|
2314 |
x > l ifTrue:[dX := l - x] |
|
2315 |
] |
|
2316 |
]. |
|
2317 |
||
2318 |
(dX == 0 and:[dY == 0]) ifFalse:[ |
|
2319 |
self scrollTo:(viewOrigin - (dX @ dY)). |
|
2320 |
] |
|
2321 |
||
2322 |
||
2323 |
! |
|
2324 |
||
2325 |
scrollToSelection |
|
2326 |
"make selection visible |
|
2327 |
" |
|
607 | 2328 |
|rowNr| |
2329 |
||
2330 |
(rowNr := self firstIndexSelected) ~~ 0 ifTrue:[ |
|
2331 |
self scrollToRowAt:rowNr colAt:(self selectedColIndex) |
|
542 | 2332 |
] |
2333 |
||
2334 |
! ! |
|
2335 |
||
2336 |
!DSVColumnView methodsFor:'selection'! |
|
2337 |
||
607 | 2338 |
deselect |
2339 |
"deselect |
|
2340 |
" |
|
2341 |
self selectColIndex:0 rowIndex:0 |
|
2342 |
! |
|
2343 |
||
2344 |
firstIndexSelected |
|
809 | 2345 |
"returns index of first row selected or 0 |
607 | 2346 |
" |
2347 |
multipleSelectOk ifFalse:[ |
|
2348 |
^ selectedRowIndex |
|
2349 |
]. |
|
2350 |
selectedRowIndex size ~~ 0 ifTrue:[ |
|
2351 |
^ selectedRowIndex at:1 |
|
2352 |
]. |
|
2353 |
^ 0 |
|
2354 |
! |
|
2355 |
||
542 | 2356 |
hasSelection |
607 | 2357 |
"returns true if a selection exists |
542 | 2358 |
" |
607 | 2359 |
^ self numberOfSelections ~~ 0 |
542 | 2360 |
|
2361 |
||
2362 |
! |
|
2363 |
||
607 | 2364 |
isInSelection:aRowNr |
2365 |
"return true, if row, aRowNr is in the selection |
|
542 | 2366 |
" |
607 | 2367 |
aRowNr ~~ 0 ifTrue:[ |
2368 |
multipleSelectOk ifFalse:[ |
|
2369 |
^ aRowNr == selectedRowIndex |
|
2370 |
]. |
|
2371 |
selectedRowIndex size ~~ 0 ifTrue:[ |
|
2372 |
^ selectedRowIndex includes:aRowNr |
|
2373 |
] |
|
2374 |
]. |
|
2375 |
^ false |
|
2376 |
! |
|
2377 |
||
647 | 2378 |
isRowSelected:aRowNr |
2379 |
"return true, if row is in the selection |
|
2380 |
" |
|
2381 |
selectedColIndex == 0 ifTrue:[ |
|
2382 |
^ self isInSelection:aRowNr |
|
2383 |
]. |
|
2384 |
^ false |
|
2385 |
! |
|
2386 |
||
607 | 2387 |
isSelected:aRowNr inColumn:aColNr |
612 | 2388 |
"returns true if cell in a row; a row number, in a column, a column |
2389 |
number is selected. |
|
2390 |
" |
|
607 | 2391 |
(self isInSelection:aRowNr) ifTrue:[ |
2392 |
^ (selectedColIndex == 0 or:[selectedColIndex == aColNr]) |
|
2393 |
]. |
|
2394 |
^ false |
|
2395 |
! |
|
2396 |
||
809 | 2397 |
lastIndexSelected |
2398 |
"returns index of last row selected or 0 |
|
2399 |
" |
|
2400 |
multipleSelectOk ifFalse:[ |
|
2401 |
^ selectedRowIndex |
|
2402 |
]. |
|
2403 |
selectedRowIndex size ~~ 0 ifTrue:[ |
|
2404 |
^ selectedRowIndex last |
|
2405 |
]. |
|
2406 |
^ 0 |
|
2407 |
! |
|
2408 |
||
607 | 2409 |
numberOfSelections |
2410 |
"return the number of selected rows |
|
2411 |
" |
|
2412 |
multipleSelectOk ifFalse:[ |
|
2413 |
^ selectedRowIndex ~~ 0 ifTrue:[1] ifFalse:[0] |
|
2414 |
]. |
|
2415 |
^ selectedRowIndex size |
|
542 | 2416 |
! |
2417 |
||
2418 |
selectColIndex:aColNr rowIndex:aRowNr |
|
2419 |
"change selection with notification |
|
2420 |
" |
|
2421 |
|oC oR| |
|
2422 |
||
607 | 2423 |
oC := self selectedColIndex. |
2424 |
oR := self selectedRowIndex. |
|
542 | 2425 |
|
2426 |
self setSelectColIndex:aColNr rowIndex:aRowNr. |
|
2427 |
||
607 | 2428 |
(oC ~~ self selectedColIndex or:[oR ~= self selectedRowIndex]) ifTrue:[ |
542 | 2429 |
self selectionChanged |
2430 |
]. |
|
2431 |
! |
|
2432 |
||
607 | 2433 |
selectRow:something |
542 | 2434 |
"select a row |
2435 |
" |
|
607 | 2436 |
^ self selectedRowIndex:something |
542 | 2437 |
! |
2438 |
||
809 | 2439 |
selectRowAt:rowNr colAt:colNr atPoint:aPoint |
2440 |
|v p| |
|
2441 |
||
2442 |
self selectColIndex:colNr rowIndex:rowNr. |
|
2443 |
||
2444 |
(v := self detectViewAt:aPoint in:editView) notNil ifTrue:[ |
|
2445 |
p := device translatePoint:aPoint from:(self id) to:(v id). |
|
2446 |
||
2447 |
self sensor pushEvent:(WindowEvent buttonEvent |
|
2448 |
for:v |
|
2449 |
type:#buttonPress:x:y: |
|
2450 |
arguments:(Array with:#select with:p x with:p y) |
|
2451 |
) |
|
2452 |
]. |
|
2453 |
||
2454 |
||
2455 |
! |
|
2456 |
||
607 | 2457 |
selectRowIndex:something |
2458 |
"set selection of rows |
|
542 | 2459 |
" |
607 | 2460 |
self selectColIndex:selectedColIndex rowIndex:something |
2461 |
||
2462 |
||
542 | 2463 |
! |
2464 |
||
2465 |
selectedColIndex |
|
2466 |
"returns selected column number or 0 |
|
2467 |
" |
|
2468 |
^ selectedColIndex |
|
2469 |
! |
|
2470 |
||
2471 |
selectedColumn |
|
2472 |
"returns selected column or nil |
|
2473 |
" |
|
2474 |
^ columnDescriptors at:selectedColIndex ifAbsent:nil. |
|
2475 |
! |
|
2476 |
||
2477 |
selectedRow |
|
607 | 2478 |
"returns selected row (or collection if multiple selection) or nil |
542 | 2479 |
" |
607 | 2480 |
multipleSelectOk ifFalse:[ |
2481 |
^ self at:selectedRowIndex ifAbsent:nil |
|
2482 |
]. |
|
2483 |
||
2484 |
selectedRowIndex size ~~ 0 ifTrue:[ |
|
2485 |
^ selectedRowIndex collect:[:i| self at:i] |
|
2486 |
]. |
|
2487 |
^ nil |
|
2488 |
! |
|
2489 |
||
2490 |
selectedRow:something |
|
2491 |
"select something |
|
2492 |
" |
|
2493 |
self selectedRowIndex:something |
|
542 | 2494 |
! |
2495 |
||
2496 |
selectedRowIndex |
|
2497 |
"returns selected row number or 0 |
|
2498 |
" |
|
2499 |
^ selectedRowIndex |
|
2500 |
! |
|
2501 |
||
607 | 2502 |
selectedRowIndex:something |
2503 |
"set selection of rows |
|
2504 |
" |
|
2505 |
self selectColIndex:selectedColIndex rowIndex:something |
|
2506 |
||
2507 |
||
542 | 2508 |
! |
2509 |
||
2510 |
selectionChanged |
|
2511 |
"selection has changed |
|
2512 |
" |
|
2513 |
self changed:#selection. |
|
2514 |
||
2515 |
actionBlock notNil ifTrue:[ |
|
607 | 2516 |
actionBlock value:(self selectedRowIndex) |
2517 |
] |
|
2518 |
! |
|
2519 |
||
2520 |
selectionIndicesDo:aOneArgBlock |
|
2521 |
"evaluate block on each row selected; the argument to the row |
|
2522 |
is the index of the selected row |
|
2523 |
" |
|
2524 |
multipleSelectOk ifFalse:[ |
|
2525 |
selectedRowIndex ~~ 0 ifTrue:[ |
|
2526 |
aOneArgBlock value:selectedRowIndex |
|
2527 |
] |
|
2528 |
] ifTrue:[ |
|
2529 |
selectedRowIndex size ~~ 0 ifTrue:[ |
|
2530 |
selectedRowIndex do:[:i| aOneArgBlock value:i ] |
|
2531 |
] |
|
542 | 2532 |
] |
2533 |
! |
|
2534 |
||
2535 |
setSelectColIndex:aColNr rowIndex:aRowNr |
|
2536 |
"change selection without notification |
|
2537 |
" |
|
833 | 2538 |
|editSpec rowNr colNr newCol oldCol oldRow sensor sglSelRow index oldSz| |
542 | 2539 |
|
607 | 2540 |
rowNr := self validateSelection:aRowNr. |
542 | 2541 |
|
607 | 2542 |
multipleSelectOk ifTrue:[ |
2543 |
colNr := (rowNr size == 1) ifTrue:[aColNr] ifFalse:[0] |
|
2544 |
] ifFalse:[ |
|
2545 |
colNr := rowNr ~~ 0 ifTrue:[aColNr] ifFalse:[0] |
|
542 | 2546 |
]. |
2547 |
||
607 | 2548 |
(colNr := colNr ? 0) ~~ 0 ifTrue:[ |
2549 |
newCol := self columnAt:colNr. |
|
2550 |
newCol rendererType == #rowSelector ifTrue:[ |
|
2551 |
colNr := 0. |
|
2552 |
newCol := nil |
|
2553 |
] ifFalse:[ |
|
2554 |
multipleSelectOk ifTrue:[sglSelRow := rowNr at:1] |
|
2555 |
ifFalse:[sglSelRow := rowNr]. |
|
2556 |
||
2557 |
(newCol canSelect:sglSelRow) ifFalse:[ |
|
2558 |
newCol := nil. |
|
2559 |
colNr := 0 |
|
2560 |
] |
|
2561 |
] |
|
2562 |
]. |
|
2563 |
||
2564 |
(rowNr = selectedRowIndex and:[colNr == selectedColIndex]) ifTrue:[ |
|
643 | 2565 |
^ self |
542 | 2566 |
]. |
2567 |
||
2568 |
"/ release old selection |
|
2569 |
||
612 | 2570 |
oldSz := self numberOfSelections. |
542 | 2571 |
oldCol := selectedColIndex. |
2572 |
oldRow := selectedRowIndex. |
|
612 | 2573 |
|
542 | 2574 |
selectedRowIndex := rowNr. |
2575 |
selectedColIndex := colNr. |
|
2576 |
||
612 | 2577 |
oldSz == 1 ifTrue:[ |
2578 |
multipleSelectOk ifTrue:[oldRow := oldRow at:1]. |
|
542 | 2579 |
|
612 | 2580 |
editValue notNil ifTrue:[ |
622 | 2581 |
editValue removeDependent:self. |
612 | 2582 |
(self columnAt:oldCol) at:oldRow put:editValue value. |
2583 |
editValue := nil |
|
2584 |
]. |
|
2585 |
editView notNil ifTrue:[ |
|
2586 |
editView destroy. |
|
2587 |
editView := nil. |
|
607 | 2588 |
] |
612 | 2589 |
]. |
2590 |
shown ifFalse:[^ self ]. |
|
542 | 2591 |
|
618 | 2592 |
oldSz > 1 ifTrue:[ "/ redraw old selection |
2593 |
oldRow do:[:aRowNr| "/ unselected if visible |
|
2594 |
self redrawRowAt:aRowNr colAt:0 |
|
2595 |
] |
|
2596 |
] ifFalse:[ |
|
2597 |
oldSz == 1 ifTrue:[ |
|
2598 |
self redrawRowAt:oldRow colAt:oldCol |
|
2599 |
] |
|
2600 |
]. |
|
2601 |
||
542 | 2602 |
"/ show new selection |
2603 |
||
2604 |
newCol notNil ifTrue:[ |
|
607 | 2605 |
self scrollToRowAt:sglSelRow colAt:colNr. |
833 | 2606 |
editSpec := newCol editorAt:sglSelRow. |
2607 |
||
2608 |
editSpec notNil ifTrue:[ |
|
607 | 2609 |
editView := SimpleView extent:( (newCol width - separatorSize) |
2610 |
@ (rowHeight - separatorSize) |
|
2611 |
) |
|
2612 |
in:self. |
|
542 | 2613 |
self updateEditViewOrigin. |
2614 |
editView viewBackground:hgLgBgColor. |
|
833 | 2615 |
editView add:(editSpec at:1). |
2616 |
||
2617 |
(editValue := (editSpec at:2)) notNil ifTrue:[ |
|
809 | 2618 |
editValue addDependent:self. |
648 | 2619 |
]. |
542 | 2620 |
editView realize. |
2621 |
] ifFalse:[ |
|
607 | 2622 |
self redrawRowAt:sglSelRow colAt:colNr |
612 | 2623 |
]. |
2624 |
] ifFalse:[ |
|
2625 |
self selectionIndicesDo:[:i| self redrawRowAt:i colAt:0 ]. |
|
2626 |
self scrollToRowAt:(self firstIndexSelected) colAt:0 |
|
2627 |
]. |
|
2628 |
||
2629 |
sensor := self sensor. "/ catch expose events |
|
2630 |
||
2631 |
[sensor hasExposeEventFor:nil] whileTrue:[ |
|
2632 |
self windowGroup processExposeEvents |
|
2633 |
]. |
|
2634 |
||
542 | 2635 |
|
607 | 2636 |
! |
2637 |
||
2638 |
validateSelection:aSelection |
|
2639 |
|newSel| |
|
2640 |
||
2641 |
newSel := aSelection. |
|
2642 |
||
618 | 2643 |
(self size == 0 or:[newSel isNil or:[newSel == 0]]) ifTrue:[ |
607 | 2644 |
^ multipleSelectOk ifFalse:[0] ifTrue:[nil] |
2645 |
]. |
|
2646 |
||
2647 |
newSel isNumber ifTrue:[ |
|
2648 |
^ multipleSelectOk ifFalse:[newSel] ifTrue:[OrderedCollection with:newSel] |
|
2649 |
]. |
|
2650 |
multipleSelectOk ifFalse:[ |
|
618 | 2651 |
newSel := self identityIndexOfRow:aSelection |
607 | 2652 |
] ifTrue:[ |
2653 |
newSel := nil. |
|
2654 |
||
2655 |
aSelection size ~~ 0 ifTrue:[ |
|
2656 |
aSelection first isNumber ifTrue:[ |
|
2657 |
newSel := aSelection |
|
2658 |
] ifFalse:[ |
|
2659 |
aSelection do:[:el||n| |
|
618 | 2660 |
(n := self identityIndexOfRow:el) ~~ 0 ifTrue:[ |
607 | 2661 |
newSel isNil ifTrue:[newSel := OrderedCollection new]. |
2662 |
newSel add:n |
|
2663 |
] |
|
2664 |
] |
|
2665 |
] |
|
2666 |
] |
|
2667 |
]. |
|
2668 |
^ newSel |
|
542 | 2669 |
! ! |
2670 |
||
2671 |
!DSVColumnView class methodsFor:'documentation'! |
|
2672 |
||
2673 |
version |
|
988 | 2674 |
^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.40 1998-07-18 15:12:58 tz Exp $' |
542 | 2675 |
! ! |