Posts Tagged ‘NSReponder’

Whether to call [super mouseDown:] etc or not

From View Programming Guide : Handling Mouse Click and Dragging Events

Notice that the mouseDown: implementation in Listing 4-7 does not call the super implementation. The NSView class’s default implementation for the mouse handling events are inherited from NSResponder and pass the event up the responder chain for handling, bypassing the view in question entirely. Typically a custom NSView subclass should not call the super implementation of any of the mouse-event methods.

Once [super mouseDown:…] is called, mouseDragged: is not called. mouseMoved: can be still received by calling [[self window] setAcceptsMouseMovedEvents:YES]; though.

So, for custom views which needs to handle all details of mouse event, it’s better not to call super’s messages of NSResponder, in other words, mouseDown, mouseUp, mouseDragged, mouseMoved, etc.

There is different results obtained by different combination of acceptsFirstResponder, acceptsFirstMouse etc. So, when implementing mouse event handler, please consider situation thoroughly and test as many as cases you can imagine. ( Hmmmm… S/W engineers who are not considerate tend to think that they know everything and ignore general situation.. So, I wonder if this recommendation would be effective to them. )

%d bloggers like this: