author | Claus Gittinger <cg@exept.de> |
Fri, 15 Jun 2018 10:54:35 +0200 | |
changeset 5816 | 7876c07931a7 |
parent 5526 | 1f7cf0ff5d7c |
child 5912 | f09029085bb4 |
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 |
|
4878 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
2197
7ad026a1ae93
Make subclass of ModelListEntry
Stefan Vogel <sv@exept.de>
parents:
1977
diff
changeset
|
16 |
ModelListEntry subclass:#LabelAndIcon |
7ad026a1ae93
Make subclass of ModelListEntry
Stefan Vogel <sv@exept.de>
parents:
1977
diff
changeset
|
17 |
instanceVariableNames:'icon gap image offset' |
172 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Support' |
|
21 |
! |
|
22 |
||
23 |
!LabelAndIcon class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
3782 | 42 |
an icon, an optional additional image and a string, all by side (from left to right). |
43 |
Each may be nil (i.e. with a nil image, it's a Label-and-Icon proper (icon to the left of the string). |
|
3781 | 44 |
|
178 | 45 |
Usable as list entries in a listView (a fileList), as |
179 | 46 |
popUpMenuItems or as Label/Button image. |
172 | 47 |
|
179 | 48 |
Notice: |
49 |
This is different from ST-80's LabelAndIcon class, which |
|
50 |
inherits from Label. Therefore, things may change in the future. |
|
51 |
||
172 | 52 |
[author:] |
53 |
Claus Gittinger |
|
54 |
||
55 |
[see also:] |
|
56 |
ListEntry Text String Icon |
|
57 |
ListView SelectionInListView |
|
58 |
" |
|
59 |
! |
|
60 |
||
61 |
examples |
|
62 |
" |
|
175 | 63 |
in a listView: |
172 | 64 |
[exBegin] |
65 |
|top slv wrapper l fileImage dirImage| |
|
66 |
||
67 |
fileImage := Image |
|
68 |
width:16 |
|
69 |
height:16 |
|
70 |
depth:1 |
|
71 |
fromArray:#[2r00000000 2r00000000 |
|
72 |
2r00000000 2r00000000 |
|
73 |
2r00011111 2r11100000 |
|
74 |
2r00010000 2r00100000 |
|
75 |
2r00010000 2r00011000 |
|
76 |
2r00010000 2r00001000 |
|
77 |
2r00010000 2r00001000 |
|
78 |
2r00010000 2r00001000 |
|
79 |
2r00010000 2r00001000 |
|
80 |
2r00010000 2r00001000 |
|
81 |
2r00010000 2r00001000 |
|
82 |
2r00010000 2r00001000 |
|
83 |
2r00010000 2r00001000 |
|
84 |
2r00011111 2r11111000 |
|
85 |
2r00000000 2r00000000 |
|
86 |
2r00000000 2r00000000]. |
|
87 |
fileImage photometric:#whiteIs0. |
|
88 |
||
89 |
dirImage := Image |
|
90 |
width:16 |
|
91 |
height:16 |
|
92 |
depth:1 |
|
93 |
fromArray:#[2r00000000 2r00000000 |
|
94 |
2r00000000 2r00000000 |
|
95 |
2r00000000 2r00000000 |
|
96 |
2r01111111 2r11110000 |
|
97 |
2r01000000 2r00001000 |
|
98 |
2r01000000 2r00000100 |
|
99 |
2r01000000 2r00000010 |
|
100 |
2r01000000 2r00000010 |
|
101 |
2r01000000 2r00000010 |
|
102 |
2r01000000 2r00000010 |
|
103 |
2r01000000 2r00000010 |
|
104 |
2r01000000 2r00000010 |
|
105 |
2r01111111 2r11111110 |
|
106 |
2r00000000 2r00000000 |
|
107 |
2r00000000 2r00000000 |
|
108 |
2r00000000 2r00000000]. |
|
109 |
dirImage photometric:#whiteIs0. |
|
110 |
||
111 |
||
112 |
l := OrderedCollection new. |
|
113 |
Filename currentDirectory directoryContents do:[:s | |
|
114 |
s asFilename isDirectory ifTrue:[ |
|
115 |
l add:(LabelAndIcon icon:dirImage string:s) |
|
116 |
] ifFalse:[ |
|
117 |
l add:(LabelAndIcon icon:fileImage string:s) |
|
118 |
] |
|
119 |
]. |
|
120 |
||
121 |
slv := SelectionInListView new. |
|
122 |
slv list:l. |
|
123 |
wrapper := HVScrollableView forView:slv miniScrollerH:true. |
|
124 |
||
125 |
top := StandardSystemView extent:150@200. |
|
126 |
top add:wrapper in:(0.0@0.0 corner:1.0@1.0). |
|
127 |
top open. |
|
128 |
[exEnd] |
|
175 | 129 |
in a selectionInListView: |
172 | 130 |
[exBegin] |
131 |
|top slv wrapper l fileImage dirImage| |
|
132 |
||
3782 | 133 |
dirImage := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/document_images/file_dir.xpm'. |
134 |
fileImage := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/document_images/file_text.xpm'. |
|
172 | 135 |
|
136 |
||
137 |
l := OrderedCollection new. |
|
138 |
Filename currentDirectory directoryContents do:[:s | |
|
139 |
s asFilename isDirectory ifTrue:[ |
|
140 |
l add:(LabelAndIcon icon:dirImage string:s) |
|
141 |
] ifFalse:[ |
|
142 |
l add:(LabelAndIcon icon:fileImage string:s) |
|
143 |
] |
|
144 |
]. |
|
145 |
||
146 |
slv := SelectionInListView new. |
|
147 |
slv list:l. |
|
148 |
wrapper := HVScrollableView forView:slv miniScrollerH:true. |
|
149 |
||
150 |
top := StandardSystemView extent:150@200. |
|
151 |
top add:wrapper in:(0.0@0.0 corner:1.0@1.0). |
|
152 |
top open. |
|
153 |
[exEnd] |
|
175 | 154 |
in a menu: |
155 |
[exBegin] |
|
3450 | 156 |
|top l image1 image2| |
175 | 157 |
|
3782 | 158 |
image1 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/argentina.xpm'. |
3450 | 159 |
image2 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/germany.xpm'. |
175 | 160 |
|
161 |
l := OrderedCollection new. |
|
4128 | 162 |
l add:(LabelAndIcon icon:image1 string:'argentina'). |
3450 | 163 |
l add:(LabelAndIcon icon:image2 string:'germany'). |
175 | 164 |
|
3782 | 165 |
top := StandardSystemView new. |
3450 | 166 |
top middleButtonMenu:(PopUpMenu |
167 |
labels:l |
|
175 | 168 |
selectors:#(foo bar)). |
3782 | 169 |
top label:'Try the right-button menu'. |
170 |
top extent:300@300. |
|
175 | 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 |
||
5020 | 380 |
|y1 x1 iconValue imageValue stringHeight maxHeight| |
180 | 381 |
|
2773 | 382 |
iconValue := icon value. |
383 |
imageValue := image value. |
|
384 |
||
5020 | 385 |
"/ gapY := (device pixelPerMillimeter x) rounded. |
3782 | 386 |
"/ maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight. |
387 |
maxHeight := self heightOn:aGC. |
|
388 |
||
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:[ |
5020 | 392 |
y1 := y - aGC font ascent + ((maxHeight - iconValue height + 1) // 2). |
5525 | 393 |
((iconValue height ~~ 0) and:[iconValue width ~~ 0]) ifTrue:[ |
5526 | 394 |
iconValue isImage ifTrue:[ icon := iconValue onDevice:aGC device ]. |
5525 | 395 |
(opaque and:[iconValue mask isNil]) ifTrue:[aGC displayOpaqueForm:iconValue x:x1 y:y1] |
396 |
ifFalse:[aGC displayForm:iconValue x:x1 y:y1]. |
|
397 |
x1 := x1 + iconValue width + gap. |
|
398 |
]. |
|
258 | 399 |
]. |
400 |
||
2773 | 401 |
imageValue notNil ifTrue:[ |
5020 | 402 |
y1 := y - aGC font ascent + ((maxHeight - imageValue height + 1) // 2). |
5526 | 403 |
((imageValue height ~~ 0) and:[imageValue width ~~ 0]) ifTrue:[ |
404 |
imageValue isImage ifTrue:[ image := imageValue onDevice:aGC device ]. |
|
405 |
(opaque and:[imageValue mask isNil]) ifTrue:[aGC displayOpaqueForm:imageValue x:x1 y:y1] |
|
406 |
ifFalse:[aGC displayForm:imageValue x:x1 y:y1]. |
|
407 |
x1 := x1 + imageValue width + gap. |
|
408 |
]. |
|
629 | 409 |
]. |
172 | 410 |
|
5020 | 411 |
stringHeight := string size ~~ 0 ifTrue:[string heightOn:aGC] ifFalse:[0]. |
726 | 412 |
stringHeight ~~ 0 ifTrue:[ |
5020 | 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 |
|
5526 | 417 |
"Modified: / 06-04-2017 / 13:12:31 / cg" |
810 | 418 |
! |
419 |
||
420 |
on:aDevice |
|
4878 | 421 |
<resource: #obsolete> |
5202 | 422 |
|
423 |
self obsoleteFeatureWarning:'use onDevice:'. |
|
1604
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
424 |
^ self onDevice:aDevice |
810 | 425 |
! |
426 |
||
427 |
onDevice:aDevice |
|
5202 | 428 |
"return with both icon and image onDevice:aDevice" |
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]. |
5202 | 435 |
(icon == form and:[image == img]) ifTrue:[ |
436 |
"nothing changed" |
|
437 |
^ self. |
|
438 |
]. |
|
1604
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
439 |
|
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
440 |
^ LabelAndIcon form:form image:img string:string |
172 | 441 |
! ! |
442 |
||
443 |
!LabelAndIcon methodsFor:'initialization'! |
|
444 |
||
445 |
initialize |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
446 |
gap := 4. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
447 |
offset := 0. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
448 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
449 |
"Modified: / 21.6.1998 / 03:10:19 / cg" |
172 | 450 |
! ! |
451 |
||
452 |
!LabelAndIcon methodsFor:'queries'! |
|
453 |
||
2657
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
454 |
hasIcon |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
455 |
^ icon notNil |
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 |
|
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
458 |
hasImage |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
459 |
^ image 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 |
|
172 | 462 |
heightOn:aGC |
463 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
464 |
||
719 | 465 |
|iconHeight imageHeight stringHeight oneMillimeter| |
682 | 466 |
|
5209 | 467 |
oneMillimeter := aGC device isNil ifTrue:[2] ifFalse:[aGC horizontalIntegerPixelPerMillimeter]. |
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 |
]. |
|
5209 | 479 |
string size ~~ 0 ifTrue:[ |
719 | 480 |
stringHeight := string heightOn:aGC |
481 |
] ifFalse:[ |
|
482 |
stringHeight := 0 |
|
483 |
]. |
|
5209 | 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 |
]. |
5209 | 499 |
string size ~~ 0 ifTrue:[ |
719 | 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 |
||
4678 | 507 |
!LabelAndIcon methodsFor:'testing'! |
508 |
||
509 |
isLabelAndIcon |
|
510 |
^ true |
|
511 |
! ! |
|
512 |
||
513 |
!LabelAndIcon methodsFor:'text compatibility'! |
|
514 |
||
515 |
withoutAnyColorEmphasis |
|
516 |
^ self shallowCopy string:(string withoutAnyColorEmphasis) |
|
517 |
! |
|
518 |
||
519 |
withoutBackgroundColorEmphasis |
|
520 |
^ self shallowCopy string:(string withoutBackgroundColorEmphasis) |
|
521 |
! |
|
522 |
||
523 |
withoutForegroundColorEmphasis |
|
524 |
^ self shallowCopy string:(string withoutForegroundColorEmphasis) |
|
525 |
! ! |
|
526 |
||
172 | 527 |
!LabelAndIcon class methodsFor:'documentation'! |
528 |
||
529 |
version |
|
4878 | 530 |
^ '$Header$' |
3781 | 531 |
! |
532 |
||
533 |
version_CVS |
|
4878 | 534 |
^ '$Header$' |
172 | 535 |
! ! |
4678 | 536 |