--- a/ButtonController.st Sun Apr 30 15:40:03 1995 +0200
+++ b/ButtonController.st Wed May 03 02:30:14 1995 +0200
@@ -11,9 +11,9 @@
"
Controller subclass:#ButtonController
- instanceVariableNames:'enabled pressed active entered triggerOnDown autoRepeat
+ instanceVariableNames:'enabled pressed active entered isTriggerOnDown autoRepeat
repeatBlock initialDelay repeatDelay
- pressActionBlock releaseActionBlock'
+ pressActionBlock releaseActionBlock isToggle'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
@@ -37,7 +37,7 @@
version
"
-$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.5 1995-03-06 19:27:54 claus Exp $
+$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.6 1995-05-03 00:28:46 claus Exp $
"
!
@@ -52,7 +52,7 @@
enabled <Boolean> pressing is allowed (default: true)
pressed <Boolean> true if currently pressed (read-only)
entered <Boolean> true if the cursor is currently in this view
- triggerOnDown <Boolean> controls if the action should be executed on
+ isTriggerOnDown <Boolean> controls if the action should be executed on
press or on release (default: on release).
pressActionBlock <Block> block to evaluate when pressed (default: noop)
releaseActionBlock <Block> block to evaluate when released (default: noop)
@@ -92,21 +92,29 @@
autoRepeat := false.
initialDelay := self class defaultInitialDelay.
repeatDelay := self class defaultRepeatDelay.
- triggerOnDown := false.
+ isTriggerOnDown := false.
+ isToggle := false.
! !
!ButtonController methodsFor:'accessing'!
+beToggle
+ "make the receiver act like a toggle"
+
+ isTriggerOnDown := true.
+ isToggle := true
+!
+
beTriggerOnUp
"make the receiver act on button release"
- triggerOnDown := false
+ isTriggerOnDown := false
!
beTriggerOnDown
"make the receiver act on button press"
- triggerOnDown := true
+ isTriggerOnDown := true
!
triggerOnDown:aBoolean
@@ -114,14 +122,14 @@
on press or on release.
(see also ST-80 compatibility methods beTriggerOn*)"
- triggerOnDown := aBoolean
+ isTriggerOnDown := aBoolean
!
isTriggerOnDown
"return true, if I trigger on press
(in contrast to triggering on up, which is the default)"
- ^ triggerOnDown
+ ^ isTriggerOnDown
!
pressAction
@@ -155,7 +163,7 @@
either set the press-action clear any release-action or
vice versa, set the release-action and clear the press-action."
- triggerOnDown ifTrue:[
+ isTriggerOnDown ifTrue:[
releaseActionBlock := nil.
pressActionBlock := aBlock
] ifFalse:[
@@ -224,19 +232,58 @@
active:aBoolean
active := aBoolean
+!
+
+toggleNoAction
+ "toggle, but do NOT perform any action"
+
+ pressed ifTrue:[
+ view turnOff.
+ pressed := false.
+ ] ifFalse:[
+ view turnOn.
+ pressed := true.
+ ].
+!
+
+toggle
+ "toggle and perform the action"
+
+ enabled ifTrue:[
+ self toggleNoAction.
+ self performAction.
+ view sendChangeMessageWith:pressed.
+ view changed:#toggle with:pressed
+ ]
! !
!ButtonController methodsFor:'event handling'!
+performAction
+ |action|
+
+ pressed ifTrue:[
+ action := pressActionBlock
+ ] ifFalse:[
+ action := releaseActionBlock
+ ].
+ action notNil ifTrue:[action value].
+!
+
buttonPress:button x:x y:y
- |sym|
+ |sym action|
(button == 1 or:[button == #select]) ifFalse:[
^ super buttonPress:button x:x y:y
].
- pressed ifFalse:[
- enabled ifTrue:[
+ enabled ifTrue:[
+ isToggle ifTrue:[
+ self toggle.
+ ^ self
+ ].
+
+ pressed ifFalse:[
pressed := true.
view showActive.
@@ -250,11 +297,9 @@
active := true.
- pressActionBlock notNil ifTrue:[
- pressActionBlock value
- ].
+ self performAction.
- triggerOnDown ifTrue:[
+ isTriggerOnDown ifTrue:[
"the ST-80 way of doing things"
view notNil ifTrue:[
view sendChangeMessageWith:true
@@ -278,6 +323,11 @@
(button == 1 or:[button == #select]) ifFalse:[
^ super buttonRelease:button x:x y:y
].
+
+ isToggle ifTrue:[
+ ^ self
+ ].
+
pressed ifTrue:[
autoRepeat ifTrue:[
Processor removeTimedBlock:repeatBlock
@@ -303,10 +353,9 @@
active := true.
- releaseActionBlock notNil ifTrue:[
- releaseActionBlock value
- ].
- triggerOnDown ifFalse:[
+ self performAction.
+
+ isTriggerOnDown ifFalse:[
"the ST-80 way of doing things"
view notNil ifTrue:[
view sendChangeMessageWith:false.
@@ -327,13 +376,13 @@
"
reentered after a leave with mouse-button down;
restart autorepeating and/or if I am a button with
- triggerOnDown, show active again.
+ isTriggerOnDown, show active again.
"
enabled ifTrue:[
autoRepeat ifTrue:[
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
].
- triggerOnDown ifFalse:[
+ isTriggerOnDown ifFalse:[
view showActive.
]
]
@@ -399,7 +448,7 @@
autoRepeat ifTrue:[
Processor removeTimedBlock:repeatBlock
].
- triggerOnDown ifFalse:[
+ isTriggerOnDown ifFalse:[
view showPassive.
]
] ifFalse:[