ui/common/document.c

changeset 1
eb5269000bc8
child 2
eeb50c534497
equal deleted inserted replaced
0:1f419bd32da1 1:eb5269000bc8
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "document.h"
34
35 static UcxMap *documents;
36
37 void uic_docmgr_init() {
38 documents = ucx_map_new(32);
39 }
40
41 void* ui_document_create(UiObject *obj, size_t size) {
42 UcxMempool *mp = ucx_mempool_new(256);
43 UiDocument *uidoc = ucx_mempool_malloc(mp, sizeof(UiDocument));
44 uidoc->obj = obj;
45 uidoc->allocator = ucx_mempool_allocator(mp);
46 uidoc->mempool = mp;
47 uidoc->vars = ucx_map_new_a(uidoc->allocator, 16);
48
49 void *document = ucx_mempool_calloc(mp, 1, size);
50 ucx_map_put(documents, ucx_key(&document, sizeof(void*)), uidoc);
51 return document;
52 }
53
54 void ui_document_destroy(void *doc) {
55 // TODO
56 }
57
58 void* ui_document_malloc(void *doc, size_t size) {
59 UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
60 return ucx_mempool_malloc(uidoc->mempool, size);
61 }
62
63 void* ui_document_calloc(void *doc, size_t nelem, size_t elsize) {
64 UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
65 return ucx_mempool_calloc(uidoc->mempool, nelem, elsize);
66 }
67
68 void ui_document_free(void *doc, void *ptr) {
69 UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
70 ucx_mempool_free(uidoc->mempool, ptr);
71 }
72
73 void* ui_document_realloc(void *doc, void *ptr, size_t size) {
74 UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
75 return ucx_mempool_realloc(uidoc->mempool, ptr, size);
76 }
77
78
79 UiVar* uic_document_getvar(UiDocument *doc, char *name) {
80 return ucx_map_cstr_get(doc->vars, name);
81 }
82
83 void ui_document_addint(void *doc, char *name) {
84 UiDocument *uidoc = ucx_map_get(documents, ucx_key(&doc, sizeof(void*)));
85 if(!uidoc) {
86 return;
87 }
88
89 UiVar *dvar = uic_document_getvar(uidoc, name);
90 UiVar *wvar = uic_getvar(uidoc->obj, name);
91 if(!dvar) {
92 UiVar *var = ucx_mempool_malloc(uidoc->mempool, sizeof(UiVar));
93 var->isextern = 0;
94 var->type = 1;
95 UiInteger *i = ucx_mempool_calloc(uidoc->mempool, 1, sizeof(UiVar));
96 if(wvar && !wvar->isextern) {
97 *i = *(UiInteger*)wvar->value;
98 }
99 }
100
101 if(wvar && wvar->isextern) {
102 fprintf(stderr, "UI Error: window variable moved to document!\n");
103 }
104 uic_rmvar(uidoc->obj, name);
105 }
106
107 void ui_document_regint(void *doc, char *name, UiInteger *i) {
108
109 }
110
111 void ui_document_setint(void *doc, char *name, int val) {
112
113 }
114
115 int ui_document_getint(void *doc, char *name) {
116
117 }

mercurial