Debian Codegraph @

phoenix/cocoa/action/check-item.cpp

raw
1 @implementation CocoaCheckItem : NSMenuItem
2
3 -(id) initWith:(phoenix::CheckItem&)checkItemReference {
4 if(self = [super initWithTitle:@"" action:@selector(activate) keyEquivalent:@""]) {
5 checkItem = &checkItemReference;
6
7 [self setTarget:self];
8 }
9 return self;
10 }
11
12 -(void) activate {
13 checkItem->state.checked = !checkItem->state.checked;
14 auto state = checkItem->state.checked ? NSOnState : NSOffState;
15 [self setState:state];
16 if(checkItem->onToggle) checkItem->onToggle();
17 }
18
19 @end
20
21 namespace phoenix {
22
23 void pCheckItem::setChecked(bool checked) {
24 @autoreleasepool {
25 auto state = checked ? NSOnState : NSOffState;
26 [cocoaAction setState:state];
27 }
28 }
29
30 void pCheckItem::setText(string text) {
31 @autoreleasepool {
32 [cocoaAction setTitle:[NSString stringWithUTF8String:text]];
33 }
34 }
35
36 void pCheckItem::constructor() {
37 @autoreleasepool {
38 cocoaAction = cocoaCheckItem = [[CocoaCheckItem alloc] initWith:checkItem];
39 setText(checkItem.state.text);
40 }
41 }
42
43 void pCheckItem::destructor() {
44 @autoreleasepool {
45 [cocoaAction release];
46 }
47 }
48
49 }