ButtonController.st
changeset 200 aa3e56929a5a
parent 177 c06d27f8525f
child 203 8a38b0b03233
--- a/ButtonController.st	Thu Nov 23 11:37:10 1995 +0100
+++ b/ButtonController.st	Thu Nov 23 11:42:48 1995 +0100
@@ -10,13 +10,10 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:2.10.5 on 4-may-1995 at 6:17:35 am'!
-
 Controller subclass:#ButtonController
-	 instanceVariableNames:'enableChannel pressChannel releaseChannel
-		pressed active entered isTriggerOnDown autoRepeat
-		repeatBlock initialDelay repeatDelay pressActionBlock
-		releaseActionBlock isToggle'
+	 instanceVariableNames:'enableChannel pressChannel releaseChannel pressed active entered
+                isTriggerOnDown autoRepeat repeatBlock initialDelay repeatDelay
+                pressActionBlock releaseActionBlock isToggle'
 	 classVariableNames:''
 	 poolDictionaries:''
 	 category:'Interface-Support-Controllers'
@@ -38,10 +35,6 @@
 "
 !
 
-version
-    ^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.21 1995-11-14 21:44:27 cg Exp $'
-!
-
 documentation
 "
     ButtonControllers are used with buttons and handle all user interaction.
@@ -82,71 +75,158 @@
 
       active                  <Boolean>       true during action evaluation (internal)
 "
+!
+
+version
+    ^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.22 1995-11-23 10:39:34 cg Exp $'
 ! !
 
 !ButtonController class methodsFor:'defaults'!
 
-defaultRepeatDelay
-    "when autorepeat is enabled, and button is not released,
-     repeat every repeatDelay seconds"
-
-    ^ 0.025
-!
-
 defaultInitialDelay
     "when autorepeat is enabled, and button is not released,
      start repeating after initialDelay seconds"
 
     ^ 0.2
+!
+
+defaultRepeatDelay
+    "when autorepeat is enabled, and button is not released,
+     repeat every repeatDelay seconds"
+
+    ^ 0.025
 ! !
 
-!ButtonController methodsFor:'accessing-state'!
+!ButtonController methodsFor:'accessing-behavior'!
+
+action:aBlock
+    "convenient method: depending on the setting the triggerOnDown flag,
+     either set the press-action clear any release-action or
+     vice versa, set the release-action and clear the press-action."
 
-pressed
-    "return true, if I am pressed"
+    isTriggerOnDown ifTrue:[
+	releaseActionBlock := nil.
+	pressActionBlock := aBlock
+    ] ifFalse:[
+	releaseActionBlock := aBlock.
+	pressActionBlock := nil
+    ]
+!
 
-    ^ pressed
+autoRepeat
+    "turn on autorepeat. OBSOLETE"
+
+    autoRepeat := true.
+    repeatBlock := [self repeat]
 !
 
-active
-    "return true, if I am active; 
-     that is: currently performing my action.
-     This query can be used to avoid multiple redraws."
+autoRepeat:aBoolean
+    "turn on/off autorepeat"
+
+    autoRepeat := aBoolean.
+    repeatBlock := [self repeat]
 
-    ^ active
+    "Modified: 5.9.1995 / 22:06:00 / claus"
+!
+
+beToggle
+    "make the receiver act like a toggle"
+
+    isTriggerOnDown := true.
+    isToggle := true
 !
 
-enabled
-    "return true, if I am enabled"
+beTriggerOnDown
+    "make the receiver act on button press"
+
+    isTriggerOnDown := true
+!
+
+beTriggerOnUp
+    "make the receiver act on button release"
 
-    ^ enableChannel value
+    isTriggerOnDown := false
+!
+
+disable
+    "disable the button"
+
+    enableChannel value ifTrue:[
+	enableChannel value:false.
+	"/ view redraw    - not needed; I listen to enableChannel
+    ]
 !
 
-entered
-    "return true, if the mouse pointer is currently in my view"
+enable
+    "enable the button"
 
-    ^ entered
+    enableChannel value ifFalse:[
+	enableChannel value:true.
+	"/ view redraw    - not needed; I listen to enableChannel
+    ]
 !
 
-entered:aBoolean
-    entered := aBoolean
+isTriggerOnDown
+    "return true, if I trigger on press
+     (in contrast to triggering on up, which is the default)"
+
+    ^ isTriggerOnDown
+!
+
+pressAction
+    "return the pressAction; thats the block which gets evaluated
+     when the button is pressed (if non-nil)"
+
+    ^ pressActionBlock
+!
+
+pressAction:aBlock
+    "define the action to be performed on press"
+
+    pressActionBlock := aBlock
 !
 
-active:aBoolean
-    active := aBoolean
+releaseAction
+    "return the releaseAction; thats the block which gets evaluated
+     when the button is relreased (if non-nil)"
+
+    ^ releaseActionBlock
+!
+
+releaseAction:aBlock
+    "define the action to be performed on release"
+
+    releaseActionBlock := aBlock
 !
 
