200 XtManageChild(button); |
200 XtManageChild(button); |
201 |
201 |
202 ui_bind_radiobutton(obj, button, NULL, it->varname, it->callback, it->userdata, 0); |
202 ui_bind_radiobutton(obj, button, NULL, it->varname, it->callback, it->userdata, 0); |
203 } |
203 } |
204 |
204 |
|
205 static void menuitem_list_remove_binding(void *obj) { |
|
206 UiActiveMenuItemList *ls = obj; |
|
207 UiList *list = ls->var->value; |
|
208 CxList *bindings = list->obj; |
|
209 if(bindings) { |
|
210 (void)cxListFindRemove(bindings, obj); |
|
211 if(cxListSize(bindings) == 0) { |
|
212 cxListFree(bindings); |
|
213 list->obj = NULL; |
|
214 list->update = NULL; |
|
215 } |
|
216 } |
|
217 } |
|
218 |
205 void add_menuitem_list_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
219 void add_menuitem_list_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
206 UiMenuItemList *il = (UiMenuItemList*)item; |
220 UiMenuItemList *il = (UiMenuItemList*)item; |
207 const CxAllocator *a = obj->ctx->allocator; |
221 const CxAllocator *a = obj->ctx->allocator; |
208 |
222 |
209 UiActiveMenuItemList *ls = cxMalloc( |
223 UiActiveMenuItemList *ls = cxMalloc( |
216 ls->getvalue = il->getvalue; |
230 ls->getvalue = il->getvalue; |
217 ls->callback = il->callback; |
231 ls->callback = il->callback; |
218 ls->userdata = il->userdata; |
232 ls->userdata = il->userdata; |
219 ls->addseparator = il->addseparator; |
233 ls->addseparator = il->addseparator; |
220 |
234 |
221 ls->var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST); //uic_widget_var(obj->ctx, obj->ctx, NULL, il->varname, UI_VAR_LIST); |
235 //ls->var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST); |
222 UiList *list = ls->var->value; |
236 ls->var = uic_create_var(obj->ctx, il->varname, UI_VAR_LIST); |
223 |
237 if(ls->var) { |
224 UiObserver *observer = ui_observer_new((ui_callback)ui_update_menuitem_list, ls); |
238 UiList *list = ls->var->value; |
225 list->observers = ui_obsvlist_add(list->observers, observer); |
239 list->update = ui_menulist_update; |
226 uic_list_register_observer_destructor(obj->ctx, list, observer); |
240 list->getselection = NULL; |
227 |
241 list->setselection = NULL; |
228 ui_update_menuitem_list(NULL, ls); |
242 |
229 } |
243 // It is possible, that the UiVar is from a global shared context, |
230 |
244 // used by multiple windows. To support this usecase, the list->obj |
231 void ui_update_menuitem_list(UiEvent *event, UiActiveMenuItemList *list) { |
245 // binding object is a list of all connected UiActiveMenuItemList. |
|
246 CxList *bindings = list->obj; |
|
247 if(!bindings) { |
|
248 bindings = cxLinkedListCreate(ls->var->from_ctx->mp->allocator, NULL, CX_STORE_POINTERS); |
|
249 list->obj = bindings; |
|
250 } |
|
251 cxListAdd(bindings, ls); |
|
252 |
|
253 // The destruction of the toplevel obj must remove the menulist binding |
|
254 uic_context_add_destructor(obj->ctx, menuitem_list_remove_binding, ls); |
|
255 |
|
256 ui_update_menuitem_list(ls); |
|
257 } |
|
258 } |
|
259 |
|
260 void ui_menulist_update(UiList *list, int ignored) { |
|
261 CxList *bindings = list->obj; |
|
262 CxIterator i = cxListIterator(bindings); |
|
263 cx_foreach(UiActiveMenuItemList *, ls, i) { |
|
264 ui_update_menuitem_list(ls); |
|
265 } |
|
266 } |
|
267 |
|
268 void ui_update_menuitem_list(UiActiveMenuItemList *list) { |
232 XmString s = NULL; |
269 XmString s = NULL; |
233 Arg args[4]; |
270 Arg args[4]; |
234 int n; |
271 int n; |
235 |
272 |
236 UiList *ls; |
273 UiList *ls; |