Migrated darwin/checkbox.m.

This commit is contained in:
Pietro Gagliardi 2015-04-16 13:51:46 -04:00
parent 63dcd776ca
commit 7ec19d56a8
1 changed files with 61 additions and 52 deletions

View File

@ -2,8 +2,8 @@
#import "uipriv_darwin.h"
@interface uiCheckboxNSButton : NSButton
@property uiControl *uiC;
@property void (*uiOnToggled)(uiControl *, void *);
@property uiCheckbox *uiC;
@property void (*uiOnToggled)(uiCheckbox *, void *);
@property void *uiOnToggledData;
@end
@ -25,19 +25,65 @@
@end
static void defaultOnToggled(uiControl *c, void *data)
static void defaultOnToggled(uiCheckbox *c, void *data)
{
// do nothing
}
uiControl *uiNewCheckbox(const char *text)
static char *checkboxText(uiCheckbox *c)
{
uiControl *c;
uiCheckboxNSButton *cc;
c = uiDarwinNewControl([uiCheckboxNSButton class], NO, NO);
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
return uiDarwinNSStringToText([cc title]);
}
static void checkboxSetText(uiCheckbox *c, const char *text)
{
uiCheckboxNSButton *cc;
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
[cc setTitle:toNSString(text)];
}
static void checkboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
{
uiCheckboxNSButton *cc;
cc = (uiCheckboxNSButton *) uiControlHandle(uiCheckbox(c));
cc.uiOnToggled = f;
cc.uiOnToggledData = data;
}
static int checkboxChecked(uiCheckbox *c)
{
uiCheckboxNSButton *cc;
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
return [cc state] == NSOnState;
}
static void checkboxSetChecked(uiCheckbox *c, int checked)
{
uiCheckboxNSButton *cc;
NSInteger state;
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
state = NSOnState;
if (!checked)
state = NSOffState;
[cc setState:state];
}
uiCheckbox *uiNewCheckbox(const char *text)
{
uiCheckbox *c;
uiCheckboxNSButton *cc;
c = uiNew(uiCheckbox);
uiDarwinNewControl(uiControl(c), [uiCheckboxNSButton class], NO, NO);
cc = (uiCheckboxNSButton *) uiControlHandle(c);
cc.uiC = c;
[cc setTitle:toNSString(text)];
[cc setButtonType:NSSwitchButton];
@ -49,50 +95,13 @@ uiControl *uiNewCheckbox(const char *text)
cc.uiOnToggled = defaultOnToggled;
uiCheckbox(c)->Text = checkboxText;
uiCheckbox(c)->SetText = checkboxSetText;
uiCheckbox(c)->OnToggled = checkboxOnToggled;
uiCheckbox(c)->Checked = checkboxChecked;
uiCheckbox(c)->SetChecked = checkboxSetChecked;
cc.uiC = c;
return cc.uiC;
}
char *uiCheckboxText(uiControl *c)
{
uiCheckboxNSButton *cc;
cc = (uiCheckboxNSButton *) uiControlHandle(c);
return uiDarwinNSStringToText([cc title]);
}
void uiCheckboxSetText(uiControl *c, const char *text)
{
uiCheckboxNSButton *cc;
cc = (uiCheckboxNSButton *) uiControlHandle(c);
[cc setTitle:toNSString(text)];
}
void uiCheckboxOnToggled(uiControl *c, void (*f)(uiControl *, void *), void *data)
{
uiCheckboxNSButton *cc;
cc = (uiCheckboxNSButton *) uiControlHandle(c);
cc.uiOnToggled = f;
cc.uiOnToggledData = data;
}
int uiCheckboxChecked(uiControl *c)
{
uiCheckboxNSButton *cc;
cc = (uiCheckboxNSButton *) uiControlHandle(c);
return [cc state] == NSOnState;
}
void uiCheckboxSetChecked(uiControl *c, int checked)
{
uiCheckboxNSButton *cc;
NSInteger state;
cc = (uiCheckboxNSButton *) uiControlHandle(c);
state = NSOnState;
if (!checked)
state = NSOffState;
[cc setState:state];
}