ui/winui/list.cpp

Wed, 04 Dec 2024 20:36:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 04 Dec 2024 20:36:16 +0100
branch
newapi
changeset 407
8ea123dd89db
parent 382
de653b07050b
permissions
-rw-r--r--

semi functional grid container (Motif)

196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
320d85f3cd14 add listview (WinUI3)
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
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
320d85f3cd14 add listview (WinUI3)
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: 204
diff changeset
29 #include "pch.h"
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 204
diff changeset
30
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "list.h"
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "container.h"
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "util.h"
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/context.h"
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "../common/object.h"
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 using namespace winrt;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 using namespace Microsoft::UI::Xaml;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 using namespace Microsoft::UI::Xaml::Controls;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 using namespace Windows::UI::Xaml::Interop;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 using namespace winrt::Windows::Foundation;
221
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
44 using namespace Microsoft::UI::Xaml::Markup;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
45 using namespace Microsoft::UI::Xaml::Media;
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
48
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 UiObject* current = uic_current_obj(obj);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 // create listview and toolkit wrapper
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 ListView listview = ListView();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 if (args.multiselection) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 listview.SelectionMode(ListViewSelectionMode::Extended);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 bool clickEnabled = listview.IsItemClickEnabled();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 listview.IsItemClickEnabled(true);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 UIElement elm = listview;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 UiWidget* widget = new UiWidget(elm);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 widget->data1 = args.model;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 widget->data2 = args.getvalue;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 ui_context_add_widget_destructor(current->ctx, widget);
382
de653b07050b implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
67 ui_set_widget_groups(current->ctx, widget, args.groups);
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 // bind var
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 if (var) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 UiList* list = (UiList*)var->value;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 list->update = ui_simple_list_update;
378
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
74 list->getselection = ui_listview_getselection;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
75 list->setselection = ui_listview_setselection;
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 list->obj = widget;
378
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
77
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 ui_simple_list_update(list, 0);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 if (args.onselection) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 ui_callback onselection = args.onselection;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 void* cbdata = args.onselectiondata;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 listview.SelectionChanged([onselection, cbdata, obj](IInspectable const& sender, RoutedEventArgs evtargs) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 std::vector<int> selectedRows = ui_create_listview_selection(sender.as<ListView>());
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 UiListSelection selection;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 selection.rows = selectedRows.data();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 selection.count = selectedRows.size();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 UiEvent evt;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 evt.obj = obj;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 evt.window = obj->window;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 evt.document = obj->ctx->document;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 evt.eventdata = &selection;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 evt.intval = 0;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 onselection(&evt, cbdata);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 });
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 if (args.onactivate) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 ui_callback cb = args.onactivate;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 void* cbdata = args.onactivatedata;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 listview.ItemClick([cb, cbdata, obj](IInspectable const& sender, RoutedEventArgs evtargs) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 std::vector<int> selectedRows = ui_create_listview_selection(sender.as<ListView>());
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 UiListSelection selection;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 selection.rows = selectedRows.data();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 selection.count = selectedRows.size();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 UiEvent evt;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 evt.obj = obj;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 evt.window = obj->window;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 evt.document = obj->ctx->document;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 evt.eventdata = &selection;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 evt.intval = 0;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 cb(&evt, cbdata);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 });
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 // add listview to current container
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 UI_APPLY_LAYOUT1(current, args);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 current->container->Add(listview, false);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 return widget;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
197
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
127
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
128 UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs args) {
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
129 UiObject* current = uic_current_obj(obj);
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
130
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
131 // create listview and toolkit wrapper
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
132 ComboBox combobox = ComboBox();
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
133
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
134 UIElement elm = combobox;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
135 UiWidget* widget = new UiWidget(elm);
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
136 widget->data1 = args.model;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
137 widget->data2 = args.getvalue;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
138 ui_context_add_widget_destructor(current->ctx, widget);
382
de653b07050b implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
139 ui_set_widget_groups(current->ctx, widget, args.groups);
197
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
140
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
141 // bind var
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
142 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
143 if (var) {
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
144 UiList* list = (UiList*)var->value;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
145 list->update = ui_simple_list_update;
378
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
146 list->getselection = ui_dropdown_getselection;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
147 list->setselection = ui_dropdown_setselection;
197
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
148 list->obj = widget;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
149 ui_simple_list_update(list, 0);
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
150 }
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
151
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
152 if (args.onactivate) {
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
153 ui_callback cb = args.onactivate;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
154 void* cbdata = args.onactivatedata;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
155 combobox.SelectionChanged([cb, cbdata, obj](IInspectable const& sender, RoutedEventArgs evtargs) {
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
156 int selectedrow = sender.as<ComboBox>().SelectedIndex();
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
157 UiListSelection selection;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
158 selection.count = 1;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
159 selection.rows = &selectedrow;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
160
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
161 UiEvent evt;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
162 evt.obj = obj;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
163 evt.window = obj->window;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
164 evt.document = obj->ctx->document;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
165 evt.eventdata = &selection;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
166 evt.intval = selectedrow;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
167 cb(&evt, cbdata);
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
168 });
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
169 }
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
170
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
171 // add listview to current container
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
172 UI_APPLY_LAYOUT1(current, args);
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
173
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
174 current->container->Add(combobox, false);
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
175
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
176 return widget;
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
177 }
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
178
378
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
179 UiListSelection ui_listview_getselection(UiList *list) {
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
180 UiWidget *widget = (UiWidget*)list->obj;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
181 ListView listview = widget->uielement.as<ListView>();
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
182 std::vector<int> selectedRows = ui_create_listview_selection(listview);
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
183
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
184 UiListSelection selection = { NULL, 0 };
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
185 if (selectedRows.size() > 0) {
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
186 selection.count = selectedRows.size();
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
187 int *data = selectedRows.data();
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
188 selection.rows = (int*)calloc(selection.count, sizeof(int));
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
189 memcpy(selection.rows, data, selection.count);
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
190 }
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
191
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
192 return selection;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
193 }
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
194
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
195 void ui_listview_setselection(UiList *list, UiListSelection selection) {
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
196 UiWidget* widget = (UiWidget*)list->obj;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
197 if (selection.count > 0) {
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
198 ListView listview = widget->uielement.as<ListView>();
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
199 listview.SelectedIndex(selection.rows[0]);
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
200 }
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
201 }
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
202
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
203 UiListSelection ui_dropdown_getselection(UiList *list) {
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
204 UiWidget* widget = (UiWidget*)list->obj;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
205 ComboBox cb = widget->uielement.as<ComboBox>();
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
206 int index = cb.SelectedIndex();
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
207 UiListSelection selection = { NULL, 0 };
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
208 if (index >= 0) {
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
209 selection.rows = (int*)calloc(1, sizeof(int));
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
210 selection.count = 1;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
211 selection.rows[0] = index;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
212 }
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
213 return selection;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
214 }
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
215
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
216 void ui_dropdown_setselection(UiList *list, UiListSelection selection) {
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
217 UiWidget* widget = (UiWidget*)list->obj;
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
218 if (selection.count > 0) {
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
219 ComboBox cb = widget->uielement.as<ComboBox>();
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
220 cb.SelectedIndex(selection.rows[0]);
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
221 }
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
222 }
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
223
204
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
224 UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args) {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
225 UiObject* current = uic_current_obj(obj);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
226
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
227 // create listview and toolkit wrapper
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
228 BreadcrumbBar bcbar = BreadcrumbBar();
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
229
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
230 UIElement elm = bcbar;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
231 UiWidget* widget = new UiWidget(elm);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
232 widget->data1 = args.model;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
233 widget->data2 = args.getvalue;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
234 ui_context_add_widget_destructor(current->ctx, widget);
382
de653b07050b implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
235 ui_set_widget_groups(current->ctx, widget, args.groups);
204
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
236
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
237 // bind var
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
238 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
239 if (var) {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
240 UiList* list = (UiList*)var->value;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
241 list->update = ui_breadcrumbbar_update;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
242 list->obj = widget;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
243 ui_breadcrumbbar_update(list, 0);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
244 }
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
245
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
246 if (args.onactivate) {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
247 ui_callback cb = args.onactivate;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
248 void* cbdata = args.onactivatedata;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
249 bcbar.ItemClicked([cb, cbdata, obj](IInspectable const& sender, BreadcrumbBarItemClickedEventArgs evtargs) {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
250 UiEvent evt;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
251 evt.obj = obj;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
252 evt.window = obj->window;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
253 evt.document = obj->ctx->document;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
254 evt.eventdata = nullptr;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
255 evt.intval = evtargs.Index();
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
256 cb(&evt, cbdata);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
257 });
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
258 }
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
259
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
260 // add listview to current container
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
261 UI_APPLY_LAYOUT1(current, args);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
262
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
263 current->container->Add(bcbar, false);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
264
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
265 return widget;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
266 }
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
267
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 static void* getstrvalue(void* elm, int ignore) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 return elm;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 void ui_simple_list_update(UiList* list, int i) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 UiWidget* widget = (UiWidget*)list->obj;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 UiModel* model = (UiModel*)widget->data1;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 ui_getvaluefunc getvalue = (ui_getvaluefunc)widget->data2;
197
8a82ebe23822 add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 196
diff changeset
276 ItemsControl listview = widget->uielement.as<ItemsControl>();
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 auto items = listview.Items();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 // priority: getvalue, model.getvalue, getstrvalue (fallback)
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 if (getvalue == nullptr) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 if (model && model->getvalue) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 getvalue = model->getvalue;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 } else {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 getvalue = getstrvalue;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 // add list elements to listview.Items
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 items.Clear();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 void* elm = list->first(list);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 while (elm) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 char* value = (char*)getvalue(elm, 0);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 wchar_t* wstr = str2wstr(value, nullptr);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 items.Append(box_value(wstr));
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 free(wstr);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 elm = list->next(list);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300
204
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
301 extern "C" void ui_breadcrumbbar_update(UiList * list, int i) {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
302 UiWidget* widget = (UiWidget*)list->obj;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
303 UiModel* model = (UiModel*)widget->data1;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
304 ui_getvaluefunc getvalue = (ui_getvaluefunc)widget->data2;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
305
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
306 // priority: getvalue, model.getvalue, getstrvalue (fallback)
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
307 if (getvalue == nullptr) {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
308 if (model && model->getvalue) {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
309 getvalue = model->getvalue;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
310 }
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
311 else {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
312 getvalue = getstrvalue;
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
313 }
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
314 }
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
315
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
316 BreadcrumbBar bar = widget->uielement.as<BreadcrumbBar>();
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
317
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
318 Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> items { winrt::single_threaded_vector<Windows::Foundation::IInspectable>() };
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
319 void* elm = list->first(list);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
320 while (elm) {
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
321 char* value = (char*)getvalue(elm, 0);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
322 wchar_t* wstr = str2wstr(value, nullptr);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
323 items.Append(box_value(wstr));
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
324 free(wstr);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
325
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
326 elm = list->next(list);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
327 }
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
328
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
329 bar.ItemsSource(items);
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
330 }
4a258d47f964 add breadcrumb bar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 197
diff changeset
331
221
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
332
196
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 std::vector<int> ui_create_listview_selection(ListView listview) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 std::vector<int> selection;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 int p = 0;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 auto ranges = listview.SelectedRanges();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 for (auto range : ranges) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 int begin = range.FirstIndex();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 int end = range.LastIndex();
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 for (int i = begin; i <= end; i++) {
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 selection.push_back(i);
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 return selection;
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 }
320d85f3cd14 add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346

mercurial