diff -r 40d6af793c1a -r c254ed644edf ui/winui/window.cpp --- a/ui/winui/window.cpp Fri Feb 09 16:50:23 2024 +0100 +++ b/ui/winui/window.cpp Sun Feb 11 13:59:02 2024 +0100 @@ -37,6 +37,7 @@ #include "util.h" #include "../common/context.h" +#include "../common/object.h" #include @@ -204,6 +205,70 @@ } } + + + +static Windows::Foundation::IAsyncAction create_dialog_async(UiObject *obj, UiDialogArgs args) { + UiObject* current = uic_current_obj(obj); + Window parentWindow = current->wobj->window; + + ContentDialog dialog = ContentDialog(); + dialog.XamlRoot(parentWindow.Content().XamlRoot()); + + if (args.title) { + wchar_t *str = str2wstr(args.title, nullptr); + dialog.Title(winrt::box_value(str)); + free(str); + } + if (args.content) { + wchar_t *str = str2wstr(args.content, nullptr); + dialog.Content(winrt::box_value(str)); + free(str); + } + + if (args.button1_label) { + wchar_t *str = str2wstr(args.button1_label, nullptr); + dialog.PrimaryButtonText(winrt::hstring(str)); + free(str); + } + if (args.button2_label) { + wchar_t *str = str2wstr(args.button2_label, nullptr); + dialog.SecondaryButtonText(winrt::hstring(str)); + free(str); + } + if (args.closebutton_label) { + wchar_t *str = str2wstr(args.closebutton_label, nullptr); + dialog.CloseButtonText(winrt::hstring(str)); + free(str); + } + + ContentDialogResult result = co_await dialog.ShowAsync(); + + if (args.result) { + UiEvent evt; + evt.obj = current; + evt.document = current->ctx->document; + evt.window = current->window; + evt.eventdata = NULL; + evt.intval = 0; + if (result == ContentDialogResult::Primary) { + evt.intval = 1; + } else if (result == ContentDialogResult::Secondary) { + evt.intval = 2; + } + + args.result(&evt, args.resultdata); + } +} + +UIEXPORT void ui_dialog_create(UiObject *obj, UiDialogArgs args) { + create_dialog_async(obj, args); +} + + + +// --------------------------------------- File Dialog --------------------------------------- + static void filedialog_callback( UiObject *obj, ui_callback file_selected_callback,