ui/common/document.c

changeset 431
bb7da585debc
parent 398
4d87a137fe70
child 440
7c4b9cba09ca
--- a/ui/common/document.c	Sun May 23 09:44:43 2021 +0200
+++ b/ui/common/document.c	Sat Jan 04 16:38:48 2025 +0100
@@ -32,10 +32,16 @@
 
 #include "document.h"
 
-static UcxMap *documents;
+#include <cx/hash_map.h>
+#include <cx/mempool.h>
+
+
+static CxMap *documents;
 
 void uic_docmgr_init() {
-    documents = ucx_map_new(32);
+    if (!documents) {
+        documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
+    }
 }
 
 void ui_set_document(UiObject *obj, void *document) {
@@ -77,25 +83,40 @@
 }
 
 void* ui_document_new(size_t size) {
-    UcxMempool *mp = ucx_mempool_new(256);
-    UiContext *ctx = ucx_mempool_calloc(mp, 1, sizeof(UiContext));
+    CxMempool *mp = cxMempoolCreate(256, NULL);
+    const CxAllocator *a = mp->allocator;
+    UiContext *ctx = cxCalloc(a, 1, sizeof(UiContext));
+    ctx->mp = mp;
     ctx->attach_document = uic_context_attach_document;
     ctx->detach_document2 = uic_context_detach_document2;
-    ctx->mempool = mp;
-    ctx->vars = ucx_map_new_a(mp->allocator, 16);
+    ctx->allocator = a;
+    ctx->vars = cxHashMapCreate(a, CX_STORE_POINTERS, 16);
     
-    void *document = ucx_mempool_calloc(mp, 1, size);
-    ucx_map_put(documents, ucx_key(&document, sizeof(void*)), ctx);
+    void *document = cxCalloc(a, size, 1);
+    cxMapPut(documents, cx_hash_key(&document, sizeof(void*)), ctx);
     return document;
 }
 
 void ui_document_destroy(void *doc) {
-    // TODO
+    UiContext *ctx = ui_document_context(doc);
+    if(ctx) {
+        UiEvent ev;
+        ev.window = NULL;
+        ev.document = doc;
+        ev.obj = NULL;
+        ev.eventdata = NULL;
+        ev.intval = 0;
+
+        if(ctx->close_callback) {
+            ctx->close_callback(&ev, ctx->close_data);
+        }
+        cxMempoolDestroy(ctx->mp);
+    }
 }
 
 UiContext* ui_document_context(void *doc) {
     if(doc) {
-        return ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
+        return cxMapGet(documents, cx_hash_key(&doc, sizeof(void*)));
     } else {
         return NULL;
     }

mercurial