MenuItem.h 1.7 KB

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