CocoaButton.m

Go to the documentation of this file.
00001 //
00002 //  CocoaButton.m
00003 //  
00004 //
00005 //  Created by Samuel Strupp on 10.08.10.
00006 //
00007 
00008 #ifdef HAVE_CONFIG_H
00009 # include <config.h>
00010 #endif
00011 
00012 
00013 
00014 #import "CocoaButton.h"
00015 
00016 #ifndef COCOA_GWEN_BUTTON_MM
00017 #define COCOA_GWEN_BUTTON_MM
00018 
00019 @implementation CocoaButton
00020 
00021 @synthesize fillX;
00022 @synthesize fillY;
00023 
00024 - (id)initWithFrame:(NSRect)frame {
00025     self = [super initWithFrame:frame];
00026     if (self) {
00027                 [self setTarget:self];
00028                 [self setAction:@selector(clicked:)];
00029                 c_actionPtr = nil;
00030                 c_actionData = nil;
00031                 fillX = NO;
00032                 fillY = NO;
00033                 minWidth = 40.0;
00034     }
00035     return self;
00036 }
00037 
00038 -(void) dealloc {
00039         [super dealloc];
00040 }
00041 
00042 
00043 -(NSSize) neededTextSize {
00044         NSString *title = [self title];
00045         if (title && [title length]>0) {
00046                 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
00047                                                                         [NSColor blackColor], NSForegroundColorAttributeName,
00048                                                                         [self font], NSFontAttributeName,
00049                                                                         nil];
00050                 return [title sizeWithAttributes:attributes];
00051         }
00052         return NSZeroSize;
00053 }
00054 
00055 -(void) computeMinWidth {
00056         NSSize size = [self neededTextSize];
00057         minWidth = size.width + 40.0;
00058         if ([self image]) {
00059                 minWidth += [[self image] size].width;
00060         }
00061 }
00062 
00063 -(void) setC_ActionPtr:(gwenActionPtr)ptr Data:(void*)data {
00064         c_actionPtr = ptr;
00065         c_actionData = data;
00066 }
00067 
00068 -(void) clicked:(id) sender {
00069         if (c_actionPtr) {
00070                 c_actionPtr(self, c_actionData);
00071         }
00072 }
00073 
00074 - (void)setTitle:(NSString *)aString {
00075         [super setTitle:aString];
00076         [self computeMinWidth];
00077 }
00078 
00079 - (void)setImage:(NSImage *)anImage {
00080         [super setImage:anImage];
00081         [self computeMinWidth];
00082 }
00083 
00084 #pragma mark Protocoll Methods
00085 
00086 - (NSSize) minSize {
00087         return NSMakeSize(minWidth, 32.0);
00088 }
00089 
00090 @end
00091 
00092 #endif