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

LibGUI: Make GMenu inherit from CObject

This is primarily to make it possible to pass a GMenu* where a CObject*
is expected.
This commit is contained in:
Andreas Kling 2019-12-09 21:05:28 +01:00
parent e9dda8d592
commit fd5eb79d19
39 changed files with 88 additions and 86 deletions

View file

@ -39,7 +39,7 @@ void GMenu::add_action(NonnullRefPtr<GAction> action)
#endif
}
void GMenu::add_submenu(NonnullOwnPtr<GMenu> submenu)
void GMenu::add_submenu(NonnullRefPtr<GMenu> submenu)
{
m_items.append(make<GMenuItem>(m_menu_id, move(submenu)));
}

View file

@ -3,15 +3,17 @@
#include <AK/Function.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/NonnullRefPtr.h>
#include <LibCore/CObject.h>
#include <LibGUI/GMenuItem.h>
class GAction;
class Point;
class GMenu {
class GMenu final : public CObject {
C_OBJECT(GMenu)
public:
explicit GMenu(const StringView& name = "");
~GMenu();
virtual ~GMenu() override;
static GMenu* from_menu_id(int);
@ -21,7 +23,7 @@ public:
void add_action(NonnullRefPtr<GAction>);
void add_separator();
void add_submenu(NonnullOwnPtr<GMenu>);
void add_submenu(NonnullRefPtr<GMenu>);
void popup(const Point& screen_position);
void dismiss();

View file

@ -10,7 +10,7 @@ GMenuBar::~GMenuBar()
unrealize_menubar();
}
void GMenuBar::add_menu(NonnullOwnPtr<GMenu>&& menu)
void GMenuBar::add_menu(NonnullRefPtr<GMenu> menu)
{
m_menus.append(move(menu));
}

View file

@ -11,7 +11,7 @@ public:
GMenuBar();
~GMenuBar();
void add_menu(NonnullOwnPtr<GMenu>&&);
void add_menu(NonnullRefPtr<GMenu>);
void notify_added_to_application(Badge<GApplication>);
void notify_removed_from_application(Badge<GApplication>);
@ -21,5 +21,5 @@ private:
void unrealize_menubar();
int m_menubar_id { -1 };
NonnullOwnPtrVector<GMenu> m_menus;
NonnullRefPtrVector<GMenu> m_menus;
};

View file

@ -21,7 +21,7 @@ GMenuItem::GMenuItem(unsigned menu_id, NonnullRefPtr<GAction>&& action)
m_checked = m_action->is_checked();
}
GMenuItem::GMenuItem(unsigned menu_id, NonnullOwnPtr<GMenu>&& submenu)
GMenuItem::GMenuItem(unsigned menu_id, NonnullRefPtr<GMenu>&& submenu)
: m_type(Submenu)
, m_menu_id(menu_id)
, m_submenu(move(submenu))

View file

@ -19,7 +19,7 @@ public:
GMenuItem(unsigned menu_id, Type);
GMenuItem(unsigned menu_id, NonnullRefPtr<GAction>&&);
GMenuItem(unsigned menu_id, NonnullOwnPtr<GMenu>&&);
GMenuItem(unsigned menu_id, NonnullRefPtr<GMenu>&&);
~GMenuItem();
Type type() const { return m_type; }
@ -53,5 +53,5 @@ private:
bool m_checkable { false };
bool m_checked { false };
RefPtr<GAction> m_action;
OwnPtr<GMenu> m_submenu;
RefPtr<GMenu> m_submenu;
};

View file

@ -550,7 +550,7 @@ GMenu& GTableView::ensure_header_context_menu()
// or if the column count/names change.
if (!m_header_context_menu) {
ASSERT(model());
m_header_context_menu = make<GMenu>();
m_header_context_menu = GMenu::construct();
for (int column = 0; column < model()->column_count(); ++column) {
auto& column_data = this->column_data(column);

View file

@ -98,5 +98,5 @@ protected:
int m_hovered_column_header_index { -1 };
GMenu& ensure_header_context_menu();
OwnPtr<GMenu> m_header_context_menu;
RefPtr<GMenu> m_header_context_menu;
};

View file

@ -1180,7 +1180,7 @@ void GTextEditor::did_update_selection()
void GTextEditor::context_menu_event(GContextMenuEvent& event)
{
if (!m_context_menu) {
m_context_menu = make<GMenu>();
m_context_menu = GMenu::construct();
m_context_menu->add_action(undo_action());
m_context_menu->add_action(redo_action());
m_context_menu->add_separator();

View file

@ -196,7 +196,7 @@ private:
size_t m_soft_tab_width { 4 };
int m_horizontal_content_padding { 2 };
GTextRange m_selection;
OwnPtr<GMenu> m_context_menu;
RefPtr<GMenu> m_context_menu;
RefPtr<GAction> m_undo_action;
RefPtr<GAction> m_redo_action;
RefPtr<GAction> m_cut_action;