Hopefully cleaned up a bit the locking in BMenu::_show()/_hide()

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16867 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-03-23 15:33:28 +00:00
parent cfa91cc4cb
commit 7abe70f1b4

View File

@ -1056,12 +1056,15 @@ BMenu::_show(bool selectFirstItem)
if (fSuper != NULL) {
fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds());
window = fSuper->MenuWindow();
if (window != NULL)
if (window != NULL && window->Lock()) {
window->SetMenu(this);
window->Unlock();
}
}
// Otherwise, create a new one
// Actually, I think this can only happen for
// "stand alone" BPopUpMenus (i.e. not within a BMenuField)
// This happens for "stand alone" BPopUpMenus
// (i.e. not within a BMenuField)
if (window == NULL) {
// Menu windows get the BMenu's handler name
window = new BMenuWindow(Name(), this);
@ -1070,20 +1073,19 @@ BMenu::_show(bool selectFirstItem)
if (window == NULL)
return false;
if (!window->IsLocked())
window->Lock();
window->ChildAt(0)->AddChild(this);
if (window->Lock()) {
window->ChildAt(0)->AddChild(this);
// TODO: for some reason, Window() can already be NULL at this point,
// which causes a crash in one of the following functions...
UpdateWindowViewSize();
window->Show();
// TODO: for some reason, Window() can already be NULL at this point,
// which causes a crash in one of the following functions...
UpdateWindowViewSize();
window->Show();
if (selectFirstItem)
SelectItem(ItemAt(0));
if (window->IsLocked())
if (selectFirstItem)
SelectItem(ItemAt(0));
window->Unlock();
}
return true;
}
@ -1114,6 +1116,10 @@ BMenu::_hide()
if (Supermenu() == NULL) {
// It's our window. Quit it.
window->Quit();
} else {
// _show() expects the window to be unlocked
// (UnlockLooper() won't work as we are no longer attached)
window->Unlock();
}
}