radioButton(group) fixes
authorClaus Gittinger <cg@exept.de>
Tue, 14 Nov 1995 22:44:34 +0100
changeset 177 c06d27f8525f
parent 176 902cc24473af
child 178 5c28593c2a3b
radioButton(group) fixes
Button.st
ButtonC.st
ButtonController.st
RButtGrp.st
RadioButtonGroup.st
Toggle.st
--- a/Button.st	Tue Nov 14 21:29:41 1995 +0100
+++ b/Button.st	Tue Nov 14 22:44:34 1995 +0100
@@ -52,7 +52,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Button.st,v 1.34 1995-11-11 16:19:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Button.st,v 1.35 1995-11-14 21:44:19 cg Exp $'
 !
 
 documentation
@@ -1428,6 +1428,27 @@
 
 !Button methodsFor:'changing state'!
 
+turnOffNoAction
+    "turn the button off (if not already off)"
+
+    controller pressed ifTrue:[
+	offLevel ~~ level ifTrue:[
+	    self level:offLevel.
+	].
+	(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
+	    self logo:passiveLogo
+	].
+	controller setPressed:false.
+	controller active:false.
+	level := offLevel.
+	margin := level abs.
+	self redraw
+    ]
+
+    "Created: 14.11.1995 / 22:00:09 / cg"
+    "Modified: 14.11.1995 / 22:00:37 / cg"
+!
+
 turnOffWithoutRedraw
     "turn the button off - no redraw"
 
@@ -1456,6 +1477,27 @@
     ]
 !
 
+turnOnNoAction
+    "turn the button on (if not already on)"
+
+    controller pressed ifFalse:[
+	onLevel ~~ level ifTrue:[
+	    self level:onLevel.
+	].
+	(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
+	    self logo:activeLogo
+	].
+	controller setPressed:true.
+	level := onLevel.
+	margin := level abs.
+
+	self redraw
+    ]
+
+    "Created: 14.11.1995 / 22:00:45 / cg"
+    "Modified: 14.11.1995 / 22:01:02 / cg"
+!
+
 turnOnWithoutRedraw
     "turn the button on - no redraw"
 
--- a/ButtonC.st	Tue Nov 14 21:29:41 1995 +0100
+++ b/ButtonC.st	Tue Nov 14 22:44:34 1995 +0100
@@ -39,7 +39,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Attic/ButtonC.st,v 1.20 1995-11-11 16:19:14 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Attic/ButtonC.st,v 1.21 1995-11-14 21:44:27 cg Exp $'
 !
 
 documentation
@@ -136,8 +136,17 @@
     active := aBoolean
 !
 
+setPressed:aBoolean
+    pressed := aBoolean.
+
+    "Created: 14.11.1995 / 21:37:08 / cg"
+!
+
 pressed:aBoolean
-    pressed := aBoolean
+    pressed ~~ aBoolean ifTrue:[
+	pressed := aBoolean.
+	self performAction.
+    ].
 ! !
 
 !ButtonController methodsFor:'accessing-channels'!
--- a/ButtonController.st	Tue Nov 14 21:29:41 1995 +0100
+++ b/ButtonController.st	Tue Nov 14 22:44:34 1995 +0100
@@ -39,7 +39,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.20 1995-11-11 16:19:14 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.21 1995-11-14 21:44:27 cg Exp $'
 !
 
 documentation
@@ -136,8 +136,17 @@
     active := aBoolean
 !
 
+setPressed:aBoolean
+    pressed := aBoolean.
+
+    "Created: 14.11.1995 / 21:37:08 / cg"
+!
+
 pressed:aBoolean
-    pressed := aBoolean
+    pressed ~~ aBoolean ifTrue:[
+	pressed := aBoolean.
+	self performAction.
+    ].
 ! !
 
 !ButtonController methodsFor:'accessing-channels'!
--- a/RButtGrp.st	Tue Nov 14 21:29:41 1995 +0100
+++ b/RButtGrp.st	Tue Nov 14 22:44:34 1995 +0100
@@ -36,7 +36,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Attic/RButtGrp.st,v 1.16 1995-11-11 16:22:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Attic/RButtGrp.st,v 1.17 1995-11-14 21:44:31 cg Exp $'
 !
 
 documentation
