# HG changeset patch # User Olaf Wintermann # Date 1750102915 -7200 # Node ID 3f0c9fe60c68ee896891713aa58800f2b7060456 # Parent 724c7036a03e29c3f56047d60a311a7c5ba503c9 use uic_object_new_toplevel to create toplevel objects diff -r 724c7036a03e -r 3f0c9fe60c68 ui/common/object.c --- a/ui/common/object.c Mon Jun 16 21:21:00 2025 +0200 +++ b/ui/common/object.c Mon Jun 16 21:41:55 2025 +0200 @@ -131,6 +131,14 @@ cxMempoolFree(obj->ctx->mp); } +UiObject* uic_object_new_toplevel(void) { + CxMempool *mp = cxMempoolCreateSimple(256); + UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); + obj->ctx = uic_context(obj, mp); + uic_object_created(obj); + return obj; +} + UiObject* uic_object_new(UiObject *toplevel, UIWIDGET widget) { return uic_ctx_object_new(toplevel->ctx, widget); } diff -r 724c7036a03e -r 3f0c9fe60c68 ui/common/object.h --- a/ui/common/object.h Mon Jun 16 21:21:00 2025 +0200 +++ b/ui/common/object.h Mon Jun 16 21:41:55 2025 +0200 @@ -45,6 +45,7 @@ void uic_object_destroy(UiObject *obj); +UiObject* uic_object_new_toplevel(void); UiObject* uic_object_new(UiObject *toplevel, UIWIDGET widget); UiObject* uic_ctx_object_new(UiContext *ctx, UIWIDGET widget); void uic_obj_add(UiObject *toplevel, UiObject *ctobj); diff -r 724c7036a03e -r 3f0c9fe60c68 ui/gtk/window.c --- a/ui/gtk/window.c Mon Jun 16 21:21:00 2025 +0200 +++ b/ui/gtk/window.c Mon Jun 16 21:41:55 2025 +0200 @@ -102,9 +102,7 @@ #endif static UiObject* create_window(const char *title, void *window_data, UiBool sidebar, UiBool simple) { - CxMempool *mp = cxMempoolCreateSimple(256); - UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); - obj->ref = 0; + UiObject *obj = uic_object_new_toplevel(); #ifdef UI_LIBADWAITA obj->widget = adw_application_window_new(ui_get_application()); @@ -114,8 +112,6 @@ obj->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); #endif - - obj->ctx = uic_context(obj, mp); obj->window = window_data; #if GTK_CHECK_VERSION(4, 0, 0) @@ -761,9 +757,7 @@ gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); } - CxMempool *mp = cxMempoolCreateSimple(256); - UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); - obj->ctx = uic_context(obj, mp); + UiObject *obj = uic_object_new_toplevel(); obj->widget = dialog; obj->ref = 0; obj->destroy = ui_window_widget_destroy; diff -r 724c7036a03e -r 3f0c9fe60c68 ui/motif/window.c --- a/ui/motif/window.c Mon Jun 16 21:21:00 2025 +0200 +++ b/ui/motif/window.c Mon Jun 16 21:41:55 2025 +0200 @@ -70,8 +70,7 @@ static UiObject* create_window(const char *title, void *window_data, Boolean simple) { CxMempool *mp = cxMempoolCreateSimple(256); const CxAllocator *a = mp->allocator; - UiObject *obj = cxCalloc(a, 1, sizeof(UiObject)); - obj->ctx = uic_context(obj, mp); + UiObject *obj = uic_object_new_toplevel(); obj->window = window_data; obj->destroy = ui_window_widget_destroy; diff -r 724c7036a03e -r 3f0c9fe60c68 ui/qt/window.cpp --- a/ui/qt/window.cpp Mon Jun 16 21:21:00 2025 +0200 +++ b/ui/qt/window.cpp Mon Jun 16 21:41:55 2025 +0200 @@ -28,6 +28,7 @@ #include #include "../common/context.h" +#include "../common/object.h" #include "window.h" #include "menu.h" @@ -39,9 +40,7 @@ #include static UiObject* create_window(const char *title, void *window_data, bool simple) { - CxMempool *mp = cxMempoolCreateSimple(256); - UiObject *obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject)); - obj->ctx = uic_context(obj, mp); + UiObject *obj = uic_object_new_toplevel(); obj->window = window_data; obj->next = NULL; diff -r 724c7036a03e -r 3f0c9fe60c68 ui/win32/window.c --- a/ui/win32/window.c Mon Jun 16 21:21:00 2025 +0200 +++ b/ui/win32/window.c Mon Jun 16 21:41:55 2025 +0200 @@ -29,6 +29,8 @@ #include "window.h" #include "Windows.h" +#include "../common/object.h" + #include #include @@ -67,10 +69,7 @@ } static UiObject* create_window(const char *title, void *window_data, bool simple) { - CxMempool *mp = cxMempoolCreateSimple(256); - const CxAllocator *a = mp->allocator; - UiObject *obj = cxCalloc(a, 1, sizeof(UiObject)); - obj->ctx = uic_context(obj, mp); + UiObject *obj = uic_object_new_toplevel(); obj->window = window_data; HWND hwnd = CreateWindowEx( diff -r 724c7036a03e -r 3f0c9fe60c68 ui/winui/window.cpp --- a/ui/winui/window.cpp Mon Jun 16 21:21:00 2025 +0200 +++ b/ui/winui/window.cpp Mon Jun 16 21:41:55 2025 +0200 @@ -147,8 +147,7 @@ } UIEXPORT UiObject* ui_simple_window(const char *title, void *window_data) { - CxMempool* mp = cxMempoolCreateSimple(256); - UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject)); + UiObject* obj = uic_object_new_toplevel(); obj->ctx = uic_context(obj, mp); obj->window = window_data;