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