How does double clicking work in Squeak?

Henrik Gedenryd Henrik.Gedenryd at lucs.lu.se
Fri Sep 24 07:51:21 UTC 1999


Chris,

Morphic has some built-in general support for generating drag:, click:, and
doubleClick: messages, in addition to the usual mouseDown: etc. It is quite
simple to use. (I now realize that Morphic may be of little help on a PDA.)
All of these are implemented by one and the same mechanism, which is
somewhat misleadingly named 'double click support', see the methods in the
HandMorph category with this name. (Bob's code-not-so-snippet is more or
less a simple re-implementation of some of this functionality.) However,
Morphic doesn't normally use these itself for its clicks and drags, but
regards mouseDowns as clicks, and uses 'hardwired' drags. This makes Morphic
somewhat less simple to extend and modify. But here's how to use the stuff:

First of all, the Morphs that wish to receive these events to mouseDown need
to add waitForClicksOrDrag:event: to their mouseDown: method, something like
this:

mouseDown: event fromMorph: sourceMorph
     "ask to get click/doubleClick/drag messages"

     event hand waitForClicksOrDrag: sourceMorph event: event.
....

Or as Morph>>click: states:

click: evt
     "Handle a single-click event. This message is only sent to clients that
request it by sending #waitForClicksOrDrag:event: to the initiating hand in
their mouseDown: method. This default implementation does nothing."



Don't forget to signal that the morph class wants the mouseDowns:

handlesMouseDown: evt
    "always receive mouseDowns to initiate drag/doubleClick detection"

    ^true


Then you just implement your click:, doubleClick:, and drag: methods.

Best regards,
Henrik

< = > .





More information about the Squeak-dev mailing list