summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GMenu.cpp29
-rw-r--r--LibGUI/GMenu.h1
-rw-r--r--LibGUI/GMenuBar.cpp12
3 files changed, 33 insertions, 9 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())
diff --git a/LibGUI/GMenu.h b/LibGUI/GMenu.h
index dceaad72eb..5d56ac0994 100644
--- a/LibGUI/GMenu.h
+++ b/LibGUI/GMenu.h
@@ -24,6 +24,7 @@ private:
friend class GMenuBar;
int menu_id() const { return m_menu_id; }
int realize_menu();
+ void unrealize_menu();
int m_menu_id { 0 };
String m_name;
diff --git a/LibGUI/GMenuBar.cpp b/LibGUI/GMenuBar.cpp
index 3ad0261891..b44bd5f256 100644
--- a/LibGUI/GMenuBar.cpp
+++ b/LibGUI/GMenuBar.cpp
@@ -44,10 +44,16 @@ void GMenuBar::notify_added_to_application(Badge<GApplication>)
ASSERT(menu);
int menu_id = menu->realize_menu();
ASSERT(menu_id > 0);
- int rc = gui_menubar_add_menu(m_menubar_id, menu_id);
- ASSERT(rc == 0);
+ GUI_ClientMessage request;
+ request.type = GUI_ClientMessage::Type::AddMenuToMenubar;
+ request.menu.menubar_id = m_menubar_id;
+ request.menu.menu_id = menu_id;
+ GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidAddMenuToMenubar);
}
- gui_app_set_menubar(m_menubar_id);
+ GUI_ClientMessage request;
+ request.type = GUI_ClientMessage::Type::SetApplicationMenubar;
+ request.menu.menubar_id = m_menubar_id;
+ GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidSetApplicationMenubar);
}
void GMenuBar::notify_removed_from_application(Badge<GApplication>)