20
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
20
|
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 |
Button subclass:#PopUpList
|
59
|
14 |
instanceVariableNames:'menu menuAction'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Interactors'
|
20
|
18 |
!
|
|
19 |
|
|
20 |
PopUpList comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
20
|
23 |
|
70
|
24 |
$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.5 1994-11-28 21:05:13 claus Exp $
|
38
|
25 |
'!
|
|
26 |
|
|
27 |
!PopUpList class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
38
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
70
|
45 |
$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.5 1994-11-28 21:05:13 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
20
|
48 |
|
38
|
49 |
documentation
|
|
50 |
"
|
|
51 |
a PopUpList is basically a button with a popup menu.
|
|
52 |
The PopUpLists label is showing the current selection from the
|
|
53 |
list.
|
63
|
54 |
"
|
|
55 |
!
|
38
|
56 |
|
63
|
57 |
examples
|
|
58 |
"
|
38
|
59 |
example use:
|
|
60 |
|
|
61 |
|p|
|
|
62 |
p := PopUpList label:'healthy fruit'.
|
|
63 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margarithas').
|
|
64 |
|
|
65 |
p open
|
|
66 |
|
|
67 |
|
|
68 |
with an initial selection:
|
|
69 |
|
|
70 |
|p|
|
|
71 |
p := PopUpList label:'dummy'.
|
|
72 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margarithas').
|
|
73 |
p selection:'apples'.
|
|
74 |
p open
|
|
75 |
|
|
76 |
|
|
77 |
with separating lines:
|
|
78 |
|
|
79 |
|p|
|
|
80 |
p := PopUpList label:'dummy'.
|
|
81 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margarithas').
|
|
82 |
p selection:'apples'.
|
|
83 |
p open
|
|
84 |
"
|
|
85 |
! !
|
20
|
86 |
|
|
87 |
!PopUpList methodsFor:'drawing'!
|
|
88 |
|
|
89 |
drawWith:fgColor and:bgColor
|
|
90 |
|mmH mmV mW mH|
|
|
91 |
|
|
92 |
pressed ifTrue:[
|
59
|
93 |
super drawWith:enteredFgColor and:enteredBgColor
|
20
|
94 |
] ifFalse:[
|
59
|
95 |
super drawWith:fgColor and:bgColor.
|
20
|
96 |
].
|
|
97 |
mmH := (device horizontalPixelPerMillimeter * 1) rounded.
|
|
98 |
mmV := (device verticalPixelPerMillimeter * 1) rounded.
|
|
99 |
mW := (device horizontalPixelPerMillimeter * 2.5) rounded.
|
|
100 |
mH := (device verticalPixelPerMillimeter * 1.5) rounded.
|
|
101 |
|
|
102 |
self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2)
|
59
|
103 |
width:mW height:mH level:2
|
20
|
104 |
! !
|
|
105 |
|
70
|
106 |
!PopUpList methodsFor:'event handling'!
|
20
|
107 |
|
|
108 |
buttonPress:button x:x y:y
|
38
|
109 |
|org mv|
|
20
|
110 |
|
38
|
111 |
((button == 1) or:[button == #select]) ifTrue:[
|
59
|
112 |
menu notNil ifTrue:[
|
|
113 |
menu font:font.
|
38
|
114 |
"
|
59
|
115 |
menu width:self width + (margin * 2).
|
38
|
116 |
"
|
59
|
117 |
mv := menu menuView.
|
|
118 |
mv width:(self width - (2 * menu margin) - (menu borderWidth*2)).
|
|
119 |
mv level:0; borderWidth:0.
|
|
120 |
mv fixSize.
|
|
121 |
org := device translatePoint:0@0
|
|
122 |
from:(self id)
|
|
123 |
to:(DisplayRootView new id).
|
38
|
124 |
|
59
|
125 |
menu showAt:org "resizing:false"
|
|
126 |
]
|
20
|
127 |
].
|
|
128 |
! !
|
|
129 |
|
|
130 |
!PopUpList methodsFor:'initialization'!
|
|
131 |
|
|
132 |
initialize
|
|
133 |
super initialize.
|
59
|
134 |
actionWhenPressed := true.
|
20
|
135 |
self adjust:#left
|
|
136 |
! !
|
|
137 |
|
|
138 |
!PopUpList methodsFor:'accessing'!
|
|
139 |
|
38
|
140 |
action:aOneArgBlock
|
|
141 |
"set the action to be performed on selection changes;
|
|
142 |
the argument, aOneArgBlock will be evaluated with the
|
|
143 |
selection-value as argument"
|
|
144 |
|
|
145 |
menuAction := aOneArgBlock
|
20
|
146 |
!
|
|
147 |
|
|
148 |
list
|
38
|
149 |
"return the list - i.e. the values shown in the pop-up list"
|
|
150 |
|
20
|
151 |
^ menu labels
|
|
152 |
!
|
|
153 |
|
|
154 |
list:aList
|
38
|
155 |
"set the list - i.e. the values shown in the pop-up list"
|
|
156 |
|
20
|
157 |
menu := PopUpMenu
|
59
|
158 |
labels:aList
|
|
159 |
selectors:(Array new:(aList size) withAll:#select:)
|
|
160 |
args:aList
|
|
161 |
receiver:self
|
|
162 |
for:self.
|
38
|
163 |
realized ifTrue:[
|
59
|
164 |
self computeLabelSize
|
38
|
165 |
]
|
|
166 |
|
|
167 |
"
|
|
168 |
|p|
|
|
169 |
p := PopUpList label:'fruit ?'.
|
|
170 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margarithas').
|
|
171 |
p open
|
|
172 |
"
|
20
|
173 |
!
|
|
174 |
|
|
175 |
selection:indexOrString
|
38
|
176 |
"set (force) a selection - usually done to set
|
|
177 |
an initial selection"
|
|
178 |
|
20
|
179 |
|index|
|
|
180 |
|
|
181 |
index := menu labels indexOf:indexOrString.
|
|
182 |
index == 0 ifTrue:[
|
59
|
183 |
indexOrString isNumber ifTrue:[
|
|
184 |
index := indexOrString
|
|
185 |
] ifFalse:[
|
|
186 |
^ self
|
|
187 |
]
|
20
|
188 |
].
|
|
189 |
self label:(menu labels at:index)
|
38
|
190 |
|
|
191 |
"
|
|
192 |
|p|
|
|
193 |
p := PopUpList label:'what fruit ?'.
|
|
194 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margarithas').
|
|
195 |
p selection:'apples'.
|
|
196 |
p open
|
|
197 |
"
|
20
|
198 |
! !
|
|
199 |
|
|
200 |
!PopUpList methodsFor:'private'!
|
|
201 |
|
|
202 |
computeLabelSize
|
|
203 |
"compute the extent needed to hold the label plus the mark"
|
|
204 |
|
|
205 |
|mmH mmV savedLogo longest longestWidth|
|
|
206 |
|
|
207 |
menu isNil ifTrue:[
|
59
|
208 |
super computeLabelSize
|
20
|
209 |
] ifFalse:[
|
59
|
210 |
"hack: simulate logo change to longest menu entry"
|
20
|
211 |
|
59
|
212 |
font := font on:device.
|
|
213 |
longest := logo.
|
|
214 |
longestWidth := font widthOf:logo.
|
|
215 |
menu labels do:[:entry |
|
|
216 |
|this|
|
20
|
217 |
|
59
|
218 |
this := font widthOf:entry printString.
|
|
219 |
this > longestWidth ifTrue:[
|
|
220 |
longest := entry.
|
|
221 |
longestWidth := this
|
|
222 |
].
|
|
223 |
].
|
|
224 |
savedLogo := logo.
|
|
225 |
logo := longest.
|
|
226 |
super computeLabelSize.
|
|
227 |
logo := savedLogo.
|
38
|
228 |
"self halt. "
|
20
|
229 |
].
|
|
230 |
mmH := device horizontalPixelPerMillimeter.
|
|
231 |
mmV := device verticalPixelPerMillimeter.
|
|
232 |
labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace.
|
|
233 |
labelHeight := labelHeight max: (mmV * 2) rounded
|
|
234 |
! !
|
|
235 |
|
|
236 |
!PopUpList methodsFor:'user actions'!
|
|
237 |
|
|
238 |
select:anEntry
|
38
|
239 |
"/ 'selected:' print. anEntry printNewline.
|
20
|
240 |
menuAction notNil ifTrue:[
|
59
|
241 |
menuAction value:anEntry.
|
20
|
242 |
].
|
|
243 |
self sizeFixed:true.
|
|
244 |
self label:anEntry printString.
|
38
|
245 |
(model notNil and:[changeSymbol notNil]) ifTrue:[
|
59
|
246 |
model perform:changeSymbol with:anEntry
|
38
|
247 |
].
|
20
|
248 |
! !
|