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