libyui-mga  1.1.0
YMGAMenuItem.h
1 /*
2  Copyright 2020 by Angelo Naselli <anaselli at linux dot it>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as
6  published by the Free Software Foundation; either version 2.1 of the
7  License, or (at your option) version 3.0 of the License. This library
8  is distributed in the hope that it will be useful, but WITHOUT ANY
9  WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11  License for more details. You should have received a copy of the GNU
12  Lesser General Public License along with this library; if not, write
13  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14  Floor, Boston, MA 02110-1301 USA
15 */
16 
17 /*-/
18 
19  File: YMGAMenuItem.h
20 
21  Author: Angelo Naselli <anaselli@linux.it>
22 
23 /-*/
24 
25 #ifndef YMGAMenuItem_h
26 #define YMGAMenuItem_h
27 
28 #include <yui/YMenuItem.h>
29 
30 
31 
32 /**
33  * New Menu Item class for menu items.
34  **/
35 class YMGAMenuItem: public YMenuItem
36 {
37 public:
38  /**
39  * Constructors for toplevel items.
40  **/
41  YMGAMenuItem( const std::string & label )
42  : YMenuItem( label ), _enabled(true), _hidden(false)
43  {}
44 
45  /**
46  * Constructor with label and icon. Note that Icon makes sense
47  * for menu actions not for menu and submenu names.
48  * iconName could be an icon name taken from fredesktop Standard Icon Names
49  * or icon pathname full or relative. Theme names if exist, win.
50  **/
51  YMGAMenuItem( const std::string & label,
52  const std::string & iconName )
53  : YMenuItem( label, iconName ), _enabled(true), _hidden(false)
54  {}
55 
56  /**
57  * Constructors for items that have a parent item.
58  *
59  * They will automatically register this item with the parent item. The
60  * parent assumes ownership of this item and will delete it in its (the
61  * parent's) destructor.
62  **/
64  const std::string & label )
65  : YMenuItem( parent, label ), _enabled(true), _hidden(false)
66  {}
67 
69  const std::string & label,
70  const std::string & iconName )
71  : YMenuItem( parent, label, iconName ), _enabled(true), _hidden(false)
72  {}
73 
74 
75  /**
76  * Destructor.
77  *
78  * This will delete all children.
79  **/
80  virtual ~YMGAMenuItem() {}
81 
82  /**
83  * is Menu item enabled?
84  */
85  virtual bool enabled() {
86  return _enabled;
87  }
88 
89  /**
90  * enable/disable Menu Item
91  */
92  virtual void enable(bool en=true) {
93  _enabled=en;
94  }
95 
96  /**
97  * is Menu item hidden?
98  */
99  virtual bool hidden() {
100  return _hidden;
101  }
102 
103  /**
104  * hide/show Menu Item
105  */
106  virtual void hide(bool invisibile=true) {
107  _hidden=invisibile;
108  }
109 
110  /**
111  * Returns this item's parent item or 0 if it is a toplevel item.
112  **/
114  {
115  return dynamic_cast<YMGAMenuItem *> ( YMenuItem::parent() );
116  }
117 
118 
119 private:
120  YMGAMenuItem( const YMGAMenuItem & item );
121 
122  bool _enabled;
123  bool _hidden;
124 };
125 
126 /**
127  * YMenuSeparator class for menu separator.
128  **/
130 {
131 public:
132  /**
133  * Constructor. A menu separator must have a partent
134  * Note that hidden and enable properties are not managed for separator by now,
135  * considering this a bit out of libyui aim.
136  **/
138  : YMGAMenuItem( parent, "" )
139  {}
140 
141 
142 private:
143  YMenuSeparator( const std::string & label,
144  const std::string & iconName );
145 
146  YMenuSeparator( const std::string & label );
147 
149  const std::string & label,
150  const std::string & iconName );
151 
152  // A Menu separator cannot have children
153  virtual void addChild( YItem * ) {YUI_THROW( YUIException("Menu separotor cannot have children") );};
154 };
155 
156 #endif // YMGAMenuItem_h
YMGAMenuItem::enabled
virtual bool enabled()
is Menu item enabled?
Definition: YMGAMenuItem.h:85
YMGAMenuItem::~YMGAMenuItem
virtual ~YMGAMenuItem()
Destructor.
Definition: YMGAMenuItem.h:80
YMGAMenuItem::YMGAMenuItem
YMGAMenuItem(const std::string &label, const std::string &iconName)
Constructor with label and icon.
Definition: YMGAMenuItem.h:51
YMGAMenuItem::YMGAMenuItem
YMGAMenuItem(const std::string &label)
Constructors for toplevel items.
Definition: YMGAMenuItem.h:41
YMGAMenuItem::hidden
virtual bool hidden()
is Menu item hidden?
Definition: YMGAMenuItem.h:99
YMenuSeparator::YMenuSeparator
YMenuSeparator(YMGAMenuItem *parent)
Constructor.
Definition: YMGAMenuItem.h:137
YMGAMenuItem::hide
virtual void hide(bool invisibile=true)
hide/show Menu Item
Definition: YMGAMenuItem.h:106
YMGAMenuItem::parent
YMGAMenuItem * parent() const
Returns this item's parent item or 0 if it is a toplevel item.
Definition: YMGAMenuItem.h:113
YMGAMenuItem::enable
virtual void enable(bool en=true)
enable/disable Menu Item
Definition: YMGAMenuItem.h:92
YMGAMenuItem
New Menu Item class for menu items.
Definition: YMGAMenuItem.h:36
YMenuSeparator
YMenuSeparator class for menu separator.
Definition: YMGAMenuItem.h:130
YMGAMenuItem::YMGAMenuItem
YMGAMenuItem(YMGAMenuItem *parent, const std::string &label)
Constructors for items that have a parent item.
Definition: YMGAMenuItem.h:63