Debian Codegraph @

phoenix/cocoa/widget/check-label.cpp

raw
1 @implementation CocoaCheckLabel : NSButton
2
3 -(id) initWith:(phoenix::CheckLabel&)checkLabelReference {
4 if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
5 checkLabel = &checkLabelReference;
6
7 [self setTarget:self];
8 [self setAction:@selector(activate:)];
9 [self setButtonType:NSSwitchButton];
10 }
11 return self;
12 }
13
14 -(IBAction) activate:(id)sender {
15 checkLabel->state.checked = [self state] != NSOffState;
16 if(checkLabel->onToggle) checkLabel->onToggle();
17 }
18
19 @end
20
21 namespace phoenix {
22
23 Size pCheckLabel::minimumSize() {
24 Size size = Font::size(checkLabel.font(), checkLabel.state.text);
25 return {size.width + 20, size.height};
26 }
27
28 void pCheckLabel::setChecked(bool checked) {
29 @autoreleasepool {
30 [cocoaView setState:checked ? NSOnState : NSOffState];
31 }
32 }
33
34 void pCheckLabel::setGeometry(Geometry geometry) {
35 pWidget::setGeometry({
36 geometry.x - 2, geometry.y,
37 geometry.width + 4, geometry.height
38 });
39 }
40
41 void pCheckLabel::setText(string text) {
42 @autoreleasepool {
43 [cocoaView setTitle:[NSString stringWithUTF8String:text]];
44 }
45 }
46
47 void pCheckLabel::constructor() {
48 @autoreleasepool {
49 cocoaView = cocoaCheckLabel = [[CocoaCheckLabel alloc] initWith:checkLabel];
50 setChecked(checkLabel.state.checked);
51 setText(checkLabel.state.text);
52 }
53 }
54
55 void pCheckLabel::destructor() {
56 @autoreleasepool {
57 [cocoaView release];
58 }
59 }
60
61 }