Skip to content
Snippets Groups Projects
Commit 3ad48cb8 authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Fix leak of context menu branch menus

parent 34da181e
No related branches found
No related tags found
No related merge requests found
...@@ -3990,25 +3990,39 @@ void LLTearOffMenu::closeTearOff() ...@@ -3990,25 +3990,39 @@ void LLTearOffMenu::closeTearOff()
} }
LLContextMenuBranch::LLContextMenuBranch(const LLContextMenuBranch::Params& p) LLContextMenuBranch::LLContextMenuBranch(const LLContextMenuBranch::Params& p)
: LLMenuItemGL(p), : LLMenuItemGL(p)
mBranch( p.branch()->getHandle() ) {
LLContextMenu* branch = static_cast<LLContextMenu*>(p.branch);
if (branch)
{ {
mBranch.get()->hide(); mBranchHandle = branch->getHandle();
mBranch.get()->setParentMenuItem(this); branch->hide();
branch->setParentMenuItem(this);
}
}
LLContextMenuBranch::~LLContextMenuBranch()
{
if (mBranchHandle.get())
{
mBranchHandle.get()->die();
}
} }
// called to rebuild the draw label // called to rebuild the draw label
void LLContextMenuBranch::buildDrawLabel( void ) void LLContextMenuBranch::buildDrawLabel( void )
{ {
auto menu = getBranch();
if (menu)
{ {
// default enablement is this -- if any of the subitems are // default enablement is this -- if any of the subitems are
// enabled, this item is enabled. JC // enabled, this item is enabled. JC
U32 sub_count = mBranch.get()->getItemCount(); U32 sub_count = menu->getItemCount();
U32 i; U32 i;
BOOL any_enabled = FALSE; BOOL any_enabled = FALSE;
for (i = 0; i < sub_count; i++) for (i = 0; i < sub_count; i++)
{ {
LLMenuItemGL* item = mBranch.get()->getItem(i); LLMenuItemGL* item = menu->getItem(i);
item->buildDrawLabel(); item->buildDrawLabel();
if (item->getEnabled() && !item->getDrawTextDisabled() ) if (item->getEnabled() && !item->getDrawTextDisabled() )
{ {
...@@ -4030,13 +4044,17 @@ void LLContextMenuBranch::buildDrawLabel( void ) ...@@ -4030,13 +4044,17 @@ void LLContextMenuBranch::buildDrawLabel( void )
void LLContextMenuBranch::showSubMenu() void LLContextMenuBranch::showSubMenu()
{ {
LLMenuItemGL* menu_item = mBranch.get()->getParentMenuItem(); auto menu = getBranch();
if(menu)
{
LLMenuItemGL* menu_item = menu->getParentMenuItem();
if (menu_item != NULL && menu_item->getVisible()) if (menu_item != NULL && menu_item->getVisible())
{ {
S32 center_x; S32 center_x;
S32 center_y; S32 center_y;
localPointToScreen(getRect().getWidth(), getRect().getHeight(), &center_x, &center_y); localPointToScreen(getRect().getWidth(), getRect().getHeight(), &center_x, &center_y);
mBranch.get()->show(center_x, center_y); menu->show(center_x, center_y);
}
} }
} }
...@@ -4050,13 +4068,17 @@ void LLContextMenuBranch::setHighlight( BOOL highlight ) ...@@ -4050,13 +4068,17 @@ void LLContextMenuBranch::setHighlight( BOOL highlight )
{ {
if (highlight == getHighlight()) return; if (highlight == getHighlight()) return;
LLMenuItemGL::setHighlight(highlight); LLMenuItemGL::setHighlight(highlight);
auto menu = getBranch();
if (menu)
{
if (highlight) if (highlight)
{ {
showSubMenu(); showSubMenu();
} }
else else
{ {
mBranch.get()->hide(); menu->hide();
}
} }
} }
......
...@@ -735,8 +735,7 @@ class LLContextMenuBranch : public LLMenuItemGL ...@@ -735,8 +735,7 @@ class LLContextMenuBranch : public LLMenuItemGL
LLContextMenuBranch(const Params&); LLContextMenuBranch(const Params&);
virtual ~LLContextMenuBranch() virtual ~LLContextMenuBranch();
{}
// called to rebuild the draw label // called to rebuild the draw label
virtual void buildDrawLabel( void ); virtual void buildDrawLabel( void );
...@@ -744,13 +743,13 @@ class LLContextMenuBranch : public LLMenuItemGL ...@@ -744,13 +743,13 @@ class LLContextMenuBranch : public LLMenuItemGL
// onCommit() - do the primary funcationality of the menu item. // onCommit() - do the primary funcationality of the menu item.
virtual void onCommit( void ); virtual void onCommit( void );
LLContextMenu* getBranch() { return mBranch.get(); } LLContextMenu* getBranch() { return mBranchHandle.get(); }
void setHighlight( BOOL highlight ); void setHighlight( BOOL highlight );
protected: protected:
void showSubMenu(); void showSubMenu();
LLHandle<LLContextMenu> mBranch; LLHandle<LLContextMenu> mBranchHandle;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment