author | Claus Gittinger <cg@exept.de> |
Thu, 27 May 2004 16:26:48 +0200 | |
changeset 2710 | fcfa161492ae |
parent 2699 | ffc569afbb18 |
child 2779 | e5b0570c2c32 |
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 |
||
2699 | 57 |
backgroundColor:aColor |
58 |
"set the background color or nil |
|
59 |
" |
|
60 |
bgColor := aColor |
|
61 |
! |
|
62 |
||
1150 | 63 |
foregroundColor |
1487 | 64 |
"returns the foreground color or nil |
1150 | 65 |
" |
66 |
^ fgColor |
|
67 |
||
2699 | 68 |
! |
69 |
||
70 |
foregroundColor:aColor |
|
71 |
"set the foreground color or nil |
|
72 |
" |
|
73 |
fgColor := aColor |
|
1150 | 74 |
! ! |
75 |
||
1818 | 76 |
!DataSetLabel methodsFor:'accessing-dimensions'! |
1150 | 77 |
|
1487 | 78 |
preferredHeight |
79 |
"returns my preferred height |
|
1150 | 80 |
" |
1487 | 81 |
^ preferredHeight |
1150 | 82 |
! |
83 |
||
1487 | 84 |
preferredWidth |
85 |
"returns my preferred width |
|
1150 | 86 |
" |
1487 | 87 |
^ preferredWidth |
1150 | 88 |
! ! |
89 |
||
90 |
!DataSetLabel methodsFor:'actions'! |
|
91 |
||
92 |
sendClickMsgTo:aReceiver |
|
93 |
"inform the receiver of a button release notification |
|
94 |
" |
|
95 |
(aReceiver notNil and:[selector notNil]) ifTrue:[ |
|
2068
3fcbf2422c5a
use new #perform:withOptionalArg
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
96 |
aReceiver perform:selector withOptionalArgument:argument |
1150 | 97 |
] |
98 |
! ! |
|
99 |
||
100 |
!DataSetLabel methodsFor:'drawing'! |
|
101 |
||
1487 | 102 |
redrawX:xLeft w:width h:height inset:inset on:aGC |
1150 | 103 |
"redraw the label; the background is cleared and the paint is set |
104 |
" |
|
2144 | 105 |
|y0 x y ascent gcFont labelWidth |
2154
cb22be939082
split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
106 |
shownLabel prevClip mustUndoClip |
2144 | 107 |
netWidth| |
1150 | 108 |
|
109 |
label isNil ifTrue:[ ^ self ]. |
|
110 |
||
1487 | 111 |
gcFont := aGC font. |
112 |
font notNil ifTrue:[ |
|
113 |
aGC font:font. |
|
114 |
ascent := font ascent |
|
115 |
] ifFalse:[ |
|
116 |
ascent := gcFont ascent |
|
117 |
]. |
|
118 |
y0 := height - preferredHeight // 2. |
|
1150 | 119 |
|
2144 | 120 |
netWidth := width-inset-inset. |
121 |
||
1487 | 122 |
label do:[:aLabel| |
2144 | 123 |
shownLabel := aLabel. |
124 |
||
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
125 |
mustUndoClip := false. |
2144 | 126 |
labelWidth := shownLabel widthOn:aGC. |
127 |
labelWidth > netWidth ifTrue:[ |
|
2154
cb22be939082
split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
128 |
shownLabel := DataSetColumn shortenedStringFor:aLabel on:aGC maxWidth:netWidth. |
cb22be939082
split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
129 |
labelWidth := shownLabel widthOn:aGC. |
2144 | 130 |
]. |
131 |
||
1487 | 132 |
adjust == #left ifTrue:[ |
133 |
x := xLeft + inset. |
|
134 |
] ifFalse:[ |
|
2144 | 135 |
x := width - labelWidth. |
1150 | 136 |
|
1487 | 137 |
adjust == #right ifTrue:[x := x - inset] |
138 |
ifFalse:[x := x // 2]. |
|
139 |
x := xLeft + x. |
|
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
140 |
|
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
141 |
"/ 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
|
142 |
x < xLeft ifTrue:[ |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
143 |
"/ must clip ... |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
144 |
prevClip := aGC clippingRectangleOrNil. |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
145 |
mustUndoClip := true. |
1591
6996391ee3ba
Avoid obsolete method. (stefan)
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
146 |
aGC clippingRectangle:(Rectangle |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
147 |
left:xLeft top:y0 |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
148 |
width:width height:height). |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
149 |
]. |
1487 | 150 |
]. |
2443
e88b4123061a
changes to allow for Object>>displayOn:x:y: to work correctly
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
151 |
"/ y := shownLabel isImageOrForm ifTrue:[y0] ifFalse:[y0 + ascent]. |
2451 | 152 |
"/ y := shownLabel isString ifTrue:[y0 + ascent] ifFalse:[y0]. |
153 |
shownLabel displayOn:aGC x:x y:y0 + (shownLabel ascentOn:aGC). |
|
2144 | 154 |
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
|
155 |
|
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
156 |
mustUndoClip == true ifTrue:[ |
1591
6996391ee3ba
Avoid obsolete method. (stefan)
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
157 |
aGC clippingRectangle:prevClip |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
158 |
]. |
1487 | 159 |
]. |
2451 | 160 |
font notNil ifTrue:[ |
161 |
aGC font:gcFont "/ restore font |
|
162 |
]. |
|
1150 | 163 |
! ! |
164 |
||
165 |
!DataSetLabel methodsFor:'instance creation'! |
|
166 |
||
1487 | 167 |
description:aDescription builder:aBuilder on:aGC |
168 |
|device gcFont| |
|
1150 | 169 |
|
1605 | 170 |
label := self resolveLabelFromDescription:aDescription withBuilder:aBuilder. |
171 |
selector := aDescription labelActionSelector. |
|
172 |
argument := (aDescription labelActionArgument) ? label. |
|
173 |
adjust := (aDescription labelAlignment) ? #left. |
|
174 |
device := aGC device. |
|
175 |
fgColor := aDescription labelForegroundColor. |
|
176 |
bgColor := aDescription labelBackgroundColor. |
|
1150 | 177 |
|
1480 | 178 |
fgColor notNil ifTrue:[ fgColor := fgColor onDevice:device ]. |
179 |
bgColor notNil ifTrue:[ bgColor := bgColor onDevice:device ]. |
|
1150 | 180 |
|
1487 | 181 |
preferredHeight := preferredWidth := 0. |
182 |
||
183 |
(label isNil or:[label perform:#isEmpty ifNotUnderstood:false]) ifTrue:[ |
|
184 |
label := nil. |
|
185 |
^ self |
|
1150 | 186 |
]. |
187 |
||
1487 | 188 |
(font := aDescription labelFont) notNil ifTrue:[ |
189 |
(gcFont := aGC font) = font ifTrue:[ |
|
190 |
font := nil |
|
191 |
] ifFalse:[ |
|
192 |
aGC font:(font := font onDevice:device) |
|
193 |
] |
|
194 |
]. |
|
1150 | 195 |
|
196 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
|
1487 | 197 |
label := Array with:label |
1150 | 198 |
]. |
199 |
||
200 |
label := label collect:[:el||lbl| |
|
1487 | 201 |
lbl := self label:el on:device. |
202 |
preferredWidth := (lbl widthOn:aGC) max:preferredWidth. |
|
203 |
preferredHeight := preferredHeight + (lbl heightOn:aGC). |
|
1150 | 204 |
lbl |
205 |
]. |
|
1487 | 206 |
font notNil ifTrue:[aGC font:gcFont]. "/ restore font |
1150 | 207 |
! ! |
208 |
||
209 |
!DataSetLabel methodsFor:'private'! |
|
210 |
||
211 |
label:aLabel on:aDevice |
|
212 |
"returns registered label on a device |
|
213 |
" |
|
214 |
|lbl img| |
|
215 |
||
1487 | 216 |
aLabel isNil ifTrue:[^ '']. |
217 |
||
1150 | 218 |
aLabel isString ifFalse:[ |
219 |
aLabel isImageOrForm ifTrue:[ |
|
2291 | 220 |
aLabel device ~~ aDevice ifTrue:[ |
221 |
lbl := aLabel copy onDevice:aDevice |
|
222 |
] ifFalse:[ |
|
223 |
lbl := aLabel |
|
224 |
]. |
|
1150 | 225 |
lbl isImage ifTrue:[ |
226 |
lbl clearMaskedPixels |
|
227 |
]. |
|
228 |
^ lbl |
|
229 |
]. |
|
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
230 |
|
1150 | 231 |
aLabel class == LabelAndIcon ifTrue:[ |
2291 | 232 |
lbl := aLabel onDevice:aDevice. |
1150 | 233 |
(img := lbl image) isImage ifTrue:[img clearMaskedPixels]. |
234 |
(img := lbl icon) isImage ifTrue:[img clearMaskedPixels]. |
|
235 |
^ lbl |
|
236 |
] |
|
237 |
]. |
|
238 |
^ aLabel |
|
239 |
! |
|
240 |
||
241 |
resolveLabelFromDescription:aDescription withBuilder:aBuilder |
|
242 |
||
243 |
|label appl size lbl| |
|
244 |
||
245 |
aBuilder isNil ifTrue:[ |
|
246 |
^ aDescription rawLabel |
|
247 |
]. |
|
248 |
label := aDescription label. |
|
249 |
||
250 |
label isString ifTrue:[ |
|
251 |
aDescription labelIsImage ifTrue:[ |
|
252 |
( aBuilder isEditing |
|
253 |
or:[(label := aBuilder labelFor:(label asSymbol)) isNil] |
|
254 |
) ifTrue:[ |
|
255 |
^ aDescription class defaultIcon |
|
256 |
]. |
|
257 |
^ label |
|
258 |
]. |
|
259 |
||
260 |
aDescription translateLabel == true ifTrue:[ |
|
261 |
( aBuilder isEditing |
|
262 |
or:[(appl := aBuilder application) isNil] |
|
263 |
) ifTrue:[ |
|
264 |
^ label |
|
265 |
]. |
|
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
266 |
"/ 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
|
267 |
( (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
|
268 |
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
|
269 |
) ifTrue: |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
270 |
|
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
271 |
"/ ( (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
|
272 |
"/ 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
|
273 |
"/ ) |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
274 |
"/ ifFalse: |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
275 |
[ |
1150 | 276 |
label := lbl |
277 |
] |
|
278 |
] |
|
279 |
]. |
|
280 |
||
281 |
label isSequenceable ifTrue:[ |
|
282 |
(size := label size) == 0 ifTrue:[ "/ empty label |
|
283 |
^ nil |
|
284 |
]. |
|
285 |
(size == 1 and:[label isString not]) ifTrue:[ "/ collection with one entry |
|
286 |
^ label at:1 "/ not a string object |
|
287 |
]. |
|
288 |
]. |
|
289 |
^ label |
|
290 |
||
291 |
||
292 |
||
293 |
! ! |
|
294 |
||
295 |
!DataSetLabel methodsFor:'queries'! |
|
296 |
||
1605 | 297 |
hasSeparator |
298 |
|l| |
|
299 |
||
300 |
label size == 1 ifTrue:[ |
|
301 |
"/ ^ (label at:1) ~= 'Alarm' |
|
302 |
^ (label at:1) ~= 'Area' |
|
303 |
]. |
|
304 |
^ true |
|
305 |
! |
|
306 |
||
1150 | 307 |
isSelectable |
308 |
"returns true if the item is selectable; a valid selector |
|
309 |
to notify the receiver for a release button event exists |
|
310 |
" |
|
311 |
^ selector notNil |
|
312 |
||
313 |
||
314 |
! ! |
|
315 |
||
316 |
!DataSetLabel class methodsFor:'documentation'! |
|
317 |
||
318 |
version |
|
2699 | 319 |
^ '$Header: /cvs/stx/stx/libwidg2/DataSetLabel.st,v 1.17 2004-04-07 08:39:01 werner Exp $' |
1150 | 320 |
! ! |