1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

WindowServer+LibGUI: Add support for nested menus

It's now possible to add a GMenu as a submenu of another GMenu.
Simply use the GMenu::add_submenu(NonnullOwnPtr<GMenu>) API :^)

The WindowServer now keeps track of a stack of open menus rather than
just one "current menu". This code needs a bit more work, but the basic
functionality is now here!
This commit is contained in:
Andreas Kling 2019-08-28 21:11:53 +02:00
parent d3ebd8897f
commit 63e6b09816
16 changed files with 177 additions and 12 deletions

View file

@ -2,6 +2,8 @@
#include <AK/AKString.h>
#include <AK/Badge.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
class GAction;
class GMenu;
@ -11,11 +13,13 @@ public:
enum Type {
Invalid,
Action,
Separator
Separator,
Submenu,
};
GMenuItem(unsigned menu_id, Type);
GMenuItem(unsigned menu_id, NonnullRefPtr<GAction>&&);
GMenuItem(unsigned menu_id, NonnullOwnPtr<GMenu>&&);
~GMenuItem();
Type type() const { return m_type; }
@ -24,6 +28,9 @@ public:
GAction* action() { return m_action.ptr(); }
unsigned identifier() const { return m_identifier; }
GMenu* submenu() { return m_submenu.ptr(); }
const GMenu* submenu() const { return m_submenu.ptr(); }
bool is_checkable() const { return m_checkable; }
void set_checkable(bool checkable) { m_checkable = checkable; }
@ -46,4 +53,5 @@ private:
bool m_checkable { false };
bool m_checked { false };
RefPtr<GAction> m_action;
OwnPtr<GMenu> m_submenu;
};