author | Claus Gittinger <cg@exept.de> |
Sun, 21 Jun 1998 04:48:23 +0200 | |
changeset 981 | b7558ca52e20 |
parent 810 | 847d7f52a2fd |
child 986 | ed6b89c43416 |
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 |
" |
|
12 |
||
13 |
||
14 |
ListEntry subclass:#LabelAndIcon |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
15 |
instanceVariableNames:'icon gap string image offset' |
172 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Support' |
|
19 |
! |
|
20 |
||
21 |
!LabelAndIcon class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
an icon and a string, side by side. |
|
178 | 41 |
Usable as list entries in a listView (a fileList), as |
179 | 42 |
popUpMenuItems or as Label/Button image. |
172 | 43 |
|
44 |
This is an example class - currently not used by the system. |
|
45 |
||
179 | 46 |
Notice: |
47 |
This is different from ST-80's LabelAndIcon class, which |
|
48 |
inherits from Label. Therefore, things may change in the future. |
|
49 |
||
172 | 50 |
[author:] |
51 |
Claus Gittinger |
|
52 |
||
53 |
[see also:] |
|
54 |
ListEntry Text String Icon |
|
55 |
ListView SelectionInListView |
|
56 |
" |
|
57 |
! |
|
58 |
||
59 |
examples |
|
60 |
" |
|
175 | 61 |
in a listView: |
172 | 62 |
[exBegin] |
63 |
|top slv wrapper l fileImage dirImage| |
|
64 |
||
65 |
fileImage := Image |
|
66 |
width:16 |
|
67 |
height:16 |
|
68 |
depth:1 |
|
69 |
fromArray:#[2r00000000 2r00000000 |
|
70 |
2r00000000 2r00000000 |
|
71 |
2r00011111 2r11100000 |
|
72 |
2r00010000 2r00100000 |
|
73 |
2r00010000 2r00011000 |
|
74 |
2r00010000 2r00001000 |
|
75 |
2r00010000 2r00001000 |
|
76 |
2r00010000 2r00001000 |
|
77 |
2r00010000 2r00001000 |
|
78 |
2r00010000 2r00001000 |
|
79 |
2r00010000 2r00001000 |
|
80 |
2r00010000 2r00001000 |
|
81 |
2r00010000 2r00001000 |
|
82 |
2r00011111 2r11111000 |
|
83 |
2r00000000 2r00000000 |
|
84 |
2r00000000 2r00000000]. |
|
85 |
fileImage photometric:#whiteIs0. |
|
86 |
||
87 |
dirImage := Image |
|
88 |
width:16 |
|
89 |
height:16 |
|
90 |
depth:1 |
|
91 |
fromArray:#[2r00000000 2r00000000 |
|
92 |
2r00000000 2r00000000 |
|
93 |
2r00000000 2r00000000 |
|
94 |
2r01111111 2r11110000 |
|
95 |
2r01000000 2r00001000 |
|
96 |
2r01000000 2r00000100 |
|
97 |
2r01000000 2r00000010 |
|
98 |
2r01000000 2r00000010 |
|
99 |
2r01000000 2r00000010 |
|
100 |
2r01000000 2r00000010 |
|
101 |
2r01000000 2r00000010 |
|
102 |
2r01000000 2r00000010 |
|
103 |
2r01111111 2r11111110 |
|
104 |
2r00000000 2r00000000 |
|
105 |
2r00000000 2r00000000 |
|
106 |
2r00000000 2r00000000]. |
|
107 |
dirImage photometric:#whiteIs0. |
|
108 |
||
109 |
||
110 |
l := OrderedCollection new. |
|
111 |
Filename currentDirectory directoryContents do:[:s | |
|
112 |
s asFilename isDirectory ifTrue:[ |
|
113 |
l add:(LabelAndIcon icon:dirImage string:s) |
|
114 |
] ifFalse:[ |
|
115 |
l add:(LabelAndIcon icon:fileImage string:s) |
|
116 |
] |
|
117 |
]. |
|
118 |
||
119 |
slv := SelectionInListView new. |
|
120 |
slv list:l. |
|
121 |
wrapper := HVScrollableView forView:slv miniScrollerH:true. |
|
122 |
||
123 |
top := StandardSystemView extent:150@200. |
|
124 |
top add:wrapper in:(0.0@0.0 corner:1.0@1.0). |
|
125 |
top open. |
|
126 |
[exEnd] |
|
175 | 127 |
in a selectionInListView: |
172 | 128 |
[exBegin] |
129 |
|top slv wrapper l fileImage dirImage| |
|
130 |
||
131 |
dirImage := Image fromFile:'DirObj.xbm'. |
|
132 |
fileImage := Image fromFile:'FileObj.xbm'. |
|
133 |
||
134 |
||
135 |
l := OrderedCollection new. |
|
136 |
Filename currentDirectory directoryContents do:[:s | |
|
137 |
s asFilename isDirectory ifTrue:[ |
|
138 |
l add:(LabelAndIcon icon:dirImage string:s) |
|
139 |
] ifFalse:[ |
|
140 |
l add:(LabelAndIcon icon:fileImage string:s) |
|
141 |
] |
|
142 |
]. |
|
143 |
||
144 |
slv := SelectionInListView new. |
|
145 |
slv list:l. |
|
146 |
wrapper := HVScrollableView forView:slv miniScrollerH:true. |
|
147 |
||
148 |
top := StandardSystemView extent:150@200. |
|
149 |
top add:wrapper in:(0.0@0.0 corner:1.0@1.0). |
|
150 |
top open. |
|
151 |
[exEnd] |
|
175 | 152 |
in a menu: |
153 |
[exBegin] |
|
154 |
|top l fileImage dirImage| |
|
155 |
||
156 |
dirImage := Image fromFile:'DirObj.xbm'. |
|
157 |
fileImage := Image fromFile:'FileObj.xbm'. |
|
158 |
||
159 |
||
160 |
l := OrderedCollection new. |
|
161 |
l add:(LabelAndIcon icon:dirImage string:'create directory'). |
|
162 |
l add:(LabelAndIcon icon:fileImage string:'create file'). |
|
163 |
||
164 |
top := View new. |
|
165 |
||
166 |
top middleButtonMenu:(PopUpMenu labels:l |
|
167 |
selectors:#(foo bar)). |
|
168 |
||
169 |
top open. |
|
170 |
[exEnd] |
|
178 | 171 |
in a button/label: |
172 |
[exBegin] |
|
173 |
|top l image| |
|
174 |
||
175 |
image := Image fromFile:'DirObj.xbm'. |
|
176 |
l := (LabelAndIcon icon:image string:'directory'). |
|
177 |
||
178 |
top := Button label:l. |
|
179 |
top open. |
|
180 |
[exEnd] |
|
172 | 181 |
" |
182 |
! ! |
|
183 |
||
184 |
!LabelAndIcon class methodsFor:'instance creation'! |
|
185 |
||
629 | 186 |
form:aForm image:anImage |
726 | 187 |
|
629 | 188 |
^self new form:aForm image:anImage string:'' |
189 |
! |
|
190 |
||
191 |
form:aForm image:anImage string:aString |
|
726 | 192 |
|
629 | 193 |
^self new form:aForm image:anImage string:aString |
194 |
! |
|
195 |
||
172 | 196 |
icon:anIcon string:aString |
726 | 197 |
|
172 | 198 |
^ self new icon:anIcon string:aString |
199 |
||
200 |
"Created: 12.5.1996 / 20:00:58 / cg" |
|
201 |
! |
|
202 |
||
203 |
new |
|
204 |
^ self basicNew initialize |
|
205 |
||
206 |
"Created: 12.5.1996 / 20:00:58 / cg" |
|
207 |
! ! |
|
208 |
||
209 |
!LabelAndIcon methodsFor:'accessing'! |
|
210 |
||
629 | 211 |
form:aForm image:anImage string:aString |
212 |
||
213 |
icon := aForm. |
|
214 |
image:= anImage. |
|
215 |
string := aString. |
|
216 |
! |
|
217 |
||
172 | 218 |
gap:pixels |
219 |
"set the spacing between the icon and the labelString. |
|
220 |
The default is 4." |
|
221 |
||
222 |
gap := pixels. |
|
223 |
||
224 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
225 |
! |
|
226 |
||
286 | 227 |
icon |
228 |
"return my icon part" |
|
229 |
||
230 |
^ icon |
|
231 |
! |
|
232 |
||
172 | 233 |
icon:anIcon |
234 |
"set the icon image" |
|
235 |
||
236 |
icon := anIcon. |
|
237 |
||
238 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
239 |
! |
|
240 |
||
241 |
icon:anIcon string:aString |
|
242 |
"set both iconImage and the labelString" |
|
243 |
||
244 |
icon := anIcon. |
|
245 |
string := aString |
|
246 |
||
247 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
175 | 248 |
! |
249 |
||
719 | 250 |
image |
251 |
"return my image" |
|
252 |
||
253 |
^ image |
|
254 |
! |
|
255 |
||
256 |
image:anImage |
|
257 |
"set the image" |
|
258 |
||
259 |
image := anImage |
|
260 |
! |
|
261 |
||
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
262 |
offset:pixels |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
263 |
"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
|
264 |
The default is 0." |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
265 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
266 |
offset := pixels. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
267 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
268 |
"Created: / 21.6.1998 / 03:11:03 / cg" |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
269 |
! |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
270 |
|
175 | 271 |
string |
180 | 272 |
"return my string part" |
273 |
||
175 | 274 |
^ string |
258 | 275 |
! |
276 |
||
277 |
string:aString |
|
278 |
"set the labelString" |
|
279 |
||
280 |
string := aString |
|
281 |
||
282 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
172 | 283 |
! ! |
284 |
||
177 | 285 |
!LabelAndIcon methodsFor:'conversion'! |
286 |
||
287 |
asString |
|
180 | 288 |
"return my string part" |
289 |
||
177 | 290 |
^ string |
291 |
||
292 |
"Created: 12.5.1996 / 21:26:47 / cg" |
|
293 |
! ! |
|
294 |
||
172 | 295 |
!LabelAndIcon methodsFor:'displaying'! |
296 |
||
297 |
displayOn:aGC x:x y:y opaque:opaque |
|
298 |
"display the receiver on a GC" |
|
299 |
||
726 | 300 |
|y1 x1 iconHeight imageHeight stringHeight maxHeight gapY asc| |
301 |
||
302 |
gapY := (aGC device pixelPerMillimeter x) rounded. |
|
303 |
asc := (aGC font on:aGC device) ascent. |
|
180 | 304 |
|
726 | 305 |
iconHeight := icon notNil ifTrue:[icon height] ifFalse:[0]. |
306 |
imageHeight := image notNil ifTrue:[image height] ifFalse:[0]. |
|
307 |
stringHeight := string size > 0 ifTrue:[string heightOn:aGC] ifFalse:[0]. |
|
172 | 308 |
|
726 | 309 |
maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight. |
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
310 |
x1 := x + offset. |
258 | 311 |
|
306 | 312 |
icon notNil ifTrue:[ |
726 | 313 |
y1 := y - asc + (maxHeight - iconHeight + 1 // 2). |
314 |
icon := icon onDevice:aGC device. |
|
578
72916ad0a5f3
fixed centering of the image w.r.t. the fontHeight
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
315 |
|
726 | 316 |
(opaque and:[icon mask isNil]) ifTrue:[aGC displayOpaqueForm:icon x:x1 y:y1] |
317 |
ifFalse:[aGC displayForm:icon 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
|
318 |
|
726 | 319 |
x1 := x1 + icon width + gap |
258 | 320 |
]. |
321 |
||
629 | 322 |
image notNil ifTrue:[ |
726 | 323 |
y1 := y - asc + (maxHeight - imageHeight + 1 // 2). |
324 |
image := image onDevice:aGC device. |
|
325 |
||
326 |
(opaque and:[image mask isNil]) ifTrue:[aGC displayOpaqueForm:image x:x1 y:y1] |
|
327 |
ifFalse:[aGC displayForm:image x:x1 y:y1]. |
|
629 | 328 |
|
726 | 329 |
x1 := x1 + image width + gap |
629 | 330 |
]. |
172 | 331 |
|
726 | 332 |
stringHeight ~~ 0 ifTrue:[ |
333 |
y1 := y + (maxHeight - stringHeight + 1 // 2). |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
334 |
string displayOn:aGC x:x1 y:y1 opaque:opaque |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
335 |
] |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
336 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
337 |
"Modified: / 21.6.1998 / 03:52:12 / cg" |
810 | 338 |
! |
339 |
||
340 |
on:aDevice |
|
341 |
"return a new image on a device |
|
342 |
" |
|
343 |
|form img| |
|
344 |
||
345 |
form := icon notNil ifTrue:[icon on:aDevice] ifFalse:[nil]. |
|
346 |
img := image notNil ifTrue:[image on:aDevice] ifFalse:[nil]. |
|
347 |
||
348 |
^ LabelAndIcon form:form image:img string:string |
|
349 |
||
350 |
! |
|
351 |
||
352 |
onDevice:aDevice |
|
353 |
"return a new image on a device |
|
354 |
" |
|
355 |
^ self on:aDevice |
|
172 | 356 |
! ! |
357 |
||
358 |
!LabelAndIcon methodsFor:'initialization'! |
|
359 |
||
360 |
initialize |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
361 |
gap := 4. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
362 |
offset := 0. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
363 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
364 |
"Modified: / 21.6.1998 / 03:10:19 / cg" |
172 | 365 |
! ! |
366 |
||
367 |
!LabelAndIcon methodsFor:'queries'! |
|
368 |
||
369 |
heightOn:aGC |
|
370 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
371 |
||
719 | 372 |
|iconHeight imageHeight stringHeight oneMillimeter| |
682 | 373 |
|
374 |
oneMillimeter := aGC device pixelPerMillimeter x rounded. |
|
306 | 375 |
|
376 |
icon notNil ifTrue:[ |
|
682 | 377 |
iconHeight := icon height + oneMillimeter |
306 | 378 |
] ifFalse:[ |
379 |
iconHeight := 0 |
|
380 |
]. |
|
629 | 381 |
image notNil ifTrue:[ |
682 | 382 |
imageHeight := image height + oneMillimeter |
629 | 383 |
] ifFalse:[ |
384 |
imageHeight := 0 |
|
385 |
]. |
|
719 | 386 |
string size > 0 ifTrue:[ |
387 |
stringHeight := string heightOn:aGC |
|
388 |
] ifFalse:[ |
|
389 |
stringHeight := 0 |
|
390 |
]. |
|
726 | 391 |
^ ((iconHeight max: imageHeight) max: stringHeight) |
172 | 392 |
! |
393 |
||
394 |
widthOn:aGC |
|
395 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
396 |
||
719 | 397 |
|width| |
306 | 398 |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
399 |
width := offset. |
306 | 400 |
icon notNil ifTrue:[ |
719 | 401 |
width := width + icon width |
306 | 402 |
]. |
629 | 403 |
image notNil ifTrue:[ |
719 | 404 |
width := width + gap + image width |
629 | 405 |
]. |
719 | 406 |
string size > 0 ifTrue:[ |
407 |
width := width + gap + (string widthOn:aGC) |
|
408 |
]. |
|
409 |
^width |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
410 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
411 |
"Modified: / 21.6.1998 / 03:11:14 / cg" |
172 | 412 |
! ! |
413 |
||
414 |
!LabelAndIcon class methodsFor:'documentation'! |
|
415 |
||
416 |
version |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
417 |
^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.22 1998-06-21 02:48:23 cg Exp $' |
172 | 418 |
! ! |