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