47 // TODO: free last obj |
49 // TODO: free last obj |
48 prev->next = NULL; |
50 prev->next = NULL; |
49 } |
51 } |
50 } |
52 } |
51 |
53 |
|
54 void ui_end_new(UiObject *obj) { |
|
55 if(!obj->container_end) { |
|
56 return; |
|
57 } |
|
58 UiContainerX *rm = obj->container_end; |
|
59 uic_object_pop_container(obj); |
|
60 ui_free(obj->ctx, rm); |
|
61 } |
|
62 |
|
63 void ui_object_ref(UiObject *obj) { |
|
64 obj->ref++; |
|
65 } |
|
66 |
|
67 int ui_object_unref(UiObject *obj) { |
|
68 // it is possible to have 0 references, in case |
|
69 // a window was created but ui_show was never called |
|
70 if(obj->ref == 0 || --obj->ref == 0) { |
|
71 if(obj->destroy) { |
|
72 obj->destroy(obj); |
|
73 } |
|
74 uic_object_destroy(obj); |
|
75 return 0; |
|
76 } |
|
77 return 1; |
|
78 } |
|
79 |
|
80 void uic_object_destroy(UiObject *obj) { |
|
81 if(obj->ctx->close_callback) { |
|
82 UiEvent ev; |
|
83 ev.window = obj->window; |
|
84 ev.document = obj->ctx->document; |
|
85 ev.obj = obj; |
|
86 ev.eventdata = NULL; |
|
87 ev.intval = 0; |
|
88 obj->ctx->close_callback(&ev, obj->ctx->close_data); |
|
89 } |
|
90 cxMempoolDestroy(obj->ctx->mp); |
|
91 } |
52 |
92 |
53 UiObject* uic_object_new(UiObject *toplevel, UIWIDGET widget) { |
93 UiObject* uic_object_new(UiObject *toplevel, UIWIDGET widget) { |
54 UiContext *ctx = toplevel->ctx; |
94 return uic_ctx_object_new(toplevel->ctx, widget); |
55 |
95 } |
56 UiObject *newobj = ucx_mempool_calloc(ctx->mempool, 1, sizeof(UiObject)); |
96 |
|
97 UiObject* uic_ctx_object_new(UiContext *ctx, UIWIDGET widget) { |
|
98 UiObject *newobj = cxCalloc(ctx->allocator, 1, sizeof(UiObject)); |
57 newobj->ctx = ctx; |
99 newobj->ctx = ctx; |
58 newobj->widget = widget; |
100 newobj->widget = widget; |
59 |
101 |
60 return newobj; |
102 return newobj; |
61 } |
103 } |
77 } |
119 } |
78 |
120 |
79 UiContainer* uic_get_current_container(UiObject *obj) { |
121 UiContainer* uic_get_current_container(UiObject *obj) { |
80 return uic_current_obj(obj)->container; |
122 return uic_current_obj(obj)->container; |
81 } |
123 } |
|
124 |
|
125 void uic_object_push_container(UiObject *toplevel, UiContainerX *newcontainer) { |
|
126 newcontainer->prev = toplevel->container_end; |
|
127 if(toplevel->container_end) { |
|
128 toplevel->container_end->next = newcontainer; |
|
129 toplevel->container_end = newcontainer; |
|
130 } else { |
|
131 toplevel->container_begin = newcontainer; |
|
132 toplevel->container_end = newcontainer; |
|
133 } |
|
134 } |
|
135 |
|
136 void uic_object_pop_container(UiObject *toplevel) { |
|
137 toplevel->container_end = toplevel->container_end->prev; |
|
138 if(toplevel->container_end) { |
|
139 toplevel->container_end->next = NULL; |
|
140 } else { |
|
141 toplevel->container_begin = NULL; |
|
142 } |
|
143 } |