diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2020-07-27 01:57:09 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-28 16:29:44 +0200 |
commit | 70fe126d01ef824922986c7cd23c1a8753f9ef73 (patch) | |
tree | 97156ffbabd788db7a03f54a79225160ca5fd498 /Libraries/LibGUI/Menu.cpp | |
parent | 048f149f5172e10c454139630aa8f34f8e2e5832 (diff) | |
download | serenity-70fe126d01ef824922986c7cd23c1a8753f9ef73.zip |
LibGUI: Enable icons for SubMenus
It doesn't make sense for a top-level menu to have an icon, however
we do not have dedicated classes to distinguish these.
Furthermore, the only other place to store an icon is MenuItem.
Storing it there would be highly confusing, as MenuItem-with-Action
then would have two icons: one in Action and one in MenuItem.
And because we need to be able to replace the icon during realization,
this would need to write-through to Action somehow.
That's why I went with Menu, not MenuItem.
Diffstat (limited to 'Libraries/LibGUI/Menu.cpp')
-rw-r--r-- | Libraries/LibGUI/Menu.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Libraries/LibGUI/Menu.cpp b/Libraries/LibGUI/Menu.cpp index 5ded8931fd..49d01773c1 100644 --- a/Libraries/LibGUI/Menu.cpp +++ b/Libraries/LibGUI/Menu.cpp @@ -63,6 +63,11 @@ Menu::~Menu() unrealize_menu(); } +void Menu::set_icon(const Gfx::Bitmap* icon) +{ + m_icon = icon; +} + void Menu::add_action(NonnullRefPtr<Action> action) { m_items.append(make<MenuItem>(m_menu_id, move(action))); @@ -143,7 +148,8 @@ int Menu::realize_menu(RefPtr<Action> default_action) if (item.type() == MenuItem::Type::Submenu) { auto& submenu = *item.submenu(); submenu.realize_if_needed(default_action); - WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, false, "", -1, false); + int icon_buffer_id = ensure_realized_icon(submenu); + WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, false, "", icon_buffer_id, false); continue; } if (item.type() == MenuItem::Type::Action) { |