| 1 |
@implementation CocoaMenu : NSMenuItem |
| 2 |
|
| 3 |
-(id) initWith:(phoenix::Menu&)menuReference { |
| 4 |
if(self = [super initWithTitle:@"" action:nil keyEquivalent:@""]) { |
| 5 |
menu = &menuReference; |
| 6 |
|
| 7 |
cocoaMenu = [[NSMenu alloc] initWithTitle:@""]; |
| 8 |
[self setSubmenu:cocoaMenu]; |
| 9 |
} |
| 10 |
return self; |
| 11 |
} |
| 12 |
|
| 13 |
-(NSMenu*) cocoaMenu { |
| 14 |
return cocoaMenu; |
| 15 |
} |
| 16 |
|
| 17 |
@end |
| 18 |
|
| 19 |
namespace phoenix { |
| 20 |
|
| 21 |
void pMenu::append(Action& action) { |
| 22 |
@autoreleasepool { |
| 23 |
[[cocoaAction cocoaMenu] addItem:action.p.cocoaAction]; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
void pMenu::remove(Action& action) { |
| 28 |
@autoreleasepool { |
| 29 |
[[cocoaAction cocoaMenu] removeItem:action.p.cocoaAction]; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
void pMenu::setImage(const image& image) { |
| 34 |
@autoreleasepool { |
| 35 |
unsigned size = 15; //there is no API to retrieve the optimal size |
| 36 |
[cocoaAction setImage:NSMakeImage(image, size, size)]; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
void pMenu::setText(string text) { |
| 41 |
@autoreleasepool { |
| 42 |
[[cocoaAction cocoaMenu] setTitle:[NSString stringWithUTF8String:text]]; |
| 43 |
[cocoaAction setTitle:[NSString stringWithUTF8String:text]]; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
void pMenu::constructor() { |
| 48 |
@autoreleasepool { |
| 49 |
cocoaAction = cocoaMenu = [[CocoaMenu alloc] initWith:menu]; |
| 50 |
setText(menu.state.text); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
void pMenu::destructor() { |
| 55 |
@autoreleasepool { |
| 56 |
[[cocoaAction cocoaMenu] release]; |
| 57 |
[cocoaAction release]; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
} |