Ticket #4930: menu-kb-nav2.patch
File menu-kb-nav2.patch, 5.0 KB (added by , 14 years ago) |
---|
-
src/kits/interface/Menu.cpp
372 372 // when called on input_server initialization, since it tries 373 373 // to send a synchronous message to itself (input_server is 374 374 // a BApplication) 375 376 375 BMenu::sAltAsCommandKey = true; 377 376 key_map* keys = NULL; 378 377 char* chars = NULL; … … 515 514 _SelectNextItem(fSelected, true); 516 515 else { 517 516 if (fSelected && fSelected->Submenu()) { 518 _SelectItem(fSelected, true, true); 517 fSelected->Submenu()->_SetStickyMode(true); 518 // fix me: this shouldn't be needed but dynamic menus 519 // aren't getting it set correctly when keyboard 520 // navigating, which aborts the attach 521 _SelectItem(fSelected, true, true, true); 519 522 } else if (dynamic_cast<BMenuBar*>(Supermenu())) { 520 523 // if we have no submenu and we're an 521 524 // item in the top menu below the menubar, … … 1462 1465 1463 1466 1464 1467 bool 1465 BMenu::_Show(bool selectFirstItem )1468 BMenu::_Show(bool selectFirstItem, bool keyDown) 1466 1469 { 1467 1470 // See if the supermenu has a cached menuwindow, 1468 1471 // and use that one if possible. … … 1486 1489 return false; 1487 1490 1488 1491 if (window->Lock()) { 1492 bool attachAborted = false; 1489 1493 fAttachAborted = false; 1494 1495 // When the keyboard was used to show a dynamic menu, we build it 1496 // here to prevent aborting because the mouse pointer is not over 1497 // the superitem. Otherwise, AttachedToWindow() will build it. 1498 if (keyDown) { 1499 BMenuItem* superItem = Superitem(); 1500 BMenu* superMenu = Supermenu(); 1501 if (AddDynamicItem(B_INITIAL_ADD)) { 1502 do { 1503 if (superMenu != NULL 1504 && !superMenu->_OkToProceed(superItem, keyDown)) { 1505 AddDynamicItem(B_ABORT); 1506 attachAborted = true; 1507 break; 1508 } 1509 } while (AddDynamicItem(B_PROCESSING)); 1510 } 1511 if (attachAborted) { 1512 if (ourWindow) 1513 window->Quit(); 1514 else 1515 window->Unlock(); 1516 return false; 1517 } 1518 } 1519 1490 1520 window->AttachMenu(this); 1491 1521 1492 1522 if (ItemAt(0) != NULL) { 1493 1523 float width, height; 1494 1524 ItemAt(0)->GetContentSize(&width, &height); 1495 1496 1525 window->SetSmallStep(ceilf(height)); 1497 1526 } 1498 1527 … … 2499 2528 2500 2529 2501 2530 void 2502 BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, bool selectFirstItem) 2531 BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, 2532 bool selectFirstItem, bool keyDown) 2503 2533 { 2504 2534 // Avoid deselecting and then reselecting the same item 2505 2535 // which would cause flickering … … 2519 2549 if (fSelected != NULL && showSubmenu) { 2520 2550 BMenu* subMenu = fSelected->Submenu(); 2521 2551 if (subMenu != NULL && subMenu->Window() == NULL) { 2522 if (!subMenu->_Show(selectFirstItem )) {2552 if (!subMenu->_Show(selectFirstItem, keyDown)) { 2523 2553 // something went wrong, deselect the item 2524 2554 fSelected->Select(false); 2525 2555 fSelected = NULL; … … 2729 2759 2730 2760 2731 2761 bool 2732 BMenu::_OkToProceed(BMenuItem* item )2762 BMenu::_OkToProceed(BMenuItem* item, bool keyDown) 2733 2763 { 2734 2764 BPoint where; 2735 2765 ulong buttons; … … 2742 2772 // BeOS seems to do something similar. This could also be a bug in 2743 2773 // Deskbar, though. 2744 2774 if ((buttons != 0 && stickyMode) 2745 || ((dynamic_cast<BMenuBar*>(this) == NULL 2746 && (buttons == 0 && !stickyMode)) || _HitTestItems(where) != item)) 2775 || (dynamic_cast<BMenuBar*>(this) == NULL 2776 && (buttons == 0 && !stickyMode)) 2777 || ((_HitTestItems(where) != item) && !keyDown)) 2747 2778 return false; 2748 2779 2749 2780 return true; -
headers/os/interface/Menu.h
183 183 BMenu& operator=(const BMenu& other); 184 184 185 185 void _InitData(BMessage* archive); 186 bool _Show(bool selectFirstItem = false); 186 bool _Show(bool selectFirstItem = false, 187 bool keyDown = false); 187 188 void _Hide(); 188 189 BMenuItem* _Track(int* action, long start = -1); 189 190 … … 212 213 void _ComputeColumnLayout(int32 index, bool bestFit, 213 214 bool moveItems, BRect& outRect); 214 215 void _ComputeRowLayout(int32 index, bool bestFit, 215 bool moveItems, BRect& outRect); 216 bool moveItems, BRect& outRect); 216 217 void _ComputeMatrixLayout(BRect& outRect); 217 218 218 219 BRect _CalcFrame(BPoint where, bool* scrollOn); … … 235 236 void _Uninstall(); 236 237 void _SelectItem(BMenuItem* item, 237 238 bool showSubmenu = true, 238 bool selectFirstItem = false); 239 bool selectFirstItem = false, 240 bool keyDown = false); 239 241 bool _SelectNextItem(BMenuItem* item, bool forward); 240 242 BMenuItem* _NextItem(BMenuItem* item, bool forward) const; 241 243 void _SetIgnoreHidden(bool on); … … 246 248 uint32& trigger, 247 249 BPrivate::TriggerList& triggers); 248 250 void _UpdateWindowViewSize(const bool &updatePosition); 249 bool _OkToProceed(BMenuItem* item); 251 bool _OkToProceed(BMenuItem* item, 252 bool keyDown = false); 250 253 251 254 bool _CustomTrackingWantsToQuit(); 252 255