views:

186

answers:

2

I have an NSControl subclass (which is configured as a layer-hosting view, although I doubt that's relevant). I've been attempting to write the code to get and display a context menu. However, neither menuForEvent: or rightMouseDown: are being called. Any idea what could be causing that? Other mouse events work correctly.

As an aside, I'm not sure if I have to call menuForEvent: myself, but the docs made it sound like I don't, which is why I tried overriding it first. Regardless, I should at least expect rightMouseDown: to be called…

Related: it appears that AppKit doesn't recognize Ctrl+Click as a right mouse click. Presumably I have to check for this condition in mouseDown: and call rightMouseDown: manually. But given the weirdness I'm seeing, is there some other way of doing it?

+1  A: 

Check its return value from mouseDownCanMoveWindow. The documentation isn't terribly clear, but implies that if this method returns YES, the view (control) won't get the mouse-down event.

If that turns out to be your problem, create a subclass of the control's class (if it's not already a subclass) and implement that method to return NO.

Peter Hosey
+1  A: 

Have you included the -(NSView *)hitTest:(NSPoint)aPoint method in your subclass? It could be that the mouse event is being picked up by another element in your view and that would prevent menuForEvent being called.

You are correct in thinking that menuForEvent should be called automatically.

Septih
Turns out I was an idiot; I had forgotten that the layer was actually living inside a subview (so that I could arrange a scroller alongside the layer) I subclassed my layer-hosting view and had it forward the `rightMouseDown:` message to `nextResponder`. After that, `menuForEvent:` and everything else started working as expected. Thanks.
Alex