summaryrefslogtreecommitdiff
path: root/LibGUI/GMenu.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-13 18:48:22 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-13 18:49:23 +0100
commitcf432b4c3d366edef40798a777ab2014715fd7f4 (patch)
treeeb8e817191dc090a024ecaf1d6bab3b85b6ed470 /LibGUI/GMenu.cpp
parentfbbf57b61c34e548159f70d496dec2b0fbc54545 (diff)
downloadserenity-cf432b4c3d366edef40798a777ab2014715fd7f4.zip
WindowServer: Refactor more of the menu APIs to be message-based.
This is all pretty verbose but I can whittle it down later. :^)
Diffstat (limited to 'LibGUI/GMenu.cpp')
-rw-r--r--LibGUI/GMenu.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/LibGUI/GMenu.cpp b/LibGUI/GMenu.cpp
index 439a71d9cd..18fb9635b3 100644
--- a/LibGUI/GMenu.cpp
+++ b/LibGUI/GMenu.cpp
@@ -1,5 +1,6 @@
#include <LibGUI/GAction.h>
#include <LibGUI/GMenu.h>
+#include <LibGUI/GEventLoop.h>
#include <LibC/gui.h>
#include <AK/HashMap.h>
@@ -26,11 +27,7 @@ GMenu::GMenu(const String& name)
GMenu::~GMenu()
{
- if (m_menu_id) {
- all_menus().remove(m_menu_id);
- gui_menu_destroy(m_menu_id);
- m_menu_id = 0;
- }
+ unrealize_menu();
}
void GMenu::add_action(OwnPtr<GAction>&& action)
@@ -45,7 +42,15 @@ void GMenu::add_separator()
int GMenu::realize_menu()
{
- m_menu_id = gui_menu_create(m_name.characters());
+ GUI_ClientMessage request;
+ request.type = GUI_ClientMessage::Type::CreateMenu;
+ ASSERT(m_name.length() < sizeof(request.menu.text));
+ strcpy(request.menu.text, m_name.characters());
+ request.menu.text_length = m_name.length();
+
+ auto response = GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidCreateMenu);
+ m_menu_id = response.menu.menu_id;
+
ASSERT(m_menu_id > 0);
for (size_t i = 0; i < m_items.size(); ++i) {
auto& item = *m_items[i];
@@ -62,6 +67,18 @@ int GMenu::realize_menu()
return m_menu_id;
}
+void GMenu::unrealize_menu()
+{
+ if (!m_menu_id)
+ return;
+ all_menus().remove(m_menu_id);
+ GUI_ClientMessage request;
+ request.type = GUI_ClientMessage::Type::DestroyMenu;
+ request.menu.menu_id = m_menu_id;
+ GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidDestroyMenu);
+ m_menu_id = 0;
+}
+
GAction* GMenu::action_at(size_t index)
{
if (index >= m_items.size())