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