| 128 } |
128 } |
| 129 |
129 |
| 130 gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget); |
130 gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget); |
| 131 |
131 |
| 132 if(i->states) { |
132 if(i->states) { |
| 133 CxList *states = cxArrayListCreateSimple(sizeof(int), i->nstates); |
133 CxList *states = cxArrayListCreate(NULL, sizeof(int), i->nstates); |
| 134 cxListAddArray(states, i->states, i->nstates); |
134 cxListAddArray(states, i->states, i->nstates); |
| 135 uic_add_state_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, states); |
135 uic_add_state_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, states); |
| 136 cxListFree(states); |
136 cxListFree(states); |
| 137 } |
137 } |
| 138 } |
138 } |
| 218 // It is possible, that the UiVar is from a global shared context, |
218 // It is possible, that the UiVar is from a global shared context, |
| 219 // used by multiple windows. To support this usecase, the list->obj |
219 // used by multiple windows. To support this usecase, the list->obj |
| 220 // binding object is a list of all connected UiActiveMenuItemList. |
220 // binding object is a list of all connected UiActiveMenuItemList. |
| 221 CxList *bindings = list->obj; |
221 CxList *bindings = list->obj; |
| 222 if(!bindings) { |
222 if(!bindings) { |
| 223 bindings = cxLinkedListCreate(var->from_ctx->mp->allocator, NULL, CX_STORE_POINTERS); |
223 bindings = cxLinkedListCreate(var->from_ctx->mp->allocator, CX_STORE_POINTERS); |
| 224 list->obj = bindings; |
224 list->obj = bindings; |
| 225 } |
225 } |
| 226 cxListAdd(bindings, ls); |
226 cxListAdd(bindings, ls); |
| 227 |
227 |
| 228 // The destruction of the toplevel obj must remove the menulist binding |
228 // The destruction of the toplevel obj must remove the menulist binding |
| 461 GSimpleAction *action = g_simple_action_new(item->id, NULL); |
461 GSimpleAction *action = g_simple_action_new(item->id, NULL); |
| 462 g_action_map_add_action(obj->ctx->action_map, G_ACTION(action)); |
462 g_action_map_add_action(obj->ctx->action_map, G_ACTION(action)); |
| 463 g_object_unref(action); |
463 g_object_unref(action); |
| 464 |
464 |
| 465 if(i->states) { |
465 if(i->states) { |
| 466 CxList *groups = cxArrayListCreateSimple(sizeof(int), i->nstates); |
466 CxList *groups = cxArrayListCreate(NULL, sizeof(int), i->nstates); |
| 467 cxListAddArray(groups, i->states, i->nstates); |
467 cxListAddArray(groups, i->states, i->nstates); |
| 468 uic_add_state_widget(obj->ctx, action, (ui_enablefunc)action_enable, groups); |
468 uic_add_state_widget(obj->ctx, action, (ui_enablefunc)action_enable, groups); |
| 469 cxListFree(groups); |
469 cxListFree(groups); |
| 470 } |
470 } |
| 471 |
471 |
| 523 } |
523 } |
| 524 } |
524 } |
| 525 } |
525 } |
| 526 |
526 |
| 527 static void stateful_action_notify_group(UiMenuRadioGroup *group, UiInteger *i) { |
527 static void stateful_action_notify_group(UiMenuRadioGroup *group, UiInteger *i) { |
| |
528 int intval = ui_get(i); |
| |
529 |
| 528 UiEvent event; |
530 UiEvent event; |
| 529 event.obj = group->obj; |
531 event.obj = group->obj; |
| 530 event.window = event.obj->window; |
532 event.window = event.obj->window; |
| 531 event.document = event.obj->ctx->document; |
533 event.document = event.obj->ctx->document; |
| 532 event.eventdata = NULL; |
534 event.eventdata = NULL; |
| 533 event.eventdatatype = 0; |
535 event.eventdatatype = 0; |
| 534 event.intval = (int)i->value; |
|
| 535 event.set = ui_get_setop(); |
536 event.set = ui_get_setop(); |
| 536 |
537 |
| 537 CxIterator iter = cxListIterator(group->callbacks); |
538 CxIterator iter = cxListIterator(group->callbacks); |
| 538 cx_foreach(UiCallbackData *, cb, iter) { |
539 cx_foreach(UiCallbackData *, cb, iter) { |
| |
540 event.intval = intval == iter.index; |
| 539 if(cb->callback) { |
541 if(cb->callback) { |
| 540 cb->callback(&event, cb->userdata); |
542 cb->callback(&event, cb->userdata); |
| 541 } |
543 } |
| 542 } |
544 } |
| 543 |
545 |
| |
546 event.intval = intval; |
| 544 UiObserver *obs = i->observers; |
547 UiObserver *obs = i->observers; |
| 545 while(obs) { |
548 while(obs) { |
| 546 if(obs->callback) { |
549 if(obs->callback) { |
| 547 obs->callback(&event, obs->data); |
550 obs->callback(&event, obs->data); |
| 548 } |
551 } |
| 567 return i->value; |
570 return i->value; |
| 568 } |
571 } |
| 569 |
572 |
| 570 static UiMenuRadioGroup* create_radio_group(UiObject *obj, UiMenuRadioItem *item, GSimpleAction *action) { |
573 static UiMenuRadioGroup* create_radio_group(UiObject *obj, UiMenuRadioItem *item, GSimpleAction *action) { |
| 571 UiMenuRadioGroup *group = cxZalloc(obj->ctx->allocator, sizeof(UiMenuRadioGroup)); |
574 UiMenuRadioGroup *group = cxZalloc(obj->ctx->allocator, sizeof(UiMenuRadioGroup)); |
| 572 group->callbacks = cxArrayListCreate(obj->ctx->allocator, NULL, sizeof(UiCallbackData), 8); |
575 group->callbacks = cxArrayListCreate(obj->ctx->allocator, sizeof(UiCallbackData), 8); |
| 573 group->var = uic_create_var(ui_global_context(), item->varname, UI_VAR_INTEGER); |
576 group->var = uic_create_var(ui_global_context(), item->varname, UI_VAR_INTEGER); |
| 574 group->obj = obj; |
577 group->obj = obj; |
| 575 group->action = action; |
578 group->action = action; |
| 576 if(group->var) { |
579 if(group->var) { |
| 577 UiInteger *i = group->var->value; |
580 UiInteger *i = group->var->value; |
| 578 CxList *bindings = i->obj; |
581 CxList *bindings = i->obj; |
| 579 if(!bindings) { |
582 if(!bindings) { |
| 580 bindings = cxLinkedListCreate(group->var->from_ctx->mp->allocator, NULL, CX_STORE_POINTERS); |
583 bindings = cxLinkedListCreate(group->var->from_ctx->mp->allocator, CX_STORE_POINTERS); |
| 581 i->obj = bindings; |
584 i->obj = bindings; |
| 582 i->set = ui_action_set_state; |
585 i->set = ui_action_set_state; |
| 583 i->get = ui_action_get_state; |
586 i->get = ui_action_get_state; |
| 584 } |
587 } |
| 585 cxListAdd(bindings, group); |
588 cxListAdd(bindings, group); |
| 709 // It is possible, that the UiVar is from a global shared context, |
712 // It is possible, that the UiVar is from a global shared context, |
| 710 // used by multiple windows. To support this usecase, the list->obj |
713 // used by multiple windows. To support this usecase, the list->obj |
| 711 // binding object is a list of all connected UiActiveMenuItemList. |
714 // binding object is a list of all connected UiActiveMenuItemList. |
| 712 CxList *bindings = list->obj; |
715 CxList *bindings = list->obj; |
| 713 if(!bindings) { |
716 if(!bindings) { |
| 714 bindings = cxLinkedListCreate(var->from_ctx->mp->allocator, NULL, CX_STORE_POINTERS); |
717 bindings = cxLinkedListCreate(var->from_ctx->mp->allocator, CX_STORE_POINTERS); |
| 715 list->obj = bindings; |
718 list->obj = bindings; |
| 716 } |
719 } |
| 717 cxListAdd(bindings, ls); |
720 cxListAdd(bindings, ls); |
| 718 |
721 |
| 719 // The destruction of the toplevel obj must remove the menulist binding |
722 // The destruction of the toplevel obj must remove the menulist binding |