Tue, 03 Oct 2023 16:30:42 +0200
add UIEXPORT macro to create a dll
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 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "list.h" |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include "container.h" |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include "util.h" |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "../common/context.h" |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "../common/object.h" |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include <winrt/Microsoft.UI.Xaml.Data.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 | using namespace winrt; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | using namespace Microsoft::UI::Xaml; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | using namespace Microsoft::UI::Xaml::Controls; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | using namespace Windows::UI::Xaml::Interop; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | using namespace winrt::Windows::Foundation; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | UiObject* current = uic_current_obj(obj); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | // create listview and toolkit wrapper |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | ListView listview = ListView(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | if (args.multiselection) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | listview.SelectionMode(ListViewSelectionMode::Extended); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | bool clickEnabled = listview.IsItemClickEnabled(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | listview.IsItemClickEnabled(true); |
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 | UIElement elm = listview; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | UiWidget* widget = new UiWidget(elm); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | widget->data1 = args.model; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | widget->data2 = args.getvalue; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | ui_context_add_widget_destructor(current->ctx, widget); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | // bind var |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | 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
|
66 | if (var) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | UiList* list = (UiList*)var->value; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | list->update = ui_simple_list_update; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | list->obj = widget; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | ui_simple_list_update(list, 0); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | if (args.onselection) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | ui_callback onselection = args.onselection; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | void* cbdata = args.onselectiondata; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | listview.SelectionChanged([onselection, cbdata, obj](IInspectable const& sender, RoutedEventArgs evtargs) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | std::vector<int> selectedRows = ui_create_listview_selection(sender.as<ListView>()); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | UiListSelection selection; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | selection.rows = selectedRows.data(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | selection.count = selectedRows.size(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | UiEvent evt; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | evt.obj = obj; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | evt.window = obj->window; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | evt.document = obj->ctx->document; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | evt.eventdata = &selection; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | evt.intval = 0; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | onselection(&evt, cbdata); |
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 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | if (args.onactivate) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | ui_callback cb = args.onactivate; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | void* cbdata = args.onactivatedata; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | listview.ItemClick([cb, cbdata, obj](IInspectable const& sender, RoutedEventArgs evtargs) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | std::vector<int> selectedRows = ui_create_listview_selection(sender.as<ListView>()); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | UiListSelection selection; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | selection.rows = selectedRows.data(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | selection.count = selectedRows.size(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | UiEvent evt; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | evt.obj = obj; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | evt.window = obj->window; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | evt.document = obj->ctx->document; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | evt.eventdata = &selection; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | evt.intval = 0; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | cb(&evt, cbdata); |
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 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | // add listview to current container |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | UI_APPLY_LAYOUT1(current, args); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | current->container->Add(listview, false); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | return widget; |
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 | |
197
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
119 | |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
120 | UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs args) { |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
121 | UiObject* current = uic_current_obj(obj); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
122 | |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
123 | // create listview and toolkit wrapper |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
124 | ComboBox combobox = ComboBox(); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
125 | |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
126 | UIElement elm = combobox; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
127 | UiWidget* widget = new UiWidget(elm); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
128 | widget->data1 = args.model; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
129 | widget->data2 = args.getvalue; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
130 | ui_context_add_widget_destructor(current->ctx, widget); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
131 | |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
132 | // bind var |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
133 | 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
|
134 | if (var) { |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
135 | UiList* list = (UiList*)var->value; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
136 | list->update = ui_simple_list_update; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
137 | list->obj = widget; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
138 | ui_simple_list_update(list, 0); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
139 | } |
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 | if (args.onactivate) { |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
142 | ui_callback cb = args.onactivate; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
143 | void* cbdata = args.onactivatedata; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
144 | combobox.SelectionChanged([cb, cbdata, obj](IInspectable const& sender, RoutedEventArgs evtargs) { |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
145 | int selectedrow = sender.as<ComboBox>().SelectedIndex(); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
146 | UiListSelection selection; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
147 | selection.count = 1; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
148 | selection.rows = &selectedrow; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
149 | |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
150 | UiEvent evt; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
151 | evt.obj = obj; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
152 | evt.window = obj->window; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
153 | evt.document = obj->ctx->document; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
154 | evt.eventdata = &selection; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
155 | evt.intval = selectedrow; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
156 | cb(&evt, cbdata); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
157 | }); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
158 | } |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
159 | |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
160 | // add listview to current container |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
161 | UI_APPLY_LAYOUT1(current, args); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
162 | |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
163 | current->container->Add(combobox, false); |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
164 | |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
165 | return widget; |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
166 | } |
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
167 | |
196
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | static void* getstrvalue(void* elm, int ignore) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | return elm; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | void ui_simple_list_update(UiList* list, int i) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | UiWidget* widget = (UiWidget*)list->obj; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | UiModel* model = (UiModel*)widget->data1; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | ui_getvaluefunc getvalue = (ui_getvaluefunc)widget->data2; |
197
8a82ebe23822
add combobox (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
176 | ItemsControl listview = widget->uielement.as<ItemsControl>(); |
196
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | auto items = listview.Items(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | // priority: getvalue, model.getvalue, getstrvalue (fallback) |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | if (getvalue == nullptr) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | if (model && model->getvalue) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | getvalue = model->getvalue; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | } else { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | getvalue = getstrvalue; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | // add list elements to listview.Items |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | items.Clear(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | void* elm = list->first(list); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | while (elm) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | char* value = (char*)getvalue(elm, 0); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | wchar_t* wstr = str2wstr(value, nullptr); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | items.Append(box_value(wstr)); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | free(wstr); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | elm = list->next(list); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | std::vector<int> ui_create_listview_selection(ListView listview) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | std::vector<int> selection; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | int p = 0; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | auto ranges = listview.SelectedRanges(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | for (auto range : ranges) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | int begin = range.FirstIndex(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | int end = range.LastIndex(); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | for (int i = begin; i <= end; i++) { |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | selection.push_back(i); |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | return selection; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | } |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 |