ButtonController.st
changeset 789 d1603717af51
parent 711 c830bb66598b
child 971 8caaeb9d63fb
--- a/ButtonController.st	Mon Jul 15 16:40:45 1996 +0200
+++ b/ButtonController.st	Mon Jul 15 16:41:08 1996 +0200
@@ -13,13 +13,13 @@
 Controller subclass:#ButtonController
 	instanceVariableNames:'enableChannel pressChannel releaseChannel pressed active entered
 		isTriggerOnDown autoRepeat repeatBlock initialDelay repeatDelay
-		pressActionBlock releaseActionBlock isToggle'
+		pressActionBlock releaseActionBlock isToggle isRadio'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-Support-Controllers'
 !
 
-!ButtonController class methodsFor:'documentation'!
+!ButtonController  class methodsFor:'documentation'!
 
 copyright
 "
@@ -80,7 +80,7 @@
 "
 ! !
 
-!ButtonController class methodsFor:'defaults'!
+!ButtonController  class methodsFor:'defaults'!
 
 defaultInitialDelay
     "when autorepeat is enabled, and button is not released,
@@ -131,11 +131,26 @@
     "Modified: 5.9.1995 / 22:06:00 / claus"
 !
 
+beRadioButton
+    "make the receiver act like a radioButton;
+     That is like a toggle, but do not allow turning myself off
+     by buttonPress (instead, must be turned off by another button or programmatically)"
+
+    isTriggerOnDown := true.
+    isToggle := false.
+    isRadio := true.
+
+    "Created: 15.7.1996 / 13:42:06 / cg"
+!
+
 beToggle
     "make the receiver act like a toggle"
 
     isTriggerOnDown := true.
-    isToggle := true
+    isToggle := true.
+    isRadio := false.
+
+    "Modified: 15.7.1996 / 13:42:15 / cg"
 !
 
 beTriggerOnDown
