mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:47:34 +00:00
Add API's and plumbing for WindowServer clients to make menus.
This commit is contained in:
parent
bb31d961b4
commit
133706d697
17 changed files with 322 additions and 24 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@ public:
|
|||
void add_separator();
|
||||
|
||||
private:
|
||||
friend class GMenuBar;
|
||||
int menu_id() const { return m_menu_id; }
|
||||
int realize_menu();
|
||||
|
||||
int m_menu_id { 0 };
|
||||
String m_name;
|
||||
Vector<GMenuItem> m_items;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <LibGUI/GMenuBar.h>
|
||||
#include <LibC/gui.h>
|
||||
|
||||
GMenuBar::GMenuBar()
|
||||
{
|
||||
|
@ -15,8 +16,22 @@ void GMenuBar::add_menu(OwnPtr<GMenu>&& menu)
|
|||
|
||||
void GMenuBar::notify_added_to_application(Badge<GApplication>)
|
||||
{
|
||||
ASSERT(!m_menubar_id);
|
||||
m_menubar_id = gui_menubar_create();
|
||||
ASSERT(m_menubar_id > 0);
|
||||
for (auto& menu : m_menus) {
|
||||
ASSERT(menu);
|
||||
int menu_id = menu->realize_menu();
|
||||
ASSERT(menu_id > 0);
|
||||
int rc = gui_menubar_add_menu(m_menubar_id, menu_id);
|
||||
ASSERT(rc == 0);
|
||||
}
|
||||
gui_app_set_menubar(m_menubar_id);
|
||||
}
|
||||
|
||||
void GMenuBar::notify_removed_from_application(Badge<GApplication>)
|
||||
{
|
||||
ASSERT(m_menubar_id);
|
||||
gui_menubar_destroy(m_menubar_id);
|
||||
m_menubar_id = 0;
|
||||
}
|
||||
|
|
|
@ -18,5 +18,6 @@ public:
|
|||
void notify_removed_from_application(Badge<GApplication>);
|
||||
|
||||
private:
|
||||
int m_menubar_id { 0 };
|
||||
Vector<OwnPtr<GMenu>> m_menus;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue