ui/winui/appmenu.cpp

Sun, 28 Jan 2024 17:10:30 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 28 Jan 2024 17:10:30 +0100
branch
newapi
changeset 233
84665f0a9ab2
parent 229
a952760955b4
child 236
ee794586f51b
permissions
-rw-r--r--

add macro for creating the appmenu toolbar item

180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
29 #include "pch.h"
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
31 #include "appmenu.h"
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <cx/linked_list.h>
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <cx/array_list.h>
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
36 #include "../common/context.h"
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
37 #include "../common/object.h"
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
38
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "util.h"
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 using namespace winrt;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 using namespace Microsoft::UI::Xaml;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 using namespace Microsoft::UI::Xaml::Controls;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 using namespace Microsoft::UI::Xaml::XamlTypeInfo;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 using namespace Microsoft::UI::Xaml::Markup;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 using namespace Windows::UI::Xaml::Interop;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 static void add_top_menu_widget(MenuBar &parent, int i, UiMenuItemI* item, UiObject* obj);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 static void add_menu_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 static void add_menuitem_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 static void add_menuseparator_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 static void add_checkitem_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj);
208
f632bc0589ab new menu api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
55 static void add_radioitem_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj);
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 static void add_menuitem_list_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 static ui_menu_add_f createMenuItem[] = {
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 /* UI_MENU */ add_menu_widget,
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 /* UI_MENU_ITEM */ add_menuitem_widget,
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 /* UI_MENU_CHECK_ITEM */ add_checkitem_widget,
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
62 /* UI_MENU_RADIO_ITEM */ add_radioitem_widget,
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget,
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
64 /* UI_MENU_CHECKITEM_LIST */ add_menuitem_list_widget,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
65 /* UI_MENU_RADIOITEM_LIST */ add_menuitem_list_widget,
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 /* UI_MENU_SEPARATOR */ add_menuseparator_widget
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 };
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 winrt::Microsoft::UI::Xaml::Controls::MenuBar ui_create_menubar(UiObject* obj) {
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 MenuBar mb = MenuBar();
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 UiMenu* menus_begin = uic_get_menu_list();
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 UiMenu* ls = menus_begin;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 while (ls) {
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 UiMenu* menu = ls;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 add_top_menu_widget(mb, 0, &menu->item, obj);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 ls = (UiMenu*)ls->item.next;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 return mb;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 static void add_top_menu_widget(MenuBar& parent, int i, UiMenuItemI* item, UiObject* obj) {
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 UiMenu* menu = (UiMenu*)item;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 MenuBarItem mi = MenuBarItem();
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 wchar_t* wlabel = str2wstr(menu->label, NULL);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 mi.Title(wlabel);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 free(wlabel);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 UiMenuItemI* it = menu->items_begin;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 int index = 0;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 while (it) {
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 createMenuItem[it->type](mi.Items(), index, it, obj);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 it = it->next;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 index++;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 parent.Items().Append(mi);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 static void add_menu_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) {
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 UiMenu* menu = (UiMenu*)item;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 MenuFlyoutSubItem mi = MenuFlyoutSubItem();
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 wchar_t* wlabel = str2wstr(menu->label, NULL);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 mi.Text(wlabel);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 free(wlabel);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 parent.Append(mi);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 UiMenuItemI* it = menu->items_begin;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 int index = 0;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 while (it) {
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 createMenuItem[it->type](mi.Items(), index, it, obj);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 it = it->next;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 index++;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 static void add_menuitem_widget(winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent, int i, UiMenuItemI* item, UiObject* obj) {
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 UiMenuItem* it = (UiMenuItem*)item;
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 MenuFlyoutItem mi = MenuFlyoutItem();
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 wchar_t* wlabel = str2wstr(it->label, NULL);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 mi.Text(wlabel);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 free(wlabel);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 parent.Append(mi);
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
138 static void add_menuseparator_widget(
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
139 winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
140 int i,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
141 UiMenuItemI* item,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
142 UiObject* obj)
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
143 {
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
147 static void add_checkitem_widget(
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
148 winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
149 int i,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
150 UiMenuItemI* item,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
151 UiObject* obj)
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
152 {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
153
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
154 }
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
155
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
156 static void add_radioitem_widget(
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
157 winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
158 int i,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
159 UiMenuItemI* item,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
160 UiObject* obj)
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
161 {
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
165
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
166 class UiMenuList {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
167 public:
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
168 winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent = { nullptr };
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
169 UiMenuItemType type;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
170 int prevSize = 0;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
171 int insertPos = 0;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
172 UiVar* var = nullptr;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
173 ui_callback callback = nullptr;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
174 void* userdata = nullptr;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
175
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
176 UiMenuList() {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
177
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
178 }
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
179
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
180 void updateItems() {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
181 UiList* list = (UiList*)var->value;
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
183 // delete previous items
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
184 for (int i = 0; i < prevSize; i++) {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
185 parent.RemoveAt(insertPos);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
186 }
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
187
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
188 // insert new items
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
189 int count = 0;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
190 void* elm = list->first(list);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
191 while (elm) {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
192
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
193 MenuFlyoutItem mi = MenuFlyoutItem();
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
194 wchar_t* wlabel = str2wstr((char*)elm, NULL);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
195 mi.Text(wlabel);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
196 free(wlabel);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
197
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
198 parent.InsertAt(insertPos + count, mi);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
199
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
200 elm = list->next(list);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
201 count++;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
202 }
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
203
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
204 prevSize = count;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
205 }
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
206 };
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
207
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
208 extern "C" void destroy_ui_menu_list(void* ptr) {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
209 UiMenuList* ls = (UiMenuList*)ptr;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
210 delete ls;
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
213 static void ui_context_add_menu_list_destructor(UiContext* ctx, UiMenuList* list) {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
214 cxMempoolRegister(ctx->mp, list, destroy_ui_menu_list);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
215 }
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
217 static void ui_menulist_update(UiEvent* event, void* userdata) {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
218 UiMenuList* mlist = (UiMenuList*)userdata;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
219 mlist->updateItems();
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 }
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
222 static void add_menuitem_list_widget(
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
223 winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::UI::Xaml::Controls::MenuFlyoutItemBase> parent,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
224 int i,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
225 UiMenuItemI* item,
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
226 UiObject* obj)
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
227 {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
228 UiMenuItemList* it = (UiMenuItemList*)item;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
229 if (!it->varname) {
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
230 return;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
231 }
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
232
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
233 uint32_t size = parent.Size();
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
234
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
235 UiVar* var = uic_create_var(ui_global_context(), it->varname, UI_VAR_LIST);
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
237 UiMenuList* mlist = new UiMenuList();
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
238 mlist->parent = parent;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
239 mlist->callback = it->callback;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
240 mlist->userdata = it->userdata;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
241 mlist->prevSize = 0;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
242 mlist->insertPos = size;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
243 mlist->type = item->type;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
244 mlist->var = var;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
245 ui_context_add_menu_list_destructor(obj->ctx, mlist);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
246
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
247 UiList* list = (UiList*)var->value;
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
248 list->observers = ui_add_observer(list->observers, ui_menulist_update, mlist);
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
249
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
250 mlist->updateItems();
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 }
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
252
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
253
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
254
229
a952760955b4 add menu item list (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 208
diff changeset
255
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
256 winrt::Microsoft::UI::Xaml::Controls::MenuFlyout ui_create_menu_flyout(UiObject* obj, UiMenu* menudef) {
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
257 MenuFlyout flyout = MenuFlyout();
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
258
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
259 UiMenuItemI* it = menudef->items_begin;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
260 int index = 0;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
261 while (it) {
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
262 createMenuItem[it->type](flyout.Items(), index, it, obj);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
263
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
264 it = it->next;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
265 index++;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
266 }
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
267
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
268 return flyout;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
269 }

mercurial