redefine UIWIDGET, remove widget abstraction class (WinUI) newapi

Mon, 29 May 2023 10:37:23 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 29 May 2023 10:37:23 +0200
branch
newapi
changeset 181
c52d88ea020b
parent 180
f34953bf4ac7
child 182
6cf690e042bd

redefine UIWIDGET, remove widget abstraction class (WinUI)

ui/ui/toolkit.h file | annotate | diff | comparison | revisions
ui/winui/toolkit.cpp file | annotate | diff | comparison | revisions
ui/winui/toolkit.h file | annotate | diff | comparison | revisions
ui/winui/window.cpp file | annotate | diff | comparison | revisions
--- a/ui/ui/toolkit.h	Tue May 23 14:19:06 2023 +0200
+++ b/ui/ui/toolkit.h	Mon May 29 10:37:23 2023 +0200
@@ -68,10 +68,27 @@
 #endif
 
 #elif UI_WINUI
+
+#ifdef __cplusplus
+#include <Windows.h>
+#undef GetCurrentTime
+#include <winrt/Windows.Foundation.Collections.h>
+#include <winrt/Windows.UI.Xaml.Interop.h>
+#include <winrt/Microsoft.UI.Xaml.Controls.h>
+
+#define UIWIDGET winrt::Microsoft::UI::Xaml::UIElement
+#define UIWINDOW winrt::Microsoft::UI::Xaml::Window
+#define UIMENU   void*
+
+#else
 #define UIWIDGET void*
+#define UIWINDOW void*
 #define UIMENU   void*
 #endif
 
+
+#endif
+
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -137,6 +154,13 @@
      * native widget
      */
     UIWIDGET    widget;
+
+#ifdef UI_WINUI
+    /*
+     * native window object 
+     */
+    UIWINDOW    wobj;
+#endif
     
     /*
      * user window data
--- a/ui/winui/toolkit.cpp	Tue May 23 14:19:06 2023 +0200
+++ b/ui/winui/toolkit.cpp	Mon May 29 10:37:23 2023 +0200
@@ -97,14 +97,6 @@
 	return application_name;
 }
 
-UiContext* ui_global_context(void) {
-	return NULL;
-}
-
-void ui_context_closefunc(UiContext* ctx, ui_callback fnc, void* udata) {
-
-}
-
 void ui_onstartup(ui_callback f, void* userdata) {
 	startup_func = f;
 	startup_data = userdata;
@@ -126,8 +118,11 @@
 }
 
 void ui_show(UiObject* obj) {
-	UiWidget* w = (UiWidget*)obj->widget;
-	w->show();
+	if (obj->wobj) {
+		obj->wobj.Activate();
+	} else {
+		// ZODO
+	}
 }
 
 void ui_close(UiObject* obj) {
--- a/ui/winui/toolkit.h	Tue May 23 14:19:06 2023 +0200
+++ b/ui/winui/toolkit.h	Mon May 29 10:37:23 2023 +0200
@@ -31,8 +31,3 @@
 #define UIEXPORT extern "C" __declspec(dllexport) 
 #include "../ui/toolkit.h"
 
-
-class UiWidget {
-public:
-	virtual void show() {};
-};
\ No newline at end of file
--- a/ui/winui/window.cpp	Tue May 23 14:19:06 2023 +0200
+++ b/ui/winui/window.cpp	Mon May 29 10:37:23 2023 +0200
@@ -39,8 +39,12 @@
 
 #include "appmenu.h"
 
+#include "../common/context.h"
+
 #include <stdlib.h>
 
+#include <cx/basic_mempool.h>
+
 using namespace winrt;
 using namespace Microsoft::UI::Xaml;
 using namespace Microsoft::UI::Xaml::Controls;
@@ -49,34 +53,26 @@
 using namespace Windows::UI::Xaml::Interop;
 
 
-class UiWindow : UiWidget {
-public:
-	UiWindow(const char* title, UiObject *obj) {
-		window = Window();
+
+
+UiObject* ui_window(const char* title, void* window_data) {
+	CxMempool* mp = cxBasicMempoolCreate(256);
+	UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject));
+
+	obj->ctx = uic_context(obj, mp->allocator);
+	obj->window = window_data;
 
-		grid = Grid();
-		window.Content(grid);
+	obj->wobj = Window();
+	Grid grid = Grid();
+	obj->wobj.Content(grid);
 
-		if (uic_get_menu_list()) {
-			MenuBar mb = ui_create_menubar(obj);
-			mb.VerticalAlignment(VerticalAlignment::Top);
-			grid.Children().Append(mb);
-		}
+	if (uic_get_menu_list()) {
+		MenuBar mb = ui_create_menubar(obj);
+		mb.VerticalAlignment(VerticalAlignment::Top);
+		grid.Children().Append(mb);
 	}
 
-	virtual void show() {
-		window.Activate();
-	}
-
-	Window window{ nullptr };
-	Grid grid;
-};
-
-UiObject* ui_window(const char* title, void* window_data) {
-	UiObject* obj = (UiObject*)malloc(sizeof(UiObject));
-
-	UiWindow* window = new UiWindow(title, obj);
-	obj->widget = window;
+	obj->window = window_data;
 
 	return obj;
 }

mercurial