author | Claus Gittinger <cg@exept.de> |
Tue, 24 Jun 2008 13:02:06 +0200 | |
changeset 3450 | b0ce6b6fa2c6 |
parent 3132 | 9ee61ede263a |
child 3453 | ed5454e9bbd1 |
permissions | -rw-r--r-- |
172 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
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 |
" |
|
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
12 |
"{ Package: 'stx:libwidg2' }" |
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
13 |
|
2197
7ad026a1ae93
Make subclass of ModelListEntry
Stefan Vogel <sv@exept.de>
parents:
1977
diff
changeset
|
14 |
ModelListEntry subclass:#LabelAndIcon |
7ad026a1ae93
Make subclass of ModelListEntry
Stefan Vogel <sv@exept.de>
parents:
1977
diff
changeset
|
15 |
instanceVariableNames:'icon gap image offset' |
172 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Support' |
|
19 |
! |
|
20 |
||
21 |
!LabelAndIcon class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
an icon and a string, side by side. |
|
178 | 41 |
Usable as list entries in a listView (a fileList), as |
179 | 42 |
popUpMenuItems or as Label/Button image. |
172 | 43 |
|
44 |
This is an example class - currently not used by the system. |
|
45 |
||
179 | 46 |
Notice: |
47 |
This is different from ST-80's LabelAndIcon class, which |
|
48 |
inherits from Label. Therefore, things may change in the future. |
|
49 |
||
172 | 50 |
[author:] |
51 |
Claus Gittinger |
|
52 |
||
53 |
[see also:] |
|
54 |
ListEntry Text String Icon |
|
55 |
ListView SelectionInListView |
|
56 |
" |
|
57 |
! |
|
58 |
||
59 |
examples |
|
60 |
" |
|
175 | 61 |
in a listView: |
172 | 62 |
[exBegin] |
63 |
|top slv wrapper l fileImage dirImage| |
|
64 |
||
65 |
fileImage := Image |
|
66 |
width:16 |
|
67 |
height:16 |
|
68 |
depth:1 |
|
69 |
fromArray:#[2r00000000 2r00000000 |
|
70 |
2r00000000 2r00000000 |
|
71 |
2r00011111 2r11100000 |
|
72 |
2r00010000 2r00100000 |
|
73 |
2r00010000 2r00011000 |
|
74 |
2r00010000 2r00001000 |
|
75 |
2r00010000 2r00001000 |
|
76 |
2r00010000 2r00001000 |
|
77 |
2r00010000 2r00001000 |
|
78 |
2r00010000 2r00001000 |
|
79 |
2r00010000 2r00001000 |
|
80 |
2r00010000 2r00001000 |
|
81 |
2r00010000 2r00001000 |
|
82 |
2r00011111 2r11111000 |
|
83 |
2r00000000 2r00000000 |
|
84 |
2r00000000 2r00000000]. |
|
85 |
fileImage photometric:#whiteIs0. |
|
86 |
||
87 |
dirImage := Image |
|
88 |
width:16 |
|
89 |
height:16 |
|
90 |
depth:1 |
|
91 |
fromArray:#[2r00000000 2r00000000 |
|
92 |
2r00000000 2r00000000 |
|
93 |
2r00000000 2r00000000 |
|
94 |
2r01111111 2r11110000 |
|
95 |
2r01000000 2r00001000 |
|
96 |
2r01000000 2r00000100 |
|
97 |
2r01000000 2r00000010 |
|
98 |
2r01000000 2r00000010 |
|
99 |
2r01000000 2r00000010 |
|
100 |
2r01000000 2r00000010 |
|
101 |
2r01000000 2r00000010 |
|
102 |
2r01000000 2r00000010 |
|
103 |
2r01111111 2r11111110 |
|
104 |
2r00000000 2r00000000 |
|
105 |
2r00000000 2r00000000 |
|
106 |
2r00000000 2r00000000]. |
|
107 |
dirImage photometric:#whiteIs0. |
|
108 |
||
109 |
||
110 |
l := OrderedCollection new. |
|
111 |
Filename currentDirectory directoryContents do:[:s | |
|
112 |
s asFilename isDirectory ifTrue:[ |
|
113 |
l add:(LabelAndIcon icon:dirImage string:s) |
|
114 |
] ifFalse:[ |
|
115 |
l add:(LabelAndIcon icon:fileImage string:s) |
|
116 |
] |
|
117 |
]. |
|
118 |
||
119 |
slv := SelectionInListView new. |
|
120 |
slv list:l. |
|
121 |
wrapper := HVScrollableView forView:slv miniScrollerH:true. |
|
122 |
||
123 |
top := StandardSystemView extent:150@200. |
|
124 |
top add:wrapper in:(0.0@0.0 corner:1.0@1.0). |
|
125 |
top open. |
|
126 |
[exEnd] |
|
175 | 127 |
in a selectionInListView: |
172 | 128 |
[exBegin] |
129 |
|top slv wrapper l fileImage dirImage| |
|
130 |
||
131 |
dirImage := Image fromFile:'DirObj.xbm'. |
|
132 |
fileImage := Image fromFile:'FileObj.xbm'. |
|
133 |
||
134 |
||
135 |
l := OrderedCollection new. |
|
136 |
Filename currentDirectory directoryContents do:[:s | |
|
137 |
s asFilename isDirectory ifTrue:[ |
|
138 |
l add:(LabelAndIcon icon:dirImage string:s) |
|
139 |
] ifFalse:[ |
|
140 |
l add:(LabelAndIcon icon:fileImage string:s) |
|
141 |
] |
|
142 |
]. |
|
143 |
||
144 |
slv := SelectionInListView new. |
|
145 |
slv list:l. |
|
146 |
wrapper := HVScrollableView forView:slv miniScrollerH:true. |
|
147 |
||
148 |
top := StandardSystemView extent:150@200. |
|
149 |
top add:wrapper in:(0.0@0.0 corner:1.0@1.0). |
|
150 |
top open. |
|
151 |
[exEnd] |
|
175 | 152 |
in a menu: |
153 |
[exBegin] |
|
3450 | 154 |
|top l image1 image2| |
175 | 155 |
|
3450 | 156 |
image1 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/brazil.xpm'. |
157 |
image2 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/germany.xpm'. |
|
175 | 158 |
|
159 |
l := OrderedCollection new. |
|
3450 | 160 |
l add:(LabelAndIcon icon:image1 string:'brazil'). |
161 |
l add:(LabelAndIcon icon:image2 string:'germany'). |
|
175 | 162 |
|
163 |
top := View new. |
|
3450 | 164 |
top middleButtonMenu:(PopUpMenu |
165 |
labels:l |
|
175 | 166 |
selectors:#(foo bar)). |
167 |
||
168 |
top open. |
|
169 |
[exEnd] |
|
178 | 170 |
in a button/label: |
171 |
[exBegin] |
|
172 |
|top l image| |
|
173 |
||
3450 | 174 |
image := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/brazil.xpm'. |
175 |
l := (LabelAndIcon icon:image string:'brazil'). |
|
176 |
||
177 |
top := Button label:l. |
|
178 |
top open. |
|
179 |
[exEnd] |
|
180 |
two images in a button/label: |
|
181 |
[exBegin] |
|
182 |
|top l image1 image2| |
|
183 |
||
184 |
image1 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/brazil.xpm'. |
|
185 |
image2 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/germany.xpm'. |
|
186 |
l := (LabelAndIcon form:image1 image:image2 string:'directory'). |
|
178 | 187 |
|
188 |
top := Button label:l. |
|
189 |
top open. |
|
190 |
[exEnd] |
|
172 | 191 |
" |
192 |
! ! |
|
193 |
||
194 |
!LabelAndIcon class methodsFor:'instance creation'! |
|
195 |
||
629 | 196 |
form:aForm image:anImage |
3450 | 197 |
"return an instance consisting of a form and an icon (on the left)" |
726 | 198 |
|
629 | 199 |
^self new form:aForm image:anImage string:'' |
200 |
! |
|
201 |
||
202 |
form:aForm image:anImage string:aString |
|
3450 | 203 |
"return an instance consisting of two images (both on the left) and a string" |
726 | 204 |
|
629 | 205 |
^self new form:aForm image:anImage string:aString |
206 |
! |
|
207 |
||
172 | 208 |
icon:anIcon string:aString |
3450 | 209 |
"return an instance consisting of a label-string and an icon (on the left)" |
726 | 210 |
|
172 | 211 |
^ self new icon:anIcon string:aString |
212 |
||
213 |
"Created: 12.5.1996 / 20:00:58 / cg" |
|
214 |
! |
|
215 |
||
1977 | 216 |
label:aString icon:anIcon |
3450 | 217 |
"return an instance consisting of a label-string and an icon (on the left)" |
218 |
||
1977 | 219 |
^ self new icon:anIcon string:aString |
220 |
! |
|
221 |
||
172 | 222 |
new |
223 |
^ self basicNew initialize |
|
224 |
||
225 |
"Created: 12.5.1996 / 20:00:58 / cg" |
|
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
226 |
! |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
227 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
228 |
string:aString |
3450 | 229 |
"return an instance consisting of a string only" |
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
230 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
231 |
^ self new icon:nil string:aString |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
232 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
233 |
"Created: / 21.6.1998 / 04:57:28 / cg" |
172 | 234 |
! ! |
235 |
||
236 |
!LabelAndIcon methodsFor:'accessing'! |
|
237 |
||
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
238 |
beCheckMark |
1860 | 239 |
"/ self icon:(CheckToggle checkFormOn:Screen current) |
240 |
self icon:((CheckToggle smallCheckImageForStyle:#borderedFatcross) onDevice:Screen current) |
|
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
241 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
242 |
"Created: / 21.6.1998 / 05:01:01 / cg" |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
243 |
"Modified: / 21.6.1998 / 05:03:23 / cg" |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
244 |
! |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
245 |
|
629 | 246 |
form:aForm image:anImage string:aString |
247 |
||
248 |
icon := aForm. |
|
249 |
image:= anImage. |
|
250 |
string := aString. |
|
251 |
! |
|
252 |
||
1975 | 253 |
gap |
254 |
"return the spacing between the icon and the labelString. |
|
255 |
The default is 4" |
|
256 |
||
257 |
^ gap |
|
258 |
! |
|
259 |
||
172 | 260 |
gap:pixels |
261 |
"set the spacing between the icon and the labelString. |
|
262 |
The default is 4." |
|
263 |
||
264 |
gap := pixels. |
|
265 |
||
266 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
267 |
! |
|
268 |
||
286 | 269 |
icon |
270 |
"return my icon part" |
|
271 |
||
272 |
^ icon |
|
273 |
! |
|
274 |
||
172 | 275 |
icon:anIcon |
276 |
"set the icon image" |
|
277 |
||
278 |
icon := anIcon. |
|
279 |
||
280 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
281 |
! |
|
282 |
||
283 |
icon:anIcon string:aString |
|
284 |
"set both iconImage and the labelString" |
|
285 |
||
286 |
icon := anIcon. |
|
287 |
string := aString |
|
288 |
||
289 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
175 | 290 |
! |
291 |
||
719 | 292 |
image |
293 |
"return my image" |
|
294 |
||
295 |
^ image |
|
296 |
! |
|
297 |
||
298 |
image:anImage |
|
299 |
"set the image" |
|
300 |
||
301 |
image := anImage |
|
302 |
! |
|
303 |
||
3132 | 304 |
offset |
305 |
"set the left offset (i.e. spacing to the left of the icon). |
|
306 |
The default is 0." |
|
307 |
||
308 |
^ offset |
|
309 |
! |
|
310 |
||
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
311 |
offset:pixels |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
312 |
"set the left offset (i.e. spacing to the left of the icon). |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
313 |
The default is 0." |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
314 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
315 |
offset := pixels. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
316 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
317 |
"Created: / 21.6.1998 / 03:11:03 / cg" |
3132 | 318 |
! |
319 |
||
320 |
xOfString |
|
321 |
"returns the x position of the string" |
|
322 |
||
323 |
|x img| |
|
324 |
||
325 |
x := offset. |
|
326 |
||
327 |
(img := icon value) notNil ifTrue:[ |
|
328 |
x := x + img width + gap |
|
329 |
]. |
|
330 |
(img := image value) notNil ifTrue:[ |
|
331 |
x := x + img width + gap |
|
332 |
]. |
|
333 |
^ x |
|
172 | 334 |
! ! |
335 |
||
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
336 |
!LabelAndIcon methodsFor:'comparing'! |
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
337 |
|
2657
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
338 |
= aStringOrLabelAndIcon |
2674
e877ecb7d8b7
Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents:
2657
diff
changeset
|
339 |
|
e877ecb7d8b7
Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents:
2657
diff
changeset
|
340 |
aStringOrLabelAndIcon isNil ifTrue:[^ false]. |
e877ecb7d8b7
Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents:
2657
diff
changeset
|
341 |
|
2657
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
342 |
self hasIcon == aStringOrLabelAndIcon hasIcon ifFalse:[^ false]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
343 |
aStringOrLabelAndIcon hasIcon ifTrue:[ |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
344 |
icon = aStringOrLabelAndIcon icon ifFalse:[^ false]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
345 |
]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
346 |
self hasImage == aStringOrLabelAndIcon hasImage ifFalse:[^ false]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
347 |
aStringOrLabelAndIcon hasImage ifTrue:[ |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
348 |
image = aStringOrLabelAndIcon image ifFalse:[^ false]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
349 |
]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
350 |
^ super = aStringOrLabelAndIcon |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
351 |
! |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
352 |
|
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
353 |
sameStringAndEmphasisAs:someStringOrLabelAndIcon |
1817 | 354 |
someStringOrLabelAndIcon class == self class ifTrue:[ |
355 |
icon = someStringOrLabelAndIcon icon ifFalse:[^ false]. |
|
356 |
image = someStringOrLabelAndIcon image ifFalse:[^ false]. |
|
357 |
(string sameStringAndEmphasisAs:someStringOrLabelAndIcon string) ifFalse:[ ^ false]. |
|
358 |
^ true. |
|
359 |
]. |
|
360 |
||
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
361 |
(string sameStringAndEmphasisAs:someStringOrLabelAndIcon) ifFalse:[ ^ false]. |
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
362 |
(icon isNil and:[image isNil]) ifTrue:[^ true]. |
1817 | 363 |
^ false |
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
364 |
! ! |
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
365 |
|
172 | 366 |
!LabelAndIcon methodsFor:'displaying'! |
367 |
||
2453
3dad4e5c2fbe
ascentOn: (is this correct ?)
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
368 |
ascentOn:aGC |
2454 | 369 |
^ aGC font ascentOn:aGC device. |
2453
3dad4e5c2fbe
ascentOn: (is this correct ?)
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
370 |
! |
3dad4e5c2fbe
ascentOn: (is this correct ?)
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
371 |
|
172 | 372 |
displayOn:aGC x:x y:y opaque:opaque |
373 |
"display the receiver on a GC" |
|
374 |
||
2773 | 375 |
|y1 x1 iconValue imageValue iconHeight imageHeight stringHeight maxHeight gapY asc| |
726 | 376 |
|
377 |
gapY := (aGC device pixelPerMillimeter x) rounded. |
|
1860 | 378 |
"/ gapY := 0. |
1479 | 379 |
asc := (aGC font onDevice:aGC device) ascent. |
180 | 380 |
|
2773 | 381 |
iconValue := icon value. |
382 |
imageValue := image value. |
|
383 |
||
384 |
iconHeight := iconValue notNil ifTrue:[iconValue height] ifFalse:[0]. |
|
385 |
imageHeight := imageValue notNil ifTrue:[imageValue height] ifFalse:[0]. |
|
726 | 386 |
stringHeight := string size > 0 ifTrue:[string heightOn:aGC] ifFalse:[0]. |
172 | 387 |
|
726 | 388 |
maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight. |
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
389 |
x1 := x + offset. |
258 | 390 |
|
2773 | 391 |
iconValue notNil ifTrue:[ |
726 | 392 |
y1 := y - asc + (maxHeight - iconHeight + 1 // 2). |
1860 | 393 |
|
2773 | 394 |
icon := iconValue onDevice:aGC device. |
578
72916ad0a5f3
fixed centering of the image w.r.t. the fontHeight
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
395 |
|
2773 | 396 |
(opaque and:[iconValue mask isNil]) ifTrue:[aGC displayOpaqueForm:iconValue x:x1 y:y1] |
397 |
ifFalse:[aGC displayForm:iconValue x:x1 y:y1]. |
|
578
72916ad0a5f3
fixed centering of the image w.r.t. the fontHeight
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
398 |
|
2773 | 399 |
x1 := x1 + iconValue width + gap |
258 | 400 |
]. |
401 |
||
2773 | 402 |
imageValue notNil ifTrue:[ |
726 | 403 |
y1 := y - asc + (maxHeight - imageHeight + 1 // 2). |
2773 | 404 |
image := imageValue onDevice:aGC device. |
726 | 405 |
|
2773 | 406 |
(opaque and:[imageValue mask isNil]) ifTrue:[aGC displayOpaqueForm:imageValue x:x1 y:y1] |
407 |
ifFalse:[aGC displayForm:imageValue x:x1 y:y1]. |
|
629 | 408 |
|
2773 | 409 |
x1 := x1 + imageValue width + gap |
629 | 410 |
]. |
172 | 411 |
|
726 | 412 |
stringHeight ~~ 0 ifTrue:[ |
413 |
y1 := y + (maxHeight - stringHeight + 1 // 2). |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
414 |
string displayOn:aGC x:x1 y:y1 opaque:opaque |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
415 |
] |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
416 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
417 |
"Modified: / 21.6.1998 / 03:52:12 / cg" |
810 | 418 |
! |
419 |
||
420 |
on:aDevice |
|
421 |
"return a new image on a device |
|
422 |
" |
|
1604
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
423 |
^ self onDevice:aDevice |
810 | 424 |
|
425 |
! |
|
426 |
||
427 |
onDevice:aDevice |
|
428 |
"return a new image on a device |
|
429 |
" |
|
1604
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
430 |
|form img| |
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
431 |
|
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
432 |
aDevice isNil ifTrue:[^ self]. |
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
433 |
icon notNil ifTrue:[form := icon onDevice:aDevice]. |
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
434 |
image notNil ifTrue:[img := image onDevice:aDevice]. |
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
435 |
|
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
436 |
^ LabelAndIcon form:form image:img string:string |
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
437 |
|
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
438 |
|
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
439 |
|
172 | 440 |
! ! |
441 |
||
442 |
!LabelAndIcon methodsFor:'initialization'! |
|
443 |
||
444 |
initialize |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
445 |
gap := 4. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
446 |
offset := 0. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
447 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
448 |
"Modified: / 21.6.1998 / 03:10:19 / cg" |
172 | 449 |
! ! |
450 |
||
451 |
!LabelAndIcon methodsFor:'queries'! |
|
452 |
||
2657
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
453 |
hasIcon |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
454 |
^ icon notNil |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
455 |
! |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
456 |
|
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
457 |
hasImage |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
458 |
^ image notNil |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
459 |
! |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
460 |
|
172 | 461 |
heightOn:aGC |
462 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
463 |
||
719 | 464 |
|iconHeight imageHeight stringHeight oneMillimeter| |
682 | 465 |
|
466 |
oneMillimeter := aGC device pixelPerMillimeter x rounded. |
|
1860 | 467 |
"/ oneMillimeter := 0. |
306 | 468 |
|
469 |
icon notNil ifTrue:[ |
|
2773 | 470 |
iconHeight := icon value height + oneMillimeter |
306 | 471 |
] ifFalse:[ |
472 |
iconHeight := 0 |
|
473 |
]. |
|
629 | 474 |
image notNil ifTrue:[ |
2773 | 475 |
imageHeight := image value height + oneMillimeter |
629 | 476 |
] ifFalse:[ |
477 |
imageHeight := 0 |
|
478 |
]. |
|
719 | 479 |
string size > 0 ifTrue:[ |
480 |
stringHeight := string heightOn:aGC |
|
481 |
] ifFalse:[ |
|
482 |
stringHeight := 0 |
|
483 |
]. |
|
726 | 484 |
^ ((iconHeight max: imageHeight) max: stringHeight) |
172 | 485 |
! |
486 |
||
487 |
widthOn:aGC |
|
488 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
489 |
||
719 | 490 |
|width| |
306 | 491 |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
492 |
width := offset. |
306 | 493 |
icon notNil ifTrue:[ |
2773 | 494 |
width := width + icon value width |
306 | 495 |
]. |
629 | 496 |
image notNil ifTrue:[ |
2773 | 497 |
width := width + gap + image value width |
629 | 498 |
]. |
719 | 499 |
string size > 0 ifTrue:[ |
500 |
width := width + gap + (string widthOn:aGC) |
|
501 |
]. |
|
502 |
^width |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
503 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
504 |
"Modified: / 21.6.1998 / 03:11:14 / cg" |
172 | 505 |
! ! |
506 |
||
507 |
!LabelAndIcon class methodsFor:'documentation'! |
|
508 |
||
509 |
version |
|
3450 | 510 |
^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.38 2008-06-24 11:02:06 cg Exp $' |
172 | 511 |
! ! |