diff options
Diffstat (limited to 'src/BoolMenuItem.hh')
-rw-r--r-- | src/BoolMenuItem.hh | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/BoolMenuItem.hh b/src/BoolMenuItem.hh index 914185d..29eef15 100644 --- a/src/BoolMenuItem.hh +++ b/src/BoolMenuItem.hh | |||
@@ -38,6 +38,7 @@ public: | |||
38 | BoolMenuItem(const FbTk::FbString &label, bool &item): | 38 | BoolMenuItem(const FbTk::FbString &label, bool &item): |
39 | FbTk::MenuItem(label), m_item(item) { | 39 | FbTk::MenuItem(label), m_item(item) { |
40 | FbTk::MenuItem::setSelected(m_item); | 40 | FbTk::MenuItem::setSelected(m_item); |
41 | setToggleItem(true); | ||
41 | } | 42 | } |
42 | bool isSelected() const { return m_item; } | 43 | bool isSelected() const { return m_item; } |
43 | // toggle state | 44 | // toggle state |
@@ -50,4 +51,30 @@ private: | |||
50 | bool &m_item; | 51 | bool &m_item; |
51 | }; | 52 | }; |
52 | 53 | ||
53 | #endif // BOOLRESMENUITEM_HH | 54 | /// a bool menu item |
55 | template <typename Type> | ||
56 | class BoolResMenuItem: public FbTk::MenuItem { | ||
57 | public: | ||
58 | BoolResMenuItem(const FbTk::FbString &label, Type &res, | ||
59 | FbTk::RefCount<FbTk::Command> &cmd): | ||
60 | FbTk::MenuItem(label, cmd), m_res(res) { | ||
61 | FbTk::MenuItem::setSelected(*m_res); | ||
62 | setToggleItem(true); | ||
63 | } | ||
64 | BoolResMenuItem(const FbTk::FbString &label, Type &res): | ||
65 | FbTk::MenuItem(label), m_res(res) { | ||
66 | FbTk::MenuItem::setSelected(*m_res); | ||
67 | setToggleItem(true); | ||
68 | } | ||
69 | bool isSelected() const { return *m_res; } | ||
70 | // toggle state | ||
71 | void click(int button, int time) { setSelected(!*m_res); FbTk::MenuItem::click(button, time); } | ||
72 | void setSelected(bool value) { | ||
73 | m_res = value; | ||
74 | FbTk::MenuItem::setSelected(*m_res); | ||
75 | } | ||
76 | private: | ||
77 | Type &m_res; | ||
78 | }; | ||
79 | |||
80 | #endif // BOOLMENUITEM_HH | ||