ui/common/document.c

branch
newapi
changeset 174
0358f1d9c506
parent 163
b70e2a77dea0
child 187
24ce2c326d85
equal deleted inserted replaced
173:809581724cc7 174:0358f1d9c506
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <string.h> 31 #include <string.h>
32 32
33 #include "document.h" 33 #include "document.h"
34 34
35 static UcxMap *documents; 35 #include <cx/hash_map.h>
36 #include <cx/basic_mempool.h>
37
38 static CxMap *documents;
36 39
37 void uic_docmgr_init() { 40 void uic_docmgr_init() {
38 documents = ucx_map_new(32); 41 documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
39 } 42 }
40 43
41 void ui_set_document(UiObject *obj, void *document) { 44 void ui_set_document(UiObject *obj, void *document) {
42 uic_context_detach_all(obj->ctx); 45 uic_context_detach_all(obj->ctx);
43 obj->ctx->attach_document(obj->ctx, document); 46 obj->ctx->attach_document(obj->ctx, document);
75 // TODO 78 // TODO
76 return NULL; 79 return NULL;
77 } 80 }
78 81
79 void* ui_document_new(size_t size) { 82 void* ui_document_new(size_t size) {
80 UcxMempool *mp = ucx_mempool_new(256); 83 CxMempool *mp = cxBasicMempoolCreate(256);
81 UiContext *ctx = ucx_mempool_calloc(mp, 1, sizeof(UiContext)); 84 const CxAllocator *a = mp->allocator;
85 UiContext *ctx = cxCalloc(a, 1, sizeof(UiContext));
82 ctx->attach_document = uic_context_attach_document; 86 ctx->attach_document = uic_context_attach_document;
83 ctx->detach_document2 = uic_context_detach_document2; 87 ctx->detach_document2 = uic_context_detach_document2;
84 ctx->mempool = mp; 88 ctx->allocator = a;
85 ctx->vars = ucx_map_new_a(mp->allocator, 16); 89 ctx->vars = cxHashMapCreate(a, CX_STORE_POINTERS, 16);
86 90
87 void *document = ucx_mempool_calloc(mp, 1, size); 91 void *document = cxCalloc(a, 1, size);
88 ucx_map_put(documents, ucx_key(&document, sizeof(void*)), ctx); 92 cxMapPut(documents, cx_hash_key(&document, sizeof(void*)), ctx);
89 return document; 93 return document;
90 } 94 }
91 95
92 void ui_document_destroy(void *doc) { 96 void ui_document_destroy(void *doc) {
93 // TODO 97 // TODO
94 } 98 }
95 99
96 UiContext* ui_document_context(void *doc) { 100 UiContext* ui_document_context(void *doc) {
97 if(doc) { 101 if(doc) {
98 return ucx_map_get(documents, ucx_key(&doc, sizeof(void*))); 102 return cxMapGet(documents, cx_hash_key(&doc, sizeof(void*)));
99 } else { 103 } else {
100 return NULL; 104 return NULL;
101 } 105 }
102 } 106 }

mercurial