gwenhywfar  4.8.0beta
CocoaComboBox.m
Go to the documentation of this file.
1 //
2 // CocoaComboBox.m
3 //
4 //
5 // Created by Samuel Strupp on 10.08.10.
6 //
7 
8 #ifdef HAVE_CONFIG_H
9 # include <config.h>
10 #endif
11 
12 #import "CocoaComboBox.h"
13 
14 #ifndef COCOA_COMBOBOX_MM
15 #define COCOA_COMBOBOX_MM
16 
17 @implementation CocoaComboBox
18 
19 @synthesize fillX;
20 @synthesize fillY;
21 
22 - (id)initWithFrame:(NSRect)frame {
23  self = [super initWithFrame:frame];
24  if (self) {
25  [self setTarget:self];
26  [self setAction:@selector(textChanged:)];
27  c_actionPtr = nil;
28  c_actionData = nil;
29 
30  c_actionPtr = nil;
31  }
32  return self;
33 }
34 
35 -(void) dealloc {
36  [super dealloc];
37 }
38 
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,
45  nil];
46  NSArray *objectValues = [self objectValues];
47 
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;
52  }
53 
54  return maxSize;
55  }
56  return NSZeroSize;
57 }
58 
59 -(void) computeMinWidth {
60  NSSize size = [self neededTextSize];
61  minWidth = size.width+44.0;
62 }
63 
64 -(void) setC_ComboBoxActionPtr:(gwenComboBoxActionPtr)ptr Data:(void*)data {
65  c_actionPtr = ptr;
66  c_actionData = data;
67 }
68 
69 -(void) textChanged:(id)sender {
70  if (c_actionPtr) {
72  }
73 }
74 
75 - (void)setStringValue:(NSString *)aString {
76  [super setStringValue:aString]; //damit hebeln wir die automatische Größen Berechnung vom CocoaLabel aus.
77 }
78 
79 - (void)addItemWithObjectValue:(id)anObject {
80  [super addItemWithObjectValue:anObject];
81  [self computeMinWidth];
82 }
83 
84 #pragma mark Protocoll Methods
85 
86 - (NSSize) minSize {
87  return NSMakeSize(minWidth, 24.0);
88 }
89 
90 @end
91 
92 #endif