38 static int window_default_width = 600; |
38 static int window_default_width = 600; |
39 static int window_default_height = 500; |
39 static int window_default_height = 500; |
40 |
40 |
41 @implementation UiCocoaWindow |
41 @implementation UiCocoaWindow |
42 |
42 |
|
43 - (UiCocoaWindow*) init: (NSRect)frame object: (UiObject*)obj { |
|
44 self = [self initWithContentRect:frame |
|
45 styleMask:NSTitledWindowMask | |
|
46 NSResizableWindowMask | |
|
47 NSClosableWindowMask | |
|
48 NSMiniaturizableWindowMask |
|
49 backing:NSBackingStoreBuffered |
|
50 defer:false]; |
|
51 |
|
52 uiobj = obj; |
|
53 UcxAllocator *allocator = uiobj->ctx->mempool->allocator; |
|
54 menus = ucx_map_new_a(allocator, 8); |
|
55 items = ucx_map_new_a(allocator, 64); |
|
56 |
|
57 return self; |
|
58 } |
|
59 |
43 - (UiObject*) object { |
60 - (UiObject*) object { |
44 return uiobj; |
61 return uiobj; |
45 } |
62 } |
46 |
63 |
47 - (void) setObject:(UiObject*)obj { |
64 - (void) setObject:(UiObject*)obj { |
48 uiobj = obj; |
65 uiobj = obj; |
49 } |
66 } |
50 |
67 |
51 - (void) setMenuItems:(UcxList*)menuItems { |
68 - (void) setMenuItems:(UcxList*)menuItems { |
52 UcxAllocator *allocator = uiobj->ctx->mempool->allocator; |
69 UcxAllocator *allocator = uiobj->ctx->mempool->allocator; |
53 menus = ucx_map_new_a(allocator, 8); |
|
54 items = ucx_map_new_a(allocator, 64); |
|
55 |
70 |
56 UCX_FOREACH(elm, menuItems) { |
71 UCX_FOREACH(elm, menuItems) { |
57 UiStateItem *item = elm->data; |
72 UiStateItem *item = elm->data; |
58 NSMenu *menu = [item->item menu]; |
73 NSMenu *menu = [item->item menu]; |
59 |
74 |
74 // TODO: error |
89 // TODO: error |
75 } |
90 } |
76 } |
91 } |
77 |
92 |
78 // add item |
93 // add item |
|
94 UiAbstractMenuItem *abstractItem = malloc(sizeof(UiAbstractMenuItem)); |
|
95 abstractItem->update = ui_update_item; |
|
96 abstractItem->item_data = windowItem; |
79 UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); |
97 UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); |
80 itemList = ucx_list_append_a(allocator, itemList, windowItem); |
98 itemList = ucx_list_append_a(allocator, itemList, abstractItem); |
81 ucx_map_put(menus, ucx_key(&menu, sizeof(void*)), itemList); |
99 ucx_map_put(menus, ucx_key(&menu, sizeof(void*)), itemList); |
82 |
100 |
83 ucx_map_put(items, ucx_key(&windowItem->item, sizeof(void*)), windowItem); |
101 ucx_map_put(items, ucx_key(&windowItem->item, sizeof(void*)), windowItem); |
|
102 } |
|
103 } |
|
104 |
|
105 - (void) setMenuItemLists:(UcxList*)itemLists { |
|
106 UcxAllocator *allocator = uiobj->ctx->mempool->allocator; |
|
107 |
|
108 UCX_FOREACH(elm, itemLists) { |
|
109 UiMenuItemList *list = elm->data; |
|
110 |
|
111 UiAbstractMenuItem *abstractItem = malloc(sizeof(UiAbstractMenuItem)); |
|
112 abstractItem->update = ui_update_item_list; |
|
113 abstractItem->item_data = list; |
|
114 |
|
115 UcxList *itemList = ucx_map_get(menus, ucx_key(&list->menu, sizeof(void*))); |
|
116 itemList = ucx_list_append_a(allocator, itemList, abstractItem); |
|
117 ucx_map_put(menus, ucx_key(&list->menu, sizeof(void*)), itemList); |
|
118 |
84 } |
119 } |
85 } |
120 } |
86 |
121 |
87 - (UiMenuItem*) getMenuItem:(NSMenuItem*)item { |
122 - (UiMenuItem*) getMenuItem:(NSMenuItem*)item { |
88 return ucx_map_get(items, ucx_key(&item, sizeof(void*))); |
123 return ucx_map_get(items, ucx_key(&item, sizeof(void*))); |
89 } |
124 } |
90 |
125 |
91 - (void) updateMenu:(NSMenu*)menu { |
126 - (void) updateMenu:(NSMenu*)menu { |
92 UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); |
127 UcxList *itemList = ucx_map_get(menus, ucx_key(&menu, sizeof(void*))); |
93 UCX_FOREACH(elm, itemList) { |
128 UCX_FOREACH(elm, itemList) { |
94 UiMenuItem *item = elm->data; |
129 UiAbstractMenuItem *item = elm->data; |
95 |
130 item->update(self, item->item_data); |
96 [item->item setState: item->state]; |
|
97 } |
131 } |
98 } |
132 } |
99 |
133 |
100 @end |
134 @end |
101 |
135 |
112 300, |
146 300, |
113 200, |
147 200, |
114 window_default_width, |
148 window_default_width, |
115 window_default_height); |
149 window_default_height); |
116 |
150 |
|
151 /* |
117 UiCocoaWindow *window = [[UiCocoaWindow alloc] initWithContentRect:frame |
152 UiCocoaWindow *window = [[UiCocoaWindow alloc] initWithContentRect:frame |
118 styleMask:NSTitledWindowMask | NSResizableWindowMask | |
153 styleMask:NSTitledWindowMask | NSResizableWindowMask | |
119 NSClosableWindowMask | NSMiniaturizableWindowMask |
154 NSClosableWindowMask | NSMiniaturizableWindowMask |
120 backing:NSBackingStoreBuffered |
155 backing:NSBackingStoreBuffered |
121 defer:false]; |
156 defer:false]; |
|
157 */ |
|
158 UiCocoaWindow *window = [[UiCocoaWindow alloc] init:frame object:obj]; |
122 |
159 |
123 [window setObject: obj]; |
|
124 NSString *titleStr = [[NSString alloc] initWithUTF8String:title]; |
160 NSString *titleStr = [[NSString alloc] initWithUTF8String:title]; |
125 [window setTitle:titleStr]; |
161 [window setTitle:titleStr]; |
126 |
162 |
127 UiMenuDelegate *menuDelegate = ui_menu_delegate(); |
163 UiMenuDelegate *menuDelegate = ui_menu_delegate(); |
128 [window setMenuItems: [menuDelegate items]]; |
164 [window setMenuItems: [menuDelegate items]]; |
|
165 [window setMenuItemLists: [menuDelegate lists]]; |
129 |
166 |
130 NSToolbar *toolbar = ui_create_toolbar(); |
167 NSToolbar *toolbar = ui_create_toolbar(); |
131 [window setToolbar: toolbar]; |
168 [window setToolbar: toolbar]; |
132 |
169 |
133 obj->widget = (NSView*)window; |
170 obj->widget = (NSView*)window; |