author | Claus Gittinger <cg@exept.de> |
Mon, 13 Sep 1999 07:49:09 +0200 | |
changeset 1523 | 4a12791de6c4 |
parent 1487 | fd003e2156cc |
child 1588 | e6039e46cae2 |
permissions | -rw-r--r-- |
1150 | 1 |
Object subclass:#DataSetLabel |
1487 | 2 |
instanceVariableNames:'label selector argument adjust font fgColor bgColor |
1523
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
3 |
preferredHeight preferredWidth labelIsButton' |
1150 | 4 |
classVariableNames:'' |
5 |
poolDictionaries:'' |
|
6 |
category:'Views-DataSet' |
|
7 |
! |
|
8 |
||
9 |
||
1523
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
10 |
!DataSetLabel methodsFor:'accessing'! |
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
11 |
|
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
12 |
labelIsButton |
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
13 |
^ labelIsButton |
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
14 |
! ! |
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
15 |
|
1150 | 16 |
!DataSetLabel methodsFor:'accessing colors'! |
17 |
||
18 |
backgroundColor |
|
1487 | 19 |
"returns the background color or nil |
1150 | 20 |
" |
21 |
^ bgColor |
|
22 |
||
23 |
||
24 |
! |
|
25 |
||
26 |
foregroundColor |
|
1487 | 27 |
"returns the foreground color or nil |
1150 | 28 |
" |
29 |
^ fgColor |
|
30 |
||
31 |
! ! |
|
32 |
||
33 |
!DataSetLabel methodsFor:'accessing dimensions'! |
|
34 |
||
1487 | 35 |
preferredHeight |
36 |
"returns my preferred height |
|
1150 | 37 |
" |
1487 | 38 |
^ preferredHeight |
1150 | 39 |
! |
40 |
||
1487 | 41 |
preferredWidth |
42 |
"returns my preferred width |
|
1150 | 43 |
" |
1487 | 44 |
^ preferredWidth |
1150 | 45 |
! ! |
46 |
||
47 |
!DataSetLabel methodsFor:'actions'! |
|
48 |
||
49 |
sendClickMsgTo:aReceiver |
|
50 |
"inform the receiver of a button release notification |
|
51 |
" |
|
52 |
(aReceiver notNil and:[selector notNil]) ifTrue:[ |
|
53 |
selector numArgs ~~ 0 ifTrue:[ |
|
54 |
aReceiver perform:selector with:argument |
|
55 |
] ifFalse:[ |
|
56 |
aReceiver perform:selector |
|
57 |
] |
|
58 |
] |
|
59 |
||
60 |
||
61 |
! ! |
|
62 |
||
63 |
!DataSetLabel methodsFor:'drawing'! |
|
64 |
||
1487 | 65 |
redrawX:xLeft w:width h:height inset:inset on:aGC |
1150 | 66 |
"redraw the label; the background is cleared and the paint is set |
67 |
" |
|
1487 | 68 |
|y0 margin x y ascent gcFont| |
1150 | 69 |
|
70 |
label isNil ifTrue:[ ^ self ]. |
|
71 |
||
1487 | 72 |
gcFont := aGC font. |
73 |
||
74 |
font notNil ifTrue:[ |
|
75 |
aGC font:font. |
|
76 |
ascent := font ascent |
|
77 |
] ifFalse:[ |
|
78 |
ascent := gcFont ascent |
|
79 |
]. |
|
80 |
y0 := height - preferredHeight // 2. |
|
1150 | 81 |
|
1487 | 82 |
label do:[:aLabel| |
83 |
adjust == #left ifTrue:[ |
|
84 |
x := xLeft + inset. |
|
85 |
] ifFalse:[ |
|
86 |
x := width - (aLabel widthOn:aGC). |
|
1150 | 87 |
|
1487 | 88 |
adjust == #right ifTrue:[x := x - inset] |
89 |
ifFalse:[x := x // 2]. |
|
90 |
x := xLeft + x. |
|
91 |
]. |
|
92 |
y := aLabel isImageOrForm ifTrue:[y0] ifFalse:[y0 + ascent]. |
|
93 |
aLabel displayOn:aGC x:x y:y. |
|
94 |
y0 := y0 + (aLabel heightOn:aGC) |
|
95 |
]. |
|
96 |
font notNil ifTrue:[aGC font:gcFont]. "/ restore font |
|
1150 | 97 |
! ! |
98 |
||
99 |
!DataSetLabel methodsFor:'instance creation'! |
|
100 |
||
1487 | 101 |
description:aDescription builder:aBuilder on:aGC |
102 |
|device gcFont| |
|
1150 | 103 |
|
104 |
label := self resolveLabelFromDescription:aDescription withBuilder:aBuilder. |
|
105 |
selector := aDescription labelActionSelector. |
|
106 |
argument := (aDescription labelActionArgument) ? label. |
|
107 |
adjust := (aDescription labelAlignment) ? #left. |
|
1487 | 108 |
device := aGC device. |
1150 | 109 |
fgColor := aDescription labelForegroundColor. |
110 |
bgColor := aDescription labelBackgroundColor. |
|
1523
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
111 |
labelIsButton := aDescription labelIsButton. |
1150 | 112 |
|
1480 | 113 |
fgColor notNil ifTrue:[ fgColor := fgColor onDevice:device ]. |
114 |
bgColor notNil ifTrue:[ bgColor := bgColor onDevice:device ]. |
|
1150 | 115 |
|
1487 | 116 |
preferredHeight := preferredWidth := 0. |
117 |
||
118 |
(label isNil or:[label perform:#isEmpty ifNotUnderstood:false]) ifTrue:[ |
|
119 |
label := nil. |
|
120 |
^ self |
|
1150 | 121 |
]. |
122 |
||
1487 | 123 |
(font := aDescription labelFont) notNil ifTrue:[ |
124 |
(gcFont := aGC font) = font ifTrue:[ |
|
125 |
font := nil |
|
126 |
] ifFalse:[ |
|
127 |
aGC font:(font := font onDevice:device) |
|
128 |
] |
|
129 |
]. |
|
1150 | 130 |
|
131 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
|
1487 | 132 |
label := Array with:label |
1150 | 133 |
]. |
134 |
||
135 |
label := label collect:[:el||lbl| |
|
1487 | 136 |
lbl := self label:el on:device. |
137 |
preferredWidth := (lbl widthOn:aGC) max:preferredWidth. |
|
138 |
preferredHeight := preferredHeight + (lbl heightOn:aGC). |
|
1150 | 139 |
lbl |
140 |
]. |
|
1487 | 141 |
font notNil ifTrue:[aGC font:gcFont]. "/ restore font |
1150 | 142 |
! ! |
143 |
||
144 |
!DataSetLabel methodsFor:'private'! |
|
145 |
||
146 |
label:aLabel on:aDevice |
|
147 |
"returns registered label on a device |
|
148 |
" |
|
149 |
|lbl img| |
|
150 |
||
1487 | 151 |
aLabel isNil ifTrue:[^ '']. |
152 |
||
1150 | 153 |
aLabel isString ifFalse:[ |
154 |
aLabel isImageOrForm ifTrue:[ |
|
155 |
aLabel device ~~ aDevice ifTrue:[lbl := aLabel copy on:aDevice] |
|
156 |
ifFalse:[lbl := aLabel]. |
|
157 |
lbl isImage ifTrue:[ |
|
158 |
lbl clearMaskedPixels |
|
159 |
]. |
|
160 |
^ lbl |
|
161 |
]. |
|
162 |
aLabel class == LabelAndIcon ifTrue:[ |
|
163 |
lbl := aLabel on:aDevice. |
|
164 |
(img := lbl image) isImage ifTrue:[img clearMaskedPixels]. |
|
165 |
(img := lbl icon) isImage ifTrue:[img clearMaskedPixels]. |
|
166 |
^ lbl |
|
167 |
] |
|
168 |
]. |
|
169 |
^ aLabel |
|
170 |
! |
|
171 |
||
172 |
resolveLabelFromDescription:aDescription withBuilder:aBuilder |
|
173 |
||
174 |
|label appl size lbl| |
|
175 |
||
176 |
aBuilder isNil ifTrue:[ |
|
177 |
^ aDescription rawLabel |
|
178 |
]. |
|
179 |
label := aDescription label. |
|
180 |
||
181 |
label isString ifTrue:[ |
|
182 |
aDescription labelIsImage ifTrue:[ |
|
183 |
( aBuilder isEditing |
|
184 |
or:[(label := aBuilder labelFor:(label asSymbol)) isNil] |
|
185 |
) ifTrue:[ |
|
186 |
^ aDescription class defaultIcon |
|
187 |
]. |
|
188 |
^ label |
|
189 |
]. |
|
190 |
||
191 |
aDescription translateLabel == true ifTrue:[ |
|
192 |
( aBuilder isEditing |
|
193 |
or:[(appl := aBuilder application) isNil] |
|
194 |
) ifTrue:[ |
|
195 |
^ label |
|
196 |
]. |
|
197 |
( (lbl := appl resources string:label) isNil |
|
198 |
or:[(lbl := aBuilder aspectAt:(label asSymbol)) isNil] |
|
199 |
) ifFalse:[ |
|
200 |
label := lbl |
|
201 |
] |
|
202 |
] |
|
203 |
]. |
|
204 |
||
205 |
label isSequenceable ifTrue:[ |
|
206 |
(size := label size) == 0 ifTrue:[ "/ empty label |
|
207 |
^ nil |
|
208 |
]. |
|
209 |
(size == 1 and:[label isString not]) ifTrue:[ "/ collection with one entry |
|
210 |
^ label at:1 "/ not a string object |
|
211 |
]. |
|
212 |
]. |
|
213 |
^ label |
|
214 |
||
215 |
||
216 |
||
217 |
! ! |
|
218 |
||
219 |
!DataSetLabel methodsFor:'queries'! |
|
220 |
||
221 |
isSelectable |
|
222 |
"returns true if the item is selectable; a valid selector |
|
223 |
to notify the receiver for a release button event exists |
|
224 |
" |
|
225 |
^ selector notNil |
|
226 |
||
227 |
||
228 |
! ! |
|
229 |
||
230 |
!DataSetLabel class methodsFor:'documentation'! |
|
231 |
||
232 |
version |
|
1523
4a12791de6c4
show label as button(enable/disable)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
233 |
^ '$Header: /cvs/stx/stx/libwidg2/DataSetLabel.st,v 1.5 1999-09-13 05:49:09 cg Exp $' |
1150 | 234 |
! ! |