ui/common/document.c

changeset 140
c03c338a7dcf
parent 52
25e5390cce41
child 163
b70e2a77dea0
equal deleted inserted replaced
139:dbde25a5bc53 140:c03c338a7dcf
1 /* 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * 3 *
4 * Copyright 2014 Olaf Wintermann. All rights reserved. 4 * Copyright 2017 Olaf Wintermann. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
40 40
41 void ui_set_document(UiObject *obj, void *document) { 41 void ui_set_document(UiObject *obj, void *document) {
42 obj->ctx->set_document(obj->ctx, document); 42 obj->ctx->set_document(obj->ctx, document);
43 } 43 }
44 44
45 void ui_detach_document(UiObject *obj, void *document) { 45 void ui_detach_document(UiObject *obj) {
46 obj->ctx->detach_document(obj->ctx, document); 46 obj->ctx->detach_document(obj->ctx);
47 } 47 }
48 48
49 void* ui_get_document(UiObject *obj) { 49 void* ui_get_document(UiObject *obj) {
50 return obj->ctx->document; 50 return obj->ctx->document;
51 } 51 }
61 void ui_detach_subdocument(void *document, void *sub) { 61 void ui_detach_subdocument(void *document, void *sub) {
62 UiContext *ctx = ui_document_context(document); 62 UiContext *ctx = ui_document_context(document);
63 if(!ctx) { 63 if(!ctx) {
64 fprintf(stderr, "UI Error: pointer is not a document\n"); 64 fprintf(stderr, "UI Error: pointer is not a document\n");
65 } 65 }
66 uic_context_detach_document(ctx, sub); 66 uic_context_detach_document(ctx);
67 } 67 }
68 68
69 void* ui_get_subdocument(void *document) { 69 void* ui_get_subdocument(void *document) {
70 UiContext *ctx = ui_document_context(document); 70 UiContext *ctx = ui_document_context(document);
71 if(!ctx) { 71 if(!ctx) {
96 return ucx_map_get(documents, ucx_key(&doc, sizeof(void*))); 96 return ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
97 } else { 97 } else {
98 return NULL; 98 return NULL;
99 } 99 }
100 } 100 }
101
102 void* ui_document_malloc(void *doc, size_t size) {
103 UiContext *uidoc = ui_document_context(doc);
104 return ucx_mempool_malloc(uidoc->mempool, size);
105 }
106
107 void* ui_document_calloc(void *doc, size_t nelem, size_t elsize) {
108 UiContext *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
109 return ucx_mempool_calloc(uidoc->mempool, nelem, elsize);
110 }
111
112 void ui_document_free(void *doc, void *ptr) {
113 UiContext *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
114 ucx_mempool_free(uidoc->mempool, ptr);
115 }
116
117 void* ui_document_realloc(void *doc, void *ptr, size_t size) {
118 UiContext *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
119 return ucx_mempool_realloc(uidoc->mempool, ptr, size);
120 }
121
122 void uic_document_addvar(void *doc, char *name, int type, size_t vs) {
123 // TODO: remove
124 UiContext *ctx = ui_document_context(doc);
125 if(ctx) {
126 UiVar *newvar = ucx_mempool_malloc(ctx->mempool, sizeof(UiVar));
127 newvar->isextern = 0;
128 newvar->type = type;
129 newvar->value = ucx_mempool_calloc(ctx->mempool, 1, vs);
130 newvar->from = NULL;
131
132 uic_add_var(ctx, name, newvar, type, vs);
133 }
134 }
135
136 void ui_document_addint(void *doc, char *name) {
137 uic_document_addvar(doc, name, UI_VAR_INTEGER, sizeof(UiInteger));
138 }
139
140
141
142 void ui_document_regint(void *doc, char *name, UiInteger *i) {
143 UiContext *ctx = ui_document_context(doc);
144 if(ctx) {
145 uic_reg_var(ctx, name, UI_VAR_INTEGER, sizeof(UiInteger), i);
146 }
147 }
148
149 void ui_document_regtext(void *doc, char *name, UiText *text) {
150 UiContext *ctx = ui_document_context(doc);
151 if(ctx) {
152 uic_reg_var(ctx, name, UI_VAR_TEXT, sizeof(UiText), text);
153 }
154 }
155
156 void ui_document_reglist(void *doc, char *name, UiList *list) {
157 UiContext *ctx = ui_document_context(doc);
158 if(ctx) {
159 UiListVar *lv = ui_document_malloc(doc, sizeof(UiListVar));
160 UiListPtr *lp = ui_document_malloc(doc, sizeof(UiListPtr));
161 lv->listptr = lp;
162 lp->list = list;
163 uic_reg_var(ctx, name, UI_VAR_LIST, sizeof(UiListPtr), lv);
164 }
165 }

mercurial