From 03f2d7791e97456c292bcbf604c48315b1381821 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Fri, 26 May 2006 18:13:38 +0000 Subject: [PATCH] Switched back to the GetMouse variation which does NOT check the message queue, should fix bug 594 and not risk of losing clicks. SetStickyMode() calls StealFocus() to give the chance to be keyboard-navigated to menus. Added an extra (temporary) InvalidateLayout() because some items weren't added in some cases (Tracker's attributes menu for example) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17599 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 17 ++++++++++++++++- src/kits/interface/MenuBar.cpp | 5 ++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index ade824145b..e2c93f6774 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1236,8 +1236,10 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) bigtime_t snoozeAmount = 50000; BPoint location; ulong buttons; - GetMouse(&location, &buttons, true); + GetMouse(&location, &buttons, false); + // Get the current mouse state + Window()->UpdateIfNeeded(); BPoint screenLocation = ConvertToScreen(location); item = HitTestItems(location, B_ORIGIN); if (item != NULL) { @@ -1356,6 +1358,10 @@ BMenu::_AddItem(BMenuItem *item, int32 index) item->SetSuper(this); + // TODO: Sometimes the menu layout isn't invalidated correctly, + // So we force a rebuild of the whole menu layout. Remove this! + InvalidateLayout(); + return true; } @@ -1927,6 +1933,15 @@ BMenu::SetStickyMode(bool on) { fStickyMode = on; + // TODO: Ugly hack, but it needs to be done right here in this method + BMenuBar *menuBar = dynamic_cast(this); + if (on && menuBar != NULL && menuBar->LockLooper()) { + // Steal the focus from the current focus view + // (needed to handle keyboard navigation) + menuBar->StealFocus(); + menuBar->UnlockLooper(); + } + // If we are switching to sticky mode, propagate the status // back to the super menu if (on && fSuper != NULL) diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index 997124e9b2..29f92290f4 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -399,7 +399,9 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) BPoint where; ulong buttons; - GetMouse(&where, &buttons, true); + GetMouse(&where, &buttons, false); + // Get the current mouse state + window->UpdateIfNeeded(); BMenuItem *menuItem = HitTestItems(where, B_ORIGIN); if (menuItem != NULL) { // Select item if: @@ -468,6 +470,7 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) SelectItem(NULL); if (resultItem != NULL) resultItem->Invoke(); + RestoreFocus(); window->Unlock(); }