menu-item.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #if defined(Hiro_MenuItem)
  2. @implementation CocoaMenuItem : NSMenuItem
  3. -(id) initWith:(hiro::mMenuItem&)menuItemReference {
  4. if(self = [super initWithTitle:@"" action:@selector(activate) keyEquivalent:@""]) {
  5. menuItem = &menuItemReference;
  6. [self setTarget:self];
  7. }
  8. return self;
  9. }
  10. -(void) activate {
  11. menuItem->doActivate();
  12. }
  13. @end
  14. namespace hiro {
  15. auto pMenuItem::construct() -> void {
  16. @autoreleasepool {
  17. cocoaAction = cocoaMenuItem = [[CocoaMenuItem alloc] initWith:self()];
  18. pAction::construct();
  19. setIcon(state().icon);
  20. setText(state().text);
  21. }
  22. }
  23. auto pMenuItem::destruct() -> void {
  24. @autoreleasepool {
  25. [cocoaAction release];
  26. }
  27. }
  28. auto pMenuItem::setIcon(const image& icon) -> void {
  29. @autoreleasepool {
  30. uint size = 15; //there is no API to retrieve the optimal size
  31. [cocoaAction setImage:NSMakeImage(icon, size, size)];
  32. }
  33. }
  34. auto pMenuItem::setText(const string& text) -> void {
  35. @autoreleasepool {
  36. [cocoaAction setTitle:[NSString stringWithUTF8String:text]];
  37. }
  38. }
  39. }
  40. #endif