How to control Mouse Event with Morph Objects in Squeak
In order to be able to catch mouse events with a morph subclass, the subclass must override the following Morph methods as necessary.
handlesMouseDown: evt ^ true.This will enable our subclass to catch when mouse is pressed on it.
If we want to handle all click, double click and drag operations, we have to override the mouseDown method.
mouseDown: evt evt hand waitForClicksOrDrag: self event: evtOnce this is done, click and doubleClick methods can be overridden so that they behave in the desired way.
To have rollover and rolloff effects or such operations we have to override the handlesMouseOver method.
handlesMouseOver: evt ^ true
mouseOver and mouseLeave methods are associated with this property and they can be overridden to obtain required behavior eg.
mouseOver: evt self color: Color black. mouseLeave: evt self color: Color whiteThis will change the color of the morph to black when mouse is over it, and change its color to white when the mouse leaves its bounds.
One other useful method is the cursorPoint which returns the position of the mouse icon. cursorPoint returns a point value. During events the location of cursor can be determined with this method.
(Thanks to Onur Aytar)