43 return uiobj; |
44 return uiobj; |
44 } |
45 } |
45 |
46 |
46 - (void) setObject:(UiObject*)obj { |
47 - (void) setObject:(UiObject*)obj { |
47 uiobj = obj; |
48 uiobj = obj; |
|
49 } |
|
50 |
|
51 - (void) setMenuItems:(UcxList*)menuItems { |
|
52 UcxAllocator *allocator = uiobj->ctx->mempool->allocator; |
|
53 menus = ucx_map_new_a(allocator, 8); |
|
54 items = ucx_map_new_a(allocator, 64); |
|
55 |
|
56 UCX_FOREACH(elm, menuItems) { |
|
57 UiStateItem *item = elm->data; |
|
58 NSMenu *menu = [item->item menu]; |
|
59 |
|
60 // create UiMenuItem which represents an NSMenuItem for a Window |
|
61 UiMenuItem *windowItem = ucx_mempool_malloc(uiobj->ctx->mempool, sizeof(UiMenuItem)); |
|
62 windowItem->item = item->item; |
|
63 windowItem->state = 0; |
|
64 if(item->var) { |
|
65 // bind value |
|
66 UiVar *var = uic_connect_var(uiobj->ctx, item->var, UI_VAR_INTEGER); |
|
67 if(var) { |
|
68 UiInteger *value = var->value; |
|
69 value->obj = windowItem; |
|
70 value->get = ui_menuitem_get; |
|
71 value->set = ui_menuitem_set; |
|
72 value = 0; |
|
73 } else { |
|
74 // TODO: error |
|
75 } |
|
76 } |
|
77 |
|
78 // add item |
|
79 UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); |
|
80 itemList = ucx_list_append_a(allocator, itemList, windowItem); |
|
81 ucx_map_put(menus, ucx_key(&menu, sizeof(void*)), itemList); |
|
82 |
|
83 ucx_map_put(items, ucx_key(&windowItem->item, sizeof(void*)), windowItem); |
|
84 } |
|
85 } |
|
86 |
|
87 - (UiMenuItem*) getMenuItem:(NSMenuItem*)item { |
|
88 return ucx_map_get(items, ucx_key(&item, sizeof(void*))); |
|
89 } |
|
90 |
|
91 - (void) updateMenu:(NSMenu*)menu { |
|
92 UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); |
|
93 UCX_FOREACH(elm, itemList) { |
|
94 UiMenuItem *item = elm->data; |
|
95 |
|
96 [item->item setState: item->state]; |
|
97 } |
48 } |
98 } |
49 |
99 |
50 @end |
100 @end |
51 |
101 |
52 |
102 |
72 |
122 |
73 [window setObject: obj]; |
123 [window setObject: obj]; |
74 NSString *titleStr = [[NSString alloc] initWithUTF8String:title]; |
124 NSString *titleStr = [[NSString alloc] initWithUTF8String:title]; |
75 [window setTitle:titleStr]; |
125 [window setTitle:titleStr]; |
76 |
126 |
|
127 UiMenuDelegate *menuDelegate = ui_menu_delegate(); |
|
128 [window setMenuItems: [menuDelegate items]]; |
|
129 |
77 NSToolbar *toolbar = ui_create_toolbar(); |
130 NSToolbar *toolbar = ui_create_toolbar(); |
78 [window setToolbar: toolbar]; |
131 [window setToolbar: toolbar]; |
79 |
132 |
80 obj->widget = (NSView*)window; |
133 obj->widget = (NSView*)window; |
81 obj->window = window_data; |
134 obj->window = window_data; |