1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:05:07 +00:00

Add API's and plumbing for WindowServer clients to make menus.

This commit is contained in:
Andreas Kling 2019-02-12 00:52:19 +01:00
parent bb31d961b4
commit 133706d697
17 changed files with 322 additions and 24 deletions

View file

@ -1,4 +1,5 @@
#include <LibGUI/GMenu.h>
#include <LibC/gui.h>
GMenu::GMenu(const String& name)
: m_name(name)
@ -7,6 +8,10 @@ GMenu::GMenu(const String& name)
GMenu::~GMenu()
{
if (m_menu_id) {
gui_menu_destroy(m_menu_id);
m_menu_id = 0;
}
}
void GMenu::add_item(unsigned identifier, const String& text)
@ -18,3 +23,16 @@ void GMenu::add_separator()
{
m_items.append(GMenuItem(GMenuItem::Separator));
}
int GMenu::realize_menu()
{
m_menu_id = gui_menu_create(m_name.characters());
ASSERT(m_menu_id > 0);
for (auto& item : m_items) {
if (item.type() == GMenuItem::Separator)
gui_menu_add_separator(m_menu_id);
else if (item.type() == GMenuItem::Text)
gui_menu_add_item(m_menu_id, item.identifier(), item.text().characters());
}
return m_menu_id;
}