blob: 1cce445e69de2fb813e742c2a677cdadcb594179 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GEventLoop.h>
GMenuBar::GMenuBar()
{
}
GMenuBar::~GMenuBar()
{
unrealize_menubar();
}
void GMenuBar::add_menu(OwnPtr<GMenu>&& menu)
{
m_menus.append(move(menu));
}
int GMenuBar::realize_menubar()
{
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::CreateMenubar;
WSAPI_ServerMessage response = GEventLoop::main().sync_request(request, WSAPI_ServerMessage::Type::DidCreateMenubar);
return response.menu.menubar_id;
}
void GMenuBar::unrealize_menubar()
{
if (!m_menubar_id)
return;
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::DestroyMenubar;
request.menu.menubar_id = m_menubar_id;
GEventLoop::main().sync_request(request, WSAPI_ServerMessage::Type::DidDestroyMenubar);
m_menubar_id = 0;
}
void GMenuBar::notify_added_to_application(Badge<GApplication>)
{
ASSERT(!m_menubar_id);
m_menubar_id = realize_menubar();
ASSERT(m_menubar_id > 0);
for (auto& menu : m_menus) {
ASSERT(menu);
int menu_id = menu->realize_menu();
ASSERT(menu_id > 0);
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::AddMenuToMenubar;
request.menu.menubar_id = m_menubar_id;
request.menu.menu_id = menu_id;
GEventLoop::main().sync_request(request, WSAPI_ServerMessage::Type::DidAddMenuToMenubar);
}
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::SetApplicationMenubar;
request.menu.menubar_id = m_menubar_id;
GEventLoop::main().sync_request(request, WSAPI_ServerMessage::Type::DidSetApplicationMenubar);
}
void GMenuBar::notify_removed_from_application(Badge<GApplication>)
{
unrealize_menubar();
}
|