author | Claus Gittinger <cg@exept.de> |
Fri, 20 Aug 1999 19:29:55 +0200 | |
changeset 1484 | 52b16597ce48 |
parent 1482 | b703fd600f73 |
child 1487 | fd003e2156cc |
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 |
Object subclass:#DataSetColumn |
|
1484 | 17 |
instanceVariableNames:'columnNumber dataSet width description buttonExtent shownValue |
18 |
rendererType backgroundColor rowSeparatorSelector |
|
19 |
showColSeparator showRowSeparator foregroundColor fgSelector |
|
20 |
bgSelector columnAlignment label readSelector |
|
21 |
numArgsToReadSelector columnAdaptor' |
|
607 | 22 |
classVariableNames:'' |
542 | 23 |
poolDictionaries:'' |
24 |
category:'Views-DataSet' |
|
25 |
! |
|
26 |
||
27 |
!DataSetColumn class methodsFor:'documentation'! |
|
28 |
||
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG |
|
32 |
All Rights Reserved |
|
33 |
||
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
||
42 |
||
43 |
||
44 |
! |
|
45 |
||
46 |
documentation |
|
47 |
" |
|
48 |
represent one single column description of a DataSetView |
|
49 |
||
50 |
[Instance variables:] |
|
51 |
||
647 | 52 |
columnNumber <Integer> sequence number (into list of columns) |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
53 |
|
542 | 54 |
dataSet <DSVColumnView> the view it belongs to |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
55 |
|
1088 | 56 |
width <Integer> width of column |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
57 |
|
1088 | 58 |
description <DataSetColumnSpec> the column description |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
59 |
|
1088 | 60 |
buttonExtent <Point> extent of drawable form |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
61 |
|
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
62 |
rendererType <Type> renderer type (cached value from |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
63 |
the column specification). |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
64 |
|
647 | 65 |
backgroundColor <Color or nil> background color of all cells or nil |
66 |
(nil: use default background color). |
|
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
67 |
|
647 | 68 |
foregroundColor <Color or nil> foreground color of all cells or nil |
69 |
(nil: use default foreground color). |
|
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
70 |
|
647 | 71 |
fgSelector <Selector or nil> access specific foreground color for |
72 |
a cell |
|
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
73 |
|
647 | 74 |
bgSelector <Selector or nil> access specific background color for |
75 |
a cell |
|
76 |
||
1088 | 77 |
columnAlignment <Symbol> align text/icon #left #right or #center |
78 |
in row (on default: #left). |
|
79 |
||
80 |
label <label/icon or nil> label resolved by the builder shown |
|
81 |
in the column description field. |
|
82 |
||
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
83 |
readSelector <Symbol> cached readSelector (from the spec) |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
84 |
|
1113 | 85 |
numArgsToReadSelector <Integer> number of arguments to the readSelector |
86 |
||
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
87 |
columnAdaptor <nil or any> if non-nil, that one is asked (via |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
88 |
read-writeSelectors to extract a column |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
89 |
from a row object. |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
90 |
If nil, the row object is used itself. |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
91 |
|
1113 | 92 |
showColSeparator <Boolean> true: vertical separators are enabled; |
93 |
separator between columns |
|
94 |
||
95 |
showRowSeparator <Boolean> true: horizontal separators are enabled; |
|
96 |
separator between rows |
|
97 |
||
98 |
rowSeparatorSelector <Selector or nil> access specific showRowSeparator state |
|
99 |
for a cell |
|
542 | 100 |
|
101 |
[author:] |
|
102 |
Claus Atzkern |
|
103 |
||
104 |
[see also:] |
|
105 |
DataSetColumnSpec |
|
106 |
DSVColumnView |
|
107 |
DataSetView |
|
108 |
" |
|
109 |
||
110 |
||
111 |
! ! |
|
112 |
||
113 |
!DataSetColumn methodsFor:'accessing'! |
|
114 |
||
115 |
at:aRowNr |
|
116 |
"get the value of the raw at an index, aRowNr |
|
117 |
" |
|
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
118 |
^ self extractColFromRow:(dataSet at:aRowNr). |
542 | 119 |
! |
120 |
||
121 |
at:aRowNr put:something |
|
122 |
"set the value of the raw at an index, aRowNr |
|
123 |
" |
|
1059 | 124 |
|row newRow| |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
125 |
|
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
126 |
row := dataSet at:aRowNr. |
1059 | 127 |
newRow := self storeCol:something inRow:row. |
128 |
newRow ~~ row ifTrue:[ |
|
1065
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
129 |
dataSet dataSetView listAt:aRowNr put:newRow. |
1059 | 130 |
] |
1065
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
131 |
|
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
132 |
"Modified: / 7.8.1998 / 22:17:27 / cg" |
542 | 133 |
! |
134 |
||
584 | 135 |
backgroundColor |
1113 | 136 |
"returns the background color or nil |
137 |
" |
|
138 |
^ backgroundColor == dataSet backgroundColor ifTrue:[nil] |
|
139 |
ifFalse:[backgroundColor] |
|
1133 | 140 |
|
141 |
! |
|
142 |
||
143 |
backgroundColorFor:aRowNr |
|
144 |
|bg| |
|
145 |
||
146 |
bgSelector notNil ifTrue:[ |
|
147 |
(bg := (dataSet at:aRowNr) perform:bgSelector) notNil ifTrue:[ |
|
148 |
^ bg |
|
149 |
] |
|
150 |
]. |
|
151 |
^ backgroundColor |
|
152 |
||
584 | 153 |
! |
154 |
||
807 | 155 |
description |
156 |
"returns the column description |
|
157 |
" |
|
158 |
^ description |
|
159 |
||
160 |
||
161 |
! |
|
162 |
||
584 | 163 |
foregroundColor |
1113 | 164 |
"returns the foreground color or nil |
165 |
" |
|
166 |
^ foregroundColor == dataSet foregroundColor ifTrue:[nil] |
|
167 |
ifFalse:[foregroundColor] |
|
1133 | 168 |
|
584 | 169 |
! |
170 |
||
542 | 171 |
label |
172 |
"get the label assigned to the column |
|
173 |
" |
|
891 | 174 |
^ label |
542 | 175 |
|
176 |
||
177 |
! |
|
178 |
||
1484 | 179 |
minWidth |
180 |
"get my minimum width required by the column |
|
181 |
" |
|
182 |
|width| |
|
183 |
||
184 |
width := description minWidth. |
|
185 |
^ width == 0 ifTrue:[self width] ifFalse:[width] |
|
186 |
||
187 |
||
188 |
! |
|
189 |
||
647 | 190 |
rendererType |
191 |
"returns my renderer type |
|
192 |
" |
|
193 |
^ rendererType |
|
194 |
! |
|
195 |
||
542 | 196 |
width |
197 |
"returns the width in pixels |
|
198 |
" |
|
1484 | 199 |
|max "{ Class:SmallInteger }"| |
542 | 200 |
|
1484 | 201 |
width notNil ifTrue:[^ width]. "/ already computed |
542 | 202 |
|
1484 | 203 |
(width := description width) isReal ifTrue:[ |
204 |
width := (width * dataSet width) rounded. |
|
205 |
]. |
|
1482 | 206 |
|
1484 | 207 |
(width := width max:(description minWidth)) ~~ 0 ifTrue:[ |
208 |
^ width |
|
1482 | 209 |
]. |
210 |
||
1484 | 211 |
self containsText ifTrue:[ |
212 |
"/ take maximum 5 entries to calculate the width; |
|
213 |
"/ can be resized later if neccessary |
|
542 | 214 |
|
1484 | 215 |
max := 5 min:dataSet size. |
542 | 216 |
|
1484 | 217 |
1 to:max do:[:i| |
218 |
width := width max:(self widthOfLabel:(shownValue value:(dataSet at:i))) |
|
219 |
]. |
|
220 |
description editorType ~~ #None ifTrue:[ |
|
221 |
width := width + (dataSet font widthOn:dataSet device) |
|
542 | 222 |
]. |
1484 | 223 |
]. |
224 |
width := width + buttonExtent x. |
|
1187 | 225 |
|
1484 | 226 |
label notNil ifTrue:[ |
227 |
width := width max:(4 + (label preferredExtent x)) |
|
542 | 228 |
]. |
1484 | 229 |
^ width := width + dataSet separatorSize + (2 * dataSet horizontalSpacing). |
230 |
||
231 |
||
542 | 232 |
! |
233 |
||
234 |
width:aWidth |
|
235 |
"set the width |
|
236 |
" |
|
1484 | 237 |
width := aWidth max:(description minWidth) |
542 | 238 |
|
239 |
! ! |
|
240 |
||
241 |
!DataSetColumn methodsFor:'drawing'! |
|
242 |
||
1147 | 243 |
drawLabel:aLabel atX:xLeft y:yTop |
244 |
"redraw label |
|
245 |
" |
|
246 |
|x space| |
|
247 |
||
248 |
space := dataSet horizontalSpacing. |
|
249 |
||
250 |
columnAlignment == #left ifTrue:[ |
|
251 |
x := xLeft + space. |
|
252 |
] ifFalse:[ |
|
253 |
x := width - (aLabel widthOn:dataSet). |
|
254 |
||
255 |
columnAlignment == #right ifTrue:[x := x - space] |
|
256 |
ifFalse:[x := x // 2]. |
|
1447 | 257 |
x := xLeft + (x max:0). |
1147 | 258 |
]. |
1447 | 259 |
|
1147 | 260 |
aLabel isImageOrForm ifTrue:[ |
261 |
aLabel displayOn:dataSet x:x y:yTop. |
|
262 |
^ self |
|
263 |
]. |
|
264 |
||
265 |
aLabel displayOn:dataSet x:x y:(yTop + dataSet rowFontAscent) |
|
266 |
! |
|
267 |
||
1132 | 268 |
drawLabelsAtX:xLeft y:yTop h:h from:start to:stop |
269 |
"redraw labels from start to stop |
|
1088 | 270 |
" |
1113 | 271 |
|fg bg label row isSel |
1132 | 272 |
y "{ Class:SmallInteger }" |
273 |
yT "{ Class:SmallInteger }" |
|
274 |
x "{ Class:SmallInteger }" |
|
275 |
hspace "{ Class:SmallInteger }" |
|
276 |
ascent "{ Class:SmallInteger }" |
|
1147 | 277 |
lblHg "{ Class:SmallInteger }" |
1088 | 278 |
| |
1132 | 279 |
yT := yTop. |
280 |
ascent := dataSet rowFontAscent. |
|
281 |
hspace := dataSet horizontalSpacing. |
|
1100 | 282 |
|
1132 | 283 |
start to:stop do:[:anIndex| |
284 |
row := dataSet at:anIndex. |
|
285 |
y := yT. |
|
286 |
x := xLeft. |
|
287 |
||
288 |
"/ GET BACKGROUND AND FOREGROUND-COLOR |
|
289 |
"/ =================================== |
|
290 |
||
291 |
isSel := dataSet isSelected:anIndex inColumn:columnNumber. |
|
292 |
||
293 |
isSel ifTrue:[ |
|
294 |
( description editorType ~~ #None |
|
295 |
and:[dataSet selectedColIndex == columnNumber] |
|
296 |
) ifTrue:[ |
|
297 |
isSel := false |
|
1115 | 298 |
] |
1113 | 299 |
]. |
300 |
||
1132 | 301 |
(isSel and:[description showSelectionHighLighted]) ifTrue:[ |
302 |
"/ SHOW SELECTED( MUST REDRAW BACKGROUND ) |
|
303 |
"/ ======================================= |
|
304 |
fg := dataSet hgLgFgColor. |
|
305 |
bg := dataSet hgLgBgColor. |
|
306 |
dataSet paint:bg. |
|
307 |
dataSet fillRectangleX:x y:y width:width height:h. |
|
1113 | 308 |
] ifFalse:[ |
1132 | 309 |
bgSelector notNil ifTrue:[ |
310 |
"/ MUST REDRAW BACKGROUND |
|
311 |
"/ ====================== |
|
312 |
(bg := row perform:bgSelector) notNil ifTrue:[ |
|
313 |
bg := dataSet colorOnDevice:bg |
|
314 |
] ifFalse:[ |
|
315 |
bg := backgroundColor |
|
316 |
]. |
|
317 |
dataSet paint:bg. |
|
318 |
dataSet fillRectangleX:x y:y width:width height:h. |
|
319 |
] ifFalse:[ |
|
320 |
bg := backgroundColor |
|
321 |
]. |
|
1100 | 322 |
|
1132 | 323 |
(fgSelector notNil and:[(fg := row perform:fgSelector) notNil]) ifTrue:[ |
324 |
fg := dataSet colorOnDevice:fg |
|
325 |
] ifFalse:[ |
|
326 |
fg := foregroundColor |
|
327 |
] |
|
328 |
]. |
|
833 | 329 |
|
1132 | 330 |
"/ GET AND DRAW LABEL |
331 |
"/ ================== |
|
332 |
rendererType == #rowSelector ifTrue:[ |
|
333 |
isSel ifTrue:[ |
|
334 |
label := dataSet rowSelectorForm. |
|
335 |
x := x + hspace. |
|
336 |
] ifFalse:[ |
|
337 |
label := nil |
|
338 |
] |
|
1113 | 339 |
] ifFalse:[ |
1147 | 340 |
(isSel and:[dataSet hasOpenEditor]) ifTrue:[ |
341 |
label := nil |
|
342 |
] ifFalse:[ |
|
343 |
label := shownValue value:row |
|
1132 | 344 |
] |
345 |
]. |
|
346 |
label notNil ifTrue:[ |
|
1147 | 347 |
lblHg := self heightOfLabel:label. |
348 |
||
349 |
lblHg ~~ 0 ifTrue:[ |
|
350 |
y := y + (h - lblHg // 2). |
|
351 |
dataSet paint:fg on:bg. |
|
1113 | 352 |
|
1147 | 353 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
354 |
self drawLabel:label atX:x y:y |
|
355 |
] ifTrue:[ |
|
356 |
label do:[:el| |
|
357 |
el notNil ifTrue:[ |
|
358 |
self drawLabel:el atX:x y:y. |
|
359 |
y := y + (el heightOn:dataSet). |
|
360 |
] |
|
361 |
] |
|
362 |
]. |
|
363 |
] |
|
1132 | 364 |
]. |
365 |
yT := yT + h |
|
366 |
] |
|
1113 | 367 |
|
833 | 368 |
|
369 |
! |
|
370 |
||
1132 | 371 |
drawSeparatorsAtX:xLeft y:yTop h:h from:start to:stop |
372 |
"redraw separators for cells between start and stop |
|
1088 | 373 |
" |
1132 | 374 |
|is3D |
375 |
xL "{ Class:SmallInteger }" |
|
1113 | 376 |
xR "{ Class:SmallInteger }" |
377 |
yB "{ Class:SmallInteger }" |
|
378 |
yT "{ Class:SmallInteger }" |
|
1132 | 379 |
times "{ Class:SmallInteger }" |
1088 | 380 |
| |
1132 | 381 |
(showColSeparator or:[showRowSeparator]) ifFalse:[ |
382 |
^ self |
|
383 |
]. |
|
384 |
is3D := dataSet has3Dseparators. |
|
385 |
||
1113 | 386 |
is3D ifTrue:[dataSet paint:(dataSet separatorDarkColor)] |
387 |
ifFalse:[dataSet paint:(dataSet foregroundColor)]. |
|
1088 | 388 |
|
1132 | 389 |
times := stop - start + 1. |
390 |
xL := xLeft. |
|
391 |
xR := xL - 1 + width. |
|
1088 | 392 |
|
1113 | 393 |
showRowSeparator ifTrue:[ |
1132 | 394 |
"/ DRAW SEPARATORS AT BOTTOM( DARK COLOR ) |
395 |
"/ ======================================= |
|
396 |
yB := yTop - 1 + h. |
|
397 |
||
398 |
rowSeparatorSelector isNil ifTrue:[ |
|
399 |
times timesRepeat:[ |
|
400 |
dataSet displayLineFromX:xL y:yB toX:xR y:yB. |
|
401 |
yB := yB + h. |
|
402 |
] |
|
403 |
] ifFalse:[ |
|
404 |
start to:stop do:[:idx| |
|
405 |
((dataSet at:idx) perform:rowSeparatorSelector) ~~ false ifTrue:[ |
|
406 |
dataSet displayLineFromX:xL y:yB toX:xR y:yB |
|
407 |
]. |
|
408 |
yB := yB + h. |
|
409 |
] |
|
1113 | 410 |
] |
411 |
]. |
|
1132 | 412 |
|
1113 | 413 |
showColSeparator ifTrue:[ |
1132 | 414 |
"/ DRAW SEPARATORS AT RIGHT( DARK COLOR ) |
415 |
"/ ====================================== |
|
416 |
yT := yTop. |
|
417 |
||
418 |
times timesRepeat:[ |
|
419 |
dataSet displayLineFromX:xR y:yT toX:xR y:(yT - 1 + h). |
|
420 |
yT := yT + h. |
|
421 |
] |
|
1113 | 422 |
]. |
1089 | 423 |
|
1113 | 424 |
is3D ifFalse:[ |
425 |
^ self |
|
426 |
]. |
|
1088 | 427 |
|
1113 | 428 |
dataSet paint:(dataSet separatorLightColor). |
1040
c8e6a2ed7928
use the same background color for a selected rowSelector
ca
parents:
1007
diff
changeset
|
429 |
|
1113 | 430 |
( columnNumber == 1 |
431 |
or:[(dataSet columnAt:(columnNumber - 1)) showColSeparator] |
|
432 |
) ifTrue:[ |
|
1132 | 433 |
|
434 |
"/ DRAW SEPARATORS AT LEFT( LIGHT COLOR ) |
|
435 |
"/ ====================================== |
|
436 |
yT := yTop. |
|
437 |
||
438 |
times timesRepeat:[ |
|
439 |
dataSet displayLineFromX:xL y:yT toX:xL y:(yT - 1 + h). |
|
440 |
yT := yT + h. |
|
441 |
]. |
|
1113 | 442 |
] ifFalse:[ |
1132 | 443 |
xL := xL - 1 |
1113 | 444 |
]. |
1092 | 445 |
|
1113 | 446 |
showRowSeparator ifTrue:[ |
1132 | 447 |
"/ DRAW SEPARATORS AT TOP( LIGHT COLOR ) |
448 |
"/ ===================================== |
|
449 |
yT := yTop. |
|
450 |
||
451 |
rowSeparatorSelector isNil ifTrue:[ |
|
452 |
times timesRepeat:[ |
|
453 |
dataSet displayLineFromX:xL y:yT toX:xR y:yT. |
|
454 |
yT := yT + h. |
|
455 |
] |
|
456 |
] ifFalse:[ |
|
457 |
"/ CHECK WHETHER PREVIOUS ROW HAS A SEPARATOR AT BOTTOM |
|
458 |
"/ ==================================================== |
|
459 |
start to:stop do:[:idx| |
|
460 |
( idx == 1 |
|
461 |
or:[((dataSet at:(idx - 1)) perform:rowSeparatorSelector) ~~ false] |
|
462 |
) ifTrue:[ |
|
463 |
dataSet displayLineFromX:xL y:yT toX:xR y:yT. |
|
464 |
]. |
|
465 |
yT := yT + h. |
|
466 |
] |
|
1088 | 467 |
] |
542 | 468 |
]. |
469 |
||
470 |
||
607 | 471 |
! |
472 |
||
542 | 473 |
invalidate |
1484 | 474 |
"invalidate width of column; forces a recomputation |
542 | 475 |
" |
1484 | 476 |
width := nil. |
542 | 477 |
|
1088 | 478 |
! |
479 |
||
1132 | 480 |
redrawX:xLeft y:yTop h:h from:start to:stop |
1088 | 481 |
"redraw rows between start and stop |
482 |
" |
|
1132 | 483 |
|rH "{ Class:SmallInteger }" |
484 |
y "{ Class:SmallInteger }" |
|
1088 | 485 |
| |
1132 | 486 |
rH := dataSet rowHeight. |
1088 | 487 |
|
1115 | 488 |
bgSelector isNil ifTrue:[ |
1132 | 489 |
dataSet paint:backgroundColor. |
490 |
dataSet fillRectangleX:xLeft y:yTop width:width height:h |
|
1115 | 491 |
]. |
492 |
||
1132 | 493 |
"/ DRAW CELLS: BACKGROUND/FOREGROUND/LABEL |
494 |
"/ ======================================= |
|
495 |
self drawLabelsAtX:xLeft y:yTop h:rH from:start to:stop. |
|
1113 | 496 |
|
497 |
"/ DRAW INDICATORS |
|
498 |
"/ =============== |
|
499 |
(rendererType == #ComboBox or:[rendererType == #ComboList]) ifTrue:[ |
|
1132 | 500 |
y := yTop. |
501 |
start to:stop do:[:i| |
|
502 |
(self hasChoices:i) ifTrue:[ |
|
503 |
dataSet drawComboButtonAtX:xLeft y:y w:width |
|
1113 | 504 |
]. |
1132 | 505 |
y := y + rH. |
1113 | 506 |
] |
507 |
] ifFalse:[ |
|
508 |
rendererType == #CheckToggle ifTrue:[ |
|
1132 | 509 |
y := yTop. |
510 |
start to:stop do:[:i| |
|
511 |
dataSet drawCheckToggleAtX:xLeft y:y w:width |
|
512 |
state:(self extractColFromRow:(dataSet at:i)). |
|
513 |
y := y + rH. |
|
1113 | 514 |
] |
515 |
] |
|
1088 | 516 |
]. |
517 |
||
518 |
"/ DRAW SEPARATORS |
|
1113 | 519 |
"/ =============== |
1132 | 520 |
self drawSeparatorsAtX:xLeft y:yTop h:rH from:start to:stop |
542 | 521 |
! ! |
522 |
||
614 | 523 |
!DataSetColumn methodsFor:'editing'! |
524 |
||
833 | 525 |
editorAt:aRowNr |
1268 | 526 |
|val row| |
614 | 527 |
|
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
528 |
row := (dataSet at:aRowNr). |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
529 |
val := self extractColFromRow:row. |
614 | 530 |
|
833 | 531 |
val isText ifTrue:[val := val string]. |
532 |
^ description editorOn:row value:val. |
|
614 | 533 |
! ! |
534 |
||
542 | 535 |
!DataSetColumn methodsFor:'event handling'! |
536 |
||
537 |
doesNotUnderstand:aMessage |
|
538 |
||
539 |
(description respondsTo:(aMessage selector)) ifTrue:[ |
|
540 |
^ aMessage sendTo:description |
|
541 |
]. |
|
542 |
^ super doesNotUnderstand:aMessage |
|
543 |
||
544 |
! ! |
|
545 |
||
546 |
!DataSetColumn methodsFor:'grow & degrow'! |
|
547 |
||
548 |
growWidth:n |
|
549 |
"grow the width for n pixels |
|
550 |
" |
|
551 |
width := width + n. |
|
552 |
||
553 |
||
554 |
! ! |
|
555 |
||
556 |
!DataSetColumn methodsFor:'initialization'! |
|
557 |
||
1147 | 558 |
on:aDSVColumnView description:aDescription columnNumber:aNumber label:aLabel |
542 | 559 |
"instance creation; set attributes dependent on the description |
560 |
" |
|
1268 | 561 |
|device selector format idx type args| |
542 | 562 |
|
1089 | 563 |
columnNumber := aNumber. |
564 |
dataSet := aDSVColumnView. |
|
1147 | 565 |
label := aLabel. |
1089 | 566 |
description := aDescription. |
567 |
rendererType := description rendererType. |
|
568 |
width := nil. |
|
569 |
device := dataSet device. |
|
1147 | 570 |
shownValue := [:aRow| nil ]. |
1113 | 571 |
rowSeparatorSelector := description rowSeparatorSelector. |
1089 | 572 |
fgSelector := description foregroundSelector. |
573 |
bgSelector := description backgroundSelector. |
|
1113 | 574 |
showColSeparator := description showColSeparator. |
575 |
showRowSeparator := description showRowSeparator. |
|
1089 | 576 |
columnAdaptor := dataSet columnAdaptor. |
577 |
buttonExtent := 0 @ 0. |
|
578 |
columnAlignment := #left. |
|
584 | 579 |
|
1113 | 580 |
(readSelector := description readSelector) notNil ifTrue:[ |
581 |
numArgsToReadSelector := readSelector numArgs. |
|
582 |
] ifFalse:[ |
|
583 |
numArgsToReadSelector := 0 |
|
584 |
]. |
|
585 |
||
1132 | 586 |
(backgroundColor := description backgroundColor) isNil ifTrue:[ |
587 |
backgroundColor := dataSet backgroundColor |
|
588 |
] ifFalse:[ |
|
1480 | 589 |
backgroundColor := backgroundColor onDevice:dataSet device |
584 | 590 |
]. |
1113 | 591 |
|
592 |
(foregroundColor := description foregroundColor) isNil ifTrue:[ |
|
593 |
foregroundColor := dataSet foregroundColor |
|
594 |
] ifFalse:[ |
|
1480 | 595 |
foregroundColor := foregroundColor onDevice:dataSet device |
584 | 596 |
]. |
542 | 597 |
|
598 |
rendererType == #CheckToggle ifTrue:[ |
|
1113 | 599 |
buttonExtent := dataSet checkToggleExtent. |
647 | 600 |
^ self |
542 | 601 |
]. |
602 |
||
603 |
rendererType == #rowSelector ifTrue:[ |
|
807 | 604 |
buttonExtent := dataSet rowSelectorExtent. |
647 | 605 |
^ self |
542 | 606 |
]. |
607 |
||
608 |
(rendererType == #ComboBox or:[rendererType == #ComboList]) ifTrue:[ |
|
807 | 609 |
buttonExtent := dataSet comboButtonExtent. |
883 | 610 |
] ifFalse:[ |
611 |
columnAlignment := description columnAlignment |
|
542 | 612 |
]. |
613 |
||
614 |
selector := description printSelector. |
|
615 |
||
616 |
selector notNil ifTrue:[ |
|
1113 | 617 |
args := selector numArgs. |
618 |
args == 0 ifTrue:[ |
|
1147 | 619 |
shownValue := [:aRow| aRow perform:selector ] |
1113 | 620 |
] ifFalse:[ |
621 |
args == 1 ifTrue:[ |
|
1147 | 622 |
shownValue := [:aRow| aRow perform:selector with:dataSet ] |
1113 | 623 |
] ifFalse:[ |
1147 | 624 |
shownValue := [:aRow| aRow perform:selector with:dataSet with:columnNumber ] |
1113 | 625 |
] |
626 |
]. |
|
542 | 627 |
^ self |
628 |
]. |
|
629 |
||
614 | 630 |
( (format := description formatString) notNil |
631 |
and:[(type := description type) == #number or:[type == #numberOrNil]] |
|
632 |
) ifTrue:[ |
|
542 | 633 |
"/ has a format string for number (supports only floats) |
634 |
||
614 | 635 |
(idx := format indexOf:$.) ~~ 0 ifTrue:[ |
636 |
idx := format size - idx |
|
542 | 637 |
]. |
614 | 638 |
format := '%0.', idx printString, 'f'. |
542 | 639 |
|
1147 | 640 |
shownValue := [:aRow||n| |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
641 |
n := self extractColFromRow:aRow. |
621 | 642 |
n isReal ifTrue:[n := n asFloat printfPrintString:format]. |
643 |
n |
|
614 | 644 |
] |
621 | 645 |
] ifFalse:[ "/ default: no format string |
1147 | 646 |
shownValue := [:aRow| self extractColFromRow:aRow ] |
614 | 647 |
] |
542 | 648 |
|
649 |
||
650 |
! ! |
|
651 |
||
621 | 652 |
!DataSetColumn methodsFor:'private'! |
653 |
||
1113 | 654 |
extractColFromRow:aRow |
1226 | 655 |
readSelector isNil ifTrue:[^ nil]. |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
656 |
|
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
657 |
columnAdaptor notNil ifTrue:[ |
1113 | 658 |
numArgsToReadSelector == 1 ifTrue:[ |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
659 |
^ columnAdaptor perform:readSelector with:aRow |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
660 |
]. |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
661 |
^ columnAdaptor perform:readSelector with:aRow with:columnNumber |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
662 |
]. |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
663 |
|
1113 | 664 |
numArgsToReadSelector == 0 ifTrue:[ |
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
665 |
^ aRow perform:readSelector |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
666 |
]. |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
667 |
^ aRow perform:readSelector with:columnNumber |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
668 |
! |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
669 |
|
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
670 |
storeCol:newValue inRow:aRow |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
671 |
|writeSelector numArgs| |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
672 |
|
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
673 |
writeSelector := description writeSelector. |
1226 | 674 |
writeSelector isNil ifTrue:[^ aRow]. |
675 |
||
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
676 |
numArgs := writeSelector numArgs. |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
677 |
|
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
678 |
columnAdaptor notNil ifTrue:[ |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
679 |
numArgs == 2 ifTrue:[ |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
680 |
^ columnAdaptor perform:writeSelector with:aRow with:newValue |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
681 |
]. |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
682 |
^ columnAdaptor perform:writeSelector with:aRow with:columnNumber with:newValue |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
683 |
]. |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
684 |
|
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
685 |
numArgs == 1 ifTrue:[ |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
686 |
aRow perform:writeSelector with:newValue |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
687 |
] ifFalse:[ |
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
688 |
aRow perform:writeSelector with:columnNumber with:newValue |
1059 | 689 |
]. |
690 |
^ aRow |
|
1007
4ea1ecf23596
added support for columndAdaptors
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
691 |
|
621 | 692 |
! ! |
693 |
||
542 | 694 |
!DataSetColumn methodsFor:'queries'! |
695 |
||
607 | 696 |
canSelect:aRowNr |
697 |
"returns true if cell in column is selectable |
|
698 |
" |
|
699 |
|s| |
|
700 |
||
701 |
description canSelect ifTrue:[ |
|
1065
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
702 |
(s := description selectSelector) notNil ifTrue:[ |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
703 |
columnAdaptor notNil ifTrue:[ |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
704 |
s numArgs == 2 ifTrue:[ |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
705 |
^ columnAdaptor perform:s with:(dataSet at:aRowNr) with:columnNumber |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
706 |
]. |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
707 |
^ columnAdaptor perform:s with:(dataSet at:aRowNr) |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
708 |
]. |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
709 |
s numArgs == 1 ifTrue:[ |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
710 |
^ (dataSet at:aRowNr) perform:s with:columnNumber |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
711 |
]. |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
712 |
^ (dataSet at:aRowNr) perform:s |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
713 |
]. |
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
714 |
^ true |
607 | 715 |
]. |
716 |
^ false |
|
717 |
||
1065
332afeb89d6b
modify the model (i.e. the list), when a
Claus Gittinger <cg@exept.de>
parents:
1059
diff
changeset
|
718 |
"Modified: / 7.8.1998 / 22:49:20 / cg" |
607 | 719 |
! |
720 |
||
647 | 721 |
containsText |
722 |
"returns true if text might exist |
|
723 |
" |
|
724 |
^ (rendererType ~~ #rowSelector and:[rendererType ~~ #CheckToggle]) |
|
725 |
! |
|
726 |
||
833 | 727 |
hasChoices:aRowNr |
728 |
^ (description choicesFor:(dataSet at:aRowNr)) notNil |
|
729 |
! |
|
730 |
||
1484 | 731 |
hasRelativeWidth |
732 |
"returns true if width is relative |
|
733 |
" |
|
734 |
^ description hasRelativeWidth |
|
735 |
||
736 |
||
737 |
||
738 |
! |
|
739 |
||
542 | 740 |
heightOfHighestRow |
741 |
"returns the height of the highest row in pixels |
|
742 |
" |
|
743 |
|hObj hMin end| |
|
744 |
||
1088 | 745 |
hMin := (dataSet font heightOn:dataSet device) max:(buttonExtent y). |
542 | 746 |
|
747 |
(hObj := description height) == 0 ifTrue:[ |
|
647 | 748 |
self containsText ifTrue:[ |
542 | 749 |
"/ search first none empty drawable object |
621 | 750 |
end := 10 min:dataSet size. |
542 | 751 |
|
752 |
1 to:end do:[:aRowNr| |lbl| |
|
1147 | 753 |
lbl := shownValue value:(dataSet at:aRowNr). |
754 |
hObj := self heightOfLabel:(shownValue value:(dataSet at:aRowNr)). |
|
755 |
hMin := hMin max:hObj |
|
542 | 756 |
] |
757 |
] |
|
758 |
]. |
|
759 |
^ hMin max:hObj. |
|
1113 | 760 |
! |
761 |
||
1147 | 762 |
heightOfLabel:aLabel |
763 |
"returns the height of the label |
|
764 |
" |
|
765 |
|h l| |
|
766 |
||
767 |
aLabel isNil ifTrue:[ ^ 0 ]. |
|
768 |
||
769 |
(aLabel isSequenceable and:[aLabel isString not]) ifFalse:[ |
|
770 |
(aLabel respondsTo:#heightOn:) ifTrue:[l := aLabel] |
|
771 |
ifFalse:[l := aLabel displayString]. |
|
772 |
^ l heightOn:dataSet |
|
773 |
]. |
|
774 |
h := 0. |
|
775 |
||
776 |
aLabel do:[:el| |
|
777 |
(el respondsTo:#heightOn:) ifTrue:[l := el] |
|
778 |
ifFalse:[l := el displayString]. |
|
779 |
h := h + (el heightOn:dataSet) |
|
780 |
]. |
|
781 |
^ h |
|
782 |
||
783 |
! |
|
784 |
||
785 |
heightOfLabelAt:aRowNr |
|
786 |
"returns the height of the label at a row in pixels |
|
787 |
" |
|
788 |
^ self heightOfLabel:(shownValue value:(dataSet at:aRowNr)). |
|
789 |
! |
|
790 |
||
1113 | 791 |
showColSeparator |
792 |
"returns true if column separator is on |
|
793 |
" |
|
794 |
^ showColSeparator |
|
1133 | 795 |
! |
796 |
||
797 |
showSelectionHighLighted |
|
798 |
"returns true if selection is highLighted |
|
799 |
" |
|
800 |
^ description showSelectionHighLighted ~~ false |
|
1147 | 801 |
! |
802 |
||
803 |
widthOfLabel:aLabel |
|
804 |
"returns the width of the label |
|
805 |
" |
|
806 |
|w l| |
|
807 |
||
808 |
aLabel isNil ifTrue:[ ^ 0 ]. |
|
809 |
||
810 |
(aLabel isSequenceable and:[aLabel isString not]) ifFalse:[ |
|
811 |
(aLabel respondsTo:#widthOn:) ifTrue:[l := aLabel] |
|
812 |
ifFalse:[l := aLabel displayString]. |
|
813 |
^ l widthOn:dataSet |
|
814 |
]. |
|
815 |
w := 0. |
|
816 |
||
817 |
aLabel do:[:el| |
|
818 |
(el respondsTo:#widthOn:) ifTrue:[l := el] |
|
819 |
ifFalse:[l := el displayString]. |
|
820 |
w := w max:(el widthOn:dataSet) |
|
821 |
]. |
|
822 |
^ w |
|
542 | 823 |
! ! |
824 |
||
825 |
!DataSetColumn methodsFor:'searching'! |
|
826 |
||
827 |
findRowNrStartingWithChar:aChar start:start stop:stop |
|
828 |
"find the first row starting at start to stop, which drawable label |
|
829 |
starts with the character, aChar. The index of the detected row is |
|
830 |
returned or if no row is found 0. |
|
831 |
" |
|
832 |
|char| |
|
833 |
||
647 | 834 |
self containsText ifTrue:[ |
542 | 835 |
char := aChar asLowercase. |
836 |
||
837 |
start to:stop do:[:aRowNr| |lbl| |
|
1147 | 838 |
lbl := shownValue value:(dataSet at:aRowNr). |
839 |
||
840 |
(lbl isSequenceable and:[lbl isString not]) ifTrue:[ |
|
841 |
lbl := lbl at:1 ifAbsent:nil |
|
842 |
]. |
|
542 | 843 |
|
1113 | 844 |
(lbl respondsTo:#string) ifTrue:[ |
845 |
lbl := lbl string. |
|
542 | 846 |
(lbl size ~~ 0 and:[(lbl at:1) asLowercase == char]) ifTrue:[ |
847 |
^ aRowNr |
|
848 |
] |
|
849 |
] ifFalse:[ |
|
850 |
lbl isNil ifFalse:[ |
|
851 |
^ 0 |
|
852 |
] |
|
853 |
] |
|
854 |
] |
|
855 |
]. |
|
856 |
^ 0 |
|
857 |
||
858 |
! ! |
|
859 |
||
860 |
!DataSetColumn class methodsFor:'documentation'! |
|
861 |
||
862 |
version |
|
1484 | 863 |
^ '$Header: /cvs/stx/stx/libwidg2/DataSetColumn.st,v 1.45 1999-08-20 17:29:55 cg Exp $' |
542 | 864 |
! ! |