From 518a5ddbf15d50a254c732a80d5907ef8878abe0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Apr 2015 18:49:45 -0400 Subject: Split all OS backends into their own folders. --- new/darwin/button.m | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 new/darwin/button.m (limited to 'new/darwin/button.m') diff --git a/new/darwin/button.m b/new/darwin/button.m new file mode 100644 index 0000000..92e2c76 --- /dev/null +++ b/new/darwin/button.m @@ -0,0 +1,79 @@ +// 7 april 2015 +#import "uipriv_darwin.h" + +@interface uiNSButton : NSButton +@property uiControl *uiC; +@property void (*uiOnClicked)(uiControl *, void *); +@property void *uiOnClickedData; +@end + +@implementation uiNSButton + +- (void)viewDidMoveToSuperview +{ + if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { + [self setTarget:nil]; + self.uiC = NULL; + } + [super viewDidMoveToSuperview]; +} + +- (IBAction)uiButtonClicked:(id)sender +{ + (*(self.uiOnClicked))(self.uiC, self.uiOnClickedData); +} + +@end + +static void defaultOnClicked(uiControl *c, void *data) +{ + // do nothing +} + +uiControl *uiNewButton(const char *text) +{ + uiControl *c; + uiNSButton *b; + + c = uiDarwinNewControl([uiNSButton class], NO, NO); + b = (uiNSButton *) uiControlHandle(c); + b.uiC = c; + + [b setTitle:toNSString(text)]; + [b setButtonType:NSMomentaryPushInButton]; + [b setBordered:YES]; + [b setBezelStyle:NSRoundedBezelStyle]; + setStandardControlFont((NSControl *) b); + + [b setTarget:b]; + [b setAction:@selector(uiButtonClicked:)]; + + b.uiOnClicked = defaultOnClicked; + + return b.uiC; +} + +char *uiButtonText(uiControl *c) +{ + uiNSButton *b; + + b = (uiNSButton *) uiControlHandle(c); + return uiDarwinNSStringToText([b title]); +} + +void uiButtonSetText(uiControl *c, const char *text) +{ + uiNSButton *b; + + b = (uiNSButton *) uiControlHandle(c); + [b setTitle:toNSString(text)]; +} + +void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data) +{ + uiNSButton *b; + + b = (uiNSButton *) uiControlHandle(c); + b.uiOnClicked = f; + b.uiOnClickedData = data; +} -- cgit v1.2.3