8 be provided or otherwise made available to, or used by, any |
8 be provided or otherwise made available to, or used by, any |
9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 |
12 |
13 'From Smalltalk/X, Version:2.10.5 on 9-may-1995 at 12:04:16 pm'! |
13 'From Smalltalk/X, Version:2.10.5 on 9-may-1995 at 12:06:03 pm'! |
14 |
14 |
15 Button subclass:#PopUpList |
15 Button subclass:#PopUpList |
16 instanceVariableNames:'menu menuAction values useIndex listMsg initialSelectionMsg' |
16 instanceVariableNames:'menu menuAction values useIndex listMsg' |
17 classVariableNames:'' |
17 classVariableNames:'' |
18 poolDictionaries:'' |
18 poolDictionaries:'' |
19 category:'Views-Interactors' |
19 category:'Views-Interactors' |
20 ! |
20 ! |
21 |
21 |
22 PopUpList comment:' |
22 PopUpList comment:' |
23 COPYRIGHT (c) 1994 by Claus Gittinger |
23 COPYRIGHT (c) 1994 by Claus Gittinger |
24 All Rights Reserved |
24 All Rights Reserved |
25 |
25 |
26 $Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.12 1995-05-09 01:56:26 claus Exp $ |
26 $Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.13 1995-05-10 02:29:55 claus Exp $ |
27 '! |
27 '! |
28 |
28 |
29 !PopUpList class methodsFor:'documentation'! |
29 !PopUpList class methodsFor:'documentation'! |
30 |
30 |
31 copyright |
31 copyright |
76 with useIndex:true and a selectionInList model. |
76 with useIndex:true and a selectionInList model. |
77 (set the changeMessage to #selectionIndex: then) |
77 (set the changeMessage to #selectionIndex: then) |
78 |
78 |
79 listMsg <Symbol> message to aquire a new list from the |
79 listMsg <Symbol> message to aquire a new list from the |
80 model. Default is #list. |
80 model. Default is #list. |
81 |
|
82 |
|
83 initialSelectionMsg <Symbol> message to aquire a new selection from the |
|
84 model. Default is #selection. |
|
85 " |
81 " |
86 ! |
82 ! |
87 |
83 |
88 examples |
84 examples |
89 " |
85 " |
138 since the list is actually a popupMenu, you can add double-separators: |
134 since the list is actually a popupMenu, you can add double-separators: |
139 |
135 |
140 |p| |
136 |p| |
141 p := PopUpList label:'dummy'. |
137 p := PopUpList label:'dummy'. |
142 p list:#('apples' 'bananas' 'grape' 'lemon' |
138 p list:#('apples' 'bananas' 'grape' 'lemon' |
143 '=' |
139 '=' |
144 'margaritas' 'pina colada' |
140 'margaritas' 'pina colada' |
145 '=' |
141 '=' |
146 'smalltalk' 'c++' 'eiffel'). |
142 'smalltalk' 'c++' 'eiffel'). |
147 p values:#(apples bananas grape lemon |
143 p values:#(apples bananas grape lemon |
148 nil |
144 nil |
149 'mhmh - so good' 'makes headache' |
145 'mhmh - so good' 'makes headache' |
150 nil |
146 nil |
151 'great' 'another headache' 'no bad'). |
147 'great' 'another headache' 'no bad'). |
152 p selection:'apples'. |
148 p selection:'apples'. |
153 p action:[:what | Transcript show:'you selected: '; showCr:what]. |
149 p action:[:what | Transcript show:'you selected: '; showCr:what]. |
154 p open |
150 p open |
155 |
151 |
156 |
152 |
195 |
191 |
196 model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
192 model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
197 model selection:'apples'. |
193 model selection:'apples'. |
198 |
194 |
199 p := PopUpList on:model. |
195 p := PopUpList on:model. |
|
196 p useIndex:true; aspect:#selectionIndex; change:#selectionIndex:. |
200 p open. |
197 p open. |
201 |
198 |
202 slv := SelectionInListView on:model. |
199 slv := SelectionInListView on:model. |
203 slv open. |
200 slv open. |
204 |
201 |
|
202 p inspect. |
205 model selectionIndexHolder inspect |
203 model selectionIndexHolder inspect |
206 |
204 |
207 |
205 |
208 two PopUpLists on the same model: |
206 two PopUpLists on the same model: |
209 |
207 |
219 top extent:(100@100). |
217 top extent:(100@100). |
220 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
218 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
221 panel horizontalLayout:#fitSpace. |
219 panel horizontalLayout:#fitSpace. |
222 |
220 |
223 p := PopUpList label:'meals'. |
221 p := PopUpList label:'meals'. |
224 p model:model; listMessage:#meals; change:#eat:. |
222 p model:model; listMessage:#meals; aspect:nil; change:#eat:. |
225 panel add:p. |
223 panel add:p. |
226 |
224 |
227 p := PopUpList label:'drinks'. |
225 p := PopUpList label:'drinks'. |
228 p model:model; listMessage:#drinks; change:#drink:. |
226 p model:model; listMessage:#drinks; aspect:nil; change:#drink:. |
229 panel add:p. |
227 panel add:p. |
230 |
228 |
231 top open |
229 top open |
232 " |
230 " |
233 ! ! |
231 ! ! |
242 ^ #list |
240 ^ #list |
243 ! |
241 ! |
244 |
242 |
245 defaultChangeMessage |
243 defaultChangeMessage |
246 ^ #selection: |
244 ^ #selection: |
247 ! ! |
|
248 |
|
249 !PopUpList methodsFor:'drawing'! |
|
250 |
|
251 drawWith:fgColor and:bgColor |
|
252 |mmH mmV mW mH| |
|
253 |
|
254 controller pressed ifTrue:[ |
|
255 super drawWith:enteredFgColor and:enteredBgColor |
|
256 ] ifFalse:[ |
|
257 super drawWith:fgColor and:bgColor. |
|
258 ]. |
|
259 mmH := device horizontalPixelPerMillimeter rounded. |
|
260 mmV := device verticalPixelPerMillimeter rounded. |
|
261 mW := (device horizontalPixelPerMillimeter * 2.5) rounded. |
|
262 mH := (device verticalPixelPerMillimeter * 1.5) rounded. |
|
263 |
|
264 self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2) |
|
265 width:mW height:mH level:2 |
|
266 ! ! |
245 ! ! |
267 |
246 |
268 !PopUpList methodsFor:'private'! |
247 !PopUpList methodsFor:'private'! |
269 |
248 |
270 realize |
249 realize |
271 super realize. |
250 super realize. |
272 model notNil ifTrue:[ |
251 model notNil ifTrue:[ |
273 self getListFromModel |
252 self getListFromModel. |
|
253 self getSelectionFromModel. |
274 ]. |
254 ]. |
275 ! |
255 ! |
276 |
256 |
277 computeLabelSize |
257 computeLabelSize |
278 "compute the extent needed to hold the label plus the mark" |
258 "compute the extent needed to hold the label plus the mark" |
306 mmV := device verticalPixelPerMillimeter. |
286 mmV := device verticalPixelPerMillimeter. |
307 labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace. |
287 labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace. |
308 labelHeight := labelHeight max: (mmV * 2) rounded |
288 labelHeight := labelHeight max: (mmV * 2) rounded |
309 ! |
289 ! |
310 |
290 |
311 getSelectionFromModel |
|
312 "if I have a model and a listMsg, get my list from it" |
|
313 |
|
314 (model notNil |
|
315 and:[aspectMsg notNil]) ifTrue:[ |
|
316 self selection:(model perform:aspectMsg). |
|
317 ]. |
|
318 ! |
|
319 |
|
320 createMenuFor:aList |
291 createMenuFor:aList |
321 menu := PopUpMenu |
292 menu := PopUpMenu |
322 labels:aList |
293 labels:aList |
323 selectors:#select: |
294 selectors:#select: |
324 args:(1 to:aList size) |
295 args:(1 to:aList size) |
325 receiver:self |
296 receiver:self |
326 for:self. |
297 for:self. |
327 ! |
298 ! ! |
328 |
299 |
329 getListFromModel |
300 !PopUpList methodsFor:'drawing'! |
330 "if I have a model and a listMsg, get my list from it" |
301 |
331 |
302 drawWith:fgColor and:bgColor |
332 (model notNil |
303 |mmH mmV mW mH| |
333 and:[listMsg notNil]) ifTrue:[ |
304 |
334 self list:(model perform:listMsg). |
305 controller pressed ifTrue:[ |
335 ]. |
306 super drawWith:enteredFgColor and:enteredBgColor |
|
307 ] ifFalse:[ |
|
308 super drawWith:fgColor and:bgColor. |
|
309 ]. |
|
310 mmH := device horizontalPixelPerMillimeter rounded. |
|
311 mmV := device verticalPixelPerMillimeter rounded. |
|
312 mW := (device horizontalPixelPerMillimeter * 2.5) rounded. |
|
313 mH := (device verticalPixelPerMillimeter * 1.5) rounded. |
|
314 |
|
315 self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2) |
|
316 width:mW height:mH level:2 |
336 ! ! |
317 ! ! |
337 |
318 |
338 !PopUpList methodsFor:'event handling'! |
319 !PopUpList methodsFor:'event handling'! |
339 |
320 |
340 popMenu |
321 popMenu |
467 p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
448 p list:#('apples' 'bananas' 'grape' 'lemon' 'margaritas'). |
468 p values:#(1 2 3 4 'mhmh - good'). |
449 p values:#(1 2 3 4 'mhmh - good'). |
469 p action:[:val | Transcript showCr:'selected: ' , val printString]. |
450 p action:[:val | Transcript showCr:'selected: ' , val printString]. |
470 p open. |
451 p open. |
471 " |
452 " |
|
453 ! ! |
|
454 |
|
455 !PopUpList methodsFor:'accessing-mvc'! |
|
456 |
|
457 getListFromModel |
|
458 "if I have a model and a listMsg, get my list from it" |
|
459 |
|
460 (model notNil |
|
461 and:[listMsg notNil]) ifTrue:[ |
|
462 self list:(model perform:listMsg). |
|
463 ]. |
|
464 ! |
|
465 |
|
466 getSelectionFromModel |
|
467 "if I have a model and an aspectMsg, get my current value from it" |
|
468 |
|
469 (model notNil |
|
470 and:[aspectMsg notNil]) ifTrue:[ |
|
471 self selection:(model perform:aspectMsg). |
|
472 ]. |
472 ! |
473 ! |
473 |
474 |
474 listMessage:aSelector |
475 listMessage:aSelector |
475 "set the selector by which we ask the model for the list. |
476 "set the selector by which we ask the model for the list. |
476 Default is #list." |
477 Default is #list." |
477 |
478 |
478 listMsg := aSelector |
479 listMsg := aSelector |
479 ! |
480 ! |
480 |
481 |
|
482 addModelInterfaceTo:aDictionary |
|
483 "see comment in View>>modelInterface" |
|
484 |
|
485 super addModelInterfaceTo:aDictionary. |
|
486 aDictionary at:#listMessage put:listMsg |
|
487 ! |
|
488 |
481 listMessage |
489 listMessage |
482 "return the selector by which we ask the model for the list. |
490 "return the selector by which we ask the model for the list. |
483 Default is #list." |
491 Default is #list." |
484 |
492 |
485 ^ listMsg |
493 ^ listMsg |