ui/winui/window.cpp

branch
newapi
changeset 250
d2068517fbdd
parent 247
4b21af9d8c5a
child 252
7d176764756d
equal deleted inserted replaced
249:4df7c366cff7 250:d2068517fbdd
35 #include "commandbar.h" 35 #include "commandbar.h"
36 #include "container.h" 36 #include "container.h"
37 #include "util.h" 37 #include "util.h"
38 38
39 #include "../common/context.h" 39 #include "../common/context.h"
40 #include "../common/object.h"
40 41
41 #include <stdlib.h> 42 #include <stdlib.h>
42 43
43 #include <cx/mempool.h> 44 #include <cx/mempool.h>
44 45
202 wsize.Height = height; 203 wsize.Height = height;
203 win->window.AppWindow().Resize(wsize); 204 win->window.AppWindow().Resize(wsize);
204 } 205 }
205 } 206 }
206 207
208
209
210
211 static Windows::Foundation::IAsyncAction create_dialog_async(UiObject *obj, UiDialogArgs args) {
212 UiObject* current = uic_current_obj(obj);
213 Window parentWindow = current->wobj->window;
214
215 ContentDialog dialog = ContentDialog();
216 dialog.XamlRoot(parentWindow.Content().XamlRoot());
217
218 if (args.title) {
219 wchar_t *str = str2wstr(args.title, nullptr);
220 dialog.Title(winrt::box_value(str));
221 free(str);
222 }
223 if (args.content) {
224 wchar_t *str = str2wstr(args.content, nullptr);
225 dialog.Content(winrt::box_value(str));
226 free(str);
227 }
228
229 if (args.button1_label) {
230 wchar_t *str = str2wstr(args.button1_label, nullptr);
231 dialog.PrimaryButtonText(winrt::hstring(str));
232 free(str);
233 }
234 if (args.button2_label) {
235 wchar_t *str = str2wstr(args.button2_label, nullptr);
236 dialog.SecondaryButtonText(winrt::hstring(str));
237 free(str);
238 }
239 if (args.closebutton_label) {
240 wchar_t *str = str2wstr(args.closebutton_label, nullptr);
241 dialog.CloseButtonText(winrt::hstring(str));
242 free(str);
243 }
244
245 ContentDialogResult result = co_await dialog.ShowAsync();
246
247 if (args.result) {
248 UiEvent evt;
249 evt.obj = current;
250 evt.document = current->ctx->document;
251 evt.window = current->window;
252 evt.eventdata = NULL;
253 evt.intval = 0;
254 if (result == ContentDialogResult::Primary) {
255 evt.intval = 1;
256 } else if (result == ContentDialogResult::Secondary) {
257 evt.intval = 2;
258 }
259
260 args.result(&evt, args.resultdata);
261 }
262 }
263
264 UIEXPORT void ui_dialog_create(UiObject *obj, UiDialogArgs args) {
265 create_dialog_async(obj, args);
266 }
267
268
269
270 // --------------------------------------- File Dialog ---------------------------------------
271
207 static void filedialog_callback( 272 static void filedialog_callback(
208 UiObject *obj, 273 UiObject *obj,
209 ui_callback file_selected_callback, 274 ui_callback file_selected_callback,
210 void *cbdata, 275 void *cbdata,
211 winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Storage::StorageFile> result) 276 winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Storage::StorageFile> result)

mercurial