diff -r 80609f9675f1 -r 3335268a8073 ui/cocoa/menu.m --- a/ui/cocoa/menu.m Mon May 23 12:28:32 2016 +0200 +++ b/ui/cocoa/menu.m Wed Jul 13 15:14:09 2016 +0200 @@ -118,7 +118,10 @@ @end -static NSMenu *currentMenu = NULL; +//static NSMenu *currentMenu = NULL; + +static UcxList *current; + static int currentItemIndex = 0; static UiMenuDelegate *delegate; @@ -141,8 +144,34 @@ [menu setAutoenablesItems:NO]; [[NSApp mainMenu] setSubmenu:menu forItem:menuItem]; - currentMenu = menu; + //currentMenu = menu; currentItemIndex = 0; + + current = ucx_list_prepend(NULL, menu); +} + +void ui_submenu(char *title) { + NSString *str = [[NSString alloc] initWithUTF8String:title]; + NSMenu *currentMenu = current->data; + + NSMenu *menu = [[NSMenu alloc] initWithTitle: str]; + NSMenuItem *menuItem = [currentMenu addItemWithTitle:str + action:nil keyEquivalent:@""]; + [menu setDelegate: delegate]; + [menu setAutoenablesItems:NO]; + + [currentMenu setSubmenu:menu forItem:menuItem]; + //currentMenu = menu; + currentItemIndex = 0; + + current = ucx_list_prepend(current, menu); +} + +void ui_submenu_end() { + if(ucx_list_size(current) < 2) { + return; + } + current = ucx_list_remove(current, current); } void ui_menuitem(char *label, ui_callback f, void *data) { @@ -169,6 +198,7 @@ } va_end(ap); + NSMenu *currentMenu = current->data; [currentMenu addItem:item]; currentItemIndex++; @@ -192,6 +222,7 @@ } va_end(ap); + NSMenu *currentMenu = current->data; [currentMenu addItem:item]; currentItemIndex++; @@ -201,6 +232,7 @@ EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f]; NSString *str = [[NSString alloc] initWithUTF8String:label]; + NSMenu *currentMenu = current->data; NSMenuItem *item = [currentMenu addItemWithTitle:str action:@selector(handleStateEvent:) keyEquivalent:@""]; [item setTarget:event]; @@ -213,6 +245,7 @@ EventWrapper *event = [[EventWrapper alloc]initWithData:NULL callback:NULL]; NSString *str = [[NSString alloc] initWithUTF8String:label]; + NSMenu *currentMenu = current->data; NSMenuItem *item = [currentMenu addItemWithTitle:str action:@selector(handleStateEvent:) keyEquivalent:@""]; [item setTarget:event]; @@ -222,11 +255,13 @@ } void ui_menuseparator() { + NSMenu *currentMenu = current->data; [currentMenu addItem: [NSMenuItem separatorItem]]; currentItemIndex++; } void ui_menuitem_list (UiList *items, ui_callback f, void *data) { + NSMenu *currentMenu = current->data; [delegate addList:items menu:currentMenu index:currentItemIndex callback:f data:data]; }