2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-26 20:50:04 +03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-03-19 02:01:02 +03:00
|
|
|
#pragma once
|
|
|
|
|
2022-02-26 20:50:04 +03:00
|
|
|
#include <LibCore/EventLoop.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Window.h>
|
2019-03-19 02:01:02 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class Dialog : public Window {
|
|
|
|
C_OBJECT(Dialog)
|
2019-03-19 02:01:02 +03:00
|
|
|
public:
|
2022-05-13 15:10:27 +03:00
|
|
|
enum class ExecResult {
|
|
|
|
OK = 0,
|
|
|
|
Cancel = 1,
|
|
|
|
Aborted = 2,
|
|
|
|
Yes = 3,
|
|
|
|
No = 4,
|
2019-05-28 12:53:16 +03:00
|
|
|
};
|
2021-07-14 13:01:31 +03:00
|
|
|
|
2023-05-13 12:07:09 +03:00
|
|
|
enum class ScreenPosition {
|
|
|
|
DoNotPosition,
|
|
|
|
CenterWithinParent,
|
|
|
|
Center,
|
2021-07-14 13:01:31 +03:00
|
|
|
};
|
2019-03-19 04:20:00 +03:00
|
|
|
|
2022-02-26 20:50:04 +03:00
|
|
|
virtual ~Dialog() override = default;
|
2019-03-19 02:01:02 +03:00
|
|
|
|
2022-05-13 15:10:27 +03:00
|
|
|
ExecResult exec();
|
2019-03-19 02:01:02 +03:00
|
|
|
|
2022-05-13 15:10:27 +03:00
|
|
|
ExecResult result() const { return m_result; }
|
|
|
|
void done(ExecResult);
|
2019-03-19 02:01:02 +03:00
|
|
|
|
2023-05-13 12:07:09 +03:00
|
|
|
ScreenPosition screen_position() const { return m_screen_position; }
|
|
|
|
void set_screen_position(ScreenPosition position) { m_screen_position = position; }
|
|
|
|
|
2020-02-02 14:34:39 +03:00
|
|
|
virtual void event(Core::Event&) override;
|
2020-01-01 03:58:37 +03:00
|
|
|
|
2019-07-26 17:13:59 +03:00
|
|
|
virtual void close() override;
|
|
|
|
|
2019-03-19 02:01:02 +03:00
|
|
|
protected:
|
2022-05-13 16:19:18 +03:00
|
|
|
explicit Dialog(Window* parent_window, ScreenPosition = ScreenPosition::CenterWithinParent);
|
2019-03-19 02:01:02 +03:00
|
|
|
|
2022-11-16 15:35:02 +03:00
|
|
|
virtual void on_done(ExecResult) { }
|
|
|
|
|
2019-03-19 02:01:02 +03:00
|
|
|
private:
|
2020-02-02 14:34:39 +03:00
|
|
|
OwnPtr<Core::EventLoop> m_event_loop;
|
2022-05-13 15:10:27 +03:00
|
|
|
ExecResult m_result { ExecResult::Aborted };
|
2022-05-13 16:19:18 +03:00
|
|
|
ScreenPosition m_screen_position { ScreenPosition::CenterWithinParent };
|
2019-03-19 02:01:02 +03:00
|
|
|
};
|
2020-02-02 17:07:41 +03:00
|
|
|
|
|
|
|
}
|
2021-01-11 15:32:26 +03:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct AK::Formatter<GUI::Dialog> : Formatter<Core::Object> {
|
|
|
|
};
|