From f0f8601b3fb1d24d77c1a9c34ddd51a9d55b2f43 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 21 Dec 2006 14:35:13 +0000 Subject: [PATCH] small cleanups git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19591 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 41 +++++++++++++++------------ src/kits/interface/MenuBar.cpp | 51 +++++++++++++++++----------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 8929347835..d29dbc7ee9 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1227,17 +1227,19 @@ BMenu::_hide() if (fSelected != NULL) _SelectItem(NULL); - window->Hide(); + window->Hide(); window->DetachMenu(); // we don't want to be deleted when the window is removed // Delete the menu window used by our submenus DeleteMenuWindow(); - window->Unlock(); - - if (fSuper == NULL && window->Lock()) + if (fSuper != NULL) + window->Unlock(); + else { + // it's our window, quit it window->Quit(); + } } @@ -1269,14 +1271,13 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) ulong buttons; GetMouse(&location, &buttons, true); - Window()->UpdateIfNeeded(); BPoint screenLocation = ConvertToScreen(location); item = HitTestItems(location, B_ORIGIN); if (item != NULL) _UpdateStateOpenSelect(item, openTime, closeTime); // Track the submenu - if (fSelected != NULL && OverSubmenu(fSelected, screenLocation)) { + if (OverSubmenu(fSelected, screenLocation)) { UnlockLooper(); locked = false; int submenuAction = MENU_STATE_TRACKING; @@ -1301,16 +1302,15 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) locked = LockLooper(); if (!locked) break; - } - if (item == NULL) { + } else if (item == NULL) { if (OverSuper(screenLocation)) { fState = MENU_STATE_TRACKING; UnlockLooper(); break; } - if (fSelected != NULL && !OverSubmenu(fSelected, screenLocation) + if (!OverSubmenu(fSelected, screenLocation) && system_time() > closeTime + kHysteresis && fState != MENU_STATE_TRACKING_SUBMENU) { _SelectItem(NULL); @@ -1318,9 +1318,9 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) } if (fSuper != NULL) { - if (locked) - UnlockLooper(); *action = fState; + if (locked) + UnlockLooper(); return NULL; } } @@ -1357,6 +1357,9 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) void BMenu::_UpdateStateOpenSelect(BMenuItem *item, bigtime_t &openTime, bigtime_t &closeTime) { + if (fState == MENU_STATE_CLOSED) + return; + if (item != fSelected && system_time() > closeTime + kHysteresis) { _SelectItem(item, false); openTime = system_time(); @@ -1376,6 +1379,9 @@ BMenu::_UpdateStateOpenSelect(BMenuItem *item, bigtime_t &openTime, bigtime_t &c void BMenu::_UpdateStateClose(BMenuItem *item, const BPoint &where, const uint32 &buttons) { + if (fState == MENU_STATE_CLOSED) + return; + if (buttons != 0 && IsStickyMode()) { if (item == NULL) fState = MENU_STATE_CLOSED; @@ -1808,17 +1814,17 @@ BMenu::OverSuper(BPoint location) bool BMenu::OverSubmenu(BMenuItem *item, BPoint loc) { - // we assume that loc is in screen coords + if (item == NULL) + return false; + BMenu *subMenu = item->Submenu(); if (subMenu == NULL || subMenu->Window() == NULL) return false; - + + // we assume that loc is in screen coords if (subMenu->Window()->Frame().Contains(loc)) return true; - if (subMenu->fSelected == NULL) - return false; - return subMenu->OverSubmenu(subMenu->fSelected, loc); } @@ -1942,8 +1948,7 @@ BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, bool selectFirstItem) // something went wrong, deselect the item fSelected->Select(false); fSelected = NULL; - } - //subMenu->Window()->Activate(); + } } } } diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index 143b386370..39d34cc81c 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -418,10 +418,12 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) if (startIndex != -1) { be_app->ObscureCursor(); - window->Lock(); - _SelectItem(ItemAt(startIndex), true, true); - window->Unlock(); + if (window->Lock()) { + _SelectItem(ItemAt(startIndex), true, true); + window->Unlock(); + } } + while (true) { bigtime_t snoozeAmount = 40000; bool locked = window->Lock();//WithTimeout(200000) @@ -432,7 +434,6 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) ulong buttons; GetMouse(&where, &buttons, true); - window->UpdateIfNeeded(); BMenuItem *menuItem = HitTestItems(where, B_ORIGIN); if (menuItem != NULL) { // Select item if: @@ -461,31 +462,29 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) } } - if (fSelected != NULL && OverSubmenu(fSelected, ConvertToScreen(where))) { + if (OverSubmenu(fSelected, ConvertToScreen(where))) { // call _track() from the selected sub-menu when the mouse cursor // is over its window BMenu *menu = fSelected->Submenu(); - if (menu != NULL) { - window->Unlock(); - locked = false; - snoozeAmount = 30000; - 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; - } - } else if (menuItem == NULL && !IsStickyMode() - && fState != MENU_STATE_TRACKING_SUBMENU) { + window->Unlock(); + locked = false; + snoozeAmount = 30000; + 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 + + if (localAction == MENU_STATE_CLOSED) + fState = MENU_STATE_CLOSED; + + } else if (menuItem == NULL && fSelected != NULL + && !IsStickyMode() && fState != MENU_STATE_TRACKING_SUBMENU) { _SelectItem(NULL); fState = MENU_STATE_TRACKING; }