ui/common/object.c

branch
newapi
changeset 383
03599608d555
parent 328
059cba080ab4
child 384
8be7fd628fbc
--- 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);

mercurial