2019-06-07 11:46:02 +02:00
|
|
|
#include <LibGUI/GMenuBar.h>
|
2019-11-08 11:39:45 +01:00
|
|
|
#include <LibGUI/GWindowServerConnection.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
|
|
|
|
2019-12-09 21:05:28 +01:00
|
|
|
void GMenuBar::add_menu(NonnullRefPtr<GMenu> menu)
|
2019-02-11 15:37:12 +01:00
|
|
|
{
|
|
|
|
m_menus.append(move(menu));
|
|
|
|
}
|
|
|
|
|
2019-02-13 17:54:30 +01:00
|
|
|
int GMenuBar::realize_menubar()
|
|
|
|
{
|
2019-12-02 09:33:37 +01:00
|
|
|
return GWindowServerConnection::the().send_sync<WindowServer::CreateMenubar>()->menubar_id();
|
2019-02-13 17:54:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GMenuBar::unrealize_menubar()
|
|
|
|
{
|
2019-05-26 01:07:30 +02:00
|
|
|
if (m_menubar_id == -1)
|
2019-02-13 17:54:30 +01:00
|
|
|
return;
|
2019-12-02 09:33:37 +01:00
|
|
|
GWindowServerConnection::the().send_sync<WindowServer::DestroyMenubar>(m_menubar_id);
|
2019-05-26 01:07:30 +02:00
|
|
|
m_menubar_id = -1;
|
2019-02-13 17:54:30 +01:00
|
|
|
}
|
|
|
|
|
2019-02-11 15:37:12 +01:00
|
|
|
void GMenuBar::notify_added_to_application(Badge<GApplication>)
|
|
|
|
{
|
2019-05-26 01:07:30 +02:00
|
|
|
ASSERT(m_menubar_id == -1);
|
2019-02-13 17:54:30 +01:00
|
|
|
m_menubar_id = realize_menubar();
|
2019-05-26 01:07:30 +02:00
|
|
|
ASSERT(m_menubar_id != -1);
|
2019-02-12 00:52:19 +01:00
|
|
|
for (auto& menu : m_menus) {
|
2019-07-24 09:12:23 +02:00
|
|
|
int menu_id = menu.realize_menu();
|
2019-05-26 01:07:30 +02:00
|
|
|
ASSERT(menu_id != -1);
|
2019-12-02 09:33:37 +01:00
|
|
|
GWindowServerConnection::the().send_sync<WindowServer::AddMenuToMenubar>(m_menubar_id, menu_id);
|
2019-02-12 00:52:19 +01:00
|
|
|
}
|
2019-12-02 09:33:37 +01:00
|
|
|
GWindowServerConnection::the().send_sync<WindowServer::SetApplicationMenubar>(m_menubar_id);
|
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
|
|
|
}
|