From 0e0b8fd554480de7f904b8e886c019bda319bb0f Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 12 Apr 2006 11:25:59 +0000 Subject: [PATCH] more fixes git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17104 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 4 +-- src/kits/interface/MenuBar.cpp | 46 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index d151a07cb5..c5b2d9d91c 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1146,7 +1146,6 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) bigtime_t startTime = system_time(); bigtime_t delay = 200000; // TODO: Test and reduce if needed. - bool okay = true; while (true) { bool locked = LockLooper(); if (!locked) @@ -1172,7 +1171,6 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) } } else { if (OverSuper(screenLocation)) { - okay = false; localAction = MENU_ACT_NONE; item = NULL; UnlockLooper(); @@ -1188,7 +1186,7 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) int submenuAction = MENU_ACT_NONE; if (IsStickyMode()) fSelected->Submenu()->SetStickyMode(true); - BMenuItem *submenuItem = fSelected->Submenu()->_track(&submenuAction, startTime); + BMenuItem *submenuItem = fSelected->Submenu()->_track(&submenuAction, trackTime); if (submenuAction == MENU_ACT_CLOSE) { item = submenuItem; localAction = submenuAction; diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index 3fb4a635fb..4bfeb72c58 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -392,18 +392,27 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) ulong buttons; GetMouse(&where, &buttons); BMenuItem *menuItem = HitTestItems(where, B_ORIGIN); - if (menuItem != NULL && menuItem != fSelected) { + if (menuItem != NULL) { // Select item if: + // - no previous selection + // - nonsticky mode and different selection, // - clicked in sticky mode - // - nonsticky mode, - // - no previous selection - if (fSelected == NULL || !IsStickyMode() || buttons != 0) { - // only select the item - SelectItem(menuItem, -1); - if (menuItem->Submenu() != NULL - && menuItem->Submenu()->Window() == NULL) { - // open the menu if it's not opened yet - SelectItem(menuItem); + if (fSelected == NULL + || (!IsStickyMode() && menuItem != fSelected) + || (buttons != 0 && IsStickyMode())) { + if (menuItem->Submenu() != NULL) { + if (menuItem->Submenu()->Window() == NULL) { + // open the menu if it's not opened yet + SelectItem(menuItem); + } else { + // Menu was already opened, close it and bail + SelectItem(NULL); + localAction = MENU_ACT_CLOSE; + resultItem = NULL; + } + } else { + // No submenu, just select the item + SelectItem(menuItem); } } } @@ -429,11 +438,15 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) if (localAction == MENU_ACT_CLOSE || (buttons != 0 && IsStickyMode() && menuItem == NULL)) break; else if (buttons == 0 && !IsStickyMode()) { - // Don't switch to sticky mode if user kept the mouse pressed for too long - // TODO: Delay could be smaller, but then it wouldn't be noticeable on QEMU on my machine - if (IsStickyPrefOn() && system_time() < startTime + 2000000) + // On an item without a submenu + if (fSelected != NULL && fSelected->Submenu() == NULL) { + resultItem = fSelected; + break; + } else if (IsStickyPrefOn() && system_time() < startTime + 2000000) { + // Don't switch to sticky mode if user kept the mouse pressed for too long + // TODO: Delay could be smaller, but then it wouldn't be noticeable on QEMU on my machine SetStickyMode(true); - else + } else break; } @@ -442,11 +455,8 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) } if (window->Lock()) { - if (fSelected != NULL) { - if (fSelected->Submenu() == NULL) - resultItem = fSelected; + if (fSelected != NULL) SelectItem(NULL); - } if (resultItem != NULL) resultItem->Invoke(); window->Unlock();