--- a/ui/common/context.h Sat Apr 05 17:57:04 2025 +0200 +++ b/ui/common/context.h Sun Jul 20 22:04:39 2025 +0200 @@ -40,10 +40,11 @@ extern "C" { #endif -typedef struct UiVar UiVar; -typedef struct UiListPtr UiListPtr; -typedef struct UiListVar UiListVar; -typedef struct UiGroupWidget UiGroupWidget; +typedef struct UiVar UiVar; +typedef struct UiListPtr UiListPtr; +typedef struct UiListVar UiListVar; +typedef struct UiGroupWidget UiGroupWidget; +typedef struct UiDestroyHandler UiDestroyHandler; typedef enum UiVarType { UI_VAR_SPECIAL = 0, @@ -61,6 +62,7 @@ UiObject *obj; CxMempool *mp; const CxAllocator *allocator; + CxList *destroy_handler; void *document; CxList *documents; @@ -93,8 +95,9 @@ // UiVar replacement, rename it to UiVar when finished struct UiVar { void *value; + void *original_value; UiVarType type; - UiVar *from; + UiVar *from; UiContext *from_ctx; }; @@ -105,18 +108,24 @@ int numgroups; }; +struct UiDestroyHandler { + cx_destructor_func destructor; + void *data; +}; + void uic_init_global_context(void); UiContext* uic_context(UiObject *toplevel, CxMempool *mp); UiContext* uic_root_context(UiContext *ctx); -void uic_context_set_document(UiContext *ctx, void *document); // deprecated -void uic_context_detach_document(UiContext *ctx); // deprecated +void uic_context_add_destructor(UiContext *ctx, cx_destructor_func func, void *data); void uic_context_prepare_close(UiContext *ctx); void uic_context_attach_document(UiContext *ctx, void *document); -void uic_context_detach_document2(UiContext *ctx, void *document); +void uic_context_detach_document(UiContext *ctx, void *document); +void uic_context_attach_context(UiContext *ctx, UiContext *doc_ctx); // TODO +void uic_context_detach_context(UiContext *ctx, UiContext *doc_ctx); // TODO void uic_context_detach_all(UiContext *ctx); UiVar* uic_get_var(UiContext *ctx, const char *name); @@ -130,7 +139,7 @@ void uic_save_var2(UiVar *var); void uic_unbind_var(UiVar *var); -void uic_reg_var(UiContext *ctx, char *name, UiVarType type, void *value); +void uic_reg_var(UiContext *ctx, const char *name, UiVarType type, void *value); void uic_remove_bound_var(UiContext *ctx, UiVar *var);