Dialog.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 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 screen_position = CenterWithinParent);
  41. private:
  42. OwnPtr<Core::EventLoop> m_event_loop;
  43. ExecResult m_result { ExecResult::Aborted };
  44. int m_screen_position { CenterWithinParent };
  45. };
  46. }
  47. template<>
  48. struct AK::Formatter<GUI::Dialog> : Formatter<Core::Object> {
  49. };