diff -r de653b07050b -r 03599608d555 ui/common/object.c --- a/ui/common/object.c Thu Nov 14 17:26:16 2024 +0100 +++ b/ui/common/object.c Fri Nov 15 21:16:18 2024 +0100 @@ -49,6 +49,32 @@ } } +void ui_object_ref(UiObject *obj) { + obj->ref++; +} + +void ui_object_unref(UiObject *obj) { + if(--obj->ref == 0) { + if(obj->destroy) { + obj->destroy(obj); + } else { + uic_object_destroy(obj); + } + } +} + +void uic_object_destroy(UiObject *obj) { + if(obj->ctx->close_callback) { + UiEvent ev; + ev.window = obj->window; + ev.document = obj->ctx->document; + ev.obj = obj; + ev.eventdata = NULL; + ev.intval = 0; + obj->ctx->close_callback(&ev, obj->ctx->close_data); + } + cxMempoolDestroy(obj->ctx->mp); +} UiObject* uic_object_new(UiObject *toplevel, UIWIDGET widget) { return uic_ctx_object_new(toplevel->ctx, widget);