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;
|
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 14:53:50 -05:00
|
|
|
- (void)viewDidMoveToSuperview
|
2015-04-08 03:35:50 -05:00
|
|
|
{
|
2015-04-08 14:53:50 -05:00
|
|
|
if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) {
|
|
|
|
[self setTarget:nil];
|
|
|
|
self.uiC = NULL;
|
|
|
|
}
|
|
|
|
[super viewDidMoveToSuperview];
|
2015-04-08 03:35:50 -05:00
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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 03:48:03 -05:00
|
|
|
c = uiDarwinNewControl([uiNSButton class], NO, NO);
|
2015-04-08 02:38:08 -05:00
|
|
|
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-08 03:48:03 -05:00
|
|
|
setStandardControlFont((NSControl *) b);
|
2015-04-07 15:12:28 -05:00
|
|
|
|
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-08 03:48:03 -05:00
|
|
|
return b.uiC;
|
2015-04-07 15:12:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO text
|
|
|
|
|
|
|
|
void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
|
|
|
|
{
|
2015-04-08 03:48:03 -05:00
|
|
|
uiNSButton *b;
|
2015-04-07 15:12:28 -05:00
|
|
|
|
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
|
|
|
}
|