ui/common/object.c

changeset 100
d2bd73d28ff1
parent 86
8e7c57c23133
equal deleted inserted replaced
99:b9767cb5b06b 100:d2bd73d28ff1
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
52 void ui_object_ref(UiObject *obj) { 63 void ui_object_ref(UiObject *obj) {
53 obj->ref++; 64 obj->ref++;
54 } 65 }
55 66
56 void ui_object_unref(UiObject *obj) { 67 int ui_object_unref(UiObject *obj) {
57 // it is possible to have 0 references, in case 68 // it is possible to have 0 references, in case
58 // a window was created but ui_show was never called 69 // a window was created but ui_show was never called
59 if(obj->ref == 0 || --obj->ref == 0) { 70 if(obj->ref == 0 || --obj->ref == 0) {
60 if(obj->destroy) { 71 if(obj->destroy) {
61 obj->destroy(obj); 72 obj->destroy(obj);
62 } else {
63 uic_object_destroy(obj);
64 } 73 }
74 uic_object_destroy(obj);
75 return 0;
65 } 76 }
77 return 1;
66 } 78 }
67 79
68 void uic_object_destroy(UiObject *obj) { 80 void uic_object_destroy(UiObject *obj) {
69 if(obj->ctx->close_callback) { 81 if(obj->ctx->close_callback) {
70 UiEvent ev; 82 UiEvent ev;
107 } 119 }
108 120
109 UiContainer* uic_get_current_container(UiObject *obj) { 121 UiContainer* uic_get_current_container(UiObject *obj) {
110 return uic_current_obj(obj)->container; 122 return uic_current_obj(obj)->container;
111 } 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