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