mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 16:35:06 +00:00
LibGUI: Put all classes in the GUI namespace and remove the leading G
This took me a moment. Welcome to the new world of GUI::Widget! :^)
This commit is contained in:
parent
2d39da5405
commit
c5bd9d4ed1
337 changed files with 5400 additions and 4816 deletions
|
@ -30,17 +30,19 @@
|
|||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GWindowServerConnection.h>
|
||||
|
||||
//#define GMENU_DEBUG
|
||||
//#define MENU_DEBUG
|
||||
|
||||
static HashMap<int, GMenu*>& all_menus()
|
||||
namespace GUI {
|
||||
|
||||
static HashMap<int, Menu*>& all_menus()
|
||||
{
|
||||
static HashMap<int, GMenu*>* map;
|
||||
static HashMap<int, Menu*>* map;
|
||||
if (!map)
|
||||
map = new HashMap<int, GMenu*>();
|
||||
map = new HashMap<int, Menu*>();
|
||||
return *map;
|
||||
}
|
||||
|
||||
GMenu* GMenu::from_menu_id(int menu_id)
|
||||
Menu* Menu::from_menu_id(int menu_id)
|
||||
{
|
||||
auto it = all_menus().find(menu_id);
|
||||
if (it == all_menus().end())
|
||||
|
@ -48,76 +50,76 @@ GMenu* GMenu::from_menu_id(int menu_id)
|
|||
return (*it).value;
|
||||
}
|
||||
|
||||
GMenu::GMenu(const StringView& name)
|
||||
Menu::Menu(const StringView& name)
|
||||
: m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
GMenu::~GMenu()
|
||||
Menu::~Menu()
|
||||
{
|
||||
unrealize_menu();
|
||||
}
|
||||
|
||||
void GMenu::add_action(NonnullRefPtr<GAction> action)
|
||||
void Menu::add_action(NonnullRefPtr<Action> action)
|
||||
{
|
||||
m_items.append(make<GMenuItem>(m_menu_id, move(action)));
|
||||
m_items.append(make<MenuItem>(m_menu_id, move(action)));
|
||||
#ifdef GMENU_DEBUG
|
||||
dbgprintf("GMenu::add_action(): MenuItem Menu ID: %d\n", m_menu_id);
|
||||
dbgprintf("GUI::Menu::add_action(): MenuItem Menu ID: %d\n", m_menu_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GMenu::add_submenu(NonnullRefPtr<GMenu> submenu)
|
||||
void Menu::add_submenu(NonnullRefPtr<Menu> submenu)
|
||||
{
|
||||
m_items.append(make<GMenuItem>(m_menu_id, move(submenu)));
|
||||
m_items.append(make<MenuItem>(m_menu_id, move(submenu)));
|
||||
}
|
||||
|
||||
void GMenu::add_separator()
|
||||
void Menu::add_separator()
|
||||
{
|
||||
m_items.append(make<GMenuItem>(m_menu_id, GMenuItem::Separator));
|
||||
m_items.append(make<MenuItem>(m_menu_id, MenuItem::Type::Separator));
|
||||
}
|
||||
|
||||
void GMenu::realize_if_needed()
|
||||
void Menu::realize_if_needed()
|
||||
{
|
||||
if (m_menu_id == -1)
|
||||
realize_menu();
|
||||
}
|
||||
|
||||
void GMenu::popup(const Point& screen_position)
|
||||
void Menu::popup(const Point& screen_position)
|
||||
{
|
||||
realize_if_needed();
|
||||
GWindowServerConnection::the().post_message(WindowServer::PopupMenu(m_menu_id, screen_position));
|
||||
WindowServerConnection::the().post_message(WindowServer::PopupMenu(m_menu_id, screen_position));
|
||||
}
|
||||
|
||||
void GMenu::dismiss()
|
||||
void Menu::dismiss()
|
||||
{
|
||||
if (m_menu_id == -1)
|
||||
return;
|
||||
GWindowServerConnection::the().post_message(WindowServer::DismissMenu(m_menu_id));
|
||||
WindowServerConnection::the().post_message(WindowServer::DismissMenu(m_menu_id));
|
||||
}
|
||||
|
||||
int GMenu::realize_menu()
|
||||
int Menu::realize_menu()
|
||||
{
|
||||
m_menu_id = GWindowServerConnection::the().send_sync<WindowServer::CreateMenu>(m_name)->menu_id();
|
||||
m_menu_id = WindowServerConnection::the().send_sync<WindowServer::CreateMenu>(m_name)->menu_id();
|
||||
|
||||
#ifdef GMENU_DEBUG
|
||||
dbgprintf("GMenu::realize_menu(): New menu ID: %d\n", m_menu_id);
|
||||
#ifdef MENU_DEBUG
|
||||
dbgprintf("GUI::Menu::realize_menu(): New menu ID: %d\n", m_menu_id);
|
||||
#endif
|
||||
ASSERT(m_menu_id > 0);
|
||||
for (int i = 0; i < m_items.size(); ++i) {
|
||||
auto& item = m_items[i];
|
||||
item.set_menu_id({}, m_menu_id);
|
||||
item.set_identifier({}, i);
|
||||
if (item.type() == GMenuItem::Separator) {
|
||||
GWindowServerConnection::the().send_sync<WindowServer::AddMenuSeparator>(m_menu_id);
|
||||
if (item.type() == MenuItem::Type::Separator) {
|
||||
WindowServerConnection::the().send_sync<WindowServer::AddMenuSeparator>(m_menu_id);
|
||||
continue;
|
||||
}
|
||||
if (item.type() == GMenuItem::Submenu) {
|
||||
if (item.type() == MenuItem::Type::Submenu) {
|
||||
auto& submenu = *item.submenu();
|
||||
submenu.realize_if_needed();
|
||||
GWindowServerConnection::the().send_sync<WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, "", -1, false);
|
||||
WindowServerConnection::the().send_sync<WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, "", -1, false);
|
||||
continue;
|
||||
}
|
||||
if (item.type() == GMenuItem::Action) {
|
||||
if (item.type() == MenuItem::Type::Action) {
|
||||
auto& action = *item.action();
|
||||
int icon_buffer_id = -1;
|
||||
if (action.icon()) {
|
||||
|
@ -129,32 +131,34 @@ int GMenu::realize_menu()
|
|||
auto shared_icon = GraphicsBitmap::create_with_shared_buffer(GraphicsBitmap::Format::RGBA32, *shared_buffer, action.icon()->size());
|
||||
memcpy(shared_buffer->data(), action.icon()->bits(0), action.icon()->size_in_bytes());
|
||||
shared_buffer->seal();
|
||||
shared_buffer->share_with(GWindowServerConnection::the().server_pid());
|
||||
shared_buffer->share_with(WindowServerConnection::the().server_pid());
|
||||
action.set_icon(shared_icon);
|
||||
}
|
||||
icon_buffer_id = action.icon()->shared_buffer_id();
|
||||
}
|
||||
auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String();
|
||||
bool exclusive = action.group() && action.group()->is_exclusive() && action.is_checkable();
|
||||
GWindowServerConnection::the().send_sync<WindowServer::AddMenuItem>(m_menu_id, i, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, shortcut_text, icon_buffer_id, exclusive);
|
||||
WindowServerConnection::the().send_sync<WindowServer::AddMenuItem>(m_menu_id, i, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, shortcut_text, icon_buffer_id, exclusive);
|
||||
}
|
||||
}
|
||||
all_menus().set(m_menu_id, this);
|
||||
return m_menu_id;
|
||||
}
|
||||
|
||||
void GMenu::unrealize_menu()
|
||||
void Menu::unrealize_menu()
|
||||
{
|
||||
if (m_menu_id == -1)
|
||||
return;
|
||||
all_menus().remove(m_menu_id);
|
||||
GWindowServerConnection::the().send_sync<WindowServer::DestroyMenu>(m_menu_id);
|
||||
WindowServerConnection::the().send_sync<WindowServer::DestroyMenu>(m_menu_id);
|
||||
m_menu_id = 0;
|
||||
}
|
||||
|
||||
GAction* GMenu::action_at(int index)
|
||||
Action* Menu::action_at(int index)
|
||||
{
|
||||
if (index >= m_items.size())
|
||||
return nullptr;
|
||||
return m_items[index].action();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue