1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:27:42 +00:00

WindowManager: Move more of the menu management logic to WSMenuManager

This patch moves a whole lot of the menu logic from WSWindowManager to
its proper home in WSMenuManager.

We also get rid of the "close_current_menu()" concept which was easily
confused in the presence of submenus. All operations should now be
aware of the menu stack instead. (The concept of a single, current menu
made a lot more sense when there were no nested menus.)
This commit is contained in:
Andreas Kling 2019-11-11 12:21:57 +01:00
parent 77de51d251
commit cbecad0a77
7 changed files with 126 additions and 96 deletions

View file

@ -198,30 +198,19 @@ void WSMenu::draw()
}
}
void close_everyone_not_in_lineage(WSMenu& menu)
{
for (auto& open_menu : WSWindowManager::the().menu_manager().open_menu_stack()) {
if (!open_menu)
continue;
if (&menu == open_menu.ptr() || open_menu->is_menu_ancestor_of(menu))
continue;
open_menu->menu_window()->set_visible(false);
}
}
void WSMenu::event(CEvent& event)
{
if (event.type() == WSEvent::MouseMove) {
ASSERT(menu_window());
auto* item = item_at(static_cast<const WSMouseEvent&>(event).position());
if (!item || m_hovered_item == item)
if (m_hovered_item == item)
return;
m_hovered_item = item;
if (m_hovered_item->is_submenu()) {
close_everyone_not_in_lineage(*m_hovered_item->submenu());
if (m_hovered_item && m_hovered_item->is_submenu()) {
WSWindowManager::the().menu_manager().close_everyone_not_in_lineage(*m_hovered_item->submenu());
m_hovered_item->submenu()->popup(m_hovered_item->rect().top_right().translated(menu_window()->rect().location()), true);
} else {
close_everyone_not_in_lineage(*this);
WSWindowManager::the().menu_manager().close_everyone_not_in_lineage(*this);
}
redraw();
return;
@ -253,7 +242,7 @@ void WSMenu::did_activate(WSMenuItem& item)
if (on_item_activation)
on_item_activation(item);
close();
WSWindowManager::the().menu_manager().close_everyone();
WSAPI_ServerMessage message;
message.type = WSAPI_ServerMessage::Type::MenuItemActivated;
@ -284,9 +273,7 @@ WSMenuItem* WSMenu::item_at(const Point& position)
void WSMenu::close()
{
WSWindowManager::the().close_menu(*this);
if (menu_window())
menu_window()->set_visible(false);
WSWindowManager::the().menu_manager().close_menu_and_descendants(*this);
}
void WSMenu::popup(const Point& position, bool is_submenu)
@ -305,7 +292,7 @@ void WSMenu::popup(const Point& position, bool is_submenu)
window.move_to(adjusted_pos);
window.set_visible(true);
WSWindowManager::the().set_current_menu(this, is_submenu);
WSWindowManager::the().menu_manager().set_current_menu(this, is_submenu);
}
bool WSMenu::is_menu_ancestor_of(const WSMenu& other) const