ui/winui/toolkit.cpp

branch
newapi
changeset 177
e79a60b3a7cb
parent 173
809581724cc7
child 179
34f4d78647be
equal deleted inserted replaced
173:809581724cc7 177:e79a60b3a7cb
1 #include "../ui/toolkit.h" 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
2 28
3 int testfunc() { 29 #include "toolkit.h"
4 return 123; 30
31 #include <Windows.h>
32 #undef GetCurrentTime
33 #include <winrt/Windows.Foundation.Collections.h>
34 #include <winrt/Windows.UI.Xaml.Interop.h>
35 #include <winrt/Microsoft.UI.Xaml.Controls.h>
36 #include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
37 #include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
38 #include <winrt/Microsoft.UI.Xaml.Markup.h>
39
40
41 using namespace winrt;
42 using namespace Microsoft::UI::Xaml;
43 using namespace Microsoft::UI::Xaml::Controls;
44 using namespace Microsoft::UI::Xaml::XamlTypeInfo;
45 using namespace Microsoft::UI::Xaml::Markup;
46 using namespace Windows::UI::Xaml::Interop;
47
48 static const char* application_name;
49
50 static ui_callback startup_func;
51 static void* startup_data;
52
53 static ui_callback open_func;
54 void* open_data;
55
56 static ui_callback exit_func;
57 void* exit_data;
58
59 static ui_callback appclose_fnc;
60
61 static void* appclose_udata;
62
63
64 static UiObject* active_window;
65
66
67 class App : public ApplicationT<App, IXamlMetadataProvider> {
68 public:
69 void OnLaunched(LaunchActivatedEventArgs const&) {
70 Resources().MergedDictionaries().Append(XamlControlsResources());
71 if (startup_func) {
72 startup_func(NULL, startup_data);
73 }
74 }
75 IXamlType GetXamlType(TypeName const& type) {
76 return provider.GetXamlType(type);
77 }
78 IXamlType GetXamlType(hstring const& fullname) {
79 return provider.GetXamlType(fullname);
80 }
81 com_array<XmlnsDefinition> GetXmlnsDefinitions() {
82 return provider.GetXmlnsDefinitions();
83 }
84 private:
85 XamlControlsXamlMetaDataProvider provider;
86 };
87
88
89
90 void ui_init(const char* appname, int argc, char** argv) {
91 application_name = appname;
5 } 92 }
93
94 const char* ui_appname() {
95 return application_name;
96 }
97
98 UiContext* ui_global_context(void) {
99 return NULL;
100 }
101
102 void ui_context_closefunc(UiContext* ctx, ui_callback fnc, void* udata) {
103
104 }
105
106 void ui_onstartup(ui_callback f, void* userdata) {
107 startup_func = f;
108 startup_data = userdata;
109 }
110
111 void ui_onopen(ui_callback f, void* userdata) {
112 open_func = f;
113 open_data = userdata;
114 }
115
116 void ui_onexit(ui_callback f, void* userdata) {
117 exit_func = f;
118 exit_data = userdata;
119 }
120
121 void ui_main() {
122 init_apartment();
123 Application::Start([](auto&&) {make<App>(); });
124 }
125
126 void ui_show(UiObject* obj) {
127 UiWidget* w = (UiWidget*)obj->widget;
128 w->show();
129 }
130
131 void ui_close(UiObject* obj) {
132
133 }
134

mercurial