14 #ifndef COCOA_COMBOBOX_MM
15 #define COCOA_COMBOBOX_MM
22 - (id)initWithFrame:(NSRect)frame {
23 self = [
super initWithFrame:frame];
25 [
self setTarget:self];
26 [
self setAction:@selector(textChanged:)];
39 -(NSSize) neededTextSize {
40 if ([
self numberOfItems] > 0) {
41 NSSize maxSize = NSZeroSize;
42 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
43 [NSColor blackColor], NSForegroundColorAttributeName,
44 [
self font], NSFontAttributeName,
46 NSArray *objectValues = [
self objectValues];
48 for (NSString *s in objectValues) {
49 NSSize titleSize = [s sizeWithAttributes:attributes];
50 if (maxSize.width < titleSize.width) maxSize.width = titleSize.width;
51 if (maxSize.height < titleSize.height) maxSize.height = titleSize.height;
59 -(void) computeMinWidth {
60 NSSize size = [
self neededTextSize];
69 -(void) textChanged:(
id)sender {
75 - (void)setStringValue:(NSString *)aString {
76 [
super setStringValue:aString];
79 - (void)addItemWithObjectValue:(
id)anObject {
80 [
super addItemWithObjectValue:anObject];
81 [
self computeMinWidth];
84 #pragma mark Protocoll Methods