author | Claus Gittinger <cg@exept.de> |
Fri, 10 Jul 1998 01:58:57 +0200 | |
changeset 986 | ed6b89c43416 |
parent 981 | b7558ca52e20 |
child 1479 | 8511f61fe8fe |
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" |
|
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
207 |
! |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
208 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
209 |
string:aString |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
210 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
211 |
^ self new icon:nil string:aString |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
212 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
213 |
"Created: / 21.6.1998 / 04:57:28 / cg" |
172 | 214 |
! ! |
215 |
||
216 |
!LabelAndIcon methodsFor:'accessing'! |
|
217 |
||
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
218 |
beCheckMark |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
219 |
self icon:(CheckToggle checkFormOn:Screen current) |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
220 |
|
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
221 |
"Created: / 21.6.1998 / 05:01:01 / cg" |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
222 |
"Modified: / 21.6.1998 / 05:03:23 / cg" |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
223 |
! |
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
224 |
|
629 | 225 |
form:aForm image:anImage string:aString |
226 |
||
227 |
icon := aForm. |
|
228 |
image:= anImage. |
|
229 |
string := aString. |
|
230 |
! |
|
231 |
||
172 | 232 |
gap:pixels |
233 |
"set the spacing between the icon and the labelString. |
|
234 |
The default is 4." |
|
235 |
||
236 |
gap := pixels. |
|
237 |
||
238 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
239 |
! |
|
240 |
||
286 | 241 |
icon |
242 |
"return my icon part" |
|
243 |
||
244 |
^ icon |
|
245 |
! |
|
246 |
||
172 | 247 |
icon:anIcon |
248 |
"set the icon image" |
|
249 |
||
250 |
icon := anIcon. |
|
251 |
||
252 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
253 |
! |
|
254 |
||
255 |
icon:anIcon string:aString |
|
256 |
"set both iconImage and the labelString" |
|
257 |
||
258 |
icon := anIcon. |
|
259 |
string := aString |
|
260 |
||
261 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
175 | 262 |
! |
263 |
||
719 | 264 |
image |
265 |
"return my image" |
|
266 |
||
267 |
^ image |
|
268 |
! |
|
269 |
||
270 |
image:anImage |
|
271 |
"set the image" |
|
272 |
||
273 |
image := anImage |
|
274 |
! |
|
275 |
||
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
276 |
offset:pixels |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
277 |
"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
|
278 |
The default is 0." |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
279 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
280 |
offset := pixels. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
281 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
282 |
"Created: / 21.6.1998 / 03:11:03 / cg" |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
283 |
! |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
284 |
|
175 | 285 |
string |
180 | 286 |
"return my string part" |
287 |
||
175 | 288 |
^ string |
258 | 289 |
! |
290 |
||
291 |
string:aString |
|
292 |
"set the labelString" |
|
293 |
||
294 |
string := aString |
|
295 |
||
296 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
172 | 297 |
! ! |
298 |
||
177 | 299 |
!LabelAndIcon methodsFor:'conversion'! |
300 |
||
301 |
asString |
|
180 | 302 |
"return my string part" |
303 |
||
177 | 304 |
^ string |
305 |
||
306 |
"Created: 12.5.1996 / 21:26:47 / cg" |
|
307 |
! ! |
|
308 |
||
172 | 309 |
!LabelAndIcon methodsFor:'displaying'! |
310 |
||
311 |
displayOn:aGC x:x y:y opaque:opaque |
|
312 |
"display the receiver on a GC" |
|
313 |
||
726 | 314 |
|y1 x1 iconHeight imageHeight stringHeight maxHeight gapY asc| |
315 |
||
316 |
gapY := (aGC device pixelPerMillimeter x) rounded. |
|
317 |
asc := (aGC font on:aGC device) ascent. |
|
180 | 318 |
|
726 | 319 |
iconHeight := icon notNil ifTrue:[icon height] ifFalse:[0]. |
320 |
imageHeight := image notNil ifTrue:[image height] ifFalse:[0]. |
|
321 |
stringHeight := string size > 0 ifTrue:[string heightOn:aGC] ifFalse:[0]. |
|
172 | 322 |
|
726 | 323 |
maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight. |
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
324 |
x1 := x + offset. |
258 | 325 |
|
306 | 326 |
icon notNil ifTrue:[ |
726 | 327 |
y1 := y - asc + (maxHeight - iconHeight + 1 // 2). |
328 |
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
|
329 |
|
726 | 330 |
(opaque and:[icon mask isNil]) ifTrue:[aGC displayOpaqueForm:icon x:x1 y:y1] |
331 |
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
|
332 |
|
726 | 333 |
x1 := x1 + icon width + gap |
258 | 334 |
]. |
335 |
||
629 | 336 |
image notNil ifTrue:[ |
726 | 337 |
y1 := y - asc + (maxHeight - imageHeight + 1 // 2). |
338 |
image := image onDevice:aGC device. |
|
339 |
||
340 |
(opaque and:[image mask isNil]) ifTrue:[aGC displayOpaqueForm:image x:x1 y:y1] |
|
341 |
ifFalse:[aGC displayForm:image x:x1 y:y1]. |
|
629 | 342 |
|
726 | 343 |
x1 := x1 + image width + gap |
629 | 344 |
]. |
172 | 345 |
|
726 | 346 |
stringHeight ~~ 0 ifTrue:[ |
347 |
y1 := y + (maxHeight - stringHeight + 1 // 2). |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
348 |
string displayOn:aGC x:x1 y:y1 opaque:opaque |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
349 |
] |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
350 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
351 |
"Modified: / 21.6.1998 / 03:52:12 / cg" |
810 | 352 |
! |
353 |
||
354 |
on:aDevice |
|
355 |
"return a new image on a device |
|
356 |
" |
|
357 |
|form img| |
|
358 |
||
359 |
form := icon notNil ifTrue:[icon on:aDevice] ifFalse:[nil]. |
|
360 |
img := image notNil ifTrue:[image on:aDevice] ifFalse:[nil]. |
|
361 |
||
362 |
^ LabelAndIcon form:form image:img string:string |
|
363 |
||
364 |
! |
|
365 |
||
366 |
onDevice:aDevice |
|
367 |
"return a new image on a device |
|
368 |
" |
|
369 |
^ self on:aDevice |
|
172 | 370 |
! ! |
371 |
||
372 |
!LabelAndIcon methodsFor:'initialization'! |
|
373 |
||
374 |
initialize |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
375 |
gap := 4. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
376 |
offset := 0. |
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
377 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
378 |
"Modified: / 21.6.1998 / 03:10:19 / cg" |
172 | 379 |
! ! |
380 |
||
381 |
!LabelAndIcon methodsFor:'queries'! |
|
382 |
||
383 |
heightOn:aGC |
|
384 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
385 |
||
719 | 386 |
|iconHeight imageHeight stringHeight oneMillimeter| |
682 | 387 |
|
388 |
oneMillimeter := aGC device pixelPerMillimeter x rounded. |
|
306 | 389 |
|
390 |
icon notNil ifTrue:[ |
|
682 | 391 |
iconHeight := icon height + oneMillimeter |
306 | 392 |
] ifFalse:[ |
393 |
iconHeight := 0 |
|
394 |
]. |
|
629 | 395 |
image notNil ifTrue:[ |
682 | 396 |
imageHeight := image height + oneMillimeter |
629 | 397 |
] ifFalse:[ |
398 |
imageHeight := 0 |
|
399 |
]. |
|
719 | 400 |
string size > 0 ifTrue:[ |
401 |
stringHeight := string heightOn:aGC |
|
402 |
] ifFalse:[ |
|
403 |
stringHeight := 0 |
|
404 |
]. |
|
726 | 405 |
^ ((iconHeight max: imageHeight) max: stringHeight) |
172 | 406 |
! |
407 |
||
408 |
widthOn:aGC |
|
409 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
410 |
||
719 | 411 |
|width| |
306 | 412 |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
413 |
width := offset. |
306 | 414 |
icon notNil ifTrue:[ |
719 | 415 |
width := width + icon width |
306 | 416 |
]. |
629 | 417 |
image notNil ifTrue:[ |
719 | 418 |
width := width + gap + image width |
629 | 419 |
]. |
719 | 420 |
string size > 0 ifTrue:[ |
421 |
width := width + gap + (string widthOn:aGC) |
|
422 |
]. |
|
423 |
^width |
|
981
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
424 |
|
b7558ca52e20
added an optional left-offset
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
425 |
"Modified: / 21.6.1998 / 03:11:14 / cg" |
172 | 426 |
! ! |
427 |
||
428 |
!LabelAndIcon class methodsFor:'documentation'! |
|
429 |
||
430 |
version |
|
986
ed6b89c43416
added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
981
diff
changeset
|
431 |
^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.23 1998-07-09 23:58:57 cg Exp $' |
172 | 432 |
! ! |