author | Claus Gittinger <cg@exept.de> |
Tue, 27 Feb 1996 14:51:16 +0100 | |
changeset 417 | 3f48ca2beb7d |
parent 327 | 5cd2a6f4f28e |
child 585 | 8f395aba0173 |
permissions | -rw-r--r-- |
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 |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
14 |
instanceVariableNames:'menu menuAction values useIndex listMsg' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
15 |
classVariableNames:'' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
16 |
poolDictionaries:'' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
17 |
category:'Views-Interactors' |
20 | 18 |
! |
19 |
||
38 | 20 |
!PopUpList class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
59 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
a PopUpList is basically a button with a popup menu. |
|
39 |
The PopUpLists label is showing the current selection from the |
|
40 |
list. |
|
121 | 41 |
When an entry is selected, an actionBlock (if nonNil) is evaluated |
42 |
and (if nonNil), the model is notified via the changeMessage. |
|
125 | 43 |
|
121 | 44 |
The default changeMessage used is #selection:, which allows a |
45 |
PopUpList to be used with a SelectionInList as model. |
|
46 |
(if used with some other model, either use an adaptor, or set the |
|
125 | 47 |
changeMessage to something else ..) |
48 |
||
49 |
Instance variables: |
|
50 |
||
51 |
menu helpers for the popup menu |
|
52 |
menuAction |
|
53 |
values |
|
54 |
||
55 |
useIndex <Boolean> if true, the index of the selected entry |
|
56 |
is passed to the action block and the |
|
57 |
model in a change-message. |
|
58 |
If false (the default), the value is passed. |
|
59 |
Notice that the default changeMessage is |
|
60 |
#selection:, which is not ok to be used |
|
61 |
with useIndex:true and a selectionInList model. |
|
62 |
(set the changeMessage to #selectionIndex: then) |
|
63 |
||
64 |
listMsg <Symbol> message to aquire a new list from the |
|
65 |
model. Default is #list. |
|
63 | 66 |
" |
67 |
! |
|
38 | 68 |
|
63 | 69 |
examples |
70 |
" |
|
38 | 71 |
example use: |
72 |
||
73 |
|p| |
|
74 |
p := PopUpList label:'healthy fruit'. |
|
119 | 75 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
38 | 76 |
p open |
77 |
||
78 |
||
79 |
with an initial selection: |
|
80 |
||
81 |
|p| |
|
82 |
p := PopUpList label:'dummy'. |
|
119 | 83 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
38 | 84 |
p selection:'apples'. |
85 |
p open |
|
86 |
||
87 |
||
88 |
with separating lines: |
|
89 |
||
90 |
|p| |
|
119 | 91 |
p := PopUpList label:'fruit'. |
92 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
|
38 | 93 |
p selection:'apples'. |
94 |
p open |
|
77 | 95 |
|
96 |
||
97 |
with an action: |
|
98 |
||
99 |
|p| |
|
100 |
p := PopUpList label:'dummy'. |
|
119 | 101 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
77 | 102 |
p selection:'apples'. |
103 |
p action:[:what | Transcript showCr:'you selected: ' , what]. |
|
104 |
p open |
|
105 |
||
106 |
||
119 | 107 |
sometimes, you may like the index instead of the value: |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
108 |
(notice, that the separating line counts, so you have to take care ...) |
119 | 109 |
|
110 |
|p| |
|
111 |
p := PopUpList label:'dummy'. |
|
112 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
|
113 |
p selection:'apples'. |
|
114 |
p action:[:what | Transcript show:'you selected: '; showCr:what]. |
|
115 |
p useIndex:true. |
|
116 |
p open |
|
117 |
||
118 |
||
119 |
since the list is actually a popupMenu, you can add double-separators: |
|
120 |
||
121 |
|p| |
|
122 |
p := PopUpList label:'dummy'. |
|
123 |
p list:#('apples' 'bananas' 'grape' 'lemon' |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
124 |
'=' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
125 |
'margaritas' 'pina colada' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
126 |
'=' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
127 |
'smalltalk' 'c++' 'eiffel' 'java'). |
119 | 128 |
p values:#(apples bananas grape lemon |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
129 |
nil |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
130 |
'mhmh - so good' 'makes headache' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
131 |
nil |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
132 |
'great' 'another headache' 'not bad' 'neat'). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
133 |
p selection:'apples'. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
134 |
p action:[:what | Transcript show:'you selected: '; showCr:what]. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
135 |
p open |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
136 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
137 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
138 |
since the list is actually represented by a menuView, |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
139 |
which itself is inheriting from listView, which itself can display |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
140 |
things different from strings, arbitrary lists can be constructed: |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
141 |
(see ListEntry classes) |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
142 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
143 |
|p l| |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
144 |
p := PopUpList label:'dummy'. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
145 |
l := OrderedCollection new. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
146 |
l add:(ColoredListEntry string:'apples' color:Color red). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
147 |
l add:(ColoredListEntry string:'bananas' color:Color red). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
148 |
l add:(ColoredListEntry string:'grape' color:Color red). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
149 |
l add:(ColoredListEntry string:'lemon' color:Color red). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
150 |
l add:'='. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
151 |
l add:(ColoredListEntry string:'margaritas' color:Color green darkened darkened). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
152 |
l add:(ColoredListEntry string:'pina colada' color:Color green darkened darkened). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
153 |
l add:'='. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
154 |
l add:(ColoredListEntry string:'smalltalk' color:Color blue). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
155 |
l add:(ColoredListEntry string:'c++' color:Color blue). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
156 |
l add:(ColoredListEntry string:'eiffel' color:Color blue). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
157 |
l add:(ColoredListEntry string:'java' color:Color blue). |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
158 |
p list:l. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
159 |
p values:#(apples bananas grape lemon |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
160 |
nil |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
161 |
'mhmh - so good' 'makes headache' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
162 |
nil |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
163 |
'great' 'another headache' 'not bad' 'neat'). |
119 | 164 |
p selection:'apples'. |
165 |
p action:[:what | Transcript show:'you selected: '; showCr:what]. |
|
166 |
p open |
|
167 |
||
168 |
||
77 | 169 |
with values different from the label strings: |
170 |
||
171 |
|p| |
|
172 |
p := PopUpList label:'dummy'. |
|
119 | 173 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
77 | 174 |
p selection:'apples'. |
175 |
p values:#(10 20 30 40 nil 50). |
|
176 |
p action:[:what | Transcript show:'you selected: '; showCr:what]. |
|
177 |
p open |
|
119 | 178 |
|
121 | 179 |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
180 |
with a model (see in the inspector, how the valueHolders index-value changes): |
119 | 181 |
|
182 |
|p model| |
|
183 |
||
184 |
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
185 |
||
186 |
p := PopUpList label:'healthy fruit'. |
|
187 |
p model:model. |
|
188 |
p open. |
|
121 | 189 |
model selectionIndexHolder inspect |
190 |
||
20 | 191 |
|
125 | 192 |
a popupList and a SelectionInListView on the same model: |
193 |
||
194 |
|p slv model| |
|
195 |
||
196 |
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
197 |
model selection:'apples'. |
|
198 |
||
199 |
p := PopUpList on:model. |
|
126 | 200 |
p useIndex:true; aspect:#selectionIndex; change:#selectionIndex:. |
125 | 201 |
p open. |
202 |
||
203 |
slv := SelectionInListView on:model. |
|
204 |
slv open. |
|
205 |
||
126 | 206 |
p inspect. |
125 | 207 |
model selectionIndexHolder inspect |
208 |
||
209 |
||
127 | 210 |
two PopUpLists on the same model, different aspects: |
121 | 211 |
|
212 |
|top panel p model| |
|
20 | 213 |
|
121 | 214 |
model := Plug new. |
215 |
model respondTo:#eat: with:[:val | Transcript showCr:'eat: ' , val]. |
|
216 |
model respondTo:#drink: with:[:val | Transcript showCr:'drink: ' , val]. |
|
217 |
model respondTo:#meals with:[#(taco burrito enchilada)]. |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
218 |
model respondTo:#drinks with:[#(margarita water corona)]. |
20 | 219 |
|
121 | 220 |
top := StandardSystemView new. |
221 |
top extent:(100@100). |
|
222 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
223 |
panel horizontalLayout:#fitSpace. |
|
77 | 224 |
|
121 | 225 |
p := PopUpList label:'meals'. |
126 | 226 |
p model:model; listMessage:#meals; aspect:nil; change:#eat:. |
121 | 227 |
panel add:p. |
119 | 228 |
|
121 | 229 |
p := PopUpList label:'drinks'. |
126 | 230 |
p model:model; listMessage:#drinks; aspect:nil; change:#drink:. |
121 | 231 |
panel add:p. |
77 | 232 |
|
121 | 233 |
top open |
234 |
" |
|
20 | 235 |
! ! |
236 |
||
125 | 237 |
!PopUpList class methodsFor:'defaults'! |
238 |
||
239 |
defaultAspectMessage |
|
240 |
^ #selection |
|
241 |
! |
|
242 |
||
243 |
defaultChangeMessage |
|
244 |
^ #selection: |
|
205 | 245 |
! |
246 |
||
247 |
defaultListMessage |
|
248 |
^ #list |
|
249 |
! ! |
|
250 |
||
251 |
!PopUpList methodsFor:'accessing'! |
|
252 |
||
253 |
action:aOneArgBlock |
|
254 |
"set the action to be performed on selection changes; |
|
255 |
the argument, aOneArgBlock will be evaluated with the |
|
256 |
selection-value as argument" |
|
257 |
||
258 |
menuAction := aOneArgBlock |
|
259 |
! |
|
260 |
||
261 |
contents |
|
262 |
^ self label |
|
263 |
! |
|
264 |
||
265 |
contents:con |
|
266 |
^ self selection:con |
|
267 |
||
268 |
! |
|
269 |
||
270 |
list |
|
271 |
"return the list - i.e. the values shown in the pop-up list" |
|
272 |
||
273 |
^ menu labels |
|
274 |
! |
|
275 |
||
276 |
list:aList |
|
277 |
"set the list - i.e. the values shown in the pop-up list" |
|
278 |
||
279 |
self createMenuFor:aList. |
|
280 |
realized ifTrue:[ |
|
281 |
self computeLabelSize |
|
282 |
] |
|
283 |
||
284 |
" |
|
285 |
|p| |
|
286 |
p := PopUpList label:'fruit ?'. |
|
287 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
288 |
p action:[:val | Transcript showCr:'selected: ' , val printString]. |
|
289 |
p open |
|
290 |
" |
|
291 |
! |
|
292 |
||
293 |
selection:indexOrString |
|
294 |
"set (force) a selection - usually done to set |
|
295 |
an initial selection without updating others" |
|
296 |
||
297 |
|index wasFix| |
|
298 |
||
299 |
index := menu indexOf:indexOrString. |
|
300 |
index == 0 ifTrue:[^ self]. |
|
301 |
||
302 |
"kludge: dont want label to resize ..." |
|
303 |
wasFix := fixSize. fixSize := true. |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
304 |
self label:(menu labels at:index) printString. |
205 | 305 |
fixSize := wasFix |
306 |
||
307 |
" |
|
308 |
|p| |
|
309 |
p := PopUpList label:'what fruit ?'. |
|
310 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
311 |
p selection:'grape'. |
|
312 |
p open |
|
313 |
||
314 |
|p| |
|
315 |
p := PopUpList label:'what fruit ?'. |
|
316 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
317 |
p selection:'blabla'. |
|
318 |
p open |
|
319 |
" |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
320 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
321 |
"Modified: 8.2.1996 / 12:55:01 / cg" |
205 | 322 |
! |
323 |
||
324 |
useIndex:aBoolean |
|
325 |
"tell the popuplist to pass the index (instead of the value) |
|
326 |
to both the actionBlock and model. Notice, that if you use a model, |
|
327 |
the default changeSelector is not ok for using index and a SelectionInList" |
|
328 |
||
329 |
useIndex := aBoolean |
|
330 |
||
331 |
" |
|
332 |
|p| |
|
333 |
p := PopUpList label:'fruit ?'. |
|
334 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
335 |
p action:[:val | Transcript showCr:'selected: ' , val printString]. |
|
336 |
p open. |
|
337 |
" |
|
338 |
" |
|
339 |
|p| |
|
340 |
p := PopUpList label:'fruit ?'. |
|
341 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
342 |
p action:[:val | Transcript showCr:'selected: ' , val printString]. |
|
343 |
p useIndex:true. |
|
344 |
p open. |
|
345 |
" |
|
346 |
! |
|
347 |
||
348 |
values:aList |
|
349 |
"set a value list - these are reported via the action or changeSymbol instead of |
|
350 |
the labe strings." |
|
351 |
||
352 |
values := aList. |
|
353 |
menu args:(1 to:aList size). |
|
354 |
||
355 |
" |
|
356 |
|p| |
|
357 |
p := PopUpList label:'fruit ?'. |
|
358 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
359 |
p values:#(1 2 3 4 'mhmh - good'). |
|
360 |
p action:[:val | Transcript showCr:'selected: ' , val printString]. |
|
361 |
p open. |
|
362 |
" |
|
125 | 363 |
! ! |
364 |
||
205 | 365 |
!PopUpList methodsFor:'accessing-mvc'! |
366 |
||
367 |
addModelInterfaceTo:aDictionary |
|
368 |
"see comment in View>>modelInterface" |
|
369 |
||
370 |
super addModelInterfaceTo:aDictionary. |
|
371 |
aDictionary at:#listMessage put:listMsg |
|
372 |
! |
|
373 |
||
374 |
getListFromModel |
|
375 |
"if I have a model and a listMsg, get my list from it" |
|
376 |
||
377 |
(model notNil |
|
378 |
and:[listMsg notNil]) ifTrue:[ |
|
379 |
self list:(model perform:listMsg). |
|
380 |
]. |
|
381 |
! |
|
382 |
||
383 |
getSelectionFromModel |
|
384 |
"if I have a model and an aspectMsg, get my current value from it" |
|
385 |
||
386 |
(model notNil |
|
387 |
and:[aspectMsg notNil]) ifTrue:[ |
|
388 |
menu isNil ifTrue:[ |
|
389 |
self getListFromModel |
|
390 |
]. |
|
391 |
self selection:(model perform:aspectMsg). |
|
392 |
]. |
|
393 |
! |
|
394 |
||
395 |
listMessage |
|
396 |
"return the selector by which we ask the model for the list. |
|
397 |
Default is #list." |
|
398 |
||
399 |
^ listMsg |
|
400 |
! |
|
401 |
||
402 |
listMessage:aSelector |
|
403 |
"set the selector by which we ask the model for the list. |
|
404 |
Default is #list." |
|
405 |
||
406 |
listMsg := aSelector |
|
407 |
! ! |
|
408 |
||
409 |
!PopUpList methodsFor:'change & update'! |
|
410 |
||
411 |
update:something with:aParameter from:changedObject |
|
412 |
changedObject == model ifTrue:[ |
|
413 |
(something == aspectMsg |
|
414 |
or:[something == #selectionIndex]) ifTrue:[ |
|
415 |
self getSelectionFromModel. |
|
416 |
^ self |
|
417 |
]. |
|
418 |
something == listMsg ifTrue:[ |
|
419 |
self getListFromModel. |
|
420 |
]. |
|
421 |
^ self |
|
422 |
]. |
|
423 |
super update:something with:aParameter from:changedObject |
|
424 |
! ! |
|
425 |
||
426 |
!PopUpList methodsFor:'drawing'! |
|
427 |
||
428 |
drawWith:fgColor and:bgColor |
|
429 |
|mmH mmV mW mH| |
|
136 | 430 |
|
205 | 431 |
controller pressed ifTrue:[ |
432 |
super drawWith:enteredFgColor and:enteredBgColor |
|
433 |
] ifFalse:[ |
|
434 |
super drawWith:fgColor and:bgColor. |
|
435 |
]. |
|
436 |
mmH := device horizontalPixelPerMillimeter rounded. |
|
437 |
mmV := device verticalPixelPerMillimeter rounded. |
|
438 |
mW := (device horizontalPixelPerMillimeter * 2.5) rounded. |
|
439 |
mH := (device verticalPixelPerMillimeter * 1.5) rounded. |
|
440 |
||
441 |
self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2) |
|
442 |
width:mW height:mH level:2 |
|
443 |
! |
|
444 |
||
445 |
showActive |
|
446 |
"no need to redraw - will pop menu ontop of me anyway ..." |
|
447 |
||
448 |
^ self |
|
449 |
! |
|
450 |
||
451 |
showPassive |
|
452 |
"no need to redraw - will redraw from unpopped menu anyway ..." |
|
453 |
||
454 |
^ self |
|
455 |
! ! |
|
456 |
||
457 |
!PopUpList methodsFor:'event handling'! |
|
458 |
||
459 |
popMenu |
|
460 |
|org mv w| |
|
461 |
||
462 |
menu notNil ifTrue:[ |
|
463 |
self turnOffWithoutRedraw. |
|
464 |
menu font:font. |
|
136 | 465 |
|
205 | 466 |
" |
467 |
adjust the menus width to my current width |
|
468 |
" |
|
469 |
mv := menu menuView. |
|
470 |
mv create. "/ stupid: it resizes itself upon first create |
|
471 |
w := mv width. "/ to its preferred size. |
|
472 |
w := w max:(self width - (2 * menu margin) - (menu borderWidth*2)). |
|
473 |
mv width:w. |
|
474 |
mv level:0; borderWidth:0. |
|
475 |
||
476 |
" |
|
477 |
the popupMenu wants Display coordinates in its showAt: method |
|
478 |
" |
|
479 |
org := device translatePoint:0@0 |
|
480 |
from:(self id) |
|
481 |
to:(DisplayRootView new id). |
|
482 |
||
483 |
menu showAt:org "resizing:false" |
|
484 |
]. |
|
485 |
! ! |
|
486 |
||
487 |
!PopUpList methodsFor:'initialization'! |
|
488 |
||
489 |
defaultControllerClass |
|
490 |
^ PopUpListController |
|
491 |
! |
|
492 |
||
493 |
initialize |
|
494 |
super initialize. |
|
495 |
||
496 |
controller beTriggerOnDown. |
|
497 |
controller action:[self popMenu]. |
|
498 |
self adjust:#left. |
|
499 |
useIndex := false. |
|
500 |
self label:'popup'. |
|
501 |
listMsg := self class defaultListMessage. |
|
502 |
||
503 |
onLevel := offLevel. |
|
136 | 504 |
! ! |
505 |
||
20 | 506 |
!PopUpList methodsFor:'private'! |
507 |
||
508 |
computeLabelSize |
|
509 |
"compute the extent needed to hold the label plus the mark" |
|
510 |
||
511 |
|mmH mmV savedLogo longest longestWidth| |
|
512 |
||
513 |
menu isNil ifTrue:[ |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
514 |
super computeLabelSize |
20 | 515 |
] ifFalse:[ |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
516 |
"hack: simulate logo change to longest menu entry" |
20 | 517 |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
518 |
font := font on:device. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
519 |
longest := logo. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
520 |
longestWidth := font widthOf:logo. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
521 |
menu labels do:[:entry | |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
522 |
|this| |
20 | 523 |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
524 |
this := font widthOf:entry printString. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
525 |
this > longestWidth ifTrue:[ |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
526 |
longest := entry. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
527 |
longestWidth := this |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
528 |
]. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
529 |
]. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
530 |
savedLogo := logo. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
531 |
logo := longest printString. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
532 |
super computeLabelSize. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
533 |
logo := savedLogo. |
38 | 534 |
"self halt. " |
20 | 535 |
]. |
536 |
mmH := device horizontalPixelPerMillimeter. |
|
537 |
mmV := device verticalPixelPerMillimeter. |
|
538 |
labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace. |
|
539 |
labelHeight := labelHeight max: (mmV * 2) rounded |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
540 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
541 |
"Modified: 8.2.1996 / 13:00:33 / cg" |
121 | 542 |
! |
543 |
||
544 |
createMenuFor:aList |
|
545 |
menu := PopUpMenu |
|
546 |
labels:aList |
|
547 |
selectors:#select: |
|
548 |
args:(1 to:aList size) |
|
549 |
receiver:self |
|
550 |
for:self. |
|
128 | 551 |
! |
552 |
||
205 | 553 |
realize |
554 |
super realize. |
|
555 |
model notNil ifTrue:[ |
|
556 |
self getListFromModel. |
|
557 |
self getSelectionFromModel. |
|
121 | 558 |
]. |
559 |
! ! |
|
560 |
||
205 | 561 |
!PopUpList methodsFor:'private-controller access'! |
121 | 562 |
|
205 | 563 |
menu |
564 |
"return the menu component" |
|
125 | 565 |
|
205 | 566 |
^ menu |
126 | 567 |
! ! |
568 |
||
136 | 569 |
!PopUpList methodsFor:'queries'! |
570 |
||
571 |
preferredExtent |
|
572 |
"redefined to make certain that the menu is fully defined" |
|
573 |
||
574 |
menu isNil ifTrue:[ |
|
575 |
self getListFromModel |
|
576 |
]. |
|
577 |
self computeLabelSize. |
|
578 |
^ super preferredExtent. |
|
155 | 579 |
! |
580 |
||
581 |
specClass |
|
582 |
self class == PopUpList ifTrue:[^ PopUpListSpec]. |
|
583 |
^ nil |
|
136 | 584 |
! ! |
585 |
||
20 | 586 |
!PopUpList methodsFor:'user actions'! |
587 |
||
588 |
select:anEntry |
|
119 | 589 |
"this is sent from the popupmenu when an entry was selected" |
590 |
||
77 | 591 |
|value label| |
592 |
||
119 | 593 |
label := menu labels at:anEntry. |
77 | 594 |
values isNil ifTrue:[ |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
595 |
value := anEntry. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
596 |
useIndex ifFalse:[ |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
597 |
value := menu labels at:anEntry. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
598 |
] |
77 | 599 |
] ifFalse:[ |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
600 |
value := values at:anEntry |
77 | 601 |
]. |
602 |
||
20 | 603 |
menuAction notNil ifTrue:[ |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
604 |
menuAction value:value. |
20 | 605 |
]. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
606 |
|
20 | 607 |
self sizeFixed:true. |
77 | 608 |
self label:label printString. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
609 |
|
119 | 610 |
" |
121 | 611 |
tell my model - if any |
119 | 612 |
" |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
613 |
self sendChangeMessageWith:value |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
614 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
615 |
"Modified: 8.2.1996 / 11:58:51 / cg" |
20 | 616 |
! ! |
121 | 617 |
|
205 | 618 |
!PopUpList class methodsFor:'documentation'! |
121 | 619 |
|
205 | 620 |
version |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
621 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.21 1996-02-08 14:08:35 cg Exp $' |
121 | 622 |
! ! |