@@ -88,6 +88,7 @@
 	top extent:(panel preferredExtent).
 	top open.
 
+
     example (using RadioButtons for 'one-on behavior'):
 
 	|top panel toggle b g|
@@ -104,6 +105,25 @@
 	top extent:(panel preferredExtent).
 	top open.
 
+
+    example (using Buttons for 'none-on behavior'; but the groups value remembers the last button):
+
+	|top panel toggle b g|
+
+	top := StandardSystemView new.
+	panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
+	g := RadioButtonGroup new.
+	b := Button label:'one' in:panel.
+	g add:b.
+	b := Button label:'two' in:panel.
+	g add:b.
+	b := Button label:'three' in:panel.
+	g add:b.
+	top extent:(panel preferredExtent).
+	top open.
+	g valueChannel inspect
+
+
     example (same, with button 'two' initially on):
 
 	|top panel toggle b g|
@@ -127,6 +147,7 @@
 
 	top := StandardSystemView new.
 	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
+	panel horizontalLayout:#left.
 	g := RadioButtonGroup new.
 	b := CheckBox label:'one' in:panel.
 	g add:b.
@@ -208,30 +229,33 @@
 	valueChannel := 0 asValue
     ].
     aRadioButton isOn ifTrue:[valueChannel value:self size].
-    aRadioButton model:self; aspectMessage:nil; changeMessage:#elementChanged:from:.
+    aRadioButton model:self; aspectMessage:#queryFrom:; changeMessage:#elementChanged:from:.
 
 ! !
 
 !RadioButtonGroup methodsFor:'update'!
 
 update:something with:someArgument from:changedButton
-    "/ no - it could be a subcomponent
-"/    (self includes:changedButton) ifFalse:[^ self].
-
     "
      a RadioButton in this group has changed - notify the others
     "
 
-"/    "in case we have a toggle in the group, 
-"/     and it has been turned off - turn it on again
-"/    "
-"/    changedButton isOn ifFalse:[
-"/        changedButton toggleNoAction.
-"/        ^ self
-"/    ].
     self elementChanged:(changedButton isOn) from:changedButton
 !
 
+queryFrom:aToggle
+    "a query from a toggle, if its the selected one"
+
+    self keysAndValuesDo:[:index :aComponent |
+       ((aToggle == aComponent) or:[aToggle isSubViewOf:aComponent]) ifTrue:[
+	    ^ valueChannel value == index
+       ]
+    ].
+    ^ false
+
+    "Modified: 14.11.1995 / 21:21:27 / cg"
+!
+
 elementChanged:aToggle
     "historic compatibility leftover - will vanish"
 
@@ -244,17 +268,18 @@
 
     |newValue|
 
