author | Claus Gittinger <cg@exept.de> |
Fri, 27 Feb 1998 15:15:15 +0100 | |
changeset 1460 | b9929a029249 |
parent 1376 | 26f519265846 |
child 1492 | 348f9d99ff8a |
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 |
|
1063 | 14 |
instanceVariableNames:'menu menuAction values useIndex listMsg defaultLabel listHolder' |
327
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 |
||
998 | 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 |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
44 |
If no model is set, the list is assumed to be a static list, which |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
45 |
is defined via #list:, and the popUpList evaluates the action block, |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
46 |
as defined via #action:. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
47 |
|
1065 | 48 |
If a model is provided, it should return the current selected items index via the |
49 |
aspectMessage (default is #selection or: #selectionIndex, depending on the setting |
|
50 |
of useIndex) and the list via the listMessage (default is #list). |
|
51 |
If the listMessage was set to nil, the list is not aquired from the model |
|
52 |
and can be set explicitely via #list:. |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
53 |
|
1065 | 54 |
The defaults are set to allow a PopUpList to be used with a SelectionInList |
1063 | 55 |
as model without further setup. |
1077 | 56 |
A simple valueHolder may also be used without further setup. |
121 | 57 |
(if used with some other model, either use an adaptor, or set the |
1063 | 58 |
change/aspect and/or listMessage to something else ..) |
125 | 59 |
|
1065 | 60 |
If a listHolder is set, this one is always asked for the list instead of the |
61 |
model, via the #value message. |
|
62 |
This allows the popUpListView to aquire the list and value from different places. |
|
63 |
||
64 |
||
1070 | 65 |
Notice: PopUpList and ComboListView provide a similar protocol and functionality. |
66 |
||
1065 | 67 |
|
585 | 68 |
[Instance variables:] |
125 | 69 |
|
1063 | 70 |
menu helpers for the popup menu |
71 |
menuAction |
|
72 |
values |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
73 |
|
1063 | 74 |
useIndex <Boolean> if true, the index of the selected entry |
75 |
is passed to the action block and the |
|
76 |
model in a change-message. |
|
77 |
If false (the default), the value is passed. |
|
78 |
Notice that the default changeMessage is |
|
79 |
#selection:, which is not ok to be used |
|
80 |
with useIndex:true and a selectionInList model. |
|
81 |
(set the changeMessage to #selectionIndex: then) |
|
125 | 82 |
|
1063 | 83 |
listMsg <Symbol> message to aquire a new list from the |
84 |
model. Default is #list. |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
85 |
|
125 | 86 |
|
1063 | 87 |
listHolder <Object> if non-nil, this object is assumed to return the |
88 |
list via the listMsg (instead of the model). |
|
89 |
Default is nil. |
|
585 | 90 |
|
91 |
[see also:] |
|
1070 | 92 |
SelectionInList ValueHolder |
1063 | 93 |
SelectionInListView |
1070 | 94 |
ComboListView |
585 | 95 |
|
96 |
[author:] |
|
1063 | 97 |
Claus Gittinger |
63 | 98 |
" |
99 |
! |
|
38 | 100 |
|
63 | 101 |
examples |
102 |
" |
|
1063 | 103 |
non-MVC use: |
104 |
[exBegin] |
|
38 | 105 |
|p| |
106 |
p := PopUpList label:'healthy fruit'. |
|
119 | 107 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
38 | 108 |
p open |
1063 | 109 |
[exEnd] |
38 | 110 |
|
111 |
||
112 |
with an initial selection: |
|
1063 | 113 |
[exBegin] |
38 | 114 |
|p| |
115 |
p := PopUpList label:'dummy'. |
|
119 | 116 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
38 | 117 |
p selection:'apples'. |
118 |
p open |
|
1063 | 119 |
[exEnd] |
38 | 120 |
|
121 |
||
122 |
with separating lines: |
|
1063 | 123 |
[exBegin] |
38 | 124 |
|p| |
119 | 125 |
p := PopUpList label:'fruit'. |
126 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
|
38 | 127 |
p selection:'apples'. |
128 |
p open |
|
1063 | 129 |
[exEnd] |
77 | 130 |
|
131 |
||
132 |
with an action: |
|
1063 | 133 |
[exBegin] |
77 | 134 |
|p| |
135 |
p := PopUpList label:'dummy'. |
|
119 | 136 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
77 | 137 |
p selection:'apples'. |
655 | 138 |
p action:[:what | Transcript showCR:'you selected: ' , what]. |
77 | 139 |
p open |
1063 | 140 |
[exEnd] |
77 | 141 |
|
142 |
||
119 | 143 |
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
|
144 |
(notice, that the separating line counts, so you have to take care ...) |
1063 | 145 |
[exBegin] |
119 | 146 |
|p| |
147 |
p := PopUpList label:'dummy'. |
|
148 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
|
149 |
p selection:'apples'. |
|
655 | 150 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
119 | 151 |
p useIndex:true. |
152 |
p open |
|
1063 | 153 |
[exEnd] |
119 | 154 |
|
155 |
||
156 |
since the list is actually a popupMenu, you can add double-separators: |
|
1071 | 157 |
also, here values are different from the labels |
1063 | 158 |
[exBegin] |
119 | 159 |
|p| |
160 |
p := PopUpList label:'dummy'. |
|
161 |
p list:#('apples' 'bananas' 'grape' 'lemon' |
|
1063 | 162 |
'=' |
163 |
'margaritas' 'pina colada' |
|
164 |
'=' |
|
165 |
'smalltalk' 'c++' 'eiffel' 'java'). |
|
119 | 166 |
p values:#(apples bananas grape lemon |
1063 | 167 |
nil |
168 |
'mhmh - so good' 'makes headache' |
|
169 |
nil |
|
170 |
'great' 'another headache' 'not bad' 'neat'). |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
171 |
p selection:'apples'. |
655 | 172 |
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
|
173 |
p open |
1063 | 174 |
[exEnd] |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
175 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
176 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
177 |
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
|
178 |
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
|
179 |
things different from strings, arbitrary lists can be constructed: |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
180 |
(see ListEntry, LabelAndIcon and Text classes) |
1063 | 181 |
[exBegin] |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
182 |
|p l| |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
183 |
p := PopUpList label:'dummy'. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
184 |
l := OrderedCollection new. |
1065 | 185 |
l add:(Text string:'apples' color:Color red). |
186 |
l add:(Text string:'bananas' color:Color red). |
|
187 |
l add:(Text string:'grape' color:Color red). |
|
188 |
l add:(Text string:'lemon' color:Color red). |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
189 |
l add:'='. |
1065 | 190 |
l add:(Text string:'margaritas' color:Color green darkened darkened). |
191 |
l add:(Text string:'pina colada' color:Color green darkened darkened). |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
192 |
l add:'='. |
1065 | 193 |
l add:(Text string:'smalltalk' color:Color blue). |
194 |
l add:(Text string:'c++' color:Color blue). |
|
195 |
l add:(Text string:'eiffel' color:Color blue). |
|
196 |
l add:(Text string:'java' color:Color blue). |
|
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
197 |
p list:l. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
198 |
p values:#(apples bananas grape lemon |
1063 | 199 |
nil |
200 |
'mhmh - so good' 'makes headache' |
|
201 |
nil |
|
202 |
'great' 'another headache' 'not bad' 'neat'). |
|
119 | 203 |
p selection:'apples'. |
655 | 204 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
119 | 205 |
p open |
1063 | 206 |
[exEnd] |
119 | 207 |
|
208 |
||
77 | 209 |
with values different from the label strings: |
1063 | 210 |
[exBegin] |
77 | 211 |
|p| |
212 |
p := PopUpList label:'dummy'. |
|
119 | 213 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
77 | 214 |
p selection:'apples'. |
215 |
p values:#(10 20 30 40 nil 50). |
|
655 | 216 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
77 | 217 |
p open |
1063 | 218 |
[exEnd] |
119 | 219 |
|
121 | 220 |
|
1069 | 221 |
with values different from the label strings: |
222 |
[exBegin] |
|
223 |
|p| |
|
224 |
||
225 |
p := PopUpList label:'language selection'. |
|
226 |
p list:( #( |
|
227 |
'usa' |
|
228 |
'uk' |
|
229 |
'france' |
|
230 |
'germany' |
|
231 |
'italy' |
|
232 |
) collect:[:country | |
|
233 |
LabelAndIcon |
|
234 |
icon:(Image fromFile:'bitmaps/xpmBitmaps/countries/' , country , '.xpm') |
|
235 |
string:country |
|
236 |
] |
|
237 |
). |
|
238 |
p values:#(us england france germany italy). |
|
239 |
||
240 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
|
241 |
p open |
|
242 |
[exEnd] |
|
243 |
||
244 |
||
1064 | 245 |
with a model (see in the inspector, how the index-holders value changes) |
1063 | 246 |
the defaults are setup to allow a SelectionInList directly as model: |
247 |
[exBegin] |
|
119 | 248 |
|p model| |
249 |
||
250 |
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
251 |
||
252 |
p := PopUpList label:'healthy fruit'. |
|
253 |
p model:model. |
|
254 |
p open. |
|
1063 | 255 |
model inspect |
256 |
[exEnd] |
|
121 | 257 |
|
20 | 258 |
|
1071 | 259 |
model provides selection; list is explicit: |
260 |
must change the aspect, since the default setup is for a SelectionInList |
|
261 |
[exBegin] |
|
262 |
|model top b| |
|
263 |
||
264 |
model := 'foo' asValue. |
|
265 |
||
266 |
top := StandardSystemView new. |
|
267 |
top extent:(300 @ 200). |
|
268 |
||
269 |
b := PopUpList in:top. |
|
270 |
b origin:(0.0 @ 0.0) corner:(1.0 @ 0.0). |
|
271 |
b bottomInset:(b preferredExtent y negated). |
|
272 |
||
273 |
b list:#('hello' 'world' 'this' 'is' 'st/x'). |
|
274 |
b model:model; aspect:#value; change:#value:. |
|
275 |
||
276 |
top openModal. |
|
277 |
Transcript showCR:('comboBox''s value: ' , model value). |
|
278 |
[exEnd] |
|
279 |
||
280 |
||
125 | 281 |
a popupList and a SelectionInListView on the same model: |
1063 | 282 |
[exBegin] |
125 | 283 |
|p slv model| |
284 |
||
285 |
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
286 |
model selection:'apples'. |
|
287 |
||
288 |
p := PopUpList on:model. |
|
1064 | 289 |
p open. |
290 |
||
291 |
slv := SelectionInListView on:model. |
|
292 |
slv open. |
|
293 |
[exEnd] |
|
294 |
||
295 |
||
296 |
dynamically changing the list (click button(s) to change): |
|
297 |
[exBegin] |
|
298 |
|p slv model b| |
|
299 |
||
300 |
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
301 |
model selection:'apples'. |
|
302 |
||
303 |
p := PopUpList on:model. |
|
125 | 304 |
p open. |
305 |
||
306 |
slv := SelectionInListView on:model. |
|
307 |
slv open. |
|
308 |
||
1064 | 309 |
b := Button label:'long list' action:[model list:#('1' '2' '3' '4' '5' '6')]. |
310 |
b open. |
|
311 |
b := Button label:'short list' action:[model list:#('1' '2' '3')]. |
|
312 |
b open. |
|
313 |
||
1063 | 314 |
[exEnd] |
315 |
||
316 |
||
125 | 317 |
|
127 | 318 |
two PopUpLists on the same model, different aspects: |
1063 | 319 |
[exBegin] |
121 | 320 |
|top panel p model| |
20 | 321 |
|
121 | 322 |
model := Plug new. |
655 | 323 |
model respondTo:#eat: with:[:val | Transcript showCR:'eat: ' , val]. |
324 |
model respondTo:#drink: with:[:val | Transcript showCR:'drink: ' , val]. |
|
121 | 325 |
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
|
326 |
model respondTo:#drinks with:[#(margarita water corona)]. |
20 | 327 |
|
121 | 328 |
top := StandardSystemView new. |
329 |
top extent:(100@100). |
|
330 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
331 |
panel horizontalLayout:#fitSpace. |
|
77 | 332 |
|
121 | 333 |
p := PopUpList label:'meals'. |
126 | 334 |
p model:model; listMessage:#meals; aspect:nil; change:#eat:. |
121 | 335 |
panel add:p. |
119 | 336 |
|
121 | 337 |
p := PopUpList label:'drinks'. |
126 | 338 |
p model:model; listMessage:#drinks; aspect:nil; change:#drink:. |
121 | 339 |
panel add:p. |
77 | 340 |
|
121 | 341 |
top open |
1063 | 342 |
[exEnd] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
343 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
344 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
345 |
with separate list- and indexHolders: |
1063 | 346 |
[exBegin] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
347 |
|p selectionHolder listHolder| |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
348 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
349 |
listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
350 |
selectionHolder := 'apples' asValue. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
351 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
352 |
p := PopUpList label:'healthy fruit'. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
353 |
p listHolder:listHolder. |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
354 |
p model:selectionHolder; aspect:#value; change:#value:. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
355 |
p open. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
356 |
selectionHolder inspect |
1063 | 357 |
[exEnd] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
358 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
359 |
same, using index: |
1063 | 360 |
[exBegin] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
361 |
|p selectionIndexHolder listHolder| |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
362 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
363 |
listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
364 |
selectionIndexHolder := 3 asValue. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
365 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
366 |
p := PopUpList new. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
367 |
p listHolder:listHolder. |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
368 |
p model:selectionIndexHolder; aspect:#value; change:#value:. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
369 |
p useIndex:true. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
370 |
p open. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
371 |
selectionIndexHolder inspect |
1063 | 372 |
[exEnd] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
373 |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
374 |
using different values: |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
375 |
[exBegin] |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
376 |
|p selectionHolder listHolder values| |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
377 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
378 |
listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
379 |
values := #(apples bananas grape lemon alcohol). |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
380 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
381 |
selectionHolder := #alcohol asValue. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
382 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
383 |
p := PopUpList label:'healthy fruit'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
384 |
p listHolder:listHolder. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
385 |
p model:selectionHolder; aspect:#value; change:#value:. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
386 |
p values:values. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
387 |
p open. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
388 |
selectionHolder inspect |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
389 |
[exEnd] |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
390 |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
391 |
|
121 | 392 |
" |
20 | 393 |
! ! |
394 |
||
998 | 395 |
!PopUpList class methodsFor:'defaults'! |
125 | 396 |
|
397 |
defaultAspectMessage |
|
398 |
^ #selection |
|
399 |
! |
|
400 |
||
401 |
defaultChangeMessage |
|
402 |
^ #selection: |
|
205 | 403 |
! |
404 |
||
405 |
defaultListMessage |
|
406 |
^ #list |
|
407 |
! ! |
|
408 |
||
409 |
!PopUpList methodsFor:'accessing'! |
|
410 |
||
411 |
contents |
|
412 |
^ self label |
|
413 |
! |
|
414 |
||
415 |
contents:con |
|
416 |
^ self selection:con |
|
417 |
||
684 | 418 |
"Modified: 25.5.1996 / 14:20:57 / cg" |
205 | 419 |
! |
420 |
||
1035 | 421 |
defaultLabel:aString |
422 |
"set the defaultLabel, to be shown if nothing is selected" |
|
423 |
||
1368 | 424 |
defaultLabel := aString. |
425 |
shown ifFalse:[ |
|
426 |
super label:defaultLabel |
|
427 |
]. |
|
428 |
||
429 |
"Modified: / 29.10.1997 / 15:50:10 / cg" |
|
1035 | 430 |
! |
431 |
||
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
432 |
label:aString |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
433 |
self defaultLabel:aString. |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
434 |
model isNil ifTrue:[ |
1368 | 435 |
super label:aString suppressResize:(self shown) |
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
436 |
]. |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
437 |
|
1368 | 438 |
"Created: / 1.3.1997 / 02:09:02 / cg" |
439 |
"Modified: / 29.10.1997 / 15:49:50 / cg" |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
440 |
! |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
441 |
|
205 | 442 |
list |
443 |
"return the list - i.e. the values shown in the pop-up list" |
|
444 |
||
445 |
^ menu labels |
|
446 |
! |
|
447 |
||
448 |
list:aList |
|
449 |
"set the list - i.e. the values shown in the pop-up list" |
|
450 |
||
451 |
self createMenuFor:aList. |
|
452 |
realized ifTrue:[ |
|
453 |
self computeLabelSize |
|
454 |
] |
|
455 |
||
456 |
" |
|
457 |
|p| |
|
458 |
p := PopUpList label:'fruit ?'. |
|
459 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 460 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 461 |
p open |
462 |
" |
|
463 |
! |
|
464 |
||
465 |
selection:indexOrString |
|
466 |
"set (force) a selection - usually done to set |
|
467 |
an initial selection without updating others" |
|
468 |
||
1368 | 469 |
|index menuLabels| |
205 | 470 |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
471 |
menu isNil ifTrue:[ |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
472 |
self getListFromModel. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
473 |
]. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
474 |
menu isNil ifTrue:[^ self]. |
1368 | 475 |
menuLabels := menu labels. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
476 |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
477 |
(useIndex not and:[values notNil]) ifTrue:[ |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
478 |
index := values indexOf:indexOrString |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
479 |
] ifFalse:[ |
1237 | 480 |
indexOrString isNumber ifTrue:[ |
481 |
index := indexOrString |
|
482 |
] ifFalse:[ |
|
1368 | 483 |
index := menuLabels indexOf:indexOrString. |
1237 | 484 |
]. |
1079 | 485 |
"/ fails if list consists of symbols ... |
486 |
"/ index := menu indexOf:indexOrString. |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
487 |
]. |
1368 | 488 |
index > menuLabels size ifTrue:[ |
489 |
index := 0 |
|
490 |
]. |
|
491 |
||
1035 | 492 |
index == 0 ifTrue:[ |
1368 | 493 |
self label:defaultLabel suppressResize:true. |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
494 |
^ self |
1035 | 495 |
]. |
205 | 496 |
|
497 |
"kludge: dont want label to resize ..." |
|
1368 | 498 |
self label:(menuLabels at:index) printString suppressResize:true. |
205 | 499 |
|
500 |
" |
|
501 |
|p| |
|
502 |
p := PopUpList label:'what fruit ?'. |
|
503 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
504 |
p selection:'grape'. |
|
505 |
p open |
|
506 |
||
507 |
|p| |
|
508 |
p := PopUpList label:'what fruit ?'. |
|
509 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
510 |
p selection:'blabla'. |
|
511 |
p open |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
512 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
513 |
|p| |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
514 |
p := PopUpList label:'what fruit ?'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
515 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
516 |
p defaultLabel:'nothing selected'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
517 |
p selection:'blabla'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
518 |
p open |
205 | 519 |
" |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
520 |
|
1368 | 521 |
"Modified: / 29.10.1997 / 15:50:12 / cg" |
205 | 522 |
! |
523 |
||
593 | 524 |
values:aList |
525 |
"set a value list - these are reported via the action or changeSymbol instead of |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
526 |
the label strings." |
593 | 527 |
|
528 |
values := aList. |
|
529 |
||
530 |
" |
|
531 |
|p| |
|
532 |
p := PopUpList label:'fruit ?'. |
|
533 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
534 |
p values:#(1 2 3 4 'mhmh - good'). |
|
655 | 535 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
593 | 536 |
p open. |
537 |
" |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
538 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
539 |
"Modified: 27.2.1997 / 10:24:12 / cg" |
593 | 540 |
! ! |
541 |
||
542 |
!PopUpList methodsFor:'accessing-behavior'! |
|
543 |
||
544 |
action:aOneArgBlock |
|
545 |
"set the action to be performed on selection changes; |
|
546 |
the argument, aOneArgBlock will be evaluated with the |
|
547 |
selection-value as argument" |
|
548 |
||
549 |
menuAction := aOneArgBlock |
|
550 |
! |
|
551 |
||
1098 | 552 |
menu:aMenu default:label |
553 |
menu := aMenu. |
|
554 |
defaultLabel := label |
|
555 |
! |
|
556 |
||
1311 | 557 |
useIndex |
558 |
"tell the popuplist to pass the index (instead of the value) |
|
559 |
to both the actionBlock and model. Notice, that if you use a model, |
|
560 |
the default changeSelector is not ok for using index and a SelectionInList" |
|
561 |
||
562 |
^ useIndex |
|
563 |
! |
|
564 |
||
205 | 565 |
useIndex:aBoolean |
566 |
"tell the popuplist to pass the index (instead of the value) |
|
567 |
to both the actionBlock and model. Notice, that if you use a model, |
|
568 |
the default changeSelector is not ok for using index and a SelectionInList" |
|
569 |
||
570 |
useIndex := aBoolean |
|
571 |
||
572 |
" |
|
573 |
|p| |
|
574 |
p := PopUpList label:'fruit ?'. |
|
575 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 576 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 577 |
p open. |
578 |
" |
|
579 |
" |
|
580 |
|p| |
|
581 |
p := PopUpList label:'fruit ?'. |
|
582 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 583 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 584 |
p useIndex:true. |
585 |
p open. |
|
586 |
" |
|
125 | 587 |
! ! |
588 |
||
205 | 589 |
!PopUpList methodsFor:'accessing-mvc'! |
590 |
||
591 |
addModelInterfaceTo:aDictionary |
|
592 |
"see comment in View>>modelInterface" |
|
593 |
||
594 |
super addModelInterfaceTo:aDictionary. |
|
595 |
aDictionary at:#listMessage put:listMsg |
|
1063 | 596 |
|
597 |
"Modified: 26.2.1997 / 19:08:04 / cg" |
|
205 | 598 |
! |
599 |
||
1063 | 600 |
listHolder |
601 |
"return the listHolder if any" |
|
602 |
||
603 |
^ listHolder |
|
604 |
! |
|
605 |
||
606 |
listHolder:aValueHolder |
|
607 |
"set the listHolder - if non nil, that one is assumed to provide the |
|
608 |
list via #value. |
|
609 |
If a listHolder was defined, the model is never asked for the list." |
|
610 |
||
611 |
listHolder notNil ifTrue:[ |
|
612 |
listHolder removeDependent:self. |
|
613 |
]. |
|
614 |
listHolder := aValueHolder. |
|
615 |
listHolder notNil ifTrue:[ |
|
616 |
listHolder addDependent:self. |
|
617 |
]. |
|
618 |
shown ifTrue:[ |
|
619 |
self getListFromModel |
|
620 |
] |
|
621 |
||
622 |
"Modified: 26.2.1997 / 19:06:01 / cg" |
|
205 | 623 |
! |
624 |
||
625 |
listMessage |
|
1063 | 626 |
"return the selector by which we ask the model or listHolder for the list. |
627 |
The default is #list. |
|
628 |
If a listHolder was defined, the model is never asked for the list." |
|
205 | 629 |
|
630 |
^ listMsg |
|
1063 | 631 |
|
632 |
"Modified: 26.2.1997 / 19:05:27 / cg" |
|
205 | 633 |
! |
634 |
||
635 |
listMessage:aSelector |
|
636 |
"set the selector by which we ask the model for the list. |
|
1063 | 637 |
The default is #list. |
638 |
If a listHolder was defined, the model is never asked for the list." |
|
205 | 639 |
|
640 |
listMsg := aSelector |
|
1063 | 641 |
|
642 |
"Modified: 26.2.1997 / 19:05:18 / cg" |
|
1083
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
643 |
! |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
644 |
|
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
645 |
model:aModel |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
646 |
super model:aModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
647 |
self getListFromModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
648 |
self getSelectionFromModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
649 |
|
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
650 |
"Created: 28.2.1997 / 19:12:08 / cg" |
205 | 651 |
! ! |
652 |
||
653 |
!PopUpList methodsFor:'change & update'! |
|
654 |
||
655 |
update:something with:aParameter from:changedObject |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
656 |
changedObject == listHolder ifTrue:[ |
1063 | 657 |
self getListFromModel. |
658 |
^ self |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
659 |
]. |
205 | 660 |
changedObject == model ifTrue:[ |
1078 | 661 |
aspectMsg notNil ifTrue:[ |
1063 | 662 |
self getSelectionFromModel. |
663 |
]. |
|
1078 | 664 |
listMsg notNil ifTrue:[ |
1063 | 665 |
self getListFromModel. |
666 |
]. |
|
667 |
^ self |
|
205 | 668 |
]. |
669 |
super update:something with:aParameter from:changedObject |
|
1063 | 670 |
|
1078 | 671 |
"Modified: 28.2.1997 / 15:18:58 / cg" |
205 | 672 |
! ! |
673 |
||
674 |
!PopUpList methodsFor:'drawing'! |
|
675 |
||
676 |
drawWith:fgColor and:bgColor |
|
677 |
|mmH mmV mW mH| |
|
136 | 678 |
|
205 | 679 |
controller pressed ifTrue:[ |
680 |
super drawWith:enteredFgColor and:enteredBgColor |
|
681 |
] ifFalse:[ |
|
682 |
super drawWith:fgColor and:bgColor. |
|
683 |
]. |
|
684 |
mmH := device horizontalPixelPerMillimeter rounded. |
|
685 |
mmV := device verticalPixelPerMillimeter rounded. |
|
686 |
mW := (device horizontalPixelPerMillimeter * 2.5) rounded. |
|
687 |
mH := (device verticalPixelPerMillimeter * 1.5) rounded. |
|
688 |
||
689 |
self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2) |
|
690 |
width:mW height:mH level:2 |
|
691 |
! |
|
692 |
||
693 |
showActive |
|
694 |
"no need to redraw - will pop menu ontop of me anyway ..." |
|
695 |
||
696 |
^ self |
|
697 |
! |
|
698 |
||
699 |
showPassive |
|
700 |
"no need to redraw - will redraw from unpopped menu anyway ..." |
|
701 |
||
702 |
^ self |
|
703 |
! ! |
|
704 |
||
705 |
!PopUpList methodsFor:'event handling'! |
|
706 |
||
707 |
popMenu |
|
1098 | 708 |
|org mv w theMenu| |
205 | 709 |
|
710 |
menu notNil ifTrue:[ |
|
1098 | 711 |
theMenu := menu value |
712 |
]. |
|
713 |
||
714 |
theMenu notNil ifTrue:[ |
|
715 |
self turnOffWithoutRedraw. |
|
1035 | 716 |
|
1098 | 717 |
theMenu value labels size == 0 ifTrue:[ |
718 |
^ self |
|
719 |
]. |
|
1035 | 720 |
|
1098 | 721 |
theMenu isView ifTrue:[ |
722 |
"/ oldStyle - theMenu is a PopUpMenu |
|
723 |
theMenu font:font. |
|
136 | 724 |
|
1098 | 725 |
" |
726 |
adjust the menus width to my current width |
|
727 |
" |
|
728 |
mv := theMenu menuView. |
|
729 |
mv create. "/ stupid: it resizes itself upon first create |
|
730 |
w := mv width. "/ to its preferred size. |
|
731 |
w := w max:(self width - (2 * theMenu margin) - (theMenu borderWidth*2)). |
|
732 |
mv width:w. |
|
733 |
mv level:0; borderWidth:0. |
|
205 | 734 |
|
1098 | 735 |
" |
736 |
the popupMenu wants Display coordinates in its showAt: method |
|
737 |
" |
|
738 |
org := device translatePoint:0@0 |
|
739 |
from:(self id) |
|
740 |
to:(device rootView id). |
|
205 | 741 |
|
1098 | 742 |
theMenu showAt:org "resizing:false" |
743 |
] ifFalse:[ |
|
744 |
"/ newStyle - theMenu is a Menu |
|
745 |
theMenu startUp |
|
746 |
] |
|
205 | 747 |
]. |
748 |
! ! |
|
749 |
||
750 |
!PopUpList methodsFor:'initialization'! |
|
751 |
||
752 |
defaultControllerClass |
|
753 |
^ PopUpListController |
|
754 |
! |
|
755 |
||
756 |
initialize |
|
757 |
super initialize. |
|
758 |
||
759 |
controller beTriggerOnDown. |
|
760 |
controller action:[self popMenu]. |
|
761 |
self adjust:#left. |
|
762 |
useIndex := false. |
|
1035 | 763 |
defaultLabel := 'popup'. |
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
764 |
super label:defaultLabel. |
1063 | 765 |
|
205 | 766 |
listMsg := self class defaultListMessage. |
767 |
||
768 |
onLevel := offLevel. |
|
1063 | 769 |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
770 |
"Modified: 1.3.1997 / 02:12:55 / cg" |
136 | 771 |
! ! |
772 |
||
20 | 773 |
!PopUpList methodsFor:'private'! |
774 |
||
775 |
computeLabelSize |
|
776 |
"compute the extent needed to hold the label plus the mark" |
|
777 |
||
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
778 |
|mmH mmV savedLogo longest longestWidth labels| |
20 | 779 |
|
780 |
menu isNil ifTrue:[ |
|
1098 | 781 |
super computeLabelSize |
20 | 782 |
] ifFalse:[ |
1098 | 783 |
"hack: simulate logo change to longest menu entry" |
20 | 784 |
|
1098 | 785 |
font := font on:device. |
786 |
longest := logo. |
|
787 |
logo isNil ifTrue:[ |
|
788 |
longestWidth := 0 |
|
789 |
] ifFalse:[ |
|
790 |
longestWidth := font widthOf:logo. |
|
791 |
]. |
|
792 |
labels := menu value labels. |
|
793 |
labels notNil ifTrue:[ |
|
794 |
labels do:[:entry | |
|
795 |
|this| |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
796 |
|
1098 | 797 |
this := font widthOf:entry printString. |
798 |
this > longestWidth ifTrue:[ |
|
799 |
longest := entry. |
|
800 |
longestWidth := this |
|
801 |
]. |
|
802 |
]. |
|
803 |
]. |
|
804 |
savedLogo := logo. |
|
805 |
logo := longest printString. |
|
806 |
super computeLabelSize. |
|
807 |
logo := savedLogo. |
|
20 | 808 |
]. |
809 |
mmH := device horizontalPixelPerMillimeter. |
|
810 |
mmV := device verticalPixelPerMillimeter. |
|
811 |
labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace. |
|
812 |
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
|
813 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
814 |
"Modified: 8.2.1996 / 13:00:33 / cg" |
121 | 815 |
! |
816 |
||
817 |
createMenuFor:aList |
|
818 |
menu := PopUpMenu |
|
819 |
labels:aList |
|
820 |
selectors:#select: |
|
821 |
args:(1 to:aList size) |
|
822 |
receiver:self |
|
823 |
for:self. |
|
128 | 824 |
! |
825 |
||
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
826 |
getListFromModel |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
827 |
"if I have a listHolder, ask it for the list; |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
828 |
otherwise, if I have a model and a listMsg, get my list from there" |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
829 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
830 |
listHolder notNil ifTrue:[ |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
831 |
self list:listHolder value |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
832 |
] ifFalse:[ |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
833 |
(listMsg notNil and:[model notNil]) ifTrue:[ |
1067 | 834 |
(model respondsTo:listMsg) ifTrue:[ |
835 |
self list:(model perform:listMsg). |
|
836 |
] |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
837 |
]. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
838 |
] |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
839 |
|
1067 | 840 |
"Modified: 27.2.1997 / 14:05:52 / cg" |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
841 |
! |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
842 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
843 |
getSelectionFromModel |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
844 |
"if I have a model and an aspectMsg, get my current value from it" |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
845 |
|
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
846 |
|aspect| |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
847 |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
848 |
(model notNil and:[aspectMsg notNil]) ifTrue:[ |
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
849 |
"/ kludge - try #value if aspect is the default and |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
850 |
"/ not understood by the model |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
851 |
"/ this allows a valueHolder to be used, even |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
852 |
"/ if the aspectMessage was not setup correctly. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
853 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
854 |
aspect := aspectMsg. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
855 |
aspect == self class defaultAspectMessage ifTrue:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
856 |
(model respondsTo:aspect) ifFalse:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
857 |
aspect := #value |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
858 |
] |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
859 |
]. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
860 |
self selection:(model perform:aspect) |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
861 |
]. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
862 |
|
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
863 |
"Modified: 28.2.1997 / 13:40:46 / cg" |
121 | 864 |
! ! |
865 |
||
205 | 866 |
!PopUpList methodsFor:'private-controller access'! |
121 | 867 |
|
205 | 868 |
menu |
869 |
"return the menu component" |
|
125 | 870 |
|
205 | 871 |
^ menu |
126 | 872 |
! ! |
873 |
||
136 | 874 |
!PopUpList methodsFor:'queries'! |
875 |
||
876 |
preferredExtent |
|
877 |
"redefined to make certain that the menu is fully defined" |
|
878 |
||
799 | 879 |
"/ If I have an explicit preferredExtent .. |
880 |
||
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
881 |
preferredExtent notNil ifTrue:[ |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
882 |
^ preferredExtent |
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
883 |
]. |
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
884 |
|
136 | 885 |
menu isNil ifTrue:[ |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
886 |
self getListFromModel |
136 | 887 |
]. |
888 |
self computeLabelSize. |
|
889 |
^ super preferredExtent. |
|
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
890 |
|
799 | 891 |
"Modified: 19.7.1996 / 20:45:16 / cg" |
155 | 892 |
! |
893 |
||
894 |
specClass |
|
1376 | 895 |
"XXX no longer needed (inherited default works here)" |
896 |
||
155 | 897 |
self class == PopUpList ifTrue:[^ PopUpListSpec]. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
898 |
^ super specClass |
1376 | 899 |
|
900 |
"Modified: / 31.10.1997 / 19:48:02 / cg" |
|
136 | 901 |
! ! |
902 |
||
20 | 903 |
!PopUpList methodsFor:'user actions'! |
904 |
||
1069 | 905 |
select:anIndex |
119 | 906 |
"this is sent from the popupmenu when an entry was selected" |
907 |
||
1368 | 908 |
|value menuLabels label chg| |
77 | 909 |
|
1368 | 910 |
menuLabels := menu labels. |
1069 | 911 |
values isNil ifTrue:[ |
912 |
value := anIndex. |
|
913 |
useIndex ifFalse:[ |
|
1368 | 914 |
value := menuLabels at:anIndex. |
1069 | 915 |
] |
916 |
] ifFalse:[ |
|
917 |
value := values at:anIndex |
|
918 |
]. |
|
919 |
||
1142
406d3829ddcc
always change my label on select:;
Claus Gittinger <cg@exept.de>
parents:
1098
diff
changeset
|
920 |
"/ model isNil ifTrue:[ |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
921 |
"/ if there is a model, |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
922 |
"/ the update will change my logo ... |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
923 |
|
1368 | 924 |
"/ self sizeFixed:true. |
925 |
label := menuLabels at:anIndex. |
|
926 |
super label:label printString suppressResize:true. |
|
1142
406d3829ddcc
always change my label on select:;
Claus Gittinger <cg@exept.de>
parents:
1098
diff
changeset
|
927 |
"/ ]. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
928 |
|
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
929 |
(model notNil and:[changeMsg notNil]) ifTrue:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
930 |
"/ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
931 |
"/ ST-80 way of doing it |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
932 |
"/ tell my model - if any |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
933 |
"/ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
934 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
935 |
"/ kludge - try #value: if changeMsg is the default and |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
936 |
"/ not understood by the model |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
937 |
"/ this allows a valueHolder to be used, even |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
938 |
"/ if the aspectMessage was not setup correctly. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
939 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
940 |
chg := changeMsg. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
941 |
chg == self class defaultChangeMessage ifTrue:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
942 |
(model respondsTo:chg) ifFalse:[ |
1076 | 943 |
chg := #value: |
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
944 |
] |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
945 |
]. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
946 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
947 |
self sendChangeMessage:chg with:value. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
948 |
]. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
949 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
950 |
"/ |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
951 |
"/ ST/X action blocks |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
952 |
"/ |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
953 |
menuAction notNil ifTrue:[ |
1063 | 954 |
menuAction value:value. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
955 |
]. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
956 |
|
1369 | 957 |
"Modified: / 29.10.1997 / 21:08:50 / cg" |
20 | 958 |
! ! |
121 | 959 |
|
998 | 960 |
!PopUpList class methodsFor:'documentation'! |
121 | 961 |
|
205 | 962 |
version |
1376 | 963 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.54 1997-11-02 17:50:11 cg Exp $' |
121 | 964 |
! ! |