author | tz |
Wed, 04 Feb 1998 18:52:06 +0100 | |
changeset 726 | 4b3a40124f6d |
parent 719 | 3a833ca1c54a |
child 810 | 847d7f52a2fd |
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 |
|
629 | 15 |
instanceVariableNames:'icon gap string image' |
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 |
||
175 | 262 |
string |
180 | 263 |
"return my string part" |
264 |
||
175 | 265 |
^ string |
258 | 266 |
! |
267 |
||
268 |
string:aString |
|
269 |
"set the labelString" |
|
270 |
||
271 |
string := aString |
|
272 |
||
273 |
"Created: 12.5.1996 / 20:00:52 / cg" |
|
172 | 274 |
! ! |
275 |
||
177 | 276 |
!LabelAndIcon methodsFor:'conversion'! |
277 |
||
278 |
asString |
|
180 | 279 |
"return my string part" |
280 |
||
177 | 281 |
^ string |
282 |
||
283 |
"Created: 12.5.1996 / 21:26:47 / cg" |
|
284 |
! ! |
|
285 |
||
172 | 286 |
!LabelAndIcon methodsFor:'displaying'! |
287 |
||
288 |
displayOn:aGC x:x y:y opaque:opaque |
|
289 |
"display the receiver on a GC" |
|
290 |
||
726 | 291 |
|y1 x1 iconHeight imageHeight stringHeight maxHeight gapY asc| |
292 |
||
293 |
gapY := (aGC device pixelPerMillimeter x) rounded. |
|
294 |
asc := (aGC font on:aGC device) ascent. |
|
180 | 295 |
|
726 | 296 |
iconHeight := icon notNil ifTrue:[icon height] ifFalse:[0]. |
297 |
imageHeight := image notNil ifTrue:[image height] ifFalse:[0]. |
|
298 |
stringHeight := string size > 0 ifTrue:[string heightOn:aGC] ifFalse:[0]. |
|
172 | 299 |
|
726 | 300 |
maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight. |
301 |
x1 := x. |
|
258 | 302 |
|
306 | 303 |
icon notNil ifTrue:[ |
726 | 304 |
y1 := y - asc + (maxHeight - iconHeight + 1 // 2). |
305 |
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
|
306 |
|
726 | 307 |
(opaque and:[icon mask isNil]) ifTrue:[aGC displayOpaqueForm:icon x:x1 y:y1] |
308 |
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
|
309 |
|
726 | 310 |
x1 := x1 + icon width + gap |
258 | 311 |
]. |
312 |
||
629 | 313 |
image notNil ifTrue:[ |
726 | 314 |
y1 := y - asc + (maxHeight - imageHeight + 1 // 2). |
315 |
image := image onDevice:aGC device. |
|
316 |
||
317 |
(opaque and:[image mask isNil]) ifTrue:[aGC displayOpaqueForm:image x:x1 y:y1] |
|
318 |
ifFalse:[aGC displayForm:image x:x1 y:y1]. |
|
629 | 319 |
|
726 | 320 |
x1 := x1 + image width + gap |
629 | 321 |
]. |
172 | 322 |
|
726 | 323 |
stringHeight ~~ 0 ifTrue:[ |
324 |
y1 := y + (maxHeight - stringHeight + 1 // 2). |
|
325 |
string displayOn:aGC x:x1 y:y1 |
|
326 |
] |
|
172 | 327 |
! ! |
328 |
||
329 |
!LabelAndIcon methodsFor:'initialization'! |
|
330 |
||
331 |
initialize |
|
332 |
gap := 4 |
|
333 |
! ! |
|
334 |
||
335 |
!LabelAndIcon methodsFor:'queries'! |
|
336 |
||
337 |
heightOn:aGC |
|
338 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
339 |
||
719 | 340 |
|iconHeight imageHeight stringHeight oneMillimeter| |
682 | 341 |
|
342 |
oneMillimeter := aGC device pixelPerMillimeter x rounded. |
|
306 | 343 |
|
344 |
icon notNil ifTrue:[ |
|
682 | 345 |
iconHeight := icon height + oneMillimeter |
306 | 346 |
] ifFalse:[ |
347 |
iconHeight := 0 |
|
348 |
]. |
|
629 | 349 |
image notNil ifTrue:[ |
682 | 350 |
imageHeight := image height + oneMillimeter |
629 | 351 |
] ifFalse:[ |
352 |
imageHeight := 0 |
|
353 |
]. |
|
719 | 354 |
string size > 0 ifTrue:[ |
355 |
stringHeight := string heightOn:aGC |
|
356 |
] ifFalse:[ |
|
357 |
stringHeight := 0 |
|
358 |
]. |
|
726 | 359 |
^ ((iconHeight max: imageHeight) max: stringHeight) |
172 | 360 |
! |
361 |
||
362 |
widthOn:aGC |
|
363 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
364 |
||
719 | 365 |
|width| |
306 | 366 |
|
719 | 367 |
width := 0. |
306 | 368 |
icon notNil ifTrue:[ |
719 | 369 |
width := width + icon width |
306 | 370 |
]. |
629 | 371 |
image notNil ifTrue:[ |
719 | 372 |
width := width + gap + image width |
629 | 373 |
]. |
719 | 374 |
string size > 0 ifTrue:[ |
375 |
width := width + gap + (string widthOn:aGC) |
|
376 |
]. |
|
377 |
^width |
|
378 |
||
172 | 379 |
! ! |
380 |
||
381 |
!LabelAndIcon class methodsFor:'documentation'! |
|
382 |
||
383 |
version |
|
726 | 384 |
^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.20 1998-02-04 17:52:06 tz Exp $' |
172 | 385 |
! ! |