call context close handler on window close (WinUI3) newapi

Thu, 08 Feb 2024 10:17:59 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 08 Feb 2024 10:17:59 +0100
branch
newapi
changeset 247
4b21af9d8c5a
parent 246
b19f3098dd11
child 248
22257f5f4019

call context close handler on window close (WinUI3)

ui/common/context.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
ui/winui/window.cpp file | annotate | diff | comparison | revisions
--- 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) {
--- 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);
--- 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);

mercurial