| 42 if (!documents) { |
42 if (!documents) { |
| 43 documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); |
43 documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); |
| 44 } |
44 } |
| 45 } |
45 } |
| 46 |
46 |
| 47 void ui_set_document(UiObject *obj, void *document) { |
|
| 48 uic_context_detach_all(obj->ctx); |
|
| 49 obj->ctx->attach_document(obj->ctx, document); |
|
| 50 } |
|
| 51 |
|
| 52 void ui_detach_document(UiObject *obj) { |
|
| 53 uic_context_detach_all(obj->ctx); |
|
| 54 } |
|
| 55 |
|
| 56 void* ui_get_document(UiObject *obj) { |
|
| 57 return obj->ctx->document; |
|
| 58 } |
|
| 59 |
|
| 60 void ui_set_subdocument(void *document, void *sub) { |
|
| 61 UiContext *ctx = ui_document_context(document); |
|
| 62 if(!ctx) { |
|
| 63 fprintf(stderr, "UI Error: pointer is not a document\n"); |
|
| 64 } |
|
| 65 // TODO |
|
| 66 } |
|
| 67 |
|
| 68 void ui_detach_subdocument(void *document, void *sub) { |
|
| 69 UiContext *ctx = ui_document_context(document); |
|
| 70 if(!ctx) { |
|
| 71 fprintf(stderr, "UI Error: pointer is not a document\n"); |
|
| 72 } |
|
| 73 // TODO |
|
| 74 } |
|
| 75 |
|
| 76 void* ui_get_subdocument(void *document) { |
|
| 77 UiContext *ctx = ui_document_context(document); |
|
| 78 if(!ctx) { |
|
| 79 fprintf(stderr, "UI Error: pointer is not a document\n"); |
|
| 80 } |
|
| 81 // TODO |
|
| 82 return NULL; |
|
| 83 } |
|
| 84 |
|
| 85 void* ui_document_new(size_t size) { |
47 void* ui_document_new(size_t size) { |
| 86 CxMempool *mp = cxMempoolCreate(256, NULL); |
48 CxMempool *mp = cxMempoolCreateSimple(256); |
| 87 const CxAllocator *a = mp->allocator; |
49 const CxAllocator *a = mp->allocator; |
| 88 UiContext *ctx = uic_context(NULL, mp); |
50 UiContext *ctx = uic_context(NULL, mp); |
| 89 |
51 |
| 90 void *document = cxCalloc(a, size, 1); |
52 void *document = cxCalloc(a, size, 1); |
| 91 cxMapPut(documents, cx_hash_key(&document, sizeof(void*)), ctx); |
53 cxMapPut(documents, cx_hash_key(&document, sizeof(void*)), ctx); |