diff options
Diffstat (limited to 'src/FbTk/BoolMenuItem.hh')
-rw-r--r-- | src/FbTk/BoolMenuItem.hh | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/FbTk/BoolMenuItem.hh b/src/FbTk/BoolMenuItem.hh new file mode 100644 index 0000000..2e8b2c3 --- /dev/null +++ b/src/FbTk/BoolMenuItem.hh | |||
@@ -0,0 +1,62 @@ | |||
1 | // BoolMenuItem.hh for FbTk | ||
2 | // Copyright (c) 2003 - 2007 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | #ifndef FBTK_BOOLMENUITEM_HH | ||
23 | #define FBTK_BOOLMENUITEM_HH | ||
24 | |||
25 | #include "MenuItem.hh" | ||
26 | #include "Accessor.hh" | ||
27 | |||
28 | namespace FbTk { | ||
29 | |||
30 | /// a bool menu item | ||
31 | class BoolMenuItem: public FbTk::MenuItem { | ||
32 | public: | ||
33 | BoolMenuItem(const FbTk::FbString &label, Accessor<bool> &item, | ||
34 | FbTk::RefCount<FbTk::Command> &cmd): | ||
35 | FbTk::MenuItem(label, cmd), m_item(item) { | ||
36 | FbTk::MenuItem::setSelected(m_item); | ||
37 | setToggleItem(true); | ||
38 | setCloseOnClick(false); | ||
39 | } | ||
40 | BoolMenuItem(const FbTk::FbString &label, Accessor<bool> &item): | ||
41 | FbTk::MenuItem(label), m_item(item) { | ||
42 | FbTk::MenuItem::setSelected(m_item); | ||
43 | setToggleItem(true); | ||
44 | setCloseOnClick(false); | ||
45 | } | ||
46 | bool isSelected() const { return m_item; } | ||
47 | // toggle state | ||
48 | void click(int button, int time, unsigned int mods) { | ||
49 | setSelected(!m_item); | ||
50 | FbTk::MenuItem::click(button, time, mods); | ||
51 | } | ||
52 | void setSelected(bool value) { | ||
53 | m_item = value; | ||
54 | FbTk::MenuItem::setSelected(m_item); | ||
55 | } | ||
56 | private: | ||
57 | Accessor<bool> &m_item; | ||
58 | }; | ||
59 | |||
60 | }; // end namespace FbTk | ||
61 | |||
62 | #endif // FBTK_BOOLMENUITEM_HH | ||