-    self keysAndValuesDo:[:index :aButton |
-	(aToggle isSubViewOf:aButton) ifFalse:[
-	    aButton isOn ifTrue:[
-		aButton turnOff
-	    ]
-	] ifTrue:[
+    self keysAndValuesDo:[:index :aComponent |
+       ((aToggle == aComponent) or:[aToggle isSubViewOf:aComponent]) ifTrue:[
 	    value ifTrue:[newValue := index]   
+	] ifFalse:[
+"/            aComponent isOn ifTrue:[
+"/               aComponent turnOff
+"/            ]
 	]
     ].
-    aToggle turnOn.
-    valueChannel value:newValue
+"/    aToggle turnOn.
+    valueChannel value:newValue.
+    self changed:#queryFrom:
 
     "Modified: 21.9.1995 / 13:42:06 / claus"
 ! !
--- a/RadioButtonGroup.st	Tue Nov 14 21:29:41 1995 +0100
+++ b/RadioButtonGroup.st	Tue Nov 14 22:44:34 1995 +0100
@@ -36,7 +36,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.16 1995-11-11 16:22:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.17 1995-11-14 21:44:31 cg Exp $'
 !
 
 documentation
@@ -88,6 +88,7 @@
 	top extent:(panel preferredExtent).
 	top open.
 
+
     example (using RadioButtons for 'one-on behavior'):
 
 	|top panel toggle b g|
@@ -104,6 +105,25 @@
 	top extent:(panel preferredExtent).
 	top open.
 
+
+    example (using Buttons for 'none-on behavior'; but the groups value remembers the last button):
+
+	|top panel toggle b g|
+
+	top := StandardSystemView new.
+	panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
+	g := RadioButtonGroup new.
+	b := Button label:'one' in:panel.
+	g add:b.
+	b := Button label:'two' in:panel.
+	g add:b.
+	b := Button label:'three' in:panel.
+	g add:b.
+	top extent:(panel preferredExtent).
+	top open.
+	g valueChannel inspect
+
+
     example (same, with button 'two' initially on):
 
 	|top panel toggle b g|
@@ -127,6 +147,7 @@
 
 	top := StandardSystemView new.
 	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
+	panel horizontalLayout:#left.
 	g := RadioButtonGroup new.
 	b := CheckBox label:'one' in:panel.
 	g add:b.
@@ -208,30 +229,33 @@
 	valueChannel := 0 asValue
     ].
     aRadioButton isOn ifTrue:[valueChannel value:self size].
-    aRadioButton model:self; aspectMessage:nil; changeMessage:#elementChanged:from:.
+    aRadioButton model:self; aspectMessage:#queryFrom:; changeMessage:#elementChanged:from:.
 
 ! !
 
 !RadioButtonGroup methodsFor:'update'!
 
 update:something with:someArgument from:changedButton
-    "/ no - it could be a subcomponent
-"/    (self includes:changedButton) ifFalse:[^ self].
-
     "
      a RadioButton in this group has changed - notify the others
     "
 
-"/    "in case we have a toggle in the group, 
-"/     and it has been turned off - turn it on again
-"/    "
-"/    changedButton isOn ifFalse:[
-"/        changedButton toggleNoAction.
-"/        ^ self
-"/    ].
     self elementChanged:(changedButton isOn) from:changedButton
 !
 
+queryFrom:aToggle
+    "a query from a toggle, if its the selected one"
+
+    self keysAndValuesDo:[:index :aComponent |
+       ((aToggle == aComponent) or:[aToggle isSubViewOf:aComponent]) ifTrue:[
+	    ^ valueChannel value == index
+       ]
+    ].
+    ^ false
+
+    "Modified: 14.11.1995 / 21:21:27 / cg"
+!
+
 elementChanged:aToggle
     "historic compatibility leftover - will vanish"
 
@@ -244,17 +268,18 @@
 
     |newValue|
 
-    self keysAndValuesDo:[:index :aButton |
-	(aToggle isSubViewOf:aButton) ifFalse:[
-	    aButton isOn ifTrue:[
-		aButton turnOff
-	    ]
-	] ifTrue:[
+    self keysAndValuesDo:[:index :aComponent |
+       ((aToggle == aComponent) or:[aToggle isSubViewOf:aComponent]) ifTrue:[
 	    value ifTrue:[newValue := index]   
+	] ifFalse:[
+"/            aComponent isOn ifTrue:[
+"/               aComponent turnOff
+"/            ]
 	]
     ].
-    aToggle turnOn.
-    valueChannel value:newValue
+"/    aToggle turnOn.
+    valueChannel value:newValue.
+    self changed:#queryFrom:
 
     "Modified: 21.9.1995 / 13:42:06 / claus"
 ! !
--- a/Toggle.st	Tue Nov 14 21:29:41 1995 +0100
+++ b/Toggle.st	Tue Nov 14 22:44:34 1995 +0100
@@ -36,7 +36,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Toggle.st,v 1.20 1995-11-14 20:29:41 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Toggle.st,v 1.21 1995-11-14 21:44:34 cg Exp $'
 !
 
 documentation
@@ -391,9 +391,9 @@
 	    val := model perform:aspectMsg with:self
 	].
 	val ifTrue:[
-	    self turnOn
+	    self turnOnNoAction
 	] ifFalse:[
-	    self turnOff
+	    self turnOffNoAction
 	].
     ].