author | ca |
Wed, 05 Mar 1997 17:09:02 +0100 | |
changeset 1098 | e60febc8c26d |
parent 1086 | 76da3ddb3372 |
child 1142 | 406d3829ddcc |
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 |
||
424 |
defaultLabel := aString |
|
425 |
! |
|
426 |
||
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
427 |
label:aString |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
428 |
self defaultLabel:aString. |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
429 |
model isNil ifTrue:[ |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
430 |
super label:aString |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
431 |
]. |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
432 |
|
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
433 |
"Created: 1.3.1997 / 02:09:02 / cg" |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
434 |
"Modified: 1.3.1997 / 02:11:03 / cg" |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
435 |
! |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
436 |
|
205 | 437 |
list |
438 |
"return the list - i.e. the values shown in the pop-up list" |
|
439 |
||
440 |
^ menu labels |
|
441 |
! |
|
442 |
||
443 |
list:aList |
|
444 |
"set the list - i.e. the values shown in the pop-up list" |
|
445 |
||
446 |
self createMenuFor:aList. |
|
447 |
realized ifTrue:[ |
|
448 |
self computeLabelSize |
|
449 |
] |
|
450 |
||
451 |
" |
|
452 |
|p| |
|
453 |
p := PopUpList label:'fruit ?'. |
|
454 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 455 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 456 |
p open |
457 |
" |
|
458 |
! |
|
459 |
||
460 |
selection:indexOrString |
|
461 |
"set (force) a selection - usually done to set |
|
462 |
an initial selection without updating others" |
|
463 |
||
464 |
|index wasFix| |
|
465 |
||
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
466 |
menu isNil ifTrue:[ |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
467 |
self getListFromModel. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
468 |
]. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
469 |
menu isNil ifTrue:[^ self]. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
470 |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
471 |
(useIndex not and:[values notNil]) ifTrue:[ |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
472 |
index := values indexOf:indexOrString |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
473 |
] ifFalse:[ |
1079 | 474 |
index := menu labels indexOf:indexOrString. |
475 |
"/ fails if list consists of symbols ... |
|
476 |
"/ index := menu indexOf:indexOrString. |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
477 |
]. |
1035 | 478 |
index == 0 ifTrue:[ |
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
479 |
super label:defaultLabel. |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
480 |
^ self |
1035 | 481 |
]. |
205 | 482 |
|
483 |
"kludge: dont want label to resize ..." |
|
484 |
wasFix := fixSize. fixSize := true. |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
485 |
super label:(menu labels at:index) printString. |
205 | 486 |
fixSize := wasFix |
487 |
||
488 |
" |
|
489 |
|p| |
|
490 |
p := PopUpList label:'what fruit ?'. |
|
491 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
492 |
p selection:'grape'. |
|
493 |
p open |
|
494 |
||
495 |
|p| |
|
496 |
p := PopUpList label:'what fruit ?'. |
|
497 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
498 |
p selection:'blabla'. |
|
499 |
p open |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
500 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
501 |
|p| |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
502 |
p := PopUpList label:'what fruit ?'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
503 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
504 |
p defaultLabel:'nothing selected'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
505 |
p selection:'blabla'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
506 |
p open |
205 | 507 |
" |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
508 |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
509 |
"Modified: 1.3.1997 / 02:12:24 / cg" |
205 | 510 |
! |
511 |
||
593 | 512 |
values:aList |
513 |
"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
|
514 |
the label strings." |
593 | 515 |
|
516 |
values := aList. |
|
517 |
||
518 |
" |
|
519 |
|p| |
|
520 |
p := PopUpList label:'fruit ?'. |
|
521 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
522 |
p values:#(1 2 3 4 'mhmh - good'). |
|
655 | 523 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
593 | 524 |
p open. |
525 |
" |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
526 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
527 |
"Modified: 27.2.1997 / 10:24:12 / cg" |
593 | 528 |
! ! |
529 |
||
530 |
!PopUpList methodsFor:'accessing-behavior'! |
|
531 |
||
532 |
action:aOneArgBlock |
|
533 |
"set the action to be performed on selection changes; |
|
534 |
the argument, aOneArgBlock will be evaluated with the |
|
535 |
selection-value as argument" |
|
536 |
||
537 |
menuAction := aOneArgBlock |
|
538 |
! |
|
539 |
||
1098 | 540 |
menu:aMenu default:label |
541 |
menu := aMenu. |
|
542 |
defaultLabel := label |
|
543 |
! |
|
544 |
||
205 | 545 |
useIndex:aBoolean |
546 |
"tell the popuplist to pass the index (instead of the value) |
|
547 |
to both the actionBlock and model. Notice, that if you use a model, |
|
548 |
the default changeSelector is not ok for using index and a SelectionInList" |
|
549 |
||
550 |
useIndex := aBoolean |
|
551 |
||
552 |
" |
|
553 |
|p| |
|
554 |
p := PopUpList label:'fruit ?'. |
|
555 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 556 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 557 |
p open. |
558 |
" |
|
559 |
" |
|
560 |
|p| |
|
561 |
p := PopUpList label:'fruit ?'. |
|
562 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 563 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 564 |
p useIndex:true. |
565 |
p open. |
|
566 |
" |
|
125 | 567 |
! ! |
568 |
||
205 | 569 |
!PopUpList methodsFor:'accessing-mvc'! |
570 |
||
571 |
addModelInterfaceTo:aDictionary |
|
572 |
"see comment in View>>modelInterface" |
|
573 |
||
574 |
super addModelInterfaceTo:aDictionary. |
|
575 |
aDictionary at:#listMessage put:listMsg |
|
1063 | 576 |
|
577 |
"Modified: 26.2.1997 / 19:08:04 / cg" |
|
205 | 578 |
! |
579 |
||
1063 | 580 |
listHolder |
581 |
"return the listHolder if any" |
|
582 |
||
583 |
^ listHolder |
|
584 |
! |
|
585 |
||
586 |
listHolder:aValueHolder |
|
587 |
"set the listHolder - if non nil, that one is assumed to provide the |
|
588 |
list via #value. |
|
589 |
If a listHolder was defined, the model is never asked for the list." |
|
590 |
||
591 |
listHolder notNil ifTrue:[ |
|
592 |
listHolder removeDependent:self. |
|
593 |
]. |
|
594 |
listHolder := aValueHolder. |
|
595 |
listHolder notNil ifTrue:[ |
|
596 |
listHolder addDependent:self. |
|
597 |
]. |
|
598 |
shown ifTrue:[ |
|
599 |
self getListFromModel |
|
600 |
] |
|
601 |
||
602 |
"Modified: 26.2.1997 / 19:06:01 / cg" |
|
205 | 603 |
! |
604 |
||
605 |
listMessage |
|
1063 | 606 |
"return the selector by which we ask the model or listHolder for the list. |
607 |
The default is #list. |
|
608 |
If a listHolder was defined, the model is never asked for the list." |
|
205 | 609 |
|
610 |
^ listMsg |
|
1063 | 611 |
|
612 |
"Modified: 26.2.1997 / 19:05:27 / cg" |
|
205 | 613 |
! |
614 |
||
615 |
listMessage:aSelector |
|
616 |
"set the selector by which we ask the model for the list. |
|
1063 | 617 |
The default is #list. |
618 |
If a listHolder was defined, the model is never asked for the list." |
|
205 | 619 |
|
620 |
listMsg := aSelector |
|
1063 | 621 |
|
622 |
"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
|
623 |
! |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
624 |
|
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
625 |
model:aModel |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
626 |
super model:aModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
627 |
self getListFromModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
628 |
self getSelectionFromModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
629 |
|
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
630 |
"Created: 28.2.1997 / 19:12:08 / cg" |
205 | 631 |
! ! |
632 |
||
633 |
!PopUpList methodsFor:'change & update'! |
|
634 |
||
635 |
update:something with:aParameter from:changedObject |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
636 |
changedObject == listHolder ifTrue:[ |
1063 | 637 |
self getListFromModel. |
638 |
^ self |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
639 |
]. |
205 | 640 |
changedObject == model ifTrue:[ |
1078 | 641 |
aspectMsg notNil ifTrue:[ |
1063 | 642 |
self getSelectionFromModel. |
643 |
]. |
|
1078 | 644 |
listMsg notNil ifTrue:[ |
1063 | 645 |
self getListFromModel. |
646 |
]. |
|
647 |
^ self |
|
205 | 648 |
]. |
649 |
super update:something with:aParameter from:changedObject |
|
1063 | 650 |
|
1078 | 651 |
"Modified: 28.2.1997 / 15:18:58 / cg" |
205 | 652 |
! ! |
653 |
||
654 |
!PopUpList methodsFor:'drawing'! |
|
655 |
||
656 |
drawWith:fgColor and:bgColor |
|
657 |
|mmH mmV mW mH| |
|
136 | 658 |
|
205 | 659 |
controller pressed ifTrue:[ |
660 |
super drawWith:enteredFgColor and:enteredBgColor |
|
661 |
] ifFalse:[ |
|
662 |
super drawWith:fgColor and:bgColor. |
|
663 |
]. |
|
664 |
mmH := device horizontalPixelPerMillimeter rounded. |
|
665 |
mmV := device verticalPixelPerMillimeter rounded. |
|
666 |
mW := (device horizontalPixelPerMillimeter * 2.5) rounded. |
|
667 |
mH := (device verticalPixelPerMillimeter * 1.5) rounded. |
|
668 |
||
669 |
self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2) |
|
670 |
width:mW height:mH level:2 |
|
671 |
! |
|
672 |
||
673 |
showActive |
|
674 |
"no need to redraw - will pop menu ontop of me anyway ..." |
|
675 |
||
676 |
^ self |
|
677 |
! |
|
678 |
||
679 |
showPassive |
|
680 |
"no need to redraw - will redraw from unpopped menu anyway ..." |
|
681 |
||
682 |
^ self |
|
683 |
! ! |
|
684 |
||
685 |
!PopUpList methodsFor:'event handling'! |
|
686 |
||
687 |
popMenu |
|
1098 | 688 |
|org mv w theMenu| |
205 | 689 |
|
690 |
menu notNil ifTrue:[ |
|
1098 | 691 |
theMenu := menu value |
692 |
]. |
|
693 |
||
694 |
theMenu notNil ifTrue:[ |
|
695 |
self turnOffWithoutRedraw. |
|
1035 | 696 |
|
1098 | 697 |
theMenu value labels size == 0 ifTrue:[ |
698 |
^ self |
|
699 |
]. |
|
1035 | 700 |
|
1098 | 701 |
theMenu isView ifTrue:[ |
702 |
"/ oldStyle - theMenu is a PopUpMenu |
|
703 |
theMenu font:font. |
|
136 | 704 |
|
1098 | 705 |
" |
706 |
adjust the menus width to my current width |
|
707 |
" |
|
708 |
mv := theMenu menuView. |
|
709 |
mv create. "/ stupid: it resizes itself upon first create |
|
710 |
w := mv width. "/ to its preferred size. |
|
711 |
w := w max:(self width - (2 * theMenu margin) - (theMenu borderWidth*2)). |
|
712 |
mv width:w. |
|
713 |
mv level:0; borderWidth:0. |
|
205 | 714 |
|
1098 | 715 |
" |
716 |
the popupMenu wants Display coordinates in its showAt: method |
|
717 |
" |
|
718 |
org := device translatePoint:0@0 |
|
719 |
from:(self id) |
|
720 |
to:(device rootView id). |
|
205 | 721 |
|
1098 | 722 |
theMenu showAt:org "resizing:false" |
723 |
] ifFalse:[ |
|
724 |
"/ newStyle - theMenu is a Menu |
|
725 |
theMenu startUp |
|
726 |
] |
|
205 | 727 |
]. |
728 |
! ! |
|
729 |
||
730 |
!PopUpList methodsFor:'initialization'! |
|
731 |
||
732 |
defaultControllerClass |
|
733 |
^ PopUpListController |
|
734 |
! |
|
735 |
||
736 |
initialize |
|
737 |
super initialize. |
|
738 |
||
739 |
controller beTriggerOnDown. |
|
740 |
controller action:[self popMenu]. |
|
741 |
self adjust:#left. |
|
742 |
useIndex := false. |
|
1035 | 743 |
defaultLabel := 'popup'. |
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
744 |
super label:defaultLabel. |
1063 | 745 |
|
205 | 746 |
listMsg := self class defaultListMessage. |
747 |
||
748 |
onLevel := offLevel. |
|
1063 | 749 |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
750 |
"Modified: 1.3.1997 / 02:12:55 / cg" |
136 | 751 |
! ! |
752 |
||
20 | 753 |
!PopUpList methodsFor:'private'! |
754 |
||
755 |
computeLabelSize |
|
756 |
"compute the extent needed to hold the label plus the mark" |
|
757 |
||
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
758 |
|mmH mmV savedLogo longest longestWidth labels| |
20 | 759 |
|
760 |
menu isNil ifTrue:[ |
|
1098 | 761 |
super computeLabelSize |
20 | 762 |
] ifFalse:[ |
1098 | 763 |
"hack: simulate logo change to longest menu entry" |
20 | 764 |
|
1098 | 765 |
font := font on:device. |
766 |
longest := logo. |
|
767 |
logo isNil ifTrue:[ |
|
768 |
longestWidth := 0 |
|
769 |
] ifFalse:[ |
|
770 |
longestWidth := font widthOf:logo. |
|
771 |
]. |
|
772 |
labels := menu value labels. |
|
773 |
labels notNil ifTrue:[ |
|
774 |
labels do:[:entry | |
|
775 |
|this| |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
776 |
|
1098 | 777 |
this := font widthOf:entry printString. |
778 |
this > longestWidth ifTrue:[ |
|
779 |
longest := entry. |
|
780 |
longestWidth := this |
|
781 |
]. |
|
782 |
]. |
|
783 |
]. |
|
784 |
savedLogo := logo. |
|
785 |
logo := longest printString. |
|
786 |
super computeLabelSize. |
|
787 |
logo := savedLogo. |
|
20 | 788 |
]. |
789 |
mmH := device horizontalPixelPerMillimeter. |
|
790 |
mmV := device verticalPixelPerMillimeter. |
|
791 |
labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace. |
|
792 |
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
|
793 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
794 |
"Modified: 8.2.1996 / 13:00:33 / cg" |
121 | 795 |
! |
796 |
||
797 |
createMenuFor:aList |
|
798 |
menu := PopUpMenu |
|
799 |
labels:aList |
|
800 |
selectors:#select: |
|
801 |
args:(1 to:aList size) |
|
802 |
receiver:self |
|
803 |
for:self. |
|
128 | 804 |
! |
805 |
||
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
806 |
getListFromModel |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
807 |
"if I have a listHolder, ask it for the list; |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
808 |
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
|
809 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
810 |
listHolder notNil ifTrue:[ |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
811 |
self list:listHolder value |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
812 |
] ifFalse:[ |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
813 |
(listMsg notNil and:[model notNil]) ifTrue:[ |
1067 | 814 |
(model respondsTo:listMsg) ifTrue:[ |
815 |
self list:(model perform:listMsg). |
|
816 |
] |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
817 |
]. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
818 |
] |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
819 |
|
1067 | 820 |
"Modified: 27.2.1997 / 14:05:52 / cg" |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
821 |
! |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
822 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
823 |
getSelectionFromModel |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
824 |
"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
|
825 |
|
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
826 |
|aspect| |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
827 |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
828 |
(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
|
829 |
"/ 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
|
830 |
"/ not understood by the model |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
831 |
"/ 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
|
832 |
"/ 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
|
833 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
834 |
aspect := aspectMsg. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
835 |
aspect == self class defaultAspectMessage ifTrue:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
836 |
(model respondsTo:aspect) ifFalse:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
837 |
aspect := #value |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
838 |
] |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
839 |
]. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
840 |
self selection:(model perform:aspect) |
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 |
|
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
843 |
"Modified: 28.2.1997 / 13:40:46 / cg" |
121 | 844 |
! ! |
845 |
||
205 | 846 |
!PopUpList methodsFor:'private-controller access'! |
121 | 847 |
|
205 | 848 |
menu |
849 |
"return the menu component" |
|
125 | 850 |
|
205 | 851 |
^ menu |
126 | 852 |
! ! |
853 |
||
136 | 854 |
!PopUpList methodsFor:'queries'! |
855 |
||
856 |
preferredExtent |
|
857 |
"redefined to make certain that the menu is fully defined" |
|
858 |
||
799 | 859 |
"/ If I have an explicit preferredExtent .. |
860 |
||
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
861 |
preferredExtent notNil ifTrue:[ |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
862 |
^ preferredExtent |
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
863 |
]. |
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
864 |
|
136 | 865 |
menu isNil ifTrue:[ |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
866 |
self getListFromModel |
136 | 867 |
]. |
868 |
self computeLabelSize. |
|
869 |
^ super preferredExtent. |
|
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
870 |
|
799 | 871 |
"Modified: 19.7.1996 / 20:45:16 / cg" |
155 | 872 |
! |
873 |
||
874 |
specClass |
|
875 |
self class == PopUpList ifTrue:[^ PopUpListSpec]. |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
876 |
^ super specClass |
136 | 877 |
! ! |
878 |
||
20 | 879 |
!PopUpList methodsFor:'user actions'! |
880 |
||
1069 | 881 |
select:anIndex |
119 | 882 |
"this is sent from the popupmenu when an entry was selected" |
883 |
||
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
884 |
|value label chg| |
77 | 885 |
|
1069 | 886 |
values isNil ifTrue:[ |
887 |
value := anIndex. |
|
888 |
useIndex ifFalse:[ |
|
889 |
value := menu labels at:anIndex. |
|
890 |
] |
|
891 |
] ifFalse:[ |
|
892 |
value := values at:anIndex |
|
893 |
]. |
|
894 |
||
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
895 |
model isNil ifTrue:[ |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
896 |
"/ if there is a model, |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
897 |
"/ the update will change my logo ... |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
898 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
899 |
self sizeFixed:true. |
1069 | 900 |
label := menu labels at:anIndex. |
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
901 |
super label:label printString. |
20 | 902 |
]. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
903 |
|
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
904 |
(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
|
905 |
"/ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
906 |
"/ 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
|
907 |
"/ tell my model - if any |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
908 |
"/ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
909 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
910 |
"/ 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
|
911 |
"/ not understood by the model |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
912 |
"/ 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
|
913 |
"/ 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
|
914 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
915 |
chg := changeMsg. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
916 |
chg == self class defaultChangeMessage ifTrue:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
917 |
(model respondsTo:chg) ifFalse:[ |
1076 | 918 |
chg := #value: |
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
919 |
] |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
920 |
]. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
921 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
922 |
self sendChangeMessage:chg with:value. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
923 |
]. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
924 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
925 |
"/ |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
926 |
"/ ST/X action blocks |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
927 |
"/ |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
928 |
menuAction notNil ifTrue:[ |
1063 | 929 |
menuAction value:value. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
930 |
]. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
931 |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
932 |
"Modified: 1.3.1997 / 02:13:07 / cg" |
20 | 933 |
! ! |
121 | 934 |
|
998 | 935 |
!PopUpList class methodsFor:'documentation'! |
121 | 936 |
|
205 | 937 |
version |
1098 | 938 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.48 1997-03-05 16:09:02 ca Exp $' |
121 | 939 |
! ! |