--- a/ButtonController.st Mon Jul 03 04:34:22 1995 +0200
+++ b/ButtonController.st Sun Jul 23 05:03:13 1995 +0200
@@ -13,7 +13,7 @@
'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
+ instanceVariableNames:'enableChannel pressed active entered isTriggerOnDown autoRepeat
repeatBlock initialDelay repeatDelay pressActionBlock
releaseActionBlock isToggle'
classVariableNames:''
@@ -39,7 +39,7 @@
version
"
-$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.12 1995-07-03 02:32:19 claus Exp $
+$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.13 1995-07-23 03:01:00 claus Exp $
"
!
@@ -48,13 +48,16 @@
ButtonControllers are used with buttons and handle all user interaction.
These are automatically created when a Button is created, therefore no manual
action is required for creation.
- In normal applications, you dont have to care for the controller; access to the
- controllers behavior is also possible via messages to the button.
+ In normal applications, you dont have to care for the controller;
+ access to the controllers behavior is possible via messages to the button.
(setting actions, controlling autorepeat etc.)
+ See examples in the Button class.
+
Instance variables:
- enabled <Boolean> pressing is allowed (default: true)
+ enableChannel <ValueHolder pressing is allowed (default: true)
+ on Boolean>
pressed <Boolean> true if currently pressed (read-only)
@@ -117,7 +120,7 @@
enabled
"return true, if I am enabled"
- ^ enabled
+ ^ enableChannel value
!
entered
@@ -222,7 +225,7 @@
toggle
"toggle and perform the action"
- enabled ifTrue:[
+ enableChannel value ifTrue:[
self toggleNoAction.
self performAction.
view changed:#toggle with:pressed
@@ -246,17 +249,37 @@
enable
"enable the button"
- enabled ifFalse:[
- enabled := true.
- view redraw
+ enableChannel value ifFalse:[
+ enableChannel value:true.
+ "/ view redraw - not needed; button listenes to enableChannel
]
!
disable
"disable the button"
- enabled ifTrue:[
- enabled := false.
+ enableChannel value ifTrue:[
+ enableChannel value:false.
+ "/ view redraw - not needed; button listenes to enableChannel
+ ]
+!
+
+enableChannel
+ "return the valueHolder which holdes the enable
+ boolean value"
+
+ ^ enableChannel
+!
+
+enableChannel:aValueHolder
+ "set the valueHolder, which holds the enable boolean value"
+
+ enableChannel notNil ifTrue:[
+ enableChannel retractInterrestFor:self.
+ ].
+ enableChannel := aValueHolder.
+ aValueHolder onChangeSend:#enableStateChange to:self.
+ view notNil ifTrue:[
view redraw
]
! !
@@ -268,7 +291,7 @@
^ super buttonPress:button x:x y:y
].
- enabled ifTrue:[
+ enableChannel value ifTrue:[
isToggle ifTrue:[
self toggle.
^ self
@@ -313,7 +336,7 @@
pressed := false.
view showPassive.
- enabled ifTrue:[
+ enableChannel value ifTrue:[
"
only perform action if released within myself
"
@@ -340,7 +363,7 @@
Redraw with enteredColors if they differ from the normal colors"
entered := true.
- enabled ifTrue:[
+ enableChannel value ifTrue:[
pressed ifTrue:[
"
reentered after a leave with mouse-button down;
@@ -377,14 +400,20 @@
view showPassive.
]
] ifFalse:[
- enabled ifTrue:[
+ enableChannel value ifTrue:[
view redraw
]
]
!
performAction
- |action|
+ |action value|
+
+ isToggle ifTrue:[
+ value := pressed
+ ] ifFalse:[
+ value := true
+ ].
"
ST/X style actionBlock evaluation ...
@@ -399,7 +428,7 @@
action numArgs == 0 ifTrue:[
action value
] ifFalse:[
- action value:pressed
+ action value:value
].
active := false.
].
@@ -413,7 +442,7 @@
"the ST-80 way of doing things"
view notNil ifTrue:[
active := true.
- view sendChangeMessageWith:pressed.
+ view sendChangeMessageWith:value.
active := false.
].
].
@@ -444,7 +473,7 @@
and press actions."
pressed ifTrue:[
- enabled ifTrue:[
+ enableChannel value ifTrue:[
active ifFalse:[
active := true.
releaseActionBlock notNil ifTrue:[releaseActionBlock value].
@@ -457,6 +486,12 @@
]
]
]
+!
+
+enableStateChange
+ "this is sent, whenever the enable value has changed"
+
+ view redraw
! !
!ButtonController methodsFor:'initialization'!
@@ -464,7 +499,8 @@
initialize
super initialize.
- enabled := true.
+ self enableChannel:(true asValue).
+
active := false.
pressed := false.
entered := false.
@@ -474,4 +510,3 @@
isTriggerOnDown := false.
isToggle := false.
! !
-