ui/winui/window.cpp

branch
newapi
changeset 184
8c9b4b28aaa9
parent 183
3ce2eb11913b
child 187
24ce2c326d85
equal deleted inserted replaced
183:3ce2eb11913b 184:8c9b4b28aaa9
37 #include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h> 37 #include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
38 #include <winrt/Microsoft.UI.Xaml.Markup.h> 38 #include <winrt/Microsoft.UI.Xaml.Markup.h>
39 39
40 #include "appmenu.h" 40 #include "appmenu.h"
41 #include "container.h" 41 #include "container.h"
42 #include "util.h"
42 43
43 #include "../common/context.h" 44 #include "../common/context.h"
44 45
45 #include <stdlib.h> 46 #include <stdlib.h>
46 47
52 using namespace Microsoft::UI::Xaml::XamlTypeInfo; 53 using namespace Microsoft::UI::Xaml::XamlTypeInfo;
53 using namespace Microsoft::UI::Xaml::Markup; 54 using namespace Microsoft::UI::Xaml::Markup;
54 using namespace Windows::UI::Xaml::Interop; 55 using namespace Windows::UI::Xaml::Interop;
55 using namespace winrt::Windows::Foundation; 56 using namespace winrt::Windows::Foundation;
56 57
58 UiWindow::UiWindow(winrt::Microsoft::UI::Xaml::Window& win) : window(win) {}
59
60
57 UiObject* ui_window(const char* title, void* window_data) { 61 UiObject* ui_window(const char* title, void* window_data) {
58 CxMempool* mp = cxBasicMempoolCreate(256); 62 CxMempool* mp = cxBasicMempoolCreate(256);
59 UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject)); 63 UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject));
60 64
61 obj->ctx = uic_context(obj, mp->allocator); 65 obj->ctx = uic_context(obj, mp->allocator);
62 obj->window = window_data; 66 obj->window = window_data;
63 67
64 Window window = Window(); 68 Window window = Window();
69 if (title) {
70 wchar_t *wtitle = str2wstr(title, nullptr);
71 window.Title(wtitle);
72 free(wtitle);
73 }
65 74
66 Grid grid = Grid(); 75 Grid grid = Grid();
67 window.Content(grid); 76 window.Content(grid);
68 77
69 obj->wobj = new UiWindow(window); 78 obj->wobj = new UiWindow(window);
79
70 80
71 window.Closed([&](IInspectable const& sender, WindowEventArgs) { delete obj->wobj; } ); 81 window.Closed([obj](IInspectable const& sender, WindowEventArgs) {
82 // TODO: destroy UiObject*, context, ...
83 delete obj->wobj;
84 });
72 85
73 obj->container = new UiBoxContainer(grid, UI_CONTAINER_VBOX); 86 obj->container = new UiBoxContainer(grid, UI_CONTAINER_VBOX);
74 87
75 if (uic_get_menu_list()) { 88 if (uic_get_menu_list()) {
76 // create/add menubar 89 // create/add menubar
77 MenuBar mb = ui_create_menubar(obj); 90 MenuBar mb = ui_create_menubar(obj);
78 mb.VerticalAlignment(VerticalAlignment::Top); 91 mb.VerticalAlignment(VerticalAlignment::Top);
79 obj->container->Add(mb, false); 92 obj->container->Add(mb, false);
80 } 93 }
81 94
82 Button b1 = Button();
83 Button b2 = Button();
84
85 b1.Content(box_value(L"Button 1"));
86 b2.Content(box_value(L"Button 2"));
87
88 obj->container->Add(b1, false);
89 obj->container->Add(b2, false);
90
91
92 obj->window = window_data; 95 obj->window = window_data;
93
94 //wptr2->Activate();
95 //obj->wobj = wptr2;
96
97 96
98 return obj; 97 return obj;
99 } 98 }

mercurial