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