2019-02-11 14:43:43 +01:00
|
|
|
#include <LibGUI/GMenuBar.h>
|
2019-02-13 17:54:30 +01:00
|
|
|
#include <LibGUI/GEventLoop.h>
|
2019-02-11 14:43:43 +01:00
|
|
|
|
|
|
|
GMenuBar::GMenuBar()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GMenuBar::~GMenuBar()
|
|
|
|
{
|
2019-02-13 17:54:30 +01:00
|
|
|
unrealize_menubar();
|
2019-02-11 14:43:43 +01:00
|
|
|
}
|
2019-02-11 15:37:12 +01:00
|
|
|
|
|
|
|
void GMenuBar::add_menu(OwnPtr<GMenu>&& menu)
|
|
|
|
{
|
|
|
|
m_menus.append(move(menu));
|
|
|
|
}
|
|
|
|
|
2019-02-13 17:54:30 +01:00
|
|
|
int GMenuBar::realize_menubar()
|
|
|
|
{
|
|
|
|
GUI_ClientMessage request;
|
|
|
|
request.type = GUI_ClientMessage::Type::CreateMenubar;
|
2019-02-13 17:59:38 +01:00
|
|
|
GUI_ServerMessage response = GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidCreateMenubar);
|
2019-02-13 17:54:30 +01:00
|
|
|
return response.menu.menubar_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GMenuBar::unrealize_menubar()
|
|
|
|
{
|
|
|
|
if (!m_menubar_id)
|
|
|
|
return;
|
|
|
|
GUI_ClientMessage request;
|
|
|
|
request.type = GUI_ClientMessage::Type::DestroyMenubar;
|
|
|
|
request.menu.menubar_id = m_menubar_id;
|
2019-02-13 17:59:38 +01:00
|
|
|
GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidDestroyMenubar);
|
2019-02-13 17:54:30 +01:00
|
|
|
m_menubar_id = 0;
|
|
|
|
}
|
|
|
|
|
2019-02-11 15:37:12 +01:00
|
|
|
void GMenuBar::notify_added_to_application(Badge<GApplication>)
|
|
|
|
{
|
2019-02-12 00:52:19 +01:00
|
|
|
ASSERT(!m_menubar_id);
|
2019-02-13 17:54:30 +01:00
|
|
|
m_menubar_id = realize_menubar();
|
2019-02-12 00:52:19 +01:00
|
|
|
ASSERT(m_menubar_id > 0);
|
|
|
|
for (auto& menu : m_menus) {
|
|
|
|
ASSERT(menu);
|
|
|
|
int menu_id = menu->realize_menu();
|
|
|
|
ASSERT(menu_id > 0);
|
2019-02-13 18:48:22 +01:00
|
|
|
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);
|
2019-02-12 00:52:19 +01:00
|
|
|
}
|
2019-02-13 18:48:22 +01:00
|
|
|
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);
|
2019-02-11 15:37:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GMenuBar::notify_removed_from_application(Badge<GApplication>)
|
|
|
|
{
|
2019-02-13 17:54:30 +01:00
|
|
|
unrealize_menubar();
|
2019-02-11 15:37:12 +01:00
|
|
|
}
|