From cb6cd9af6f11dc9a5f4ed2781323fddbe71df337 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Fri, 11 Jan 2008 11:34:53 +0000 Subject: [PATCH] BMenu::_SelectNextItem() also opens the menu if we're inside a menubar. That way menubars are navigable via keyboard. There are still glitches, but menu keyboard navigation works now. Minor optimization: cache the value of CountItems() instead of calling it multiple times. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23387 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 0199128447..e9994495fb 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -2159,7 +2159,10 @@ BMenu::_SelectNextItem(BMenuItem *item, bool forward) if (nextItem == NULL) return false; - _SelectItem(nextItem, false); + bool openMenu = false; + if (dynamic_cast(this) != NULL) + openMenu = true; + _SelectItem(nextItem, openMenu); return true; } @@ -2167,18 +2170,12 @@ BMenu::_SelectNextItem(BMenuItem *item, bool forward) BMenuItem * BMenu::_NextItem(BMenuItem *item, bool forward) const { - /*if (item == NULL) { - if (forward) - return ItemAt(CountItems() - 1); - - return ItemAt(0); - } -*/ // go to next item, and skip over disabled items such as separators int32 index = fItems.IndexOf(item); if (index < 0) index = 0; + const int32 numItems = fItems.CountItems(); int32 startIndex = index; do { if (forward) @@ -2188,8 +2185,8 @@ BMenu::_NextItem(BMenuItem *item, bool forward) const // cycle through menu items if (index < 0) - index = CountItems() - 1; - else if(index >= fItems.CountItems()) + index = numItems - 1; + else if (index >= numItems) index = 0; } while (!ItemAt(index)->IsEnabled() && index != startIndex);