31 #include <string.h> |
31 #include <string.h> |
32 |
32 |
33 #include "context.h" |
33 #include "context.h" |
34 #include "../ui/window.h" |
34 #include "../ui/window.h" |
35 |
35 |
36 void uic_docmgr_init() { |
|
37 |
|
38 } |
|
39 |
36 |
40 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) { |
37 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) { |
41 UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext)); |
38 UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext)); |
42 UcxAllocator *allocator = ucx_mempool_allocator(mp); |
39 UcxAllocator *allocator = ucx_mempool_allocator(mp); |
43 ctx->mempool = mp; |
40 ctx->mempool = mp; |
48 |
45 |
49 return ctx; |
46 return ctx; |
50 } |
47 } |
51 |
48 |
52 UiVar* uic_getvar(UiObject *obj, char *name) { |
49 UiVar* uic_getvar(UiObject *obj, char *name) { |
|
50 if(!obj) { |
|
51 return NULL; |
|
52 } |
53 return ucx_map_cstr_get(obj->ctx->vars, name); |
53 return ucx_map_cstr_get(obj->ctx->vars, name); |
54 } |
54 } |
55 |
55 |
56 UiVar* uic_addplaceholder(UiObject *obj, char *name) { |
56 void uic_rmvar(UiObject *obj, char *name) { |
57 UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); |
57 if(obj) { |
58 var->type = -1; |
58 UiVar *var = uic_getvar(obj, name); |
59 var->value = NULL; |
59 if(var) { |
60 ucx_map_cstr_put(obj->ctx->vars, name, var); |
60 if(var->isextern) { |
|
61 ucx_mempool_free(obj->ctx->mempool, var->value); |
|
62 } |
|
63 ucx_mempool_free(obj->ctx->mempool, var); |
|
64 } |
|
65 } |
61 } |
66 } |
62 |
67 |
63 void ui_window_addint(UiObject *obj, char *name) { |
68 void ui_window_addint(UiObject *obj, char *name) { |
64 if(uic_getvar(obj, name)) { |
69 if(uic_getvar(obj, name)) { |
65 // var already exists |
70 // var already exists |
66 return; |
71 return; |
67 } |
72 } |
68 UiInteger *i = ucx_mempool_calloc(obj->ctx->mempool, 1, sizeof(UiInteger)); |
73 UiInteger *i = ucx_mempool_calloc(obj->ctx->mempool, 1, sizeof(UiInteger)); |
69 ui_window_regint(obj, name, i); |
74 UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); |
|
75 var->value = i; |
|
76 var->type = 1; |
|
77 var->isextern = 0; |
|
78 ucx_map_cstr_put(obj->ctx->vars, name, var); |
70 } |
79 } |
71 |
80 |
72 void ui_window_regint(UiObject *obj, char *name, UiInteger *i) { |
81 void ui_window_regint(UiObject *obj, char *name, UiInteger *i) { |
73 if(uic_getvar(obj, name)) { |
82 if(uic_getvar(obj, name)) { |
74 // var already exists |
83 // var already exists |
75 return; |
84 return; |
76 } |
85 } |
77 UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); |
86 UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); |
78 var->value = i; |
87 var->value = i; |
79 var->type = 1; |
88 var->type = 1; |
|
89 var->isextern = 1; |
80 ucx_map_cstr_put(obj->ctx->vars, name, var); |
90 ucx_map_cstr_put(obj->ctx->vars, name, var); |
81 } |
91 } |
82 |
92 |
83 void ui_window_setint(UiObject *obj, char *name, int val) { |
93 void ui_window_setint(UiObject *obj, char *name, int val) { |
84 UiVar *var = uic_getvar(obj, name); |
94 UiVar *var = uic_getvar(obj, name); |