libyui-ncurses  2.57.2
NCMenuBar.h
1 /*
2  Copyright (C) 2020 SUSE LLC
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCMenuBar.h
20 
21  Author: Jose Iván López <jlopez@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef NCMenuBar_h
27 #define NCMenuBar_h
28 
29 #include <yui/YMenuBar.h>
30 #include "NCWidget.h"
31 #include "CyclicContainer.h"
32 
33 class NCMenuBar: public YMenuBar, public NCWidget
34 {
35 public:
36  /**
37  * Constructor.
38  **/
39  NCMenuBar( YWidget * parent );
40 
41  /**
42  * Destructor.
43  **/
44  virtual ~NCMenuBar();
45 
46  /**
47  * Rebuild the displayed menu tree from the internally stored YMenuItems.
48  *
49  * Implemented from YMenuWidget.
50  **/
51  virtual void rebuildMenuTree();
52 
53  /**
54  * Enable or disable an item.
55  *
56  * Reimplemented from YMenuWidget.
57  **/
58  virtual void setItemEnabled( YMenuItem * item, bool enabled );
59 
60  /**
61  * show or hide an item.
62  *
63  * Reimplemented from YMenuWidget.
64  **/
65  virtual void setItemVisible( YMenuItem * item, bool visible );
66 
67  /**
68  * Support for the Rest API for UI testing:
69  *
70  * Activate the item selected in the tree.
71  * This can be used in tests to simulate user input.
72  *
73  * Implemented from YMenuWidget.
74  **/
75  virtual void activateItem( YMenuItem * item );
76 
77  /**
78  * Handle keyboard input.
79  * Reimplemented from NCWidget.
80  **/
81  virtual NCursesEvent wHandleInput( wint_t key );
82 
83  /**
84  * Return the preferred width for this widget.
85  * Reimplemented from YWidget.
86  **/
87  virtual int preferredWidth();
88 
89  /**
90  * Return the preferred height for this widget.
91  * Reimplemented from YWidget.
92  **/
93  virtual int preferredHeight();
94 
95  /**
96  * Set the size of this widget.
97  * Reimplemented from YWidget.
98  **/
99  virtual void setSize( int newWidth, int newHeight );
100 
101  /**
102  * Enable or disable this widget.
103  * Reimplemented from YWidget.
104  **/
105  virtual void setEnabled( bool enabled );
106 
107  /**
108  * Set the keyboard focus to this widget.
109  * Reimplemented from YWidget.
110  **/
111  virtual bool setKeyboardFocus();
112 
113  /**
114  * Handle keyboard input.
115  * Reimplemented from NCWidget.
116  **/
117  virtual NCursesEvent wHandleHotkey( wint_t key );
118 
119  /**
120  * Whether any menu option has the given hot-key .
121  * Reimplemented from NCWidget.
122  **/
123  virtual bool HasHotkey( int key ) ;
124 
125  /**
126  * Notification that some shortcut was changed.
127  *
128  * Reimplemented from YSelectionWidget.
129  **/
130  virtual void shortcutChanged();
131 
132 protected:
133 
134  /**
135  * Clear all content.
136  **/
137  void clear();
138 
139  virtual const char * location() const { return "NCMenuBar"; }
140 
141  /**
142  * Reimplemented from NCWidget.
143  **/
144  virtual void wRedraw();
145 
146  /**
147  * Open a menu dialog
148  * @return event from the menu dialog
149  **/
151 
152 private:
153 
154  struct Menu;
155 
156  friend std::ostream & operator<<( std::ostream & str,
157  const NCMenuBar & obj );
158 
159  // Disable assignment operator and copy constructor
160 
161  NCMenuBar & operator=( const NCMenuBar & );
162  NCMenuBar( const NCMenuBar & );
163 
164  /** Helper method to manage the menu dialog event
165  * @param event event from the menu dialog
166  * @return a new event
167  **/
168  NCursesEvent handlePostMenu( const NCursesEvent & event );
169 
170  /** Currently selected menu.
171  * @return selected menu
172  **/
173  Menu * selectedMenu();
174 
175  /** Select the next enabled menu option.
176  * @note When there is no selected menu, the first enabled one is selected.
177  **/
178  void selectNextMenu();
179 
180  /** Select the previous enabled menu.
181  * @note When there is no selected menu, the last enabled one is selected.
182  **/
183  void selectPreviousMenu();
184 
185  /** Find the menu with the given hot-key.
186  * @param key a hot-key
187  * @return the menu with the given hot-key.
188  **/
189  CyclicContainer<Menu>::Iterator findMenuWithHotkey( wint_t key );
190 
191  /** Style to apply to the given menu
192  * The style depends on the status of the menu (enabled or disabled).
193  * @param menu a menu
194  * @return style to apply
195  **/
196  const NCstyle::StWidget & menuStyle( const Menu * menu );
197 
198  /** Container of menus
199  * It allows cyclic navigation between the menus.
200  * Note that this container holds pointers to menus, but it does not own the pointers. The pointers
201  * are owned by the NCMenuBar object.
202  **/
203  CyclicContainer<Menu> _menus;
204 
205 }; // NCMenuBar
206 
207 #endif // NCMenuBar_h
NCMenuBar::setItemVisible
virtual void setItemVisible(YMenuItem *item, bool visible)
show or hide an item.
Definition: NCMenuBar.cc:196
NCMenuBar::clear
void clear()
Clear all content.
Definition: NCMenuBar.cc:88
NCMenuBar::setEnabled
virtual void setEnabled(bool enabled)
Enable or disable this widget.
Definition: NCMenuBar.cc:277
NCMenuBar::preferredHeight
virtual int preferredHeight()
Return the preferred height for this widget.
Definition: NCMenuBar.cc:263
NCMenuBar::rebuildMenuTree
virtual void rebuildMenuTree()
Rebuild the displayed menu tree from the internally stored YMenuItems.
Definition: NCMenuBar.cc:100
NCMenuBar::wHandleHotkey
virtual NCursesEvent wHandleHotkey(wint_t key)
Handle keyboard input.
Definition: NCMenuBar.cc:305
NCMenuBar
Definition: NCMenuBar.h:34
NCWidget
Definition: NCWidget.h:46
NCMenuBar::Menu
Definition: NCMenuBar.cc:44
NCMenuBar::postMenu
NCursesEvent postMenu()
Open a menu dialog.
Definition: NCMenuBar.cc:165
NCstyle::StWidget
Definition: NCstyle.h:358
NCMenuBar::NCMenuBar
NCMenuBar(YWidget *parent)
Constructor.
Definition: NCMenuBar.cc:74
NCMenuBar::setSize
virtual void setSize(int newWidth, int newHeight)
Set the size of this widget.
Definition: NCMenuBar.cc:270
NCMenuBar::HasHotkey
virtual bool HasHotkey(int key)
Whether any menu option has the given hot-key .
Definition: NCMenuBar.cc:295
NCMenuBar::shortcutChanged
virtual void shortcutChanged()
Notification that some shortcut was changed.
Definition: NCMenuBar.cc:320
NCMenuBar::wHandleInput
virtual NCursesEvent wHandleInput(wint_t key)
Handle keyboard input.
Definition: NCMenuBar.cc:220
NCMenuBar::activateItem
virtual void activateItem(YMenuItem *item)
Support for the Rest API for UI testing:
Definition: NCMenuBar.cc:205
NCMenuBar::preferredWidth
virtual int preferredWidth()
Return the preferred width for this widget.
Definition: NCMenuBar.cc:256
NCMenuBar::setItemEnabled
virtual void setItemEnabled(YMenuItem *item, bool enabled)
Enable or disable an item.
Definition: NCMenuBar.cc:187
NCMenuBar::setKeyboardFocus
virtual bool setKeyboardFocus()
Set the keyboard focus to this widget.
Definition: NCMenuBar.cc:285
NCursesEvent
Definition: NCurses.h:73
NCMenuBar::~NCMenuBar
virtual ~NCMenuBar()
Destructor.
Definition: NCMenuBar.cc:81
NCMenuBar::wRedraw
virtual void wRedraw()
Reimplemented from NCWidget.
Definition: NCMenuBar.cc:137
CyclicContainer
Container class that allows cyclic navigation between its elements by moving to the next/previous ele...
Definition: CyclicContainer.h:40