# HG changeset patch # User Olaf Wintermann # Date 1707383879 -3600 # Node ID 4b21af9d8c5a6d309fe86c355c469014d73ecaae # Parent b19f3098dd1136eea3337a7771279d9c843f2bea call context close handler on window close (WinUI3) diff -r b19f3098dd11 -r 4b21af9d8c5a ui/common/context.c --- a/ui/common/context.c Wed Feb 07 17:15:03 2024 +0100 +++ b/ui/common/context.c Thu Feb 08 10:17:59 2024 +0100 @@ -436,6 +436,10 @@ ctx->close_data = udata; } +UIEXPORT void ui_context_destroy(UiContext *ctx) { + cxMempoolDestroy(ctx->mp); +} + void ui_set_group(UiContext *ctx, int group) { if(cxListFind(ctx->groups, &group) == -1) { diff -r b19f3098dd11 -r 4b21af9d8c5a ui/ui/toolkit.h --- a/ui/ui/toolkit.h Wed Feb 07 17:15:03 2024 +0100 +++ b/ui/ui/toolkit.h Thu Feb 08 10:17:59 2024 +0100 @@ -371,6 +371,8 @@ UIEXPORT void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata); +UIEXPORT void ui_context_destroy(UiContext *ctx); + UIEXPORT void ui_onstartup(ui_callback f, void *userdata); UIEXPORT void ui_onopen(ui_callback f, void *userdata); UIEXPORT void ui_onexit(ui_callback f, void *userdata); diff -r b19f3098dd11 -r 4b21af9d8c5a ui/winui/window.cpp --- a/ui/winui/window.cpp Wed Feb 07 17:15:03 2024 +0100 +++ b/ui/winui/window.cpp Thu Feb 08 10:17:59 2024 +0100 @@ -171,7 +171,17 @@ ui_context_add_window_destructor(obj->ctx, obj->wobj); window.Closed([obj](IInspectable const& sender, WindowEventArgs) { - cxMempoolDestroy(obj->ctx->mp); + if (obj->ctx->close_callback) { + UiEvent evt; + evt.obj = obj; + evt.document = obj->ctx->document; + evt.window = obj->window; + evt.eventdata = NULL; + evt.intval = 0; + obj->ctx->close_callback(&evt, obj->ctx->close_data); + } else { + ui_context_destroy(obj->ctx); + } }); obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0);