diff -r 2dbc56c2323b -r e2fd132ab781 ui/cocoa/window.m --- a/ui/cocoa/window.m Sat Mar 29 19:12:07 2014 +0100 +++ b/ui/cocoa/window.m Mon Mar 31 20:22:16 2014 +0200 @@ -40,6 +40,23 @@ @implementation UiCocoaWindow +- (UiCocoaWindow*) init: (NSRect)frame object: (UiObject*)obj { + self = [self initWithContentRect:frame + styleMask:NSTitledWindowMask | + NSResizableWindowMask | + NSClosableWindowMask | + NSMiniaturizableWindowMask + backing:NSBackingStoreBuffered + defer:false]; + + uiobj = obj; + UcxAllocator *allocator = uiobj->ctx->mempool->allocator; + menus = ucx_map_new_a(allocator, 8); + items = ucx_map_new_a(allocator, 64); + + return self; +} + - (UiObject*) object { return uiobj; } @@ -50,8 +67,6 @@ - (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; @@ -76,14 +91,34 @@ } // add item + UiAbstractMenuItem *abstractItem = malloc(sizeof(UiAbstractMenuItem)); + abstractItem->update = ui_update_item; + abstractItem->item_data = windowItem; UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); - itemList = ucx_list_append_a(allocator, itemList, windowItem); + itemList = ucx_list_append_a(allocator, itemList, abstractItem); ucx_map_put(menus, ucx_key(&menu, sizeof(void*)), itemList); ucx_map_put(items, ucx_key(&windowItem->item, sizeof(void*)), windowItem); } } +- (void) setMenuItemLists:(UcxList*)itemLists { + UcxAllocator *allocator = uiobj->ctx->mempool->allocator; + + UCX_FOREACH(elm, itemLists) { + UiMenuItemList *list = elm->data; + + UiAbstractMenuItem *abstractItem = malloc(sizeof(UiAbstractMenuItem)); + abstractItem->update = ui_update_item_list; + abstractItem->item_data = list; + + UcxList *itemList = ucx_map_get(menus, ucx_key(&list->menu, sizeof(void*))); + itemList = ucx_list_append_a(allocator, itemList, abstractItem); + ucx_map_put(menus, ucx_key(&list->menu, sizeof(void*)), itemList); + + } +} + - (UiMenuItem*) getMenuItem:(NSMenuItem*)item { return ucx_map_get(items, ucx_key(&item, sizeof(void*))); } @@ -91,9 +126,8 @@ - (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]; + UiAbstractMenuItem *item = elm->data; + item->update(self, item->item_data); } } @@ -114,18 +148,21 @@ window_default_width, window_default_height); + /* UiCocoaWindow *window = [[UiCocoaWindow alloc] initWithContentRect:frame styleMask:NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask backing:NSBackingStoreBuffered defer:false]; + */ + UiCocoaWindow *window = [[UiCocoaWindow alloc] init:frame object:obj]; - [window setObject: obj]; NSString *titleStr = [[NSString alloc] initWithUTF8String:title]; [window setTitle:titleStr]; UiMenuDelegate *menuDelegate = ui_menu_delegate(); [window setMenuItems: [menuDelegate items]]; + [window setMenuItemLists: [menuDelegate lists]]; NSToolbar *toolbar = ui_create_toolbar(); [window setToolbar: toolbar];