-setPressed:aBoolean
-    pressed := aBoolean.
+toggle
+    "toggle and perform the action"
 
-    "Created: 14.11.1995 / 21:37:08 / cg"
+    enableChannel value ifTrue:[
+	self toggleNoAction.
+	self performAction.
+	view changed:#toggle with:pressed
+    ]
 !
 
-pressed:aBoolean
-    pressed ~~ aBoolean ifTrue:[
-	pressed := aBoolean.
-	self performAction.
+toggleNoAction
+    "toggle, but do NOT perform any action"
+
+    pressed ifTrue:[
+	view turnOff.
+	pressed := false.
+    ] ifFalse:[
+	view turnOn.
+	pressed := true.
     ].
+!
+
+triggerOnDown:aBoolean
+    "set/clear the flag which controls if the action block is to be evaluated
+     on press or on release. 
+     (see also ST-80 compatibility methods beTriggerOn*)"
+
+    isTriggerOnDown := aBoolean
 ! !
 
 !ButtonController methodsFor:'accessing-channels'!
@@ -186,140 +266,61 @@
     releaseChannel := aChannel
 ! !
 
-!ButtonController methodsFor:'accessing-behavior'!
-
-beTriggerOnDown
-    "make the receiver act on button press"
+!ButtonController methodsFor:'accessing-state'!
 
-    isTriggerOnDown := true
-!
+active
+    "return true, if I am active; 
+     that is: currently performing my action.
+     This query can be used to avoid multiple redraws."
 
-beTriggerOnUp
-    "make the receiver act on button release"
-
-    isTriggerOnDown := false
+    ^ active
 !
 
-triggerOnDown:aBoolean
-    "set/clear the flag which controls if the action block is to be evaluated
-     on press or on release. 
-     (see also ST-80 compatibility methods beTriggerOn*)"
-
-    isTriggerOnDown := aBoolean
+active:aBoolean
+    active := aBoolean
 !
 
-isTriggerOnDown
-    "return true, if I trigger on press
-     (in contrast to triggering on up, which is the default)"
-
-    ^ isTriggerOnDown
-!
-
-beToggle
-    "make the receiver act like a toggle"
+enabled
+    "return true, if I am enabled"
 
-    isTriggerOnDown := true.
-    isToggle := true
-!
-
-autoRepeat
-    "turn on autorepeat. OBSOLETE"
-
-    autoRepeat := true.
-    repeatBlock := [self repeat]
+    ^ enableChannel value
 !
 
-autoRepeat:aBoolean
-    "turn on/off autorepeat"
+entered
+    "return true, if the mouse pointer is currently in my view"
 
-    autoRepeat := aBoolean.
-    repeatBlock := [self repeat]
+    ^ entered
+!
 
-    "Modified: 5.9.1995 / 22:06:00 / claus"
+entered:aBoolean
+    entered := aBoolean
 !
 
-action:aBlock
-    "convenient method: depending on the setting the triggerOnDown flag,
-     either set the press-action clear any release-action or
-     vice versa, set the release-action and clear the press-action."
+pressed
+    "return true, if I am pressed"
 
-    isTriggerOnDown ifTrue:[
-	releaseActionBlock := nil.
-	pressActionBlock := aBlock
-    ] ifFalse:[
-	releaseActionBlock := aBlock.
-	pressActionBlock := nil
-    ]
+    ^ pressed
 !
 
-pressAction:aBlock
-    "define the action to be performed on press"
-
-    pressActionBlock := aBlock
-!
-
-releaseAction:aBlock
-    "define the action to be performed on release"
-
-    releaseActionBlock := aBlock
-!
-
-toggleNoAction
-    "toggle, but do NOT perform any action"
-
-    pressed ifTrue:[
-	view turnOff.
-	pressed := false.
-    ] ifFalse:[
-	view turnOn.
-	pressed := true.
+pressed:aBoolean
+    pressed ~~ aBoolean ifTrue:[
+	pressed := aBoolean.
+	self performAction.
     ].
 !
 
-toggle
-    "toggle and perform the action"
-
-    enableChannel value ifTrue:[
-	self toggleNoAction.
-	self performAction.
-	view changed:#toggle with:pressed
-    ]
-!
-
-pressAction
-    "return the pressAction; thats the block which gets evaluated
-     when the button is pressed (if non-nil)"
-
-    ^ pressActionBlock
-!
+setPressed:aBoolean
+    pressed := aBoolean.
 
-releaseAction
-    "return the releaseAction; thats the block which gets evaluated
-     when the button is relreased (if non-nil)"
-
-    ^ releaseActionBlock
-!
-
-enable
-    "enable the button"
-
-    enableChannel value ifFalse:[
-	enableChannel value:true.
-	"/ view redraw    - not needed; I listen to enableChannel
-    ]
-!
-
-disable
-    "disable the button"
-
-    enableChannel value ifTrue:[
-	enableChannel value:false.
-	"/ view redraw    - not needed; I listen to enableChannel
-    ]
+    "Created: 14.11.1995 / 21:37:08 / cg"
 ! !
 
 !ButtonController methodsFor:'event handling'!
 
+buttonMultiPress:button x:x y:y
+    ^ self buttonPress:button x:x y:y
+!
+
 buttonPress:button x:x y:y
     (button == 1 or:[button == #select]) ifFalse:[
 	^ super buttonPress:button x:x y:y
@@ -392,52 +393,27 @@
     ]
 !
 
-pointerEnter:state x:x y:y
-    "mouse pointer entered my view.
-     Redraw with enteredColors if they differ from the normal colors"
+enableStateChange
+    "this is sent, whenever the enable value has changed"
 
-    entered := true.
-    enableChannel value ifTrue:[
-	pressed ifTrue:[
-	    "
-	     reentered after a leave with mouse-button down;
-	     restart autorepeating and/or if I am a button with
-	     triggerOnDown, show active again.
-	    "
-	    autoRepeat ifTrue:[
-		Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
-	    ].
-	    isTriggerOnDown ifFalse:[
-		view showActive.
-	    ]
-	] ifFalse:[
-	    view redraw
-	]
-    ]
+    view notNil ifTrue:[view enableStateChangeRedraw]
+
+    "Modified: 17.9.1995 / 19:55:52 / claus"
 !
 
-pointerLeave:state
-    "mouse pointer left my view.
-     Redraw with normal colors if they differ from enteredColors"
+keyPress:key x:x y:y
+    "trigger on Return and space, if I am the focusView of my group
+     (i.e. if I got an explicit focus)"
 
-    entered := false.
-    pressed ifTrue:[
-	"
-	 leave with mouse-button down;
-	 stop autorepeating and/or if I am a button with
-	 action on release, show passive
-	"
-	autoRepeat ifTrue:[
-	    Processor removeTimedBlock:repeatBlock
-	].
-	isTriggerOnDown ifFalse:[
-	    view showPassive.
+    (key == #Return or:[key == Character space]) ifTrue:[
+	view hasFocus ifTrue:[
+	    "just simulate a buttonPress/release here."
+	    self buttonPress:1 x:0 y:0.
+	    self buttonRelease:1 x:0 y:0.
+	    ^ self.
 	]
-    ] ifFalse:[
-	enableChannel value ifTrue:[
-	    view redraw
-	]
-    ]
+    ].
+    view keyPress:key x:x y:y
 !
 
 performAction
@@ -488,23 +464,52 @@
     ].
 !
 
-buttonMultiPress:button x:x y:y
-    ^ self buttonPress:button x:x y:y
+pointerEnter:state x:x y:y
+    "mouse pointer entered my view.
+     Redraw with enteredColors if they differ from the normal colors"
+
+    entered := true.
+    enableChannel value ifTrue:[
+	pressed ifTrue:[
+	    "
+	     reentered after a leave with mouse-button down;
+	     restart autorepeating and/or if I am a button with
+	     triggerOnDown, show active again.
+	    "
+	    autoRepeat ifTrue:[
+		Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
+	    ].
+	    isTriggerOnDown ifFalse:[
+		view showActive.
+	    ]
+	] ifFalse:[
+	    view redraw
+	]
+    ]
 !
 
-keyPress:key x:x y:y
-    "trigger on Return and space, if I am the focusView of my group
-     (i.e. if I got an explicit focus)"
+pointerLeave:state
+    "mouse pointer left my view.
+     Redraw with normal colors if they differ from enteredColors"
 
-    (key == #Return or:[key == Character space]) ifTrue:[
-	view hasFocus ifTrue:[
-	    "just simulate a buttonPress/release here."
-	    self buttonPress:1 x:0 y:0.
-	    self buttonRelease:1 x:0 y:0.
-	    ^ self.
+    entered := false.
+    pressed ifTrue:[
+	"
+	 leave with mouse-button down;
+	 stop autorepeating and/or if I am a button with
+	 action on release, show passive
+	"
+	autoRepeat ifTrue:[
+	    Processor removeTimedBlock:repeatBlock
+	].
+	isTriggerOnDown ifFalse:[
+	    view showPassive.
 	]
-    ].
-    view keyPress:key x:x y:y
+    ] ifFalse:[
+	enableChannel value ifTrue:[
+	    view redraw
+	]
+    ]
 !
 
 repeat
@@ -527,14 +532,6 @@
 	    ]
 	]
     ]
-!
-
-enableStateChange
-    "this is sent, whenever the enable value has changed"
-
-    view notNil ifTrue:[view enableStateChangeRedraw]
-
-    "Modified: 17.9.1995 / 19:55:52 / claus"
 ! !
 
 !ButtonController methodsFor:'initialization'!
@@ -553,3 +550,4 @@
     isTriggerOnDown := false.
     isToggle := false.
 ! !
+