author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 21 Mar 2019 11:09:23 +0000 | |
branch | jv |
changeset 6607 | 1da320242101 |
parent 6519 | 6777704804e1 |
permissions | -rw-r--r-- |
20 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
6349 | 3 |
COPYRIGHT (c) 2018 Jan Vrany |
59 | 4 |
All Rights Reserved |
20 | 5 |
|
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
2172
411ac4dcf8b4
action invocation for VW compatibility.
Claus Gittinger <cg@exept.de>
parents:
1988
diff
changeset
|
13 |
"{ Package: 'stx:libwidg' }" |
411ac4dcf8b4
action invocation for VW compatibility.
Claus Gittinger <cg@exept.de>
parents:
1988
diff
changeset
|
14 |
|
5415 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
20 | 17 |
Button subclass:#PopUpList |
1758 | 18 |
instanceVariableNames:'menu menuAction values useIndex listMsg defaultLabel listHolder |
2578 | 19 |
showHandle ignoreReselect' |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
20 |
classVariableNames:'' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
21 |
poolDictionaries:'' |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
22 |
category:'Views-Interactors' |
20 | 23 |
! |
24 |
||
998 | 25 |
!PopUpList class methodsFor:'documentation'! |
38 | 26 |
|
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
6349 | 30 |
COPYRIGHT (c) 2018 Jan Vrany |
59 | 31 |
All Rights Reserved |
38 | 32 |
|
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
a PopUpList is basically a button with a popup menu. |
|
45 |
The PopUpLists label is showing the current selection from the |
|
46 |
list. |
|
121 | 47 |
When an entry is selected, an actionBlock (if nonNil) is evaluated |
48 |
and (if nonNil), the model is notified via the changeMessage. |
|
125 | 49 |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
as defined via #action:. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
53 |
|
1065 | 54 |
If a model is provided, it should return the current selected items index via the |
55 |
aspectMessage (default is #selection or: #selectionIndex, depending on the setting |
|
56 |
of useIndex) and the list via the listMessage (default is #list). |
|
5781 | 57 |
If the listMessage was set to nil, the list is not acquired from the model |
1065 | 58 |
and can be set explicitely via #list:. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
59 |
|
1065 | 60 |
The defaults are set to allow a PopUpList to be used with a SelectionInList |
1063 | 61 |
as model without further setup. |
1077 | 62 |
A simple valueHolder may also be used without further setup. |
121 | 63 |
(if used with some other model, either use an adaptor, or set the |
1063 | 64 |
change/aspect and/or listMessage to something else ..) |
125 | 65 |
|
1065 | 66 |
If a listHolder is set, this one is always asked for the list instead of the |
67 |
model, via the #value message. |
|
5781 | 68 |
This allows the popUpListView to acquire the list and value from different places. |
1065 | 69 |
|
70 |
||
1070 | 71 |
Notice: PopUpList and ComboListView provide a similar protocol and functionality. |
72 |
||
1065 | 73 |
|
585 | 74 |
[Instance variables:] |
125 | 75 |
|
1063 | 76 |
menu helpers for the popup menu |
77 |
menuAction |
|
78 |
values |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
79 |
|
1063 | 80 |
useIndex <Boolean> if true, the index of the selected entry |
81 |
is passed to the action block and the |
|
82 |
model in a change-message. |
|
83 |
If false (the default), the value is passed. |
|
84 |
Notice that the default changeMessage is |
|
85 |
#selection:, which is not ok to be used |
|
86 |
with useIndex:true and a selectionInList model. |
|
87 |
(set the changeMessage to #selectionIndex: then) |
|
125 | 88 |
|
5781 | 89 |
listMsg <Symbol> message to acquire a new list from the |
1063 | 90 |
model. Default is #list. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
91 |
|
125 | 92 |
|
1063 | 93 |
listHolder <Object> if non-nil, this object is assumed to return the |
94 |
list via the listMsg (instead of the model). |
|
95 |
Default is nil. |
|
585 | 96 |
|
97 |
[see also:] |
|
1070 | 98 |
SelectionInList ValueHolder |
1063 | 99 |
SelectionInListView |
1070 | 100 |
ComboListView |
585 | 101 |
|
102 |
[author:] |
|
1063 | 103 |
Claus Gittinger |
63 | 104 |
" |
105 |
! |
|
38 | 106 |
|
63 | 107 |
examples |
108 |
" |
|
1063 | 109 |
non-MVC use: |
110 |
[exBegin] |
|
38 | 111 |
|p| |
112 |
p := PopUpList label:'healthy fruit'. |
|
119 | 113 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
38 | 114 |
p open |
1063 | 115 |
[exEnd] |
38 | 116 |
|
117 |
||
118 |
with an initial selection: |
|
1063 | 119 |
[exBegin] |
38 | 120 |
|p| |
121 |
p := PopUpList label:'dummy'. |
|
119 | 122 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
38 | 123 |
p selection:'apples'. |
124 |
p open |
|
1063 | 125 |
[exEnd] |
38 | 126 |
|
127 |
||
128 |
with separating lines: |
|
1063 | 129 |
[exBegin] |
38 | 130 |
|p| |
119 | 131 |
p := PopUpList label:'fruit'. |
132 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
|
38 | 133 |
p selection:'apples'. |
134 |
p open |
|
1063 | 135 |
[exEnd] |
77 | 136 |
|
137 |
||
1772 | 138 |
draw without menu-handle: |
139 |
[exBegin] |
|
140 |
|p| |
|
141 |
p := PopUpList label:'fruit'. |
|
142 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
|
143 |
p showHandle:false. |
|
144 |
p open |
|
145 |
[exEnd] |
|
146 |
||
147 |
||
77 | 148 |
with an action: |
1063 | 149 |
[exBegin] |
77 | 150 |
|p| |
151 |
p := PopUpList label:'dummy'. |
|
119 | 152 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
77 | 153 |
p selection:'apples'. |
655 | 154 |
p action:[:what | Transcript showCR:'you selected: ' , what]. |
77 | 155 |
p open |
1063 | 156 |
[exEnd] |
77 | 157 |
|
158 |
||
119 | 159 |
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
|
160 |
(notice, that the separating line counts, so you have to take care ...) |
1063 | 161 |
[exBegin] |
119 | 162 |
|p| |
163 |
p := PopUpList label:'dummy'. |
|
164 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
|
165 |
p selection:'apples'. |
|
655 | 166 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
119 | 167 |
p useIndex:true. |
168 |
p open |
|
1063 | 169 |
[exEnd] |
119 | 170 |
|
171 |
||
172 |
since the list is actually a popupMenu, you can add double-separators: |
|
1071 | 173 |
also, here values are different from the labels |
1063 | 174 |
[exBegin] |
119 | 175 |
|p| |
176 |
p := PopUpList label:'dummy'. |
|
177 |
p list:#('apples' 'bananas' 'grape' 'lemon' |
|
1063 | 178 |
'=' |
179 |
'margaritas' 'pina colada' |
|
180 |
'=' |
|
181 |
'smalltalk' 'c++' 'eiffel' 'java'). |
|
119 | 182 |
p values:#(apples bananas grape lemon |
1063 | 183 |
nil |
184 |
'mhmh - so good' 'makes headache' |
|
185 |
nil |
|
186 |
'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
|
187 |
p selection:'apples'. |
655 | 188 |
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
|
189 |
p open |
1063 | 190 |
[exEnd] |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
191 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
192 |
|
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
193 |
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
|
194 |
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
|
195 |
things different from strings, arbitrary lists can be constructed: |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
196 |
(see ListEntry, LabelAndIcon and Text classes) |
1063 | 197 |
[exBegin] |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
198 |
|p l| |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
199 |
p := PopUpList label:'dummy'. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
200 |
l := OrderedCollection new. |
1065 | 201 |
l add:(Text string:'apples' color:Color red). |
202 |
l add:(Text string:'bananas' color:Color red). |
|
203 |
l add:(Text string:'grape' color:Color red). |
|
204 |
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
|
205 |
l add:'='. |
1065 | 206 |
l add:(Text string:'margaritas' color:Color green darkened darkened). |
207 |
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
|
208 |
l add:'='. |
1065 | 209 |
l add:(Text string:'smalltalk' color:Color blue). |
210 |
l add:(Text string:'c++' color:Color blue). |
|
211 |
l add:(Text string:'eiffel' color:Color blue). |
|
212 |
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
|
213 |
p list:l. |
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
214 |
p values:#(apples bananas grape lemon |
1063 | 215 |
nil |
216 |
'mhmh - so good' 'makes headache' |
|
217 |
nil |
|
218 |
'great' 'another headache' 'not bad' 'neat'). |
|
119 | 219 |
p selection:'apples'. |
655 | 220 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
119 | 221 |
p open |
1063 | 222 |
[exEnd] |
119 | 223 |
|
224 |
||
77 | 225 |
with values different from the label strings: |
1063 | 226 |
[exBegin] |
77 | 227 |
|p| |
228 |
p := PopUpList label:'dummy'. |
|
119 | 229 |
p list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas'). |
77 | 230 |
p selection:'apples'. |
231 |
p values:#(10 20 30 40 nil 50). |
|
655 | 232 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
77 | 233 |
p open |
1063 | 234 |
[exEnd] |
119 | 235 |
|
121 | 236 |
|
1069 | 237 |
with values different from the label strings: |
238 |
[exBegin] |
|
239 |
|p| |
|
240 |
||
241 |
p := PopUpList label:'language selection'. |
|
242 |
p list:( #( |
|
243 |
'usa' |
|
244 |
'uk' |
|
245 |
'france' |
|
246 |
'germany' |
|
247 |
'italy' |
|
248 |
) collect:[:country | |
|
249 |
LabelAndIcon |
|
250 |
icon:(Image fromFile:'bitmaps/xpmBitmaps/countries/' , country , '.xpm') |
|
251 |
string:country |
|
252 |
] |
|
253 |
). |
|
254 |
p values:#(us england france germany italy). |
|
255 |
||
256 |
p action:[:what | Transcript show:'you selected: '; showCR:what]. |
|
257 |
p open |
|
258 |
[exEnd] |
|
259 |
||
260 |
||
1064 | 261 |
with a model (see in the inspector, how the index-holders value changes) |
1063 | 262 |
the defaults are setup to allow a SelectionInList directly as model: |
263 |
[exBegin] |
|
119 | 264 |
|p model| |
265 |
||
266 |
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
267 |
||
268 |
p := PopUpList label:'healthy fruit'. |
|
269 |
p model:model. |
|
270 |
p open. |
|
1063 | 271 |
model inspect |
272 |
[exEnd] |
|
121 | 273 |
|
20 | 274 |
|
1071 | 275 |
model provides selection; list is explicit: |
276 |
must change the aspect, since the default setup is for a SelectionInList |
|
277 |
[exBegin] |
|
278 |
|model top b| |
|
279 |
||
280 |
model := 'foo' asValue. |
|
281 |
||
282 |
top := StandardSystemView new. |
|
283 |
top extent:(300 @ 200). |
|
284 |
||
285 |
b := PopUpList in:top. |
|
286 |
b origin:(0.0 @ 0.0) corner:(1.0 @ 0.0). |
|
287 |
b bottomInset:(b preferredExtent y negated). |
|
288 |
||
289 |
b list:#('hello' 'world' 'this' 'is' 'st/x'). |
|
290 |
b model:model; aspect:#value; change:#value:. |
|
291 |
||
292 |
top openModal. |
|
293 |
Transcript showCR:('comboBox''s value: ' , model value). |
|
294 |
[exEnd] |
|
295 |
||
296 |
||
125 | 297 |
a popupList and a SelectionInListView on the same model: |
1063 | 298 |
[exBegin] |
125 | 299 |
|p slv model| |
300 |
||
301 |
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
302 |
model selection:'apples'. |
|
303 |
||
304 |
p := PopUpList on:model. |
|
1064 | 305 |
p open. |
306 |
||
307 |
slv := SelectionInListView on:model. |
|
308 |
slv open. |
|
309 |
[exEnd] |
|
310 |
||
311 |
||
312 |
dynamically changing the list (click button(s) to change): |
|
313 |
[exBegin] |
|
314 |
|p slv model b| |
|
315 |
||
316 |
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
317 |
model selection:'apples'. |
|
318 |
||
319 |
p := PopUpList on:model. |
|
125 | 320 |
p open. |
321 |
||
322 |
slv := SelectionInListView on:model. |
|
323 |
slv open. |
|
324 |
||
1064 | 325 |
b := Button label:'long list' action:[model list:#('1' '2' '3' '4' '5' '6')]. |
326 |
b open. |
|
327 |
b := Button label:'short list' action:[model list:#('1' '2' '3')]. |
|
328 |
b open. |
|
329 |
||
1063 | 330 |
[exEnd] |
331 |
||
332 |
||
125 | 333 |
|
127 | 334 |
two PopUpLists on the same model, different aspects: |
1063 | 335 |
[exBegin] |
121 | 336 |
|top panel p model| |
20 | 337 |
|
121 | 338 |
model := Plug new. |
655 | 339 |
model respondTo:#eat: with:[:val | Transcript showCR:'eat: ' , val]. |
340 |
model respondTo:#drink: with:[:val | Transcript showCR:'drink: ' , val]. |
|
121 | 341 |
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
|
342 |
model respondTo:#drinks with:[#(margarita water corona)]. |
20 | 343 |
|
121 | 344 |
top := StandardSystemView new. |
345 |
top extent:(100@100). |
|
346 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
347 |
panel horizontalLayout:#fitSpace. |
|
77 | 348 |
|
121 | 349 |
p := PopUpList label:'meals'. |
126 | 350 |
p model:model; listMessage:#meals; aspect:nil; change:#eat:. |
121 | 351 |
panel add:p. |
119 | 352 |
|
121 | 353 |
p := PopUpList label:'drinks'. |
126 | 354 |
p model:model; listMessage:#drinks; aspect:nil; change:#drink:. |
121 | 355 |
panel add:p. |
77 | 356 |
|
121 | 357 |
top open |
1063 | 358 |
[exEnd] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
359 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
360 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
361 |
with separate list- and indexHolders: |
1063 | 362 |
[exBegin] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
363 |
|p selectionHolder listHolder| |
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 |
listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
366 |
selectionHolder := 'apples' asValue. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
367 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
368 |
p := PopUpList label:'healthy fruit'. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
369 |
p listHolder:listHolder. |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
370 |
p model:selectionHolder; aspect:#value; change:#value:. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
371 |
p open. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
372 |
selectionHolder inspect |
1063 | 373 |
[exEnd] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
374 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
375 |
same, using index: |
1063 | 376 |
[exBegin] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
377 |
|p selectionIndexHolder listHolder| |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
378 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
379 |
listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
380 |
selectionIndexHolder := 3 asValue. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
381 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
382 |
p := PopUpList new. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
383 |
p listHolder:listHolder. |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
384 |
p model:selectionIndexHolder; aspect:#value; change:#value:. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
385 |
p useIndex:true. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
386 |
p open. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
387 |
selectionIndexHolder inspect |
1063 | 388 |
[exEnd] |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
389 |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
390 |
using different values: |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
391 |
[exBegin] |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
392 |
|p selectionHolder listHolder values| |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
393 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
394 |
listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
395 |
values := #(apples bananas grape lemon alcohol). |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
396 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
397 |
selectionHolder := #alcohol asValue. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
398 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
399 |
p := PopUpList label:'healthy fruit'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
400 |
p listHolder:listHolder. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
401 |
p model:selectionHolder; aspect:#value; change:#value:. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
402 |
p values:values. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
403 |
p open. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
404 |
selectionHolder inspect |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
405 |
[exEnd] |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
406 |
|
2262 | 407 |
provide your own menu (spec could come from a specMethod): |
408 |
[exBegin] |
|
409 |
|p myMenu selectionHolder| |
|
410 |
||
411 |
selectionHolder := nil asValue. |
|
412 |
myMenu := |
|
413 |
#(#Menu |
|
414 |
#( |
|
415 |
#(#MenuItem |
|
416 |
#label: 'Oranges' |
|
417 |
#translateLabel: true |
|
418 |
#value: #oranges |
|
419 |
) |
|
420 |
#(#MenuItem |
|
421 |
#label: 'Lemons' |
|
422 |
#translateLabel: true |
|
423 |
#value: #lemons |
|
424 |
) |
|
425 |
#(#MenuItem |
|
426 |
#label: 'grape' |
|
427 |
#translateLabel: true |
|
428 |
#value: #grape |
|
429 |
) |
|
430 |
#(#MenuItem |
|
431 |
#label: '-' |
|
432 |
) |
|
433 |
#(#MenuItem |
|
434 |
#label: 'other' |
|
435 |
#translateLabel: true |
|
436 |
#value: #other |
|
437 |
#submenu: |
|
438 |
#(#Menu |
|
439 |
#( |
|
440 |
#(#MenuItem |
|
441 |
#label: 'margarita' |
|
442 |
#translateLabel: true |
|
443 |
#value: #margarita |
|
444 |
) |
|
445 |
#(#MenuItem |
|
446 |
#label: 'vine' |
|
447 |
#translateLabel: true |
|
448 |
#value: #vine |
|
449 |
) |
|
450 |
) |
|
451 |
) |
|
452 |
) |
|
453 |
) |
|
454 |
) decodeAsLiteralArray. |
|
455 |
p := PopUpList label:'healthy fruit'. |
|
456 |
p menu:myMenu. |
|
457 |
p model:selectionHolder; aspect:#value; change:#value:. |
|
458 |
selectionHolder inspect. |
|
459 |
p open. |
|
460 |
[exEnd] |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
461 |
|
121 | 462 |
" |
20 | 463 |
! ! |
464 |
||
998 | 465 |
!PopUpList class methodsFor:'defaults'! |
125 | 466 |
|
467 |
defaultAspectMessage |
|
468 |
^ #selection |
|
469 |
! |
|
470 |
||
471 |
defaultChangeMessage |
|
472 |
^ #selection: |
|
205 | 473 |
! |
474 |
||
475 |
defaultListMessage |
|
476 |
^ #list |
|
477 |
! ! |
|
478 |
||
479 |
!PopUpList methodsFor:'accessing'! |
|
480 |
||
481 |
contents |
|
2262 | 482 |
"return the current contents" |
483 |
||
205 | 484 |
^ self label |
485 |
! |
|
486 |
||
487 |
contents:con |
|
2262 | 488 |
"change the contents" |
489 |
||
205 | 490 |
^ self selection:con |
491 |
||
684 | 492 |
"Modified: 25.5.1996 / 14:20:57 / cg" |
205 | 493 |
! |
494 |
||
1035 | 495 |
defaultLabel:aString |
496 |
"set the defaultLabel, to be shown if nothing is selected" |
|
497 |
||
1368 | 498 |
defaultLabel := aString. |
499 |
shown ifFalse:[ |
|
500 |
super label:defaultLabel |
|
501 |
]. |
|
502 |
||
503 |
"Modified: / 29.10.1997 / 15:50:10 / cg" |
|
1035 | 504 |
! |
505 |
||
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
506 |
label:aString |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
507 |
self defaultLabel:aString. |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
508 |
model isNil ifTrue:[ |
1368 | 509 |
super label:aString suppressResize:(self shown) |
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
510 |
]. |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
511 |
|
1368 | 512 |
"Created: / 1.3.1997 / 02:09:02 / cg" |
513 |
"Modified: / 29.10.1997 / 15:49:50 / cg" |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
514 |
! |
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
515 |
|
205 | 516 |
list |
517 |
"return the list - i.e. the values shown in the pop-up list" |
|
518 |
||
519 |
^ menu labels |
|
520 |
! |
|
521 |
||
522 |
list:aList |
|
523 |
"set the list - i.e. the values shown in the pop-up list" |
|
524 |
||
525 |
self createMenuFor:aList. |
|
526 |
realized ifTrue:[ |
|
527 |
self computeLabelSize |
|
528 |
] |
|
529 |
||
530 |
" |
|
531 |
|p| |
|
532 |
p := PopUpList label:'fruit ?'. |
|
533 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 534 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 535 |
p open |
536 |
" |
|
537 |
! |
|
538 |
||
539 |
selection:indexOrString |
|
540 |
"set (force) a selection - usually done to set |
|
541 |
an initial selection without updating others" |
|
542 |
||
1839
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
543 |
|index menuLabels newLabel| |
205 | 544 |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
545 |
menu isNil ifTrue:[ |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
546 |
self getListFromModel. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
547 |
]. |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
548 |
menu isNil ifTrue:[^ self]. |
1368 | 549 |
menuLabels := menu labels. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
550 |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
551 |
(useIndex not and:[values notNil]) ifTrue:[ |
2494
6e3fc702b1af
care for nil list, when setting the model
Claus Gittinger <cg@exept.de>
parents:
2464
diff
changeset
|
552 |
values notNil ifTrue:[ |
6e3fc702b1af
care for nil list, when setting the model
Claus Gittinger <cg@exept.de>
parents:
2464
diff
changeset
|
553 |
index := values indexOf:indexOrString |
6e3fc702b1af
care for nil list, when setting the model
Claus Gittinger <cg@exept.de>
parents:
2464
diff
changeset
|
554 |
] |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
555 |
] ifFalse:[ |
1237 | 556 |
indexOrString isNumber ifTrue:[ |
557 |
index := indexOrString |
|
558 |
] ifFalse:[ |
|
2494
6e3fc702b1af
care for nil list, when setting the model
Claus Gittinger <cg@exept.de>
parents:
2464
diff
changeset
|
559 |
menuLabels notNil ifTrue:[ |
6e3fc702b1af
care for nil list, when setting the model
Claus Gittinger <cg@exept.de>
parents:
2464
diff
changeset
|
560 |
index := menuLabels indexOf:indexOrString. |
6e3fc702b1af
care for nil list, when setting the model
Claus Gittinger <cg@exept.de>
parents:
2464
diff
changeset
|
561 |
] |
1237 | 562 |
]. |
1079 | 563 |
"/ fails if list consists of symbols ... |
564 |
"/ index := menu indexOf:indexOrString. |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
565 |
]. |
2494
6e3fc702b1af
care for nil list, when setting the model
Claus Gittinger <cg@exept.de>
parents:
2464
diff
changeset
|
566 |
(index isNil or:[index > menuLabels size]) ifTrue:[ |
1368 | 567 |
index := 0 |
568 |
]. |
|
569 |
||
1035 | 570 |
index == 0 ifTrue:[ |
1839
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
571 |
newLabel := defaultLabel |
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
572 |
] ifFalse:[ |
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
573 |
newLabel := (menuLabels at:index) |
1035 | 574 |
]. |
205 | 575 |
|
5957 | 576 |
"kludge: don't want label to resize ..." |
2266 | 577 |
|
1839
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
578 |
self label:newLabel suppressResize:true. |
205 | 579 |
|
580 |
" |
|
581 |
|p| |
|
582 |
p := PopUpList label:'what fruit ?'. |
|
583 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
584 |
p selection:'grape'. |
|
585 |
p open |
|
586 |
||
587 |
|p| |
|
588 |
p := PopUpList label:'what fruit ?'. |
|
589 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
590 |
p selection:'blabla'. |
|
591 |
p open |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
592 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
593 |
|p| |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
594 |
p := PopUpList label:'what fruit ?'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
595 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
596 |
p defaultLabel:'nothing selected'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
597 |
p selection:'blabla'. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
598 |
p open |
205 | 599 |
" |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
600 |
|
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
601 |
"Modified: / 29-10-1997 / 15:50:12 / cg" |
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
602 |
"Modified: / 26-01-2018 / 10:10:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
205 | 603 |
! |
604 |
||
593 | 605 |
values:aList |
606 |
"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
|
607 |
the label strings." |
593 | 608 |
|
609 |
values := aList. |
|
610 |
||
611 |
" |
|
612 |
|p| |
|
613 |
p := PopUpList label:'fruit ?'. |
|
614 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
615 |
p values:#(1 2 3 4 'mhmh - good'). |
|
655 | 616 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
593 | 617 |
p open. |
618 |
" |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
619 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
620 |
"Modified: 27.2.1997 / 10:24:12 / cg" |
593 | 621 |
! ! |
622 |
||
623 |
!PopUpList methodsFor:'accessing-behavior'! |
|
624 |
||
625 |
action:aOneArgBlock |
|
626 |
"set the action to be performed on selection changes; |
|
627 |
the argument, aOneArgBlock will be evaluated with the |
|
628 |
selection-value as argument" |
|
629 |
||
630 |
menuAction := aOneArgBlock |
|
631 |
! |
|
632 |
||
2578 | 633 |
ignoreReselect:aBoolean |
634 |
ignoreReselect := aBoolean |
|
635 |
! |
|
636 |
||
2262 | 637 |
menu:aMenu |
638 |
"explicit change of the menu; |
|
639 |
allows for non-list-based, or MenuBuilder-constructed menus to be used. |
|
640 |
Attention: this bypasses the list/listHolder" |
|
641 |
||
642 |
menu := aMenu. |
|
643 |
! |
|
644 |
||
1098 | 645 |
menu:aMenu default:label |
2262 | 646 |
"explicit change of the menu and default value; |
647 |
allows for non-list-based, or MenuBuilder-constructed menus to be used. |
|
648 |
Attention: this bypasses the list/listHolder" |
|
649 |
||
1098 | 650 |
menu := aMenu. |
651 |
defaultLabel := label |
|
652 |
! |
|
653 |
||
1311 | 654 |
useIndex |
655 |
"tell the popuplist to pass the index (instead of the value) |
|
656 |
to both the actionBlock and model. Notice, that if you use a model, |
|
657 |
the default changeSelector is not ok for using index and a SelectionInList" |
|
658 |
||
659 |
^ useIndex |
|
660 |
! |
|
661 |
||
205 | 662 |
useIndex:aBoolean |
663 |
"tell the popuplist to pass the index (instead of the value) |
|
664 |
to both the actionBlock and model. Notice, that if you use a model, |
|
665 |
the default changeSelector is not ok for using index and a SelectionInList" |
|
666 |
||
667 |
useIndex := aBoolean |
|
668 |
||
669 |
" |
|
670 |
|p| |
|
671 |
p := PopUpList label:'fruit ?'. |
|
672 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 673 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 674 |
p open. |
675 |
" |
|
676 |
" |
|
677 |
|p| |
|
678 |
p := PopUpList label:'fruit ?'. |
|
679 |
p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
|
655 | 680 |
p action:[:val | Transcript showCR:'selected: ' , val printString]. |
205 | 681 |
p useIndex:true. |
682 |
p open. |
|
683 |
" |
|
125 | 684 |
! ! |
685 |
||
1921 | 686 |
!PopUpList methodsFor:'accessing-look'! |
687 |
||
688 |
showHandle |
|
689 |
"return true if the pull-handle is to be drawn; default is true" |
|
690 |
||
691 |
^ showHandle |
|
692 |
||
693 |
"Created: / 6.3.1999 / 21:26:40 / cg" |
|
694 |
! |
|
695 |
||
696 |
showHandle:aBoolean |
|
697 |
"controls if the pull-handle is to be drawn; default is true" |
|
698 |
||
2267 | 699 |
showHandle ~~ aBoolean ifTrue:[ |
700 |
showHandle := aBoolean. |
|
701 |
self computeLabelSize |
|
702 |
]. |
|
1921 | 703 |
|
704 |
"Modified: / 6.3.1999 / 21:58:21 / cg" |
|
705 |
! ! |
|
706 |
||
205 | 707 |
!PopUpList methodsFor:'accessing-mvc'! |
708 |
||
709 |
addModelInterfaceTo:aDictionary |
|
710 |
"see comment in View>>modelInterface" |
|
711 |
||
712 |
super addModelInterfaceTo:aDictionary. |
|
713 |
aDictionary at:#listMessage put:listMsg |
|
1063 | 714 |
|
715 |
"Modified: 26.2.1997 / 19:08:04 / cg" |
|
205 | 716 |
! |
717 |
||
1063 | 718 |
listHolder |
719 |
"return the listHolder if any" |
|
720 |
||
721 |
^ listHolder |
|
722 |
! |
|
723 |
||
724 |
listHolder:aValueHolder |
|
725 |
"set the listHolder - if non nil, that one is assumed to provide the |
|
726 |
list via #value. |
|
727 |
If a listHolder was defined, the model is never asked for the list." |
|
728 |
||
729 |
listHolder notNil ifTrue:[ |
|
730 |
listHolder removeDependent:self. |
|
731 |
]. |
|
732 |
listHolder := aValueHolder. |
|
733 |
listHolder notNil ifTrue:[ |
|
734 |
listHolder addDependent:self. |
|
735 |
]. |
|
736 |
shown ifTrue:[ |
|
737 |
self getListFromModel |
|
738 |
] |
|
739 |
||
740 |
"Modified: 26.2.1997 / 19:06:01 / cg" |
|
205 | 741 |
! |
742 |
||
743 |
listMessage |
|
1063 | 744 |
"return the selector by which we ask the model or listHolder for the list. |
745 |
The default is #list. |
|
746 |
If a listHolder was defined, the model is never asked for the list." |
|
205 | 747 |
|
748 |
^ listMsg |
|
1063 | 749 |
|
750 |
"Modified: 26.2.1997 / 19:05:27 / cg" |
|
205 | 751 |
! |
752 |
||
753 |
listMessage:aSelector |
|
754 |
"set the selector by which we ask the model for the list. |
|
1063 | 755 |
The default is #list. |
756 |
If a listHolder was defined, the model is never asked for the list." |
|
205 | 757 |
|
758 |
listMsg := aSelector |
|
1063 | 759 |
|
760 |
"Modified: 26.2.1997 / 19:05:18 / cg" |
|
1083
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
761 |
! |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
762 |
|
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
763 |
model:aModel |
2262 | 764 |
"set the model which provides the selection and/or the list" |
765 |
||
1083
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
766 |
super model:aModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
767 |
self getListFromModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
768 |
self getSelectionFromModel. |
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
769 |
|
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
770 |
"Created: 28.2.1997 / 19:12:08 / cg" |
205 | 771 |
! ! |
772 |
||
773 |
!PopUpList methodsFor:'change & update'! |
|
774 |
||
775 |
update:something with:aParameter from:changedObject |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
776 |
changedObject == listHolder ifTrue:[ |
1063 | 777 |
self getListFromModel. |
778 |
^ self |
|
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
779 |
]. |
205 | 780 |
changedObject == model ifTrue:[ |
1078 | 781 |
aspectMsg notNil ifTrue:[ |
2267 | 782 |
|
1063 | 783 |
self getSelectionFromModel. |
784 |
]. |
|
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
785 |
listHolder notNil ifTrue:[ |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
786 |
"/ that one holds the list; |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
787 |
"/ model holds the value |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
788 |
self getSelectionFromModel |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
789 |
] ifFalse:[ |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
790 |
listMsg notNil ifTrue:[ |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
791 |
self getListFromModel. |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
792 |
] |
1063 | 793 |
]. |
794 |
^ self |
|
205 | 795 |
]. |
796 |
super update:something with:aParameter from:changedObject |
|
1063 | 797 |
|
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
798 |
"Modified: / 18.6.1998 / 23:48:47 / cg" |
205 | 799 |
! ! |
800 |
||
801 |
!PopUpList methodsFor:'drawing'! |
|
802 |
||
803 |
drawWith:fgColor and:bgColor |
|
804 |
|mmH mmV mW mH| |
|
136 | 805 |
|
205 | 806 |
controller pressed ifTrue:[ |
1758 | 807 |
super drawWith:enteredFgColor and:enteredBgColor |
205 | 808 |
] ifFalse:[ |
1758 | 809 |
super drawWith:fgColor and:bgColor. |
205 | 810 |
]. |
811 |
||
1758 | 812 |
showHandle ifTrue:[ |
5631 | 813 |
mmH := device horizontalPixelPerMillimeter. |
814 |
mmV := device verticalPixelPerMillimeter. |
|
1772 | 815 |
mW := (mmH * 2.5) rounded. |
816 |
mH := (mmV * 1.5) rounded. |
|
1758 | 817 |
|
2497
e3e1a719e31d
support etched color (win32 style)
Claus Gittinger <cg@exept.de>
parents:
2495
diff
changeset
|
818 |
self |
5631 | 819 |
drawEdgesForX:(width - mW - (hSpace*2)) y:((height - mmV rounded) // 2) |
2497
e3e1a719e31d
support etched color (win32 style)
Claus Gittinger <cg@exept.de>
parents:
2495
diff
changeset
|
820 |
width:mW height:mH |
e3e1a719e31d
support etched color (win32 style)
Claus Gittinger <cg@exept.de>
parents:
2495
diff
changeset
|
821 |
level:2 |
1758 | 822 |
]. |
1772 | 823 |
|
824 |
"Modified: / 6.3.1999 / 21:56:13 / cg" |
|
205 | 825 |
! |
826 |
||
827 |
showActive |
|
5946 | 828 |
"no need to redraw - will pop menu on top of me anyway ..." |
205 | 829 |
|
830 |
^ self |
|
831 |
! |
|
832 |
||
833 |
showPassive |
|
834 |
"no need to redraw - will redraw from unpopped menu anyway ..." |
|
835 |
||
836 |
^ self |
|
837 |
! ! |
|
838 |
||
839 |
!PopUpList methodsFor:'event handling'! |
|
840 |
||
1492 | 841 |
keyPress:key x:x y:y |
3224 | 842 |
"pull menu on Return and space" |
843 |
||
2398 | 844 |
<resource: #keyboard (#Return)> |
845 |
||
2262 | 846 |
(key == Character space or:[key == #Return])ifTrue:[ |
1492 | 847 |
self popMenu. |
848 |
^ self |
|
849 |
]. |
|
850 |
super keyPress:key x:x y:y |
|
851 |
||
852 |
"Created: / 21.4.1998 / 20:05:19 / cg" |
|
853 |
! |
|
854 |
||
205 | 855 |
popMenu |
2495 | 856 |
|org theMenu val| |
205 | 857 |
|
858 |
menu notNil ifTrue:[ |
|
1098 | 859 |
theMenu := menu value |
860 |
]. |
|
861 |
||
862 |
theMenu notNil ifTrue:[ |
|
863 |
self turnOffWithoutRedraw. |
|
1035 | 864 |
|
1098 | 865 |
theMenu value labels size == 0 ifTrue:[ |
866 |
^ self |
|
867 |
]. |
|
1035 | 868 |
|
1098 | 869 |
theMenu isView ifTrue:[ |
2464 | 870 |
"/ oldStyle - theMenu is a PopUpMenu / MenuPanel |
4904 | 871 |
theMenu font:gc font. |
136 | 872 |
|
1098 | 873 |
" |
874 |
adjust the menus width to my current width |
|
875 |
" |
|
2464 | 876 |
menu preferredWidth:(self width). |
205 | 877 |
|
1098 | 878 |
" |
879 |
the popupMenu wants Display coordinates in its showAt: method |
|
880 |
" |
|
5631 | 881 |
org := device translatePoint:0@0 fromView:self toView:nil. |
205 | 882 |
|
1098 | 883 |
theMenu showAt:org "resizing:false" |
884 |
] ifFalse:[ |
|
885 |
"/ newStyle - theMenu is a Menu |
|
2174 | 886 |
val := theMenu startUpOrNil. |
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
887 |
(theMenu isKindOf:PopUpMenu) ifFalse:[ |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
888 |
"/ sigh - brand new ... |
2174 | 889 |
val notNil ifTrue:[ |
890 |
self sendChangeMessage:changeMsg with:val. |
|
891 |
menuAction notNil ifTrue:[ |
|
892 |
menuAction value:val |
|
893 |
] |
|
2172
411ac4dcf8b4
action invocation for VW compatibility.
Claus Gittinger <cg@exept.de>
parents:
1988
diff
changeset
|
894 |
]. |
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
895 |
]. |
1098 | 896 |
] |
205 | 897 |
]. |
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
898 |
|
2464 | 899 |
"Modified: / 15.11.2001 / 16:53:53 / cg" |
205 | 900 |
! ! |
901 |
||
902 |
!PopUpList methodsFor:'initialization'! |
|
903 |
||
904 |
defaultControllerClass |
|
905 |
^ PopUpListController |
|
906 |
! |
|
907 |
||
908 |
initialize |
|
909 |
super initialize. |
|
910 |
||
911 |
controller beTriggerOnDown. |
|
912 |
controller action:[self popMenu]. |
|
2578 | 913 |
ignoreReselect := true. |
205 | 914 |
useIndex := false. |
1035 | 915 |
defaultLabel := 'popup'. |
1758 | 916 |
showHandle := true. |
1840 | 917 |
self adjust:#left. |
1758 | 918 |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
919 |
super label:defaultLabel. |
1063 | 920 |
|
205 | 921 |
listMsg := self class defaultListMessage. |
922 |
||
923 |
onLevel := offLevel. |
|
1063 | 924 |
|
1086
76da3ddb3372
label: only affects the actual label, if there is no model.
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
925 |
"Modified: 1.3.1997 / 02:12:55 / cg" |
136 | 926 |
! ! |
927 |
||
20 | 928 |
!PopUpList methodsFor:'private'! |
929 |
||
121 | 930 |
createMenuFor:aList |
2464 | 931 |
|index| |
932 |
||
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
933 |
(aList isKindOf:Menu) ifTrue:[ |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
934 |
menu := aList. |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
935 |
^ self. |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
936 |
]. |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
937 |
|
2464 | 938 |
"/ old code (uses old PopUpMenu) |
939 |
"/ menu := PopUpMenu |
|
940 |
"/ labels:aList |
|
941 |
"/ selectors:#select: |
|
942 |
"/ args:(1 to:aList size) |
|
943 |
"/ receiver:self |
|
944 |
"/ for:self. |
|
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
945 |
|
2464 | 946 |
"/ new code - uses (scrollable) MenuPanel |
947 |
menu := MenuPanel labels:aList. |
|
948 |
||
949 |
index := 1. |
|
950 |
menu do:[:el | el value:#select:. el argument:index. index := index + 1. ]. |
|
951 |
menu receiver:self. |
|
4904 | 952 |
menu font:gc font. |
953 |
menu preferredWidth:self width. |
|
2464 | 954 |
|
955 |
"/ end of change |
|
956 |
||
957 |
"Modified: / 15.11.2001 / 16:51:34 / cg" |
|
128 | 958 |
! |
959 |
||
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
960 |
getListFromModel |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
961 |
"if I have a listHolder, ask it for the list; |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
962 |
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
|
963 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
964 |
listHolder notNil ifTrue:[ |
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
965 |
self list:listHolder value. |
1587 | 966 |
"/ model notNil ifTrue:[ |
967 |
"/ self halt. |
|
968 |
"/ ] |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
969 |
] ifFalse:[ |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
970 |
(listMsg notNil and:[model notNil]) ifTrue:[ |
1067 | 971 |
(model respondsTo:listMsg) ifTrue:[ |
972 |
self list:(model perform:listMsg). |
|
973 |
] |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
974 |
]. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
975 |
] |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
976 |
|
1587 | 977 |
"Modified: / 19.6.1998 / 01:54:17 / cg" |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
978 |
! |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
979 |
|
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
980 |
getSelectionFromModel |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
981 |
"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
|
982 |
|
1839
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
983 |
|aspect val newLabel| |
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
984 |
|
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
985 |
(model notNil and:[aspectMsg notNil]) ifTrue:[ |
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
986 |
"/ kludge - try #value if aspect is the default and |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
987 |
"/ not understood by the model |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
988 |
"/ this allows a valueHolder to be used, even |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
989 |
"/ if the aspectMessage was not setup correctly. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
990 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
991 |
aspect := aspectMsg. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
992 |
aspect == self class defaultAspectMessage ifTrue:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
993 |
(model respondsTo:aspect) ifFalse:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
994 |
aspect := #value |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
995 |
] |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
996 |
]. |
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
997 |
val := (model perform:aspect). |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
998 |
|
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
999 |
useIndex ifFalse:[ |
1839
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
1000 |
val isNil ifTrue:[ |
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
1001 |
newLabel := defaultLabel |
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
1002 |
] ifFalse:[ |
6519
6777704804e1
Use `#displatString` instead of `#printString` in `PopUpList >> getSelectionFromModel`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6349
diff
changeset
|
1003 |
newLabel := val displayString. |
1839
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
1004 |
]. |
75f77fcf458b
fix: defaultLabel with nil-selection and not useIndex.
Claus Gittinger <cg@exept.de>
parents:
1772
diff
changeset
|
1005 |
^ self label:newLabel suppressResize:true. |
1586
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1006 |
]. |
e4e6e12cbd1f
ST-80 compatibility changes.
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1007 |
self selection:val |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
1008 |
]. |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
1009 |
|
6519
6777704804e1
Use `#displatString` instead of `#printString` in `PopUpList >> getSelectionFromModel`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6349
diff
changeset
|
1010 |
"Modified: / 18-06-1998 / 23:54:34 / cg" |
6777704804e1
Use `#displatString` instead of `#printString` in `PopUpList >> getSelectionFromModel`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6349
diff
changeset
|
1011 |
"Modified: / 28-11-2018 / 13:10:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
3998
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1012 |
! |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1013 |
|
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1014 |
rawLabelSizeOf:aLogo |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1015 |
"compute the extent needed to hold the label plus the mark" |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1016 |
|
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1017 |
|ext mmH mmV longest longestWidth labels| |
3998
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1018 |
|
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1019 |
ext := super rawLabelSizeOf:aLogo. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1020 |
|
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1021 |
(menu notNil |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1022 |
and:[adjust ~~ #right |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1023 |
and:[adjust ~~ #center]]) ifTrue:[ |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1024 |
"compute length of longest menu entry" |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1025 |
|
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1026 |
longest := logo. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1027 |
logo isNil ifTrue:[ |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1028 |
longestWidth := 0 |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1029 |
] ifFalse:[ |
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1030 |
longestWidth := super rawLabelSizeOf: logo. |
3998
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1031 |
]. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1032 |
labels := menu value labels. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1033 |
labels notNil ifTrue:[ |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1034 |
labels do:[:entry | |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1035 |
|this| |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1036 |
|
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1037 |
this := super rawLabelSizeOf: entry. |
3998
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1038 |
this > longestWidth ifTrue:[ |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1039 |
longest := entry. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1040 |
longestWidth := this |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1041 |
]. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1042 |
]. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1043 |
]. |
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1044 |
ext := ext max:(super rawLabelSizeOf:(longest displayString)) |
3998
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1045 |
]. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1046 |
|
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1047 |
showHandle ifTrue:[ |
5631 | 1048 |
mmH := device horizontalPixelPerMillimeter. |
1049 |
mmV := device verticalPixelPerMillimeter. |
|
3998
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1050 |
^ (ext x + hSpace + (mmH * 2.5) rounded + hSpace) |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1051 |
@ |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1052 |
(ext y max: (mmV * 2) rounded) |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1053 |
]. |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1054 |
^ ext |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1055 |
|
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1056 |
"Modified: / 06-03-1999 / 21:51:14 / cg" |
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1057 |
"Modified: / 26-01-2018 / 10:11:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
121 | 1058 |
! ! |
1059 |
||
205 | 1060 |
!PopUpList methodsFor:'private-controller access'! |
121 | 1061 |
|
205 | 1062 |
menu |
1063 |
"return the menu component" |
|
125 | 1064 |
|
205 | 1065 |
^ menu |
126 | 1066 |
! ! |
1067 |
||
136 | 1068 |
!PopUpList methodsFor:'queries'! |
1069 |
||
1070 |
preferredExtent |
|
1071 |
"redefined to make certain that the menu is fully defined" |
|
1072 |
||
1073 |
menu isNil ifTrue:[ |
|
3773
4fea6dc2496c
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
1074 |
self getListFromModel |
136 | 1075 |
]. |
1076 |
^ super preferredExtent. |
|
714
5ff02d2d9fa7
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
1077 |
|
799 | 1078 |
"Modified: 19.7.1996 / 20:45:16 / cg" |
155 | 1079 |
! |
1080 |
||
1081 |
specClass |
|
1376 | 1082 |
"XXX no longer needed (inherited default works here)" |
1083 |
||
155 | 1084 |
self class == PopUpList ifTrue:[^ PopUpListSpec]. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
1085 |
^ super specClass |
1376 | 1086 |
|
1087 |
"Modified: / 31.10.1997 / 19:48:02 / cg" |
|
136 | 1088 |
! ! |
1089 |
||
5415 | 1090 |
!PopUpList methodsFor:'testing'! |
1091 |
||
1092 |
isPopUpList |
|
1093 |
^ true |
|
1094 |
! ! |
|
1095 |
||
20 | 1096 |
!PopUpList methodsFor:'user actions'! |
1097 |
||
1069 | 1098 |
select:anIndex |
119 | 1099 |
"this is sent from the popupmenu when an entry was selected" |
1100 |
||
1368 | 1101 |
|value menuLabels label chg| |
77 | 1102 |
|
1368 | 1103 |
menuLabels := menu labels. |
1069 | 1104 |
values isNil ifTrue:[ |
1105 |
value := anIndex. |
|
1106 |
useIndex ifFalse:[ |
|
1368 | 1107 |
value := menuLabels at:anIndex. |
1069 | 1108 |
] |
1109 |
] ifFalse:[ |
|
1110 |
value := values at:anIndex |
|
1111 |
]. |
|
1112 |
||
1142
406d3829ddcc
always change my label on select:;
Claus Gittinger <cg@exept.de>
parents:
1098
diff
changeset
|
1113 |
"/ model isNil ifTrue:[ |
1066
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
1114 |
"/ if there is a model, |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
1115 |
"/ the update will change my logo ... |
d324041c0aaf
examples and values-handling
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
1116 |
|
1368 | 1117 |
"/ self sizeFixed:true. |
1118 |
label := menuLabels at:anIndex. |
|
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1119 |
super label:label suppressResize:true. |
1142
406d3829ddcc
always change my label on select:;
Claus Gittinger <cg@exept.de>
parents:
1098
diff
changeset
|
1120 |
"/ ]. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
1121 |
|
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1122 |
(model notNil and:[changeMsg notNil]) ifTrue:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1123 |
"/ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1124 |
"/ ST-80 way of doing it |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1125 |
"/ tell my model - if any |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1126 |
"/ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1127 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1128 |
"/ kludge - try #value: if changeMsg is the default and |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1129 |
"/ not understood by the model |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1130 |
"/ this allows a valueHolder to be used, even |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1131 |
"/ if the aspectMessage was not setup correctly. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1132 |
|
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1133 |
chg := changeMsg. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1134 |
chg == self class defaultChangeMessage ifTrue:[ |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1135 |
(model respondsTo:chg) ifFalse:[ |
1076 | 1136 |
chg := #value: |
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1137 |
] |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1138 |
]. |
2578 | 1139 |
ignoreReselect ifFalse:[ |
1140 |
(value == model value) ifTrue:[ |
|
1141 |
model setValue:nil. |
|
1142 |
]. |
|
1143 |
]. |
|
1075
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1144 |
self sendChangeMessage:chg with:value. |
662f7e5069fd
allow use of a valueHolder, without setting change/aspect
Claus Gittinger <cg@exept.de>
parents:
1071
diff
changeset
|
1145 |
]. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
1146 |
|
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
1147 |
"/ |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
1148 |
"/ ST/X action blocks |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
1149 |
"/ |
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
1150 |
menuAction notNil ifTrue:[ |
1063 | 1151 |
menuAction value:value. |
1052
59f182d1304f
added list- and selectionHolders
Claus Gittinger <cg@exept.de>
parents:
1035
diff
changeset
|
1152 |
]. |
327
5cd2a6f4f28e
fixes to allow use of ListEntries (and an example)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
1153 |
|
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1154 |
"Modified: / 29-10-1997 / 21:08:50 / cg" |
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1155 |
"Modified: / 26-01-2018 / 10:10:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
20 | 1156 |
! ! |
121 | 1157 |
|
998 | 1158 |
!PopUpList class methodsFor:'documentation'! |
121 | 1159 |
|
205 | 1160 |
version |
5415 | 1161 |
^ '$Header$' |
3998
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1162 |
! |
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1163 |
|
39508f0084af
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3773
diff
changeset
|
1164 |
version_CVS |
5415 | 1165 |
^ '$Header$' |
6279
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1166 |
! |
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1167 |
|
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1168 |
version_HG |
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1169 |
|
232954e959f7
Fixed `PopUpList` widget to display correctly non-string objects
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
5957
diff
changeset
|
1170 |
^ '$Changeset: <not expanded> $' |
121 | 1171 |
! ! |
4904 | 1172 |