ui/winui/window.cpp

Fri, 15 Nov 2024 21:50:20 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 15 Nov 2024 21:50:20 +0100
changeset 86
8e7c57c23133
parent 79
483d7342b439
permissions
-rw-r--r--

add reference counting to download window

0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2483f517c562 add existing toolkit code
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
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "pch.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
31
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "window.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "appmenu.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "commandbar.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "container.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "util.h"
79
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
38 #include "button.h"
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "../common/context.h"
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
41 #include "../common/object.h"
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #include <stdlib.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #include <cx/mempool.h>
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #include "MainWindow.xaml.h"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
50 #include <Windows.h>
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
51 #include <shobjidl.h>
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
52 #include <iostream>
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
53
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 using namespace winrt;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 using namespace Microsoft::UI::Xaml;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 using namespace Microsoft::UI::Xaml::Controls;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 using namespace Microsoft::UI::Xaml::Controls::Primitives;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 using namespace Microsoft::UI::Xaml::XamlTypeInfo;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 using namespace Microsoft::UI::Xaml::Markup;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 using namespace Windows::UI::Xaml::Interop;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 using namespace winrt::Windows::Foundation;
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
62 using namespace winrt::Windows::Storage::Pickers;
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 UiWindow::UiWindow(winrt::Microsoft::UI::Xaml::Window& win) : window(win) {}
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 UiObject* ui_window(const char* title, void* window_data) {
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
67 UiObject* obj = ui_simple_window(title, window_data);
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
69 /*
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 if (uic_get_menu_list()) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 // create/add menubar
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 MenuBar mb = ui_create_menubar(obj);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 mb.VerticalAlignment(VerticalAlignment::Top);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 obj->container->Add(mb, false);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 }
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
76 */
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 if (uic_toolbar_isenabled()) {
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 // create a grid for the toolbar: ColumnDefinitions="Auto, *, Auto"
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 Grid toolbar_grid = Grid();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 GridLength gl;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 gl.Value = 0;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 gl.GridUnitType = GridUnitType::Auto;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 ColumnDefinition coldef0 = ColumnDefinition();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 coldef0.Width(gl);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 toolbar_grid.ColumnDefinitions().Append(coldef0);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 gl.Value = 1;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 gl.GridUnitType = GridUnitType::Star;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 ColumnDefinition coldef1 = ColumnDefinition();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 coldef1.Width(gl);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 toolbar_grid.ColumnDefinitions().Append(coldef1);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 gl.Value = 0;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 gl.GridUnitType = GridUnitType::Auto;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 ColumnDefinition coldef2 = ColumnDefinition();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 coldef2.Width(gl);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 toolbar_grid.ColumnDefinitions().Append(coldef2);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 // rowdef
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 gl.Value = 0;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 gl.GridUnitType = GridUnitType::Auto;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 RowDefinition rowdef = RowDefinition();
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 rowdef.Height(gl);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 toolbar_grid.RowDefinitions().Append(rowdef);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 // create commandbar
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 CxList* def_l = uic_get_toolbar_defaults(UI_TOOLBAR_LEFT);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 CxList* def_c = uic_get_toolbar_defaults(UI_TOOLBAR_CENTER);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 CxList* def_r = uic_get_toolbar_defaults(UI_TOOLBAR_RIGHT);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 bool addappmenu = true;
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
115 if (cxListSize(def_r) > 0) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 CommandBar toolbar_r = ui_create_toolbar(obj, def_r, addappmenu);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 toolbar_grid.SetColumn(toolbar_r, 2);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 toolbar_grid.SetRow(toolbar_r, 0);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 toolbar_grid.Children().Append(toolbar_r);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 addappmenu = false;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 }
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
122 if (cxListSize(def_c) > 0) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 CommandBar toolbar_c = ui_create_toolbar(obj, def_c, addappmenu);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 toolbar_c.HorizontalAlignment(HorizontalAlignment::Center);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 toolbar_grid.SetColumn(toolbar_c, 1);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 toolbar_grid.SetRow(toolbar_c, 0);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 toolbar_grid.Children().Append(toolbar_c);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 addappmenu = false;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 }
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
130 if (cxListSize(def_l) > 0) {
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 CommandBar toolbar_l = ui_create_toolbar(obj, def_l, addappmenu);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 toolbar_grid.SetColumn(toolbar_l, 0);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 toolbar_grid.SetRow(toolbar_l, 0);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 toolbar_grid.Children().Append(toolbar_l);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 toolbar_grid.VerticalAlignment(VerticalAlignment::Top);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 obj->container->Add(toolbar_grid, false);
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 }
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
141 return obj;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
142 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
143
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
144 UIEXPORT UiObject* ui_simple_window(const char *title, void *window_data) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
145 CxMempool* mp = cxBasicMempoolCreate(256);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
146 UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject));
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
147
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
148 obj->ctx = uic_context(obj, mp);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
149 obj->window = window_data;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
150
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
151 Window window = Window();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
152 //Window window = make<winui::implementation::MainWindow>();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
153
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
154 winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///MainWindow.xaml" };
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
155 Application::LoadComponent(window, resourceLocator, ComponentResourceLocation::Nested);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
156
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
157 window.ExtendsContentIntoTitleBar(true);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
158
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
159 Grid grid = Grid();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
160 window.Content(grid);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
161
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
162 StackPanel titleBar = StackPanel();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
163 Thickness titleBarPadding = { 10, 5, 5, 10 };
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
164 titleBar.Padding(titleBarPadding);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
165 titleBar.Orientation(Orientation::Horizontal);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
166 TextBlock titleLabel = TextBlock();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
167 titleBar.Children().Append(titleLabel);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
168
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
169 if (title) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
170 wchar_t* wtitle = str2wstr(title, nullptr);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
171 window.Title(wtitle);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
172 titleLabel.Text(hstring(wtitle));
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
173 free(wtitle);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
174 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
175
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
176 window.SetTitleBar(titleBar);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
177
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
178 obj->wobj = new UiWindow(window);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
179 ui_context_add_window_destructor(obj->ctx, obj->wobj);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
180
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
181 window.Closed([obj](IInspectable const& sender, WindowEventArgs) {
21
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
182 if (obj->ctx->close_callback) {
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
183 UiEvent evt;
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
184 evt.obj = obj;
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
185 evt.document = obj->ctx->document;
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
186 evt.window = obj->window;
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
187 evt.eventdata = NULL;
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
188 evt.intval = 0;
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
189 obj->ctx->close_callback(&evt, obj->ctx->close_data);
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
190 } else {
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
191 ui_context_destroy(obj->ctx);
3060a5a1d5fd don't crash when the upload is in progress and the window is closed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
192 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
193 });
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
194
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
195 obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
196
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
197 titleBar.VerticalAlignment(VerticalAlignment::Top);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
198 obj->container->Add(titleBar, false);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
199
0
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 obj->window = window_data;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 return obj;
2483f517c562 add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 }
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
204
79
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
205 static void dialog_button_add_callback(ContentDialog dialog, Button button, int num, UiObject *obj, ui_callback onclick, void *onclickdata) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
206 button.Click([dialog, num, obj, onclick, onclickdata](IInspectable const& sender, RoutedEventArgs) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
207 if (onclick) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
208 UiEvent evt;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
209 evt.obj = obj;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
210 evt.window = obj->window;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
211 evt.document = obj->ctx->document;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
212 evt.eventdata = nullptr;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
213 evt.intval = num;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
214 onclick(&evt, onclickdata);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
215 }
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
216 dialog.Hide();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
217 });
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
218 }
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
219
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
220 UIEXPORT UiObject* ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs args) {
79
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
221 UiWindow *window = parent->wobj;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
222 if (!window) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
223 return NULL;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
224 }
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
225
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
226 CxMempool* mp = cxBasicMempoolCreate(256);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
227 UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject));
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
228
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
229 obj->ctx = uic_context(obj, mp);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
230
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
231 ContentDialog dialog = ContentDialog();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
232 UIElement elm = dialog;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
233 UiWidget* widget = new UiWidget(elm);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
234 ui_context_add_widget_destructor(obj->ctx, widget);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
235 obj->widget = widget;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
236
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
237 if (args.title) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
238 wchar_t* wtitle = str2wstr(args.title, nullptr);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
239 dialog.Title(box_value(wtitle));
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
240 free(wtitle);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
241 }
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
242
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
243
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
244 Grid dialogContent = Grid();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
245 GridLength gl;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
246
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
247 // content row
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
248 gl.Value = 1;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
249 gl.GridUnitType = GridUnitType::Star;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
250 RowDefinition rowdef0 = RowDefinition();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
251 rowdef0.Height(gl);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
252 dialogContent.RowDefinitions().Append(rowdef0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
253
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
254 // button row
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
255 gl.Value = 0;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
256 gl.GridUnitType = GridUnitType::Auto;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
257 RowDefinition rowdef1 = RowDefinition();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
258 rowdef1.Height(gl);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
259 dialogContent.RowDefinitions().Append(rowdef1);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
260
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
261 // coldef
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
262 gl.Value = 1;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
263 gl.GridUnitType = GridUnitType::Star;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
264 ColumnDefinition coldef = ColumnDefinition();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
265 coldef.Width(gl);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
266 dialogContent.ColumnDefinitions().Append(coldef);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
267
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
268 // content
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
269 Grid grid = Grid();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
270 grid.SetRow(grid, 0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
271 grid.SetColumn(grid, 0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
272 dialogContent.Children().Append(grid);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
273 obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
274
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
275 // buttons
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
276 Grid buttons = Grid();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
277 Thickness btnsMargin = { (double)0, (double)10, (double)0, (double)0 };
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
278 buttons.Margin(btnsMargin);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
279
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
280 RowDefinition btnrowdef = RowDefinition();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
281 gl.Value = 0;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
282 gl.GridUnitType = GridUnitType::Auto;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
283 btnrowdef.Height(gl);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
284 buttons.RowDefinitions().Append(btnrowdef);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
285
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
286 gl.Value = 1;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
287 gl.GridUnitType = GridUnitType::Auto;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
288 int c = 0;
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
289 if (args.lbutton1) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
290 ColumnDefinition bcoldef = ColumnDefinition();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
291 bcoldef.Width(gl);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
292 buttons.ColumnDefinitions().Append(bcoldef);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
293
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
294 Button btn = Button();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
295 ui_set_button_label(btn, args.lbutton1, NULL, NULL, UI_LABEL_TEXT);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
296 Thickness margin = { (double)5, (double)5, (double)5, (double)5 };
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
297 btn.Margin(margin);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
298 btn.HorizontalAlignment(HorizontalAlignment::Stretch);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
299 dialog_button_add_callback(dialog, btn, 1, obj, args.onclick, args.onclickdata);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
300
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
301 buttons.SetRow(btn, 0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
302 buttons.SetColumn(btn, c++);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
303 buttons.Children().Append(btn);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
304 }
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
305 if (args.lbutton2) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
306 ColumnDefinition bcoldef = ColumnDefinition();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
307 bcoldef.Width(gl);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
308 buttons.ColumnDefinitions().Append(bcoldef);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
309
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
310 Button btn = Button();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
311 ui_set_button_label(btn, args.lbutton2, NULL, NULL, UI_LABEL_TEXT);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
312 Thickness margin = { (double)5, (double)5, (double)5, (double)5 };
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
313 btn.Margin(margin);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
314 btn.HorizontalAlignment(HorizontalAlignment::Stretch);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
315 dialog_button_add_callback(dialog, btn, 2, obj, args.onclick, args.onclickdata);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
316
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
317 buttons.SetRow(btn, 0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
318 buttons.SetColumn(btn, c++);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
319 buttons.Children().Append(btn);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
320 }
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
321 if (args.rbutton3) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
322 ColumnDefinition bcoldef = ColumnDefinition();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
323 bcoldef.Width(gl);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
324 buttons.ColumnDefinitions().Append(bcoldef);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
325
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
326 Button btn = Button();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
327 ui_set_button_label(btn, args.rbutton3, NULL, NULL, UI_LABEL_TEXT);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
328 Thickness margin = { (double)5, (double)5, (double)5, (double)5 };
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
329 btn.Margin(margin);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
330 btn.HorizontalAlignment(HorizontalAlignment::Stretch);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
331 dialog_button_add_callback(dialog, btn, 3, obj, args.onclick, args.onclickdata);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
332
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
333 buttons.SetRow(btn, 0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
334 buttons.SetColumn(btn, c++);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
335 buttons.Children().Append(btn);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
336 }
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
337 if (args.rbutton4) {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
338 ColumnDefinition bcoldef = ColumnDefinition();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
339 bcoldef.Width(gl);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
340 buttons.ColumnDefinitions().Append(bcoldef);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
341
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
342 Button btn = Button();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
343 ui_set_button_label(btn, args.rbutton4, NULL, NULL, UI_LABEL_TEXT);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
344 Thickness margin = { (double)5, (double)5, (double)5, (double)5 };
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
345 btn.Margin(margin);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
346 btn.HorizontalAlignment(HorizontalAlignment::Stretch);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
347 dialog_button_add_callback(dialog, btn, 4, obj, args.onclick, args.onclickdata);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
348
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
349 buttons.SetRow(btn, 0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
350 buttons.SetColumn(btn, c++);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
351 buttons.Children().Append(btn);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
352 }
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
353
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
354 dialogContent.SetRow(buttons, 1);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
355 dialogContent.SetColumn(buttons, 0);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
356 dialogContent.Children().Append(buttons);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
357
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
358
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
359 dialog.Content(dialogContent);
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
360 dialog.XamlRoot(window->window.Content().XamlRoot());
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
361
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
362 obj->widget->Show = [dialog]() {
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
363 dialog.ShowAsync();
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
364 };
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
365
483d7342b439 update toolkit (winui dialog window)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
366 return obj;
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
367 }
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
368
13
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
369 void ui_window_size(UiObject *obj, int width, int height) {
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
370 UIWINDOW win = obj->wobj;
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
371 if (win) {
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
372 winrt::Windows::Graphics::SizeInt32 wsize;
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
373 wsize.Width = width;
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
374 wsize.Height = height;
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
375 win->window.AppWindow().Resize(wsize);
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
376 }
5a8762fcfecc update toolkit / set window size
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
377 }
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
378
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
379
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
380
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
381
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
382 static Windows::Foundation::IAsyncAction create_dialog_async(UiObject *obj, UiDialogArgs args) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
383 UiObject* current = uic_current_obj(obj);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
384 Window parentWindow = current->wobj->window;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
385
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
386 ContentDialog dialog = ContentDialog();
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
387 dialog.XamlRoot(parentWindow.Content().XamlRoot());
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
388
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
389 if (args.title) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
390 wchar_t *str = str2wstr(args.title, nullptr);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
391 dialog.Title(winrt::box_value(str));
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
392 free(str);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
393 }
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
394
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
395 TextBox textfield{ nullptr };
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
396 PasswordBox password{ nullptr };
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
397 if(args.input || args.password) {
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
398 StackPanel panel = StackPanel();
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
399 panel.Orientation(Orientation::Vertical);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
400 if (args.content) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
401 wchar_t *str = str2wstr(args.content, nullptr);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
402 TextBlock label = TextBlock();
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
403 label.Text(str);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
404 panel.Children().Append(label);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
405 free(str);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
406 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
407
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
408 Thickness margin = { 0, 5, 0, 0 };
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
409 if (args.password) {
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
410 password = PasswordBox();
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
411 password.Margin(margin);
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
412 panel.Children().Append(password);
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
413 } else {
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
414 textfield = TextBox();
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
415 textfield.Margin(margin);
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
416 panel.Children().Append(textfield);
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
417 }
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
418
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
419 panel.Margin(margin);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
420
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
421 dialog.Content(panel);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
422
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
423 } else {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
424 if (args.content) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
425 wchar_t *str = str2wstr(args.content, nullptr);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
426 dialog.Content(winrt::box_value(str));
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
427 free(str);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
428 }
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
429 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
430
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
431 if (args.button1_label) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
432 wchar_t *str = str2wstr(args.button1_label, nullptr);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
433 dialog.PrimaryButtonText(winrt::hstring(str));
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
434 free(str);
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
435 dialog.DefaultButton(ContentDialogButton::Primary);
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
436 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
437 if (args.button2_label) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
438 wchar_t *str = str2wstr(args.button2_label, nullptr);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
439 dialog.SecondaryButtonText(winrt::hstring(str));
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
440 free(str);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
441 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
442 if (args.closebutton_label) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
443 wchar_t *str = str2wstr(args.closebutton_label, nullptr);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
444 dialog.CloseButtonText(winrt::hstring(str));
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
445 free(str);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
446 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
447
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
448 ContentDialogResult result = co_await dialog.ShowAsync();
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
449
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
450 if (args.result) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
451 UiEvent evt;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
452 evt.obj = current;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
453 evt.document = current->ctx->document;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
454 evt.window = current->window;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
455 evt.eventdata = NULL;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
456 evt.intval = 0;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
457 if (result == ContentDialogResult::Primary) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
458 evt.intval = 1;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
459 } else if (result == ContentDialogResult::Secondary) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
460 evt.intval = 2;
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
461 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
462
76
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
463 if (args.password) {
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
464 std::wstring wstr(password.Password());
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
465 char *text = wchar2utf8(wstr.c_str(), wstr.length());
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
466 evt.eventdata = text;
641dcc79e0ef update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
467 } else if (args.input) {
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
468 std::wstring wstr(textfield.Text());
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
469 char *text = wchar2utf8(wstr.c_str(), wstr.length());
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
470 evt.eventdata = text;
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
471 }
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
472
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
473 args.result(&evt, args.resultdata);
28
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
474
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
475 if (evt.eventdata) {
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
476 free(evt.eventdata);
1ecc1183f046 implement new-collection toolbar button
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 27
diff changeset
477 }
27
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
478 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
479 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
480
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
481 UIEXPORT void ui_dialog_create(UiObject *obj, UiDialogArgs args) {
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
482 create_dialog_async(obj, args);
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
483 }
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
484
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
485
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
486
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
487 // --------------------------------------- File Dialog ---------------------------------------
c254ed644edf remove deleted resources from the browser list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
488
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
489 static void filedialog_callback(
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
490 UiObject *obj,
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
491 ui_callback file_selected_callback,
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
492 void *cbdata,
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
493 winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Storage::StorageFile> result)
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
494 {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
495 UiFileList flist;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
496 flist.nfiles = result.Size();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
497 flist.files = new char*[flist.nfiles];
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
498
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
499 int i = 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
500 for (auto const& file : result) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
501 winrt::hstring path = file.Path();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
502 flist.files[i++] = wchar2utf8(path.c_str(), path.size());
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
503 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
504
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
505 UiEvent evt;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
506 evt.obj = obj;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
507 evt.document = obj->ctx->document;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
508 evt.window = obj->window;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
509 evt.eventdata = &flist;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
510 evt.intval = 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
511 file_selected_callback(&evt, cbdata);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
512
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
513 for (int i = 0; i < flist.nfiles;i++) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
514 free(flist.files[i]);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
515 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
516 delete[] flist.files;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
517 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
518
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
519 static Windows::Foundation::IAsyncAction open_filedialog_async(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
520 FileOpenPicker openFileDialog = FileOpenPicker();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
521 auto initializeWithWindow { openFileDialog.as<::IInitializeWithWindow>()
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
522 };
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
523
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
524 HWND hwnd{ nullptr };
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
525 winrt::check_hresult(obj->wobj->window.as<IWindowNative>()->get_WindowHandle(&hwnd));
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
526
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
527 initializeWithWindow->Initialize(hwnd);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
528
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
529 openFileDialog.FileTypeFilter().Append(L"*");
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
530
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
531 if ((mode & UI_FILEDIALOG_SELECT_MULTI) == UI_FILEDIALOG_SELECT_MULTI) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
532 auto files = co_await openFileDialog.PickMultipleFilesAsync();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
533 filedialog_callback(obj, file_selected_callback, cbdata, files);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
534 } else {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
535 auto file = co_await openFileDialog.PickSingleFileAsync();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
536 auto files = single_threaded_vector<winrt::Windows::Storage::StorageFile>();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
537 files.Append(file);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
538 filedialog_callback(obj, file_selected_callback, cbdata, files.GetView());
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
539 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
540 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
541
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
542 static Windows::Foundation::IAsyncAction save_filedialog_async(UiObject *obj, char *name, ui_callback file_selected_callback, void *cbdata) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
543 IFileSaveDialog *saveFileDialog;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
544
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
545 HRESULT hr = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_ALL, IID_IFileSaveDialog, reinterpret_cast<void**>(&saveFileDialog));
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
546 if (FAILED(hr))
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
547 {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
548 co_return;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
549 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
550
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
551 if (name) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
552 wchar_t *wname = str2wstr(name, NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
553 saveFileDialog->SetFileName(wname);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
554 free(wname);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
555 free(name);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
556 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
557
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
558
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
559 hr = saveFileDialog->Show(NULL);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
560 if (SUCCEEDED(hr)) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
561 IShellItem *item;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
562 hr = saveFileDialog->GetResult(&item);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
563 if (SUCCEEDED(hr)) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
564 PWSTR wpath;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
565 hr = item->GetDisplayName(SIGDN_FILESYSPATH, &wpath);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
566
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
567 if (SUCCEEDED(hr)) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
568 char *path = wchar2utf8(wpath, lstrlen(wpath));
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
569 CoTaskMemFree(wpath);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
570
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
571 UiFileList flist;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
572 flist.nfiles = 1;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
573 flist.files = new char*[1];
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
574 flist.files[0] = path;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
575
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
576 UiEvent evt;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
577 evt.obj = obj;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
578 evt.document = obj->ctx->document;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
579 evt.window = obj->window;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
580 evt.eventdata = &flist;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
581 evt.intval = 0;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
582 file_selected_callback(&evt, cbdata);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
583
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
584 free(path);
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
585 delete[] flist.files;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
586 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
587 item->Release();
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
588 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
589 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
590
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
591 // cleanup
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
592 saveFileDialog->Release();
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
593 }
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
594
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
595 static Windows::Foundation::IAsyncAction folderdialog_async(UiObject *obj, ui_callback file_selected_callback, void *cbdata) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
596 FolderPicker folderPicker = FolderPicker();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
597 auto initializeWithWindow { folderPicker.as<::IInitializeWithWindow>()
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
598 };
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
599
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
600 HWND hwnd{ nullptr };
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
601 winrt::check_hresult(obj->wobj->window.as<IWindowNative>()->get_WindowHandle(&hwnd));
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
602
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
603 initializeWithWindow->Initialize(hwnd);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
604
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
605 folderPicker.FileTypeFilter().Append(L"*");
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
606
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
607 auto folder = co_await folderPicker.PickSingleFolderAsync();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
608 if (folder) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
609 winrt::hstring hpath = folder.Path();
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
610 char *cpath = wchar2utf8(hpath.c_str(), hpath.size());
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
611
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
612 UiFileList flist;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
613 flist.nfiles = 1;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
614 flist.files = &cpath;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
615
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
616 UiEvent evt;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
617 evt.obj = obj;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
618 evt.document = obj->ctx->document;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
619 evt.window = obj->window;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
620 evt.eventdata = &flist;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
621 evt.intval = 0;
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
622 file_selected_callback(&evt, cbdata);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
623 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
624 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
625
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
626 UIEXPORT void ui_openfiledialog(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
627 if ((mode & UI_FILEDIALOG_SELECT_FOLDER) == UI_FILEDIALOG_SELECT_FOLDER) {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
628 folderdialog_async(obj, file_selected_callback, cbdata);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
629 } else {
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
630 open_filedialog_async(obj, mode, file_selected_callback, cbdata);
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
631 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
632 }
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
633
29
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
634 UIEXPORT void ui_savefiledialog(UiObject *obj, const char *name, ui_callback file_selected_callback, void *cbdata) {
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
635 char *n = name ? _strdup(name) : NULL;
3fc287f06305 add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
636 save_filedialog_async(obj, n, file_selected_callback, cbdata);
18
af411868ab9b implement dnd upload (without progressbar)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
637 }

mercurial