ui/cocoa/menu.m

changeset 128
c284c15509a8
parent 125
3335268a8073
child 129
5babf09f5f19
equal deleted inserted replaced
127:ce342364fad5 128:c284c15509a8
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
125 static int currentItemIndex = 0; 122 static int currentItemIndex = 0;
126 static UiMenuDelegate *delegate; 123 static UiMenuDelegate *delegate;
127 124
128 void ui_menu_init() { 125 void ui_menu_init() {
129 delegate = [[UiMenuDelegate alloc]init]; 126 delegate = [[UiMenuDelegate alloc]init];
142 action:nil keyEquivalent:@""]; 139 action:nil keyEquivalent:@""];
143 [menu setDelegate: delegate]; 140 [menu setDelegate: delegate];
144 [menu setAutoenablesItems:NO]; 141 [menu setAutoenablesItems:NO];
145 142
146 [[NSApp mainMenu] setSubmenu:menu forItem:menuItem]; 143 [[NSApp mainMenu] setSubmenu:menu forItem:menuItem];
147 //currentMenu = menu; 144 currentMenu = menu;
148 currentItemIndex = 0; 145 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);
175 } 146 }
176 147
177 void ui_menuitem(char *label, ui_callback f, void *data) { 148 void ui_menuitem(char *label, ui_callback f, void *data) {
178 ui_menuitem_gr(label, f, data, -1); 149 ui_menuitem_gr(label, f, data, -1);
179 } 150 }
196 while((group = va_arg(ap, int)) != -1) { 167 while((group = va_arg(ap, int)) != -1) {
197 [item addGroup: group]; 168 [item addGroup: group];
198 } 169 }
199 va_end(ap); 170 va_end(ap);
200 171
201 NSMenu *currentMenu = current->data;
202 [currentMenu addItem:item]; 172 [currentMenu addItem:item];
203 173
204 currentItemIndex++; 174 currentItemIndex++;
205 } 175 }
206 176
220 while((group = va_arg(ap, int)) != -1) { 190 while((group = va_arg(ap, int)) != -1) {
221 [item addGroup: group]; 191 [item addGroup: group];
222 } 192 }
223 va_end(ap); 193 va_end(ap);
224 194
225 NSMenu *currentMenu = current->data;
226 [currentMenu addItem:item]; 195 [currentMenu addItem:item];
227 196
228 currentItemIndex++; 197 currentItemIndex++;
229 } 198 }
230 199
231 void ui_checkitem(char *label, ui_callback f, void *data) { 200 void ui_checkitem(char *label, ui_callback f, void *data) {
232 EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f]; 201 EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f];
233 NSString *str = [[NSString alloc] initWithUTF8String:label]; 202 NSString *str = [[NSString alloc] initWithUTF8String:label];
234 203
235 NSMenu *currentMenu = current->data;
236 NSMenuItem *item = [currentMenu addItemWithTitle:str 204 NSMenuItem *item = [currentMenu addItemWithTitle:str
237 action:@selector(handleStateEvent:) keyEquivalent:@""]; 205 action:@selector(handleStateEvent:) keyEquivalent:@""];
238 [item setTarget:event]; 206 [item setTarget:event];
239 207
240 [delegate addItem: item var:NULL]; 208 [delegate addItem: item var:NULL];
243 211
244 void ui_checkitem_nv(char *label, char *vname) { 212 void ui_checkitem_nv(char *label, char *vname) {
245 EventWrapper *event = [[EventWrapper alloc]initWithData:NULL callback:NULL]; 213 EventWrapper *event = [[EventWrapper alloc]initWithData:NULL callback:NULL];
246 NSString *str = [[NSString alloc] initWithUTF8String:label]; 214 NSString *str = [[NSString alloc] initWithUTF8String:label];
247 215
248 NSMenu *currentMenu = current->data;
249 NSMenuItem *item = [currentMenu addItemWithTitle:str 216 NSMenuItem *item = [currentMenu addItemWithTitle:str
250 action:@selector(handleStateEvent:) keyEquivalent:@""]; 217 action:@selector(handleStateEvent:) keyEquivalent:@""];
251 [item setTarget:event]; 218 [item setTarget:event];
252 219
253 [delegate addItem: item var:vname]; 220 [delegate addItem: item var:vname];
254 currentItemIndex++; 221 currentItemIndex++;
255 } 222 }
256 223
257 void ui_menuseparator() { 224 void ui_menuseparator() {
258 NSMenu *currentMenu = current->data;
259 [currentMenu addItem: [NSMenuItem separatorItem]]; 225 [currentMenu addItem: [NSMenuItem separatorItem]];
260 currentItemIndex++; 226 currentItemIndex++;
261 } 227 }
262 228
263 void ui_menuitem_list (UiList *items, ui_callback f, void *data) { 229 void ui_menuitem_list (UiList *items, ui_callback f, void *data) {
264 NSMenu *currentMenu = current->data;
265 [delegate addList:items menu:currentMenu index:currentItemIndex callback:f data:data]; 230 [delegate addList:items menu:currentMenu index:currentItemIndex callback:f data:data];
266 } 231 }
267 232
268 233
269 234

mercurial