29 #import <stdio.h> |
29 #import <stdio.h> |
30 #import <stdlib.h> |
30 #import <stdlib.h> |
31 #import <string.h> |
31 #import <string.h> |
32 |
32 |
33 #import "menu.h" |
33 #import "menu.h" |
|
34 #import "window.h" |
|
35 |
|
36 @implementation UiMenuDelegate |
|
37 |
|
38 - (UiMenuDelegate*) init { |
|
39 items = NULL; |
|
40 return self; |
|
41 } |
|
42 |
|
43 - (void) menuNeedsUpdate:(NSMenu *) menu { |
|
44 NSWindow *activeWindow = [NSApp keyWindow]; |
|
45 [(UiCocoaWindow*)activeWindow updateMenu: menu]; |
|
46 } |
|
47 |
|
48 - (void) addItem:(NSMenuItem*) item var: (char*)name { |
|
49 UiStateItem *i = malloc(sizeof(UiStateItem)); |
|
50 i->item = item; |
|
51 i->var = name; |
|
52 items = ucx_list_append(items, i); |
|
53 } |
|
54 |
|
55 - (UcxList*) items { |
|
56 return items; |
|
57 } |
|
58 |
|
59 @end |
|
60 |
|
61 |
34 |
62 |
35 |
63 |
36 static NSMenu *currentMenu = NULL; |
64 static NSMenu *currentMenu = NULL; |
|
65 static UiMenuDelegate *delegate; |
|
66 |
|
67 void ui_menu_init() { |
|
68 delegate = [[UiMenuDelegate alloc]init]; |
|
69 } |
|
70 |
|
71 UiMenuDelegate* ui_menu_delegate() { |
|
72 return delegate; |
|
73 } |
|
74 |
37 |
75 |
38 void ui_menu(char *title) { |
76 void ui_menu(char *title) { |
39 NSString *str = [[NSString alloc] initWithUTF8String:title]; |
77 NSString *str = [[NSString alloc] initWithUTF8String:title]; |
40 |
78 |
41 NSMenu *menu = [[NSMenu alloc] initWithTitle: str]; |
79 NSMenu *menu = [[NSMenu alloc] initWithTitle: str]; |
42 NSMenuItem *menuItem = [[NSApp mainMenu] addItemWithTitle:str |
80 NSMenuItem *menuItem = [[NSApp mainMenu] addItemWithTitle:str |
43 action:nil keyEquivalent:@""]; |
81 action:nil keyEquivalent:@""]; |
|
82 [menu setDelegate: delegate]; |
44 |
83 |
45 [[NSApp mainMenu] setSubmenu:menu forItem:menuItem]; |
84 [[NSApp mainMenu] setSubmenu:menu forItem:menuItem]; |
46 currentMenu = menu; |
85 currentMenu = menu; |
47 } |
86 } |
48 |
87 |
51 NSString *str = [[NSString alloc] initWithUTF8String:label]; |
90 NSString *str = [[NSString alloc] initWithUTF8String:label]; |
52 |
91 |
53 NSMenuItem *item = [currentMenu addItemWithTitle:str |
92 NSMenuItem *item = [currentMenu addItemWithTitle:str |
54 action:@selector(handleEvent:) keyEquivalent:@""]; |
93 action:@selector(handleEvent:) keyEquivalent:@""]; |
55 [item setTarget:event]; |
94 [item setTarget:event]; |
|
95 |
|
96 //[delegate addItem: item]; |
56 } |
97 } |
57 |
98 |
58 void ui_checkitem(char *label, ui_callback f, void *userdata) { |
99 void ui_checkitem(char *label, ui_callback f, void *data) { |
|
100 EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f]; |
|
101 NSString *str = [[NSString alloc] initWithUTF8String:label]; |
59 |
102 |
|
103 NSMenuItem *item = [currentMenu addItemWithTitle:str |
|
104 action:@selector(handleStateEvent:) keyEquivalent:@""]; |
|
105 [item setTarget:event]; |
|
106 |
|
107 [delegate addItem: item var:NULL]; |
60 } |
108 } |
61 |
109 |
62 void ui_checkitem_nv(char *label, char *vname) { |
110 void ui_checkitem_nv(char *label, char *vname) { |
|
111 EventWrapper *event = [[EventWrapper alloc]initWithData:NULL callback:NULL]; |
|
112 NSString *str = [[NSString alloc] initWithUTF8String:label]; |
63 |
113 |
|
114 NSMenuItem *item = [currentMenu addItemWithTitle:str |
|
115 action:@selector(handleStateEvent:) keyEquivalent:@""]; |
|
116 [item setTarget:event]; |
|
117 |
|
118 [delegate addItem: item var:vname]; |
64 } |
119 } |
65 |
120 |
66 void ui_menuseparator() { |
121 void ui_menuseparator() { |
67 |
122 |
68 } |
123 } |
69 |
124 |
70 |
125 |
|
126 |
|
127 int ui_menuitem_get(UiInteger *i) { |
|
128 UiMenuItem *item = i->obj; |
|
129 i->value = [item->item state]; |
|
130 return i->value; |
|
131 } |
|
132 |
|
133 void ui_menuitem_set(UiInteger *i, int value) { |
|
134 UiMenuItem *item = i->obj; |
|
135 [item->item setState: value]; |
|
136 i->value = value; |
|
137 } |