[UI Overhaul] Introduce LLMenuGL::insert from upstream and remove append/addChild wrappers in favor of insert
This commit is contained in:
@@ -2084,7 +2084,7 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory
|
|||||||
{
|
{
|
||||||
// SUBMENU
|
// SUBMENU
|
||||||
LLMenuGL *submenu = (LLMenuGL*)LLMenuGL::fromXML(child, parent, factory);
|
LLMenuGL *submenu = (LLMenuGL*)LLMenuGL::fromXML(child, parent, factory);
|
||||||
appendMenu(submenu, 0);
|
appendMenu(submenu);
|
||||||
if (LLMenuGL::sMenuContainer != NULL)
|
if (LLMenuGL::sMenuContainer != NULL)
|
||||||
{
|
{
|
||||||
submenu->updateParent(LLMenuGL::sMenuContainer);
|
submenu->updateParent(LLMenuGL::sMenuContainer);
|
||||||
@@ -2355,27 +2355,18 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This wrapper is needed because the virtual linkage causes errors if default parameters are used
|
|
||||||
bool LLMenuGL::addChild(LLView* view, S32 tab_group)
|
bool LLMenuGL::addChild(LLView* view, S32 tab_group)
|
||||||
{
|
|
||||||
return addChild(view, 0, tab_group);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LLMenuGL::addChild(LLView* view, LLView* insert_before, S32 tab_group)
|
|
||||||
{
|
{
|
||||||
if (LLMenuGL* menup = dynamic_cast<LLMenuGL*>(view))
|
if (LLMenuGL* menup = dynamic_cast<LLMenuGL*>(view))
|
||||||
{
|
{
|
||||||
lldebugs << "Adding menu " << menup->getName() << " to " << getName() << llendl;
|
lldebugs << "Adding menu " << menup->getName() << " to " << getName() << llendl;
|
||||||
if (!insert_before)
|
|
||||||
appendMenu(menup);
|
appendMenu(menup);
|
||||||
else
|
|
||||||
appendMenu(menup, insert_before);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (LLMenuItemGL* itemp = dynamic_cast<LLMenuItemGL*>(view))
|
else if (LLMenuItemGL* itemp = dynamic_cast<LLMenuItemGL*>(view))
|
||||||
{
|
{
|
||||||
lldebugs << "Adding " << itemp->getName() << " to " << getName() << llendl;
|
lldebugs << "Adding " << itemp->getName() << " to " << getName() << llendl;
|
||||||
append(itemp, insert_before);
|
append(itemp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
lldebugs << "Error adding unknown child '"<<(view ? view->getName() : std::string("NULL")) << "' to " << getName() << llendl;
|
lldebugs << "Error adding unknown child '"<<(view ? view->getName() : std::string("NULL")) << "' to " << getName() << llendl;
|
||||||
@@ -3110,7 +3101,60 @@ void LLMenuGL::empty( void )
|
|||||||
mArrowDownItem = NULL;
|
mArrowDownItem = NULL;
|
||||||
|
|
||||||
deleteAllChildren();
|
deleteAllChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
// erase group of items from menu
|
||||||
|
void LLMenuGL::erase( S32 begin, S32 end, bool arrange/* = true*/)
|
||||||
|
{
|
||||||
|
S32 items = mItems.size();
|
||||||
|
|
||||||
|
if ( items == 0 || begin >= end || begin < 0 || end > items )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
item_list_t::iterator start_position = mItems.begin();
|
||||||
|
std::advance(start_position, begin);
|
||||||
|
|
||||||
|
item_list_t::iterator end_position = mItems.begin();
|
||||||
|
std::advance(end_position, end);
|
||||||
|
|
||||||
|
for (item_list_t::iterator position_iter = start_position; position_iter != end_position; position_iter++)
|
||||||
|
{
|
||||||
|
LLUICtrl::removeChild(*position_iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
mItems.erase(start_position, end_position);
|
||||||
|
|
||||||
|
if (arrange)
|
||||||
|
{
|
||||||
|
needsArrange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add new item at position
|
||||||
|
void LLMenuGL::insert(S32 position, LLView* ctrl, bool arrange /*= true*/)
|
||||||
|
{
|
||||||
|
LLMenuItemGL* item = dynamic_cast<LLMenuItemGL *>(ctrl);
|
||||||
|
|
||||||
|
if (NULL == item || position < 0 || (U32)position >= mItems.size())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
item_list_t::iterator position_iter = mItems.begin();
|
||||||
|
std::advance(position_iter, position);
|
||||||
|
insert(position_iter, item, arrange);
|
||||||
|
}
|
||||||
|
void LLMenuGL::insert(item_list_t::iterator position_iter, LLMenuItemGL* item, bool arrange /*= true*/)
|
||||||
|
{
|
||||||
|
mItems.insert(position_iter, item);
|
||||||
|
LLUICtrl::addChild(item);
|
||||||
|
|
||||||
|
if (arrange)
|
||||||
|
{
|
||||||
|
needsArrange();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust rectangle of the menu
|
// Adjust rectangle of the menu
|
||||||
@@ -3142,29 +3186,10 @@ BOOL LLMenuGL::handleJumpKey(KEY key)
|
|||||||
|
|
||||||
|
|
||||||
// Add the menu item to this menu.
|
// Add the menu item to this menu.
|
||||||
// This wrapper is needed because the virtual linkage causes errors if default parameters are used
|
|
||||||
BOOL LLMenuGL::append( LLMenuItemGL* item )
|
BOOL LLMenuGL::append( LLMenuItemGL* item )
|
||||||
{
|
|
||||||
return append(item, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL LLMenuGL::append(LLMenuItemGL* item, LLView* insert_before)
|
|
||||||
{
|
{
|
||||||
if (!item) return FALSE;
|
if (!item) return FALSE;
|
||||||
if (!insert_before)
|
|
||||||
{
|
|
||||||
mItems.push_back( item );
|
mItems.push_back( item );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item_list_t::iterator i;
|
|
||||||
|
|
||||||
for (i = mItems.begin(); i != mItems.end(); ++i)
|
|
||||||
if (*i == insert_before)
|
|
||||||
break;
|
|
||||||
mItems.insert(i, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
LLUICtrl::addChild(item);
|
LLUICtrl::addChild(item);
|
||||||
needsArrange();
|
needsArrange();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -3178,13 +3203,7 @@ BOOL LLMenuGL::addSeparator()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add a menu - this will create a cascading menu
|
// add a menu - this will create a cascading menu
|
||||||
// This wrapper is needed because the virtual linkage causes errors if default parameters are used
|
|
||||||
BOOL LLMenuGL::appendMenu( LLMenuGL* menu )
|
BOOL LLMenuGL::appendMenu( LLMenuGL* menu )
|
||||||
{
|
|
||||||
return appendMenu(menu, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL LLMenuGL::appendMenu(LLMenuGL* menu, LLView* insert_before)
|
|
||||||
{
|
{
|
||||||
if( menu == this )
|
if( menu == this )
|
||||||
{
|
{
|
||||||
@@ -3196,7 +3215,7 @@ BOOL LLMenuGL::appendMenu(LLMenuGL* menu, LLView* insert_before)
|
|||||||
LLMenuItemBranchGL* branch = NULL;
|
LLMenuItemBranchGL* branch = NULL;
|
||||||
branch = new LLMenuItemBranchGL( menu->getName(), menu->getLabel(), menu->getHandle() );
|
branch = new LLMenuItemBranchGL( menu->getName(), menu->getLabel(), menu->getHandle() );
|
||||||
branch->setJumpKey(menu->getJumpKey());
|
branch->setJumpKey(menu->getJumpKey());
|
||||||
success &= append( branch, insert_before );
|
success &= append( branch );
|
||||||
|
|
||||||
// Inherit colors
|
// Inherit colors
|
||||||
menu->setBackgroundColor( mBackgroundColor );
|
menu->setBackgroundColor( mBackgroundColor );
|
||||||
|
|||||||
@@ -475,8 +475,6 @@ public:
|
|||||||
/*virtual*/ void removeChild( LLView* ctrl);
|
/*virtual*/ void removeChild( LLView* ctrl);
|
||||||
/*virtual*/ BOOL postBuild();
|
/*virtual*/ BOOL postBuild();
|
||||||
|
|
||||||
bool addChild(LLView* view, LLView* insert_before, S32 tab_group = 0);
|
|
||||||
|
|
||||||
virtual BOOL handleAcceleratorKey(KEY key, MASK mask);
|
virtual BOOL handleAcceleratorKey(KEY key, MASK mask);
|
||||||
|
|
||||||
LLMenuGL* getChildMenuByName(const std::string& name, BOOL recurse) const;
|
LLMenuGL* getChildMenuByName(const std::string& name, BOOL recurse) const;
|
||||||
@@ -530,6 +528,16 @@ public:
|
|||||||
// remove all items on the menu
|
// remove all items on the menu
|
||||||
void empty( void );
|
void empty( void );
|
||||||
|
|
||||||
|
// erase group of items from menu
|
||||||
|
void erase(S32 begin, S32 end, bool arrange = true);
|
||||||
|
|
||||||
|
// add new item at position
|
||||||
|
void insert(S32 begin, LLView* ctrl, bool arrange = true);
|
||||||
|
void insert(std::list<LLMenuItemGL*>::iterator position_iter, LLMenuItemGL* item, bool arrange = true);
|
||||||
|
|
||||||
|
// find an item's position
|
||||||
|
std::list<LLMenuItemGL*>::iterator find(LLMenuItemGL* item) { return std::find(mItems.begin(), mItems.end(), item); }
|
||||||
|
|
||||||
void setItemLastSelected(LLMenuItemGL* item); // must be in menu
|
void setItemLastSelected(LLMenuItemGL* item); // must be in menu
|
||||||
U32 getItemCount(); // number of menu items
|
U32 getItemCount(); // number of menu items
|
||||||
LLMenuItemGL* getItem(S32 number); // 0 = first item
|
LLMenuItemGL* getItem(S32 number); // 0 = first item
|
||||||
|
|||||||
@@ -9551,18 +9551,20 @@ void parse_simulator_features()
|
|||||||
{
|
{
|
||||||
std::string insertMarker = "insert_" + i->first;
|
std::string insertMarker = "insert_" + i->first;
|
||||||
|
|
||||||
LLView* marker = gMenuBarView->getChildView(insertMarker, true, false);
|
LLMenuItemGL* marker = gMenuBarView->findChild<LLMenuItemGL>(insertMarker);
|
||||||
if (!marker) continue;
|
if (!marker) continue;
|
||||||
|
|
||||||
LLMenuGL* menu = dynamic_cast<LLMenuGL*>(marker->getParent());
|
LLMenuGL* menu = dynamic_cast<LLMenuGL*>(marker->getParent());
|
||||||
if (!menu) continue;
|
if (!menu) continue;
|
||||||
|
|
||||||
|
std::list<LLMenuItemGL*>::iterator it = menu->find(marker);
|
||||||
|
|
||||||
for (LLSD::map_iterator j = i->second.beginMap(); j != i->second.endMap(); ++j)
|
for (LLSD::map_iterator j = i->second.beginMap(); j != i->second.endMap(); ++j)
|
||||||
{
|
{
|
||||||
LLMenuItemCallGL* custom = new LLMenuItemCallGL(j->second.asString(), j->first, custom_selected);
|
LLMenuItemCallGL* custom = new LLMenuItemCallGL(j->second.asString(), j->first, custom_selected);
|
||||||
custom->setUserData(custom);
|
custom->setUserData(custom);
|
||||||
gCustomMenuItems.push_back(custom);
|
gCustomMenuItems.push_back(custom);
|
||||||
menu->addChild(custom, marker);
|
menu->insert(it, custom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user