@@ -326,78 +341,84 @@
 
 buttonPress:button x:x y:y
     (button == 1 or:[button == #select]) ifFalse:[
-	^ super buttonPress:button x:x y:y
+        ^ super buttonPress:button x:x y:y
     ].
 
     enableChannel value ifTrue:[
-	isToggle ifTrue:[
-	    self toggle.
-	    ^ self
-	].
+        isToggle ifTrue:[
+            self toggle.
+            ^ self
+        ].
+        isRadio ifTrue:[
+            pressed ifFalse:[
+                self toggle
+            ].
+            ^ self
+        ].
 
-	pressed ifFalse:[
-	    pressed := true.
-	    view showActive.
+        pressed ifFalse:[
+            pressed := true.
+            view showActive.
 
-	    (pressActionBlock notNil or:[model notNil]) ifTrue:[
-		"
-		 force output - so that button is drawn correctly in case
-		 of any long-computation (at high priority)
-		"
-		view flush.
-	    ].
+            (pressActionBlock notNil or:[model notNil]) ifTrue:[
+                "
+                 force output - so that button is drawn correctly in case
+                 of any long-computation (at high priority)
+                "
+                view flush.
+            ].
 
-	    self performAction.
+            self performAction.
 
-	    autoRepeat ifTrue:[
-		Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
-	    ]
-	]
+            autoRepeat ifTrue:[
+                Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
+            ]
+        ]
     ]
 
-    "Modified: 16.12.1995 / 17:31:55 / cg"
+    "Modified: 15.7.1996 / 14:07:48 / cg"
 !
 
 buttonRelease:button x:x y:y
     "button was released - if enabled, perform releaseaction"
 
     (button == 1 or:[button == #select]) ifFalse:[
-	^ super buttonRelease:button x:x y:y
+        ^ super buttonRelease:button x:x y:y
     ].
 
-    isToggle ifTrue:[
-	^ self
+    (isToggle or:[isRadio]) ifTrue:[
+        ^ self
     ].
 
     pressed ifTrue:[
-	autoRepeat ifTrue:[
-	    Processor removeTimedBlock:repeatBlock
-	].
-	pressed := false.
-	view showPassive.
+        autoRepeat ifTrue:[
+            Processor removeTimedBlock:repeatBlock
+        ].
+        pressed := false.
+        view showPassive.
 
-	enableChannel value ifTrue:[
-	    "
-	     only perform action if released within myself
-	    "
-	    ((x >= 0) 
-	    and:[x <= view width
-	    and:[y >= 0
-	    and:[y <= view height]]]) ifTrue:[
-		(releaseActionBlock notNil or:[model notNil]) ifTrue:[
-		    "
-		     force output - so that button is drawn correctly in case
-		     of any long-computation (at high priority)
-		    "
-		    view flush.
-		].
+        enableChannel value ifTrue:[
+            "
+             only perform action if released within myself
+            "
+            ((x >= 0) 
+            and:[x <= view width
+            and:[y >= 0
+            and:[y <= view height]]]) ifTrue:[
+                (releaseActionBlock notNil or:[model notNil]) ifTrue:[
+                    "
+                     force output - so that button is drawn correctly in case
+                     of any long-computation (at high priority)
+                    "
+                    view flush.
+                ].
 
-		self performAction.
-	    ]
-	]
+                self performAction.
+            ]
+        ]
     ]
 
-    "Modified: 16.12.1995 / 17:32:09 / cg"
+    "Modified: 15.7.1996 / 13:42:34 / cg"
 !
 
 enableStateChange
@@ -428,34 +449,34 @@
 performAction
     |action value|
 
-    isToggle ifTrue:[
-	value := pressed
+    (isToggle or:[isRadio]) ifTrue:[
+        value := pressed
     ] ifFalse:[
-	value := true
+        value := true
     ].
 
     "
      ST/X style actionBlock evaluation & channel notification ...
     "
     pressed ifTrue:[
-	action := pressActionBlock.
+        action := pressActionBlock.
     ] ifFalse:[
-	action := releaseActionBlock.
+        action := releaseActionBlock.
     ].
     action notNil ifTrue:[
-	active := true.
-	action numArgs == 0 ifTrue:[
-	    action value
-	] ifFalse:[
-	    action value:value
-	].
-	active := false.
+        active := true.
+        action numArgs == 0 ifTrue:[
+            action value
+        ] ifFalse:[
+            action value:value
+        ].
+        active := false.
     ].
     pressChannel notNil ifTrue:[
-	pressChannel value:pressed 
+        pressChannel value:pressed 
     ].
     releaseChannel notNil ifTrue:[
-	releaseChannel value:pressed not
+        releaseChannel value:pressed not
     ].
 
     "
@@ -464,13 +485,15 @@
     (isToggle
     or:[(isTriggerOnDown and:[pressed])
     or:[isTriggerOnDown not and:[pressed not]]]) ifTrue:[
-	"the ST-80 way of doing things"
-	view notNil ifTrue:[
-	    active := true.
-	    view sendChangeMessageWith:value.
-	    active := false.
-	].
+        "the ST-80 way of doing things"
+        view notNil ifTrue:[
+            active := true.
+            view sendChangeMessageWith:value.
+            active := false.
+        ].
     ].
+
+    "Modified: 15.7.1996 / 13:40:59 / cg"
 !
 
 pointerEnter:state x:x y:y
@@ -571,11 +594,13 @@
     initialDelay := self class defaultInitialDelay.
     repeatDelay := self class defaultRepeatDelay.
     isTriggerOnDown := false.
-    isToggle := false.
+    isToggle := isRadio := false.
+
+    "Modified: 15.7.1996 / 13:40:14 / cg"
 ! !
 
-!ButtonController class methodsFor:'documentation'!
+!ButtonController  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.34 1996-05-28 20:11:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.35 1996-07-15 14:41:08 cg Exp $'
 ! !