Fri, 26 Jan 2024 17:17:14 +0100
add menu item list (WinUI3)
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2023 Olaf Wintermann. All rights reserved. |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
b1ac0dd1d38b
new winui vs project, add toolbar
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 |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "pch.h" |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include "commandbar.h" |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "util.h" |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
34 | #include "../common/object.h" |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
35 | #include "../common/context.h" |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
36 | |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
37 | #include "button.h" |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
38 | #include "appmenu.h" |
213
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
39 | #include "icons.h" |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | using namespace winrt; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | using namespace Microsoft::UI::Xaml; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | using namespace Microsoft::UI::Xaml::Controls; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | using namespace Microsoft::UI::Xaml::XamlTypeInfo; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | using namespace Microsoft::UI::Xaml::Markup; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | using namespace Windows::UI::Xaml::Interop; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
48 | static void create_item(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarItemI* i); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
49 | static void create_cmditem(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarItem* item); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
50 | static void create_toggleitem(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarToggleItem* item); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
51 | static void create_menuitem(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarMenuItem* item); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
52 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
53 | static void create_appmenu_items(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarMenuItem* i); |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
226
4eef1d49f794
split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
55 | CommandBar ui_create_toolbar(UiObject *obj, CxList* defaults, bool addappmenu) { |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
56 | |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
57 | CommandBar cb = CommandBar(); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
58 | cb.DefaultLabelPosition(CommandBarDefaultLabelPosition::Right); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
59 | |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
60 | // add pre-configured items |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | CxIterator i = cxListIterator(defaults); |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | cx_foreach(char*, def, i) { |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | UiToolbarItemI* item = uic_toolbar_get_item(def); |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | if (!item) { |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
65 | exit(-1); // TODO: maybe an error dialog? |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | } |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
67 | create_item(obj, cb.PrimaryCommands(), item); |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
69 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
70 | // add appmenu |
226
4eef1d49f794
split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
71 | if (addappmenu) { |
4eef1d49f794
split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
72 | UiToolbarMenuItem* appmenu = uic_get_appmenu(); |
4eef1d49f794
split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
73 | if (appmenu) { |
4eef1d49f794
split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
74 | create_appmenu_items(obj, cb.SecondaryCommands(), appmenu); |
4eef1d49f794
split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
75 | } |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
76 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
77 | |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | return cb; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | } |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
81 | static void create_item(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarItemI* i) { |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | switch (i->type) { |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | case UI_TOOLBAR_ITEM: { |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
84 | create_cmditem(obj, cb, (UiToolbarItem*)i); |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | break; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | case UI_TOOLBAR_TOGGLEITEM: { |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
88 | create_toggleitem(obj, cb, (UiToolbarToggleItem*)i); |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | break; |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | } |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
91 | case UI_TOOLBAR_MENU: { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
92 | create_menuitem(obj, cb, (UiToolbarMenuItem*)i); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
93 | break; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
94 | } |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | } |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
98 | static void create_appmenu_items(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarMenuItem* i) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
99 | for (UiMenuItemI* mi = i->menu.items_begin; mi; mi = mi->next) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
100 | // convert UiMenuItemI to UiToolbarItemI |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
101 | switch (mi->type) { |
208 | 102 | case UI_MENU: { |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
103 | UiMenu* mitem = (UiMenu*)mi; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
104 | UiToolbarMenuItem tbitem; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
105 | memset(&tbitem, 0, sizeof(UiToolbarMenuItem)); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
106 | tbitem.item.type = UI_TOOLBAR_MENU; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
107 | tbitem.args.label = mitem->label; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
108 | tbitem.menu.items_begin = mitem->items_begin; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
109 | tbitem.menu.items_end = mitem->items_end; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
110 | create_menuitem(obj, cb, &tbitem); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
111 | break; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
112 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
113 | case UI_MENU_ITEM: { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
114 | UiMenuItem* mitem = (UiMenuItem*)mi; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
115 | UiToolbarItem tbitem; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
116 | memset(&tbitem, 0, sizeof(UiToolbarItem)); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
117 | tbitem.item.type = UI_TOOLBAR_ITEM; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
118 | tbitem.args.label = mitem->label; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
119 | tbitem.args.onclick = mitem->callback; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
120 | tbitem.args.onclickdata = mitem->userdata; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
121 | create_cmditem(obj, cb, &tbitem); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
122 | break; |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
123 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
124 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
125 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
126 | } |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
127 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
128 | static void create_cmditem(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarItem* item) { |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | AppBarButton button = AppBarButton(); |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | if (item->args.label) { |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | wchar_t* wlabel = str2wstr(item->args.label, nullptr); |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
132 | button.Label(wlabel); |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | free(wlabel); |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | } |
213
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
135 | if(item->args.icon) { |
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
136 | button.Icon(ui_get_icon(item->args.icon)); |
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
137 | } |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
139 | // register callback |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
140 | if (item->args.onclick) { |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
141 | ui_callback cbfunc = item->args.onclick; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
142 | void* cbdata = item->args.onclickdata; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
143 | button.Click([cbfunc, cbdata, obj](Windows::Foundation::IInspectable const& sender, RoutedEventArgs) { |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
144 | UiEvent evt; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
145 | evt.obj = obj; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
146 | evt.window = obj->window; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
147 | evt.document = obj->ctx->document; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
148 | evt.eventdata = nullptr; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
149 | evt.intval = 0; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
150 | cbfunc(&evt, cbdata); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
151 | }); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
152 | } |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
153 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
154 | cb.Append(button); |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | } |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
157 | static void create_toggleitem(UiObject *obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarToggleItem* item) { |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
158 | AppBarToggleButton button = AppBarToggleButton(); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
159 | if (item->args.label) { |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
160 | wchar_t* wlabel = str2wstr(item->args.label, nullptr); |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
161 | button.Label(wlabel); |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
162 | free(wlabel); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
163 | } |
213
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
164 | if (item->args.icon) { |
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
165 | button.Icon(ui_get_icon(item->args.icon)); |
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
166 | } |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
167 | |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
168 | UiVar* var = uic_widget_var(obj->ctx, obj->ctx, nullptr, item->args.varname, UI_VAR_INTEGER); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
169 | if (var) { |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
170 | UIElement elm = button; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
171 | UiWidget* widget = new UiWidget(elm); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
172 | ui_context_add_widget_destructor(obj->ctx, widget); |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
174 | UiInteger* value = (UiInteger*)var->value; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
175 | int64_t i = value->value; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
176 | value->get = ui_toggle_button_get; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
177 | value->set = ui_toggle_button_set; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
178 | value->obj = widget; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
179 | ui_toggle_button_set(value, i); // init togglebutton state |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
180 | |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
181 | // listener for notifying observers |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
182 | togglebutton_register_checked_observers(button, obj, var); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
183 | togglebutton_register_unchecked_observers(button, obj, var); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
184 | } |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
185 | |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
186 | UiToggleArgs args = {}; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
187 | args.onchange = item->args.onchange; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
188 | args.onchangedata = item->args.onchangedata; |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
189 | togglebutton_register_callback(button, obj, args); |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
190 | |
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
191 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
192 | cb.Append(button); |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | } |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
194 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
195 | static void create_menuitem(UiObject* obj, Windows::Foundation::Collections::IObservableVector<ICommandBarElement> cb, UiToolbarMenuItem* item) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
196 | AppBarButton button = AppBarButton(); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
197 | if (item->args.label) { |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
198 | wchar_t* wlabel = str2wstr(item->args.label, nullptr); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
199 | button.Label(wlabel); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
200 | free(wlabel); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
201 | } |
213
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
202 | if (item->args.icon) { |
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
203 | button.Icon(ui_get_icon(item->args.icon)); |
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
208
diff
changeset
|
204 | } |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
205 | |
207
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
206 | MenuFlyoutItem mi = MenuFlyoutItem(); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
207 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
208 | MenuFlyout flyout = ui_create_menu_flyout(obj, &item->menu); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
209 | button.Flyout(flyout); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
210 | |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
211 | cb.Append(button); |
93b9f502cb88
add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
212 | } |