MenuItem.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. Action const* 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. Menu const* 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. int menu_id() const { return m_menu_id; }
  39. void set_menu_id(Badge<Menu>, unsigned menu_id);
  40. void set_identifier(Badge<Menu>, unsigned identifier);
  41. void update_from_action(Badge<Action>) { update_window_server(); }
  42. private:
  43. void update_window_server();
  44. Type m_type { Type::Invalid };
  45. int m_menu_id { -1 };
  46. unsigned m_identifier { 0 };
  47. bool m_enabled { true };
  48. bool m_checkable { false };
  49. bool m_checked { false };
  50. bool m_default { false };
  51. RefPtr<Action> m_action;
  52. RefPtr<Menu> m_submenu;
  53. };
  54. }