/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace GUI { class Menu final : public Core::Object { C_OBJECT(Menu) public: virtual ~Menu() override; void realize_menu_if_needed(); static Menu* from_menu_id(int); int menu_id() const { return m_menu_id; } const String& name() const { return m_name; } const Gfx::Bitmap* icon() const { return m_icon.ptr(); } void set_icon(const Gfx::Bitmap*); Action* action_at(size_t); void add_action(NonnullRefPtr); void add_separator(); Menu& add_submenu(const String& name); void popup(const Gfx::IntPoint& screen_position, const RefPtr& default_action = nullptr); void dismiss(); void visibility_did_change(Badge, bool visible); Function on_visibility_change; bool is_visible() const { return m_visible; } private: friend class Menubar; explicit Menu(String name = ""); int realize_menu(RefPtr default_action = nullptr); void unrealize_menu(); void realize_if_needed(const RefPtr& default_action); void realize_menu_item(MenuItem&, int item_id); int m_menu_id { -1 }; String m_name; RefPtr m_icon; NonnullOwnPtrVector m_items; WeakPtr m_current_default_action; bool m_visible { false }; }; }