--- a/ButtonController.st Wed May 03 18:30:51 1995 +0200
+++ b/ButtonController.st Sat May 06 16:18:13 1995 +0200
@@ -10,10 +10,12 @@
hereby transferred.
"
+'From Smalltalk/X, Version:2.10.5 on 4-may-1995 at 6:17:35 am'!
+
Controller subclass:#ButtonController
instanceVariableNames:'enabled pressed active entered isTriggerOnDown autoRepeat
- repeatBlock initialDelay repeatDelay
- pressActionBlock releaseActionBlock isToggle'
+ repeatBlock initialDelay repeatDelay pressActionBlock
+ releaseActionBlock isToggle'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
@@ -37,7 +39,7 @@
version
"
-$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.6 1995-05-03 00:28:46 claus Exp $
+$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.7 1995-05-06 14:16:24 claus Exp $
"
!
@@ -80,35 +82,31 @@
^ 0.2
! !
-!ButtonController methodsFor:'initialization'!
-
-initialize
- super initialize.
-
- enabled := true.
- active := false.
- pressed := false.
- entered := false.
- autoRepeat := false.
- initialDelay := self class defaultInitialDelay.
- repeatDelay := self class defaultRepeatDelay.
- isTriggerOnDown := false.
- isToggle := false.
-! !
-
!ButtonController methodsFor:'accessing'!
-beToggle
- "make the receiver act like a toggle"
+pressed
+ "return true, if I am pressed"
- isTriggerOnDown := true.
- isToggle := true
+ ^ pressed
!
-beTriggerOnUp
- "make the receiver act on button release"
+active
+ "return true, if I am active; that is currently performing my
+ action."
+
+ ^ active
+!
- isTriggerOnDown := false
+enabled
+ "return true, if I am enabled"
+
+ ^ enabled
+!
+
+entered
+ "return true, if the mouse pointer is currently in my view"
+
+ ^ entered
!
beTriggerOnDown
@@ -117,12 +115,8 @@
isTriggerOnDown := 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
+active:aBoolean
+ active := aBoolean
!
isTriggerOnDown
@@ -132,30 +126,8 @@
^ 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
-!
-
-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
+pressed:aBoolean
+ pressed := aBoolean
!
action:aBlock
@@ -172,6 +144,25 @@
]
!
+beToggle
+ "make the receiver act like a toggle"
+
+ isTriggerOnDown := true.
+ isToggle := true
+!
+
+pressAction:aBlock
+ "define the action to be performed on press"
+
+ pressActionBlock := aBlock
+!
+
+releaseAction:aBlock
+ "define the action to be performed on release"
+
+ releaseActionBlock := aBlock
+!
+
autoRepeat
"turn on autorepeat"
@@ -179,13 +170,14 @@
repeatBlock := [self repeat]
!
-disable
- "disable the button"
+entered:aBoolean
+ entered := aBoolean
+!
- enabled ifTrue:[
- enabled := false.
- view redraw
- ]
+beTriggerOnUp
+ "make the receiver act on button release"
+
+ isTriggerOnDown := false
!
enable
@@ -197,43 +189,6 @@
]
!
-enabled
- "return true, if I am enabled"
-
- ^ enabled
-!
-
-active
- "return true, if I am active; that is currently performing my
- action."
-
- ^ active
-!
-
-pressed
- "return true, if I am pressed"
-
- ^ pressed
-!
-
-entered
- "return true, if the mouse pointer is currently in my view"
-
- ^ entered
-!
-
-entered:aBoolean
- entered := aBoolean
-!
-
-pressed:aBoolean
- pressed := aBoolean
-!
-
-active:aBoolean
- active := aBoolean
-!
-
toggleNoAction
"toggle, but do NOT perform any action"
@@ -246,72 +201,84 @@
].
!
+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
+!
+
toggle
"toggle and perform the action"
enabled ifTrue:[
- self toggleNoAction.
- self performAction.
- view sendChangeMessageWith:pressed.
- view changed:#toggle with:pressed
+ 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
+!
+
+releaseAction
+ "return the releaseAction; thats the block which gets evaluated
+ when the button is relreased (if non-nil)"
+
+ ^ releaseActionBlock
+!
+
+disable
+ "disable the button"
+
+ enabled ifTrue:[
+ enabled := false.
+ view redraw
]
! !
!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 action|
(button == 1 or:[button == #select]) ifFalse:[
- ^ super buttonPress:button x:x y:y
+ ^ super buttonPress:button x:x y:y
].
enabled ifTrue:[
- isToggle ifTrue:[
- self toggle.
- ^ self
- ].
+ isToggle ifTrue:[
+ self toggle.
+ ^ self
+ ].
- 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 device synchronizeOutput.
- ].
+ pressed ifFalse:[
+ pressed := true.
+ view showActive.
- active := true.
-
- self performAction.
+ (pressActionBlock notNil or:[model notNil]) ifTrue:[
+ "
+ force output - so that button is drawn correctly in case
+ of any long-computation (at high priority)
+ "
+ view device synchronizeOutput.
+ ].
- isTriggerOnDown ifTrue:[
- "the ST-80 way of doing things"
- view notNil ifTrue:[
- view sendChangeMessageWith:true
- ]
- ].
+ active := true.
+
+ self performAction.
- active := false.
+ active := false.
- autoRepeat ifTrue:[
- Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
- ]
- ]
+ autoRepeat ifTrue:[
+ Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
+ ]
+ ]
]
!
@@ -321,50 +288,43 @@
|sym|
(button == 1 or:[button == #select]) ifFalse:[
- ^ super buttonRelease:button x:x y:y
+ ^ super buttonRelease:button x:x y:y
].
isToggle ifTrue:[
- ^ self
+ ^ self
].
pressed ifTrue:[
- autoRepeat ifTrue:[
- Processor removeTimedBlock:repeatBlock
- ].
- pressed := false.
- view showPassive.
+ autoRepeat ifTrue:[
+ Processor removeTimedBlock:repeatBlock
+ ].
+ pressed := false.
+ view showPassive.
- enabled 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 device synchronizeOutput.
- ].
+ enabled 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 device synchronizeOutput.
+ ].
- active := true.
+ active := true.
- self performAction.
+ self performAction.
- isTriggerOnDown ifFalse:[
- "the ST-80 way of doing things"
- view notNil ifTrue:[
- view sendChangeMessageWith:false.
- ].
- ].
-
- active := false.
- ]
- ]
+ active := false.
+ ]
+ ]
]
!
@@ -393,25 +353,47 @@
]
!
-repeat
- "this is sent from the autorepeat-block, when the button has been pressed long
- enough; it simulates a release-press, by evaluating both release
- and press actions."
+pointerLeave:state
+ "redraw with normal colors if they differ from enteredColors"
+
+ 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.
+ ]
+ ] ifFalse:[
+ enabled ifTrue:[
+ view redraw
+ ]
+ ]
+!
+
+performAction
+ |action|
pressed ifTrue:[
- enabled ifTrue:[
- active ifFalse:[
- active := true.
- releaseActionBlock notNil ifTrue:[releaseActionBlock value].
- pressActionBlock notNil ifTrue:[pressActionBlock value].
- active := false.
+ action := pressActionBlock
+ ] ifFalse:[
+ action := releaseActionBlock
+ ].
+ action notNil ifTrue:[action value].
- autoRepeat ifTrue:[
- Processor addTimedBlock:repeatBlock afterSeconds:repeatDelay
- ]
- ]
- ]
- ]
+ (isToggle
+ or:[(isTriggerOnDown and:[pressed])
+ or:[isTriggerOnDown not and:[pressed not]]]) ifTrue:[
+ "the ST-80 way of doing things"
+ view notNil ifTrue:[
+ view sendChangeMessageWith:pressed.
+ ].
+ ].
!
buttonMultiPress:button x:x y:y
@@ -435,25 +417,40 @@
view keyPress:key x:x y:y
!
-pointerLeave:state
- "redraw with normal colors if they differ from enteredColors"
+repeat
+ "this is sent from the autorepeat-block, when the button has been pressed long
+ enough; it simulates a release-press, by evaluating both release
+ and press actions."
- 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.
- ]
- ] ifFalse:[
enabled ifTrue:[
- view redraw
+ active ifFalse:[
+ active := true.
+ releaseActionBlock notNil ifTrue:[releaseActionBlock value].
+ pressActionBlock notNil ifTrue:[pressActionBlock value].
+ active := false.
+
+ autoRepeat ifTrue:[
+ Processor addTimedBlock:repeatBlock afterSeconds:repeatDelay
+ ]
+ ]
]
]
! !
+
+!ButtonController methodsFor:'initialization'!
+
+initialize
+ super initialize.
+
+ enabled := true.
+ active := false.
+ pressed := false.
+ entered := false.
+ autoRepeat := false.
+ initialDelay := self class defaultInitialDelay.
+ repeatDelay := self class defaultRepeatDelay.
+ isTriggerOnDown := false.
+ isToggle := false.
+! !
+