2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_RadioLabel)
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
@implementation CocoaRadioLabel : NSButton
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
-(id) initWith:(hiro::mRadioLabel&)radioLabelReference {
|
2013-11-28 10:29:01 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
|
|
|
|
radioLabel = &radioLabelReference;
|
|
|
|
|
|
|
|
[self setTarget:self];
|
|
|
|
[self setAction:@selector(activate:)];
|
|
|
|
[self setButtonType:NSRadioButton];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(IBAction) activate:(id)sender {
|
|
|
|
radioLabel->setChecked();
|
2015-12-30 06:41:46 +00:00
|
|
|
radioLabel->doActivate();
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
auto pRadioLabel::construct() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
cocoaView = cocoaRadioLabel = [[CocoaRadioLabel alloc] initWith:self()];
|
|
|
|
pWidget::construct();
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
if(state().checked) setChecked();
|
|
|
|
setText(state().text);
|
|
|
|
}
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pRadioLabel::destruct() -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
2016-01-07 08:14:33 +00:00
|
|
|
[cocoaView removeFromSuperview];
|
2015-12-30 06:41:46 +00:00
|
|
|
[cocoaView release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pRadioLabel::minimumSize() const -> Size {
|
|
|
|
Size size = pFont::size(self().font(true), state().text);
|
|
|
|
return {size.width() + 22, size.height()};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pRadioLabel::setChecked() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
if(auto group = state().group) {
|
|
|
|
for(auto& weak : group->state.objects) {
|
|
|
|
if(auto object = weak.acquire()) {
|
|
|
|
if(auto self = object->self()) {
|
|
|
|
if(auto p = dynamic_cast<pRadioLabel*>(self)) {
|
|
|
|
auto state = this == p ? NSOnState : NSOffState;
|
|
|
|
[p->cocoaView setState:state];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pRadioLabel::setGeometry(Geometry geometry) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
pWidget::setGeometry({
|
2015-12-30 06:41:46 +00:00
|
|
|
geometry.x() - 1, geometry.y(),
|
|
|
|
geometry.width() + 2, geometry.height()
|
2013-11-28 10:29:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pRadioLabel::setGroup(sGroup group) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pRadioLabel::setText(const string& text) -> void {
|
2013-11-28 10:29:01 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
#endif
|