36 |
36 |
37 static UiMenu *menus_begin; |
37 static UiMenu *menus_begin; |
38 static UiMenu *menus_end; |
38 static UiMenu *menus_end; |
39 static CxList *current; |
39 static CxList *current; |
40 |
40 |
|
41 static int menu_item_counter = 0; |
|
42 |
41 static void add_menu(UiMenu *menu) { |
43 static void add_menu(UiMenu *menu) { |
42 cx_linked_list_add( |
44 cx_linked_list_add( |
43 (void**)&menus_begin, |
45 (void**)&menus_begin, |
44 (void**)&menus_end, |
46 (void**)&menus_end, |
45 offsetof(UiMenu, item.prev), |
47 offsetof(UiMenu, item.prev), |
55 offsetof(UiMenu, item.prev), |
57 offsetof(UiMenu, item.prev), |
56 offsetof(UiMenu, item.next), |
58 offsetof(UiMenu, item.next), |
57 item); |
59 item); |
58 } |
60 } |
59 |
61 |
|
62 static void mitem_set_id(UiMenuItemI *item) { |
|
63 snprintf(item->id, 8, "%x", menu_item_counter++); |
|
64 } |
|
65 |
60 static char* nl_strdup(const char* s) { |
66 static char* nl_strdup(const char* s) { |
61 return s ? strdup(s) : NULL; |
67 return s ? strdup(s) : NULL; |
62 } |
68 } |
63 |
69 |
64 static int* copy_groups(const int* groups, size_t *ngroups) { |
70 static int* copy_groups(const int* groups, size_t *ngroups) { |
84 current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |
90 current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |
85 } |
91 } |
86 |
92 |
87 // create menu |
93 // create menu |
88 UiMenu *menu = malloc(sizeof(UiMenu)); |
94 UiMenu *menu = malloc(sizeof(UiMenu)); |
|
95 mitem_set_id(&menu->item); |
89 menu->item.prev = NULL; |
96 menu->item.prev = NULL; |
90 menu->item.next = NULL; |
97 menu->item.next = NULL; |
91 menu->item.type = UI_MENU; |
98 menu->item.type = UI_MENU; |
92 |
99 |
93 menu->label = label; |
100 menu->label = label; |
116 if (!current) { |
123 if (!current) { |
117 return; // error? |
124 return; // error? |
118 } |
125 } |
119 |
126 |
120 UiMenuItem* item = malloc(sizeof(UiMenuItem)); |
127 UiMenuItem* item = malloc(sizeof(UiMenuItem)); |
|
128 mitem_set_id(&item->item); |
121 item->item.prev = NULL; |
129 item->item.prev = NULL; |
122 item->item.next = NULL; |
130 item->item.next = NULL; |
123 item->item.type = UI_MENU_ITEM; |
131 item->item.type = UI_MENU_ITEM; |
124 |
132 |
125 item->label = nl_strdup(args.label); |
133 item->label = nl_strdup(args.label); |
149 if(!current) { |
158 if(!current) { |
150 return; |
159 return; |
151 } |
160 } |
152 |
161 |
153 UiMenuCheckItem *item = malloc(sizeof(UiMenuCheckItem)); |
162 UiMenuCheckItem *item = malloc(sizeof(UiMenuCheckItem)); |
|
163 mitem_set_id(&item->item); |
154 item->item.prev = NULL; |
164 item->item.prev = NULL; |
155 item->item.next = NULL; |
165 item->item.next = NULL; |
156 item->item.type = UI_MENU_CHECK_ITEM; |
166 item->item.type = UI_MENU_CHECK_ITEM; |
157 |
167 |
158 item->label = nl_strdup(args.label); |
168 item->label = nl_strdup(args.label); |
170 if (!current) { |
180 if (!current) { |
171 return; |
181 return; |
172 } |
182 } |
173 |
183 |
174 UiMenuCheckItem* item = malloc(sizeof(UiMenuCheckItem)); |
184 UiMenuCheckItem* item = malloc(sizeof(UiMenuCheckItem)); |
|
185 mitem_set_id(&item->item); |
175 item->item.prev = NULL; |
186 item->item.prev = NULL; |
176 item->item.next = NULL; |
187 item->item.next = NULL; |
177 item->item.type = UI_MENU_CHECK_ITEM; |
188 item->item.type = UI_MENU_CHECK_ITEM; |
178 |
189 |
179 item->label = nl_strdup(args.label); |
190 item->label = nl_strdup(args.label); |
191 if(!current) { |
202 if(!current) { |
192 return; |
203 return; |
193 } |
204 } |
194 |
205 |
195 UiMenuItemList*item = malloc(sizeof(UiMenuItemList)); |
206 UiMenuItemList*item = malloc(sizeof(UiMenuItemList)); |
|
207 mitem_set_id(&item->item); |
196 item->item.prev = NULL; |
208 item->item.prev = NULL; |
197 item->item.next = NULL; |
209 item->item.next = NULL; |
198 item->item.type = UI_MENU_ITEM_LIST; |
210 item->item.type = UI_MENU_ITEM_LIST; |
199 item->getvalue = args.getvalue; |
211 item->getvalue = args.getvalue; |
200 item->callback = args.onselect; |
212 item->callback = args.onselect; |
208 if (!current) { |
220 if (!current) { |
209 return; |
221 return; |
210 } |
222 } |
211 |
223 |
212 UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); |
224 UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); |
|
225 mitem_set_id(&item->item); |
213 item->item.prev = NULL; |
226 item->item.prev = NULL; |
214 item->item.next = NULL; |
227 item->item.next = NULL; |
215 item->item.type = UI_MENU_CHECKITEM_LIST; |
228 item->item.type = UI_MENU_CHECKITEM_LIST; |
216 item->callback = args.onselect; |
229 item->callback = args.onselect; |
217 item->userdata = args.onselectdata; |
230 item->userdata = args.onselectdata; |
224 if (!current) { |
237 if (!current) { |
225 return; |
238 return; |
226 } |
239 } |
227 |
240 |
228 UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); |
241 UiMenuItemList* item = malloc(sizeof(UiMenuItemList)); |
|
242 mitem_set_id(&item->item); |
229 item->item.prev = NULL; |
243 item->item.prev = NULL; |
230 item->item.next = NULL; |
244 item->item.next = NULL; |
231 item->item.type = UI_MENU_RADIOITEM_LIST; |
245 item->item.type = UI_MENU_RADIOITEM_LIST; |
232 item->callback = args.onselect; |
246 item->callback = args.onselect; |
233 item->userdata = args.onselectdata; |
247 item->userdata = args.onselectdata; |