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