1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// 7 april 2015
#import "uipriv_darwin.h"
@interface uiCheckboxNSButton : NSButton
@property uiCheckbox *uiC;
@property void (*uiOnToggled)(uiCheckbox *, void *);
@property void *uiOnToggledData;
@end
@implementation uiCheckboxNSButton
- (void)viewDidMoveToSuperview
{
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiC), [self superview])) {
[self setTarget:nil];
self.uiC = NULL;
}
[super viewDidMoveToSuperview];
}
- (IBAction)uiCheckboxToggled:(id)sender
{
(*(self.uiOnToggled))(self.uiC, self.uiOnToggledData);
}
@end
static void defaultOnToggled(uiCheckbox *c, void *data)
{
// do nothing
}
static char *checkboxText(uiCheckbox *c)
{
uiCheckboxNSButton *cc;
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(uiControl(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(uiControl(c));
[cc setTitle:toNSString(text)];
[cc setButtonType:NSSwitchButton];
[cc setBordered:NO];
setStandardControlFont((NSControl *) cc);
[cc setTarget:cc];
[cc setAction:@selector(uiCheckboxToggled:)];
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;
}
|