ui/winui/commandbar.cpp

Thu, 12 Oct 2023 13:51:44 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 12 Oct 2023 13:51:44 +0200
branch
newapi
changeset 210
83556205edad
parent 208
f632bc0589ab
child 213
7e39db525fd9
permissions
-rw-r--r--

change table colors (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"
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 using namespace winrt;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 using namespace Microsoft::UI::Xaml;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 using namespace Microsoft::UI::Xaml::Controls;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 using namespace Microsoft::UI::Xaml::XamlTypeInfo;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 using namespace Microsoft::UI::Xaml::Markup;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 using namespace Windows::UI::Xaml::Interop;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
47 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
48 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
49 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
50 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
51
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
52 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
53
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
54 CommandBar ui_create_toolbar(UiObject *obj) {
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
55
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
56 CommandBar cb = CommandBar();
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
57 cb.DefaultLabelPosition(CommandBarDefaultLabelPosition::Right);
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
58
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
59 // add pre-configured items
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 CxList* defaults = uic_get_toolbar_defaults();
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
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
71 UiToolbarMenuItem* appmenu = uic_get_appmenu();
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
72 if (appmenu) {
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
73 create_appmenu_items(obj, cb.SecondaryCommands(), appmenu);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
74 }
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
75
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
76
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 return cb;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 }
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
80 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
81 switch (i->type) {
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 case UI_TOOLBAR_ITEM: {
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
83 create_cmditem(obj, cb, (UiToolbarItem*)i);
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 break;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 case UI_TOOLBAR_TOGGLEITEM: {
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
87 create_toggleitem(obj, cb, (UiToolbarToggleItem*)i);
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 break;
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 }
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
90 case UI_TOOLBAR_MENU: {
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
91 create_menuitem(obj, cb, (UiToolbarMenuItem*)i);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
92 break;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
93 }
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 }
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
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
97 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
98 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
99 // convert UiMenuItemI to UiToolbarItemI
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
100 switch (mi->type) {
208
f632bc0589ab new menu api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
101 case UI_MENU: {
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
102 UiMenu* mitem = (UiMenu*)mi;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
103 UiToolbarMenuItem tbitem;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
104 memset(&tbitem, 0, sizeof(UiToolbarMenuItem));
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
105 tbitem.item.type = UI_TOOLBAR_MENU;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
106 tbitem.args.label = mitem->label;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
107 tbitem.menu.items_begin = mitem->items_begin;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
108 tbitem.menu.items_end = mitem->items_end;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
109 create_menuitem(obj, cb, &tbitem);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
110 break;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
111 }
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
112 case UI_MENU_ITEM: {
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
113 UiMenuItem* mitem = (UiMenuItem*)mi;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
114 UiToolbarItem tbitem;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
115 memset(&tbitem, 0, sizeof(UiToolbarItem));
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
116 tbitem.item.type = UI_TOOLBAR_ITEM;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
117 tbitem.args.label = mitem->label;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
118 tbitem.args.onclick = mitem->callback;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
119 tbitem.args.onclickdata = mitem->userdata;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
120 create_cmditem(obj, cb, &tbitem);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
121 break;
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
122 }
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 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
128 AppBarButton button = AppBarButton();
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 if (item->args.label) {
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 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
131 button.Label(wlabel);
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 free(wlabel);
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
135 // register callback
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
136 if (item->args.onclick) {
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
137 ui_callback cbfunc = item->args.onclick;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
138 void* cbdata = item->args.onclickdata;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
139 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
140 UiEvent evt;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
141 evt.obj = obj;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
142 evt.window = obj->window;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
143 evt.document = obj->ctx->document;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
144 evt.eventdata = nullptr;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
145 evt.intval = 0;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
146 cbfunc(&evt, cbdata);
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
147 });
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
148 }
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
149
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
150 cb.Append(button);
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 }
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
153 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
154 AppBarToggleButton button = AppBarToggleButton();
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
155 if (item->args.label) {
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
156 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
157 button.Label(wlabel);
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
158 free(wlabel);
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
159 }
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
160
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
161 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
162 if (var) {
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
163 UIElement elm = button;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
164 UiWidget* widget = new UiWidget(elm);
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
165 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
166
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
167 UiInteger* value = (UiInteger*)var->value;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
168 int64_t i = value->value;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
169 value->get = ui_toggle_button_get;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
170 value->set = ui_toggle_button_set;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
171 value->obj = widget;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
172 ui_toggle_button_set(value, i); // init togglebutton state
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
173
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
174 // listener for notifying observers
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
175 togglebutton_register_checked_observers(button, obj, var);
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
176 togglebutton_register_unchecked_observers(button, obj, var);
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
177 }
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
178
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
179 UiToggleArgs args = {};
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
180 args.onchange = item->args.onchange;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
181 args.onchangedata = item->args.onchangedata;
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
182 togglebutton_register_callback(button, obj, args);
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
183
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
184
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
185 cb.Append(button);
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 }
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
187
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
188 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
189 AppBarButton button = AppBarButton();
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
190 if (item->args.label) {
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
191 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
192 button.Label(wlabel);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
193 free(wlabel);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
194 }
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
195
207
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
196 MenuFlyoutItem mi = MenuFlyoutItem();
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
197
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
198 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
199 button.Flyout(flyout);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
200
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
201 cb.Append(button);
93b9f502cb88 add toolbar appmenu and menu buttons
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 206
diff changeset
202 }

mercurial