diff options
author | fluxgen <fluxgen> | 2003-01-12 17:06:07 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-01-12 17:06:07 (GMT) |
commit | 99692be7062dab68efe45c5377981f3df9f90392 (patch) | |
tree | 831700b4d34c7090ec041bd704ca56da8a6fb64a /src | |
parent | 5dabdacd6f60fee4877e86caf2875087de86bb38 (diff) | |
download | fluxbox_lack-99692be7062dab68efe45c5377981f3df9f90392.zip fluxbox_lack-99692be7062dab68efe45c5377981f3df9f90392.tar.bz2 |
item in the menu
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/MenuItem.cc | 34 | ||||
-rw-r--r-- | src/FbTk/MenuItem.hh | 94 |
2 files changed, 128 insertions, 0 deletions
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc new file mode 100644 index 0000000..0dbdc69 --- /dev/null +++ b/src/FbTk/MenuItem.cc | |||
@@ -0,0 +1,34 @@ | |||
1 | // MenuItem.cc 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.cc,v 1.1 2003/01/12 17:06:07 fluxgen Exp $ | ||
23 | |||
24 | #include "MenuItem.hh" | ||
25 | #include "Command.hh" | ||
26 | |||
27 | namespace FbTk { | ||
28 | |||
29 | void MenuItem::click(int button, int time) { | ||
30 | if (m_command.get() != 0) | ||
31 | m_command->execute(); | ||
32 | } | ||
33 | |||
34 | }; // end namespace FbTk | ||
diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh new file mode 100644 index 0000000..134c8a3 --- /dev/null +++ b/src/FbTk/MenuItem.hh | |||
@@ -0,0 +1,94 @@ | |||
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.1 2003/01/12 17:06:07 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 | virtual void setSelected(bool selected) { m_selected = selected; } | ||
64 | virtual void setEnabled(bool enabled) { m_enabled = enabled; } | ||
65 | virtual void setLabel(const char *label) { m_label = (label ? label : ""); } | ||
66 | Menu *submenu() { return m_submenu; } | ||
67 | /** | ||
68 | @name accessors | ||
69 | */ | ||
70 | //@{ | ||
71 | virtual const std::string &label() const { return m_label; } | ||
72 | const Menu *submenu() const { return m_submenu; } | ||
73 | virtual bool isEnabled() const { return m_enabled; } | ||
74 | virtual bool isSelected() const { return m_selected; } | ||
75 | /** | ||
76 | Called when the item was clicked with a specific button | ||
77 | @param button the button number | ||
78 | @param time the time stamp | ||
79 | */ | ||
80 | virtual void click(int button, int time); | ||
81 | RefCount<Command> &command() { return m_command; } | ||
82 | const RefCount<Command> &command() const { return m_command; } | ||
83 | //@} | ||
84 | |||
85 | private: | ||
86 | std::string m_label; ///< label of this item | ||
87 | Menu *m_submenu; ///< a submenu, 0 if we don't have one | ||
88 | RefCount<Command> m_command; ///< command to be executed | ||
89 | bool m_enabled, m_selected; | ||
90 | }; | ||
91 | |||
92 | };// end namespace FbTk | ||
93 | |||
94 | #endif // FBTK_MENUITEM_HH | ||