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);
|
2013-04-09 13:31:46 +00:00
|
|
|
return {size.width + 22, size.height};
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::setChecked() {
|
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& button : radioButton.state.group) {
|
2013-03-15 13:11:33 +00:00
|
|
|
auto state = (&button == &radioButton) ? NSOnState : NSOffState;
|
|
|
|
[button.p.cocoaView setState:state];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
void pRadioButton::setGeometry(const Geometry& geometry) {
|
2013-04-09 13:31:46 +00:00
|
|
|
pWidget::setGeometry({
|
|
|
|
geometry.x - 1, geometry.y,
|
|
|
|
geometry.width + 2, geometry.height
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
void pRadioButton::setGroup(const group<RadioButton>& group) {
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
void pRadioButton::setText(const string& text) {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::constructor() {
|
|
|
|
@autoreleasepool {
|
|
|
|
cocoaView = cocoaRadioButton = [[CocoaRadioButton alloc] initWith:radioButton];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::destructor() {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|