PDA

View Full Version : rightMouseDown: woes


MacFiend
2006.05.27, 02:48 PM
I've got an NSWindow subclass which I want to handle all user-input events (ie, mouse, keyboard, etc.).

Everything is working good except for the NSResponder rightMouseDown: function. For whatever reason, it isn't being called - mouseDown:, rightMouseUp:, and rightMouseDragged: all work - so I cannot pinpoint why rightMouseDown: wouldn't be called?

I've searched Google, and came up with this:

http://developer.apple.com/releasenotes/Cocoa/AppKitOlderNotes.html
"A RightMouseDown in a window of an inactive application will not be delivered to -[NSWindow sendEvent:]. The event will be delivered to -[NSApplication sendEvent:], but the windowNumber will be 0."

My application is no inactive when I attempt the right-click, so I'm disregarding this note.

I also came across this:

http://www.idevapps.com/forum/archive/index.php/t-3679.html
another programmer having the exact same problem as mine.

Does anybody know what the deal is?

[Edit]
A reply suggested catching the event in an NSApp subclass - sure, it'd probably work - but why have a rightMouseDown: event if NSResponder isn't going to respond to it??

Someone also suggested that an NSView on the window could be 'consuming' the event - so I tried implementing rightMouseDown: in my NSView subclass, and still no good.

[Edit 2]
I figured out a workaround: I set my NSView subclass as the window's contentView, and now it receives rightMouseDown:
I'm still confused as to why the NSWindow would receive every single event except for rightMouseDown:
I guess this will have to do for now.

kelvin
2006.05.28, 06:06 AM
Handling Mouse Events (http://developer.apple.com/documentation/Cocoa/Conceptual/BasicEventHandling/Tasks/HandlingMouseEvents.html#//apple_ref/doc/uid/20000906-BBCCBEAF). Right mouse events are defined by the Application Kit to open pop-up menus, but you can override this behavior if necessary.

Haven't tried, but I assume you just need to override +defaultMenu; to return nil.

MacFiend
2006.05.28, 08:42 AM
Ahh okay. That would make sense! Thanks for the heads up. But it's still a little misleading of Apple to let rightMouseDrag: and rightMouseUp: go while rightMouseDown: must be treated differently - they could have put a comment or something (I don't care if it IS in the documentation, this is bad style imho). Anyways thanks.