diff -r abb4d3851061 -r fd7dc0716ab6 ui/common/context.c --- a/ui/common/context.c Sun Jun 14 12:10:34 2026 +0200 +++ b/ui/common/context.c Mon Jun 15 21:13:05 2026 +0200 @@ -196,6 +196,7 @@ event.document = document; doc_ctx->onattach(&event, doc_ctx->onattachdata); } + uic_check_state_widgets(ui_context_toplevel_parent(ctx)); uic_send_status_change(doc_ctx); } @@ -252,6 +253,7 @@ doc_ctx->ondetach(&event, doc_ctx->ondetachdata); } + uic_check_state_widgets(ui_context_toplevel_parent(ctx)); uic_send_status_change(doc_ctx); ui_document_unref(document); } @@ -651,6 +653,15 @@ return ctx->parent; } +UiContext* ui_context_toplevel_parent(UiContext *ctx) { + if(ctx->obj) { + return ctx; + } else if (ctx->parent) { + return ui_context_toplevel_parent(ctx->parent); + } + return NULL; +} + void ui_set_state(UiContext *ctx, int state) { if(!cxListIndexValid(ctx->states, cxListFind(ctx->states, &state))) { @@ -658,7 +669,7 @@ } // enable/disable group widgets - uic_check_state_widgets(ctx); + uic_check_state_widgets(ui_context_toplevel_parent(ctx)); } void ui_unset_state(UiContext *ctx, int state) { @@ -668,15 +679,39 @@ } // enable/disable group widgets - uic_check_state_widgets(ctx); + uic_check_state_widgets(ui_context_toplevel_parent(ctx)); +} + +typedef struct StatesList { + CX_ARRAY(int, states); +} StatesList; + +static void add_ctx_states(UiContext *ctx, StatesList *states) { + size_t nstates = cxListSize(ctx->states); + int *ctx_states = cxListAt(ctx->states, 0);; + + cx_array_add_array(states->states, ctx_states, nstates); + + CxIterator i = cxListIterator(ctx->documents); + cx_foreach(void *, doc, i) { + UiContext *doc_ctx = ui_document_context(doc); + add_ctx_states(doc_ctx, states); + } } int* ui_active_states(UiContext *ctx, int *nstates) { - *nstates = cxListSize(ctx->states); - return cxListAt(ctx->states, 0); + StatesList states; + cx_array_init(states.states, 32); + add_ctx_states(ctx, &states); + *nstates = (int)states.states.size; + return states.states.data; } void uic_check_state_widgets(UiContext *ctx) { + if(!ctx) { + return; + } + int ngroups = 0; int *groups = ui_active_states(ctx, &ngroups); @@ -702,6 +737,8 @@ free(check); gw->enable(gw->widget, enable); } + + free(groups); } void ui_widget_set_states(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...) {