diff -r 84a541c6e093 -r 6f263196f916 ui/cocoa/window.m --- a/ui/cocoa/window.m Wed Mar 26 15:53:43 2014 +0100 +++ b/ui/cocoa/window.m Fri Mar 28 20:03:01 2014 +0100 @@ -29,6 +29,7 @@ #include #import "window.h" +#import "menu.h" #import "toolbar.h" #import "container.h" #import "../../ucx/mempool.h" @@ -47,6 +48,55 @@ uiobj = obj; } +- (void) setMenuItems:(UcxList*)menuItems { + UcxAllocator *allocator = uiobj->ctx->mempool->allocator; + menus = ucx_map_new_a(allocator, 8); + items = ucx_map_new_a(allocator, 64); + + UCX_FOREACH(elm, menuItems) { + UiStateItem *item = elm->data; + NSMenu *menu = [item->item menu]; + + // create UiMenuItem which represents an NSMenuItem for a Window + UiMenuItem *windowItem = ucx_mempool_malloc(uiobj->ctx->mempool, sizeof(UiMenuItem)); + windowItem->item = item->item; + windowItem->state = 0; + if(item->var) { + // bind value + UiVar *var = uic_connect_var(uiobj->ctx, item->var, UI_VAR_INTEGER); + if(var) { + UiInteger *value = var->value; + value->obj = windowItem; + value->get = ui_menuitem_get; + value->set = ui_menuitem_set; + value = 0; + } else { + // TODO: error + } + } + + // add item + UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); + itemList = ucx_list_append_a(allocator, itemList, windowItem); + ucx_map_put(menus, ucx_key(&menu, sizeof(void*)), itemList); + + ucx_map_put(items, ucx_key(&windowItem->item, sizeof(void*)), windowItem); + } +} + +- (UiMenuItem*) getMenuItem:(NSMenuItem*)item { + return ucx_map_get(items, ucx_key(&item, sizeof(void*))); +} + +- (void) updateMenu:(NSMenu*)menu { + UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); + UCX_FOREACH(elm, itemList) { + UiMenuItem *item = elm->data; + + [item->item setState: item->state]; + } +} + @end @@ -74,6 +124,9 @@ NSString *titleStr = [[NSString alloc] initWithUTF8String:title]; [window setTitle:titleStr]; + UiMenuDelegate *menuDelegate = ui_menu_delegate(); + [window setMenuItems: [menuDelegate items]]; + NSToolbar *toolbar = ui_create_toolbar(); [window setToolbar: toolbar];