aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lllineeditor.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llui/lllineeditor.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/llui/lllineeditor.cpp214
1 files changed, 30 insertions, 184 deletions
diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp
index b091bb7..1c96bc4 100644
--- a/linden/indra/llui/lllineeditor.cpp
+++ b/linden/indra/llui/lllineeditor.cpp
@@ -81,44 +81,6 @@ const S32 PREEDIT_STANDOUT_GAP = 1;
81const S32 PREEDIT_STANDOUT_POSITION = 2; 81const S32 PREEDIT_STANDOUT_POSITION = 2;
82const S32 PREEDIT_STANDOUT_THICKNESS = 2; 82const S32 PREEDIT_STANDOUT_THICKNESS = 2;
83 83
84// This is a friend class of and is only used by LLLineEditor
85class LLLineEditorRollback
86{
87public:
88 LLLineEditorRollback( LLLineEditor* ed )
89 :
90 mCursorPos( ed->mCursorPos ),
91 mScrollHPos( ed->mScrollHPos ),
92 mIsSelecting( ed->mIsSelecting ),
93 mSelectionStart( ed->mSelectionStart ),
94 mSelectionEnd( ed->mSelectionEnd )
95 {
96 mText = ed->getText();
97 }
98
99 void doRollback( LLLineEditor* ed )
100 {
101 ed->mCursorPos = mCursorPos;
102 ed->mScrollHPos = mScrollHPos;
103 ed->mIsSelecting = mIsSelecting;
104 ed->mSelectionStart = mSelectionStart;
105 ed->mSelectionEnd = mSelectionEnd;
106 ed->mText = mText;
107 ed->mPrevText = mText;
108 }
109
110 LLString getText() { return mText; }
111
112private:
113 LLString mText;
114 S32 mCursorPos;
115 S32 mScrollHPos;
116 BOOL mIsSelecting;
117 S32 mSelectionStart;
118 S32 mSelectionEnd;
119};
120
121
122// 84//
123// Member functions 85// Member functions
124// 86//
@@ -190,7 +152,7 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect,
190 setFocusLostCallback(focus_lost_callback); 152 setFocusLostCallback(focus_lost_callback);
191 153
192 mMinHPixels = mBorderThickness + UI_LINEEDITOR_H_PAD + mBorderLeft; 154 mMinHPixels = mBorderThickness + UI_LINEEDITOR_H_PAD + mBorderLeft;
193 mMaxHPixels = mRect.getWidth() - mMinHPixels - mBorderThickness - mBorderRight; 155 mMaxHPixels = getRect().getWidth() - mMinHPixels - mBorderThickness - mBorderRight;
194 156
195 mScrollTimer.reset(); 157 mScrollTimer.reset();
196 158
@@ -200,7 +162,7 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect,
200 162
201 // Scalable UI somehow made these rectangles off-by-one. 163 // Scalable UI somehow made these rectangles off-by-one.
202 // I don't know why. JC 164 // I don't know why. JC
203 LLRect border_rect(0, mRect.getHeight()-1, mRect.getWidth()-1, 0); 165 LLRect border_rect(0, getRect().getHeight()-1, getRect().getWidth()-1, 0);
204 mBorder = new LLViewBorder( "line ed border", border_rect, border_bevel, border_style, mBorderThickness ); 166 mBorder = new LLViewBorder( "line ed border", border_rect, border_bevel, border_style, mBorderThickness );
205 addChild( mBorder ); 167 addChild( mBorder );
206 mBorder->setFollows(FOLLOWS_LEFT|FOLLOWS_RIGHT|FOLLOWS_TOP|FOLLOWS_BOTTOM); 168 mBorder->setFollows(FOLLOWS_LEFT|FOLLOWS_RIGHT|FOLLOWS_TOP|FOLLOWS_BOTTOM);
@@ -219,17 +181,6 @@ LLLineEditor::~LLLineEditor()
219 } 181 }
220} 182}
221 183
222//virtual
223EWidgetType LLLineEditor::getWidgetType() const
224{
225 return WIDGET_TYPE_LINE_EDITOR;
226}
227
228//virtual
229LLString LLLineEditor::getWidgetTag() const
230{
231 return LL_LINE_EDITOR_TAG;
232}
233 184
234void LLLineEditor::onFocusReceived() 185void LLLineEditor::onFocusReceived()
235{ 186{
@@ -269,18 +220,6 @@ void LLLineEditor::onCommit()
269 selectAll(); 220 selectAll();
270} 221}
271 222
272// virtual
273BOOL LLLineEditor::isDirty() const
274{
275 return ( mText.getString() != mPrevText );
276}
277
278// virtual
279void LLLineEditor::resetDirty()
280{
281 mPrevText = mText.getString();
282}
283
284 223
285// line history support 224// line history support
286void LLLineEditor::updateHistory() 225void LLLineEditor::updateHistory()
@@ -306,12 +245,7 @@ void LLLineEditor::reshape(S32 width, S32 height, BOOL called_from_parent)
306{ 245{
307 LLUICtrl::reshape(width, height, called_from_parent ); 246 LLUICtrl::reshape(width, height, called_from_parent );
308 247
309 mMaxHPixels = mRect.getWidth() - 2 * (mBorderThickness + UI_LINEEDITOR_H_PAD) + 1 - mBorderRight; 248 mMaxHPixels = getRect().getWidth() - 2 * (mBorderThickness + UI_LINEEDITOR_H_PAD) + 1 - mBorderRight;
310}
311
312void LLLineEditor::setEnableLineHistory( BOOL enabled )
313{
314 mHaveHistory = enabled;
315} 249}
316 250
317void LLLineEditor::setEnabled(BOOL enabled) 251void LLLineEditor::setEnabled(BOOL enabled)
@@ -330,16 +264,12 @@ void LLLineEditor::setMaxTextLength(S32 max_text_length)
330 264
331void LLLineEditor::setBorderWidth(S32 left, S32 right) 265void LLLineEditor::setBorderWidth(S32 left, S32 right)
332{ 266{
333 mBorderLeft = llclamp(left, 0, mRect.getWidth()); 267 mBorderLeft = llclamp(left, 0, getRect().getWidth());
334 mBorderRight = llclamp(right, 0, mRect.getWidth()); 268 mBorderRight = llclamp(right, 0, getRect().getWidth());
335 mMinHPixels = mBorderThickness + UI_LINEEDITOR_H_PAD + mBorderLeft; 269 mMinHPixels = mBorderThickness + UI_LINEEDITOR_H_PAD + mBorderLeft;
336 mMaxHPixels = mRect.getWidth() - mMinHPixels - mBorderThickness - mBorderRight; 270 mMaxHPixels = getRect().getWidth() - mMinHPixels - mBorderThickness - mBorderRight;
337} 271}
338 272
339void LLLineEditor::setLabel(const LLStringExplicit &new_label)
340{
341 mLabel = new_label;
342}
343 273
344void LLLineEditor::setText(const LLStringExplicit &new_text) 274void LLLineEditor::setText(const LLStringExplicit &new_text)
345{ 275{
@@ -451,12 +381,11 @@ void LLLineEditor::setCursorToEnd()
451 deselect(); 381 deselect();
452} 382}
453 383
454BOOL LLLineEditor::canDeselect() 384BOOL LLLineEditor::canDeselect() const
455{ 385{
456 return hasSelection(); 386 return hasSelection();
457} 387}
458 388
459
460void LLLineEditor::deselect() 389void LLLineEditor::deselect()
461{ 390{
462 mSelectionStart = 0; 391 mSelectionStart = 0;
@@ -481,7 +410,7 @@ void LLLineEditor::endSelection()
481 } 410 }
482} 411}
483 412
484BOOL LLLineEditor::canSelectAll() 413BOOL LLLineEditor::canSelectAll() const
485{ 414{
486 return TRUE; 415 return TRUE;
487} 416}
@@ -554,7 +483,7 @@ BOOL LLLineEditor::handleDoubleClick(S32 x, S32 y, MASK mask)
554 483
555BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) 484BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask)
556{ 485{
557 if (x < mBorderLeft || x > (mRect.getWidth() - mBorderRight)) 486 if (x < mBorderLeft || x > (getRect().getWidth() - mBorderRight))
558 { 487 {
559 return LLUICtrl::handleMouseDown(x, y, mask); 488 return LLUICtrl::handleMouseDown(x, y, mask);
560 } 489 }
@@ -634,7 +563,7 @@ BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask)
634BOOL LLLineEditor::handleHover(S32 x, S32 y, MASK mask) 563BOOL LLLineEditor::handleHover(S32 x, S32 y, MASK mask)
635{ 564{
636 BOOL handled = FALSE; 565 BOOL handled = FALSE;
637 if (!hasMouseCapture() && (x < mBorderLeft || x > (mRect.getWidth() - mBorderRight))) 566 if (!hasMouseCapture() && (x < mBorderLeft || x > (getRect().getWidth() - mBorderRight)))
638 { 567 {
639 return LLUICtrl::handleHover(x, y, mask); 568 return LLUICtrl::handleHover(x, y, mask);
640 } 569 }
@@ -705,7 +634,7 @@ BOOL LLLineEditor::handleMouseUp(S32 x, S32 y, MASK mask)
705 handled = TRUE; 634 handled = TRUE;
706 } 635 }
707 636
708 if (!handled && (x < mBorderLeft || x > (mRect.getWidth() - mBorderRight))) 637 if (!handled && (x < mBorderLeft || x > (getRect().getWidth() - mBorderRight)))
709 { 638 {
710 return LLUICtrl::handleMouseUp(x, y, mask); 639 return LLUICtrl::handleMouseUp(x, y, mask);
711 } 640 }
@@ -856,11 +785,6 @@ BOOL LLLineEditor::handleSelectionKey(KEY key, MASK mask)
856 switch( key ) 785 switch( key )
857 { 786 {
858 case KEY_LEFT: 787 case KEY_LEFT:
859 if (mIgnoreArrowKeys)
860 {
861 handled = FALSE;
862 break;
863 }
864 if( 0 < getCursor() ) 788 if( 0 < getCursor() )
865 { 789 {
866 S32 cursorPos = getCursor() - 1; 790 S32 cursorPos = getCursor() - 1;
@@ -877,11 +801,6 @@ BOOL LLLineEditor::handleSelectionKey(KEY key, MASK mask)
877 break; 801 break;
878 802
879 case KEY_RIGHT: 803 case KEY_RIGHT:
880 if (mIgnoreArrowKeys)
881 {
882 handled = FALSE;
883 break;
884 }
885 if( getCursor() < mText.length()) 804 if( getCursor() < mText.length())
886 { 805 {
887 S32 cursorPos = getCursor() + 1; 806 S32 cursorPos = getCursor() + 1;
@@ -899,22 +818,12 @@ BOOL LLLineEditor::handleSelectionKey(KEY key, MASK mask)
899 818
900 case KEY_PAGE_UP: 819 case KEY_PAGE_UP:
901 case KEY_HOME: 820 case KEY_HOME:
902 if (mIgnoreArrowKeys)
903 {
904 handled = FALSE;
905 break;
906 }
907 extendSelection( 0 ); 821 extendSelection( 0 );
908 break; 822 break;
909 823
910 case KEY_PAGE_DOWN: 824 case KEY_PAGE_DOWN:
911 case KEY_END: 825 case KEY_END:
912 { 826 {
913 if (mIgnoreArrowKeys)
914 {
915 handled = FALSE;
916 break;
917 }
918 S32 len = mText.length(); 827 S32 len = mText.length();
919 if( len ) 828 if( len )
920 { 829 {
@@ -962,7 +871,7 @@ void LLLineEditor::deleteSelection()
962 } 871 }
963} 872}
964 873
965BOOL LLLineEditor::canCut() 874BOOL LLLineEditor::canCut() const
966{ 875{
967 return !mReadOnly && !mDrawAsterixes && hasSelection(); 876 return !mReadOnly && !mDrawAsterixes && hasSelection();
968} 877}
@@ -996,7 +905,7 @@ void LLLineEditor::cut()
996 } 905 }
997} 906}
998 907
999BOOL LLLineEditor::canCopy() 908BOOL LLLineEditor::canCopy() const
1000{ 909{
1001 return !mDrawAsterixes && hasSelection(); 910 return !mDrawAsterixes && hasSelection();
1002} 911}
@@ -1013,7 +922,7 @@ void LLLineEditor::copy()
1013 } 922 }
1014} 923}
1015 924
1016BOOL LLLineEditor::canPaste() 925BOOL LLLineEditor::canPaste() const
1017{ 926{
1018 return !mReadOnly && gClipboard.canPasteString(); 927 return !mReadOnly && gClipboard.canPasteString();
1019} 928}
@@ -1148,8 +1057,9 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask)
1148 break; 1057 break;
1149 1058
1150 case KEY_LEFT: 1059 case KEY_LEFT:
1151 if (!mIgnoreArrowKeys 1060 if (mIgnoreArrowKeys && mask == MASK_NONE)
1152 && mask != MASK_ALT) 1061 break;
1062 if ((mask & MASK_ALT) == 0)
1153 { 1063 {
1154 if( hasSelection() ) 1064 if( hasSelection() )
1155 { 1065 {
@@ -1174,8 +1084,9 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask)
1174 break; 1084 break;
1175 1085
1176 case KEY_RIGHT: 1086 case KEY_RIGHT:
1177 if (!mIgnoreArrowKeys 1087 if (mIgnoreArrowKeys && mask == MASK_NONE)
1178 && mask != MASK_ALT) 1088 break;
1089 if ((mask & MASK_ALT) == 0)
1179 { 1090 {
1180 if (hasSelection()) 1091 if (hasSelection())
1181 { 1092 {
@@ -1428,7 +1339,7 @@ BOOL LLLineEditor::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_pare
1428} 1339}
1429 1340
1430 1341
1431BOOL LLLineEditor::canDoDelete() 1342BOOL LLLineEditor::canDoDelete() const
1432{ 1343{
1433 return ( !mReadOnly && (!mPassDelete || (hasSelection() || (getCursor() < mText.length()))) ); 1344 return ( !mReadOnly && (!mPassDelete || (hasSelection() || (getCursor() < mText.length()))) );
1434} 1345}
@@ -1490,7 +1401,7 @@ void LLLineEditor::draw()
1490 } 1401 }
1491 1402
1492 // draw rectangle for the background 1403 // draw rectangle for the background
1493 LLRect background( 0, mRect.getHeight(), mRect.getWidth(), 0 ); 1404 LLRect background( 0, getRect().getHeight(), getRect().getWidth(), 0 );
1494 background.stretch( -mBorderThickness ); 1405 background.stretch( -mBorderThickness );
1495 1406
1496 LLColor4 bg_color = mReadOnlyBgColor; 1407 LLColor4 bg_color = mReadOnlyBgColor;
@@ -1521,7 +1432,7 @@ void LLLineEditor::draw()
1521 LLColor4 text_color; 1432 LLColor4 text_color;
1522 if (!mReadOnly) 1433 if (!mReadOnly)
1523 { 1434 {
1524 if (!mTentative) 1435 if (!getTentative())
1525 { 1436 {
1526 text_color = mFgColor; 1437 text_color = mFgColor;
1527 } 1438 }
@@ -1846,7 +1757,7 @@ BOOL LLLineEditor::prevalidateFloat(const LLWString &str)
1846 if( 0 < len ) 1757 if( 0 < len )
1847 { 1758 {
1848 // May be a comma or period, depending on the locale 1759 // May be a comma or period, depending on the locale
1849 char decimal_point = gResMgr->getDecimalPoint(); 1760 llwchar decimal_point = (llwchar)gResMgr->getDecimalPoint();
1850 1761
1851 S32 i = 0; 1762 S32 i = 0;
1852 1763
@@ -1895,7 +1806,7 @@ BOOL LLLineEditor::postvalidateFloat(const LLString &str)
1895 } 1806 }
1896 1807
1897 // May be a comma or period, depending on the locale 1808 // May be a comma or period, depending on the locale
1898 char decimal_point = gResMgr->getDecimalPoint(); 1809 llwchar decimal_point = (llwchar)gResMgr->getDecimalPoint();
1899 1810
1900 for( ; i < len; i++ ) 1811 for( ; i < len; i++ )
1901 { 1812 {
@@ -2366,18 +2277,6 @@ void LLLineEditor::setColorParameters(LLXMLNodePtr node)
2366 } 2277 }
2367} 2278}
2368 2279
2369void LLLineEditor::setValue(const LLSD& value )
2370{
2371 setText(value.asString());
2372}
2373
2374LLSD LLLineEditor::getValue() const
2375{
2376 LLString str = getText();
2377 LLSD ret(str);
2378 return ret;
2379}
2380
2381BOOL LLLineEditor::setTextArg( const LLString& key, const LLStringExplicit& text ) 2280BOOL LLLineEditor::setTextArg( const LLString& key, const LLStringExplicit& text )
2382{ 2281{
2383 mText.setArg(key, text); 2282 mText.setArg(key, text);
@@ -2492,7 +2391,7 @@ BOOL LLLineEditor::getPreeditLocation(S32 query_offset, LLCoordGL *coord, LLRect
2492 if (control) 2391 if (control)
2493 { 2392 {
2494 LLRect control_rect_screen; 2393 LLRect control_rect_screen;
2495 localRectToScreen(mRect, &control_rect_screen); 2394 localRectToScreen(getRect(), &control_rect_screen);
2496 LLUI::screenRectToGL(control_rect_screen, control); 2395 LLUI::screenRectToGL(control_rect_screen, control);
2497 } 2396 }
2498 2397
@@ -2522,21 +2421,21 @@ BOOL LLLineEditor::getPreeditLocation(S32 query_offset, LLCoordGL *coord, LLRect
2522 { 2421 {
2523 S32 query_local = findPixelNearestPos(query - getCursor()); 2422 S32 query_local = findPixelNearestPos(query - getCursor());
2524 S32 query_screen_x, query_screen_y; 2423 S32 query_screen_x, query_screen_y;
2525 localPointToScreen(query_local, mRect.getHeight() / 2, &query_screen_x, &query_screen_y); 2424 localPointToScreen(query_local, getRect().getHeight() / 2, &query_screen_x, &query_screen_y);
2526 LLUI::screenPointToGL(query_screen_x, query_screen_y, &coord->mX, &coord->mY); 2425 LLUI::screenPointToGL(query_screen_x, query_screen_y, &coord->mX, &coord->mY);
2527 } 2426 }
2528 2427
2529 if (bounds) 2428 if (bounds)
2530 { 2429 {
2531 S32 preedit_left_local = findPixelNearestPos(llmax(preedit_left_column, mScrollHPos) - getCursor()); 2430 S32 preedit_left_local = findPixelNearestPos(llmax(preedit_left_column, mScrollHPos) - getCursor());
2532 S32 preedit_right_local = llmin(findPixelNearestPos(preedit_right_column - getCursor()), mRect.getWidth() - mBorderThickness); 2431 S32 preedit_right_local = llmin(findPixelNearestPos(preedit_right_column - getCursor()), getRect().getWidth() - mBorderThickness);
2533 if (preedit_left_local > preedit_right_local) 2432 if (preedit_left_local > preedit_right_local)
2534 { 2433 {
2535 // Is this condition possible? 2434 // Is this condition possible?
2536 preedit_right_local = preedit_left_local; 2435 preedit_right_local = preedit_left_local;
2537 } 2436 }
2538 2437
2539 LLRect preedit_rect_local(preedit_left_local, mRect.getHeight(), preedit_right_local, 0); 2438 LLRect preedit_rect_local(preedit_left_local, getRect().getHeight(), preedit_right_local, 0);
2540 LLRect preedit_rect_screen; 2439 LLRect preedit_rect_screen;
2541 localRectToScreen(preedit_rect_local, &preedit_rect_screen); 2440 localRectToScreen(preedit_rect_local, &preedit_rect_screen);
2542 LLUI::screenRectToGL(preedit_rect_screen, bounds); 2441 LLUI::screenRectToGL(preedit_rect_screen, bounds);
@@ -2620,7 +2519,7 @@ LLSearchEditor::LLSearchEditor(const LLString& name,
2620 LLUICtrl(name, rect, TRUE, NULL, userdata), 2519 LLUICtrl(name, rect, TRUE, NULL, userdata),
2621 mSearchCallback(search_callback) 2520 mSearchCallback(search_callback)
2622{ 2521{
2623 LLRect search_edit_rect(0, mRect.getHeight(), mRect.getWidth(), 0); 2522 LLRect search_edit_rect(0, getRect().getHeight(), getRect().getWidth(), 0);
2624 mSearchEdit = new LLLineEditor("search edit", 2523 mSearchEdit = new LLLineEditor("search edit",
2625 search_edit_rect, 2524 search_edit_rect,
2626 LLString::null, 2525 LLString::null,
@@ -2656,55 +2555,6 @@ LLSearchEditor::LLSearchEditor(const LLString& name,
2656 mSearchEdit->setBorderWidth(0, btn_width); 2555 mSearchEdit->setBorderWidth(0, btn_width);
2657} 2556}
2658 2557
2659LLSearchEditor::~LLSearchEditor()
2660{
2661}
2662
2663//virtual
2664EWidgetType LLSearchEditor::getWidgetType() const
2665{
2666 return WIDGET_TYPE_SEARCH_EDITOR;
2667}
2668
2669//virtual
2670LLString LLSearchEditor::getWidgetTag() const
2671{
2672 return LL_SEARCH_EDITOR_TAG;
2673}
2674
2675//virtual
2676void LLSearchEditor::setValue(const LLSD& value )
2677{
2678 mSearchEdit->setValue(value);
2679}
2680
2681//virtual
2682LLSD LLSearchEditor::getValue() const
2683{
2684 return mSearchEdit->getValue();
2685}
2686
2687//virtual
2688BOOL LLSearchEditor::setTextArg( const LLString& key, const LLStringExplicit& text )
2689{
2690 return mSearchEdit->setTextArg(key, text);
2691}
2692
2693//virtual
2694BOOL LLSearchEditor::setLabelArg( const LLString& key, const LLStringExplicit& text )
2695{
2696 return mSearchEdit->setLabelArg(key, text);
2697}
2698
2699//virtual
2700void LLSearchEditor::clear()
2701{
2702 if (mSearchEdit)
2703 {
2704 mSearchEdit->clear();
2705 }
2706}
2707
2708 2558
2709void LLSearchEditor::draw() 2559void LLSearchEditor::draw()
2710{ 2560{
@@ -2713,10 +2563,6 @@ void LLSearchEditor::draw()
2713 LLUICtrl::draw(); 2563 LLUICtrl::draw();
2714} 2564}
2715 2565
2716void LLSearchEditor::setText(const LLStringExplicit &new_text)
2717{
2718 mSearchEdit->setText(new_text);
2719}
2720 2566
2721//static 2567//static
2722void LLSearchEditor::onSearchEdit(LLLineEditor* caller, void* user_data ) 2568void LLSearchEditor::onSearchEdit(LLLineEditor* caller, void* user_data )