Migrated darwin/checkbox.m and fixed some things in darwin/button.m.
This commit is contained in:
parent
2fa8bfd95b
commit
b28c020bdd
|
@ -7,6 +7,7 @@
|
||||||
void *onClickedData;
|
void *onClickedData;
|
||||||
}
|
}
|
||||||
- (IBAction)buttonClicked:(id)sender;
|
- (IBAction)buttonClicked:(id)sender;
|
||||||
|
- (void)setButton(uiButton *)b;
|
||||||
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data;
|
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -19,6 +20,11 @@ uiLogObjCClassAllocations
|
||||||
(*(self->onClicked))(self->b, self->onClickedData);
|
(*(self->onClicked))(self->b, self->onClickedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setButton:(uiButton *)b
|
||||||
|
{
|
||||||
|
self->b = b;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data
|
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data
|
||||||
{
|
{
|
||||||
self->onClicked = f;
|
self->onClicked = f;
|
||||||
|
@ -40,7 +46,7 @@ static void defaultOnClicked(uiButton *c, void *data)
|
||||||
|
|
||||||
static void destroy(void *data)
|
static void destroy(void *data)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) bb;
|
struct button *b = (struct button *) data;
|
||||||
|
|
||||||
[b->button setTarget:nil];
|
[b->button setTarget:nil];
|
||||||
[b->delegate release];
|
[b->delegate release];
|
||||||
|
@ -87,6 +93,7 @@ uiButton *uiNewButton(const char *text)
|
||||||
b->delegate = [uipButtonDelegate new];
|
b->delegate = [uipButtonDelegate new];
|
||||||
[b->button setTarget:b->delegate];
|
[b->button setTarget:b->delegate];
|
||||||
[b->button setAction:@selector(buttonClicked:)];
|
[b->button setAction:@selector(buttonClicked:)];
|
||||||
|
[b->delegate setButton:uiButton(b)];
|
||||||
[b->delegate setOnClicked:defaultOnClicked data:NULL];
|
[b->delegate setOnClicked:defaultOnClicked data:NULL];
|
||||||
|
|
||||||
uiButton(b)->Text = buttonText;
|
uiButton(b)->Text = buttonText;
|
||||||
|
|
|
@ -1,99 +1,117 @@
|
||||||
// 7 april 2015
|
// 7 april 2015
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
@interface uiCheckboxNSButton : NSButton
|
@interface uipCheckboxDelegate : NSObject {
|
||||||
@property uiCheckbox *uiC;
|
uiCheckbox *c;
|
||||||
@property void (*uiOnToggled)(uiCheckbox *, void *);
|
void (*onToggled)(uiCheckbox *, void *);
|
||||||
@property void *uiOnToggledData;
|
void *onToggledData;
|
||||||
|
}
|
||||||
|
- (IBAction)checkboxToggled:(id)sender;
|
||||||
|
- (void)setCheckbox:(uiCheckbox *)c;
|
||||||
|
- (void)setOnToggled:(void (*)(uiCheckbox *, void *))f data:(void *)data;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation uiCheckboxNSButton
|
@implementation uipCheckboxDelegate
|
||||||
|
|
||||||
- (void)viewDidMoveToSuperview
|
uiLogObjCClassAllocations
|
||||||
|
|
||||||
|
- (IBAction)checkboxToggled:(id)sender
|
||||||
{
|
{
|
||||||
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiC), [self superview])) {
|
(*(self->onToggled))(self->c, self->onToggledData);
|
||||||
[self setTarget:nil];
|
|
||||||
self.uiC = NULL;
|
|
||||||
}
|
|
||||||
[super viewDidMoveToSuperview];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)uiCheckboxToggled:(id)sender
|
- (void)setCheckbox:(uiCheckbox *)c
|
||||||
{
|
{
|
||||||
(*(self.uiOnToggled))(self.uiC, self.uiOnToggledData);
|
self->c = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setOnToggled:(void (*)(uiCheckbox *, void *))f data:(void *)data
|
||||||
|
{
|
||||||
|
self->onToggled = f;
|
||||||
|
self->onToggledData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
struct checkbox {
|
||||||
|
uiCheckbox c;
|
||||||
|
NSButton *checkbox;
|
||||||
|
uipCheckboxDelegate *delegate;
|
||||||
|
};
|
||||||
|
|
||||||
static void defaultOnToggled(uiCheckbox *c, void *data)
|
static void defaultOnToggled(uiCheckbox *c, void *data)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *checkboxText(uiCheckbox *c)
|
static void destroy(void *data)
|
||||||
{
|
{
|
||||||
uiCheckboxNSButton *cc;
|
struct checkbox *c = (struct checkbox *) data;
|
||||||
|
|
||||||
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
|
[c->checkbox setTarget:nil];
|
||||||
return uiDarwinNSStringToText([cc title]);
|
[c->delegate release];
|
||||||
|
uiFree(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkboxSetText(uiCheckbox *c, const char *text)
|
static char *checkboxText(uiCheckbox *cc)
|
||||||
{
|
{
|
||||||
uiCheckboxNSButton *cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
|
return uiDarwinNSStringToText([c->checkbox title]);
|
||||||
[cc setTitle:toNSString(text)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
|
static void checkboxSetText(uiCheckbox *cc, const char *text)
|
||||||
{
|
{
|
||||||
uiCheckboxNSButton *cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
|
[c->checkbox setTitle:toNSString(text)];
|
||||||
cc.uiOnToggled = f;
|
|
||||||
cc.uiOnToggledData = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int checkboxChecked(uiCheckbox *c)
|
static void checkboxOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data)
|
||||||
{
|
{
|
||||||
uiCheckboxNSButton *cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
|
[c->delegate setOnToggled:f data:data];
|
||||||
return [cc state] == NSOnState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkboxSetChecked(uiCheckbox *c, int checked)
|
static int checkboxChecked(uiCheckbox *cc)
|
||||||
{
|
{
|
||||||
uiCheckboxNSButton *cc;
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
|
|
||||||
|
return [c->checkbox state] == NSOnState;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void checkboxSetChecked(uiCheckbox *cc, int checked)
|
||||||
|
{
|
||||||
|
struct checkbox *c = (struct checkbox *) cc;
|
||||||
NSInteger state;
|
NSInteger state;
|
||||||
|
|
||||||
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
|
|
||||||
state = NSOnState;
|
state = NSOnState;
|
||||||
if (!checked)
|
if (!checked)
|
||||||
state = NSOffState;
|
state = NSOffState;
|
||||||
[cc setState:state];
|
[c->checkbox setState:state];
|
||||||
}
|
}
|
||||||
|
|
||||||
uiCheckbox *uiNewCheckbox(const char *text)
|
uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
{
|
{
|
||||||
uiCheckbox *c;
|
uiCheckbox *c;
|
||||||
uiCheckboxNSButton *cc;
|
|
||||||
|
|
||||||
c = uiNew(uiCheckbox);
|
c = uiNew(uiCheckbox);
|
||||||
|
|
||||||
uiDarwinNewControl(uiControl(c), [uiCheckboxNSButton class], NO, NO);
|
uiDarwinNewControl(uiControl(c), [uiCheckboxNSButton class], NO, NO, destroy, NULL);
|
||||||
cc = (uiCheckboxNSButton *) uiControlHandle(uiControl(c));
|
|
||||||
|
|
||||||
[cc setTitle:toNSString(text)];
|
c->checkbox = (NSButton *) VIEW(c);
|
||||||
[cc setButtonType:NSSwitchButton];
|
|
||||||
[cc setBordered:NO];
|
|
||||||
setStandardControlFont((NSControl *) cc);
|
|
||||||
|
|
||||||
[cc setTarget:cc];
|
[c-checkbox setTitle:toNSString(text)];
|
||||||
[cc setAction:@selector(uiCheckboxToggled:)];
|
[c->checkbox setButtonType:NSSwitchButton];
|
||||||
|
[c->checkbox setBordered:NO];
|
||||||
|
setStandardControlFont(c->checkbox);
|
||||||
|
|
||||||
cc.uiOnToggled = defaultOnToggled;
|
c->delegate = [uipCheckboxDelegate new];
|
||||||
|
[c->checkbox setTarget:c->delegate];
|
||||||
|
[c->checkbox setAction:@selector(checkboxToggled:)];
|
||||||
|
[c->delegate setCheckbox:uiCheckbox(c)];
|
||||||
|
[c->delegate setOnToggled:defaultOnToggled data:NULL];
|
||||||
|
|
||||||
uiCheckbox(c)->Text = checkboxText;
|
uiCheckbox(c)->Text = checkboxText;
|
||||||
uiCheckbox(c)->SetText = checkboxSetText;
|
uiCheckbox(c)->SetText = checkboxSetText;
|
||||||
|
@ -101,7 +119,5 @@ uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
uiCheckbox(c)->Checked = checkboxChecked;
|
uiCheckbox(c)->Checked = checkboxChecked;
|
||||||
uiCheckbox(c)->SetChecked = checkboxSetChecked;
|
uiCheckbox(c)->SetChecked = checkboxSetChecked;
|
||||||
|
|
||||||
cc.uiC = c;
|
return uiCheckbox(c);
|
||||||
|
|
||||||
return cc.uiC;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue