author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 30 May 2018 09:34:26 +0100 | |
branch | jv |
changeset 5814 | 70d07365a2d4 |
parent 5212 | ab0c9d002aea |
permissions | -rw-r--r-- |
172 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
5814 | 3 |
COPYRIGHT (c) 2015 Jan Vrany |
172 | 4 |
All Rights Reserved |
5 |
||
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
13 |
"{ Package: 'stx:libwidg2' }" |
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
14 |
|
4878 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
2197
7ad026a1ae93
Make subclass of ModelListEntry
Stefan Vogel <sv@exept.de>
parents:
1977
diff
changeset
|
17 |
ModelListEntry subclass:#LabelAndIcon |
7ad026a1ae93
Make subclass of ModelListEntry
Stefan Vogel <sv@exept.de>
parents:
1977
diff
changeset
|
18 |
instanceVariableNames:'icon gap image offset' |
172 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Views-Support' |
|
22 |
! |
|
23 |
||
24 |
!LabelAndIcon class methodsFor:'documentation'! |
|
25 |
||
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
5814 | 29 |
COPYRIGHT (c) 2015 Jan Vrany |
172 | 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 |
|
3450 | 208 |
"return an instance consisting of two images (both on the left) and a string" |
726 | 209 |
|
629 | 210 |
^self new form:aForm image:anImage string:aString |
211 |
! |
|
212 |
||
172 | 213 |
icon:anIcon string:aString |
3450 | 214 |
"return an instance consisting of a label-string and an icon (on the left)" |
726 | 215 |
|
172 | 216 |
^ self new icon:anIcon string:aString |
217 |
||
218 |
"Created: 12.5.1996 / 20:00:58 / cg" |
|
219 |
! |
|
220 |
||
1977 | 221 |
label:aString icon:anIcon |
3450 | 222 |
"return an instance consisting of a label-string and an icon (on the left)" |
223 |
||
1977 | 224 |
^ self new icon:anIcon string:aString |
225 |
! |
|
226 |
||
172 | 227 |
new |
228 |
^ self basicNew initialize |
|
229 |
||
230 |
"Created: 12.5.1996 / 20:00:58 / cg" |
|
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
231 |
! |
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 |
string:aString |
3450 | 234 |
"return an instance consisting of a string only" |
986
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 |
^ self new icon:nil string:aString |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
237 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
238 |
"Created: / 21.6.1998 / 04:57:28 / cg" |
3781 | 239 |
! |
240 |
||
241 |
string:aString image:image |
|
242 |
"return an instance consisting of a label-string and an image (on the right)" |
|
243 |
||
244 |
^ self new form:nil image:image string:aString |
|
172 | 245 |
! ! |
246 |
||
247 |
!LabelAndIcon methodsFor:'accessing'! |
|
248 |
||
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
249 |
beCheckMark |
1860 | 250 |
"/ self icon:(CheckToggle checkFormOn:Screen current) |
251 |
self icon:((CheckToggle smallCheckImageForStyle:#borderedFatcross) onDevice:Screen current) |
|
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
252 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
253 |
"Created: / 21.6.1998 / 05:01:01 / cg" |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
254 |
"Modified: / 21.6.1998 / 05:03:23 / cg" |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
255 |
! |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
256 |
|
629 | 257 |
form:aForm image:anImage string:aString |
258 |
||
259 |
icon := aForm. |
|
260 |
image:= anImage. |
|
261 |
string := aString. |
|
262 |
! |
|
263 |
||
1975 | 264 |
gap |
265 |
"return the spacing between the icon and the labelString. |
|
266 |
The default is 4" |
|
267 |
||
268 |
^ gap |
|
269 |
! |
|
270 |
||
172 | 271 |
gap:pixels |
272 |
"set the spacing between the icon and the labelString. |
|
273 |
The default is 4." |
|
274 |
||
275 |
gap := pixels. |
|
276 |
||
277 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
278 |
! |
|
279 |
||
286 | 280 |
icon |
281 |
"return my icon part" |
|
282 |
||
283 |
^ icon |
|
284 |
! |
|
285 |
||
172 | 286 |
icon:anIcon |
287 |
"set the icon image" |
|
288 |
||
289 |
icon := anIcon. |
|
290 |
||
291 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
292 |
! |
|
293 |
||
294 |
icon:anIcon string:aString |
|
295 |
"set both iconImage and the labelString" |
|
296 |
||
297 |
icon := anIcon. |
|
298 |
string := aString |
|
299 |
||
300 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
175 | 301 |
! |
302 |
||
719 | 303 |
image |
304 |
"return my image" |
|
305 |
||
306 |
^ image |
|
307 |
! |
|
308 |
||
309 |
image:anImage |
|
310 |
"set the image" |
|
311 |
||
312 |
image := anImage |
|
313 |
! |
|
314 |
||
3132 | 315 |
offset |
316 |
"set the left offset (i.e. spacing to the left of the icon). |
|
317 |
The default is 0." |
|
318 |
||
319 |
^ offset |
|
320 |
! |
|
321 |
||
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
322 |
offset:pixels |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
323 |
"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
|
324 |
The default is 0." |
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 |
offset := pixels. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
327 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
328 |
"Created: / 21.6.1998 / 03:11:03 / cg" |
3132 | 329 |
! |
330 |
||
331 |
xOfString |
|
332 |
"returns the x position of the string" |
|
333 |
||
334 |
|x img| |
|
335 |
||
336 |
x := offset. |
|
337 |
||
338 |
(img := icon value) notNil ifTrue:[ |
|
339 |
x := x + img width + gap |
|
340 |
]. |
|
341 |
(img := image value) notNil ifTrue:[ |
|
342 |
x := x + img width + gap |
|
343 |
]. |
|
344 |
^ x |
|
172 | 345 |
! ! |
346 |
||
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
347 |
!LabelAndIcon methodsFor:'comparing'! |
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
348 |
|
2657
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
349 |
= aStringOrLabelAndIcon |
2674
e877ecb7d8b7
Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents:
2657
diff
changeset
|
350 |
|
e877ecb7d8b7
Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents:
2657
diff
changeset
|
351 |
aStringOrLabelAndIcon isNil ifTrue:[^ false]. |
e877ecb7d8b7
Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents:
2657
diff
changeset
|
352 |
|
2657
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
353 |
self hasIcon == aStringOrLabelAndIcon hasIcon ifFalse:[^ false]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
354 |
aStringOrLabelAndIcon hasIcon ifTrue:[ |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
355 |
icon = aStringOrLabelAndIcon icon ifFalse:[^ false]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
356 |
]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
357 |
self hasImage == aStringOrLabelAndIcon hasImage ifFalse:[^ false]. |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
358 |
aStringOrLabelAndIcon hasImage ifTrue:[ |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
359 |
image = aStringOrLabelAndIcon image ifFalse:[^ false]. |
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 |
^ super = aStringOrLabelAndIcon |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
362 |
! |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
363 |
|
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
364 |
sameStringAndEmphasisAs:someStringOrLabelAndIcon |
1817 | 365 |
someStringOrLabelAndIcon class == self class ifTrue:[ |
366 |
icon = someStringOrLabelAndIcon icon ifFalse:[^ false]. |
|
367 |
image = someStringOrLabelAndIcon image ifFalse:[^ false]. |
|
368 |
(string sameStringAndEmphasisAs:someStringOrLabelAndIcon string) ifFalse:[ ^ false]. |
|
369 |
^ true. |
|
370 |
]. |
|
371 |
||
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
372 |
(string sameStringAndEmphasisAs:someStringOrLabelAndIcon) ifFalse:[ ^ false]. |
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
373 |
(icon isNil and:[image isNil]) ifTrue:[^ true]. |
1817 | 374 |
^ false |
1814
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
375 |
! ! |
a7697ca7f34f
added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents:
1604
diff
changeset
|
376 |
|
172 | 377 |
!LabelAndIcon methodsFor:'displaying'! |
378 |
||
379 |
displayOn:aGC x:x y:y opaque:opaque |
|
380 |
"display the receiver on a GC" |
|
381 |
||
5020 | 382 |
|y1 x1 iconValue imageValue stringHeight maxHeight| |
180 | 383 |
|
2773 | 384 |
iconValue := icon value. |
385 |
imageValue := image value. |
|
386 |
||
5020 | 387 |
"/ gapY := (device pixelPerMillimeter x) rounded. |
3782 | 388 |
"/ maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight. |
389 |
maxHeight := self heightOn:aGC. |
|
390 |
||
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
391 |
x1 := x + offset. |
258 | 392 |
|
2773 | 393 |
iconValue notNil ifTrue:[ |
5020 | 394 |
y1 := y - aGC font ascent + ((maxHeight - iconValue height + 1) // 2). |
395 |
icon := iconValue onDevice:aGC device. |
|
2773 | 396 |
(opaque and:[iconValue mask isNil]) ifTrue:[aGC displayOpaqueForm:iconValue x:x1 y:y1] |
397 |
ifFalse:[aGC displayForm:iconValue x:x1 y:y1]. |
|
5020 | 398 |
x1 := x1 + iconValue width + gap. |
258 | 399 |
]. |
400 |
||
2773 | 401 |
imageValue notNil ifTrue:[ |
5020 | 402 |
y1 := y - aGC font ascent + ((maxHeight - imageValue height + 1) // 2). |
403 |
image := imageValue onDevice:aGC device. |
|
2773 | 404 |
(opaque and:[imageValue mask isNil]) ifTrue:[aGC displayOpaqueForm:imageValue x:x1 y:y1] |
405 |
ifFalse:[aGC displayForm:imageValue x:x1 y:y1]. |
|
5020 | 406 |
x1 := x1 + imageValue width + gap. |
629 | 407 |
]. |
172 | 408 |
|
5020 | 409 |
stringHeight := string size ~~ 0 ifTrue:[string heightOn:aGC] ifFalse:[0]. |
726 | 410 |
stringHeight ~~ 0 ifTrue:[ |
5020 | 411 |
y1 := y + ((maxHeight - stringHeight + 1) // 2). |
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
412 |
string displayOn:aGC x:x1 y:y1 opaque:opaque |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
413 |
] |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
414 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
415 |
"Modified: / 21.6.1998 / 03:52:12 / cg" |
810 | 416 |
! |
417 |
||
418 |
on:aDevice |
|
4878 | 419 |
<resource: #obsolete> |
5202 | 420 |
|
421 |
self obsoleteFeatureWarning:'use onDevice:'. |
|
1604
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
422 |
^ self onDevice:aDevice |
810 | 423 |
! |
424 |
||
425 |
onDevice:aDevice |
|
5202 | 426 |
"return with both icon and image onDevice:aDevice" |
427 |
||
1604
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
428 |
|form img| |
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
429 |
|
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
430 |
aDevice isNil ifTrue:[^ self]. |
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
431 |
icon notNil ifTrue:[form := icon onDevice:aDevice]. |
2c15dd8fb3cf
ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents:
1479
diff
changeset
|
432 |
image notNil ifTrue:[img := image onDevice:aDevice]. |
5202 | 433 |
(icon == form and:[image == img]) ifTrue:[ |
434 |
"nothing changed" |
|
435 |
^ self. |
|
436 |
]. |
|
1604
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 |
^ LabelAndIcon form:form image:img string:string |
172 | 439 |
! ! |
440 |
||
441 |
!LabelAndIcon methodsFor:'initialization'! |
|
442 |
||
443 |
initialize |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
444 |
gap := 4. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
445 |
offset := 0. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
446 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
447 |
"Modified: / 21.6.1998 / 03:10:19 / cg" |
172 | 448 |
! ! |
449 |
||
450 |
!LabelAndIcon methodsFor:'queries'! |
|
451 |
||
2657
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
452 |
hasIcon |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
453 |
^ icon notNil |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
454 |
! |
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 |
hasImage |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
457 |
^ image notNil |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
458 |
! |
20d7ed550989
also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents:
2454
diff
changeset
|
459 |
|
172 | 460 |
heightOn:aGC |
461 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
462 |
||
719 | 463 |
|iconHeight imageHeight stringHeight oneMillimeter| |
682 | 464 |
|
5212 | 465 |
"/oneMillimeter := aGC device isNil ifTrue:[2] ifFalse:[aGC horizontalIntegerPixelPerMillimeter]. |
4779
85c21ae4fddc
UI fix in LabelAndIcon: do not add extra space to height - looks ugly.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4678
diff
changeset
|
466 |
oneMillimeter := 0. |
306 | 467 |
|
468 |
icon notNil ifTrue:[ |
|
2773 | 469 |
iconHeight := icon value height + oneMillimeter |
306 | 470 |
] ifFalse:[ |
471 |
iconHeight := 0 |
|
472 |
]. |
|
629 | 473 |
image notNil ifTrue:[ |
2773 | 474 |
imageHeight := image value height + oneMillimeter |
629 | 475 |
] ifFalse:[ |
476 |
imageHeight := 0 |
|
477 |
]. |
|
5209 | 478 |
string size ~~ 0 ifTrue:[ |
719 | 479 |
stringHeight := string heightOn:aGC |
480 |
] ifFalse:[ |
|
481 |
stringHeight := 0 |
|
482 |
]. |
|
5209 | 483 |
^ (iconHeight max: imageHeight) max: stringHeight |
4779
85c21ae4fddc
UI fix in LabelAndIcon: do not add extra space to height - looks ugly.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4678
diff
changeset
|
484 |
|
85c21ae4fddc
UI fix in LabelAndIcon: do not add extra space to height - looks ugly.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4678
diff
changeset
|
485 |
"Modified: / 02-06-2015 / 14:14:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
172 | 486 |
! |
487 |
||
488 |
widthOn:aGC |
|
489 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
490 |
||
719 | 491 |
|width| |
306 | 492 |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
493 |
width := offset. |
306 | 494 |
icon notNil ifTrue:[ |
2773 | 495 |
width := width + icon value width |
306 | 496 |
]. |
629 | 497 |
image notNil ifTrue:[ |
2773 | 498 |
width := width + gap + image value width |
629 | 499 |
]. |
5209 | 500 |
string size ~~ 0 ifTrue:[ |
719 | 501 |
width := width + gap + (string widthOn:aGC) |
502 |
]. |
|
503 |
^width |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
504 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
505 |
"Modified: / 21.6.1998 / 03:11:14 / cg" |
172 | 506 |
! ! |
507 |
||
4678 | 508 |
!LabelAndIcon methodsFor:'testing'! |
509 |
||
510 |
isLabelAndIcon |
|
511 |
^ true |
|
512 |
! ! |
|
513 |
||
514 |
!LabelAndIcon methodsFor:'text compatibility'! |
|
515 |
||
516 |
withoutAnyColorEmphasis |
|
517 |
^ self shallowCopy string:(string withoutAnyColorEmphasis) |
|
518 |
! |
|
519 |
||
520 |
withoutBackgroundColorEmphasis |
|
521 |
^ self shallowCopy string:(string withoutBackgroundColorEmphasis) |
|
522 |
! |
|
523 |
||
524 |
withoutForegroundColorEmphasis |
|
525 |
^ self shallowCopy string:(string withoutForegroundColorEmphasis) |
|
526 |
! ! |
|
527 |
||
172 | 528 |
!LabelAndIcon class methodsFor:'documentation'! |
529 |
||
530 |
version |
|
4878 | 531 |
^ '$Header$' |
3781 | 532 |
! |
533 |
||
534 |
version_CVS |
|
4878 | 535 |
^ '$Header$' |
4779
85c21ae4fddc
UI fix in LabelAndIcon: do not add extra space to height - looks ugly.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4678
diff
changeset
|
536 |
! |
85c21ae4fddc
UI fix in LabelAndIcon: do not add extra space to height - looks ugly.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4678
diff
changeset
|
537 |
|
85c21ae4fddc
UI fix in LabelAndIcon: do not add extra space to height - looks ugly.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4678
diff
changeset
|
538 |
version_HG |
85c21ae4fddc
UI fix in LabelAndIcon: do not add extra space to height - looks ugly.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4678
diff
changeset
|
539 |
|
85c21ae4fddc
UI fix in LabelAndIcon: do not add extra space to height - looks ugly.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4678
diff
changeset
|
540 |
^ '$Changeset: <not expanded> $' |
172 | 541 |
! ! |
4678 | 542 |