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 <[email protected]>
Reviewed-by: John Scipione <[email protected]>
This commit is contained in:
Augustin Cavalier
2025-07-02 18:39:25 +00:00
committed by waddlesplash
parent 45f3d65457
commit 987a07492e
2 changed files with 6 additions and 6 deletions
+6 -5
View File
@@ -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();
-1
View File
@@ -140,7 +140,6 @@ BMenuBar::Archive(BMessage* data, bool deep) const
void
BMenuBar::AttachedToWindow()
{
_Install(Window());
Window()->SetKeyMenuBar(this);
BMenu::AttachedToWindow();