2013-03-15 13:11:33 +00:00
|
|
|
@implementation CocoaRadioButton : NSButton
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(id) initWith:(phoenix::RadioButton&)radioButtonReference {
|
2013-03-15 13:11:33 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
|
|
|
|
radioButton = &radioButtonReference;
|
|
|
|
|
|
|
|
[self setTarget:self];
|
|
|
|
[self setAction:@selector(activate:)];
|
|
|
|
[self setButtonType:NSRadioButton];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(IBAction) activate:(id)sender {
|
2013-03-15 13:11:33 +00:00
|
|
|
radioButton->setChecked();
|
|
|
|
if(radioButton->onActivate) radioButton->onActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
namespace phoenix {
|
|
|
|
|
|
|
|
bool pRadioButton::checked() {
|
|
|
|
@autoreleasepool {
|
|
|
|
return [cocoaView state] != NSOffState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Size pRadioButton::minimumSize() {
|
|
|
|
Size size = Font::size(radioButton.font(), radioButton.state.text);
|
|
|
|
return {size.width + 24, size.height + 8};
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::setChecked() {
|
|
|
|
@autoreleasepool {
|
|
|
|
for(auto &button : radioButton.state.group) {
|
|
|
|
auto state = (&button == &radioButton) ? NSOnState : NSOffState;
|
|
|
|
[button.p.cocoaView setState:state];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::setGroup(const set<RadioButton&> &group) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::setText(const string &text) {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::constructor() {
|
|
|
|
@autoreleasepool {
|
|
|
|
cocoaView = cocoaRadioButton = [[CocoaRadioButton alloc] initWith:radioButton];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::destructor() {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|