small cleanups

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19591 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-12-21 14:35:13 +00:00
parent 59f9192c3b
commit f0f8601b3f
2 changed files with 48 additions and 44 deletions
+23 -18
View File
@@ -1227,17 +1227,19 @@ BMenu::_hide()
if (fSelected != NULL) if (fSelected != NULL)
_SelectItem(NULL); _SelectItem(NULL);
window->Hide(); window->Hide();
window->DetachMenu(); window->DetachMenu();
// we don't want to be deleted when the window is removed // we don't want to be deleted when the window is removed
// Delete the menu window used by our submenus // Delete the menu window used by our submenus
DeleteMenuWindow(); DeleteMenuWindow();
window->Unlock(); if (fSuper != NULL)
window->Unlock();
if (fSuper == NULL && window->Lock()) else {
// it's our window, quit it
window->Quit(); window->Quit();
}
} }
@@ -1269,14 +1271,13 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
ulong buttons; ulong buttons;
GetMouse(&location, &buttons, true); GetMouse(&location, &buttons, true);
Window()->UpdateIfNeeded();
BPoint screenLocation = ConvertToScreen(location); BPoint screenLocation = ConvertToScreen(location);
item = HitTestItems(location, B_ORIGIN); item = HitTestItems(location, B_ORIGIN);
if (item != NULL) if (item != NULL)
_UpdateStateOpenSelect(item, openTime, closeTime); _UpdateStateOpenSelect(item, openTime, closeTime);
// Track the submenu // Track the submenu
if (fSelected != NULL && OverSubmenu(fSelected, screenLocation)) { if (OverSubmenu(fSelected, screenLocation)) {
UnlockLooper(); UnlockLooper();
locked = false; locked = false;
int submenuAction = MENU_STATE_TRACKING; int submenuAction = MENU_STATE_TRACKING;
@@ -1301,16 +1302,15 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
locked = LockLooper(); locked = LockLooper();
if (!locked) if (!locked)
break; break;
}
if (item == NULL) { } else if (item == NULL) {
if (OverSuper(screenLocation)) { if (OverSuper(screenLocation)) {
fState = MENU_STATE_TRACKING; fState = MENU_STATE_TRACKING;
UnlockLooper(); UnlockLooper();
break; break;
} }
if (fSelected != NULL && !OverSubmenu(fSelected, screenLocation) if (!OverSubmenu(fSelected, screenLocation)
&& system_time() > closeTime + kHysteresis && system_time() > closeTime + kHysteresis
&& fState != MENU_STATE_TRACKING_SUBMENU) { && fState != MENU_STATE_TRACKING_SUBMENU) {
_SelectItem(NULL); _SelectItem(NULL);
@@ -1318,9 +1318,9 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
} }
if (fSuper != NULL) { if (fSuper != NULL) {
if (locked)
UnlockLooper();
*action = fState; *action = fState;
if (locked)
UnlockLooper();
return NULL; return NULL;
} }
} }
@@ -1357,6 +1357,9 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
void void
BMenu::_UpdateStateOpenSelect(BMenuItem *item, bigtime_t &openTime, bigtime_t &closeTime) BMenu::_UpdateStateOpenSelect(BMenuItem *item, bigtime_t &openTime, bigtime_t &closeTime)
{ {
if (fState == MENU_STATE_CLOSED)
return;
if (item != fSelected && system_time() > closeTime + kHysteresis) { if (item != fSelected && system_time() > closeTime + kHysteresis) {
_SelectItem(item, false); _SelectItem(item, false);
openTime = system_time(); openTime = system_time();
@@ -1376,6 +1379,9 @@ BMenu::_UpdateStateOpenSelect(BMenuItem *item, bigtime_t &openTime, bigtime_t &c
void void
BMenu::_UpdateStateClose(BMenuItem *item, const BPoint &where, const uint32 &buttons) BMenu::_UpdateStateClose(BMenuItem *item, const BPoint &where, const uint32 &buttons)
{ {
if (fState == MENU_STATE_CLOSED)
return;
if (buttons != 0 && IsStickyMode()) { if (buttons != 0 && IsStickyMode()) {
if (item == NULL) if (item == NULL)
fState = MENU_STATE_CLOSED; fState = MENU_STATE_CLOSED;
@@ -1808,17 +1814,17 @@ BMenu::OverSuper(BPoint location)
bool bool
BMenu::OverSubmenu(BMenuItem *item, BPoint loc) BMenu::OverSubmenu(BMenuItem *item, BPoint loc)
{ {
// we assume that loc is in screen coords if (item == NULL)
return false;
BMenu *subMenu = item->Submenu(); BMenu *subMenu = item->Submenu();
if (subMenu == NULL || subMenu->Window() == NULL) if (subMenu == NULL || subMenu->Window() == NULL)
return false; return false;
// we assume that loc is in screen coords
if (subMenu->Window()->Frame().Contains(loc)) if (subMenu->Window()->Frame().Contains(loc))
return true; return true;
if (subMenu->fSelected == NULL)
return false;
return subMenu->OverSubmenu(subMenu->fSelected, loc); return subMenu->OverSubmenu(subMenu->fSelected, loc);
} }
@@ -1942,8 +1948,7 @@ BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, bool selectFirstItem)
// something went wrong, deselect the item // something went wrong, deselect the item
fSelected->Select(false); fSelected->Select(false);
fSelected = NULL; fSelected = NULL;
} }
//subMenu->Window()->Activate();
} }
} }
} }
+25 -26
View File
@@ -418,10 +418,12 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
if (startIndex != -1) { if (startIndex != -1) {
be_app->ObscureCursor(); be_app->ObscureCursor();
window->Lock(); if (window->Lock()) {
_SelectItem(ItemAt(startIndex), true, true); _SelectItem(ItemAt(startIndex), true, true);
window->Unlock(); window->Unlock();
}
} }
while (true) { while (true) {
bigtime_t snoozeAmount = 40000; bigtime_t snoozeAmount = 40000;
bool locked = window->Lock();//WithTimeout(200000) bool locked = window->Lock();//WithTimeout(200000)
@@ -432,7 +434,6 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
ulong buttons; ulong buttons;
GetMouse(&where, &buttons, true); GetMouse(&where, &buttons, true);
window->UpdateIfNeeded();
BMenuItem *menuItem = HitTestItems(where, B_ORIGIN); BMenuItem *menuItem = HitTestItems(where, B_ORIGIN);
if (menuItem != NULL) { if (menuItem != NULL) {
// Select item if: // 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 // call _track() from the selected sub-menu when the mouse cursor
// is over its window // is over its window
BMenu *menu = fSelected->Submenu(); BMenu *menu = fSelected->Submenu();
if (menu != NULL) { window->Unlock();
window->Unlock(); locked = false;
locked = false; snoozeAmount = 30000;
snoozeAmount = 30000; bool wasSticky = IsStickyMode();
bool wasSticky = IsStickyMode(); if (wasSticky)
if (wasSticky) menu->SetStickyMode(true);
menu->SetStickyMode(true); int localAction;
int localAction; fChosenItem = menu->_track(&localAction, system_time());
fChosenItem = menu->_track(&localAction, system_time());
// check if the user started holding down a mouse button in a submenu
// check if the user started holding down a mouse button in a submenu if (wasSticky && !IsStickyMode())
if (wasSticky && !IsStickyMode()) buttons = 1;
buttons = 1; // buttons must have been pressed in the meantime
// buttons must have been pressed in the meantime
if (localAction == MENU_STATE_CLOSED)
//menu->Window()->Activate(); fState = MENU_STATE_CLOSED;
if (localAction == MENU_STATE_CLOSED)
fState = MENU_STATE_CLOSED; } else if (menuItem == NULL && fSelected != NULL
} && !IsStickyMode() && fState != MENU_STATE_TRACKING_SUBMENU) {
} else if (menuItem == NULL && !IsStickyMode()
&& fState != MENU_STATE_TRACKING_SUBMENU) {
_SelectItem(NULL); _SelectItem(NULL);
fState = MENU_STATE_TRACKING; fState = MENU_STATE_TRACKING;
} }