aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/llscrolllistctrl.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:50 -0500
committerJacek Antonelli2008-08-15 23:44:50 -0500
commit89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch)
treebcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/llui/llscrolllistctrl.cpp
parentSecond Life viewer sources 1.13.3.2 (diff)
downloadmeta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/llui/llscrolllistctrl.cpp')
-rw-r--r--linden/indra/llui/llscrolllistctrl.cpp123
1 files changed, 70 insertions, 53 deletions
diff --git a/linden/indra/llui/llscrolllistctrl.cpp b/linden/indra/llui/llscrolllistctrl.cpp
index df4ca64..4d5c49f 100644
--- a/linden/indra/llui/llscrolllistctrl.cpp
+++ b/linden/indra/llui/llscrolllistctrl.cpp
@@ -95,7 +95,7 @@ protected:
95// LLScrollListIcon 95// LLScrollListIcon
96// 96//
97LLScrollListIcon::LLScrollListIcon(LLImageGL* icon, S32 width, LLUUID image_id) : 97LLScrollListIcon::LLScrollListIcon(LLImageGL* icon, S32 width, LLUUID image_id) :
98mIcon(icon), mImageUUID(image_id.getString()) 98mIcon(icon), mImageUUID(image_id.asString())
99{ 99{
100 if (width) 100 if (width)
101 { 101 {
@@ -156,13 +156,15 @@ BOOL LLScrollListCheck::handleClick()
156// 156//
157U32 LLScrollListText::sCount = 0; 157U32 LLScrollListText::sCount = 0;
158 158
159LLScrollListText::LLScrollListText( const LLString& text, const LLFontGL* font, S32 width, U8 font_style, LLColor4& color, BOOL use_color, BOOL visible) 159LLScrollListText::LLScrollListText( const LLString& text, const LLFontGL* font, S32 width, U8 font_style, LLFontGL::HAlign font_alignment, LLColor4& color, BOOL use_color, BOOL visible)
160: mText( text ), 160: mText( text ),
161 mFont( font ), 161 mFont( font ),
162 mFontStyle( font_style ), 162 mFontStyle( font_style ),
163 mFontAlignment( font_alignment ),
163 mWidth( width ), 164 mWidth( width ),
164 mVisible( visible ), 165 mVisible( visible ),
165 mHighlightChars( 0 ) 166 mHighlightCount( 0 ),
167 mHighlightOffset( 0 )
166{ 168{
167 if (use_color) 169 if (use_color)
168 { 170 {
@@ -181,10 +183,6 @@ LLScrollListText::LLScrollListText( const LLString& text, const LLFontGL* font,
181 { 183 {
182 mRoundedRectImage = LLUI::sImageProvider->getUIImageByID(LLUUID(LLUI::sAssetsGroup->getString("rounded_square.tga"))); 184 mRoundedRectImage = LLUI::sImageProvider->getUIImageByID(LLUUID(LLUI::sAssetsGroup->getString("rounded_square.tga")));
183 } 185 }
184
185 // Yes, that's four dots, because we want it to have a little
186 // padding, in proportion to the font size.
187 mEllipsisWidth = (S32)mFont->getWidth("....");
188} 186}
189 187
190LLScrollListText::~LLScrollListText() 188LLScrollListText::~LLScrollListText()
@@ -216,13 +214,26 @@ void LLScrollListText::drawToWidth(S32 width, const LLColor4& color, const LLCol
216 display_color = &color; 214 display_color = &color;
217 } 215 }
218 216
219 if (mHighlightChars > 0) 217 if (mHighlightCount > 0)
220 { 218 {
221 mRoundedRectImage->bind(); 219 mRoundedRectImage->bind();
222 glColor4fv(highlight_color.mV); 220 glColor4fv(highlight_color.mV);
223 gl_segmented_rect_2d_tex(-2, 221 S32 left = 0;
222 switch(mFontAlignment)
223 {
224 case LLFontGL::LEFT:
225 left = mFont->getWidth(mText.getString(), 0, mHighlightOffset);
226 break;
227 case LLFontGL::RIGHT:
228 left = width - mFont->getWidth(mText.getString(), mHighlightOffset, S32_MAX);
229 break;
230 case LLFontGL::HCENTER:
231 left = (width - mFont->getWidth(mText.getString())) / 2;
232 break;
233 }
234 gl_segmented_rect_2d_tex(left - 2,
224 llround(mFont->getLineHeight()) + 1, 235 llround(mFont->getLineHeight()) + 1,
225 mFont->getWidth(mText.getString(), 0, mHighlightChars) + 1, 236 left + mFont->getWidth(mText.getString(), mHighlightOffset, mHighlightCount) + 1,
226 1, 237 1,
227 mRoundedRectImage->getWidth(), 238 mRoundedRectImage->getWidth(),
228 mRoundedRectImage->getHeight(), 239 mRoundedRectImage->getHeight(),
@@ -232,21 +243,28 @@ void LLScrollListText::drawToWidth(S32 width, const LLColor4& color, const LLCol
232 // Try to draw the entire string 243 // Try to draw the entire string
233 F32 right_x; 244 F32 right_x;
234 U32 string_chars = mText.length(); 245 U32 string_chars = mText.length();
235 U32 drawn_chars = mFont->render(mText.getWString(), 0, 0, 2, 246 F32 start_x = 0.f;
236 *display_color, 247 switch(mFontAlignment)
237 LLFontGL::LEFT, 248 {
238 LLFontGL::BOTTOM, 249 case LLFontGL::LEFT:
239 mFontStyle, 250 start_x = 0.f;
240 string_chars, 251 break;
241 width - mEllipsisWidth, 252 case LLFontGL::RIGHT:
242 &right_x, FALSE); 253 start_x = (F32)width;
243 254 break;
244 // If we didn't get the whole string, abbreviate 255 case LLFontGL::HCENTER:
245 if (drawn_chars < string_chars && drawn_chars) 256 start_x = (F32)width * 0.5f;
246 { 257 break;
247 mFont->renderUTF8("...", 0, right_x, 0.f, color, LLFontGL::LEFT, LLFontGL::BOTTOM, mFontStyle, 258 }
248 S32_MAX, S32_MAX, NULL, FALSE); 259 mFont->render(mText.getWString(), 0,
249 } 260 start_x, 2.f,
261 *display_color,
262 mFontAlignment,
263 LLFontGL::BOTTOM,
264 mFontStyle,
265 string_chars,
266 width,
267 &right_x, FALSE, TRUE);
250} 268}
251 269
252 270
@@ -378,20 +396,21 @@ LLScrollListCtrl::LLScrollListCtrl(const LLString& name, const LLRect& rect,
378 mFgUnselectedColor( LLUI::sColorsGroup->getColor("ScrollUnselectedColor") ), 396 mFgUnselectedColor( LLUI::sColorsGroup->getColor("ScrollUnselectedColor") ),
379 mFgDisabledColor( LLUI::sColorsGroup->getColor("ScrollDisabledColor") ), 397 mFgDisabledColor( LLUI::sColorsGroup->getColor("ScrollDisabledColor") ),
380 mHighlightedColor( LLUI::sColorsGroup->getColor("ScrollHighlightedColor") ), 398 mHighlightedColor( LLUI::sColorsGroup->getColor("ScrollHighlightedColor") ),
381 mHighlightedItem(-1),
382 mBorderThickness( 2 ), 399 mBorderThickness( 2 ),
383 mOnDoubleClickCallback( NULL ), 400 mOnDoubleClickCallback( NULL ),
384 mOnMaximumSelectCallback( NULL ), 401 mOnMaximumSelectCallback( NULL ),
385 mOnSortChangedCallback( NULL ), 402 mOnSortChangedCallback( NULL ),
386 mDrewSelected(FALSE), 403 mHighlightedItem(-1),
387 mBorder(NULL), 404 mBorder(NULL),
388 mSearchColumn(0),
389 mDefaultColumn("SIMPLE"), 405 mDefaultColumn("SIMPLE"),
406 mSearchColumn(0),
390 407
391 mNumDynamicWidthColumns(0), 408 mNumDynamicWidthColumns(0),
392 mTotalStaticColumnWidth(0), 409 mTotalStaticColumnWidth(0),
393 mSortColumn(0), 410 mSortColumn(0),
394 mSortAscending(TRUE) 411 mSortAscending(TRUE),
412
413 mDrewSelected(FALSE)
395{ 414{
396 mItemListRect.setOriginAndSize( 415 mItemListRect.setOriginAndSize(
397 mBorderThickness + LIST_BORDER_PAD, 416 mBorderThickness + LIST_BORDER_PAD,
@@ -1160,11 +1179,17 @@ BOOL LLScrollListCtrl::selectSimpleItemByPrefix(const LLWString& target, BOOL ca
1160 { 1179 {
1161 LLWString::toLower(item_label); 1180 LLWString::toLower(item_label);
1162 } 1181 }
1182 // remove extraneous whitespace from searchable label
1183 LLWString trimmed_label = item_label;
1184 LLWString::trim(trimmed_label);
1163 1185
1164 BOOL select = item->getEnabled() && !item_label.compare(0, target_len, target_trimmed); 1186 BOOL select = item->getEnabled() && trimmed_label.compare(0, target_trimmed.size(), target_trimmed) == 0;
1165 1187
1166 if (select) 1188 if (select)
1167 { 1189 {
1190 // find offset of matching text (might have leading whitespace)
1191 S32 offset = item_label.find(target_trimmed);
1192 cellp->highlightText(offset, target_trimmed.size());
1168 selectItem(item); 1193 selectItem(item);
1169 found = TRUE; 1194 found = TRUE;
1170 break; 1195 break;
@@ -1466,6 +1491,9 @@ BOOL LLScrollListCtrl::handleMouseDown(S32 x, S32 y, MASK mask)
1466{ 1491{
1467 BOOL handled = LLView::childrenHandleMouseDown(x, y, mask) != NULL; 1492 BOOL handled = LLView::childrenHandleMouseDown(x, y, mask) != NULL;
1468 1493
1494 // set keyboard focus first, in case click action wants to move focus elsewhere
1495 setFocus(TRUE);
1496
1469 if( !handled && mCanSelect) 1497 if( !handled && mCanSelect)
1470 { 1498 {
1471 LLScrollListItem* hit_item = hitItem(x, y); 1499 LLScrollListItem* hit_item = hitItem(x, y);
@@ -1558,8 +1586,6 @@ BOOL LLScrollListCtrl::handleMouseDown(S32 x, S32 y, MASK mask)
1558 } 1586 }
1559 } 1587 }
1560 1588
1561 gFocusMgr.setKeyboardFocus(this, NULL);
1562
1563 return TRUE; 1589 return TRUE;
1564} 1590}
1565 1591
@@ -1758,7 +1784,7 @@ BOOL LLScrollListCtrl::handleKeyHere(KEY key,MASK mask, BOOL called_from_parent
1758 LLScrollListCell* cellp = getFirstSelected()->getColumn(mSearchColumn); 1784 LLScrollListCell* cellp = getFirstSelected()->getColumn(mSearchColumn);
1759 if (cellp) 1785 if (cellp)
1760 { 1786 {
1761 cellp->highlightText(0); 1787 cellp->highlightText(0, 0);
1762 } 1788 }
1763 } 1789 }
1764 } 1790 }
@@ -1767,13 +1793,6 @@ BOOL LLScrollListCtrl::handleKeyHere(KEY key,MASK mask, BOOL called_from_parent
1767 // update search string only on successful match 1793 // update search string only on successful match
1768 mSearchTimer.reset(); 1794 mSearchTimer.reset();
1769 1795
1770 // highlight current search on matching item
1771 LLScrollListCell* cellp = getFirstSelected()->getColumn(mSearchColumn);
1772 if (cellp)
1773 {
1774 cellp->highlightText(mSearchString.size());
1775 }
1776
1777 if (mCommitOnKeyboardMovement 1796 if (mCommitOnKeyboardMovement
1778 && !mCommitOnSelectionChange) 1797 && !mCommitOnSelectionChange)
1779 { 1798 {
@@ -1813,13 +1832,6 @@ BOOL LLScrollListCtrl::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_
1813 mSearchString += uni_char; 1832 mSearchString += uni_char;
1814 mSearchTimer.reset(); 1833 mSearchTimer.reset();
1815 1834
1816 // highlight current search on matching item
1817 LLScrollListCell* cellp = getFirstSelected()->getColumn(mSearchColumn);
1818 if (cellp)
1819 {
1820 cellp->highlightText(mSearchString.size());
1821 }
1822
1823 if (mCommitOnKeyboardMovement 1835 if (mCommitOnKeyboardMovement
1824 && !mCommitOnSelectionChange) 1836 && !mCommitOnSelectionChange)
1825 { 1837 {
@@ -1862,7 +1874,7 @@ BOOL LLScrollListCtrl::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_
1862 if (item->getEnabled() && LLStringOps::toLower(item_label[0]) == uni_char) 1874 if (item->getEnabled() && LLStringOps::toLower(item_label[0]) == uni_char)
1863 { 1875 {
1864 selectItem(item); 1876 selectItem(item);
1865 cellp->highlightText(1); 1877 cellp->highlightText(0, 1);
1866 mSearchTimer.reset(); 1878 mSearchTimer.reset();
1867 1879
1868 if (mCommitOnKeyboardMovement 1880 if (mCommitOnKeyboardMovement
@@ -1925,7 +1937,7 @@ void LLScrollListCtrl::selectItem(LLScrollListItem* itemp, BOOL select_single_it
1925 LLScrollListCell* cellp = mLastSelected->getColumn(mSearchColumn); 1937 LLScrollListCell* cellp = mLastSelected->getColumn(mSearchColumn);
1926 if (cellp) 1938 if (cellp)
1927 { 1939 {
1928 cellp->highlightText(0); 1940 cellp->highlightText(0, 0);
1929 } 1941 }
1930 } 1942 }
1931 if (select_single_item) 1943 if (select_single_item)
@@ -1953,7 +1965,7 @@ void LLScrollListCtrl::deselectItem(LLScrollListItem* itemp)
1953 LLScrollListCell* cellp = itemp->getColumn(mSearchColumn); 1965 LLScrollListCell* cellp = itemp->getColumn(mSearchColumn);
1954 if (cellp) 1966 if (cellp)
1955 { 1967 {
1956 cellp->highlightText(0); 1968 cellp->highlightText(0, 0);
1957 } 1969 }
1958 mSelectionChanged = TRUE; 1970 mSelectionChanged = TRUE;
1959 } 1971 }
@@ -2195,7 +2207,7 @@ LLView* LLScrollListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFac
2195 NULL, 2207 NULL,
2196 multi_select, 2208 multi_select,
2197 draw_border); 2209 draw_border);
2198 2210
2199 scroll_list->setDisplayHeading(draw_heading); 2211 scroll_list->setDisplayHeading(draw_heading);
2200 if (node->hasAttribute("heading_height")) 2212 if (node->hasAttribute("heading_height"))
2201 { 2213 {
@@ -2250,6 +2262,8 @@ LLView* LLScrollListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFac
2250 F32 columnrelwidth = 0.f; 2262 F32 columnrelwidth = 0.f;
2251 child->getAttributeF32("relwidth", columnrelwidth); 2263 child->getAttributeF32("relwidth", columnrelwidth);
2252 2264
2265 LLFontGL::HAlign h_align = LLFontGL::LEFT;
2266 h_align = LLView::selectFontHAlign(child);
2253 2267
2254 columns[index]["name"] = columnname; 2268 columns[index]["name"] = columnname;
2255 columns[index]["sort"] = sortname; 2269 columns[index]["sort"] = sortname;
@@ -2258,6 +2272,7 @@ LLView* LLScrollListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFac
2258 columns[index]["width"] = columnwidth; 2272 columns[index]["width"] = columnwidth;
2259 columns[index]["relwidth"] = columnrelwidth; 2273 columns[index]["relwidth"] = columnrelwidth;
2260 columns[index]["dynamicwidth"] = columndynamicwidth; 2274 columns[index]["dynamicwidth"] = columndynamicwidth;
2275 columns[index]["halign"] = (S32)h_align;
2261 index++; 2276 index++;
2262 } 2277 }
2263 } 2278 }
@@ -2604,6 +2619,7 @@ LLScrollListItem* LLScrollListCtrl::addElement(const LLSD& value, EAddPosition p
2604 2619
2605 S32 index = column_itor->second.mIndex; 2620 S32 index = column_itor->second.mIndex;
2606 S32 width = column_itor->second.mWidth; 2621 S32 width = column_itor->second.mWidth;
2622 LLFontGL::HAlign font_alignment = column_itor->second.mFontAlignment;
2607 2623
2608 LLSD value = (*itor)["value"]; 2624 LLSD value = (*itor)["value"];
2609 LLString fontname = (*itor)["font"].asString(); 2625 LLString fontname = (*itor)["font"].asString();
@@ -2631,7 +2647,7 @@ LLScrollListItem* LLScrollListCtrl::addElement(const LLSD& value, EAddPosition p
2631 } 2647 }
2632 else 2648 else
2633 { 2649 {
2634 new_item->setColumn(index, new LLScrollListText(value.asString(), font, width, font_style)); 2650 new_item->setColumn(index, new LLScrollListText(value.asString(), font, width, font_style, font_alignment));
2635 } 2651 }
2636 } 2652 }
2637 2653
@@ -2724,7 +2740,7 @@ void LLScrollListCtrl::setFocus(BOOL b)
2724 if (!getFirstSelected()) 2740 if (!getFirstSelected())
2725 { 2741 {
2726 selectFirstItem(); 2742 selectFirstItem();
2727 onCommit(); 2743 //onCommit(); // SJB: selectFirstItem() will call onCommit() if appropriate
2728 } 2744 }
2729 LLUICtrl::setFocus(b); 2745 LLUICtrl::setFocus(b);
2730} 2746}
@@ -2739,3 +2755,4 @@ void LLScrollListCtrl::onFocusLost()
2739 } 2755 }
2740 } 2756 }
2741} 2757}
2758