# HG changeset patch # User Olaf Wintermann # Date 1681633221 -7200 # Node ID e79a60b3a7cb5dc9517984244202bc811028eca9 # Parent 809581724cc71dfa31b66766761e04a10b0afffe minimal working winui app diff -r 809581724cc7 -r e79a60b3a7cb make/vs/testapp/main.c --- a/make/vs/testapp/main.c Sat Apr 15 21:06:45 2023 +0200 +++ b/make/vs/testapp/main.c Sun Apr 16 10:20:21 2023 +0200 @@ -1,6 +1,53 @@ -#include +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ -int main(int argc, char** argv) { - printf("hello world!\n"); - return 0; +#include + +#include +#include + +#include + + + +void application_startup(UiEvent* event, void* data) { + UiObject* obj = ui_window("Test", NULL); + + ui_show(obj); } + + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) +{ + ui_init("app1", 0, NULL); + ui_onstartup(application_startup, NULL); + + ui_main(); + + return (EXIT_SUCCESS); +} diff -r 809581724cc7 -r e79a60b3a7cb make/vs/testapp/testapp.vcxproj --- a/make/vs/testapp/testapp.vcxproj Sat Apr 15 21:06:45 2023 +0200 +++ b/make/vs/testapp/testapp.vcxproj Sun Apr 16 10:20:21 2023 +0200 @@ -27,6 +27,9 @@ {3541f08b-e6cc-4c23-a0d3-51983aab33c6} testapp 10.0 + true + None + false @@ -111,9 +114,10 @@ true _DEBUG;_CONSOLE;UI_WINUI;%(PreprocessorDefinitions) true + C:\Users\Olaf\Projekte\toolkit\ui;%(AdditionalIncludeDirectories) - Console + Windows true @@ -139,6 +143,11 @@ + + + {04d5ee2c-6076-4c7c-8b70-b0f6d602ff55} + + diff -r 809581724cc7 -r e79a60b3a7cb ui/ui/toolkit.h --- a/ui/ui/toolkit.h Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/ui/toolkit.h Sun Apr 16 10:20:21 2023 +0200 @@ -79,6 +79,10 @@ #define FALSE 0 #endif +#ifndef UIEXPORT +#define UIEXPORT +#endif + #ifdef __cplusplus extern "C" { #endif @@ -284,8 +288,8 @@ }; -void ui_init(char *appname, int argc, char **argv); -char* ui_appname(); +void ui_init(const char *appname, int argc, char **argv); +const char* ui_appname(); UiContext* ui_global_context(void); diff -r 809581724cc7 -r e79a60b3a7cb ui/ui/window.h --- a/ui/ui/window.h Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/ui/window.h Sun Apr 16 10:20:21 2023 +0200 @@ -35,7 +35,7 @@ extern "C" { #endif -UiObject* ui_window(char *title, void *window_data); +UiObject* ui_window(const char *title, void *window_data); UiObject* ui_simplewindow(char *title, void *window_data); char* ui_openfiledialog(UiObject *obj); diff -r 809581724cc7 -r e79a60b3a7cb ui/winui/toolkit.cpp --- a/ui/winui/toolkit.cpp Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/winui/toolkit.cpp Sun Apr 16 10:20:21 2023 +0200 @@ -1,5 +1,134 @@ -#include "../ui/toolkit.h" +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "toolkit.h" + +#include +#undef GetCurrentTime +#include +#include +#include +#include +#include +#include + + +using namespace winrt; +using namespace Microsoft::UI::Xaml; +using namespace Microsoft::UI::Xaml::Controls; +using namespace Microsoft::UI::Xaml::XamlTypeInfo; +using namespace Microsoft::UI::Xaml::Markup; +using namespace Windows::UI::Xaml::Interop; + +static const char* application_name; + +static ui_callback startup_func; +static void* startup_data; + +static ui_callback open_func; +void* open_data; + +static ui_callback exit_func; +void* exit_data; + +static ui_callback appclose_fnc; + +static void* appclose_udata; + + +static UiObject* active_window; + -int testfunc() { - return 123; +class App : public ApplicationT { +public: + void OnLaunched(LaunchActivatedEventArgs const&) { + Resources().MergedDictionaries().Append(XamlControlsResources()); + if (startup_func) { + startup_func(NULL, startup_data); + } + } + IXamlType GetXamlType(TypeName const& type) { + return provider.GetXamlType(type); + } + IXamlType GetXamlType(hstring const& fullname) { + return provider.GetXamlType(fullname); + } + com_array GetXmlnsDefinitions() { + return provider.GetXmlnsDefinitions(); + } +private: + XamlControlsXamlMetaDataProvider provider; +}; + + + +void ui_init(const char* appname, int argc, char** argv) { + application_name = appname; +} + +const char* ui_appname() { + 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; +} + +void ui_onopen(ui_callback f, void* userdata) { + open_func = f; + open_data = userdata; +} + +void ui_onexit(ui_callback f, void* userdata) { + exit_func = f; + exit_data = userdata; +} + +void ui_main() { + init_apartment(); + Application::Start([](auto&&) {make(); }); +} + +void ui_show(UiObject* obj) { + UiWidget* w = (UiWidget*)obj->widget; + w->show(); +} + +void ui_close(UiObject* obj) { + +} + diff -r 809581724cc7 -r e79a60b3a7cb ui/winui/toolkit.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/toolkit.h Sun Apr 16 10:20:21 2023 +0200 @@ -0,0 +1,38 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#define UIEXPORT extern "C" __declspec(dllexport) +#include "../ui/toolkit.h" + + +class UiWidget { +public: + virtual void show() {}; +}; \ No newline at end of file diff -r 809581724cc7 -r e79a60b3a7cb ui/winui/window.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/window.cpp Sun Apr 16 10:20:21 2023 +0200 @@ -0,0 +1,70 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "window.h" + +#include +#undef GetCurrentTime +#include +#include +#include +#include +#include +#include + +#include + +using namespace winrt; +using namespace Microsoft::UI::Xaml; +using namespace Microsoft::UI::Xaml::Controls; +using namespace Microsoft::UI::Xaml::XamlTypeInfo; +using namespace Microsoft::UI::Xaml::Markup; +using namespace Windows::UI::Xaml::Interop; + + +class UiWindow : UiWidget { +public: + UiWindow(const char* title) { + window = Window(); + } + + virtual void show() { + window.Activate(); + } + + Window window{ nullptr }; +}; + +UiObject* ui_window(const char* title, void* window_data) { + UiObject* obj = (UiObject*)malloc(sizeof(UiObject)); + + UiWindow* window = new UiWindow(title); + obj->widget = window; + + return obj; +} diff -r 809581724cc7 -r e79a60b3a7cb ui/winui/window.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/window.h Sun Apr 16 10:20:21 2023 +0200 @@ -0,0 +1,44 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "toolkit.h" + +#include "../ui/window.h" + +#include +#undef GetCurrentTime +#include +#include +#include +#include +#include +#include + + diff -r 809581724cc7 -r e79a60b3a7cb ui/winui/winui.vcxproj --- a/ui/winui/winui.vcxproj Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/winui/winui.vcxproj Sun Apr 16 10:20:21 2023 +0200 @@ -27,6 +27,9 @@ {04d5ee2c-6076-4c7c-8b70-b0f6d602ff55} winui 10.0 + true + None + false @@ -136,10 +139,15 @@ + + + + + diff -r 809581724cc7 -r e79a60b3a7cb ui/winui/winui.vcxproj.filters --- a/ui/winui/winui.vcxproj.filters Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/winui/winui.vcxproj.filters Sun Apr 16 10:20:21 2023 +0200 @@ -18,8 +18,19 @@ Quelldateien + + Quelldateien + + + + Headerdateien + + + Headerdateien + + \ No newline at end of file