diff options
author | Andrey Lihatskiy <alihatskiy@productengine.com> | 2024-09-04 13:51:31 +0300 |
---|---|---|
committer | Andrey Lihatskiy <alihatskiy@productengine.com> | 2024-09-04 13:51:31 +0300 |
commit | e5bcd6f50a8247dde1121210150835d968dc214d (patch) | |
tree | 27f2d17c397bbebc1a1071248b63dc6d33a43cb7 /indra/llui/llscrolllistctrl.cpp | |
parent | e25d23aaac77f3793207aa0baf59ae64ea5eba41 (diff) | |
parent | 2fc8d5ff3cfa1b9ad00b310cd4a6cdb557b9415c (diff) |
Merge branch 'develop' into marchcat/b-develop
# Conflicts:
# indra/llcommon/llerror.h
Diffstat (limited to 'indra/llui/llscrolllistctrl.cpp')
-rw-r--r-- | indra/llui/llscrolllistctrl.cpp | 148 |
1 files changed, 65 insertions, 83 deletions
diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp index e711a6ed1b..445377d3a2 100644 --- a/indra/llui/llscrolllistctrl.cpp +++ b/indra/llui/llscrolllistctrl.cpp @@ -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(); @@ -889,13 +872,13 @@ bool LLScrollListCtrl::selectFirstItem() // Deselects all other items // virtual -bool LLScrollListCtrl::selectNthItem( S32 target_index ) +bool LLScrollListCtrl::selectNthItem(S32 target_index) { return selectItemRange(target_index, target_index); } // virtual -bool LLScrollListCtrl::selectItemRange( S32 first_index, S32 last_index ) +bool LLScrollListCtrl::selectItemRange(S32 first_index, S32 last_index) { if (mItemList.empty()) { @@ -905,28 +888,24 @@ bool LLScrollListCtrl::selectItemRange( S32 first_index, S32 last_index ) // make sure sort is up to date updateSort(); - S32 listlen = (S32)mItemList.size(); - first_index = llclamp(first_index, 0, listlen-1); - - if (last_index < 0) - last_index = listlen-1; - else - last_index = llclamp(last_index, first_index, listlen-1); + S32 bottom = (S32)mItemList.size() - 1; + first_index = llclamp(first_index, 0, bottom); + last_index = last_index < 0 ? bottom : llclamp(last_index, first_index, bottom); bool success = false; S32 index = 0; for (item_list::iterator iter = mItemList.begin(); iter != mItemList.end(); ) { LLScrollListItem *itemp = *iter; - if(!itemp) + if (!itemp) { iter = mItemList.erase(iter); - continue ; + continue; } - if( index >= first_index && index <= last_index ) + if (index >= first_index && index <= last_index) { - if( itemp->getEnabled() ) + if (itemp->getEnabled()) { // TODO: support range selection for cells selectItem(itemp, -1, false); @@ -1173,7 +1152,6 @@ void LLScrollListCtrl::selectPrevItem( bool extend_selection) mSearchString.clear(); } - void LLScrollListCtrl::selectNextItem( bool extend_selection) { LLScrollListItem* next_item = NULL; @@ -1217,8 +1195,6 @@ void LLScrollListCtrl::selectNextItem( bool extend_selection) mSearchString.clear(); } - - void LLScrollListCtrl::deselectAllItems(bool no_commit_on_change) { item_list::iterator iter; @@ -1290,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; } @@ -1307,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) { @@ -1467,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; @@ -1511,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++) @@ -2638,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) { @@ -2674,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) { @@ -2882,7 +2864,7 @@ void LLScrollListCtrl::updateStaticColumnWidth(LLScrollListColumn* col, S32 new_ // LLEditMenuHandler functions // virtual -void LLScrollListCtrl::copy() +void LLScrollListCtrl::copy() { std::string buffer; @@ -2896,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; @@ -2935,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(); } |