Dialog.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibCore/EventLoop.h>
  9. #include <LibGUI/Window.h>
  10. namespace GUI {
  11. class Dialog : public Window {
  12. C_OBJECT(Dialog)
  13. public:
  14. enum class ExecResult {
  15. OK = 0,
  16. Cancel = 1,
  17. Aborted = 2,
  18. Yes = 3,
  19. No = 4,
  20. };
  21. enum class ScreenPosition {
  22. CenterWithinParent = 0,
  23. Center = 1,
  24. CenterLeft = 2,
  25. CenterRight = 3,
  26. TopLeft = 4,
  27. TopCenter = 5,
  28. TopRight = 6,
  29. BottomLeft = 7,
  30. BottomCenter = 8,
  31. BottomRight = 9,
  32. };
  33. virtual ~Dialog() override = default;
  34. ExecResult exec();
  35. ExecResult result() const { return m_result; }
  36. void done(ExecResult);
  37. virtual void event(Core::Event&) override;
  38. virtual void close() override;
  39. protected:
  40. explicit Dialog(Window* parent_window, ScreenPosition = ScreenPosition::CenterWithinParent);
  41. virtual void on_done(ExecResult) { }
  42. private:
  43. OwnPtr<Core::EventLoop> m_event_loop;
  44. ExecResult m_result { ExecResult::Aborted };
  45. ScreenPosition m_screen_position { ScreenPosition::CenterWithinParent };
  46. };
  47. }
  48. template<>
  49. struct AK::Formatter<GUI::Dialog> : Formatter<Core::Object> {
  50. };