The menus work a bit less good now I think, but they no longer have 100% CPU usage

when the menu item under the mouse cursor has a sub-menu.
Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16160 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-01-30 23:40:05 +00:00
parent badb1d4be6
commit ec549309c9
2 changed files with 52 additions and 66 deletions
+21 -21
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2005, Haiku, Inc.
* Copyright 2001-2006, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -7,6 +7,7 @@
* Stefano Ceccherini ([email protected])
*/
#include <string.h>
#include <Debug.h>
@@ -1110,22 +1111,23 @@ BMenu::_track(int *action, long start)
ulong buttons;
BMenuItem *item = NULL;
int localAction = MENU_ACT_NONE;
bigtime_t startTime = system_time();
bigtime_t clickTime = 0;
get_click_speed(&clickTime);
// TODO: Test and reduce the timeout if needed.
clickTime /= 2;
do {
if (!LockLooper())
break;
bigtime_t snoozeAmount = 50000;
BPoint location;
GetMouse(&location, &buttons, true);
BPoint screenLocation = ConvertToScreen(location);
item = HitTestItems(location, B_ORIGIN);
if (item != NULL) {
if (item != fSelected) {
@@ -1140,18 +1142,18 @@ BMenu::_track(int *action, long start)
SelectItem(item);
}
} else {
if (OverSuper(location)) {
if (OverSuper(screenLocation)) {
UnlockLooper();
break;
}
if (fSelected != NULL && !OverSubmenu(fSelected, ConvertToScreen(location)))
if (fSelected != NULL && !OverSubmenu(fSelected, screenLocation))
SelectItem(NULL);
}
if (fSelected != NULL && fSelected->Submenu() != NULL
if (item != NULL && fSelected != NULL && OverSubmenu(fSelected, screenLocation)
&& fSelected->Submenu()->Window() != NULL) {
UnlockLooper();
int submenuAction = MENU_ACT_NONE;
BMenuItem *submenuItem = fSelected->Submenu()->_track(&submenuAction);
if (submenuAction == MENU_ACT_CLOSE) {
@@ -1159,31 +1161,31 @@ BMenu::_track(int *action, long start)
localAction = submenuAction;
break;
}
if (!LockLooper())
break;
}
UnlockLooper();
snooze(snoozeAmount);
} while (buttons != 0);
if (localAction == MENU_ACT_NONE) {
if (buttons != 0)
localAction = MENU_ACT_NONE;
else
localAction = MENU_ACT_CLOSE;
}
if (action != NULL)
*action = localAction;
if (LockLooper()) {
SelectItem(NULL);
UnlockLooper();
}
// delete the menu window recycled for all the child menus
DeleteMenuWindow();
@@ -1543,9 +1545,7 @@ BMenu::OverSuper(BPoint location)
{
if (!Supermenu())
return false;
ConvertToScreen(&location);
return fSuperbounds.Contains(location);
}
@@ -1557,7 +1557,7 @@ BMenu::OverSubmenu(BMenuItem *item, BPoint loc)
BMenu *subMenu = item->Submenu();
if (subMenu == NULL || subMenu->Window() == NULL)
return false;
if (subMenu->Window()->Frame().Contains(loc))
return true;