PopUpList.st
changeset 59 450ce95a72a4
parent 38 4b9b70b2cc87
child 63 f4eaf04d1eaf
equal deleted inserted replaced
58:28815246bbc1 59:450ce95a72a4
     1 "
     1 "
     2  COPYRIGHT (c) 1994 by Claus Gittinger
     2  COPYRIGHT (c) 1994 by Claus Gittinger
     3               All Rights Reserved
     3 	      All Rights Reserved
     4 
     4 
     5  This software is furnished under a license and may be used
     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
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     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 Button subclass:#PopUpList
    13 Button subclass:#PopUpList
    14          instanceVariableNames:'menu menuAction'
    14 	 instanceVariableNames:'menu menuAction'
    15          classVariableNames:''
    15 	 classVariableNames:''
    16          poolDictionaries:''
    16 	 poolDictionaries:''
    17          category:'Views-Interactors'
    17 	 category:'Views-Interactors'
    18 !
    18 !
    19 
    19 
    20 PopUpList comment:'
    20 PopUpList comment:'
    21 COPYRIGHT (c) 1994 by Claus Gittinger
    21 COPYRIGHT (c) 1994 by Claus Gittinger
    22               All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.2 1994-08-07 13:23:07 claus Exp $
    24 $Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.3 1994-10-10 03:02:34 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !PopUpList class methodsFor:'documentation'!
    27 !PopUpList class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    30 "
    30 "
    31  COPYRIGHT (c) 1994 by Claus Gittinger
    31  COPYRIGHT (c) 1994 by Claus Gittinger
    32               All Rights Reserved
    32 	      All Rights Reserved
    33 
    33 
    34  This software is furnished under a license and may be used
    34  This software is furnished under a license and may be used
    35  only in accordance with the terms of that license and with the
    35  only in accordance with the terms of that license and with the
    36  inclusion of the above copyright notice.   This software may not
    36  inclusion of the above copyright notice.   This software may not
    37  be provided or otherwise made available to, or used by, any
    37  be provided or otherwise made available to, or used by, any
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.2 1994-08-07 13:23:07 claus Exp $
    45 $Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.3 1994-10-10 03:02:34 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
    84 
    84 
    85 drawWith:fgColor and:bgColor
    85 drawWith:fgColor and:bgColor
    86     |mmH mmV mW mH|
    86     |mmH mmV mW mH|
    87 
    87 
    88     pressed ifTrue:[
    88     pressed ifTrue:[
    89         super drawWith:enteredFgColor and:enteredBgColor
    89 	super drawWith:enteredFgColor and:enteredBgColor
    90     ] ifFalse:[
    90     ] ifFalse:[
    91         super drawWith:fgColor and:bgColor.
    91 	super drawWith:fgColor and:bgColor.
    92     ].
    92     ].
    93     mmH := (device horizontalPixelPerMillimeter * 1) rounded.
    93     mmH := (device horizontalPixelPerMillimeter * 1) rounded.
    94     mmV := (device verticalPixelPerMillimeter * 1) rounded.
    94     mmV := (device verticalPixelPerMillimeter * 1) rounded.
    95     mW := (device horizontalPixelPerMillimeter * 2.5) rounded.
    95     mW := (device horizontalPixelPerMillimeter * 2.5) rounded.
    96     mH := (device verticalPixelPerMillimeter * 1.5) rounded.
    96     mH := (device verticalPixelPerMillimeter * 1.5) rounded.
    97 
    97 
    98     self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2)
    98     self drawEdgesForX:(width - mW - (hSpace*2)) y:(height - mmV // 2)
    99                  width:mW height:mH level:2
    99 		 width:mW height:mH level:2
   100 ! !
   100 ! !
   101 
   101 
   102 !PopUpList methodsFor:'events'!
   102 !PopUpList methodsFor:'events'!
   103 
   103 
   104 buttonPress:button x:x y:y
   104 buttonPress:button x:x y:y
   105     |org mv|
   105     |org mv|
   106 
   106 
   107     ((button == 1) or:[button == #select]) ifTrue:[
   107     ((button == 1) or:[button == #select]) ifTrue:[
   108         menu notNil ifTrue:[
   108 	menu notNil ifTrue:[
   109             menu font:font.
   109 	    menu font:font.
   110 "
   110 "
   111             menu width:self width + (margin * 2).
   111 	    menu width:self width + (margin * 2).
   112 "
   112 "
   113             mv := menu menuView.
   113 	    mv := menu menuView.
   114             mv width:(self width - (2 * menu margin) - (menu borderWidth*2)).
   114 	    mv width:(self width - (2 * menu margin) - (menu borderWidth*2)).
   115             mv level:0; borderWidth:0.
   115 	    mv level:0; borderWidth:0.
   116             mv fixSize.
   116 	    mv fixSize.
   117             org := device translatePoint:0@0 
   117 	    org := device translatePoint:0@0 
   118                                     from:(self id)
   118 				    from:(self id)
   119                                       to:(DisplayRootView new id).
   119 				      to:(DisplayRootView new id).
   120         
   120         
   121             menu showAt:org "resizing:false"
   121 	    menu showAt:org "resizing:false"
   122         ]
   122 	]
   123     ].
   123     ].
   124 ! !
   124 ! !
   125 
   125 
   126 !PopUpList methodsFor:'initialization'!
   126 !PopUpList methodsFor:'initialization'!
   127 
   127 
   128 initialize
   128 initialize
   129     super initialize.
   129     super initialize.
       
   130     actionWhenPressed := true.
   130     self adjust:#left
   131     self adjust:#left
   131 ! !
   132 ! !
   132 
   133 
   133 !PopUpList methodsFor:'accessing'!
   134 !PopUpList methodsFor:'accessing'!
   134 
   135 
   148 
   149 
   149 list:aList
   150 list:aList
   150     "set the list - i.e. the values shown in the pop-up list"
   151     "set the list - i.e. the values shown in the pop-up list"
   151 
   152 
   152     menu := PopUpMenu
   153     menu := PopUpMenu
   153                   labels:aList
   154 		  labels:aList
   154                selectors:(Array new:(aList size) withAll:#select:)
   155 	       selectors:(Array new:(aList size) withAll:#select:)
   155                     args:aList
   156 		    args:aList
   156                 receiver:self
   157 		receiver:self
   157                      for:self.
   158 		     for:self.
   158     realized ifTrue:[
   159     realized ifTrue:[
   159         self computeLabelSize
   160 	self computeLabelSize
   160     ]
   161     ]
   161 
   162 
   162     "
   163     "
   163      |p|
   164      |p|
   164      p := PopUpList label:'fruit ?'.
   165      p := PopUpList label:'fruit ?'.
   173 
   174 
   174     |index|
   175     |index|
   175 
   176 
   176     index := menu labels indexOf:indexOrString.
   177     index := menu labels indexOf:indexOrString.
   177     index == 0 ifTrue:[
   178     index == 0 ifTrue:[
   178         indexOrString isNumber ifTrue:[
   179 	indexOrString isNumber ifTrue:[
   179             index := indexOrString
   180 	    index := indexOrString
   180         ] ifFalse:[
   181 	] ifFalse:[
   181             ^ self
   182 	    ^ self
   182         ]
   183 	]
   183     ].
   184     ].
   184     self label:(menu labels at:index)
   185     self label:(menu labels at:index)
   185 
   186 
   186     "
   187     "
   187      |p|
   188      |p|
   198     "compute the extent needed to hold the label plus the mark"
   199     "compute the extent needed to hold the label plus the mark"
   199 
   200 
   200     |mmH mmV savedLogo longest longestWidth|
   201     |mmH mmV savedLogo longest longestWidth|
   201 
   202 
   202     menu isNil ifTrue:[
   203     menu isNil ifTrue:[
   203         super computeLabelSize
   204 	super computeLabelSize
   204     ] ifFalse:[
   205     ] ifFalse:[
   205         "hack: simulate logo change to longest menu entry"
   206 	"hack: simulate logo change to longest menu entry"
   206 
   207 
   207         font := font on:device.
   208 	font := font on:device.
   208         longest := logo.
   209 	longest := logo.
   209         longestWidth := font widthOf:logo.
   210 	longestWidth := font widthOf:logo.
   210         menu labels do:[:entry |
   211 	menu labels do:[:entry |
   211             |this|
   212 	    |this|
   212 
   213 
   213             this := font widthOf:entry printString.
   214 	    this := font widthOf:entry printString.
   214             this > longestWidth ifTrue:[
   215 	    this > longestWidth ifTrue:[
   215                 longest := entry.
   216 		longest := entry.
   216                 longestWidth := this
   217 		longestWidth := this
   217             ].
   218 	    ].
   218         ].
   219 	].
   219         savedLogo := logo.
   220 	savedLogo := logo.
   220         logo := longest.
   221 	logo := longest.
   221         super computeLabelSize.
   222 	super computeLabelSize.
   222         logo := savedLogo.
   223 	logo := savedLogo.
   223 "self halt.     "
   224 "self halt.     "
   224     ].
   225     ].
   225     mmH := device horizontalPixelPerMillimeter.
   226     mmH := device horizontalPixelPerMillimeter.
   226     mmV := device verticalPixelPerMillimeter.
   227     mmV := device verticalPixelPerMillimeter.
   227     labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace.
   228     labelWidth := labelWidth + hSpace + (mmH * 2.5) rounded + hSpace.
   231 !PopUpList methodsFor:'user actions'!
   232 !PopUpList methodsFor:'user actions'!
   232 
   233 
   233 select:anEntry
   234 select:anEntry
   234 "/ 'selected:' print. anEntry printNewline.
   235 "/ 'selected:' print. anEntry printNewline.
   235     menuAction notNil ifTrue:[
   236     menuAction notNil ifTrue:[
   236         menuAction value:anEntry.
   237 	menuAction value:anEntry.
   237     ].
   238     ].
   238     self sizeFixed:true.
   239     self sizeFixed:true.
   239     self label:anEntry printString.
   240     self label:anEntry printString.
   240     (model notNil and:[changeSymbol notNil]) ifTrue:[
   241     (model notNil and:[changeSymbol notNil]) ifTrue:[
   241         model perform:changeSymbol with:anEntry
   242 	model perform:changeSymbol with:anEntry
   242     ].
   243     ].
   243 ! !
   244 ! !