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