56 UiContext* uic_context(UiObject *toplevel, CxMempool *mp) { |
56 UiContext* uic_context(UiObject *toplevel, CxMempool *mp) { |
57 UiContext *ctx = cxMalloc(mp->allocator, sizeof(UiContext)); |
57 UiContext *ctx = cxMalloc(mp->allocator, sizeof(UiContext)); |
58 memset(ctx, 0, sizeof(UiContext)); |
58 memset(ctx, 0, sizeof(UiContext)); |
59 ctx->mp = mp; |
59 ctx->mp = mp; |
60 ctx->allocator = mp->allocator; |
60 ctx->allocator = mp->allocator; |
|
61 ctx->destroy_handler = cxArrayListCreate(ctx->allocator, NULL, sizeof(UiDestroyHandler), 16); |
61 ctx->obj = toplevel; |
62 ctx->obj = toplevel; |
62 ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16); |
63 ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16); |
63 |
64 |
64 ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, CX_STORE_POINTERS); |
65 ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, CX_STORE_POINTERS); |
65 ctx->group_widgets = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, sizeof(UiGroupWidget)); |
66 ctx->group_widgets = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, sizeof(UiGroupWidget)); |
78 return ctx; |
79 return ctx; |
79 } |
80 } |
80 |
81 |
81 UiContext* uic_root_context(UiContext *ctx) { |
82 UiContext* uic_root_context(UiContext *ctx) { |
82 return ctx->parent ? uic_root_context(ctx->parent) : ctx; |
83 return ctx->parent ? uic_root_context(ctx->parent) : ctx; |
|
84 } |
|
85 |
|
86 void uic_context_add_destructor(UiContext *ctx, cx_destructor_func func, void *data) { |
|
87 UiDestroyHandler handler; |
|
88 handler.destructor = func; |
|
89 handler.data = data; |
|
90 cxListAdd(ctx->destroy_handler, &handler); |
83 } |
91 } |
84 |
92 |
85 void uic_context_prepare_close(UiContext *ctx) { |
93 void uic_context_prepare_close(UiContext *ctx) { |
86 cxListClear(ctx->groups); |
94 cxListClear(ctx->groups); |
87 cxListClear(ctx->group_widgets); |
95 cxListClear(ctx->group_widgets); |
467 ctx->close_callback = fnc; |
475 ctx->close_callback = fnc; |
468 ctx->close_data = udata; |
476 ctx->close_data = udata; |
469 } |
477 } |
470 |
478 |
471 UIEXPORT void ui_context_destroy(UiContext *ctx) { |
479 UIEXPORT void ui_context_destroy(UiContext *ctx) { |
|
480 CxIterator i = cxListIterator(ctx->destroy_handler); |
|
481 cx_foreach(UiDestroyHandler *, h, i) { |
|
482 h->destructor(h->data); |
|
483 } |
472 cxMempoolFree(ctx->mp); |
484 cxMempoolFree(ctx->mp); |
473 } |
485 } |
474 |
486 |
475 |
487 |
476 void ui_set_group(UiContext *ctx, int group) { |
488 void ui_set_group(UiContext *ctx, int group) { |