ui/common/context.c

changeset 1195
6ec3c71ba298
parent 1169
c69f2941d536
equal deleted inserted replaced
1194:91696f7fa475 1195:6ec3c71ba298
122 ev.eventdata = NULL; 122 ev.eventdata = NULL;
123 ev.eventdatatype = 0; 123 ev.eventdatatype = 0;
124 ev.intval = 0; 124 ev.intval = 0;
125 ev.set = 0; 125 ev.set = 0;
126 126
127 if(ctx->close_callback) { 127 if(ctx->onclose) {
128 ctx->close_callback(&ev, ctx->close_data); 128 ctx->onclose(&ev, ctx->onclosedata);
129 } 129 }
130 130
131 CxIterator i = cxListIterator(ctx->destroy_handler); 131 CxIterator i = cxListIterator(ctx->destroy_handler);
132 cx_foreach(UiDestroyHandler *, h, i) { 132 cx_foreach(UiDestroyHandler *, h, i) {
133 h->destructor(h->data); 133 h->destructor(h->data);
188 UiContext *doc_ctx = ui_document_context(document); 188 UiContext *doc_ctx = ui_document_context(document);
189 doc_ctx->parent = ctx; 189 doc_ctx->parent = ctx;
190 doc_ctx->ref++; 190 doc_ctx->ref++;
191 191
192 uic_context_update_bindings(doc_ctx); 192 uic_context_update_bindings(doc_ctx);
193 if(doc_ctx->onattach) {
194 UiEvent event;
195 memset(&event, 0, sizeof(UiEvent));
196 event.document = document;
197 doc_ctx->onattach(&event, doc_ctx->onattachdata);
198 }
193 } 199 }
194 200
195 static void uic_context_unbind_vars(UiContext *ctx) { 201 static void uic_context_unbind_vars(UiContext *ctx) {
196 int onchange_enabled = ui_onchange_events_is_enabled(); 202 int onchange_enabled = ui_onchange_events_is_enabled();
197 int onselection_enabled = ui_selection_events_is_enabled(); 203 int onselection_enabled = ui_selection_events_is_enabled();
231 } 237 }
232 238
233 cxListRemove(ctx->documents, docIndex); 239 cxListRemove(ctx->documents, docIndex);
234 ctx->document = cxListAt(ctx->documents, 0); 240 ctx->document = cxListAt(ctx->documents, 0);
235 241
236 UiContext *docctx = ui_document_context(document); 242 UiContext *doc_ctx = ui_document_context(document);
237 uic_context_unbind_vars(docctx); // unbind all doc/subdoc vars from the parent 243 uic_context_unbind_vars(doc_ctx); // unbind all doc/subdoc vars from the parent
238 docctx->parent = NULL; 244 doc_ctx->parent = NULL;
239 ui_document_unref(document); 245 ui_document_unref(document);
240 246
241 ui_update_action_bindings(ctx); 247 ui_update_action_bindings(ctx);
248 if(doc_ctx->ondetach) {
249 UiEvent event;
250 memset(&event, 0, sizeof(UiEvent));
251 event.document = document;
252 doc_ctx->ondetach(&event, doc_ctx->ondetachdata);
253 }
242 } 254 }
243 255
244 void uic_context_detach_all(UiContext *ctx) { 256 void uic_context_detach_all(UiContext *ctx) {
245 // copy list 257 // copy list
246 CxList *ls = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); 258 CxList *ls = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS);
598 void ui_detach_document(UiContext *ctx, void *document) { 610 void ui_detach_document(UiContext *ctx, void *document) {
599 uic_context_detach_document(ctx, document); 611 uic_context_detach_document(ctx, document);
600 } 612 }
601 613
602 void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata) { 614 void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata) {
603 ctx->close_callback = fnc; 615 ctx->onclose = fnc;
604 ctx->close_data = udata; 616 ctx->onclosedata = udata;
605 } 617 }
606 618
607 UiContext* ui_context_parent(UiContext *ctx) { 619 UiContext* ui_context_parent(UiContext *ctx) {
608 return ctx->parent; 620 return ctx->parent;
609 } 621 }

mercurial