Ticket #4930: menu-keyboard-nav.patch

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

     
    221221    fIgnoreHidden(true),
    222222    fTriggerEnabled(true),
    223223    fRedrawAfterSticky(false),
    224     fAttachAborted(false)
     224    fAttachAborted(false),
     225    fKeyDown(false)
    225226{
    226227    _InitData(NULL);
    227228}
     
    255256    fIgnoreHidden(true),
    256257    fTriggerEnabled(true),
    257258    fRedrawAfterSticky(false),
    258     fAttachAborted(false)
     259    fAttachAborted(false),
     260    fKeyDown(false)
    259261{
    260262    _InitData(NULL);
    261263}
     
    290292    fIgnoreHidden(true),
    291293    fTriggerEnabled(true),
    292294    fRedrawAfterSticky(false),
    293     fAttachAborted(false)
     295    fAttachAborted(false),
     296    fKeyDown(false)
    294297{
    295298    _InitData(archive);
    296299}
     
    479482void
    480483BMenu::KeyDown(const char* bytes, int32 numBytes)
    481484{
     485    // maybe ignore key presses if not sticky?
     486    fKeyDown = false;
     487        // if a menu is still attaching it should abort as the user pressed
     488        // another key
     489
    482490    // TODO: Test how it works on beos and implement it correctly
    483491    switch (bytes[0]) {
    484492        case B_UP_ARROW:
     
    515523                _SelectNextItem(fSelected, true);
    516524            else {
    517525                if (fSelected && fSelected->Submenu()) {
     526                    fSelected->Submenu()->_SetStickyMode(true);
     527                        // fix me: this shouldn't be needed but dynamic menus
     528                        // aren't getting it set correctly when keyboard
     529                        // navigating, which aborts the attach
     530                    fKeyDown = true;
     531                        // see _OkToProceed()
    518532                    _SelectItem(fSelected, true, true);
    519533                } else if (dynamic_cast<BMenuBar*>(Supermenu())) {
    520534                    // if we have no submenu and we're an
     
    569583            break;
    570584        }
    571585    }
     586    fKeyDown = false;
     587        // if a submenu was opened it has failed or suceeded by now
    572588}
    573589
    574590
     
    12721288    fIgnoreHidden(true),
    12731289    fTriggerEnabled(true),
    12741290    fRedrawAfterSticky(false),
    1275     fAttachAborted(false)
     1291    fAttachAborted(false),
     1292    fKeyDown(false)
    12761293{
    12771294    _InitData(NULL);
    12781295}
     
    27422759    // BeOS seems to do something similar. This could also be a bug in
    27432760    // Deskbar, though.
    27442761    if ((buttons != 0 && stickyMode)
    2745         || ((dynamic_cast<BMenuBar*>(this) == NULL
    2746             && (buttons == 0 && !stickyMode)) || _HitTestItems(where) != item))
     2762            || (dynamic_cast<BMenuBar*>(this) == NULL
     2763                && (buttons == 0 && !stickyMode))
     2764            || ((_HitTestItems(where) != item) && !fKeyDown))
    27472765        return false;
    2748 
    27492766    return true;
    27502767}
    27512768
  • headers/os/interface/Menu.h

     
    212212            void                _ComputeColumnLayout(int32 index, bool bestFit,
    213213                                    bool moveItems, BRect& outRect);
    214214            void                _ComputeRowLayout(int32 index, bool bestFit,
    215                                     bool moveItems, BRect& outRect);       
     215                                    bool moveItems, BRect& outRect);
    216216            void                _ComputeMatrixLayout(BRect& outRect);
    217217
    218218            BRect               _CalcFrame(BPoint where, bool* scrollOn);
     
    291291            bool                fTriggerEnabled;
    292292            bool                fRedrawAfterSticky;
    293293            bool                fAttachAborted;
     294            bool                fKeyDown;
    294295};
    295296
    296297#endif // _MENU_H