116 } |
116 } |
117 |
117 |
118 @end |
118 @end |
119 |
119 |
120 |
120 |
121 static NSMenu *currentMenu = NULL; |
121 //static NSMenu *currentMenu = NULL; |
|
122 |
|
123 static UcxList *current; |
|
124 |
122 static int currentItemIndex = 0; |
125 static int currentItemIndex = 0; |
123 static UiMenuDelegate *delegate; |
126 static UiMenuDelegate *delegate; |
124 |
127 |
125 void ui_menu_init() { |
128 void ui_menu_init() { |
126 delegate = [[UiMenuDelegate alloc]init]; |
129 delegate = [[UiMenuDelegate alloc]init]; |
139 action:nil keyEquivalent:@""]; |
142 action:nil keyEquivalent:@""]; |
140 [menu setDelegate: delegate]; |
143 [menu setDelegate: delegate]; |
141 [menu setAutoenablesItems:NO]; |
144 [menu setAutoenablesItems:NO]; |
142 |
145 |
143 [[NSApp mainMenu] setSubmenu:menu forItem:menuItem]; |
146 [[NSApp mainMenu] setSubmenu:menu forItem:menuItem]; |
144 currentMenu = menu; |
147 //currentMenu = menu; |
145 currentItemIndex = 0; |
148 currentItemIndex = 0; |
|
149 |
|
150 current = ucx_list_prepend(NULL, menu); |
|
151 } |
|
152 |
|
153 void ui_submenu(char *title) { |
|
154 NSString *str = [[NSString alloc] initWithUTF8String:title]; |
|
155 NSMenu *currentMenu = current->data; |
|
156 |
|
157 NSMenu *menu = [[NSMenu alloc] initWithTitle: str]; |
|
158 NSMenuItem *menuItem = [currentMenu addItemWithTitle:str |
|
159 action:nil keyEquivalent:@""]; |
|
160 [menu setDelegate: delegate]; |
|
161 [menu setAutoenablesItems:NO]; |
|
162 |
|
163 [currentMenu setSubmenu:menu forItem:menuItem]; |
|
164 //currentMenu = menu; |
|
165 currentItemIndex = 0; |
|
166 |
|
167 current = ucx_list_prepend(current, menu); |
|
168 } |
|
169 |
|
170 void ui_submenu_end() { |
|
171 if(ucx_list_size(current) < 2) { |
|
172 return; |
|
173 } |
|
174 current = ucx_list_remove(current, current); |
146 } |
175 } |
147 |
176 |
148 void ui_menuitem(char *label, ui_callback f, void *data) { |
177 void ui_menuitem(char *label, ui_callback f, void *data) { |
149 ui_menuitem_gr(label, f, data, -1); |
178 ui_menuitem_gr(label, f, data, -1); |
150 } |
179 } |
190 while((group = va_arg(ap, int)) != -1) { |
220 while((group = va_arg(ap, int)) != -1) { |
191 [item addGroup: group]; |
221 [item addGroup: group]; |
192 } |
222 } |
193 va_end(ap); |
223 va_end(ap); |
194 |
224 |
|
225 NSMenu *currentMenu = current->data; |
195 [currentMenu addItem:item]; |
226 [currentMenu addItem:item]; |
196 |
227 |
197 currentItemIndex++; |
228 currentItemIndex++; |
198 } |
229 } |
199 |
230 |
200 void ui_checkitem(char *label, ui_callback f, void *data) { |
231 void ui_checkitem(char *label, ui_callback f, void *data) { |
201 EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f]; |
232 EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f]; |
202 NSString *str = [[NSString alloc] initWithUTF8String:label]; |
233 NSString *str = [[NSString alloc] initWithUTF8String:label]; |
203 |
234 |
|
235 NSMenu *currentMenu = current->data; |
204 NSMenuItem *item = [currentMenu addItemWithTitle:str |
236 NSMenuItem *item = [currentMenu addItemWithTitle:str |
205 action:@selector(handleStateEvent:) keyEquivalent:@""]; |
237 action:@selector(handleStateEvent:) keyEquivalent:@""]; |
206 [item setTarget:event]; |
238 [item setTarget:event]; |
207 |
239 |
208 [delegate addItem: item var:NULL]; |
240 [delegate addItem: item var:NULL]; |
211 |
243 |
212 void ui_checkitem_nv(char *label, char *vname) { |
244 void ui_checkitem_nv(char *label, char *vname) { |
213 EventWrapper *event = [[EventWrapper alloc]initWithData:NULL callback:NULL]; |
245 EventWrapper *event = [[EventWrapper alloc]initWithData:NULL callback:NULL]; |
214 NSString *str = [[NSString alloc] initWithUTF8String:label]; |
246 NSString *str = [[NSString alloc] initWithUTF8String:label]; |
215 |
247 |
|
248 NSMenu *currentMenu = current->data; |
216 NSMenuItem *item = [currentMenu addItemWithTitle:str |
249 NSMenuItem *item = [currentMenu addItemWithTitle:str |
217 action:@selector(handleStateEvent:) keyEquivalent:@""]; |
250 action:@selector(handleStateEvent:) keyEquivalent:@""]; |
218 [item setTarget:event]; |
251 [item setTarget:event]; |
219 |
252 |
220 [delegate addItem: item var:vname]; |
253 [delegate addItem: item var:vname]; |
221 currentItemIndex++; |
254 currentItemIndex++; |
222 } |
255 } |
223 |
256 |
224 void ui_menuseparator() { |
257 void ui_menuseparator() { |
|
258 NSMenu *currentMenu = current->data; |
225 [currentMenu addItem: [NSMenuItem separatorItem]]; |
259 [currentMenu addItem: [NSMenuItem separatorItem]]; |
226 currentItemIndex++; |
260 currentItemIndex++; |
227 } |
261 } |
228 |
262 |
229 void ui_menuitem_list (UiList *items, ui_callback f, void *data) { |
263 void ui_menuitem_list (UiList *items, ui_callback f, void *data) { |
|
264 NSMenu *currentMenu = current->data; |
230 [delegate addList:items menu:currentMenu index:currentItemIndex callback:f data:data]; |
265 [delegate addList:items menu:currentMenu index:currentItemIndex callback:f data:data]; |
231 } |
266 } |
232 |
267 |
233 |
268 |
234 |
269 |