From 7ec19d56a84db17084bab925c8e7f6955ec834e6 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 16 Apr 2015 13:51:46 -0400 Subject: [PATCH] Migrated darwin/checkbox.m. --- darwin/checkbox.m | 113 +++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 52 deletions(-) diff --git a/darwin/checkbox.m b/darwin/checkbox.m index ca52389c..42ea833a 100644 --- a/darwin/checkbox.m +++ b/darwin/checkbox.m @@ -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]; -}