Sat, 04 Oct 2025 12:29:44 +0200
remove separate ctx vars_unbound map
| ui/common/context.c | file | annotate | diff | comparison | revisions | |
| ui/common/context.h | file | annotate | diff | comparison | revisions | |
| ui/common/types.c | file | annotate | diff | comparison | revisions | |
| ui/gtk/toolkit.c | file | annotate | diff | comparison | revisions |
--- a/ui/common/context.c Sat Oct 04 10:59:56 2025 +0200 +++ b/ui/common/context.c Sat Oct 04 12:29:44 2025 +0200 @@ -103,21 +103,19 @@ UiContext *doc_ctx = ui_document_context(document); doc_ctx->parent = ctx; - // check if any parent context has an unbound variable with the same name - // as any document variable + // if a document variable has the same name as a parent variable, + // move the bindings to the document UiContext *var_ctx = ctx; while(var_ctx) { - if(var_ctx->vars_unbound && cxMapSize(var_ctx->vars_unbound) > 0) { - CxMapIterator i = cxMapIterator(var_ctx->vars_unbound); - cx_foreach(CxMapEntry*, entry, i) { - printf("attach %s\n", entry->key->data); - UiVar *var = entry->value; - UiVar *docvar = cxMapGet(doc_ctx->vars, *entry->key); - if(docvar) { - // bind var to document var - uic_copy_binding(var, docvar, TRUE); - cxIteratorFlagRemoval(i); - } + CxMapIterator i = cxMapIterator(var_ctx->vars); + cx_foreach(CxMapEntry*, entry, i) { + printf("attach %.*s\n", (int)entry->key->len, entry->key->data); + UiVar *var = entry->value; + UiVar *docvar = cxMapGet(doc_ctx->vars, *entry->key); + if(docvar) { + // bind var to document var + uic_copy_binding(var, docvar, TRUE); + cxIteratorFlagRemoval(i); } } @@ -130,10 +128,10 @@ cx_foreach(CxMapEntry*, entry, mi) { UiVar *var = entry->value; // var->from && var->from_ctx && var->from_ctx != ctx + uic_save_var(var); if(var->from) { - uic_save_var2(var); uic_copy_binding(var, var->from, FALSE); - cxMapPut(var->from->from_ctx->vars_unbound, *entry->key, var->from); + cxMapPut(var->from->from_ctx->vars, *entry->key, var->from); var->from = NULL; } } @@ -200,13 +198,6 @@ } UiVar* uic_create_var(UiContext *ctx, const char *name, UiVarType type) { - if(ctx->vars_unbound) { - UiVar *unbound = cxMapGet(ctx->vars_unbound, name); - if(unbound) { - return unbound; - } - } - UiVar *var = uic_get_var(ctx, name); if(var) { if(var->type == type) { @@ -225,10 +216,7 @@ cxMempoolSetDestructor(var, (cx_destructor_func)uic_unbind_var); - if(!ctx->vars_unbound) { - ctx->vars_unbound = cxHashMapCreate(ctx->allocator, CX_STORE_POINTERS, 16); - } - cxMapPut(ctx->vars_unbound, name, var); + cxMapPut(ctx->vars, name, var); return var; } @@ -279,7 +267,7 @@ } -UiVar* uic_widget_var(UiContext* toplevel, UiContext* current, void* value, const char* varname, UiVarType type) { +UiVar* uic_widget_var(UiContext *toplevel, UiContext *current, void *value, const char *varname, UiVarType type) { if (value) { return uic_create_value_var(current, value); } @@ -384,7 +372,7 @@ ui_setop_enable(FALSE); } -void uic_save_var2(UiVar *var) { +void uic_save_var(UiVar *var) { switch(var->type) { case UI_VAR_SPECIAL: break; case UI_VAR_INTEGER: uic_int_save(var->value); break;
--- a/ui/common/context.h Sat Oct 04 10:59:56 2025 +0200 +++ b/ui/common/context.h Sat Oct 04 12:29:44 2025 +0200 @@ -67,8 +67,7 @@ void *document; CxList *documents; - CxMap *vars; // manually created context vars - CxMap *vars_unbound; // unbound vars created by widgets + CxMap *vars; CxList *groups; // int list CxList *group_widgets; // UiGroupWidget list @@ -92,7 +91,6 @@ void *close_data; }; -// UiVar replacement, rename it to UiVar when finished struct UiVar { void *value; void *original_value; @@ -133,10 +131,10 @@ UiVar* uic_create_value_var(UiContext *ctx, void *value); void* uic_create_value(UiContext *ctx, UiVarType type); -UiVar* uic_widget_var(UiContext* toplevel, UiContext* current, void* value, const char* varname, UiVarType type); +UiVar* uic_widget_var(UiContext *toplevel, UiContext *current, void *value, const char *varname, UiVarType type); void uic_copy_binding(UiVar *from, UiVar *to, UiBool copytodoc); -void uic_save_var2(UiVar *var); +void uic_save_var(UiVar *var); void uic_unbind_var(UiVar *var); void uic_reg_var(UiContext *ctx, const char *name, UiVarType type, void *value);
--- a/ui/common/types.c Sat Oct 04 10:59:56 2025 +0200 +++ b/ui/common/types.c Sat Oct 04 12:29:44 2025 +0200 @@ -671,6 +671,8 @@ void uic_list_unbind(UiList *l) { l->update = NULL; + l->getselection = NULL; + l->setselection = NULL; l->obj = NULL; }
--- a/ui/gtk/toolkit.c Sat Oct 04 10:59:56 2025 +0200 +++ b/ui/gtk/toolkit.c Sat Oct 04 12:29:44 2025 +0200 @@ -322,15 +322,15 @@ ui_destroy_boundvar(NULL, var); } +// TODO: move to common void ui_destroy_boundvar(UiContext *ctx, UiVar *var) { + uic_save_var(var); uic_unbind_var(var); + // UI_VAR_SPECIAL: anonymous value variable, that is not registered + // in ctx->vars if(var->type == UI_VAR_SPECIAL) { ui_free(var->from_ctx, var); - } else { - ui_free(var->from_ctx, var); - // TODO: free or unbound - //uic_remove_bound_var(ctx, var); } }