gwenhywfar 5.10.1
CocoaPopUpButton.m
Go to the documentation of this file.
1//
2// CocoaPopUpButton.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
13#import "CocoaPopUpButton.h"
14
15#ifndef COCOA_POPUP_BUTTON_MM
16#define COCOA_POPUP_BUTTON_MM
17
18@implementation CocoaPopUpButton
19
20@synthesize fillX;
21@synthesize fillY;
22
23- (id)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag {
24 self = [super initWithFrame:frameRect pullsDown:flag];
25 if (self) {
26 [self setTarget:self];
27 [self setAction:@selector(clicked:)];
28 c_actionPtr = nil;
29 c_actionData = nil;
30 fillX = NO;
31 fillY = NO;
32 minWidth = 40.0;
33 }
34 return self;
35}
36
37-(void) dealloc {
38 [super dealloc];
39}
40
41
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,
48 nil];
49
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;
55 }
56
57 return maxSize;
58 }
59 return NSZeroSize;
60}
61
62-(void) computeMinWidth {
63 NSSize size = [self neededTextSize];
64 minWidth = size.width + 40.0;
65}
66
67-(void) setC_PopUpActionPtr:(gwenPopUpActionPtr)ptr Data:(void*)data {
68 c_actionPtr = ptr;
69 c_actionData = data;
70}
71
72-(void) clicked:(id) sender {
73 if (c_actionPtr) {
75 }
76}
77
78- (void)setTitle:(NSString *)aString {
79 [super setTitle:aString];
80 [self computeMinWidth];
81}
82
83- (void)addItemWithTitle:(NSString *)title {
84 [super addItemWithTitle:title];
85 [self computeMinWidth];
86}
87
88#pragma mark Protocoll Methods
89
90- (NSSize) minSize {
91 return NSMakeSize(minWidth, 24.0);
92}
93
94@end
95
96#endif
void(* gwenPopUpActionPtr)(NSPopUpButton *button, void *data)
gwenPopUpActionPtr c_actionPtr