15 #ifndef COCOA_POPUP_BUTTON_MM
16 #define COCOA_POPUP_BUTTON_MM
23 - (id)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag {
24 self = [
super initWithFrame:frameRect pullsDown:flag];
26 [
self setTarget:self];
27 [
self setAction:@selector(clicked:)];
42 -(NSSize) neededTextSize {
43 if ([
self numberOfItems] > 0) {
44 NSSize maxSize = NSZeroSize;
45 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
46 [NSColor blackColor], NSForegroundColorAttributeName,
47 [
self font], NSFontAttributeName,
50 NSArray *titles = [
self itemTitles];
51 for (NSString *title in titles) {
52 NSSize titleSize = [title sizeWithAttributes:attributes];
53 if (maxSize.width < titleSize.width) maxSize.width = titleSize.width;
54 if (maxSize.height < titleSize.height) maxSize.height = titleSize.height;
62 -(void) computeMinWidth {
63 NSSize size = [
self neededTextSize];
72 -(void) clicked:(
id) sender {
78 - (void)setTitle:(NSString *)aString {
79 [
super setTitle:aString];
80 [
self computeMinWidth];
83 - (void)addItemWithTitle:(NSString *)title {
84 [
super addItemWithTitle:title];
85 [
self computeMinWidth];
88 #pragma mark Protocoll Methods