mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 03:09:08 +00:00
Add API's and plumbing for WindowServer clients to make menus.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user