28 #define YUILogComponent "ncurses"
29 #include <yui/YUILog.h>
30 #include "NCMenuBar.h"
31 #include "YNCursesUI.h"
32 #include "NCPopupMenu.h"
50 bool isSelectable()
const
55 return item->isEnabled();
60 bool hasHotkey(
int key )
const
65 if ( ! label.hasHotkey() )
68 return tolower( key ) == tolower( label.hotkey() );
75 YMenuBar( parent ),
NCWidget( parent ), _menus()
77 defsze =
wsze( 1, 10 );
90 for (
Menu* menu : _menus )
95 defsze =
wsze( 1, 10 );
104 int width = LEFT_MARGIN;
106 for ( YItemIterator it = itemsBegin(); it != itemsEnd(); ++it )
108 YMenuItem * item =
dynamic_cast<YMenuItem *
>(*it);
109 YUI_CHECK_PTR( item );
111 if ( ! item->isMenu() )
112 YUI_THROW( YUIException(
"NCMenuBar: Only menus allowed on toplevel. ") );
114 if ( ! item->isVisible() )
119 menu->position =
wpos( 0, width );
122 item->setUiItem( menu );
127 width += label.width() + SPACING;
132 defsze =
wsze( 1, width );
142 for (
const Menu * menu : _menus )
151 label.drawAt( *
win, style, menu->position,
wsze( -1, label.width() + SPACING ), NC::LEFT );
167 wpos at(ScreenPos() +
wpos( 1, selectedMenu()->position.C) );
171 selectedMenu()->item->childrenBegin(),
172 selectedMenu()->item->childrenEnd()
175 YUI_CHECK_NEW( dialog );
178 dialog->post( &event );
180 YDialog::deleteTopmostDialog();
182 return handlePostMenu( event );
189 YMenuWidget::setItemEnabled( item, enabled );
198 YMenuWidget::setItemVisible( item, visible );
207 if ( item->isMenu() || item->isSeparator() )
213 event.selection = item;
227 selectPreviousMenu();
247 event = NCWidget::wHandleInput(key);
272 wRelocate(
wpos( 0 ),
wsze( newHeight, newWidth ) );
280 YMenuBar::setEnabled( enabled );
288 return YWidget::setKeyboardFocus();
297 if( key < 0 || UCHAR_MAX < key )
300 return findMenuWithHotkey( key ) != _menus.end();
307 CyclicContainer<Menu>::Iterator menu = findMenuWithHotkey( key );
309 if ( menu == _menus.end() )
310 return NCursesEvent::none;
312 _menus.setCurrent( menu );
334 if ( event == NCursesEvent::button )
336 newEvent = NCursesEvent::menu;
337 newEvent.selection =
event.selection;
339 else if ( event == NCursesEvent::key )
341 if ( event.keySymbol ==
"CursorLeft" )
346 else if ( event.keySymbol ==
"CursorRight" )
351 else if ( event.keySymbol ==
"BackSpace" )
355 else if ( event.keySymbol ==
"Hotkey" )
366 NCMenuBar::selectedMenu()
368 return *_menus.current();
373 NCMenuBar::selectNextMenu()
375 _menus.setCurrent( _menus.next() );
380 NCMenuBar::selectPreviousMenu()
382 _menus.setCurrent( _menus.previous() );
387 NCMenuBar::findMenuWithHotkey( wint_t key )
389 return std::find_if( _menus.begin(), _menus.end(), [key](Menu * menu) {
390 return menu->hasHotkey( key );
396 NCMenuBar::menuStyle(
const Menu * menu )
398 if ( !menu->item->isEnabled() )
399 return wStyle().getWidget( NC::WSdisabled );
401 bool non_active = ( menu != selectedMenu() );
402 return widgetStyle( non_active );