Mon, 21 Oct 2024 15:47:10 +0200
implement context destroy
ui/common/context.c | file | annotate | diff | comparison | revisions | |
ui/common/document.c | file | annotate | diff | comparison | revisions | |
ui/common/types.c | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/ui/common/context.c Sun Oct 20 21:26:06 2024 +0200 +++ b/ui/common/context.c Mon Oct 21 15:47:10 2024 +0200 @@ -541,8 +541,8 @@ cxListAdd(ctx->group_widgets, &gw); } -UIEXPORT void *ui_ctx_allocator(UiContext *ctx) { - return (void*) ctx ? ctx->allocator : NULL; +UIEXPORT void *ui_allocator(UiContext *ctx) { + return ctx ? (void*)ctx->allocator : NULL; } void* ui_malloc(UiContext *ctx, size_t size) { @@ -563,3 +563,11 @@ return ctx ? cxRealloc(ctx->allocator, ptr, size) : NULL; } +UIEXPORT char* ui_strdup(UiContext *ctx, const char *str) { + if(!ctx) { + return NULL; + } + cxstring s = cx_str(str); + cxmutstr d = cx_strdup_a(ctx->allocator, s); + return d.ptr; +}
--- a/ui/common/document.c Sun Oct 20 21:26:06 2024 +0200 +++ b/ui/common/document.c Mon Oct 21 15:47:10 2024 +0200 @@ -96,7 +96,20 @@ } void ui_document_destroy(void *doc) { - // TODO + UiContext *ctx = ui_document_context(doc); + if(ctx) { + UiEvent ev; + ev.window = NULL; + ev.document = doc; + ev.obj = NULL; + ev.eventdata = NULL; + ev.intval = 0; + + if(ctx->close_callback) { + ctx->close_callback(&ev, ctx->close_data); + } + cxMempoolDestroy(ctx->mp); + } } UiContext* ui_document_context(void *doc) {
--- a/ui/common/types.c Sun Oct 20 21:26:06 2024 +0200 +++ b/ui/common/types.c Mon Oct 21 15:47:10 2024 +0200 @@ -158,6 +158,10 @@ cxListClear(list->data); } +UIEXPORT void ui_list_update(UiList *list) { + list->update(list, 0); +} + void ui_list_addobsv(UiList *list, ui_callback f, void *data) { list->observers = ui_add_observer(list->observers, f, data); }
--- a/ui/ui/toolkit.h Sun Oct 20 21:26:06 2024 +0200 +++ b/ui/ui/toolkit.h Mon Oct 21 15:47:10 2024 +0200 @@ -447,11 +447,12 @@ UIEXPORT void ui_unset_group(UiContext *ctx, int group); UIEXPORT int* ui_active_groups(UiContext *ctx, int *ngroups); -UIEXPORT void *ui_ctx_allocator(UiContext *ctx); +UIEXPORT void* ui_allocator(UiContext *ctx); UIEXPORT void* ui_malloc(UiContext *ctx, size_t size); UIEXPORT void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize); UIEXPORT void ui_free(UiContext *ctx, void *ptr); UIEXPORT void* ui_realloc(UiContext *ctx, void *ptr, size_t size); +UIEXPORT char* ui_strdup(UiContext *ctx, const char *str); // types @@ -502,13 +503,14 @@ UIEXPORT void* ui_list_first(UiList *list); UIEXPORT void* ui_list_next(UiList *list); UIEXPORT void* ui_list_get(UiList *list, int i); -UIEXPORT int ui_list_count(UiList *list); -UIEXPORT void ui_list_append(UiList *list, void *data); -UIEXPORT void ui_list_prepend(UiList *list, void *data); +UIEXPORT int ui_list_count(UiList *list); +UIEXPORT void ui_list_append(UiList *list, void *data); +UIEXPORT void ui_list_prepend(UiList *list, void *data); UIEXPORT void ui_list_remove(UiList *list, int i); UIEXPORT void ui_list_clear(UiList *list); -UIEXPORT void ui_list_addobsv(UiList *list, ui_callback f, void *data); -UIEXPORT void ui_list_notify(UiList *list); +UIEXPORT void ui_list_update(UiList *list); +UIEXPORT void ui_list_addobsv(UiList *list, ui_callback f, void *data); +UIEXPORT void ui_list_notify(UiList *list); UIEXPORT UiListSelection ui_list_getselection(UiList *list);