|
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 */ |
|
28 |
|
29 #include "appmenu.h" |
|
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 #include <cx/linked_list.h> |
|
41 #include <cx/array_list.h> |
|
42 |
|
43 #include "util.h" |
|
44 |
|
45 |
|
46 using namespace winrt; |
|
47 using namespace Microsoft::UI::Xaml; |
|
48 using namespace Microsoft::UI::Xaml::Controls; |
|
49 using namespace Microsoft::UI::Xaml::XamlTypeInfo; |
|
50 using namespace Microsoft::UI::Xaml::Markup; |
|
51 using namespace Windows::UI::Xaml::Interop; |
|
52 |
|
53 static void add_top_menu_widget(MenuBar &parent, int i, UiMenuItemI* item, UiObject* obj); |
|
54 |
|
55 static void add_menu_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj); |
|
56 static void add_menuitem_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj); |
|
57 static void add_menuitem_st_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj); |
|
58 static void add_menuseparator_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj); |
|
59 static void add_checkitem_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj); |
|
60 static void add_checkitemnv_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj); |
|
61 static void add_menuitem_list_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj); |
|
62 |
|
63 static ui_menu_add_f createMenuItem[] = { |
|
64 /* UI_MENU */ add_menu_widget, |
|
65 /* UI_MENU_SUBMENU */ add_menu_widget, |
|
66 /* UI_MENU_ITEM */ add_menuitem_widget, |
|
67 /* UI_MENU_STOCK_ITEM */ add_menuitem_st_widget, |
|
68 /* UI_MENU_CHECK_ITEM */ add_checkitem_widget, |
|
69 /* UI_MENU_CHECK_ITEM_NV */ add_checkitemnv_widget, |
|
70 /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget, |
|
71 /* UI_MENU_ITEM_LIST_NV */ NULL, // TODO |
|
72 /* UI_MENU_SEPARATOR */ add_menuseparator_widget |
|
73 }; |
|
74 |
|
75 winrt::Microsoft::UI::Xaml::Controls::MenuBar ui_create_menubar(UiObject* obj) { |
|
76 MenuBar mb = MenuBar(); |
|
77 |
|
78 UiMenu* menus_begin = uic_get_menu_list(); |
|
79 |
|
80 UiMenu* ls = menus_begin; |
|
81 while (ls) { |
|
82 UiMenu* menu = ls; |
|
83 add_top_menu_widget(mb, 0, &menu->item, obj); |
|
84 |
|
85 ls = (UiMenu*)ls->item.next; |
|
86 } |
|
87 |
|
88 return mb; |
|
89 } |
|
90 |
|
91 static void add_top_menu_widget(MenuBar& parent, int i, UiMenuItemI* item, UiObject* obj) { |
|
92 UiMenu* menu = (UiMenu*)item; |
|
93 |
|
94 MenuBarItem mi = MenuBarItem(); |
|
95 wchar_t* wlabel = str2wstr(menu->label, NULL); |
|
96 mi.Title(wlabel); |
|
97 free(wlabel); |
|
98 |
|
99 UiMenuItemI* it = menu->items_begin; |
|
100 int index = 0; |
|
101 while (it) { |
|
102 createMenuItem[it->type](mi.Items(), index, it, obj); |
|
103 |
|
104 it = it->next; |
|
105 index++; |
|
106 } |
|
107 |
|
108 parent.Items().Append(mi); |
|
109 } |
|
110 |
|
111 static void add_menu_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) { |
|
112 UiMenu* menu = (UiMenu*)item; |
|
113 |
|
114 MenuFlyoutSubItem mi = MenuFlyoutSubItem(); |
|
115 wchar_t* wlabel = str2wstr(menu->label, NULL); |
|
116 mi.Text(wlabel); |
|
117 free(wlabel); |
|
118 |
|
119 parent.Append(mi); |
|
120 |
|
121 UiMenuItemI* it = menu->items_begin; |
|
122 int index = 0; |
|
123 while (it) { |
|
124 createMenuItem[it->type](mi.Items(), index, it, obj); |
|
125 |
|
126 it = it->next; |
|
127 index++; |
|
128 } |
|
129 |
|
130 |
|
131 } |
|
132 |
|
133 static void add_menuitem_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) { |
|
134 UiMenuItem* it = (UiMenuItem*)item; |
|
135 |
|
136 MenuFlyoutItem mi = MenuFlyoutItem(); |
|
137 wchar_t* wlabel = str2wstr(it->label, NULL); |
|
138 mi.Text(wlabel); |
|
139 free(wlabel); |
|
140 |
|
141 parent.Append(mi); |
|
142 } |
|
143 |
|
144 static void add_menuitem_st_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) { |
|
145 |
|
146 } |
|
147 |
|
148 static void add_menuseparator_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) { |
|
149 |
|
150 } |
|
151 |
|
152 static void add_checkitem_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) { |
|
153 |
|
154 } |
|
155 |
|
156 static void add_checkitemnv_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) { |
|
157 |
|
158 } |
|
159 |
|
160 static void add_menuitem_list_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) { |
|
161 |
|
162 } |