libyui-mga-ncurses  1.1.0
YMGANCMenuBar.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: YMGANMenuBar.h
20 
21  Author: Angelo Naselli <anaselli@linux.it>
22 
23 /-*/
24 
25 #ifndef YMGANMenuBar_h
26 #define YMGANMenuBar_h
27 
28 #include <yui/mga/YMGAMenuBar.h>
29 #include <yui/ncurses/NCWidget.h>
30 #include <yui/YUI.h>
31 #include <yui/YApplication.h>
32 
33 class YMGANCMenuBar : public YMGAMenuBar, public NCWidget
34 {
35 private:
36 
37  friend std::ostream & operator<<( std::ostream & str, const YMGANCMenuBar & obj );
38 
39  YMGANCMenuBar & operator=( const YMGANCMenuBar & );
40  YMGANCMenuBar( const YMGANCMenuBar & );
41 
42  bool haveUtf8() { return YUI::app()->hasFullUtf8Support(); }
43 
44 protected:
45 
46  virtual const char * location() const { return "YMGANCMenuBar"; }
47 
48  virtual void wRedraw();
49 
50  NCursesEvent postMenu();
51 
52 public:
53 
54  YMGANCMenuBar( YWidget * parent );
55  virtual ~YMGANCMenuBar();
56 
57  virtual int preferredWidth();
58  virtual int preferredHeight();
59 
60  virtual void setSize( int newWidth, int newHeight );
61 
62  virtual NCursesEvent wHandleHotkey( wint_t key );
63  virtual NCursesEvent wHandleInput( wint_t key );
64 
65  virtual bool setKeyboardFocus()
66  {
67  if ( !grabFocus() )
68  return YWidget::setKeyboardFocus();
69 
70  return true;
71  }
72 
73  virtual void setEnabled( bool do_bv );
74 
75  /**
76  * Add an YMenuItem first item represents the menu name, other sub items menu entries
77  *
78  * Reimplemented from YSelectionWidget.
79  **/
80  virtual void addItem( YItem * item );
81 
82  /**
83  * Add multiple items. For some UIs, this can be more efficient than
84  * calling addItem() multiple times.
85  *
86  * Reimplemented from YSelectionWidget.
87  **/
88  virtual void addItems( const YItemCollection & itemCollection );
89 
90  /**
91  * Reimplemnted to check all the hotkeys from YMenuItems
92  *
93  */
94  virtual bool HasHotkey(int key) ;
95 
96  /**
97  * Enable YMGAMenuItem (menu name or menu entry) to enable/disable it into menubar or menu
98  *
99  * Reimplemented from YMGAMenuBar.
100  **/
101  virtual void enableItem(YItem * menu_item, bool enable=true);
102 
103  /**
104  * Hide YMGAMenuItem (menu name or menu entry) to hide/show it into menubar or menu
105  *
106  * Reimplemented from YMGAMenuBar.
107  **/
108  virtual void hideItem(YItem * menu_item, bool invisible=true);
109 
110  /**
111  * Delete all items.
112  *
113  * Reimplemented from YSelectionWidget
114  **/
115  virtual void deleteAllItems();
116 
117 private:
118  /**
119  * Recursively find the first menu item with the specified index.
120  * Returns 0 if there is no such item.
121  **/
122  YMenuItem * findMenuItem( int index );
123 
124  /**
125  * Recursively find the first menu item with the specified index
126  * from iterator 'begin' to iterator 'end'.
127  *
128  * Returns 0 if there is no such item.
129  **/
130  YMenuItem * findMenuItem( int index, YItemConstIterator begin, YItemConstIterator end );
131 
132  /**
133  * Alias for findMenuItem(). Reimplemented to ensure consistent behaviour
134  * with YSelectionWidget::itemAt().
135  **/
136  YMenuItem * itemAt( int index )
137  { return findMenuItem( index ); }
138 
139 
140  void assignUniqueIndex( YItemIterator begin, YItemIterator end );
141 
142  struct Private;
143  Private *d;
144 };
145 
146 #endif //YMGANMenuBar_h
YMGANCMenuBar::addItem
virtual void addItem(YItem *item)
Add an YMenuItem first item represents the menu name, other sub items menu entries.
Definition: YMGANCMenuBar.cc:244
YMGANCMenuBar::HasHotkey
virtual bool HasHotkey(int key)
Reimplemnted to check all the hotkeys from YMenuItems.
Definition: YMGANCMenuBar.cc:168
YMGANCMenuBar
Definition: YMGANCMenuBar.h:34
YMGANCMenuBar::deleteAllItems
virtual void deleteAllItems()
Delete all items.
Definition: YMGANCMenuBar.cc:473
YMGANCMenuBar::enableItem
virtual void enableItem(YItem *menu_item, bool enable=true)
Enable YMGAMenuItem (menu name or menu entry) to enable/disable it into menubar or menu.
Definition: YMGANCMenuBar.cc:463
YMGANCMenuBar::hideItem
virtual void hideItem(YItem *menu_item, bool invisible=true)
Hide YMGAMenuItem (menu name or menu entry) to hide/show it into menubar or menu.
Definition: YMGANCMenuBar.cc:468
YMGANCMenuBar::Private
Definition: YMGANCMenuBar.cc:47
YMGANCMenuBar::addItems
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
Definition: YMGANCMenuBar.cc:269