diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-12 02:53:27 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-12 02:53:27 +0200 |
commit | 054c9821819de22d1522021978959e50f8fc6382 (patch) | |
tree | 7673e6d859fe6cfb26c28d944724ef8d53f0be99 /Servers/WindowServer/WSMenu.cpp | |
parent | 32e5c8c6890a27acb268cd43f087731e11f99d79 (diff) | |
download | serenity-054c9821819de22d1522021978959e50f8fc6382.zip |
LibGUI+WindowServer: Add support for enabled/disabled actions.
The enabled state of a GAction now propagates both to any toolbar buttons
and any menu items linked to the action. Toolbar buttons are painted in
a grayed out style when disabled. Menu items are gray when disabled. :^)
Diffstat (limited to 'Servers/WindowServer/WSMenu.cpp')
-rw-r--r-- | Servers/WindowServer/WSMenu.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Servers/WindowServer/WSMenu.cpp b/Servers/WindowServer/WSMenu.cpp index 02eeaa7723..38d2e7b445 100644 --- a/Servers/WindowServer/WSMenu.cpp +++ b/Servers/WindowServer/WSMenu.cpp @@ -50,7 +50,8 @@ int WSMenu::height() const void WSMenu::redraw() { - ASSERT(menu_window()); + if (!menu_window()) + return; draw(); menu_window()->invalidate(); } @@ -95,6 +96,8 @@ void WSMenu::draw() painter.fill_rect(item->rect(), WSWindowManager::the().menu_selection_color()); text_color = Color::White; } + if (!item->is_enabled()) + text_color = Color::MidGray; painter.draw_text(item->rect().translated(left_padding(), 0), item->text(), TextAlignment::CenterLeft, text_color); if (!item->shortcut_text().is_empty()) { painter.draw_text(item->rect().translated(-right_padding(), 0), item->shortcut_text(), TextAlignment::CenterRight, text_color); @@ -122,7 +125,8 @@ void WSMenu::on_message(const WSMessage& message) if (message.type() == WSMessage::MouseUp) { if (!m_hovered_item) return; - did_activate(*m_hovered_item); + if (m_hovered_item->is_enabled()) + did_activate(*m_hovered_item); clear_hovered_item(); return; } @@ -152,6 +156,15 @@ void WSMenu::did_activate(WSMenuItem& item) m_client->post_message(message); } +WSMenuItem* WSMenu::item_with_identifier(unsigned identifer) +{ + for (auto& item : m_items) { + if (item->identifier() == identifer) + return item.ptr(); + } + return nullptr; +} + WSMenuItem* WSMenu::item_at(const Point& position) { for (auto& item : m_items) { |