2015-07-11 15:56:37 -05:00
|
|
|
// 10 june 2015
|
2015-07-11 16:02:01 -05:00
|
|
|
#include "uipriv_darwin.h"
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-22 22:03:26 -05:00
|
|
|
// TODO reimplement CommitDestroy() on all of these
|
|
|
|
|
2015-07-11 19:28:04 -05:00
|
|
|
@interface buttonDelegate : NSObject {
|
|
|
|
uiButton *b;
|
2015-07-11 15:56:37 -05:00
|
|
|
void (*onClicked)(uiButton *, void *);
|
|
|
|
void *onClickedData;
|
2015-07-11 19:28:04 -05:00
|
|
|
}
|
|
|
|
- (IBAction)buttonClicked:(id)sender;
|
|
|
|
- (void)setButton:(uiButton *)newb;
|
|
|
|
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation buttonDelegate
|
|
|
|
|
|
|
|
- (IBAction)buttonClicked:(id)sender
|
|
|
|
{
|
|
|
|
(*(self->onClicked))(self->b, self->onClickedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setButton:(uiButton *)newb
|
|
|
|
{
|
|
|
|
self->b = newb;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data
|
|
|
|
{
|
|
|
|
self->onClicked = f;
|
|
|
|
self->onClickedData = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
struct button {
|
|
|
|
uiButton b;
|
|
|
|
NSButton *button;
|
|
|
|
buttonDelegate *delegate;
|
2015-07-11 15:56:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
uiDefineControlType(uiButton, uiTypeButton, struct button)
|
|
|
|
|
|
|
|
static uintptr_t buttonHandle(uiControl *c)
|
|
|
|
{
|
|
|
|
struct button *b = (struct button *) c;
|
|
|
|
|
2015-07-11 19:28:04 -05:00
|
|
|
return (uintptr_t) (b->button);
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnClicked(uiButton *b, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *buttonText(uiButton *bb)
|
|
|
|
{
|
|
|
|
struct button *b = (struct button *) bb;
|
|
|
|
|
2015-07-11 19:28:04 -05:00
|
|
|
return uiDarwinNSStringToText([b->button title]);
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void buttonSetText(uiButton *bb, const char *text)
|
|
|
|
{
|
|
|
|
struct button *b = (struct button *) bb;
|
|
|
|
|
2015-07-11 19:28:04 -05:00
|
|
|
[b->button setTitle:toNSString(text)];
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
|
|
|
{
|
|
|
|
struct button *b = (struct button *) bb;
|
|
|
|
|
2015-07-11 19:28:04 -05:00
|
|
|
[b->delegate setOnClicked:f data:data];
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiButton *uiNewButton(const char *text)
|
|
|
|
{
|
|
|
|
struct button *b;
|
|
|
|
|
2015-07-11 19:28:04 -05:00
|
|
|
b = (struct button *) uiNewControl(uiTypeButton());
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-28 13:14:41 -05:00
|
|
|
b->button = [[NSButton alloc] initWithFrame:NSZeroRect];
|
2015-07-11 19:28:04 -05:00
|
|
|
[b->button setTitle:toNSString(text)];
|
|
|
|
[b->button setButtonType:NSMomentaryPushInButton];
|
|
|
|
[b->button setBordered:YES];
|
|
|
|
[b->button setBezelStyle:NSRoundedBezelStyle];
|
|
|
|
uiDarwinMakeSingleViewControl(uiControl(b), b->button, YES);
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-11 19:28:04 -05:00
|
|
|
b->delegate = [buttonDelegate new];
|
|
|
|
[b->button setTarget:b->delegate];
|
|
|
|
[b->button setAction:@selector(buttonClicked:)];
|
|
|
|
[b->delegate setButton:uiButton(b)];
|
|
|
|
[b->delegate setOnClicked:defaultOnClicked data:NULL];
|
2015-07-11 15:56:37 -05:00
|
|
|
|
|
|
|
uiControl(b)->Handle = buttonHandle;
|
|
|
|
|
|
|
|
uiButton(b)->Text = buttonText;
|
|
|
|
uiButton(b)->SetText = buttonSetText;
|
|
|
|
uiButton(b)->OnClicked = buttonOnClicked;
|
|
|
|
|
|
|
|
return uiButton(b);
|
|
|
|
}
|