| 194 UiEvent event; |
194 UiEvent event; |
| 195 memset(&event, 0, sizeof(UiEvent)); |
195 memset(&event, 0, sizeof(UiEvent)); |
| 196 event.document = document; |
196 event.document = document; |
| 197 doc_ctx->onattach(&event, doc_ctx->onattachdata); |
197 doc_ctx->onattach(&event, doc_ctx->onattachdata); |
| 198 } |
198 } |
| |
199 uic_check_state_widgets(ui_context_toplevel_parent(ctx)); |
| 199 uic_send_status_change(doc_ctx); |
200 uic_send_status_change(doc_ctx); |
| 200 } |
201 } |
| 201 |
202 |
| 202 static void uic_context_unbind_vars(UiContext *ctx) { |
203 static void uic_context_unbind_vars(UiContext *ctx) { |
| 203 int onchange_enabled = ui_onchange_events_is_enabled(); |
204 int onchange_enabled = ui_onchange_events_is_enabled(); |
| 250 memset(&event, 0, sizeof(UiEvent)); |
251 memset(&event, 0, sizeof(UiEvent)); |
| 251 event.document = document; |
252 event.document = document; |
| 252 doc_ctx->ondetach(&event, doc_ctx->ondetachdata); |
253 doc_ctx->ondetach(&event, doc_ctx->ondetachdata); |
| 253 } |
254 } |
| 254 |
255 |
| |
256 uic_check_state_widgets(ui_context_toplevel_parent(ctx)); |
| 255 uic_send_status_change(doc_ctx); |
257 uic_send_status_change(doc_ctx); |
| 256 ui_document_unref(document); |
258 ui_document_unref(document); |
| 257 } |
259 } |
| 258 |
260 |
| 259 void uic_context_detach_all(UiContext *ctx) { |
261 void uic_context_detach_all(UiContext *ctx) { |
| 649 |
651 |
| 650 UiContext* ui_context_parent(UiContext *ctx) { |
652 UiContext* ui_context_parent(UiContext *ctx) { |
| 651 return ctx->parent; |
653 return ctx->parent; |
| 652 } |
654 } |
| 653 |
655 |
| |
656 UiContext* ui_context_toplevel_parent(UiContext *ctx) { |
| |
657 if(ctx->obj) { |
| |
658 return ctx; |
| |
659 } else if (ctx->parent) { |
| |
660 return ui_context_toplevel_parent(ctx->parent); |
| |
661 } |
| |
662 return NULL; |
| |
663 } |
| |
664 |
| 654 |
665 |
| 655 void ui_set_state(UiContext *ctx, int state) { |
666 void ui_set_state(UiContext *ctx, int state) { |
| 656 if(!cxListIndexValid(ctx->states, cxListFind(ctx->states, &state))) { |
667 if(!cxListIndexValid(ctx->states, cxListFind(ctx->states, &state))) { |
| 657 cxListAdd(ctx->states, &state); |
668 cxListAdd(ctx->states, &state); |
| 658 } |
669 } |
| 659 |
670 |
| 660 // enable/disable group widgets |
671 // enable/disable group widgets |
| 661 uic_check_state_widgets(ctx); |
672 uic_check_state_widgets(ui_context_toplevel_parent(ctx)); |
| 662 } |
673 } |
| 663 |
674 |
| 664 void ui_unset_state(UiContext *ctx, int state) { |
675 void ui_unset_state(UiContext *ctx, int state) { |
| 665 int i = cxListFind(ctx->states, &state); |
676 int i = cxListFind(ctx->states, &state); |
| 666 if(i != -1) { |
677 if(i != -1) { |
| 667 cxListRemove(ctx->states, i); |
678 cxListRemove(ctx->states, i); |
| 668 } |
679 } |
| 669 |
680 |
| 670 // enable/disable group widgets |
681 // enable/disable group widgets |
| 671 uic_check_state_widgets(ctx); |
682 uic_check_state_widgets(ui_context_toplevel_parent(ctx)); |
| |
683 } |
| |
684 |
| |
685 typedef struct StatesList { |
| |
686 CX_ARRAY(int, states); |
| |
687 } StatesList; |
| |
688 |
| |
689 static void add_ctx_states(UiContext *ctx, StatesList *states) { |
| |
690 size_t nstates = cxListSize(ctx->states); |
| |
691 int *ctx_states = cxListAt(ctx->states, 0);; |
| |
692 |
| |
693 cx_array_add_array(states->states, ctx_states, nstates); |
| |
694 |
| |
695 CxIterator i = cxListIterator(ctx->documents); |
| |
696 cx_foreach(void *, doc, i) { |
| |
697 UiContext *doc_ctx = ui_document_context(doc); |
| |
698 add_ctx_states(doc_ctx, states); |
| |
699 } |
| 672 } |
700 } |
| 673 |
701 |
| 674 int* ui_active_states(UiContext *ctx, int *nstates) { |
702 int* ui_active_states(UiContext *ctx, int *nstates) { |
| 675 *nstates = cxListSize(ctx->states); |
703 StatesList states; |
| 676 return cxListAt(ctx->states, 0); |
704 cx_array_init(states.states, 32); |
| |
705 add_ctx_states(ctx, &states); |
| |
706 *nstates = (int)states.states.size; |
| |
707 return states.states.data; |
| 677 } |
708 } |
| 678 |
709 |
| 679 void uic_check_state_widgets(UiContext *ctx) { |
710 void uic_check_state_widgets(UiContext *ctx) { |
| |
711 if(!ctx) { |
| |
712 return; |
| |
713 } |
| |
714 |
| 680 int ngroups = 0; |
715 int ngroups = 0; |
| 681 int *groups = ui_active_states(ctx, &ngroups); |
716 int *groups = ui_active_states(ctx, &ngroups); |
| 682 |
717 |
| 683 CxIterator i = cxListIterator(ctx->state_widgets); |
718 CxIterator i = cxListIterator(ctx->state_widgets); |
| 684 cx_foreach(UiStateWidget *, gw, i) { |
719 cx_foreach(UiStateWidget *, gw, i) { |