author | Claus Gittinger <cg@exept.de> |
Fri, 28 Feb 2003 14:24:49 +0100 | |
changeset 2451 | 383fdea243d0 |
parent 2443 | e88b4123061a |
child 2699 | ffc569afbb18 |
permissions | -rw-r--r-- |
1716 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
14 |
||
15 |
||
16 |
||
1818 | 17 |
"{ Package: 'stx:libwidg2' }" |
18 |
||
1150 | 19 |
Object subclass:#DataSetLabel |
1487 | 20 |
instanceVariableNames:'label selector argument adjust font fgColor bgColor |
1605 | 21 |
preferredHeight preferredWidth' |
1150 | 22 |
classVariableNames:'' |
23 |
poolDictionaries:'' |
|
24 |
category:'Views-DataSet' |
|
25 |
! |
|
26 |
||
1716 | 27 |
!DataSetLabel class methodsFor:'documentation'! |
28 |
||
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1997 by 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 |
! ! |
|
1150 | 46 |
|
1818 | 47 |
!DataSetLabel methodsFor:'accessing-colors'! |
1150 | 48 |
|
49 |
backgroundColor |
|
1487 | 50 |
"returns the background color or nil |
1150 | 51 |
" |
52 |
^ bgColor |
|
53 |
||
54 |
||
55 |
! |
|
56 |
||
57 |
foregroundColor |
|
1487 | 58 |
"returns the foreground color or nil |
1150 | 59 |
" |
60 |
^ fgColor |
|
61 |
||
62 |
! ! |
|
63 |
||
1818 | 64 |
!DataSetLabel methodsFor:'accessing-dimensions'! |
1150 | 65 |
|
1487 | 66 |
preferredHeight |
67 |
"returns my preferred height |
|
1150 | 68 |
" |
1487 | 69 |
^ preferredHeight |
1150 | 70 |
! |
71 |
||
1487 | 72 |
preferredWidth |
73 |
"returns my preferred width |
|
1150 | 74 |
" |
1487 | 75 |
^ preferredWidth |
1150 | 76 |
! ! |
77 |
||
78 |
!DataSetLabel methodsFor:'actions'! |
|
79 |
||
80 |
sendClickMsgTo:aReceiver |
|
81 |
"inform the receiver of a button release notification |
|
82 |
" |
|
83 |
(aReceiver notNil and:[selector notNil]) ifTrue:[ |
|
2068
3fcbf2422c5a
use new #perform:withOptionalArg
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
84 |
aReceiver perform:selector withOptionalArgument:argument |
1150 | 85 |
] |
86 |
! ! |
|
87 |
||
88 |
!DataSetLabel methodsFor:'drawing'! |
|
89 |
||
1487 | 90 |
redrawX:xLeft w:width h:height inset:inset on:aGC |
1150 | 91 |
"redraw the label; the background is cleared and the paint is set |
92 |
" |
|
2144 | 93 |
|y0 x y ascent gcFont labelWidth |
2154
cb22be939082
split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
94 |
shownLabel prevClip mustUndoClip |
2144 | 95 |
netWidth| |
1150 | 96 |
|
97 |
label isNil ifTrue:[ ^ self ]. |
|
98 |
||
1487 | 99 |
gcFont := aGC font. |
100 |
font notNil ifTrue:[ |
|
101 |
aGC font:font. |
|
102 |
ascent := font ascent |
|
103 |
] ifFalse:[ |
|
104 |
ascent := gcFont ascent |
|
105 |
]. |
|
106 |
y0 := height - preferredHeight // 2. |
|
1150 | 107 |
|
2144 | 108 |
netWidth := width-inset-inset. |
109 |
||
1487 | 110 |
label do:[:aLabel| |
2144 | 111 |
shownLabel := aLabel. |
112 |
||
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
113 |
mustUndoClip := false. |
2144 | 114 |
labelWidth := shownLabel widthOn:aGC. |
115 |
labelWidth > netWidth ifTrue:[ |
|
2154
cb22be939082
split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
116 |
shownLabel := DataSetColumn shortenedStringFor:aLabel on:aGC maxWidth:netWidth. |
cb22be939082
split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
117 |
labelWidth := shownLabel widthOn:aGC. |
2144 | 118 |
]. |
119 |
||
1487 | 120 |
adjust == #left ifTrue:[ |
121 |
x := xLeft + inset. |
|
122 |
] ifFalse:[ |
|
2144 | 123 |
x := width - labelWidth. |
1150 | 124 |
|
1487 | 125 |
adjust == #right ifTrue:[x := x - inset] |
126 |
ifFalse:[x := x // 2]. |
|
127 |
x := xLeft + x. |
|
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
128 |
|
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
129 |
"/ cg: must clip left, if string is too large |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
130 |
x < xLeft ifTrue:[ |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
131 |
"/ must clip ... |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
132 |
prevClip := aGC clippingRectangleOrNil. |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
133 |
mustUndoClip := true. |
1591
6996391ee3ba
Avoid obsolete method. (stefan)
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
134 |
aGC clippingRectangle:(Rectangle |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
135 |
left:xLeft top:y0 |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
136 |
width:width height:height). |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
137 |
]. |
1487 | 138 |
]. |
2443
e88b4123061a
changes to allow for Object>>displayOn:x:y: to work correctly
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
139 |
"/ y := shownLabel isImageOrForm ifTrue:[y0] ifFalse:[y0 + ascent]. |
2451 | 140 |
"/ y := shownLabel isString ifTrue:[y0 + ascent] ifFalse:[y0]. |
141 |
shownLabel displayOn:aGC x:x y:y0 + (shownLabel ascentOn:aGC). |
|
2144 | 142 |
y0 := y0 + (shownLabel heightOn:aGC). |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
143 |
|
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
144 |
mustUndoClip == true ifTrue:[ |
1591
6996391ee3ba
Avoid obsolete method. (stefan)
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
145 |
aGC clippingRectangle:prevClip |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
146 |
]. |
1487 | 147 |
]. |
2451 | 148 |
font notNil ifTrue:[ |
149 |
aGC font:gcFont "/ restore font |
|
150 |
]. |
|
1150 | 151 |
! ! |
152 |
||
153 |
!DataSetLabel methodsFor:'instance creation'! |
|
154 |
||
1487 | 155 |
description:aDescription builder:aBuilder on:aGC |
156 |
|device gcFont| |
|
1150 | 157 |
|
1605 | 158 |
label := self resolveLabelFromDescription:aDescription withBuilder:aBuilder. |
159 |
selector := aDescription labelActionSelector. |
|
160 |
argument := (aDescription labelActionArgument) ? label. |
|
161 |
adjust := (aDescription labelAlignment) ? #left. |
|
162 |
device := aGC device. |
|
163 |
fgColor := aDescription labelForegroundColor. |
|
164 |
bgColor := aDescription labelBackgroundColor. |
|
1150 | 165 |
|
1480 | 166 |
fgColor notNil ifTrue:[ fgColor := fgColor onDevice:device ]. |
167 |
bgColor notNil ifTrue:[ bgColor := bgColor onDevice:device ]. |
|
1150 | 168 |
|
1487 | 169 |
preferredHeight := preferredWidth := 0. |
170 |
||
171 |
(label isNil or:[label perform:#isEmpty ifNotUnderstood:false]) ifTrue:[ |
|
172 |
label := nil. |
|
173 |
^ self |
|
1150 | 174 |
]. |
175 |
||
1487 | 176 |
(font := aDescription labelFont) notNil ifTrue:[ |
177 |
(gcFont := aGC font) = font ifTrue:[ |
|
178 |
font := nil |
|
179 |
] ifFalse:[ |
|
180 |
aGC font:(font := font onDevice:device) |
|
181 |
] |
|
182 |
]. |
|
1150 | 183 |
|
184 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
|
1487 | 185 |
label := Array with:label |
1150 | 186 |
]. |
187 |
||
188 |
label := label collect:[:el||lbl| |
|
1487 | 189 |
lbl := self label:el on:device. |
190 |
preferredWidth := (lbl widthOn:aGC) max:preferredWidth. |
|
191 |
preferredHeight := preferredHeight + (lbl heightOn:aGC). |
|
1150 | 192 |
lbl |
193 |
]. |
|
1487 | 194 |
font notNil ifTrue:[aGC font:gcFont]. "/ restore font |
1150 | 195 |
! ! |
196 |
||
197 |
!DataSetLabel methodsFor:'private'! |
|
198 |
||
199 |
label:aLabel on:aDevice |
|
200 |
"returns registered label on a device |
|
201 |
" |
|
202 |
|lbl img| |
|
203 |
||
1487 | 204 |
aLabel isNil ifTrue:[^ '']. |
205 |
||
1150 | 206 |
aLabel isString ifFalse:[ |
207 |
aLabel isImageOrForm ifTrue:[ |
|
2291 | 208 |
aLabel device ~~ aDevice ifTrue:[ |
209 |
lbl := aLabel copy onDevice:aDevice |
|
210 |
] ifFalse:[ |
|
211 |
lbl := aLabel |
|
212 |
]. |
|
1150 | 213 |
lbl isImage ifTrue:[ |
214 |
lbl clearMaskedPixels |
|
215 |
]. |
|
216 |
^ lbl |
|
217 |
]. |
|
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
218 |
|
1150 | 219 |
aLabel class == LabelAndIcon ifTrue:[ |
2291 | 220 |
lbl := aLabel onDevice:aDevice. |
1150 | 221 |
(img := lbl image) isImage ifTrue:[img clearMaskedPixels]. |
222 |
(img := lbl icon) isImage ifTrue:[img clearMaskedPixels]. |
|
223 |
^ lbl |
|
224 |
] |
|
225 |
]. |
|
226 |
^ aLabel |
|
227 |
! |
|
228 |
||
229 |
resolveLabelFromDescription:aDescription withBuilder:aBuilder |
|
230 |
||
231 |
|label appl size lbl| |
|
232 |
||
233 |
aBuilder isNil ifTrue:[ |
|
234 |
^ aDescription rawLabel |
|
235 |
]. |
|
236 |
label := aDescription label. |
|
237 |
||
238 |
label isString ifTrue:[ |
|
239 |
aDescription labelIsImage ifTrue:[ |
|
240 |
( aBuilder isEditing |
|
241 |
or:[(label := aBuilder labelFor:(label asSymbol)) isNil] |
|
242 |
) ifTrue:[ |
|
243 |
^ aDescription class defaultIcon |
|
244 |
]. |
|
245 |
^ label |
|
246 |
]. |
|
247 |
||
248 |
aDescription translateLabel == true ifTrue:[ |
|
249 |
( aBuilder isEditing |
|
250 |
or:[(appl := aBuilder application) isNil] |
|
251 |
) ifTrue:[ |
|
252 |
^ label |
|
253 |
]. |
|
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
254 |
"/ cg: the old code below did it in the wrong order ... |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
255 |
( (lbl := aBuilder aspectAt:(label asSymbol)) notNil |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
256 |
or:[ (lbl := appl resources string:label) notNil] |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
257 |
) ifTrue: |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
258 |
|
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
259 |
"/ ( (lbl := appl resources string:label) isNil |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
260 |
"/ or:[(lbl := aBuilder aspectAt:(label asSymbol)) isNil] |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
261 |
"/ ) |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
262 |
"/ ifFalse: |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
263 |
[ |
1150 | 264 |
label := lbl |
265 |
] |
|
266 |
] |
|
267 |
]. |
|
268 |
||
269 |
label isSequenceable ifTrue:[ |
|
270 |
(size := label size) == 0 ifTrue:[ "/ empty label |
|
271 |
^ nil |
|
272 |
]. |
|
273 |
(size == 1 and:[label isString not]) ifTrue:[ "/ collection with one entry |
|
274 |
^ label at:1 "/ not a string object |
|
275 |
]. |
|
276 |
]. |
|
277 |
^ label |
|
278 |
||
279 |
||
280 |
||
281 |
! ! |
|
282 |
||
283 |
!DataSetLabel methodsFor:'queries'! |
|
284 |
||
1605 | 285 |
hasSeparator |
286 |
|l| |
|
287 |
||
288 |
label size == 1 ifTrue:[ |
|
289 |
"/ ^ (label at:1) ~= 'Alarm' |
|
290 |
^ (label at:1) ~= 'Area' |
|
291 |
]. |
|
292 |
^ true |
|
293 |
! |
|
294 |
||
1150 | 295 |
isSelectable |
296 |
"returns true if the item is selectable; a valid selector |
|
297 |
to notify the receiver for a release button event exists |
|
298 |
" |
|
299 |
^ selector notNil |
|
300 |
||
301 |
||
302 |
! ! |
|
303 |
||
304 |
!DataSetLabel class methodsFor:'documentation'! |
|
305 |
||
306 |
version |
|
2451 | 307 |
^ '$Header: /cvs/stx/stx/libwidg2/DataSetLabel.st,v 1.16 2003-02-28 13:24:49 cg Exp $' |
1150 | 308 |
! ! |