diff -r 2dbc56c2323b -r e2fd132ab781 ui/cocoa/menu.m --- a/ui/cocoa/menu.m Sat Mar 29 19:12:07 2014 +0100 +++ b/ui/cocoa/menu.m Mon Mar 31 20:22:16 2014 +0200 @@ -37,6 +37,7 @@ - (UiMenuDelegate*) init { items = NULL; + itemlists = NULL; return self; } @@ -52,16 +53,34 @@ items = ucx_list_append(items, i); } +- (void) addList:(UiList*) list menu:(NSMenu*)menu index: (int)i callback: (ui_callback)f data:(void*) data { + UiMenuItemList *itemList = malloc(sizeof(UiMenuItemList)); + itemList->list = list; + itemList->menu = menu; + itemList->first = NULL; + itemList->index = i; + itemList->oldcount = 0; + itemList->callback = f; + itemList->data = data; + itemlists = ucx_list_append(itemlists, itemList); +} + - (UcxList*) items { return items; } +- (UcxList*) lists { + return itemlists; + +} + @end static NSMenu *currentMenu = NULL; +static int currentItemIndex = 0; static UiMenuDelegate *delegate; void ui_menu_init() { @@ -83,6 +102,7 @@ [[NSApp mainMenu] setSubmenu:menu forItem:menuItem]; currentMenu = menu; + currentItemIndex = 0; } void ui_menuitem(char *label, ui_callback f, void *data) { @@ -94,6 +114,7 @@ [item setTarget:event]; //[delegate addItem: item]; + currentItemIndex++; } void ui_checkitem(char *label, ui_callback f, void *data) { @@ -105,6 +126,7 @@ [item setTarget:event]; [delegate addItem: item var:NULL]; + currentItemIndex++; } void ui_checkitem_nv(char *label, char *vname) { @@ -116,10 +138,16 @@ [item setTarget:event]; [delegate addItem: item var:vname]; + currentItemIndex++; } void ui_menuseparator() { - + [currentMenu addItem: [NSMenuItem separatorItem]]; + currentItemIndex++; +} + +void ui_menuitem_list (UiList *items, ui_callback f, void *data) { + [delegate addList:items menu:currentMenu index:currentItemIndex callback:f data:data]; } @@ -136,3 +164,38 @@ i->value = value; item->state = value; } + + +int ui_update_item(UiCocoaWindow *window, void *data) { + UiMenuItem *item = data; + [item->item setState: item->state]; + return 0; +} + +int ui_update_item_list(UiCocoaWindow *window, void *data) { + printf("update list\n"); + + UiMenuItemList *itemList = data; + UiList *list = itemList->list; + + printf("oldcount: %d\n", itemList->oldcount); + for(int r=0;roldcount;r++) { + [itemList->menu removeItemAtIndex:itemList->index]; + } + + char *str = ui_list_first(list); + int i = itemList->index; + [itemList->menu insertItem: [NSMenuItem separatorItem] atIndex: i]; + i++; + do { + NSString *title = [[NSString alloc] initWithUTF8String:str]; + NSMenuItem *item = [[NSMenuItem alloc]initWithTitle:title action:@selector(handleStateEvent:) keyEquivalent:@""]; + + [itemList->menu insertItem:item atIndex:i]; + i++; + } while ((str = ui_list_next(list))); + + itemList->oldcount = i - itemList->index; + + return 0; +}