gwenhywfar 5.14.1
CocoaButton.m
Go to the documentation of this file.
1//
2// CocoaButton.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
14#import "CocoaButton.h"
15
16#ifndef COCOA_GWEN_BUTTON_MM
17#define COCOA_GWEN_BUTTON_MM
18
19@implementation CocoaButton
20
21@synthesize fillX;
22@synthesize fillY;
23
24- (id)initWithFrame:(NSRect)frame {
25 self = [super initWithFrame:frame];
26 if (self) {
27 [self setTarget:self];
28 [self setAction:@selector(clicked:)];
29 c_actionPtr = nil;
30 c_actionData = nil;
31 fillX = NO;
32 fillY = NO;
33 minWidth = 40.0;
34 }
35 return self;
36}
37
38-(void) dealloc {
39 [super dealloc];
40}
41
42
43-(NSSize) neededTextSize {
44 NSString *title = [self title];
45 if (title && [title length]>0) {
46 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
47 [NSColor blackColor], NSForegroundColorAttributeName,
48 [self font], NSFontAttributeName,
49 nil];
50 return [title sizeWithAttributes:attributes];
51 }
52 return NSZeroSize;
53}
54
55-(void) computeMinWidth {
56 NSSize size = [self neededTextSize];
57 minWidth = size.width + 40.0;
58 if ([self image]) {
59 minWidth += [[self image] size].width;
60 }
61}
62
63-(void) setC_ActionPtr:(gwenActionPtr)ptr Data:(void*)data {
64 c_actionPtr = ptr;
65 c_actionData = data;
66}
67
68-(void) clicked:(id) sender {
69 if (c_actionPtr) {
71 }
72}
73
74- (void)setTitle:(NSString *)aString {
75 [super setTitle:aString];
76 [self computeMinWidth];
77}
78
79- (void)setImage:(NSImage *)anImage {
80 [super setImage:anImage];
81 [self computeMinWidth];
82}
83
84#pragma mark Protocoll Methods
85
86- (NSSize) minSize {
87 return NSMakeSize(minWidth, 32.0);
88}
89
90@end
91
92#endif
void(* gwenActionPtr)(NSButton *button, void *data)
Definition CocoaButton.h:14
CGFloat minWidth
Definition CocoaButton.h:25
void * c_actionData
Definition CocoaButton.h:21
NSSize neededTextSize()
Definition CocoaButton.m:43
gwenActionPtr c_actionPtr
Definition CocoaButton.h:20