Re: Way to determine size of a menu?
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Mitchell, @implementation DBBottomPopUpButton - (void)mouseDown:(NSEvent *)theEvent { _isClicked = YES; [super mouseDown:theEvent]; } @end -- Dave Batton Mere Mortal Software http://www.Mere-Mortal-Software.com/blog/ _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.apple... How would I do it with NSPopUpButton. As I understand it, that class will take the first item in the menu and display that (and not show it in the list). How can I get it to show the gear icon all the time? Here's my NSPopUpButton subclass that I use to duplicate the look and feel of the gear icon button at the bottom of Apple Mail. The code below handles drawing the image using picture resources (one each for the normal, pressed, and disabled button) and drawing as pressed when the drop-down menu is displayed. So, if you specify the icon name as "Action" in Interface Builder, then you need a picture named "Action", another named "Action_Pressed", and a third named "Action_Disabled". It looks like crap in Interface Builder, since you need to size the NSPopUpButton object for the actual button size, not for the image drawn on your layout by Interface Builder (which shifts the icon to the right). But it works perfectly. - (void)awakeFromNib { _isClicked = NO; // a private instance variable we use to track when the button is clicked } - (void)drawRect:(NSRect)aRect { NSString *buttonName; if (_isClicked) { buttonName = [NSString stringWithFormat:@"%@_Pressed", [[self image] name]]; } else if ([self isEnabled] == YES) { buttonName = [[self image] name]; } else { buttonName = [NSString stringWithFormat:@"%@_Disabled", [[self image] name]]; } NSImage *image = [NSImage imageNamed:buttonName]; if (image) { [image setFlipped:YES]; NSRect srcRect; srcRect.origin = NSZeroPoint; srcRect.size = [image size]; aRect.size = srcRect.size; aRect.origin.x += 1; aRect.origin.y += 1; [image drawInRect:aRect fromRect:srcRect operation:NSCompositeCopy fraction:1.0 ]; } _isClicked = NO; } This email sent to site_archiver@lists.apple.com
participants (1)
-
Dave Batton