From 7abe70f1b4ea54686c0a200b9087b958ddc94705 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 23 Mar 2006 15:33:28 +0000 Subject: [PATCH] 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 --- src/kits/interface/Menu.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 54570a43f0..b301d231c7 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -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(); } }