"
COPYRIGHT (c) 1994 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
Button subclass:#PopUpList
instanceVariableNames:'menu menuAction'
classVariableNames:''
poolDictionaries:''
category:'Views-Interactors'
!
PopUpList comment:'
COPYRIGHT (c) 1994 by Claus Gittinger
All Rights Reserved
$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.1 1994-01-08 17:27:39 claus Exp $
written jan 94 by claus
'!
!PopUpList methodsFor:'drawing'!
drawWith:fgColor and:bgColor
|mmH mmV mW mH|
pressed ifTrue:[
super drawWith:enteredFgColor and:enteredBgColor
] ifFalse:[
super drawWith:fgColor and:bgColor.
].
mmH := (device horizontalPixelPerMillimeter * 1) rounded.
mmV := (device verticalPixelPerMillimeter * 1) rounded.
mW := (device horizontalPixelPerMillimeter * 2.5) rounded.
mH := (device verticalPixelPerMillimeter * 1.5) rounded.
self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2)
width:mW height:mH level:2
! !
!PopUpList methodsFor:'events'!
buttonPress:button x:x y:y
|org|
button == 1 ifTrue:[
menu notNil ifTrue:[
menu font:font.
menu width:self width.
menu menuView width:(menu width - menu margin - (menu borderWidth*2)).
org := device translatePoint:0@0
from:(self id)
to:(DisplayRootView new id).
menu showAt:org "resizing:false"
]
].
! !
!PopUpList methodsFor:'initialization'!
initialize
super initialize.
self adjust:#left
! !
!PopUpList methodsFor:'accessing'!
action:aBlock
menuAction := aBlock
!
list
^ menu labels
!
list:aList
menu := PopUpMenu
labels:aList
selectors:(Array new:(aList size) withAll:#select:)
args:aList
receiver:self
for:self
!
selection:indexOrString
|index|
index := menu labels indexOf:indexOrString.
index == 0 ifTrue:[
indexOrString isNumber ifTrue:[
index := indexOrString
] ifFalse:[
^ self
]
].
self label:(menu labels at:index)
! !
!PopUpList methodsFor:'private'!
computeLabelSize
"compute the extent needed to hold the label plus the mark"
|mmH mmV savedLogo longest longestWidth|
menu isNil ifTrue:[
super computeLabelSize
] ifFalse:[
"hack: simulate logo change to longest menu entry"
font := font on:device.
longest := nil.
longestWidth := 0.
menu labels do:[:entry |
|this|
this := font widthOf:entry printString.
this > longestWidth ifTrue:[
longest := entry.
longestWidth := this
].
].
savedLogo := logo.
logo := longest.
super computeLabelSize.
logo := savedLogo.
].
mmH := device horizontalPixelPerMillimeter.
mmV := device verticalPixelPerMillimeter.
labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace.
labelHeight := labelHeight max: (mmV * 2) rounded
! !
!PopUpList methodsFor:'user actions'!
select:anEntry
'selected:' print. anEntry printNewline.
menuAction notNil ifTrue:[
menuAction value:anEntry.
].
self sizeFixed:true.
self label:anEntry printString.
! !