ui/common/object.c

changeset 431
bb7da585debc
parent 406
0ebf9d7b23e8
child 440
7c4b9cba09ca
equal deleted inserted replaced
169:fe49cff3c571 431:bb7da585debc
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include "object.h" 32 #include "object.h"
33 #include "context.h" 33 #include "context.h"
34 34
35 #include "../ui/container.h"
36
35 void ui_end(UiObject *obj) { 37 void ui_end(UiObject *obj) {
36 if(!obj->next) { 38 if(!obj->next) {
37 return; 39 return;
38 } 40 }
39 41
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 }

mercurial