Debian Codegraph @

phoenix/cocoa/widget/radio-label.cpp

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