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.

These methods return false as default. Therefore if we want to catch clicks we have to override the handlesMouseDown event as following:
	handlesMouseDown: evt
		^ true.
This will enable our subclass to catch when mouse is pressed on it.


The methods related to handlesMouseDown are as follows: Once we enabled handlesMouseDown, mouseDown method will be executed when mouse is pressed over the morph.


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: evt
Once 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 white
This 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)