/* * Copyright (c) 2018-2022, Andreas Kling * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include namespace GUI { ErrorOr> MessageBox::create(Window* parent_window, StringView text, StringView title, Type type, InputType input_type) { auto box = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MessageBox(parent_window, type, input_type))); TRY(box->build()); box->set_title(TRY(String::from_utf8(title)).to_deprecated_string()); box->set_text(TRY(String::from_utf8(text))); auto size = box->main_widget()->effective_min_size(); box->resize(TRY(size.width().shrink_value()), TRY(size.height().shrink_value())); return box; } Dialog::ExecResult MessageBox::show(Window* parent_window, StringView text, StringView title, Type type, InputType input_type) { return MUST(try_show(parent_window, text, title, type, input_type)); } ErrorOr MessageBox::try_show(Window* parent_window, StringView text, StringView title, Type type, InputType input_type) { auto box = TRY(MessageBox::create(parent_window, text, title, type, input_type)); if (parent_window) box->set_icon(parent_window->icon()); return box->exec(); } ErrorOr MessageBox::try_show(Badge, i32 window_server_client_id, i32 parent_window_id, StringView text, StringView title) { auto box = TRY(MessageBox::create(nullptr, text, title, MessageBox::Type::Warning, MessageBox::InputType::YesNo)); auto parent_rect = ConnectionToWindowServer::the().get_window_rect_from_client(window_server_client_id, parent_window_id); box->center_within(parent_rect); box->constrain_to_desktop(); box->set_screen_position(ScreenPosition::DoNotPosition); box->Dialog::show(); ConnectionToWindowServer::the().set_window_parent_from_client(window_server_client_id, parent_window_id, box->window_id()); return box->exec(); } Dialog::ExecResult MessageBox::show_error(Window* parent_window, StringView text) { return MUST(try_show_error(parent_window, text)); } ErrorOr MessageBox::try_show_error(Window* parent_window, StringView text) { return TRY(try_show(parent_window, text, "Error"sv, GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK)); } Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional