1 Delta define: #ToggleButton as: (
\r
2 (Class subclassOf: 'PressHandler' instanceVariables: 'model <Boolean>
\r
3 modelSink <[Boolean]>
\r
7 pressedBorder <Border>
\r
8 unpressedBorder <Border>
\r
10 ') classVariables: 'FocusPainter <Painter>
\r
11 '; protocols: 'View[Boolean]') !
\r
13 (Delta mirrorFor: #ToggleButton) revision: '$Revision: 1.3 $'!
\r
15 (Delta mirrorFor: #ToggleButton) group: 'ui'!
\r
17 (Delta mirrorFor: #ToggleButton)
\r
19 'General non-native button.
\r
23 (c) 1995-1997 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
\r
24 Use and distribution of this software is subject to the terms of the attached source license
\r
27 ! (Delta mirrorFor: #ToggleButton) classSide methodsFor: 'instance creation' !
\r
30 withTrueLook: t <Visual>
\r
31 falseLook: f <Visual>
\r
34 ^self new trueLook: t falseLook: f initialLook: false!
\r
36 withTrueLook: t <Visual>
\r
37 falseLook: f <Visual>
\r
38 initialLook: b <Boolean>
\r
41 ^self new trueLook: t falseLook: f initialLook: b! !
\r
43 ! (Delta mirrorFor: #ToggleButton) methodsFor: 'accessing' !
\r
54 look: flag <Boolean>
\r
68 modelSink ^<[Boolean]>
\r
72 modelSink: b <[Boolean]>
\r
76 pressedBorder ^<Border>
\r
80 pressedBorder: b <Border>
\r
82 pressedBorder notNil
\r
83 ifTrue: [ self changing; updatePart ].
\r
90 trueLook: t <Visual> falseLook: f <Visual>
\r
95 self onPress: [ self look: self model not ];
\r
96 onAction: [ self toggle ];
\r
97 onCancel: [ self look: self model ].
\r
99 self look: self model.!
\r
101 trueLook: t <Visual> falseLook: f <Visual> initialLook: b <Boolean>
\r
105 self trueLook: t falseLook: f!
\r
107 unpressedBorder ^<Border>
\r
111 unpressedBorder: b <Border>
\r
113 unpressedBorder notNil
\r
114 ifTrue: [ self changing; updatePart ].
\r
115 unpressedBorder := b! !
\r
117 ! (Delta mirrorFor: #ToggleButton) methodsFor: 'initialize' !
\r
123 self modelSink: [ :f <Boolean> | ].
\r
125 self pressedBorder: (Border standard3DRaised: false);
\r
126 unpressedBorder: (Border standard3DRaised: true).! !
\r
128 ! (Delta mirrorFor: #ToggleButton) methodsFor: 'control' !
\r
133 self model: self model not.
\r
134 self modelSink value: self model.
\r
135 self updatePart.! !
\r
137 ! (Delta mirrorFor: #ToggleButton) methodsFor: 'private' !
\r
144 "We regain the focus if needed because some parents might move or reparent us
\r
145 during the action (like outliners)"
\r
146 (self isFocus not and: [ self isAttached and: [ self session activeWindow == self topWindow ] ])
\r
147 ifTrue: [ self becomeFocus ].!
\r
149 focusPainter ^<Painter>
\r
152 ifTrue: [ "We don't need a critical region because replacement won't hurt"
\r
153 FocusPainter := Painter new lineStyle: #dot ].
\r
165 isFocusCandidate ^<Boolean>
\r
171 self scrollIfNeededToMakeVisible: self allocation enclosingRect
\r
172 relativeTo: self minimizeMotion: true.
\r
176 skipCheckLayout ^<Boolean>
\r
182 | b <Border> f <Frame> look <Visual> |
\r
184 ifTrue: [ self frame removePart ]
\r
185 ifFalse: [ self frame: (Frame new) ].
\r
188 ifTrue: [ b := self pressedBorder ]
\r
189 ifFalse: [ b := self unpressedBorder ].
\r
192 ifTrue: [ self trueLook ]
\r
193 ifFalse: [ self falseLook ].
\r
199 ! (Delta mirrorFor: #ToggleButton) methodsFor: 'restricted-to session' !
\r
202 isFocus: f <Boolean>
\r
205 (f not and: [ self isGrabbing ])
\r
206 ifTrue: [ self releaseGrab ].
\r
207 self invalidate.! !
\r
209 ! (Delta mirrorFor: #ToggleButton) methodsFor: 'displaying' !
\r
212 localDisplayOn: can <Canvas>
\r
214 super localDisplayOn: can.
\r
216 (self isFocus and: [ self blinkState and: [ self pressing not ] ])
\r
217 ifTrue: [ can withPainter: self focusPainter
\r
218 do: [ can displayRectangle:
\r
219 ((self frame part allocationRelativeTo: self) enclosingRect
\r
220 expandBy: 1) ] ].! !
\r
222 ! (Delta mirrorFor: #ToggleButton) methodsFor: 'event processing' !
\r
225 keyDown: key <Symbol> focus: focus <Visual> event: ev <UIEvent> ^<Boolean>
\r
228 ifFalse: [ ^false ].
\r
231 ifTrue: [ self press.
\r
234 ifTrue: [ self action.
\r
236 (key = #TAB and: [ self pressing ])
\r
237 ifTrue: [ self cancel.
\r
242 keyUp: key <Symbol> focus: focus <Visual> event: ev <UIEvent> ^<Boolean>
\r
245 ifFalse: [ ^false ].
\r
247 ^(key = #RETURN and: [ self pressing ])
\r
248 onTrue: [ self action ]! !
\r