| 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 } |