create WinUI wrapper classes for usage in UiObject and widget creation functions newapi

Fri, 22 Sep 2023 21:32:45 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 22 Sep 2023 21:32:45 +0200
branch
newapi
changeset 183
3ce2eb11913b
parent 182
6cf690e042bd
child 184
8c9b4b28aaa9

create WinUI wrapper classes for usage in UiObject and widget creation functions

ui/ui/toolkit.h file | annotate | diff | comparison | revisions
ui/winui/toolkit.cpp file | annotate | diff | comparison | revisions
ui/winui/window.cpp file | annotate | diff | comparison | revisions
ui/winui/winui.vcxproj file | annotate | diff | comparison | revisions
--- a/ui/ui/toolkit.h	Mon May 29 12:48:42 2023 +0200
+++ b/ui/ui/toolkit.h	Fri Sep 22 21:32:45 2023 +0200
@@ -70,16 +70,39 @@
 #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
+class UiWindow {
+public:
+    winrt::Microsoft::UI::Xaml::Window window { nullptr };
+
+    UiWindow(winrt::Microsoft::UI::Xaml::Window& win);
+};
+
+class UiWidget {
+public:
+    winrt::Microsoft::UI::Xaml::UIElement uielement;
+
+    UiWidget(winrt::Microsoft::UI::Xaml::UIElement& elm);
+};
+
+#define UIWIDGET UiWidget*
+#define UIWINDOW UiWindow*
 #define UIMENU   void*
 
+/*
+// winrt::Microsoft::UI::Xaml::UIElement
+#define UIWIDGET void*
+// winrt::Microsoft::UI::Xaml::Window
+#define UIWINDOW void*
+#define UIMENU   void*
+*/
+
 #else
 #define UIWIDGET void*
 #define UIWINDOW void*
--- a/ui/winui/toolkit.cpp	Mon May 29 12:48:42 2023 +0200
+++ b/ui/winui/toolkit.cpp	Fri Sep 22 21:32:45 2023 +0200
@@ -87,6 +87,11 @@
 	XamlControlsXamlMetaDataProvider provider;
 };
 
+UiWindow::UiWindow(winrt::Microsoft::UI::Xaml::Window& win) : window(win) {};
+
+UiWidget::UiWidget(winrt::Microsoft::UI::Xaml::UIElement& elm) : uielement(elm) {}
+
+
 
 
 void ui_init(const char* appname, int argc, char** argv) {
@@ -117,11 +122,16 @@
 	Application::Start([](auto&&) {make<App>(); });
 }
 
+class UiWin {
+public:
+	Window window;
+};
+
 void ui_show(UiObject* obj) {
 	if (obj->wobj) {
-		obj->wobj.Activate();
+		obj->wobj->window.Activate();
 	} else {
-		// ZODO
+		// TODO
 	}
 }
 
--- a/ui/winui/window.cpp	Mon May 29 12:48:42 2023 +0200
+++ b/ui/winui/window.cpp	Fri Sep 22 21:32:45 2023 +0200
@@ -52,9 +52,7 @@
 using namespace Microsoft::UI::Xaml::XamlTypeInfo;
 using namespace Microsoft::UI::Xaml::Markup;
 using namespace Windows::UI::Xaml::Interop;
-
-
-
+using namespace winrt::Windows::Foundation;
 
 UiObject* ui_window(const char* title, void* window_data) {
 	CxMempool* mp = cxBasicMempoolCreate(256);
@@ -63,9 +61,14 @@
 	obj->ctx = uic_context(obj, mp->allocator);
 	obj->window = window_data;
 
-	obj->wobj = Window();
+	Window window = Window();
+
 	Grid grid = Grid();
-	obj->wobj.Content(grid);
+	window.Content(grid);
+
+	obj->wobj = new UiWindow(window);
+
+	window.Closed([&](IInspectable const& sender, WindowEventArgs) { delete obj->wobj; } );
 
 	obj->container = new UiBoxContainer(grid, UI_CONTAINER_VBOX);
 
@@ -87,6 +90,9 @@
 
 
 	obj->window = window_data;
+
+	//wptr2->Activate();
+	//obj->wobj = wptr2;
 	
 
 	return obj;
--- a/ui/winui/winui.vcxproj	Mon May 29 12:48:42 2023 +0200
+++ b/ui/winui/winui.vcxproj	Fri Sep 22 21:32:45 2023 +0200
@@ -119,6 +119,7 @@
       <AdditionalOptions>
       </AdditionalOptions>
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
+      <PrecompiledHeaderFile>toolkit.h</PrecompiledHeaderFile>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>

mercurial