#2471 The Destinations ComboBox on Login Screen changes the selected item to the similar one

meow-7.2.2
Alexander Gavriliuk 2024-09-02 18:22:54 +02:00 committed by Guru
parent 12d60b3d9b
commit 470f35b109
3 changed files with 113 additions and 98 deletions

View File

@ -107,7 +107,7 @@ LLComboBox::LLComboBox(const LLComboBox::Params& p)
button_params.follows.flags(FOLLOWS_LEFT|FOLLOWS_BOTTOM|FOLLOWS_RIGHT);
button_params.rect(p.rect);
if(mAllowTextEntry)
if (mAllowTextEntry)
{
button_params.pad_right(2);
}
@ -121,7 +121,7 @@ LLComboBox::LLComboBox(const LLComboBox::Params& p)
mButton = LLUICtrlFactory::create<LLButton>(button_params);
if(mAllowTextEntry)
if (mAllowTextEntry)
{
//redo to compensate for button hack that leaves space for a character
//unless it is a "minimal combobox"(drop down)
@ -207,14 +207,27 @@ void LLComboBox::clear()
void LLComboBox::onCommit()
{
if (mAllowTextEntry && getCurrentIndex() != -1)
if (LLScrollListItem* item = mList->getFirstSelected())
{
// we have selected an existing item, blitz the manual text entry with
// the properly capitalized item
mTextEntry->setValue(getSimple());
mTextEntry->setTentative(false);
if (mAllowTextEntry && mTextEntry)
{
// we have selected an existing item, blitz the manual text entry with
// the properly capitalized item
LLSD label = item->getColumn(0)->getValue();
mTextEntry->setValue(label);
mTextEntry->setTentative(false);
}
setControlValue(item->getValue());
}
setControlValue(getValue());
else if (mAllowTextEntry)
{
setControlValue(mTextEntry->getValue());
}
else
{
setControlValue(LLSD());
}
LLUICtrl::onCommit();
}
@ -349,6 +362,13 @@ bool LLComboBox::setSimple(const LLStringExplicit& name)
// virtual
void LLComboBox::setValue(const LLSD& value)
{
if (LLScrollListItem* item = mList->getFirstSelected())
{
LLSD item_value = item->getValue();
if (item_value.asStringRef() == value.asStringRef())
return;
}
bool found = mList->selectByValue(value);
if (found)
{
@ -372,10 +392,8 @@ const std::string LLComboBox::getSimple() const
{
return mTextEntry->getText();
}
else
{
return res;
}
return res;
}
const std::string LLComboBox::getSelectedItemLabel(S32 column) const
@ -386,24 +404,22 @@ const std::string LLComboBox::getSelectedItemLabel(S32 column) const
// virtual
LLSD LLComboBox::getValue() const
{
LLScrollListItem* item = mList->getFirstSelected();
if( item )
if (LLScrollListItem* item = mList->getFirstSelected())
{
return item->getValue();
}
else if (mAllowTextEntry)
if (mAllowTextEntry)
{
return mTextEntry->getValue();
}
else
{
return LLSD();
}
return LLSD();
}
void LLComboBox::setLabel(const LLStringExplicit& name)
{
if ( mTextEntry )
if (mTextEntry)
{
mTextEntry->setText(name);
if (mList->selectItemByLabel(name, false))
@ -500,13 +516,23 @@ void LLComboBox::setButtonVisible(bool visible)
bool LLComboBox::setCurrentByIndex(S32 index)
{
bool found = mList->selectNthItem(index);
if (found)
if (LLScrollListItem* item = mList->getItemByIndex(index))
{
setLabel(getSelectedItemLabel());
mLastSelectedIndex = index;
if (item->getEnabled())
{
mList->selectItem(item, -1, true);
if (mTextEntry)
{
LLSD::String label = item->getColumn(0)->getValue().asString();
mTextEntry->setText(label);
mTextEntry->setTentative(false);
}
mLastSelectedIndex = index;
return true;
}
}
return found;
return false;
}
S32 LLComboBox::getCurrentIndex() const

View File

@ -410,10 +410,8 @@ void LLScrollListCtrl::clearRows()
LLScrollListItem* LLScrollListCtrl::getFirstSelected() const
{
item_list::const_iterator iter;
for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
for (LLScrollListItem* item : mItemList)
{
LLScrollListItem* item = *iter;
if (item->getSelected())
{
return item;
@ -425,10 +423,8 @@ LLScrollListItem* LLScrollListCtrl::getFirstSelected() const
std::vector<LLScrollListItem*> LLScrollListCtrl::getAllSelected() const
{
std::vector<LLScrollListItem*> ret;
item_list::const_iterator iter;
for(iter = mItemList.begin(); iter != mItemList.end(); iter++)
for (LLScrollListItem* item : mItemList)
{
LLScrollListItem* item = *iter;
if (item->getSelected())
{
ret.push_back(item);
@ -441,9 +437,8 @@ S32 LLScrollListCtrl::getNumSelected() const
{
S32 numSelected = 0;
for(item_list::const_iterator iter = mItemList.begin(); iter != mItemList.end(); ++iter)
for (LLScrollListItem* item : mItemList)
{
LLScrollListItem* item = *iter;
if (item->getSelected())
{
++numSelected;
@ -460,10 +455,8 @@ S32 LLScrollListCtrl::getFirstSelectedIndex() const
// make sure sort is up to date before returning an index
updateSort();
item_list::const_iterator iter;
for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
for (LLScrollListItem* item : mItemList)
{
LLScrollListItem* item = *iter;
if (item->getSelected())
{
return CurSelectedIndex;
@ -476,29 +469,19 @@ S32 LLScrollListCtrl::getFirstSelectedIndex() const
LLScrollListItem* LLScrollListCtrl::getFirstData() const
{
if (mItemList.size() == 0)
{
return NULL;
}
return mItemList[0];
return mItemList.empty() ? NULL : mItemList.front();
}
LLScrollListItem* LLScrollListCtrl::getLastData() const
{
if (mItemList.size() == 0)
{
return NULL;
}
return mItemList[mItemList.size() - 1];
return mItemList.empty() ? NULL : mItemList.back();
}
std::vector<LLScrollListItem*> LLScrollListCtrl::getAllData() const
{
std::vector<LLScrollListItem*> ret;
item_list::const_iterator iter;
for(iter = mItemList.begin(); iter != mItemList.end(); iter++)
for (LLScrollListItem* item : mItemList)
{
LLScrollListItem* item = *iter;
ret.push_back(item);
}
return ret;
@ -507,22 +490,20 @@ std::vector<LLScrollListItem*> LLScrollListCtrl::getAllData() const
// returns first matching item
LLScrollListItem* LLScrollListCtrl::getItem(const LLSD& sd) const
{
std::string string_val = sd.asString();
const std::string& string_val = sd.asStringRef();
item_list::const_iterator iter;
for(iter = mItemList.begin(); iter != mItemList.end(); iter++)
for (LLScrollListItem* item : mItemList)
{
LLScrollListItem* item = *iter;
// assumes string representation is good enough for comparison
if (item->getValue().asString() == string_val)
if (item->getValue().asStringRef() == string_val)
{
return item;
}
}
return NULL;
}
void LLScrollListCtrl::reshape( S32 width, S32 height, bool called_from_parent )
{
LLUICtrl::reshape( width, height, called_from_parent );
@ -567,15 +548,16 @@ void LLScrollListCtrl::updateLayout()
void LLScrollListCtrl::fitContents(S32 max_width, S32 max_height)
{
S32 height = llmin( getRequiredRect().getHeight(), max_height );
if(mPageLines)
height = llmin( mPageLines * mLineHeight + 2*mBorderThickness + (mDisplayColumnHeaders ? mHeadingHeight : 0), height );
if (mPageLines)
{
height = llmin(mPageLines * mLineHeight + 2 * mBorderThickness + (mDisplayColumnHeaders ? mHeadingHeight : 0), height);
}
S32 width = getRect().getWidth();
reshape( width, height );
}
LLRect LLScrollListCtrl::getRequiredRect()
{
S32 heading_size = (mDisplayColumnHeaders ? mHeadingHeight : 0);
@ -627,7 +609,8 @@ bool LLScrollListCtrl::addItem( LLScrollListItem* item, EAddPosition pos, bool r
S32 i = 0;
for (LLScrollListCell* cell = item->getColumn(i); i < num_cols; cell = item->getColumn(++i))
{
if (i >= (S32)mColumnsIndexed.size()) break;
if (i >= (S32)mColumnsIndexed.size())
break;
cell->setWidth(mColumnsIndexed[i]->getWidth());
}
@ -650,23 +633,21 @@ S32 LLScrollListCtrl::calcMaxContentWidth()
S32 max_item_width = 0;
ordered_columns_t::iterator column_itor;
for (column_itor = mColumnsIndexed.begin(); column_itor != mColumnsIndexed.end(); ++column_itor)
for (LLScrollListColumn* column : mColumnsIndexed)
{
LLScrollListColumn* column = *column_itor;
if (!column) continue;
if (!column)
continue;
if (mColumnWidthsDirty)
{
// update max content width for this column, by looking at all items
column->mMaxContentWidth = column->mHeader ? LLFontGL::getFontSansSerifSmall()->getWidth(column->mLabel.getWString().c_str()) + mColumnPadding + HEADING_TEXT_PADDING : 0;
item_list::iterator iter;
for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
for (LLScrollListItem* item : mItemList)
{
LLScrollListCell* cellp = (*iter)->getColumn(column->mIndex);
if (!cellp) continue;
column->mMaxContentWidth = llmax(LLFontGL::getFontSansSerifSmall()->getWidth(cellp->getValue().asString()) + mColumnPadding + COLUMN_TEXT_PADDING, column->mMaxContentWidth);
if (LLScrollListCell* cellp = item->getColumn(column->mIndex))
{
column->mMaxContentWidth = llmax(LLFontGL::getFontSansSerifSmall()->getWidth(cellp->getValue().asString()) + mColumnPadding + COLUMN_TEXT_PADDING, column->mMaxContentWidth);
}
}
}
max_item_width += column->mMaxContentWidth;
@ -683,7 +664,8 @@ bool LLScrollListCtrl::updateColumnWidths()
for (column_itor = mColumnsIndexed.begin(); column_itor != mColumnsIndexed.end(); ++column_itor)
{
LLScrollListColumn* column = *column_itor;
if (!column) continue;
if (!column)
continue;
// update column width
S32 new_width = 0;
@ -737,7 +719,6 @@ void LLScrollListCtrl::updateLineHeightInsert(LLScrollListItem* itemp)
}
}
void LLScrollListCtrl::updateColumns(bool force_update)
{
if (!mColumnsDirty && !force_update)
@ -810,7 +791,8 @@ void LLScrollListCtrl::updateColumns(bool force_update)
S32 i = 0;
for (LLScrollListCell* cell = itemp->getColumn(i); i < num_cols; cell = itemp->getColumn(++i))
{
if (i >= (S32)mColumnsIndexed.size()) break;
if (i >= (S32)mColumnsIndexed.size())
break;
cell->setWidth(mColumnsIndexed[i]->getWidth());
}
@ -837,8 +819,8 @@ void LLScrollListCtrl::setHeadingHeight(S32 heading_height)
mHeadingHeight = heading_height;
updateLayout();
}
void LLScrollListCtrl::setPageLines(S32 new_page_lines)
{
mPageLines = new_page_lines;
@ -880,6 +862,7 @@ bool LLScrollListCtrl::selectFirstItem()
}
first_item = false;
}
if (mCommitOnSelectionChange)
{
commitIfChanged();
@ -1169,7 +1152,6 @@ void LLScrollListCtrl::selectPrevItem( bool extend_selection)
mSearchString.clear();
}
void LLScrollListCtrl::selectNextItem( bool extend_selection)
{
LLScrollListItem* next_item = NULL;
@ -1213,8 +1195,6 @@ void LLScrollListCtrl::selectNextItem( bool extend_selection)
mSearchString.clear();
}
void LLScrollListCtrl::deselectAllItems(bool no_commit_on_change)
{
item_list::iterator iter;
@ -1286,16 +1266,14 @@ LLScrollListItem* LLScrollListCtrl::getItemByLabel(const std::string& label, boo
LLStringUtil::toLower(target_text);
}
item_list::iterator iter;
for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
for (LLScrollListItem* item : mItemList)
{
LLScrollListItem* item = *iter;
std::string item_text = item->getColumn(column)->getValue().asString(); // Only select enabled items with matching names
if (!case_sensitive)
{
LLStringUtil::toLower(item_text);
}
if(item_text == target_text)
if (item_text == target_text)
{
return item;
}
@ -1303,6 +1281,15 @@ LLScrollListItem* LLScrollListCtrl::getItemByLabel(const std::string& label, boo
return NULL;
}
LLScrollListItem* LLScrollListCtrl::getItemByIndex(S32 index)
{
if (index >= 0 && index < (S32)mItemList.size())
{
return mItemList[index];
}
return NULL;
}
bool LLScrollListCtrl::selectItemByPrefix(const std::string& target, bool case_sensitive, S32 column)
{
@ -1463,7 +1450,7 @@ U32 LLScrollListCtrl::searchItems(const LLWString& substring, bool case_sensitiv
return found;
}
const std::string LLScrollListCtrl::getSelectedItemLabel(S32 column) const
std::string LLScrollListCtrl::getSelectedItemLabel(S32 column) const
{
LLScrollListItem* item;
@ -1507,7 +1494,10 @@ bool LLScrollListCtrl::setSelectedByValue(const LLSD& value, bool selected)
{
bool found = false;
if (selected && !mAllowMultipleSelection) deselectAllItems(true);
if (selected && !mAllowMultipleSelection)
{
deselectAllItems(true);
}
item_list::iterator iter;
for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
@ -2634,9 +2624,7 @@ bool LLScrollListCtrl::isRepeatedChars(const LLWString& string) const
void LLScrollListCtrl::selectItem(LLScrollListItem* itemp, S32 cell, bool select_single_item)
{
if (!itemp) return;
if (!itemp->getSelected())
if (itemp && !itemp->getSelected())
{
if (mLastSelected)
{
@ -2670,9 +2658,7 @@ void LLScrollListCtrl::selectItem(LLScrollListItem* itemp, S32 cell, bool select
void LLScrollListCtrl::deselectItem(LLScrollListItem* itemp)
{
if (!itemp) return;
if (itemp->getSelected())
if (itemp && itemp->getSelected())
{
if (mLastSelected == itemp)
{
@ -2878,7 +2864,7 @@ void LLScrollListCtrl::updateStaticColumnWidth(LLScrollListColumn* col, S32 new_
// LLEditMenuHandler functions
// virtual
void LLScrollListCtrl::copy()
void LLScrollListCtrl::copy()
{
std::string buffer;
@ -2892,26 +2878,26 @@ void LLScrollListCtrl::copy()
}
// virtual
bool LLScrollListCtrl::canCopy() const
bool LLScrollListCtrl::canCopy() const
{
return (getFirstSelected() != NULL);
}
// virtual
void LLScrollListCtrl::cut()
void LLScrollListCtrl::cut()
{
copy();
doDelete();
}
// virtual
bool LLScrollListCtrl::canCut() const
bool LLScrollListCtrl::canCut() const
{
return canCopy() && canDoDelete();
}
// virtual
void LLScrollListCtrl::selectAll()
void LLScrollListCtrl::selectAll()
{
// Deselects all other items
item_list::iterator iter;
@ -2931,13 +2917,13 @@ void LLScrollListCtrl::selectAll()
}
// virtual
bool LLScrollListCtrl::canSelectAll() const
bool LLScrollListCtrl::canSelectAll() const
{
return getCanSelect() && mAllowMultipleSelection && !(mMaxSelectable > 0 && mItemList.size() > mMaxSelectable);
}
// virtual
void LLScrollListCtrl::deselect()
void LLScrollListCtrl::deselect()
{
deselectAllItems();
}

View File

@ -260,11 +260,12 @@ public:
// one of which can be selected at a time.
virtual LLScrollListItem* addSimpleElement(const std::string& value, EAddPosition pos = ADD_BOTTOM, const LLSD& id = LLSD());
bool selectItemByLabel( const std::string& item, bool case_sensitive = true, S32 column = 0 ); // false if item not found
bool selectItemByLabel(const std::string& item, bool case_sensitive = true, S32 column = 0); // false if item not found
bool selectItemByPrefix(const std::string& target, bool case_sensitive = true, S32 column = -1);
bool selectItemByPrefix(const LLWString& target, bool case_sensitive = true, S32 column = -1);
LLScrollListItem* getItemByLabel( const std::string& item, bool case_sensitive = true, S32 column = 0 );
const std::string getSelectedItemLabel(S32 column = 0) const;
LLScrollListItem* getItemByLabel(const std::string& item, bool case_sensitive = true, S32 column = 0);
LLScrollListItem* getItemByIndex(S32 index);
std::string getSelectedItemLabel(S32 column = 0) const;
LLSD getSelectedValue();
// If multi select is on, select all element that include substring,
@ -559,6 +560,8 @@ private:
sort_signal_t* mSortCallback;
is_friend_signal_t* mIsFriendSignal;
friend class LLComboBox;
}; // end class LLScrollListCtrl
#endif // LL_SCROLLLISTCTRL_H