use uic_object_new_toplevel to create toplevel objects

Mon, 16 Jun 2025 21:41:55 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 16 Jun 2025 21:41:55 +0200
changeset 627
3f0c9fe60c68
parent 626
724c7036a03e
child 628
8e39f713169b
child 629
0385a450c2a6

use uic_object_new_toplevel to create toplevel objects

ui/common/object.c file | annotate | diff | comparison | revisions
ui/common/object.h file | annotate | diff | comparison | revisions
ui/gtk/window.c file | annotate | diff | comparison | revisions
ui/motif/window.c file | annotate | diff | comparison | revisions
ui/qt/window.cpp file | annotate | diff | comparison | revisions
ui/win32/window.c file | annotate | diff | comparison | revisions
ui/winui/window.cpp file | annotate | diff | comparison | revisions
--- 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);
 }
--- 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);
--- 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;
--- 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;
     
--- 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 <cx/mempool.h>
 #include "../common/context.h"
+#include "../common/object.h"
 
 #include "window.h"
 #include "menu.h"
@@ -39,9 +40,7 @@
 #include <QPushButton>
 
 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;
     
--- 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 <stdbool.h>
 #include <stdio.h>
@@ -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(
--- 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;

mercurial