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