| 1 |
#if defined(Hiro_MenuItem) |
| 2 |
|
| 3 |
@implementation CocoaMenuItem |
| 4 |
|
| 5 |
-(id) initWith:(hiro::mMenuItem&)menuItemReference { |
| 6 |
if(self = [super initWithTitle:@"" action:@selector(activate) keyEquivalent:@""]) { |
| 7 |
menuItem = &menuItemReference; |
| 8 |
|
| 9 |
[self setTarget:self]; |
| 10 |
} |
| 11 |
return self; |
| 12 |
} |
| 13 |
|
| 14 |
-(void) activate { |
| 15 |
menuItem->doActivate(); |
| 16 |
} |
| 17 |
|
| 18 |
@end |
| 19 |
|
| 20 |
namespace hiro { |
| 21 |
|
| 22 |
auto pMenuItem::construct() -> void { |
| 23 |
cocoaAction = cocoaMenuItem = [[CocoaMenuItem alloc] initWith:self()]; |
| 24 |
pAction::construct(); |
| 25 |
|
| 26 |
setIcon(state().icon); |
| 27 |
setText(state().text); |
| 28 |
} |
| 29 |
|
| 30 |
auto pMenuItem::destruct() -> void { |
| 31 |
} |
| 32 |
|
| 33 |
auto pMenuItem::setIcon(const multiFactorImage& icon, bool force) -> void { |
| 34 |
if(!force) return; |
| 35 |
u32 size = 16; //there is no API to retrieve the optimal size |
| 36 |
[cocoaAction setImage:NSMakeImage(icon, size, size)]; |
| 37 |
} |
| 38 |
|
| 39 |
auto pMenuItem::setIconForFile(const string& filename) -> void { |
| 40 |
NSImage* icon = [[NSWorkspace sharedWorkspace] iconForFile:@((const char*)filename)]; |
| 41 |
icon.size = NSMakeSize(16, 16); |
| 42 |
[cocoaAction setImage:icon]; |
| 43 |
} |
| 44 |
|
| 45 |
auto pMenuItem::setText(const string& text) -> void { |
| 46 |
[cocoaAction setTitle:[NSString stringWithUTF8String:text]]; |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
#endif |