Re: Way to determine size of a menu?
Re: Way to determine size of a menu?
- Subject: Re: Way to determine size of a menu?
- From: Dave Batton <email@hidden>
- Date: Tue, 2 Jan 2007 12:35:49 +0100
Mitchell,
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.
@implementation DBBottomPopUpButton
- (void)awakeFromNib
{
_isClicked = NO; // a private instance variable we use to track
when the button is clicked
}
- (void)mouseDown:(NSEvent *)theEvent
{
_isClicked = YES;
[super mouseDown:theEvent];
}
- (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;
}
@end
--
Dave Batton
Mere Mortal Software
http://www.Mere-Mortal-Software.com/blog/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden