summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GMenu.h
blob: f873c92defcc5ca9ba064c18d947b4940cc01eaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <AK/Function.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/NonnullRefPtr.h>
#include <LibGUI/GMenuItem.h>

class GAction;
class Point;

class GMenu {
public:
    explicit GMenu(const StringView& name);
    ~GMenu();

    static GMenu* from_menu_id(int);

    const String& name() const { return m_name; }

    GAction* action_at(int);

    void add_action(NonnullRefPtr<GAction>);
    void add_separator();
    void add_submenu(NonnullOwnPtr<GMenu>);

    void popup(const Point& screen_position);
    void dismiss();

    Function<void(unsigned)> on_item_activation;

private:
    friend class GMenuBar;

    int menu_id() const { return m_menu_id; }
    int realize_menu();
    void unrealize_menu();
    void realize_if_needed();

    int m_menu_id { -1 };
    String m_name;
    NonnullOwnPtrVector<GMenuItem> m_items;
};