From b80eb9d443ee892b6c4e10a46112a76eab01124c Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 22 Mar 2006 20:47:52 +0000 Subject: [PATCH] Partially reverted axel's change, because it brings more troubles than benefits (menus lock when they reuse the supermenu's menuwindow). I'll try to resolve the various problems in another way. Some cleanups git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16861 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 79a26cd9eb..5e516010c2 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -7,7 +7,6 @@ * Stefano Ceccherini (burton666@libero.it) */ - #include #include @@ -1053,7 +1052,9 @@ BMenu::_show(bool selectFirstItem) // See if the supermenu has a cached menuwindow, // and use that one if possible. BMenuWindow *window = NULL; + if (fSuper != NULL) { + fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds()); window = fSuper->MenuWindow(); if (window != NULL) window->SetMenu(this); @@ -1068,19 +1069,22 @@ BMenu::_show(bool selectFirstItem) if (window == NULL) return false; - - window->Lock(); + + if (!window->IsLocked()) + window->Lock(); window->ChildAt(0)->AddChild(this); - if (fSuper != NULL) - fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds()); - // 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(); - window->Unlock(); + if (selectFirstItem) + SelectItem(ItemAt(0)); + + if (window->IsLocked()) + window->Unlock(); + return true; } @@ -1091,7 +1095,8 @@ BMenu::_hide() if (!LockLooper()) return; - BMenuWindow *menuWindow = fSuper ? fSuper->fCachedMenuWindow : NULL; + SelectItem(NULL); + BMenuWindow *window = static_cast(Window()); if (window == NULL) { // Huh? What did happen here? - we're trying to be on the safe side @@ -1103,10 +1108,13 @@ BMenu::_hide() window->ChildAt(0)->RemoveChild(this); // we don't want to be deleted when the window is removed - // Only quit if the window isn't cached. The cached menu window - // will be deleted at the end of BMenu::_track(). - if (menuWindow != window) + // Delete the menu window used by our submenus + DeleteMenuWindow(); + + if (Supermenu() == NULL) { + // It's our window. Quit it. window->Quit(); + } } @@ -1251,6 +1259,8 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *item, bool deleteItems) // and ignore index and count. Otherwise, we use them instead. if (item != NULL) { if (fItems.RemoveItem(item)) { + if (item == fSelected) + SelectItem(NULL); item->SetSuper(NULL); item->Uninstall(); if (deleteItems) @@ -1268,6 +1278,8 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *item, bool deleteItems) item = static_cast(fItems.ItemAt(i)); if (item != NULL) { if (fItems.RemoveItem(item)) { + if (item == fSelected) + SelectItem(NULL); item->SetSuper(NULL); item->Uninstall(); if (deleteItems)