summaryrefslogtreecommitdiff
path: root/src/gui_menu.hh
blob: a6c6b54a422638f0d37dc29fd4b31ce5db63de97 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// -*- mode: c++; c-basic-offset: 2; -*-

#ifndef GUI_MENU_HH
#define GUI_MENU_HH

#include <string>

class GuiMenu {
public:
  class Listener {
  public:
    virtual ~Listener() {}

    virtual void item_activated(std::string const& id) = 0;

  protected:
    Listener() {}
  };

  static const uint32_t CTRL;
  static const uint32_t ALT;
  static const uint32_t SHIFT;
  static const uint32_t META;

  static const char ESC;
  static const char UP;
  static const char LEFT;
  static const char RIGHT;
  static const char DOWN;
  static const char RETURN;

  struct Shortcut {
    uint32_t const mask;
    char const key;
    bool const function;

    Shortcut()
      : mask(0), key(0), function(false) {
    }
    Shortcut(uint32_t mask, char key)
      : mask(mask), key(key), function(false) {
    }
    Shortcut(uint32_t mask, int function)
      : mask(mask), key(function), function(true) {
    }
  };

  virtual ~GuiMenu() {}

  static GuiMenu* create();

  virtual void add_item(std::string const& id, std::string const& label,
                        Shortcut const& shortcut = Shortcut()) = 0;
  // The returned menu lives as long as the root-menu, do not free
  // the pointer yourself
  virtual GuiMenu* add_menu(std::string const& label) = 0;
  virtual void add_separator() = 0;

  // Call to enable/disable menu item, searches sub menues if no such
  // item is found in this menu. Returns true if an item was found.
  virtual bool enable_item(std::string const& id, bool enable = true) = 0;

  virtual void add_listener(Listener* listener) = 0;
  virtual void remove_listener(Listener* listener) = 0;

protected:
  GuiMenu() {}
  GuiMenu(GuiMenu const&) = delete;
};

#endif  // GUI_MENU_HH