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