summaryrefslogtreecommitdiff
path: root/indra/llui/llscrolllistctrl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/llscrolllistctrl.cpp')
-rw-r--r--indra/llui/llscrolllistctrl.cpp204
1 files changed, 98 insertions, 106 deletions
diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp
index 8998d965fb..8093536868 100644
--- a/indra/llui/llscrolllistctrl.cpp
+++ b/indra/llui/llscrolllistctrl.cpp
@@ -326,17 +326,11 @@ S32 LLScrollListCtrl::getSearchColumn()
}
return llclamp(mSearchColumn, 0, getNumColumns());
}
-/*virtual*/
+
+// virtual
bool LLScrollListCtrl::preProcessChildNode(LLXMLNodePtr child)
{
- if (child->hasName("column") || child->hasName("row"))
- {
- return true; // skip
- }
- else
- {
- return false;
- }
+ return child->hasName("column") || child->hasName("row");
}
LLScrollListCtrl::~LLScrollListCtrl()
@@ -356,7 +350,6 @@ LLScrollListCtrl::~LLScrollListCtrl()
}
}
-
bool LLScrollListCtrl::setMaxItemCount(S32 max_count)
{
if (max_count >= getItemCount())
@@ -379,10 +372,9 @@ S32 LLScrollListCtrl::getItemCount() const
bool LLScrollListCtrl::hasSelectedItem() const
{
item_list::iterator iter;
- for (iter = mItemList.begin(); iter < mItemList.end(); )
+ for (LLScrollListItem* item : mItemList)
{
- LLScrollListItem* itemp = *iter;
- if (itemp && itemp->getSelected())
+ if (item->getSelected())
{
return true;
}
@@ -396,7 +388,6 @@ void LLScrollListCtrl::clearRows()
{
std::for_each(mItemList.begin(), mItemList.end(), DeletePointer());
mItemList.clear();
- //mItemCount = 0;
// Scroll the bar back up to the top.
mScrollbar->setDocParams(0, 0);
@@ -407,7 +398,6 @@ void LLScrollListCtrl::clearRows()
mDirty = false;
}
-
LLScrollListItem* LLScrollListCtrl::getFirstSelected() const
{
for (LLScrollListItem* item : mItemList)
@@ -444,14 +434,12 @@ S32 LLScrollListCtrl::getNumSelected() const
++numSelected;
}
}
-
return numSelected;
}
S32 LLScrollListCtrl::getFirstSelectedIndex() const
{
S32 CurSelectedIndex = 0;
-
// make sure sort is up to date before returning an index
updateSort();
@@ -463,7 +451,6 @@ S32 LLScrollListCtrl::getFirstSelectedIndex() const
}
CurSelectedIndex++;
}
-
return -1;
}
@@ -477,6 +464,15 @@ LLScrollListItem* LLScrollListCtrl::getLastData() const
return mItemList.empty() ? NULL : mItemList.back();
}
+LLScrollListItem* LLScrollListCtrl::getNthData(size_t index) const
+{
+ if (mItemList.size() <= index)
+ {
+ return NULL;
+ }
+ return mItemList[index];
+}
+
std::vector<LLScrollListItem*> LLScrollListCtrl::getAllData() const
{
std::vector<LLScrollListItem*> ret;
@@ -1052,7 +1048,7 @@ S32 LLScrollListCtrl::selectMultiple( uuid_vec_t ids )
{
LLScrollListItem* item = *iter;
uuid_vec_t::iterator iditr;
- for(iditr = ids.begin(); iditr != ids.end(); ++iditr)
+ for (iditr = ids.begin(); iditr != ids.end(); ++iditr)
{
if (item->getEnabled() && (item->getUUID() == (*iditr)))
{
@@ -1062,7 +1058,10 @@ S32 LLScrollListCtrl::selectMultiple( uuid_vec_t ids )
break;
}
}
- if(ids.end() != iditr) ids.erase(iditr);
+ if (ids.end() != iditr)
+ {
+ ids.erase(iditr);
+ }
}
if (mCommitOnSelectionChange)
@@ -1077,11 +1076,9 @@ S32 LLScrollListCtrl::getItemIndex( LLScrollListItem* target_item ) const
updateSort();
S32 index = 0;
- item_list::const_iterator iter;
- for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
+ for (LLScrollListItem* item : mItemList)
{
- LLScrollListItem *itemp = *iter;
- if (target_item == itemp)
+ if (target_item == item)
{
return index;
}
@@ -1095,11 +1092,9 @@ S32 LLScrollListCtrl::getItemIndex( const LLUUID& target_id ) const
updateSort();
S32 index = 0;
- item_list::const_iterator iter;
- for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
+ for (LLScrollListItem* item : mItemList)
{
- LLScrollListItem *itemp = *iter;
- if (target_id == itemp->getUUID())
+ if (target_id == item->getUUID())
{
return index;
}
@@ -1110,40 +1105,32 @@ S32 LLScrollListCtrl::getItemIndex( const LLUUID& target_id ) const
void LLScrollListCtrl::selectPrevItem( bool extend_selection)
{
+ updateSort();
+
LLScrollListItem* prev_item = NULL;
- if (!getFirstSelected())
- {
- // select last item
- selectNthItem(getItemCount() - 1);
- }
- else
+ for (LLScrollListItem* item : mItemList)
{
- updateSort();
-
- item_list::iterator iter;
- for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
+ if (item->getSelected())
{
- LLScrollListItem* cur_item = *iter;
-
- if (cur_item->getSelected())
- {
- if (prev_item)
- {
- selectItem(prev_item, cur_item->getSelectedCell(), !extend_selection);
- }
- else
- {
- reportInvalidInput();
- }
- break;
- }
+ break;
+ }
- // don't allow navigation to disabled elements
- prev_item = cur_item->getEnabled() ? cur_item : prev_item;
+ // don't allow navigation to disabled elements
+ if (item->getEnabled())
+ {
+ prev_item = item;
}
}
+ if (!prev_item)
+ {
+ reportInvalidInput();
+ return;
+ }
+
+ selectItem(prev_item, prev_item->getSelectedCell(), !extend_selection);
+
if ((mCommitOnSelectionChange || mCommitOnKeyboardMovement))
{
commitIfChanged();
@@ -1154,39 +1141,41 @@ void LLScrollListCtrl::selectPrevItem( bool extend_selection)
void LLScrollListCtrl::selectNextItem( bool extend_selection)
{
+ updateSort();
+
+ LLScrollListItem* current_item = NULL;
LLScrollListItem* next_item = NULL;
- if (!getFirstSelected())
- {
- selectFirstItem();
- }
- else
+ for (LLScrollListItem* item : mItemList)
{
- updateSort();
-
- item_list::reverse_iterator iter;
- for (iter = mItemList.rbegin(); iter != mItemList.rend(); iter++)
+ if (current_item)
{
- LLScrollListItem* cur_item = *iter;
-
- if (cur_item->getSelected())
+ if (item->getEnabled())
{
- if (next_item)
- {
- selectItem(next_item, cur_item->getSelectedCell(), !extend_selection);
- }
- else
- {
- reportInvalidInput();
- }
+ next_item = item;
break;
}
-
- // don't allow navigation to disabled items
- next_item = cur_item->getEnabled() ? cur_item : next_item;
}
+ else if (item->getSelected())
+ {
+ current_item = item;
+ next_item = NULL;
+ continue;
+ }
+ else if (!next_item && item->getEnabled())
+ {
+ next_item = item;
+ }
+ }
+
+ if (!next_item)
+ {
+ reportInvalidInput();
+ return;
}
+ selectItem(next_item, next_item->getSelectedCell(), !extend_selection);
+
if (mCommitOnKeyboardMovement)
{
onCommit();
@@ -1197,10 +1186,8 @@ void LLScrollListCtrl::selectNextItem( bool extend_selection)
void LLScrollListCtrl::deselectAllItems(bool no_commit_on_change)
{
- item_list::iterator iter;
- for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
+ for (LLScrollListItem* item : mItemList)
{
- LLScrollListItem* item = *iter;
deselectItem(item);
}
@@ -1725,6 +1712,16 @@ void LLScrollListCtrl::setEnabled(bool enabled)
mCanSelect = enabled;
setTabStop(enabled);
mScrollbar->setTabStop(!enabled && mScrollbar->getPageSize() < mScrollbar->getDocSize());
+
+ // when the table is disabled also disable its items
+ for (LLScrollListItem* item : mItemList)
+ {
+ item->setEnabled(enabled);
+ if (!enabled)
+ {
+ item->setSelected(false);
+ }
+ }
}
bool LLScrollListCtrl::handleScrollWheel(S32 x, S32 y, S32 clicks)
@@ -2624,7 +2621,9 @@ bool LLScrollListCtrl::isRepeatedChars(const LLWString& string) const
void LLScrollListCtrl::selectItem(LLScrollListItem* itemp, S32 cell, bool select_single_item)
{
- if (itemp && !itemp->getSelected())
+ if (!itemp) return;
+
+ if (!itemp->getSelected() || itemp->getSelectedCell() != cell)
{
if (mLastSelected)
{
@@ -2900,11 +2899,9 @@ bool LLScrollListCtrl::canCut() const
void LLScrollListCtrl::selectAll()
{
// Deselects all other items
- item_list::iterator iter;
- for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
+ for (LLScrollListItem* itemp : mItemList)
{
- LLScrollListItem *itemp = *iter;
- if( itemp->getEnabled() )
+ if (itemp->getEnabled())
{
selectItem(itemp, -1, false);
}
@@ -2944,7 +2941,8 @@ void LLScrollListCtrl::addColumn(const LLSD& column, EAddPosition pos)
void LLScrollListCtrl::addColumn(const LLScrollListColumn::Params& column_params, EAddPosition pos)
{
- if (!column_params.validateBlock()) return;
+ if (!column_params.validateBlock())
+ return;
std::string name = column_params.name;
// if no column name provided, just use ordinal as name
@@ -2971,7 +2969,7 @@ void LLScrollListCtrl::addColumn(const LLScrollListColumn::Params& column_params
{
new_column->setWidth((S32)ll_round(new_column->mRelWidth*mItemListRect.getWidth()));
}
- else if(new_column->mDynamicWidth)
+ else if (new_column->mDynamicWidth)
{
mNumDynamicWidthColumns++;
new_column->setWidth((mItemListRect.getWidth() - mTotalStaticColumnWidth - mTotalColumnPadding) / mNumDynamicWidthColumns);
@@ -2979,14 +2977,12 @@ void LLScrollListCtrl::addColumn(const LLScrollListColumn::Params& column_params
S32 top = mItemListRect.mTop;
S32 left = mItemListRect.mLeft;
- for (column_map_t::iterator itor = mColumns.begin();
- itor != mColumns.end();
- ++itor)
+ for (const auto& data_pair : mColumns)
{
- if (itor->second->mIndex < new_column->mIndex &&
- itor->second->getWidth() > 0)
+ if (data_pair.second->mIndex < new_column->mIndex &&
+ data_pair.second->getWidth() > 0)
{
- left += itor->second->getWidth() + mColumnPadding;
+ left += data_pair.second->getWidth() + mColumnPadding;
}
}
@@ -3152,17 +3148,16 @@ LLScrollListItem* LLScrollListCtrl::addRow(const LLScrollListItem::Params& item_
LLScrollListItem* LLScrollListCtrl::addRow(LLScrollListItem *new_item, const LLScrollListItem::Params& item_p, EAddPosition pos)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_UI;
- if (!item_p.validateBlock() || !new_item) return NULL;
- new_item->setNumColumns(static_cast<S32>(mColumns.size()));
+ if (!item_p.validateBlock() || !new_item)
+ return nullptr;
+
+ new_item->setNumColumns((S32)mColumns.size());
// Add any columns we don't already have
S32 col_index = 0;
- for(LLInitParam::ParamIterator<LLScrollListCell::Params>::const_iterator itor = item_p.columns.begin();
- itor != item_p.columns.end();
- ++itor)
+ for (LLScrollListCell::Params cell_p : item_p.columns)
{
- LLScrollListCell::Params cell_p = *itor;
std::string column = cell_p.column;
// empty columns strings index by ordinal
@@ -3224,8 +3219,7 @@ LLScrollListItem* LLScrollListCtrl::addRow(LLScrollListItem *new_item, const LLS
new_item->setNumColumns(static_cast<S32>(mColumns.size()));
}
- LLScrollListCell* cell = LLScrollListCell::create(LLScrollListCell::Params().value(item_p.value));
- if (cell)
+ if (LLScrollListCell* cell = LLScrollListCell::create(LLScrollListCell::Params().value(item_p.value)))
{
LLScrollListColumn* columnp = mColumns.begin()->second;
@@ -3240,15 +3234,13 @@ LLScrollListItem* LLScrollListCtrl::addRow(LLScrollListItem *new_item, const LLS
}
// add dummy cells for missing columns
- for (column_map_t::iterator column_it = mColumns.begin(); column_it != mColumns.end(); ++column_it)
+ for (const auto& column_it : mColumns)
{
- S32 column_idx = column_it->second->mIndex;
+ S32 column_idx = column_it.second->mIndex;
if (new_item->getColumn(column_idx) == NULL)
{
- LLScrollListColumn* column_ptr = column_it->second;
LLScrollListCell::Params cell_p;
- cell_p.width = column_ptr->getWidth();
-
+ cell_p.width = column_it.second->getWidth();
new_item->setColumn(column_idx, new LLScrollListSpacer(cell_p));
}
}