Handling one MC message blocks another

Dave Cragg dcragg at lacscentre.co.uk
Sun Dec 26 11:49:22 EST 2004


On 26 Dec 2004, at 04:30, depstein at att.net wrote:

> Trying to understand how a mouseDown handler and a linkClicked handler 
> coexisted or interacted, I conducted this test:
>
> In a field script, write
>
> on linkClicked
>   put "c" after msg
> end linkClicked
>
> With the field unlocked, click with the command key down on a 
> character of text of style "link".  The result is as expected.
> 	
> Now add this "mouseDown" handler to the field script:
>
> on mouseDown
>   if the lockText of me then
>     put "a" after msg
>   else
>     put "b" after msg
>   end if
> end mouseDown
>
> When I command-click on the linked text, the result now is that the 
> mouseDown message blocks the linkClicked message, so only the "b", not 
> the "c", appears.  This is not a problem, since I can do what I need 
> with either the mouseDown or the linkClicked handler, and don't need 
> both.  (I don't find any mention of this behavior in the help files, 
> though).  But here's what impressed me most:  If I remove the else 
> clause of the mouseDown handler, it no longer blocks the linkClicked 
> message (if lockText is true).  I can even keep the "else" and "end 
> if" lines, with nothing in between, or with a "do empty" statement in 
> between, and it won't block the linkClicked message.
>
> So MC's rule seems to be NOT "if there's a mousedown handler, don't 
> send the linkClicked message"; it's "if there's a mousedown handler 
> that takes any action, don't send the linkClicked message."  Very 
> smart.  The same rule is followed if I lock the field, restore the 
> second branch, and alternately activate and comment out the first 
> branch of my "if" clause.
>
I don't think the engine takes those kinds of "smart" decisions. What 
you're seeing may be explained by the focus shifting to the message box 
during the mouseDown handler. I think this is what interferes with the 
linkClicked being handled. Try this instead, which dosn't move focus 
out of the field:

global gTemp

on linkClicked
   put "c" & cr after gTemp
end linkClicked

on mouseDown
   put empty into gTemp
   if the lockText of me then
     put "a" & cr after gTemp
   else
     put "b" & cr after gTemp
   end if
end mouseDown

And in a separate button on the same card put this:

on mouseUp
   global gTemp
   put gTemp
end mouseUp

After command-clicking the link, and then clicking the new button, I 
think you'll see that the mouseDown and linkClicked messages are in 
fact handled.

Cheers
Dave



More information about the metacard mailing list