ButtonController.st
changeset 266 8b8e9c60fa1d
parent 262 d2c946b6a5b4
child 347 9ba2cb5c2ec7
equal deleted inserted replaced
265:76336839475b 266:8b8e9c60fa1d
   193     "define the action to be performed on release"
   193     "define the action to be performed on release"
   194 
   194 
   195     releaseActionBlock := aBlock
   195     releaseActionBlock := aBlock
   196 !
   196 !
   197 
   197 
       
   198 triggerOnDown:aBoolean
       
   199     "set/clear the flag which controls if the action block is to be evaluated
       
   200      on press or on release. 
       
   201      (see also ST-80 compatibility methods beTriggerOn*)"
       
   202 
       
   203     isTriggerOnDown := aBoolean
       
   204 ! !
       
   205 
       
   206 !ButtonController methodsFor:'accessing-channels'!
       
   207 
       
   208 enableChannel
       
   209     "return the valueHolder which holdes the enable
       
   210      boolean value"
       
   211 
       
   212     ^ enableChannel
       
   213 !
       
   214 
       
   215 enableChannel:aValueHolder
       
   216     "set the valueHolder, which holds the enable boolean value"
       
   217 
       
   218     |wasEnabled|
       
   219 
       
   220     enableChannel notNil ifTrue:[
       
   221 	wasEnabled := enableChannel value.
       
   222 	enableChannel retractInterestsFor:self. 
       
   223     ] ifFalse:[
       
   224 	wasEnabled := true
       
   225     ].
       
   226     enableChannel := aValueHolder.
       
   227     aValueHolder onChangeSend:#enableStateChange to:self.
       
   228     enableChannel value ~~ wasEnabled ifTrue:[
       
   229 	self enableStateChange
       
   230     ]
       
   231 
       
   232     "Modified: 17.9.1995 / 19:41:18 / claus"
       
   233 !
       
   234 
       
   235 pressChannel:aChannel
       
   236     pressChannel := aChannel
       
   237 !
       
   238 
       
   239 releaseChannel:aChannel
       
   240     releaseChannel := aChannel
       
   241 ! !
       
   242 
       
   243 !ButtonController methodsFor:'accessing-state'!
       
   244 
       
   245 active
       
   246     "return true, if I am active; 
       
   247      that is: currently performing my action.
       
   248      This query can be used to avoid multiple redraws."
       
   249 
       
   250     ^ active
       
   251 !
       
   252 
       
   253 active:aBoolean
       
   254     active := aBoolean
       
   255 !
       
   256 
       
   257 enabled
       
   258     "return true, if I am enabled"
       
   259 
       
   260     ^ enableChannel value
       
   261 !
       
   262 
       
   263 entered
       
   264     "return true, if the mouse pointer is currently in my view"
       
   265 
       
   266     ^ entered
       
   267 !
       
   268 
       
   269 entered:aBoolean
       
   270     entered := aBoolean
       
   271 !
       
   272 
       
   273 pressed
       
   274     "return true, if I am pressed"
       
   275 
       
   276     ^ pressed
       
   277 !
       
   278 
       
   279 pressed:aBoolean
       
   280     pressed ~~ aBoolean ifTrue:[
       
   281 	pressed := aBoolean.
       
   282 	self performAction.
       
   283     ].
       
   284 !
       
   285 
       
   286 setPressed:aBoolean
       
   287     pressed := aBoolean.
       
   288 
       
   289     "Created: 14.11.1995 / 21:37:08 / cg"
       
   290 !
       
   291 
   198 toggle
   292 toggle
   199     "toggle and perform the action"
   293     "toggle and perform the action"
   200 
   294 
   201     enableChannel value ifTrue:[
   295     enableChannel value ifTrue:[
   202 	self toggleNoAction.
   296 	self toggleNoAction.
   213 	pressed := false.
   307 	pressed := false.
   214     ] ifFalse:[
   308     ] ifFalse:[
   215 	view turnOn.
   309 	view turnOn.
   216 	pressed := true.
   310 	pressed := true.
   217     ].
   311     ].
   218 !
       
   219 
       
   220 triggerOnDown:aBoolean
       
   221     "set/clear the flag which controls if the action block is to be evaluated
       
   222      on press or on release. 
       
   223      (see also ST-80 compatibility methods beTriggerOn*)"
       
   224 
       
   225     isTriggerOnDown := aBoolean
       
   226 ! !
       
   227 
       
   228 !ButtonController methodsFor:'accessing-channels'!
       
   229 
       
   230 enableChannel
       
   231     "return the valueHolder which holdes the enable
       
   232      boolean value"
       
   233 
       
   234     ^ enableChannel
       
   235 !
       
   236 
       
   237 enableChannel:aValueHolder
       
   238     "set the valueHolder, which holds the enable boolean value"
       
   239 
       
   240     |wasEnabled|
       
   241 
       
   242     enableChannel notNil ifTrue:[
       
   243 	wasEnabled := enableChannel value.
       
   244 	enableChannel retractInterestsFor:self. 
       
   245     ] ifFalse:[
       
   246 	wasEnabled := true
       
   247     ].
       
   248     enableChannel := aValueHolder.
       
   249     aValueHolder onChangeSend:#enableStateChange to:self.
       
   250     enableChannel value ~~ wasEnabled ifTrue:[
       
   251 	self enableStateChange
       
   252     ]
       
   253 
       
   254     "Modified: 17.9.1995 / 19:41:18 / claus"
       
   255 !
       
   256 
       
   257 pressChannel:aChannel
       
   258     pressChannel := aChannel
       
   259 !
       
   260 
       
   261 releaseChannel:aChannel
       
   262     releaseChannel := aChannel
       
   263 ! !
       
   264 
       
   265 !ButtonController methodsFor:'accessing-state'!
       
   266 
       
   267 active
       
   268     "return true, if I am active; 
       
   269      that is: currently performing my action.
       
   270      This query can be used to avoid multiple redraws."
       
   271 
       
   272     ^ active
       
   273 !
       
   274 
       
   275 active:aBoolean
       
   276     active := aBoolean
       
   277 !
       
   278 
       
   279 enabled
       
   280     "return true, if I am enabled"
       
   281 
       
   282     ^ enableChannel value
       
   283 !
       
   284 
       
   285 entered
       
   286     "return true, if the mouse pointer is currently in my view"
       
   287 
       
   288     ^ entered
       
   289 !
       
   290 
       
   291 entered:aBoolean
       
   292     entered := aBoolean
       
   293 !
       
   294 
       
   295 pressed
       
   296     "return true, if I am pressed"
       
   297 
       
   298     ^ pressed
       
   299 !
       
   300 
       
   301 pressed:aBoolean
       
   302     pressed ~~ aBoolean ifTrue:[
       
   303 	pressed := aBoolean.
       
   304 	self performAction.
       
   305     ].
       
   306 !
       
   307 
       
   308 setPressed:aBoolean
       
   309     pressed := aBoolean.
       
   310 
       
   311     "Created: 14.11.1995 / 21:37:08 / cg"
       
   312 ! !
   312 ! !
   313 
   313 
   314 !ButtonController methodsFor:'event handling'!
   314 !ButtonController methodsFor:'event handling'!
   315 
   315 
   316 buttonMultiPress:button x:x y:y
   316 buttonMultiPress:button x:x y:y
   317     ^ self buttonPress:button x:x y:y
   317     ^ self buttonPress:button x:x y:y
   318 !
   318 !
   319 
   319 
   320 buttonPress:button x:x y:y
   320 buttonPress:button x:x y:y
   321     (button == 1 or:[button == #select]) ifFalse:[
   321     (button == 1 or:[button == #select]) ifFalse:[
   322         ^ super buttonPress:button x:x y:y
   322 	^ super buttonPress:button x:x y:y
   323     ].
   323     ].
   324 
   324 
   325     enableChannel value ifTrue:[
   325     enableChannel value ifTrue:[
   326         isToggle ifTrue:[
   326 	isToggle ifTrue:[
   327             self toggle.
   327 	    self toggle.
   328             ^ self
   328 	    ^ self
   329         ].
   329 	].
   330 
   330 
   331         pressed ifFalse:[
   331 	pressed ifFalse:[
   332             pressed := true.
   332 	    pressed := true.
   333             view showActive.
   333 	    view showActive.
   334 
   334 
   335             (pressActionBlock notNil or:[model notNil]) ifTrue:[
   335 	    (pressActionBlock notNil or:[model notNil]) ifTrue:[
   336                 "
   336 		"
   337                  force output - so that button is drawn correctly in case
   337 		 force output - so that button is drawn correctly in case
   338                  of any long-computation (at high priority)
   338 		 of any long-computation (at high priority)
   339                 "
   339 		"
   340                 view flush.
   340 		view flush.
   341             ].
   341 	    ].
   342 
   342 
   343             self performAction.
   343 	    self performAction.
   344 
   344 
   345             autoRepeat ifTrue:[
   345 	    autoRepeat ifTrue:[
   346                 Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
   346 		Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
   347             ]
   347 	    ]
   348         ]
   348 	]
   349     ]
   349     ]
   350 
   350 
   351     "Modified: 16.12.1995 / 17:31:55 / cg"
   351     "Modified: 16.12.1995 / 17:31:55 / cg"
   352 !
   352 !
   353 
   353 
   354 buttonRelease:button x:x y:y
   354 buttonRelease:button x:x y:y
   355     "button was released - if enabled, perform releaseaction"
   355     "button was released - if enabled, perform releaseaction"
   356 
   356 
   357     (button == 1 or:[button == #select]) ifFalse:[
   357     (button == 1 or:[button == #select]) ifFalse:[
   358         ^ super buttonRelease:button x:x y:y
   358 	^ super buttonRelease:button x:x y:y
   359     ].
   359     ].
   360 
   360 
   361     isToggle ifTrue:[
   361     isToggle ifTrue:[
   362         ^ self
   362 	^ self
   363     ].
   363     ].
   364 
   364 
   365     pressed ifTrue:[
   365     pressed ifTrue:[
   366         autoRepeat ifTrue:[
   366 	autoRepeat ifTrue:[
   367             Processor removeTimedBlock:repeatBlock
   367 	    Processor removeTimedBlock:repeatBlock
   368         ].
   368 	].
   369         pressed := false.
   369 	pressed := false.
   370         view showPassive.
   370 	view showPassive.
   371 
   371 
   372         enableChannel value ifTrue:[
   372 	enableChannel value ifTrue:[
   373             "
   373 	    "
   374              only perform action if released within myself
   374 	     only perform action if released within myself
   375             "
   375 	    "
   376             ((x >= 0) 
   376 	    ((x >= 0) 
   377             and:[x <= view width
   377 	    and:[x <= view width
   378             and:[y >= 0
   378 	    and:[y >= 0
   379             and:[y <= view height]]]) ifTrue:[
   379 	    and:[y <= view height]]]) ifTrue:[
   380                 (releaseActionBlock notNil or:[model notNil]) ifTrue:[
   380 		(releaseActionBlock notNil or:[model notNil]) ifTrue:[
   381                     "
   381 		    "
   382                      force output - so that button is drawn correctly in case
   382 		     force output - so that button is drawn correctly in case
   383                      of any long-computation (at high priority)
   383 		     of any long-computation (at high priority)
   384                     "
   384 		    "
   385                     view flush.
   385 		    view flush.
   386                 ].
   386 		].
   387 
   387 
   388                 self performAction.
   388 		self performAction.
   389             ]
   389 	    ]
   390         ]
   390 	]
   391     ]
   391     ]
   392 
   392 
   393     "Modified: 16.12.1995 / 17:32:09 / cg"
   393     "Modified: 16.12.1995 / 17:32:09 / cg"
   394 !
   394 !
   395 
   395 
   544 !ButtonController methodsFor:'initialization'!
   544 !ButtonController methodsFor:'initialization'!
   545 
   545 
   546 initialize
   546 initialize
   547     super initialize.
   547     super initialize.
   548 
   548 
   549     self enableChannel:(true asValue).
   549     enableChannel := true asValue.
       
   550     enableChannel onChangeSend:#enableStateChange to:self.
   550 
   551 
   551     active := false.
   552     active := false.
   552     pressed := false.
   553     pressed := false.
   553     entered := false.
   554     entered := false.
   554     autoRepeat := false.
   555     autoRepeat := false.
   559 ! !
   560 ! !
   560 
   561 
   561 !ButtonController class methodsFor:'documentation'!
   562 !ButtonController class methodsFor:'documentation'!
   562 
   563 
   563 version
   564 version
   564     ^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.26 1995-12-16 16:37:04 cg Exp $'
   565     ^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.27 1995-12-17 16:49:09 cg Exp $'
   565 ! !
   566 ! !