Question

The setEnabled: method is not working in my subclass of NSButton in which I have overridden mouse{down,drag,up} and rightMouse{down,drag,up}. I feel the enabling/disabling of the button should be outside these functions -- the button should not be receiving mouse events in the first place when it is disabled.

Do I have to make a check explicitly when I am overriding these functions?

Was it helpful?

Solution

I think that you do need to do your own check.

As explained in Apple's writeup on Cocoa Event Architechture, the window containing your button is sending mouseDown: (or whichever other method is appropriate) to your button in response to recieving an event. In order for the window to decide not to send the message, it would have to first determine that the button is an NSControl subclass (enabled being a property of NSControl, but not NSView) and then check that enabled flag. That is beyond the window's area of responsibility. A control being enabled isn't part of the event dispatch system the way first responder status is.

As an interesting piece of insight, if you take a look at GNUStep's -[NSControl mouseDown:] implementation, they do indeed check [self isEnabled] before handling the event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top