diff -r 3ee5ea99d0e2 -r 59758ff5b841 Toggle.st --- a/Toggle.st Wed May 03 02:30:14 1995 +0200 +++ b/Toggle.st Wed May 03 02:39:07 1995 +0200 @@ -14,7 +14,7 @@ Button subclass:#Toggle instanceVariableNames:'showLamp lampColor lampWidth lampHeight' - classVariableNames:'' + classVariableNames:'DefaultShowLamp DefaultLampColor' poolDictionaries:'' category:'Views-Interactors' ! @@ -23,7 +23,7 @@ COPYRIGHT (c) 1989 by Claus Gittinger All Rights Reserved -$Header: /cvs/stx/stx/libwidg/Toggle.st,v 1.14 1995-03-18 05:16:19 claus Exp $ +$Header: /cvs/stx/stx/libwidg/Toggle.st,v 1.15 1995-05-03 00:38:26 claus Exp $ '! !Toggle class methodsFor:'documentation'! @@ -44,7 +44,7 @@ version " -$Header: /cvs/stx/stx/libwidg/Toggle.st,v 1.14 1995-03-18 05:16:19 claus Exp $ +$Header: /cvs/stx/stx/libwidg/Toggle.st,v 1.15 1995-05-03 00:38:26 claus Exp $ " ! @@ -66,10 +66,14 @@ instance variables: - showLamp true if a lamp should be displayed - lampColor color of the lamp - lampWidth width of the lamp in pixel - lampHeight height of the lamp in pixel + showLamp true if a lamp should be displayed + lampColor color of the lamp + lampWidth width of the lamp in pixel + lampHeight height of the lamp in pixel + + styleSheet values: + toggleShowLamp if true, a lamp is shown; default:false. + toggleLampColor lamps color; default:yellow. " ! @@ -79,36 +83,46 @@ Try these, to see what is possible. (notice, that these examples are meant to show what can be done; - usually, all style-related stuff id preinitialized - you should not + usually, all style-related stuff is preinitialized - you should not normally play around with onLevel, offLevel, showLamp: etc) simple: |v t| - v := View new. + v := StandardSystemView new extent:200@200. + t := Toggle label:'press here' in:v. + t origin:10 @ 10. + t action:[:value | Transcript show:'toggle state: '; showCr:value.]. + v open + + separate press/release actions: + + |v t| + + v := StandardSystemView new extent:200@200. t := Toggle label:'press here' in:v. t origin:10 @ 10. t pressAction:[Transcript showCr:'toggle pressed'.]. t releaseAction:[Transcript showCr:'toggle released'.]. - v realize + v open changing logo: |v t| - v := View new. + v := StandardSystemView new extent:200@200. t := Toggle label:'eat me' in:v. t origin:10 @ 10. t pressAction:[Transcript showCr:'smaller'. t label:'drink me']. t releaseAction:[Transcript showCr:'larger'. t label:'eat me']. - v realize + v open changing logo and freezing size (looks better): |v t| - v := View new. + v := StandardSystemView new extent:200@200. 'create with large logo; freeze; change to small logo'. t := Toggle label:'drink me' in:v. t sizeFixed:true. @@ -117,51 +131,77 @@ t origin:10 @ 10. t pressAction:[Transcript showCr:'smaller'. t label:'drink me']. t releaseAction:[Transcript showCr:'larger'. t label:'eat me']. - v realize + v open - adding lamp (on by default in some view styles): + adding a lamp (in some view styles, this is the default anyway): |v t| - v := View new. + v := StandardSystemView new extent:200@200. t := Toggle label:'off' in:v. t showLamp:true. t origin:10 @ 10. t pressAction:[Transcript showCr:'on'. t label:'on']. t releaseAction:[Transcript showCr:'off'. t label:'off']. - v realize + v open - lamp only - no 'going-in' + changing lamps color: |v t| - v := View new. + v := StandardSystemView new extent:200@200. + t := Toggle label:'off' in:v. + t showLamp:true. + t lampColor:Color red. + t origin:10 @ 10. + t pressAction:[Transcript showCr:'on'. t label:'on'.]. + t releaseAction:[Transcript showCr:'off'. t label:'off'.]. + v open + + changing lamps color & size: + + |v t| + + v := StandardSystemView new extent:200@200. + t := Toggle label:'off' in:v. + t showLamp:true. + t lampColor:Color red. + t origin:10 @ 10. + t pressAction:[Transcript showCr:'on'. t label:'on'.]. + t releaseAction:[Transcript showCr:'off'. t label:'off'.]. + v open + + lamp only - no '3D going-in' (this is the default with IRIS style) + + |v t| + + v := StandardSystemView new extent:200@200. t := Toggle label:'off' in:v. t showLamp:true. t onLevel:(t offLevel). t origin:10 @ 10. t pressAction:[Transcript showCr:'on'. t label:'on']. t releaseAction:[Transcript showCr:'off'. t label:'off']. - v realize + v open lamp and freezing size of the label (looks better): |v t| - v := View new. + v := StandardSystemView new extent:200@200. t := Toggle label:'off' in:v. t showLamp:true. t sizeFixed:true. t origin:10 @ 10. t pressAction:[Transcript showCr:'on'. t label:'on']. t releaseAction:[Transcript showCr:'off'. t label:'off']. - v realize + v open another variation: |v t| - v := View new. + v := StandardSystemView new extent:200@200. t := Toggle label:'off' in:v. t showLamp:true. t sizeFixed:true. @@ -169,13 +209,13 @@ t origin:10 @ 10. t pressAction:[Transcript showCr:'on'. t label:'on']. t releaseAction:[Transcript showCr:'off'. t label:'off']. - v realize + v open and another one: |v t| - v := View new. + v := StandardSystemView new extent:200@200. t := Toggle label:'off' in:v. t showLamp:true. t sizeFixed:true. @@ -186,26 +226,26 @@ t origin:10 @ 10. t pressAction:[Transcript showCr:'on'. t showLamp:true. t label:'on']. t releaseAction:[Transcript showCr:'off'. t showLamp:false. t label:'off']. - v realize + v open another font: |v t| - v := View new. + v := StandardSystemView new extent:200@200. t := Toggle label:'off' in:v. t font:(Font family:'times' face:'bold' style:'roman' size:24). t label:'hello'. t origin:10 @ 10. t pressAction:[Transcript showCr:'on'.]. t releaseAction:[Transcript showCr:'off'.]. - v realize + v open another font (no, I dont know what it means :-): |v t| - v := View new. + v := StandardSystemView new extent:200@200. t := Toggle label:'off' in:v. t font:(Font family:'k14' face:nil style:nil size:nil). t label:(TwoByteString with:(Character value:16r3021)). @@ -213,10 +253,47 @@ t origin:10 @ 10. t pressAction:[Transcript showCr:'on'.]. t releaseAction:[Transcript showCr:'off'.]. - v realize + v open + + using a model (look at value of model in inspector): + + |m v t| + + m := ValueHolder newBoolean. + m inspect. + + v := StandardSystemView new extent:200@200. + t := Toggle label:'press here to change value' in:v. + t origin:10 @ 10. + t model:m. + v open + + using a model with different changeSelector: + + |m v t| + + m := Plug new. + m respondTo:#setValue1: with:[:value | Transcript show:'value 1 changed to: '; showCr:value]. + m respondTo:#setValue2: with:[:value | Transcript show:'value 2 changed to: '; showCr:value]. + + v := StandardSystemView new extent:200@200. + t := Toggle label:'press here for value1' in:v. + t origin:10 @ 10. + t model:m; change:#setValue1:. + t := Toggle label:'press here for value2' in:v. + t origin:10 @ 50. + t model:m; change:#setValue2:. + v open " ! ! +!Toggle class methodsFor:'defaults'! + +updateStyleCache + DefaultShowLamp := StyleSheet at:'toggleShowLamp' default:false. + DefaultLampColor := StyleSheet colorAt:'toggleLampColor' default:Color yellow. +! ! + !Toggle methodsFor:'initialization'! defaultControllerClass @@ -226,7 +303,7 @@ initStyle super initStyle. - showLamp := StyleSheet at:#toggleShowLamp default:false. + showLamp := DefaultShowLamp. showLamp ifTrue:[ onLevel := offLevel. @@ -236,9 +313,17 @@ " ]. - lampColor := StyleSheet at:#toggleLampColor default:Color yellow. + lampColor := DefaultLampColor on:device. lampWidth := (device horizontalPixelPerMillimeter * 1.8) rounded. lampHeight := (device verticalPixelPerMillimeter * 3.5) rounded. +! + +realize + "/ + "/ get my initial state from the model (if there is one) + "/ + self getValueFromModel. + super realize ! ! !Toggle methodsFor:'accessing'! @@ -272,6 +357,12 @@ !Toggle methodsFor:'private'! +getValueFromModel + (model notNil and:[aspectMsg notNil]) ifTrue:[ + controller pressed:(model perform:aspectMsg) + ]. +! + computeLabelOrigin "compute the origin of the form/text. redefined to move label to the right if there is a lamp." @@ -315,44 +406,3 @@ self fillRectangleX:x+2 y:y+2 width:lampWidth - 4 height:lampHeight - 4 ] ! ! - -!Toggle methodsFor:'changing state'! - -toggleNoAction - "toggle, but do NOT perform any action - can be used to change a toggle - under program control (i.e. turn one toggle off from another one)" - - |newLevel pressed| - - pressed := controller pressed not. - controller pressed:pressed. - pressed ifTrue:[ - newLevel := onLevel. - ] ifFalse:[ - newLevel := offLevel. - ]. - self level:newLevel. - - shown ifTrue:[ - self redraw - ]. -! - -toggle - "toggle and perform the action" - - |action pressed sym| - - controller enabled ifTrue:[ - self toggleNoAction. - (pressed := controller pressed) ifTrue:[ - action := controller pressAction - ] ifFalse:[ - action := controller releaseAction - ]. - action notNil ifTrue:[action value]. - self sendChangeMessageWith:pressed. - self changed:#toggle with:pressed - ] -! ! -