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