Skip navigation.
 
mlRe: NSStatusItem custom view with menu
FROM : Michael Ash
DATE : Sat Jul 05 00:05:07 2008

On Thu, Jul 3, 2008 at 8:46 PM, Jacob Bandes-Storch <<email_removed>> wrote:
> I'm making an NSStatusItem with a custom view. In drawRect:, it draws things
> based on the value of the "highlighted" instance variable. When mouseDown:
> is called, it pops up a menu using the status item's popUpStatusItemMenu:
> method. Using the mouseUp: event does not work, because it is not called
> after the menu goes away. This is the way I've found that makes it work:
>
> - (void)mouseDown:(NSEvent *)theEvent {
>        highlighted = YES;
>        [self setNeedsDisplay:YES];
>        [statusItem popUpStatusItemMenu:menu];
>        highlighted = NO;
>        [self setNeedsDisplay:YES];
>        [super mouseDown:theEvent];
> }
>
> Is this a good method, or is there something better that involves mouseUp:?


This is a standard technique to use when subclassing controls or other
custom views. The reason it works is because menu and control tracking
is usually done by running a separate custom event loop, and control
is only returned to the caller once tracking is complete. That said, I
think Andy's response in this same thread is better for this
particular situation.

Mike

Related mailsAuthorDate
mlNSStatusItem custom view with menu Jacob Bandes-Storc… Jul 4, 02:46
mlRe: NSStatusItem custom view with menu Andy Kim Jul 4, 22:03
mlRe: NSStatusItem custom view with menu Michael Ash Jul 5, 00:05