Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSStatusItems and Right Mouse Clicks



I'm updating a program which displays the rating of the current iTunes song in the menubar using an NSStatusItem. I have written my own NSView subclass which actually does the necessary drawing. I want to be able to right click in the menubar, and have a contextual menu appear. I cannot figure out a good way of doing this. When I set the menu outlet of the NSView subclass in Interface Builder, I can control-left-click on the status item and have a contextual menu appear, but no matter how many times I right-click, my rightMouseDown: method of my NSView subclass never gets called.

If I override NSApplication's sendEvent method, I see that NSRightMouseDown messages are definitely appearing in the event queue, but when they are then passed using [super sendEvent:], the messages never reach my NSView subclass (in the rightMouseDown: method). The windowNumber of the NSRightMouseDown events is 0, which is supposed to happen when a right mouse event is passed to a background application. However, when I tried modifying the event so that its windowNumber was the same as the NSView's "window's", nothing happens.

I've also tried (in the NSApplication subclass) converting the right-click event to a left-click with a control key modifier, but that also does not bring up a contextual menu.

Finally, I've tried intercepting the events in the NSApplication subclass and sending them directly to the NSView subclass, but I cannot seem to be able to correctly compute the transformation necessary to compute the screen coordinates to the view's coordinates.

How, then, can I do this? If I found either the correct way of converting the screen coordinates to the view's coordinates, or some way for the NSStatusItem's window to send me right mouse clicks, or some way to modify the clicks at the NSApplication level, then I think I'd be able to do this.

Thanks so much,
Matt
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.