diff options
Diffstat (limited to 'src/FbTk/MenuItem.hh')
-rw-r--r-- | src/FbTk/MenuItem.hh | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh new file mode 100644 index 0000000..4dcecc7 --- /dev/null +++ b/src/FbTk/MenuItem.hh | |||
@@ -0,0 +1,95 @@ | |||
1 | // MenuItem.hh for FbTk - Fluxbox Toolkit | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
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 | // $Id: MenuItem.hh,v 1.2 2003/02/17 12:28:06 fluxgen Exp $ | ||
23 | |||
24 | #ifndef FBTK_MENUITEM_HH | ||
25 | #define FBTK_MENUITEM_HH | ||
26 | |||
27 | #include "RefCount.hh" | ||
28 | #include "Command.hh" | ||
29 | #include <string> | ||
30 | |||
31 | namespace FbTk { | ||
32 | |||
33 | class Menu; | ||
34 | |||
35 | /// An interface for a menu item in Menu | ||
36 | class MenuItem { | ||
37 | public: | ||
38 | MenuItem( | ||
39 | const char *label) | ||
40 | : m_label(label ? label : ""), | ||
41 | m_submenu(0), | ||
42 | m_enabled(true), | ||
43 | m_selected(false) | ||
44 | { } | ||
45 | /// create a menu item with a specific command to be executed on click | ||
46 | MenuItem(const char *label, RefCount<Command> &cmd): | ||
47 | m_label(label ? label : ""), | ||
48 | m_submenu(0), | ||
49 | m_command(cmd), | ||
50 | m_enabled(true), | ||
51 | m_selected(false) { | ||
52 | |||
53 | } | ||
54 | |||
55 | MenuItem(const char *label, Menu *submenu) | ||
56 | : m_label(label ? label : "") | ||
57 | , m_submenu(submenu) | ||
58 | , m_enabled(true) | ||
59 | , m_selected(false) | ||
60 | { } | ||
61 | virtual ~MenuItem() { } | ||
62 | |||
63 | void setCommand(RefCount<Command> &cmd) { m_command = cmd; } | ||
64 | virtual void setSelected(bool selected) { m_selected = selected; } | ||
65 | virtual void setEnabled(bool enabled) { m_enabled = enabled; } | ||
66 | virtual void setLabel(const char *label) { m_label = (label ? label : ""); } | ||
67 | Menu *submenu() { return m_submenu; } | ||
68 | /** | ||
69 | @name accessors | ||
70 | */ | ||
71 | //@{ | ||
72 | virtual const std::string &label() const { return m_label; } | ||
73 | const Menu *submenu() const { return m_submenu; } | ||
74 | virtual bool isEnabled() const { return m_enabled; } | ||
75 | virtual bool isSelected() const { return m_selected; } | ||
76 | /** | ||
77 | Called when the item was clicked with a specific button | ||
78 | @param button the button number | ||
79 | @param time the time stamp | ||
80 | */ | ||
81 | virtual void click(int button, int time); | ||
82 | RefCount<Command> &command() { return m_command; } | ||
83 | const RefCount<Command> &command() const { return m_command; } | ||
84 | //@} | ||
85 | |||
86 | private: | ||
87 | std::string m_label; ///< label of this item | ||
88 | Menu *m_submenu; ///< a submenu, 0 if we don't have one | ||
89 | RefCount<Command> m_command; ///< command to be executed | ||
90 | bool m_enabled, m_selected; | ||
91 | }; | ||
92 | |||
93 | };// end namespace FbTk | ||
94 | |||
95 | #endif // FBTK_MENUITEM_HH | ||