ui/winui/window.cpp

Sun, 11 Feb 2024 22:06:23 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 11 Feb 2024 22:06:23 +0100
branch
newapi
changeset 253
087cc9216f28
parent 252
7d176764756d
child 256
8874a68bafb0
permissions
-rw-r--r--

initial newapi GTK port

177
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e79a60b3a7cb minimal working winui app
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
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
e79a60b3a7cb minimal working winui app
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: 200
diff changeset
29 #include "pch.h"
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
30
242
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
31
177
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "window.h"
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 177
diff changeset
34 #include "appmenu.h"
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
35 #include "commandbar.h"
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
36 #include "container.h"
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 183
diff changeset
37 #include "util.h"
180
f34953bf4ac7 add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 177
diff changeset
38
181
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
39 #include "../common/context.h"
250
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
40 #include "../common/object.h"
181
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
41
177
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include <stdlib.h>
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
44 #include <cx/mempool.h>
181
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
45
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
46 #include "MainWindow.xaml.h"
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
47
213
7e39db525fd9 add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 212
diff changeset
48
177
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 using namespace winrt;
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 using namespace Microsoft::UI::Xaml;
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 using namespace Microsoft::UI::Xaml::Controls;
221
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 213
diff changeset
52 using namespace Microsoft::UI::Xaml::Controls::Primitives;
177
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 using namespace Microsoft::UI::Xaml::XamlTypeInfo;
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 using namespace Microsoft::UI::Xaml::Markup;
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 using namespace Windows::UI::Xaml::Interop;
183
3ce2eb11913b create WinUI wrapper classes for usage in UiObject and widget creation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
56 using namespace winrt::Windows::Foundation;
242
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
57 using namespace winrt::Windows::Storage::Pickers;
181
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
58
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 183
diff changeset
59 UiWindow::UiWindow(winrt::Microsoft::UI::Xaml::Window& win) : window(win) {}
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 183
diff changeset
60
181
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
61 UiObject* ui_window(const char* title, void* window_data) {
244
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
62 UiObject* obj = ui_simple_window(title, window_data);
211
5d71a36b833b add custom titlebar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 209
diff changeset
63
181
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
64 if (uic_get_menu_list()) {
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
65 // create/add menubar
181
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
66 MenuBar mb = ui_create_menubar(obj);
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
67 mb.VerticalAlignment(VerticalAlignment::Top);
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 181
diff changeset
68 obj->container->Add(mb, false);
177
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
71 if (uic_toolbar_isenabled()) {
226
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
72 // create a grid for the toolbar: ColumnDefinitions="Auto, *, Auto"
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
73 Grid toolbar_grid = Grid();
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
74 GridLength gl;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
75 gl.Value = 0;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
76 gl.GridUnitType = GridUnitType::Auto;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
77
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
78 ColumnDefinition coldef0 = ColumnDefinition();
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
79 coldef0.Width(gl);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
80 toolbar_grid.ColumnDefinitions().Append(coldef0);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
81
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
82 gl.Value = 1;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
83 gl.GridUnitType = GridUnitType::Star;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
84 ColumnDefinition coldef1 = ColumnDefinition();
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
85 coldef1.Width(gl);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
86 toolbar_grid.ColumnDefinitions().Append(coldef1);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
87
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
88 gl.Value = 0;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
89 gl.GridUnitType = GridUnitType::Auto;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
90 ColumnDefinition coldef2 = ColumnDefinition();
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
91 coldef2.Width(gl);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
92 toolbar_grid.ColumnDefinitions().Append(coldef2);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
93
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
94 // rowdef
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
95 gl.Value = 0;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
96 gl.GridUnitType = GridUnitType::Auto;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
97 RowDefinition rowdef = RowDefinition();
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
98 rowdef.Height(gl);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
99 toolbar_grid.RowDefinitions().Append(rowdef);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
100
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
101
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
102 // create commandbar
226
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
103 CxList* def_l = uic_get_toolbar_defaults(UI_TOOLBAR_LEFT);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
104 CxList* def_c = uic_get_toolbar_defaults(UI_TOOLBAR_CENTER);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
105 CxList* def_r = uic_get_toolbar_defaults(UI_TOOLBAR_RIGHT);
206
7ebc5a747c6f implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
106
226
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
107 bool addappmenu = true;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
108 if (def_r->size > 0) {
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
109 CommandBar toolbar_r = ui_create_toolbar(obj, def_r, addappmenu);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
110 toolbar_grid.SetColumn(toolbar_r, 2);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
111 toolbar_grid.SetRow(toolbar_r, 0);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
112 toolbar_grid.Children().Append(toolbar_r);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
113 addappmenu = false;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
114 }
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
115 if (def_c->size > 0) {
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
116 CommandBar toolbar_c = ui_create_toolbar(obj, def_c, addappmenu);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
117 toolbar_c.HorizontalAlignment(HorizontalAlignment::Center);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
118 toolbar_grid.SetColumn(toolbar_c, 1);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
119 toolbar_grid.SetRow(toolbar_c, 0);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
120 toolbar_grid.Children().Append(toolbar_c);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
121 addappmenu = false;
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
122 }
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
123 if (def_l->size > 0) {
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
124 CommandBar toolbar_l = ui_create_toolbar(obj, def_l, addappmenu);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
125 toolbar_grid.SetColumn(toolbar_l, 0);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
126 toolbar_grid.SetRow(toolbar_l, 0);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
127 toolbar_grid.Children().Append(toolbar_l);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
128 }
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
129
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
130 toolbar_grid.VerticalAlignment(VerticalAlignment::Top);
4eef1d49f794 split toolbar in left,center,right segments (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
131 obj->container->Add(toolbar_grid, false);
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
132 }
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
133
244
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
134 return obj;
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
135 }
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
136
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
137 UIEXPORT UiObject* ui_simple_window(const char *title, void *window_data) {
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
138 CxMempool* mp = cxBasicMempoolCreate(256);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
139 UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject));
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
140
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
141 obj->ctx = uic_context(obj, mp);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
142 obj->window = window_data;
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
143
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
144 Window window = Window();
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
145 //Window window = make<winui::implementation::MainWindow>();
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
146
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
147 winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///MainWindow.xaml" };
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
148 Application::LoadComponent(window, resourceLocator, ComponentResourceLocation::Nested);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
149
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
150 window.ExtendsContentIntoTitleBar(true);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
151
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
152 Grid grid = Grid();
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
153 window.Content(grid);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
154
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
155 StackPanel titleBar = StackPanel();
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
156 Thickness titleBarPadding = { 10, 5, 5, 10 };
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
157 titleBar.Padding(titleBarPadding);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
158 titleBar.Orientation(Orientation::Horizontal);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
159 TextBlock titleLabel = TextBlock();
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
160 titleBar.Children().Append(titleLabel);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
161
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
162 if (title) {
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
163 wchar_t* wtitle = str2wstr(title, nullptr);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
164 window.Title(wtitle);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
165 titleLabel.Text(hstring(wtitle));
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
166 free(wtitle);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
167 }
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
168
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
169 window.SetTitleBar(titleBar);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
170
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
171 obj->wobj = new UiWindow(window);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
172 ui_context_add_window_destructor(obj->ctx, obj->wobj);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
173
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
174 window.Closed([obj](IInspectable const& sender, WindowEventArgs) {
247
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
175 if (obj->ctx->close_callback) {
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
176 UiEvent evt;
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
177 evt.obj = obj;
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
178 evt.document = obj->ctx->document;
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
179 evt.window = obj->window;
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
180 evt.eventdata = NULL;
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
181 evt.intval = 0;
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
182 obj->ctx->close_callback(&evt, obj->ctx->close_data);
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
183 } else {
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
184 ui_context_destroy(obj->ctx);
4b21af9d8c5a call context close handler on window close (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 244
diff changeset
185 }
244
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
186 });
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
187
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
188 obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
189
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
190 titleBar.VerticalAlignment(VerticalAlignment::Top);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
191 obj->container->Add(titleBar, false);
33c0a3797a0d add function for creating windows without menu/toolbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 242
diff changeset
192
181
c52d88ea020b redefine UIWIDGET, remove widget abstraction class (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
193 obj->window = window_data;
183
3ce2eb11913b create WinUI wrapper classes for usage in UiObject and widget creation functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
194
177
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 return obj;
e79a60b3a7cb minimal working winui app
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 }
241
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
197
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
198 void ui_window_size(UiObject *obj, int width, int height) {
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
199 UIWINDOW win = obj->wobj;
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
200 if (win) {
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
201 winrt::Windows::Graphics::SizeInt32 wsize;
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
202 wsize.Width = width;
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
203 wsize.Height = height;
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
204 win->window.AppWindow().Resize(wsize);
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
205 }
c51dd0e9ecb7 add support for table string values, that need to be freed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 226
diff changeset
206 }
242
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
207
250
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
208
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
209
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
210
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
211 static Windows::Foundation::IAsyncAction create_dialog_async(UiObject *obj, UiDialogArgs args) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
212 UiObject* current = uic_current_obj(obj);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
213 Window parentWindow = current->wobj->window;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
214
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
215 ContentDialog dialog = ContentDialog();
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
216 dialog.XamlRoot(parentWindow.Content().XamlRoot());
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
217
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
218 if (args.title) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
219 wchar_t *str = str2wstr(args.title, nullptr);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
220 dialog.Title(winrt::box_value(str));
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
221 free(str);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
222 }
252
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
223
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
224 TextBox textfield{ nullptr };
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
225 if (args.input) {
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
226 StackPanel panel = StackPanel();
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
227 panel.Orientation(Orientation::Vertical);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
228 if (args.content) {
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
229 wchar_t *str = str2wstr(args.content, nullptr);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
230 TextBlock label = TextBlock();
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
231 label.Text(str);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
232 panel.Children().Append(label);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
233 free(str);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
234 }
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
235
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
236 textfield = TextBox();
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
237 Thickness margin = { 0, 5, 0, 0 };
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
238 textfield.Margin(margin);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
239 panel.Margin(margin);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
240
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
241 panel.Children().Append(textfield);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
242
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
243 dialog.Content(panel);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
244
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
245 } else {
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
246 if (args.content) {
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
247 wchar_t *str = str2wstr(args.content, nullptr);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
248 dialog.Content(winrt::box_value(str));
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
249 free(str);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
250 }
250
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
251 }
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
252
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
253 if (args.button1_label) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
254 wchar_t *str = str2wstr(args.button1_label, nullptr);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
255 dialog.PrimaryButtonText(winrt::hstring(str));
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
256 free(str);
252
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
257 dialog.DefaultButton(ContentDialogButton::Primary);
250
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
258 }
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
259 if (args.button2_label) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
260 wchar_t *str = str2wstr(args.button2_label, nullptr);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
261 dialog.SecondaryButtonText(winrt::hstring(str));
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
262 free(str);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
263 }
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
264 if (args.closebutton_label) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
265 wchar_t *str = str2wstr(args.closebutton_label, nullptr);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
266 dialog.CloseButtonText(winrt::hstring(str));
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
267 free(str);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
268 }
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
269
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
270 ContentDialogResult result = co_await dialog.ShowAsync();
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
271
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
272 if (args.result) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
273 UiEvent evt;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
274 evt.obj = current;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
275 evt.document = current->ctx->document;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
276 evt.window = current->window;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
277 evt.eventdata = NULL;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
278 evt.intval = 0;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
279 if (result == ContentDialogResult::Primary) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
280 evt.intval = 1;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
281 } else if (result == ContentDialogResult::Secondary) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
282 evt.intval = 2;
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
283 }
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
284
252
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
285 if (args.input) {
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
286 std::wstring wstr(textfield.Text());
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
287 char *text = wchar2utf8(wstr.c_str(), wstr.length());
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
288 evt.eventdata = text;
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
289 }
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
290
250
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
291 args.result(&evt, args.resultdata);
252
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
292
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
293 if (evt.eventdata) {
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
294 free(evt.eventdata);
7d176764756d add input option to ui_dialog
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 250
diff changeset
295 }
250
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
296 }
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
297 }
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
298
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
299 UIEXPORT void ui_dialog_create(UiObject *obj, UiDialogArgs args) {
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
300 create_dialog_async(obj, args);
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
301 }
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
302
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
303
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
304
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
305 // --------------------------------------- File Dialog ---------------------------------------
d2068517fbdd add function for creating dialogs (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 247
diff changeset
306
242
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
307 static void filedialog_callback(
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
308 UiObject *obj,
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
309 ui_callback file_selected_callback,
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
310 void *cbdata,
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
311 winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Storage::StorageFile> result)
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
312 {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
313 UiFileList flist;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
314 flist.nfiles = result.Size();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
315 flist.files = new char*[flist.nfiles];
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
316
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
317 int i = 0;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
318 for (auto const& file : result) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
319 winrt::hstring path = file.Path();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
320 flist.files[i++] = wchar2utf8(path.c_str(), path.size());
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
321 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
322
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
323 UiEvent evt;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
324 evt.obj = obj;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
325 evt.document = obj->ctx->document;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
326 evt.window = obj->window;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
327 evt.eventdata = &flist;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
328 evt.intval = 0;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
329 file_selected_callback(&evt, cbdata);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
330
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
331 for (int i = 0; i < flist.nfiles;i++) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
332 free(flist.files[i]);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
333 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
334 delete[] flist.files;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
335 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
336
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
337 static Windows::Foundation::IAsyncAction open_filedialog_async(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
338 FileOpenPicker openFileDialog = FileOpenPicker();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
339 auto initializeWithWindow { openFileDialog.as<::IInitializeWithWindow>()
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
340 };
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
341
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
342 HWND hwnd{ nullptr };
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
343 winrt::check_hresult(obj->wobj->window.as<IWindowNative>()->get_WindowHandle(&hwnd));
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
344
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
345 initializeWithWindow->Initialize(hwnd);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
346
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
347 openFileDialog.FileTypeFilter().Append(L"*");
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
348
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
349 if ((mode & UI_FILEDIALOG_SELECT_MULTI) == UI_FILEDIALOG_SELECT_MULTI) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
350 auto files = co_await openFileDialog.PickMultipleFilesAsync();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
351 filedialog_callback(obj, file_selected_callback, cbdata, files);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
352 } else {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
353 auto file = co_await openFileDialog.PickSingleFileAsync();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
354 auto files = single_threaded_vector<winrt::Windows::Storage::StorageFile>();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
355 files.Append(file);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
356 filedialog_callback(obj, file_selected_callback, cbdata, files.GetView());
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
357 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
358 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
359
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
360 static Windows::Foundation::IAsyncAction folderdialog_async(UiObject *obj, ui_callback file_selected_callback, void *cbdata) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
361 FolderPicker folderPicker = FolderPicker();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
362 auto initializeWithWindow { folderPicker.as<::IInitializeWithWindow>()
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
363 };
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
364
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
365 HWND hwnd{ nullptr };
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
366 winrt::check_hresult(obj->wobj->window.as<IWindowNative>()->get_WindowHandle(&hwnd));
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
367
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
368 initializeWithWindow->Initialize(hwnd);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
369
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
370 folderPicker.FileTypeFilter().Append(L"*");
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
371
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
372 auto folder = co_await folderPicker.PickSingleFolderAsync();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
373 if (folder) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
374 winrt::hstring hpath = folder.Path();
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
375 char *cpath = wchar2utf8(hpath.c_str(), hpath.size());
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
376
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
377 UiFileList flist;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
378 flist.nfiles = 1;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
379 flist.files = &cpath;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
380
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
381 UiEvent evt;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
382 evt.obj = obj;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
383 evt.document = obj->ctx->document;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
384 evt.window = obj->window;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
385 evt.eventdata = &flist;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
386 evt.intval = 0;
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
387 file_selected_callback(&evt, cbdata);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
388 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
389 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
390
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
391 UIEXPORT void ui_openfiledialog(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
392 if ((mode & UI_FILEDIALOG_SELECT_FOLDER) == UI_FILEDIALOG_SELECT_FOLDER) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
393 folderdialog_async(obj, file_selected_callback, cbdata);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
394 } else {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
395 open_filedialog_async(obj, mode, file_selected_callback, cbdata);
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
396 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
397 }
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
398
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
399 UIEXPORT void ui_savefiledialog(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) {
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
400
4ff7361dce95 add file open dialog (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
401 }

mercurial