MenuItem.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Badge.h>
  8. #include <AK/Forward.h>
  9. #include <AK/RefPtr.h>
  10. #include <LibGUI/Forward.h>
  11. namespace GUI {
  12. class MenuItem {
  13. public:
  14. enum class Type {
  15. Invalid,
  16. Action,
  17. Separator,
  18. Submenu,
  19. };
  20. MenuItem(unsigned menu_id, Type);
  21. MenuItem(unsigned menu_id, NonnullRefPtr<Action>);
  22. MenuItem(unsigned menu_id, NonnullRefPtr<Menu>);
  23. ~MenuItem();
  24. Type type() const { return m_type; }
  25. const Action* action() const { return m_action.ptr(); }
  26. Action* action() { return m_action.ptr(); }
  27. unsigned identifier() const { return m_identifier; }
  28. Menu* submenu() { return m_submenu.ptr(); }
  29. const Menu* submenu() const { return m_submenu.ptr(); }
  30. bool is_checkable() const { return m_checkable; }
  31. void set_checkable(bool checkable) { m_checkable = checkable; }
  32. bool is_checked() const { return m_checked; }
  33. void set_checked(bool);
  34. bool is_enabled() const { return m_enabled; }
  35. void set_enabled(bool);
  36. bool is_default() const { return m_default; }
  37. void set_default(bool);
  38. void set_menu_id(Badge<Menu>, unsigned menu_id);
  39. void set_identifier(Badge<Menu>, unsigned identifier);
  40. void update_from_action(Badge<Action>) { update_window_server(); }
  41. private:
  42. void update_window_server();
  43. Type m_type { Type::Invalid };
  44. int m_menu_id { -1 };
  45. unsigned m_identifier { 0 };
  46. bool m_enabled { true };
  47. bool m_checkable { false };
  48. bool m_checked { false };
  49. bool m_default { false };
  50. RefPtr<Action> m_action;
  51. RefPtr<Menu> m_submenu;
  52. };
  53. }