Determine which control is being focused on in focusOut message?

Ken Ray kray at sonsothunder.com
Thu Jan 31 10:42:30 EST 2008


On Thu, 31 Jan 2008 09:13:50 -0500, Trevor DeVore wrote:

> Hi,
> 
> Anybody know of a way to determine what control is being focused on 
> in the focusOut message of the previously focused control?
> 
> For example, if an image was currently focused and then the user 
> clicks on a field I would like to know the reference to that field in 
> the focusOut message of the image. My current workaround is to fire 
> off a message in focusOut using send in time. This does work but is 
> not ideal in all circumstances.

Well, the only other thing I can think of is to keep track in a custom 
property/global/etc. of each object that gets the focusIn message, and 
then send a message to the previous object. But keep in mind that an 
unlocked field won't get a 'focusIn' , so you'd need to do the same 
thing for 'openField'. Something like a frontscript (unless you're not 
trapping focusIn/openField) that is:

on focusIn
  if the uLastFocusedObj of this stack is not empty then
    send "NewFocus" && (the long id of the target) to \
      (the uLastFocusedObj of this stack)
  end if
  set the uLastFocusedObj of this stack to \
      the long id of the target 
  pass focusIn
end focusIn

on openField
  if the uLastFocusedObj of this stack is not empty then
    send "NewFocus" && (the long id of the target) to \
      (the uLastFocusedObj of this stack)
  end if
  set the uLastFocusedObj of this stack to \
      the long id of the target 
  pass openField
end openField


And of course, don't forget to clear the custom prop (if you store the 
flag that way) when your stack opens (or just don't ever save the 
stack). Other than that, I can't think of a way to do it other than a 
"send", since the 'focusOut'/'closeField'/'exitField' message is sent 
to the "old" object BEFORE the 'focusIn' is sent to the "new" object.


Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/

Email has been scanned for viruses by Altman Technologies' email management service - www.altman.co.uk/emailsystems



More information about the use-livecode mailing list