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
|
|
15 |
instanceVariableNames:'icon gap string'
|
|
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 |
|
|
186 |
icon:anIcon string:aString
|
|
187 |
^ self new icon:anIcon string:aString
|
|
188 |
|
|
189 |
"Created: 12.5.1996 / 20:00:58 / cg"
|
|
190 |
!
|
|
191 |
|
|
192 |
new
|
|
193 |
^ self basicNew initialize
|
|
194 |
|
|
195 |
"Created: 12.5.1996 / 20:00:58 / cg"
|
|
196 |
! !
|
|
197 |
|
|
198 |
!LabelAndIcon methodsFor:'accessing'!
|
|
199 |
|
|
200 |
gap:pixels
|
|
201 |
"set the spacing between the icon and the labelString.
|
|
202 |
The default is 4."
|
|
203 |
|
|
204 |
gap := pixels.
|
|
205 |
|
|
206 |
"Created: 12.5.1996 / 20:00:52 / cg"
|
|
207 |
!
|
|
208 |
|
286
|
209 |
icon
|
|
210 |
"return my icon part"
|
|
211 |
|
|
212 |
^ icon
|
|
213 |
!
|
|
214 |
|
172
|
215 |
icon:anIcon
|
|
216 |
"set the icon image"
|
|
217 |
|
|
218 |
icon := anIcon.
|
|
219 |
|
|
220 |
"Created: 12.5.1996 / 20:00:52 / cg"
|
|
221 |
!
|
|
222 |
|
|
223 |
icon:anIcon string:aString
|
|
224 |
"set both iconImage and the labelString"
|
|
225 |
|
|
226 |
icon := anIcon.
|
|
227 |
string := aString
|
|
228 |
|
|
229 |
"Created: 12.5.1996 / 20:00:52 / cg"
|
175
|
230 |
!
|
|
231 |
|
|
232 |
string
|
180
|
233 |
"return my string part"
|
|
234 |
|
175
|
235 |
^ string
|
258
|
236 |
!
|
|
237 |
|
|
238 |
string:aString
|
|
239 |
"set the labelString"
|
|
240 |
|
|
241 |
string := aString
|
|
242 |
|
|
243 |
"Created: 12.5.1996 / 20:00:52 / cg"
|
172
|
244 |
! !
|
|
245 |
|
177
|
246 |
!LabelAndIcon methodsFor:'conversion'!
|
|
247 |
|
|
248 |
asString
|
180
|
249 |
"return my string part"
|
|
250 |
|
177
|
251 |
^ string
|
|
252 |
|
|
253 |
"Created: 12.5.1996 / 21:26:47 / cg"
|
|
254 |
! !
|
|
255 |
|
172
|
256 |
!LabelAndIcon methodsFor:'displaying'!
|
|
257 |
|
|
258 |
displayOn:aGC x:x y:y opaque:opaque
|
|
259 |
"display the receiver on a GC"
|
|
260 |
|
258
|
261 |
|yOffs font fH iH fA yI|
|
180
|
262 |
|
|
263 |
font := aGC font.
|
|
264 |
fH := font height.
|
|
265 |
iH := icon height.
|
258
|
266 |
fA := font ascent.
|
172
|
267 |
|
258
|
268 |
iH <= fA ifTrue:[
|
|
269 |
"/ place the icon on the baseLine
|
|
270 |
yI := y-fA.
|
|
271 |
] ifFalse:[
|
|
272 |
yI := y-fA+(font descent // 2)-1.
|
|
273 |
].
|
|
274 |
|
287
|
275 |
icon := icon on:aGC device.
|
|
276 |
|
258
|
277 |
(opaque
|
|
278 |
and:[icon mask isNil]) ifTrue:[
|
|
279 |
aGC displayOpaqueForm:icon x:x y:yI.
|
|
280 |
] ifFalse:[
|
|
281 |
aGC displayForm:icon x:x y:yI.
|
|
282 |
].
|
|
283 |
|
180
|
284 |
(iH > fH) ifTrue:[
|
|
285 |
yOffs := (iH - fH) // 2
|
172
|
286 |
] ifFalse:[
|
|
287 |
yOffs := 0
|
|
288 |
].
|
180
|
289 |
|
172
|
290 |
string
|
|
291 |
displayOn:aGC
|
|
292 |
x:x + icon width + gap
|
|
293 |
y:y+yOffs.
|
|
294 |
|
|
295 |
"Modified: 12.5.1996 / 20:36:43 / cg"
|
|
296 |
! !
|
|
297 |
|
|
298 |
!LabelAndIcon methodsFor:'initialization'!
|
|
299 |
|
|
300 |
initialize
|
|
301 |
gap := 4
|
|
302 |
! !
|
|
303 |
|
|
304 |
!LabelAndIcon methodsFor:'queries'!
|
|
305 |
|
|
306 |
heightOn:aGC
|
|
307 |
"return the height of the receiver, if it is to be displayed on aGC"
|
|
308 |
|
|
309 |
^ icon height + (aGC device pixelPerMillimeter x rounded)
|
|
310 |
max:(string heightOn:aGC)
|
|
311 |
|
|
312 |
"Created: 12.5.1996 / 20:26:20 / cg"
|
|
313 |
"Modified: 12.5.1996 / 20:34:23 / cg"
|
|
314 |
!
|
|
315 |
|
|
316 |
widthOn:aGC
|
|
317 |
"return the width of the receiver, if it is to be displayed on aGC"
|
|
318 |
|
|
319 |
^ icon width + gap + (string widthOn:aGC)
|
|
320 |
|
|
321 |
"Created: 12.5.1996 / 20:10:06 / cg"
|
|
322 |
"Modified: 12.5.1996 / 20:13:49 / cg"
|
|
323 |
! !
|
|
324 |
|
|
325 |
!LabelAndIcon class methodsFor:'documentation'!
|
|
326 |
|
|
327 |
version
|
287
|
328 |
^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.10 1997-01-27 14:17:57 ca Exp $'
|
172
|
329 |
! !
|