Ticket #4930: menu-kb-nav.patch

File menu-kb-nav.patch, 5.6 KB (added by Ziusudra, 14 years ago)
  • ../src/kits/interface/Menu.cpp

     
    372372    // when called on input_server initialization, since it tries
    373373    // to send a synchronous message to itself (input_server is
    374374    // a BApplication)
    375 
    376375    BMenu::sAltAsCommandKey = true;
    377376    key_map* keys = NULL;
    378377    char* chars = NULL;
     
    383382    free(chars);
    384383    free(keys);
    385384
    386     BMenuItem* superItem = Superitem();
    387     BMenu* superMenu = Supermenu();
    388     if (AddDynamicItem(B_INITIAL_ADD)) {
    389         do {
    390             if (superMenu != NULL && !superMenu->_OkToProceed(superItem)) {
    391                 AddDynamicItem(B_ABORT);
    392                 fAttachAborted = true;
    393                 break;
    394             }
    395         } while (AddDynamicItem(B_PROCESSING));
    396     }
    397 
    398     if (!fAttachAborted) {
    399         _CacheFontInfo();
    400         _LayoutItems(0);
    401         _UpdateWindowViewSize(false);
    402     }
     385    _CacheFontInfo();
     386    _LayoutItems(0);
     387    _UpdateWindowViewSize(false);
    403388}
    404389
    405390
     
    515500                _SelectNextItem(fSelected, true);
    516501            else {
    517502                if (fSelected && fSelected->Submenu()) {
    518                     _SelectItem(fSelected, true, true);
     503                    fSelected->Submenu()->_SetStickyMode(true);
     504                        // fix me: this shouldn't be needed but dynamic menus
     505                        // aren't getting it set correctly when keyboard
     506                        // navigating, which aborts the attach
     507                    _SelectItem(fSelected, true, true, true);
    519508                } else if (dynamic_cast<BMenuBar*>(Supermenu())) {
    520509                    // if we have no submenu and we're an
    521510                    // item in the top menu below the menubar,
     
    14621451
    14631452
    14641453bool
    1465 BMenu::_Show(bool selectFirstItem)
     1454BMenu::_Show(bool selectFirstItem, bool keyDown)
    14661455{
    14671456    // See if the supermenu has a cached menuwindow,
    14681457    // and use that one if possible.
     
    14871476
    14881477    if (window->Lock()) {
    14891478        fAttachAborted = false;
    1490         window->AttachMenu(this);
    14911479
    1492         if (ItemAt(0) != NULL) {
    1493             float width, height;
    1494             ItemAt(0)->GetContentSize(&width, &height);
    1495 
    1496             window->SetSmallStep(ceilf(height));
     1480        BMenuItem* superItem = Superitem();
     1481        BMenu* superMenu = Supermenu();
     1482        if (AddDynamicItem(B_INITIAL_ADD)) {
     1483            do {
     1484                if (superMenu != NULL
     1485                        && !superMenu->_OkToProceed(superItem, keyDown)) {
     1486                    AddDynamicItem(B_ABORT);
     1487                    fAttachAborted = true;
     1488                    break;
     1489                }
     1490            } while (AddDynamicItem(B_PROCESSING));
    14971491        }
    14981492
     1493        if (!fAttachAborted) {
     1494            window->AttachMenu(this);
     1495
     1496            if (ItemAt(0) != NULL) {
     1497                float width, height;
     1498                ItemAt(0)->GetContentSize(&width, &height);
     1499                window->SetSmallStep(ceilf(height));
     1500            }
     1501        } else {
    14991502        // Menu didn't have the time to add its items: aborting...
    1500         if (fAttachAborted) {
    1501             window->DetachMenu();
    1502             // TODO: Probably not needed, we can just let _hide() quit the
    1503             // window.
    15041503            if (ourWindow)
    15051504                window->Quit();
    15061505            else
     
    24992498
    25002499
    25012500void
    2502 BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, bool selectFirstItem)
     2501BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu,
     2502                        bool selectFirstItem, bool keyDown)
    25032503{
    25042504    // Avoid deselecting and then reselecting the same item
    25052505    // which would cause flickering
     
    25192519    if (fSelected != NULL && showSubmenu) {
    25202520        BMenu* subMenu = fSelected->Submenu();
    25212521        if (subMenu != NULL && subMenu->Window() == NULL) {
    2522             if (!subMenu->_Show(selectFirstItem)) {
     2522            if (!subMenu->_Show(selectFirstItem, keyDown)) {
    25232523                // something went wrong, deselect the item
    25242524                fSelected->Select(false);
    25252525                fSelected = NULL;
     
    27292729
    27302730
    27312731bool
    2732 BMenu::_OkToProceed(BMenuItem* item)
     2732BMenu::_OkToProceed(BMenuItem* item, bool keyDown)
    27332733{
    27342734    BPoint where;
    27352735    ulong buttons;
     
    27422742    // BeOS seems to do something similar. This could also be a bug in
    27432743    // Deskbar, though.
    27442744    if ((buttons != 0 && stickyMode)
    2745         || ((dynamic_cast<BMenuBar*>(this) == NULL
    2746             && (buttons == 0 && !stickyMode)) || _HitTestItems(where) != item))
     2745            || (dynamic_cast<BMenuBar*>(this) == NULL
     2746                && (buttons == 0 && !stickyMode))
     2747            || ((_HitTestItems(where) != item) && !keyDown))
    27472748        return false;
    27482749
    27492750    return true;
  • ../headers/os/interface/Menu.h

     
    183183            BMenu&              operator=(const BMenu& other);
    184184
    185185            void                _InitData(BMessage* archive);
    186             bool                _Show(bool selectFirstItem = false);
     186            bool                _Show(bool selectFirstItem = false,
     187                                    bool keyDown = false);
    187188            void                _Hide();
    188189            BMenuItem*          _Track(int* action, long start = -1);
    189190
     
    212213            void                _ComputeColumnLayout(int32 index, bool bestFit,
    213214                                    bool moveItems, BRect& outRect);
    214215            void                _ComputeRowLayout(int32 index, bool bestFit,
    215                                     bool moveItems, BRect& outRect);       
     216                                    bool moveItems, BRect& outRect);
    216217            void                _ComputeMatrixLayout(BRect& outRect);
    217218
    218219            BRect               _CalcFrame(BPoint where, bool* scrollOn);
     
    235236            void                _Uninstall();
    236237            void                _SelectItem(BMenuItem* item,
    237238                                    bool showSubmenu = true,
    238                                     bool selectFirstItem = false);
     239                                    bool selectFirstItem = false,
     240                                    bool keyDown = false);
    239241            bool                _SelectNextItem(BMenuItem* item, bool forward);
    240242            BMenuItem*          _NextItem(BMenuItem* item, bool forward) const;
    241243            void                _SetIgnoreHidden(bool on);
     
    246248                                    uint32& trigger,
    247249                                    BPrivate::TriggerList& triggers);
    248250            void                _UpdateWindowViewSize(const bool &updatePosition);
    249             bool                _OkToProceed(BMenuItem* item);
     251            bool                _OkToProceed(BMenuItem* item,
     252                                    bool keyDown = false);
    250253
    251254            bool                _CustomTrackingWantsToQuit();
    252255