2015-04-07 15:12:28 -05:00
|
|
|
// 7 april 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2015-04-08 03:35:50 -05:00
|
|
|
@interface uiNSButton : NSButton
|
2015-04-08 02:38:08 -05:00
|
|
|
@property uiControl *uiC;
|
|
|
|
@property void (*uiOnClicked)(uiControl *, void *);
|
|
|
|
@property void *uiOnClickedData;
|
|
|
|
@property NSMutableArray *uiFreeList;
|
2015-04-08 01:28:42 -05:00
|
|
|
@end
|
|
|
|
|
2015-04-08 02:38:08 -05:00
|
|
|
@implementation uiNSButton
|
2015-04-08 01:28:42 -05:00
|
|
|
|
2015-04-08 03:35:50 -05:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
uiDarwinControlFree(self.uiC);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
2015-04-08 01:28:42 -05:00
|
|
|
|
2015-04-08 02:38:08 -05:00
|
|
|
- (IBAction)uiButtonClicked:(id)sender
|
2015-04-07 15:12:28 -05:00
|
|
|
{
|
2015-04-08 03:35:50 -05:00
|
|
|
(*(self.uiOnClicked))(self.uiC, self.uiOnClickedData);
|
2015-04-07 15:12:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
static void defaultOnClicked(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO destruction
|
|
|
|
uiControl *uiNewButton(const char *text)
|
|
|
|
{
|
2015-04-08 02:38:08 -05:00
|
|
|
uiControl *c;
|
|
|
|
uiNSButton *b;
|
2015-04-07 15:12:28 -05:00
|
|
|
|
2015-04-08 02:38:08 -05:00
|
|
|
c = uiDarwinNewControl([uiNSButton class], NO, NO, NULL);
|
|
|
|
b = (uiNSButton *) uiControlHandle(c);
|
2015-04-08 03:35:50 -05:00
|
|
|
b.uiC = c;
|
2015-04-07 15:12:28 -05:00
|
|
|
|
2015-04-08 02:38:08 -05:00
|
|
|
[b setTitle:toNSString(text)];
|
|
|
|
[b setButtonType:NSMomentaryPushInButton];
|
|
|
|
[b setBordered:YES];
|
|
|
|
[b setBezelStyle:NSRoundedBezelStyle];
|
2015-04-07 15:12:28 -05:00
|
|
|
setStandardControlFont((NSControl *) bb);
|
|
|
|
|
2015-04-08 02:38:08 -05:00
|
|
|
[b setTarget:b];
|
|
|
|
[b setAction:@selector(uiButtonClicked:)];
|
2015-04-07 15:12:28 -05:00
|
|
|
|
2015-04-08 03:35:50 -05:00
|
|
|
b.uiOnClicked = defaultOnClicked;
|
2015-04-07 15:12:28 -05:00
|
|
|
|
2015-04-07 15:38:51 -05:00
|
|
|
return b.c;
|
2015-04-07 15:12:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO text
|
|
|
|
|
|
|
|
void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
|
|
|
|
{
|
|
|
|
button *b;
|
|
|
|
|
2015-04-08 02:38:08 -05:00
|
|
|
b = (uiNSButton *) uiControlHandle(c);
|
2015-04-08 03:35:50 -05:00
|
|
|
b.uiOnClicked = f;
|
|
|
|
b.uiOnClickedData = data;
|
2015-04-07 15:12:28 -05:00
|
|
|
}
|