From 987a07492e853e3bd360d2311e2ed969aec305cc Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 2 Jul 2025 14:23:32 -0400 Subject: [PATCH] BMenu: Automatically invoke _Install and _Uninstall in Attached/Detached. This way, we can't inadvertently end up in a state where the window is deleted but some things are still attached to it. Fixes #19662. Change-Id: I3ce7b5ccffc8cf12670209f3023613b32e31c41c Reviewed-on: https://review.haiku-os.org/c/haiku/+/9437 Reviewed-by: waddlesplash Reviewed-by: John Scipione --- src/kits/interface/Menu.cpp | 11 ++++++----- src/kits/interface/MenuBar.cpp | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 8091e90e7d..0de83fa3a7 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -415,6 +415,9 @@ BMenu::AttachedToWindow() _GetOptionKey(sOptionKey); _GetMenuKey(sMenuKey); + if (Superitem() == NULL) + _Install(Window()); + // The menu should be added to the menu hierarchy and made visible if: // * the mouse is over the menu, // * the user has requested the menu via the keyboard. @@ -436,6 +439,9 @@ void BMenu::DetachedFromWindow() { BView::DetachedFromWindow(); + + if (Superitem() == NULL) + _Uninstall(); } @@ -1383,7 +1389,6 @@ BMenu::Show() void BMenu::Show(bool selectFirst) { - _Install(NULL); _Show(selectFirst); } @@ -1391,7 +1396,6 @@ BMenu::Show(bool selectFirst) void BMenu::Hide() { - _Uninstall(); _Hide(); } @@ -1648,9 +1652,6 @@ BMenu::_Show(bool selectFirstItem, bool keyDown) return false; } - if (ourWindow) - _Install(window); - _UpdateWindowViewSize(true); window->Show(); diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index 19fd364dce..edca4c98d6 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -140,7 +140,6 @@ BMenuBar::Archive(BMessage* data, bool deep) const void BMenuBar::AttachedToWindow() { - _Install(Window()); Window()->SetKeyMenuBar(this); BMenu::AttachedToWindow();