git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10695 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2005-01-12 11:39:56 +00:00
parent d1d811ec70
commit 2ce1b3ecc2
+40 -17
View File
@@ -324,11 +324,13 @@ BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool showMenu,
BRect *specialRect)
{
BWindow *window = Window();
if (!window)
if (window == NULL)
debugger("MenuBar must be added to a window before it can be used.");
BAutolock lock(window);
if (lock.IsLocked()) {
if (!lock.IsLocked())
return;
fPrevFocusToken = -1;
fTracking = true;
@@ -356,7 +358,6 @@ BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool showMenu,
delete_sem(fMenuSem);
}
}
}
long
@@ -397,19 +398,23 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
// Cleanup
BMenuItem *resultItem = NULL;
BWindow *window = Window();
if (window->LockWithTimeout(200000) == B_OK) {
int localAction;
bool exitLoop = false;
do {
if (window->LockLooperWithTimeout(200000) < B_OK)
break;
BPoint where;
ulong buttons;
do {
snooze(40000);
GetMouse(&where, &buttons);
BMenuItem *menuItem = HitTestItems(where, B_ORIGIN);
if (menuItem) {
if (menuItem != NULL) {
SelectItem(menuItem);
BMenu *menu = menuItem->Submenu();
// TODO: Actually, this test shouldn't be needed, as
// all BMenuBar's BMenuItems are BMenus.
if (menu) {
if (menu != NULL) {
if (IsStickyPrefOn())
menu->SetStickyMode(true);
do {
@@ -421,19 +426,37 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
if (testItem != NULL && testItem != menuItem)
break;
resultItem = menu->_track((int *)action, startIndex);
// No need to keep the window locked for the
// whole time, as BMenu::_track() does its own locking.
window->Unlock();
// "action" is "5" when the BMenu is closed.
} while (*action != 5);
resultItem = menu->_track(&localAction, startIndex);
if (window->LockLooperWithTimeout(200000) < B_OK)
break;
// the returned action is "5" when the BMenu is closed.
} while (localAction != 5);
}
if (window->IsLocked()) {
SelectItem(NULL);
Invalidate();
}
} while (buttons != 0);
window->Unlock();
}
if (window->IsLocked())
window->Unlock();
snooze(40000);
if (buttons == 0)
exitLoop = true;
} while (!exitLoop);
if (action != NULL)
*action = static_cast<int>(localAction);
if (resultItem != NULL)
resultItem->Invoke();
@@ -445,9 +468,9 @@ void
BMenuBar::StealFocus()
{
BWindow *window = Window();
if (window && window->Lock()) {
if (window != NULL && window->Lock()) {
BView *focus = window->CurrentFocus();
if (focus)
if (focus != NULL)
fPrevFocusToken = _get_object_token_(focus);
MakeFocus();
window->Unlock();
@@ -459,7 +482,7 @@ void
BMenuBar::RestoreFocus()
{
BWindow *window = Window();
if (window && window->Lock()) {
if (window != NULL && window->Lock()) {
BHandler *handler = NULL;
if (BPrivate::gDefaultTokens.GetToken(fPrevFocusToken, B_HANDLER_TOKEN,
(void **)&handler, NULL) == B_OK) {