Debian Codegraph @

phoenix/cocoa/widget/radio-button.cpp

raw
1 @implementation CocoaRadioButton : NSButton
2
3 -(id) initWith:(phoenix::RadioButton&)radioButtonReference {
4 if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
5 radioButton = &radioButtonReference;
6
7 [self setTarget:self];
8 [self setAction:@selector(activate:)];
9 [self setBezelStyle:NSRegularSquareBezelStyle];
10 [self setButtonType:NSOnOffButton];
11 }
12 return self;
13 }
14
15 -(IBAction) activate:(id)sender {
16 bool wasChecked = radioButton->state.checked;
17 radioButton->setChecked();
18 if(wasChecked == false) {
19 if(radioButton->onActivate) radioButton->onActivate();
20 }
21 }
22
23 @end
24
25 namespace phoenix {
26
27 Size pRadioButton::minimumSize() {
28 Size size = Font::size(radioButton.font(), radioButton.state.text);
29
30 if(radioButton.state.orientation == Orientation::Horizontal) {
31 size.width += radioButton.state.image.width;
32 size.height = max(radioButton.state.image.height, size.height);
33 }
34
35 if(radioButton.state.orientation == Orientation::Vertical) {
36 size.width = max(radioButton.state.image.width, size.width);
37 size.height += radioButton.state.image.height;
38 }
39
40 return {size.width + 20, size.height + 4};
41 }
42
43 void pRadioButton::setChecked() {
44 @autoreleasepool {
45 for(auto& button : radioButton.state.group) {
46 auto state = (&button == &radioButton) ? NSOnState : NSOffState;
47 [button.p.cocoaView setState:state];
48 }
49 }
50 }
51
52 void pRadioButton::setGeometry(Geometry geometry) {
53 pWidget::setGeometry({
54 geometry.x - 2, geometry.y - 2,
55 geometry.width + 4, geometry.height + 4
56 });
57 }
58
59 void pRadioButton::setGroup(const group<RadioButton>& group) {
60 }
61
62 void pRadioButton::setImage(const image& image, Orientation orientation) {
63 @autoreleasepool {
64 if(image.empty()) {
65 [cocoaView setImage:nil];
66 return;
67 }
68
69 [cocoaView setImage:NSMakeImage(image)];
70
71 if(orientation == Orientation::Horizontal) [cocoaView setImagePosition:NSImageLeft];
72 if(orientation == Orientation::Vertical ) [cocoaView setImagePosition:NSImageAbove];
73 }
74 }
75
76 void pRadioButton::setText(string text) {
77 @autoreleasepool {
78 [cocoaView setTitle:[NSString stringWithUTF8String:text]];
79 }
80 }
81
82 void pRadioButton::constructor() {
83 @autoreleasepool {
84 cocoaView = cocoaRadioButton = [[CocoaRadioButton alloc] initWith:radioButton];
85 }
86 }
87
88 void pRadioButton::destructor() {
89 @autoreleasepool {
90 [cocoaView release];
91 }
92 }
93
94 }