Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifdef HAVE_CONFIG_H
00009 # include <config.h>
00010 #endif
00011
00012
00013 #import "CocoaPopUpButton.h"
00014
00015 #ifndef COCOA_POPUP_BUTTON_MM
00016 #define COCOA_POPUP_BUTTON_MM
00017
00018 @implementation CocoaPopUpButton
00019
00020 @synthesize fillX;
00021 @synthesize fillY;
00022
00023 - (id)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag {
00024 self = [super initWithFrame:frameRect pullsDown:flag];
00025 if (self) {
00026 [self setTarget:self];
00027 [self setAction:@selector(clicked:)];
00028 c_actionPtr = nil;
00029 c_actionData = nil;
00030 fillX = NO;
00031 fillY = NO;
00032 minWidth = 40.0;
00033 }
00034 return self;
00035 }
00036
00037 -(void) dealloc {
00038 [super dealloc];
00039 }
00040
00041
00042 -(NSSize) neededTextSize {
00043 if ([self numberOfItems] > 0) {
00044 NSSize maxSize = NSZeroSize;
00045 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
00046 [NSColor blackColor], NSForegroundColorAttributeName,
00047 [self font], NSFontAttributeName,
00048 nil];
00049
00050 NSArray *titles = [self itemTitles];
00051 for (NSString *title in titles) {
00052 NSSize titleSize = [title sizeWithAttributes:attributes];
00053 if (maxSize.width < titleSize.width) maxSize.width = titleSize.width;
00054 if (maxSize.height < titleSize.height) maxSize.height = titleSize.height;
00055 }
00056
00057 return maxSize;
00058 }
00059 return NSZeroSize;
00060 }
00061
00062 -(void) computeMinWidth {
00063 NSSize size = [self neededTextSize];
00064 minWidth = size.width + 40.0;
00065 }
00066
00067 -(void) setC_PopUpActionPtr:(gwenPopUpActionPtr)ptr Data:(void*)data {
00068 c_actionPtr = ptr;
00069 c_actionData = data;
00070 }
00071
00072 -(void) clicked:(id) sender {
00073 if (c_actionPtr) {
00074 c_actionPtr(self, c_actionData);
00075 }
00076 }
00077
00078 - (void)setTitle:(NSString *)aString {
00079 [super setTitle:aString];
00080 [self computeMinWidth];
00081 }
00082
00083 - (void)addItemWithTitle:(NSString *)title {
00084 [super addItemWithTitle:title];
00085 [self computeMinWidth];
00086 }
00087
00088 #pragma mark Protocoll Methods
00089
00090 - (NSSize) minSize {
00091 return NSMakeSize(minWidth, 24.0);
00092 }
00093
00094 @end
00095
00096 #endif