From a7067566a15085384a0c47db8e55d4d3fade36f0 Mon Sep 17 00:00:00 2001 From: Waldemar Kornewald Date: Wed, 22 Nov 2006 11:32:35 +0000 Subject: [PATCH] Fixed menu disappearing bug when (in sticky mode) mouse button is pressed (and held down) and the mouse pointer is moved outside of the menu. Now, menus should work as expected and switch from sticky to non-sticky mode on mouse button press correctly. BTW, I disabled trackTime. It seems to work without it, correctly, so I guess it can be removed completely. If not, just revert the change ("if (system_time....") after TODO. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19358 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 25 ++++++++++++++++++++----- src/kits/interface/MenuBar.cpp | 9 ++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 2aa1f8eab0..53ad3c9ea5 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1295,16 +1295,26 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) locked = false; int submenuAction = MENU_STATE_TRACKING; BMenu *submenu = fSelected->Submenu(); - if (IsStickyMode()) + bool wasSticky = IsStickyMode(); + if (wasSticky) submenu->SetStickyMode(true); BMenuItem *submenuItem = submenu->_track(&submenuAction, trackTime); + + // check if the user started holding down a mouse button in a submenu + if (wasSticky && !IsStickyMode()) { + buttons = 1; + // buttons must have been pressed in the meantime + trackTime = 0; + // we are already in non-sticky mode + } + //submenu->Window()->Activate(); if (submenuAction == MENU_STATE_CLOSED) { item = submenuItem; fState = submenuAction; break; } - + locked = LockLooper(); if (!locked) break; @@ -1328,7 +1338,7 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) if (locked) UnlockLooper(); *action = fState; - return NULL; + return NULL; } } @@ -1336,11 +1346,16 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) UnlockLooper(); if (buttons != 0 && IsStickyMode()) { + BMenu *supermenu = Supermenu(); + for(; supermenu; supermenu = supermenu->Supermenu()) + supermenu->SetStickyMode(false); SetStickyMode(false); trackTime = 0; } else if (buttons == 0 && !IsStickyMode()) { - if (system_time() < trackTime + 1000000 - || (fExtraRect != NULL && fExtraRect->Contains(location))) +// TODO: trackTime isn't very useful. we should probably remove it +/* if (system_time() < trackTime + 1000000 + || (fExtraRect != NULL && fExtraRect->Contains(location))) */ + if (fExtraRect != NULL && fExtraRect->Contains(location)) SetStickyMode(true); else fState = MENU_STATE_CLOSED; diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index d1c18ae97a..de7a62a53c 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -466,10 +466,17 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) window->Unlock(); locked = false; snoozeAmount = 30000; - if (IsStickyMode()) + bool wasSticky = IsStickyMode(); + if (wasSticky) menu->SetStickyMode(true); int localAction; fChosenItem = menu->_track(&localAction, system_time()); + + // check if the user started holding down a mouse button in a submenu + if (wasSticky && !IsStickyMode()) + buttons = 1; + // buttons must have been pressed in the meantime + //menu->Window()->Activate(); if (localAction == MENU_STATE_CLOSED) fState = MENU_STATE_CLOSED;