| 72 cx_foreach(objcallback *, cb, i) { |
72 cx_foreach(objcallback *, cb, i) { |
| 73 cb->func(obj, cb->userdata); |
73 cb->func(obj, cb->userdata); |
| 74 } |
74 } |
| 75 } |
75 } |
| 76 |
76 |
| 77 void ui_end(UiObject *obj) { |
|
| 78 if(!obj->next) { |
|
| 79 return; |
|
| 80 } |
|
| 81 |
|
| 82 UiObject *prev = NULL; |
|
| 83 while(obj->next) { |
|
| 84 prev = obj; |
|
| 85 obj = obj->next; |
|
| 86 } |
|
| 87 |
|
| 88 if(prev) { |
|
| 89 // TODO: free last obj |
|
| 90 prev->next = NULL; |
|
| 91 } |
|
| 92 } |
|
| 93 |
|
| 94 void ui_end_new(UiObject *obj) { |
|
| 95 if(!obj->container_end) { |
|
| 96 return; |
|
| 97 } |
|
| 98 UiContainerX *rm = obj->container_end; |
|
| 99 uic_object_pop_container(obj); |
|
| 100 ui_free(obj->ctx, rm); |
|
| 101 } |
|
| 102 |
|
| 103 void ui_object_ref(UiObject *obj) { |
77 void ui_object_ref(UiObject *obj) { |
| 104 obj->ref++; |
78 obj->ref++; |
| 105 } |
79 } |
| 106 |
80 |
| 107 int ui_object_unref(UiObject *obj) { |
81 int ui_object_unref(UiObject *obj) { |
| 139 obj->ctx->parent = ui_global_context(); |
113 obj->ctx->parent = ui_global_context(); |
| 140 uic_object_created(obj); |
114 uic_object_created(obj); |
| 141 return obj; |
115 return obj; |
| 142 } |
116 } |
| 143 |
117 |
| 144 UiObject* uic_object_new(UiObject *toplevel, UIWIDGET widget) { |
|
| 145 return uic_ctx_object_new(toplevel->ctx, widget); |
|
| 146 } |
|
| 147 |
|
| 148 UiObject* uic_ctx_object_new(UiContext *ctx, UIWIDGET widget) { |
118 UiObject* uic_ctx_object_new(UiContext *ctx, UIWIDGET widget) { |
| 149 UiObject *newobj = cxCalloc(ctx->allocator, 1, sizeof(UiObject)); |
119 UiObject *newobj = cxCalloc(ctx->allocator, 1, sizeof(UiObject)); |
| 150 newobj->ctx = ctx; |
120 newobj->ctx = ctx; |
| 151 newobj->widget = widget; |
121 newobj->widget = widget; |
| 152 uic_object_created(newobj); |
122 uic_object_created(newobj); |
| 153 return newobj; |
123 return newobj; |
| 154 } |
|
| 155 |
|
| 156 void uic_obj_add(UiObject *toplevel, UiObject *ctobj) { |
|
| 157 UiObject *current = uic_current_obj(toplevel); |
|
| 158 current->next = ctobj; |
|
| 159 } |
|
| 160 |
|
| 161 UiObject* uic_current_obj(UiObject *toplevel) { |
|
| 162 if(!toplevel) { |
|
| 163 return NULL; |
|
| 164 } |
|
| 165 UiObject *obj = toplevel; |
|
| 166 while(obj->next) { |
|
| 167 obj = obj->next; |
|
| 168 } |
|
| 169 return obj; |
|
| 170 } |
|
| 171 |
|
| 172 UiContainer* uic_get_current_container(UiObject *obj) { |
|
| 173 return uic_current_obj(obj)->container; |
|
| 174 } |
124 } |
| 175 |
125 |
| 176 void uic_object_push_container(UiObject *toplevel, UiContainerX *newcontainer) { |
126 void uic_object_push_container(UiObject *toplevel, UiContainerX *newcontainer) { |
| 177 newcontainer->prev = toplevel->container_end; |
127 newcontainer->prev = toplevel->container_end; |
| 178 if(toplevel->container_end) { |
128 if(toplevel->container_end) { |