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 #import "CocoaComboBox.h"
00013
00014 #ifndef COCOA_COMBOBOX_MM
00015 #define COCOA_COMBOBOX_MM
00016
00017 @implementation CocoaComboBox
00018
00019 @synthesize fillX;
00020 @synthesize fillY;
00021
00022 - (id)initWithFrame:(NSRect)frame {
00023 self = [super initWithFrame:frame];
00024 if (self) {
00025 [self setTarget:self];
00026 [self setAction:@selector(textChanged:)];
00027 c_actionPtr = nil;
00028 c_actionData = nil;
00029
00030 c_actionPtr = nil;
00031 }
00032 return self;
00033 }
00034
00035 -(void) dealloc {
00036 [super dealloc];
00037 }
00038
00039 -(NSSize) neededTextSize {
00040 if ([self numberOfItems] > 0) {
00041 NSSize maxSize = NSZeroSize;
00042 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
00043 [NSColor blackColor], NSForegroundColorAttributeName,
00044 [self font], NSFontAttributeName,
00045 nil];
00046 NSArray *objectValues = [self objectValues];
00047
00048 for (NSString *s in objectValues) {
00049 NSSize titleSize = [s sizeWithAttributes:attributes];
00050 if (maxSize.width < titleSize.width) maxSize.width = titleSize.width;
00051 if (maxSize.height < titleSize.height) maxSize.height = titleSize.height;
00052 }
00053
00054 return maxSize;
00055 }
00056 return NSZeroSize;
00057 }
00058
00059 -(void) computeMinWidth {
00060 NSSize size = [self neededTextSize];
00061 minWidth = size.width+44.0;
00062 }
00063
00064 -(void) setC_ComboBoxActionPtr:(gwenComboBoxActionPtr)ptr Data:(void*)data {
00065 c_actionPtr = ptr;
00066 c_actionData = data;
00067 }
00068
00069 -(void) textChanged:(id)sender {
00070 if (c_actionPtr) {
00071 c_actionPtr(self, c_actionData);
00072 }
00073 }
00074
00075 - (void)setStringValue:(NSString *)aString {
00076 [super setStringValue:aString];
00077 }
00078
00079 - (void)addItemWithObjectValue:(id)anObject {
00080 [super addItemWithObjectValue:anObject];
00081 [self computeMinWidth];
00082 }
00083
00084 #pragma mark Protocoll Methods
00085
00086 - (NSSize) minSize {
00087 return NSMakeSize(minWidth, 24.0);
00088 }
00089
00090 @end
00091
00092 #endif