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