author | Claus Gittinger <cg@exept.de> |
Fri, 19 Jul 1996 20:57:13 +0200 | |
changeset 799 | 64f8700489a4 |
parent 714 | 5ff02d2d9fa7 |
child 998 | ab1890b4e157 |
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 |
||
799 | 20 |
!PopUpList class methodsFor:'documentation'! |
38 | 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'. |
655 | 113 |
p action:[:what | Transcript showCR:'you selected: ' , what]. |
77 | 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'. |
|
655 | 125 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
119 | 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'. |
655 | 146 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
327
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'. |
655 | 178 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
119 | 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). |
|
655 | 190 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
77 | 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. |
655 | 232 |
model respondTo:#eat: with:[:val | Transcript showCR:'eat: ' , val]. |
233 |
model respondTo:#drink: with:[:val | Transcript showCR:'drink: ' , val]. |
|
121 | 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 |
||
799 | 255 |
!PopUpList class methodsFor:'defaults'! |
125 | 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 |
||
684 | 278 |
"Modified: 25.5.1996 / 14:20:57 / cg" |
205 | 279 |
! |
280 |
||
281 |
list |
|
282 |
"return the list - i.e. the values shown in the pop-up list" |
|
283 |
||
284 |
^ menu labels |
|
285 |
! |
|
286 |
||
287 |
list:aList |
|
288 |
"set the list - i.e. the values shown in the pop-up list" |
|
289 |
||
290 |
self createMenuFor:aList. |
|
291 |
realized ifTrue:[ |
|
292 |
self computeLabelSize |
|
293 |
] |
|
294 |
||
295 |
" |
|
296 |
|p| |
|
297 |
p := PopUpList label:'fruit ?'. |
|
298 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 299 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 300 |
p open |
301 |
" |
|
302 |
! |
|
303 |
||
304 |
selection:indexOrString |
|
305 |
"set (force) a selection - usually done to set |
|
306 |
an initial selection without updating others" |
|
307 |
||
308 |
|index wasFix| |
|
309 |
||
310 |
index := menu indexOf:indexOrString. |
|
311 |
index == 0 ifTrue:[^ self]. |
|
312 |
||
313 |
"kludge: dont want label to resize ..." |
|
314 |
wasFix := fixSize. fixSize := true. |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
315 |
self label:(menu labels at:index) printString. |
205 | 316 |
fixSize := wasFix |
317 |
||
318 |
" |
|
319 |
|p| |
|
320 |
p := PopUpList label:'what fruit ?'. |
|
321 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
322 |
p selection:'grape'. |
|
323 |
p open |
|
324 |
||
325 |
|p| |
|
326 |
p := PopUpList label:'what fruit ?'. |
|
327 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
328 |
p selection:'blabla'. |
|
329 |
p open |
|
330 |
" |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
331 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
332 |
"Modified: 8.2.1996 / 12:55:01 / cg" |
205 | 333 |
! |
334 |
||
593 | 335 |
values:aList |
336 |
"set a value list - these are reported via the action or changeSymbol instead of |
|
337 |
the labe strings." |
|
338 |
||
339 |
values := aList. |
|
340 |
menu args:(1 to:aList size). |
|
341 |
||
342 |
" |
|
343 |
|p| |
|
344 |
p := PopUpList label:'fruit ?'. |
|
345 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
346 |
p values:#(1 2 3 4 'mhmh - good'). |
|
655 | 347 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
593 | 348 |
p open. |
349 |
" |
|
350 |
! ! |
|
351 |
||
352 |
!PopUpList methodsFor:'accessing-behavior'! |
|
353 |
||
354 |
action:aOneArgBlock |
|
355 |
"set the action to be performed on selection changes; |
|
356 |
the argument, aOneArgBlock will be evaluated with the |
|
357 |
selection-value as argument" |
|
358 |
||
359 |
menuAction := aOneArgBlock |
|
360 |
! |
|
361 |
||
205 | 362 |
useIndex:aBoolean |
363 |
"tell the popuplist to pass the index (instead of the value) |
|
364 |
to both the actionBlock and model. Notice, that if you use a model, |
|
365 |
the default changeSelector is not ok for using index and a SelectionInList" |
|
366 |
||
367 |
useIndex := aBoolean |
|
368 |
||
369 |
" |
|
370 |
|p| |
|
371 |
p := PopUpList label:'fruit ?'. |
|
372 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 373 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 374 |
p open. |
375 |
" |
|
376 |
" |
|
377 |
|p| |
|
378 |
p := PopUpList label:'fruit ?'. |
|
379 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 380 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 381 |
p useIndex:true. |
382 |
p open. |
|
383 |
" |
|
125 | 384 |
! ! |
385 |
||
205 | 386 |
!PopUpList methodsFor:'accessing-mvc'! |
387 |
||
388 |
addModelInterfaceTo:aDictionary |
|
389 |
"see comment in View>>modelInterface" |
|
390 |
||
391 |
super addModelInterfaceTo:aDictionary. |
|
392 |
aDictionary at:#listMessage put:listMsg |
|
393 |
! |
|
394 |
||
395 |
getListFromModel |
|
396 |
"if I have a model and a listMsg, get my list from it" |
|
397 |
||
398 |
(model notNil |
|
399 |
and:[listMsg notNil]) ifTrue:[ |
|
400 |
self list:(model perform:listMsg). |
|
401 |
]. |
|
402 |
! |
|
403 |
||
404 |
getSelectionFromModel |
|
405 |
"if I have a model and an aspectMsg, get my current value from it" |
|
406 |
||
407 |
(model notNil |
|
408 |
and:[aspectMsg notNil]) ifTrue:[ |
|
684 | 409 |
menu isNil ifTrue:[ |
410 |
self getListFromModel |
|
411 |
]. |
|
412 |
self selection:(model perform:aspectMsg). |
|
205 | 413 |
]. |
684 | 414 |
|
415 |
"Modified: 25.5.1996 / 14:21:07 / cg" |
|
205 | 416 |
! |
417 |
||
418 |
listMessage |
|
419 |
"return the selector by which we ask the model for the list. |
|
420 |
Default is #list." |
|
421 |
||
422 |
^ listMsg |
|
423 |
! |
|
424 |
||
425 |
listMessage:aSelector |
|
426 |
"set the selector by which we ask the model for the list. |
|
427 |
Default is #list." |
|
428 |
||
429 |
listMsg := aSelector |
|
430 |
! ! |
|
431 |
||
432 |
!PopUpList methodsFor:'change & update'! |
|
433 |
||
434 |
update:something with:aParameter from:changedObject |
|
435 |
changedObject == model ifTrue:[ |
|
436 |
(something == aspectMsg |
|
437 |
or:[something == #selectionIndex]) ifTrue:[ |
|
438 |
self getSelectionFromModel. |
|
439 |
^ self |
|
440 |
]. |
|
441 |
something == listMsg ifTrue:[ |
|
442 |
self getListFromModel. |
|
443 |
]. |
|
444 |
^ self |
|
445 |
]. |
|
446 |
super update:something with:aParameter from:changedObject |
|
447 |
! ! |
|
448 |
||
449 |
!PopUpList methodsFor:'drawing'! |
|
450 |
||
451 |
drawWith:fgColor and:bgColor |
|
452 |
|mmH mmV mW mH| |
|
136 | 453 |
|
205 | 454 |
controller pressed ifTrue:[ |
455 |
super drawWith:enteredFgColor and:enteredBgColor |
|
456 |
] ifFalse:[ |
|
457 |
super drawWith:fgColor and:bgColor. |
|
458 |
]. |
|
459 |
mmH := device horizontalPixelPerMillimeter rounded. |
|
460 |
mmV := device verticalPixelPerMillimeter rounded. |
|
461 |
mW := (device horizontalPixelPerMillimeter * 2.5) rounded. |
|
462 |
mH := (device verticalPixelPerMillimeter * 1.5) rounded. |
|
463 |
||
464 |
self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2) |
|
465 |
width:mW height:mH level:2 |
|
466 |
! |
|
467 |
||
468 |
showActive |
|
469 |
"no need to redraw - will pop menu ontop of me anyway ..." |
|
470 |
||
471 |
^ self |
|
472 |
! |
|
473 |
||
474 |
showPassive |
|
475 |
"no need to redraw - will redraw from unpopped menu anyway ..." |
|
476 |
||
477 |
^ self |
|
478 |
! ! |
|
479 |
||
480 |
!PopUpList methodsFor:'event handling'! |
|
481 |
||
482 |
popMenu |
|
483 |
|org mv w| |
|
484 |
||
485 |
menu notNil ifTrue:[ |
|
486 |
self turnOffWithoutRedraw. |
|
487 |
menu font:font. |
|
136 | 488 |
|
205 | 489 |
" |
490 |
adjust the menus width to my current width |
|
491 |
" |
|
492 |
mv := menu menuView. |
|
493 |
mv create. "/ stupid: it resizes itself upon first create |
|
494 |
w := mv width. "/ to its preferred size. |
|
495 |
w := w max:(self width - (2 * menu margin) - (menu borderWidth*2)). |
|
496 |
mv width:w. |
|
497 |
mv level:0; borderWidth:0. |
|
498 |
||
499 |
" |
|
500 |
the popupMenu wants Display coordinates in its showAt: method |
|
501 |
" |
|
502 |
org := device translatePoint:0@0 |
|
503 |
from:(self id) |
|
694 | 504 |
to:(device rootView id). |
205 | 505 |
|
506 |
menu showAt:org "resizing:false" |
|
507 |
]. |
|
508 |
! ! |
|
509 |
||
510 |
!PopUpList methodsFor:'initialization'! |
|
511 |
||
512 |
defaultControllerClass |
|
513 |
^ PopUpListController |
|
514 |
! |
|
515 |
||
516 |
initialize |
|
517 |
super initialize. |
|
518 |
||
519 |
controller beTriggerOnDown. |
|
520 |
controller action:[self popMenu]. |
|
521 |
self adjust:#left. |
|
522 |
useIndex := false. |
|
523 |
self label:'popup'. |
|
524 |
listMsg := self class defaultListMessage. |
|
525 |
||
526 |
onLevel := offLevel. |
|
136 | 527 |
! ! |
528 |
||
20 | 529 |
!PopUpList methodsFor:'private'! |
530 |
||
531 |
computeLabelSize |
|
532 |
"compute the extent needed to hold the label plus the mark" |
|
533 |
||
534 |
|mmH mmV savedLogo longest longestWidth| |
|
535 |
||
536 |
menu isNil ifTrue:[ |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
537 |
super computeLabelSize |
20 | 538 |
] ifFalse:[ |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
539 |
"hack: simulate logo change to longest menu entry" |
20 | 540 |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
541 |
font := font on:device. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
542 |
longest := logo. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
543 |
longestWidth := font widthOf:logo. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
544 |
menu labels do:[:entry | |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
545 |
|this| |
20 | 546 |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
547 |
this := font widthOf:entry printString. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
548 |
this > longestWidth ifTrue:[ |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
549 |
longest := entry. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
550 |
longestWidth := this |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
551 |
]. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
552 |
]. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
553 |
savedLogo := logo. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
554 |
logo := longest printString. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
555 |
super computeLabelSize. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
556 |
logo := savedLogo. |
38 | 557 |
"self halt. " |
20 | 558 |
]. |
559 |
mmH := device horizontalPixelPerMillimeter. |
|
560 |
mmV := device verticalPixelPerMillimeter. |
|
561 |
labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace. |
|
562 |
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
|
563 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
564 |
"Modified: 8.2.1996 / 13:00:33 / cg" |
121 | 565 |
! |
566 |
||
567 |
createMenuFor:aList |
|
568 |
menu := PopUpMenu |
|
569 |
labels:aList |
|
570 |
selectors:#select: |
|
571 |
args:(1 to:aList size) |
|
572 |
receiver:self |
|
573 |
for:self. |
|
128 | 574 |
! |
575 |
||
205 | 576 |
realize |
577 |
super realize. |
|
578 |
model notNil ifTrue:[ |
|
579 |
self getListFromModel. |
|
580 |
self getSelectionFromModel. |
|
121 | 581 |
]. |
582 |
! ! |
|
583 |
||
205 | 584 |
!PopUpList methodsFor:'private-controller access'! |
121 | 585 |
|
205 | 586 |
menu |
587 |
"return the menu component" |
|
125 | 588 |
|
205 | 589 |
^ menu |
126 | 590 |
! ! |
591 |
||
136 | 592 |
!PopUpList methodsFor:'queries'! |
593 |
||
594 |
preferredExtent |
|
595 |
"redefined to make certain that the menu is fully defined" |
|
596 |
||
799 | 597 |
"/ If I have an explicit preferredExtent .. |
598 |
||
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
599 |
preferredExtent notNil ifTrue:[ |
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
600 |
^ preferredExtent |
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
601 |
]. |
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
602 |
|
136 | 603 |
menu isNil ifTrue:[ |
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
604 |
self getListFromModel |
136 | 605 |
]. |
606 |
self computeLabelSize. |
|
607 |
^ super preferredExtent. |
|
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
608 |
|
799 | 609 |
"Modified: 19.7.1996 / 20:45:16 / cg" |
155 | 610 |
! |
611 |
||
612 |
specClass |
|
613 |
self class == PopUpList ifTrue:[^ PopUpListSpec]. |
|
614 |
^ nil |
|
136 | 615 |
! ! |
616 |
||
20 | 617 |
!PopUpList methodsFor:'user actions'! |
618 |
||
619 |
select:anEntry |
|
119 | 620 |
"this is sent from the popupmenu when an entry was selected" |
621 |
||
77 | 622 |
|value label| |
623 |
||
119 | 624 |
label := menu labels at:anEntry. |
77 | 625 |
values isNil ifTrue:[ |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
626 |
value := anEntry. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
627 |
useIndex ifFalse:[ |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
628 |
value := menu labels at:anEntry. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
629 |
] |
77 | 630 |
] ifFalse:[ |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
631 |
value := values at:anEntry |
77 | 632 |
]. |
633 |
||
20 | 634 |
menuAction notNil ifTrue:[ |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
635 |
menuAction value:value. |
20 | 636 |
]. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
637 |
|
20 | 638 |
self sizeFixed:true. |
77 | 639 |
self label:label printString. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
640 |
|
119 | 641 |
" |
121 | 642 |
tell my model - if any |
119 | 643 |
" |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
644 |
self sendChangeMessageWith:value |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
645 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
646 |
"Modified: 8.2.1996 / 11:58:51 / cg" |
20 | 647 |
! ! |
121 | 648 |
|
799 | 649 |
!PopUpList class methodsFor:'documentation'! |
121 | 650 |
|
205 | 651 |
version |
799 | 652 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.28 1996-07-19 18:55:38 cg Exp $' |
121 | 653 |
! ! |