FROM : Andy Kim
DATE : Fri Jul 04 22:03:05 2008
Another way to do this is to implement the NSMenu delegate methods:
- menuWillOpen:
- menuDidClose:
You would then set the highlighted variable there. I think it'll make
the code easier to read. You need to set the menu's delegate for this
to work (obviously).
- Andy Kim
On Jul 3, 2008, at 5:46 PM, Jacob Bandes-Storch 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:?
DATE : Fri Jul 04 22:03:05 2008
Another way to do this is to implement the NSMenu delegate methods:
- menuWillOpen:
- menuDidClose:
You would then set the highlighted variable there. I think it'll make
the code easier to read. You need to set the menu's delegate for this
to work (obviously).
- Andy Kim
On Jul 3, 2008, at 5:46 PM, Jacob Bandes-Storch 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:?
| Related mails | Author | Date |
|---|---|---|
| Jacob Bandes-Storc… | Jul 4, 02:46 | |
| Andy Kim | Jul 4, 22:03 | |
| Michael Ash | Jul 5, 00:05 |






Cocoa mail archive

