| 1 |
#if defined(Hiro_MenuRadioItem) |
| 2 |
|
| 3 |
@implementation CocoaMenuRadioItem |
| 4 |
|
| 5 |
-(id) initWith:(hiro::mMenuRadioItem&)menuRadioItemReference { |
| 6 |
if(self = [super initWithTitle:@"" action:@selector(activate) keyEquivalent:@""]) { |
| 7 |
menuRadioItem = &menuRadioItemReference; |
| 8 |
|
| 9 |
[self setTarget:self]; |
| 10 |
//todo: the default image is a check mark, which is not indicative of radio states. |
| 11 |
//however, NSMenuRadio does not respect macOS' dark theme, and is barely visible. |
| 12 |
//[self setOnStateImage:[NSImage imageNamed:@"NSMenuRadio"]]; |
| 13 |
} |
| 14 |
return self; |
| 15 |
} |
| 16 |
|
| 17 |
-(void) activate { |
| 18 |
menuRadioItem->setChecked(); |
| 19 |
menuRadioItem->doActivate(); |
| 20 |
} |
| 21 |
|
| 22 |
@end |
| 23 |
|
| 24 |
namespace hiro { |
| 25 |
|
| 26 |
auto pMenuRadioItem::construct() -> void { |
| 27 |
cocoaAction = cocoaMenuRadioItem = [[CocoaMenuRadioItem alloc] initWith:self()]; |
| 28 |
pAction::construct(); |
| 29 |
|
| 30 |
if(state().checked) setChecked(); |
| 31 |
setText(state().text); |
| 32 |
} |
| 33 |
|
| 34 |
auto pMenuRadioItem::destruct() -> void { |
| 35 |
} |
| 36 |
|
| 37 |
auto pMenuRadioItem::setChecked() -> void { |
| 38 |
if(auto group = state().group) { |
| 39 |
for(auto& weak : group->state.objects) { |
| 40 |
if(auto object = weak.lock()) { |
| 41 |
if(auto self = object->self()) { |
| 42 |
if(auto p = dynamic_cast<pMenuRadioItem*>(self)) { |
| 43 |
auto state = this == p ? NSControlStateValueOn : NSControlStateValueOff; |
| 44 |
[p->cocoaAction setState:state]; |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
auto pMenuRadioItem::setGroup(sGroup group) -> void { |
| 53 |
} |
| 54 |
|
| 55 |
auto pMenuRadioItem::setText(const string& text) -> void { |
| 56 |
[cocoaAction setTitle:[NSString stringWithUTF8String:text]]; |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
#endif |