ui/common/object.c

changeset 932
28fc967f74ef
parent 886
6f5e02fcb7b9
child 935
d95e8723545c
equal deleted inserted replaced
931:6ca1ef6c8107 932:28fc967f74ef
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include "object.h" 31 #include "object.h"
32 #include "context.h" 32 #include "context.h"
33 33
34 #include <cx/linked_list.h> 34 #include <cx/linked_list.h>
35 #include <cx/hash_map.h>
35 36
36 #include "../ui/container.h" 37 #include "../ui/container.h"
37 38
38 static CxList *creation_callbacks; 39 static CxList *creation_callbacks;
39 static CxList *destruction_callbacks; 40 static CxList *destruction_callbacks;
106 } 107 }
107 108
108 UiObject* uic_object_new_toplevel(void) { 109 UiObject* uic_object_new_toplevel(void) {
109 fflush(stdout); 110 fflush(stdout);
110 CxMempool *mp = cxMempoolCreateSimple(256); 111 CxMempool *mp = cxMempoolCreateSimple(256);
111 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); 112 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObjectPrivate));
112 fflush(stdout); 113 fflush(stdout);
113 obj->ctx = uic_context(obj, mp); 114 obj->ctx = uic_context(obj, mp);
114 obj->ctx->parent = ui_global_context(); 115 obj->ctx->parent = ui_global_context();
115 fflush(stdout); 116 fflush(stdout);
116 uic_object_created(obj); 117 uic_object_created(obj);
117 fflush(stdout); 118 fflush(stdout);
118 return obj; 119 return obj;
119 } 120 }
120 121
121 UiObject* uic_ctx_object_new(UiContext *ctx, UIWIDGET widget) { 122 UiObject* uic_ctx_object_new(UiContext *ctx, UIWIDGET widget) {
122 UiObject *newobj = cxCalloc(ctx->allocator, 1, sizeof(UiObject)); 123 UiObject *newobj = cxCalloc(ctx->allocator, 1, sizeof(UiObjectPrivate));
123 newobj->ctx = ctx; 124 newobj->ctx = ctx;
124 newobj->widget = widget; 125 newobj->widget = widget;
125 uic_object_created(newobj); 126 uic_object_created(newobj);
126 return newobj; 127 return newobj;
127 } 128 }
168 // TODO: free container? 169 // TODO: free container?
169 } else { 170 } else {
170 fprintf(stderr, "Error: uic_object_remove_second_last_container expected at least 2 containers\n"); 171 fprintf(stderr, "Error: uic_object_remove_second_last_container expected at least 2 containers\n");
171 } 172 }
172 } 173 }
174
175 // public API
176
177 void ui_object_set(UiObject *obj, const char *key, void *data) {
178 UiObjectPrivate *p = (UiObjectPrivate*)obj;
179 if(!p->ext) {
180 p->ext = cxHashMapCreate(obj->ctx->mp->allocator, CX_STORE_POINTERS, 4);
181 }
182 if(data) {
183 cxMapPut(p->ext, key, data);
184 } else {
185 cxMapRemove(p->ext, key);
186 }
187 }
188
189 void* ui_object_get(UiObject *obj, const char *key) {
190 UiObjectPrivate *p = (UiObjectPrivate*)obj;
191 if(p->ext) {
192 return cxMapGet(p->ext, key);
193 }
194 }

mercurial