aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lltexteditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llui/lltexteditor.cpp')
-rw-r--r--linden/indra/llui/lltexteditor.cpp267
1 files changed, 140 insertions, 127 deletions
diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp
index 6e5cdc4..d2469c3 100644
--- a/linden/indra/llui/lltexteditor.cpp
+++ b/linden/indra/llui/lltexteditor.cpp
@@ -323,7 +323,7 @@ LLTextEditor::LLTextEditor(
323 mLastSelectionY(-1), 323 mLastSelectionY(-1),
324 mReflowNeeded(FALSE), 324 mReflowNeeded(FALSE),
325 mScrollNeeded(FALSE), 325 mScrollNeeded(FALSE),
326 mOverRideAndShowMisspellings(FALSE) 326 mShowMisspellings(FALSE)
327{ 327{
328 mSourceID.generate(); 328 mSourceID.generate();
329 329
@@ -490,10 +490,10 @@ void LLTextEditor::spell_show(void * data)
490 { 490 {
491 if(tempBind->word=="Show Misspellings") 491 if(tempBind->word=="Show Misspellings")
492 { 492 {
493 line->setOverRideAndShowMisspellings(TRUE); 493 line->setShowMisspellings(TRUE);
494 }else 494 }else
495 { 495 {
496 line->setOverRideAndShowMisspellings(FALSE); 496 line->setShowMisspellings(FALSE);
497 } 497 }
498 } 498 }
499} 499}
@@ -1426,7 +1426,6 @@ BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask)
1426} 1426}
1427BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) 1427BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask )
1428{ 1428{
1429
1430 setFocus(TRUE); 1429 setFocus(TRUE);
1431 1430
1432 //setCursorAtLocalPos( x, y, TRUE ); 1431 //setCursorAtLocalPos( x, y, TRUE );
@@ -1450,69 +1449,73 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask )
1450 } 1449 }
1451 suggestionMenuItems.clear(); 1450 suggestionMenuItems.clear();
1452 1451
1453 menu->setItemVisible("Translate To",!mReadOnly); 1452 menu->setItemVisible("Translate To", !mReadOnly);
1454 menu->setItemVisible("Transep",!mReadOnly); 1453 menu->setItemVisible("Transep", !mReadOnly);
1455
1456 const LLWString &text = mWText;
1457 1454
1458 if(( isPartOfWord( text[wordEnd] ) )&&(!mReadOnly)) 1455 // spell_check="true" in xui
1456 if (!mReadOnly && mShowMisspellings)
1459 { 1457 {
1460 // Select word the cursor is over 1458 const LLWString &text = mWText;
1461 while ((wordEnd > 0) && isPartOfWord(text[wordEnd-1])) 1459
1462 { 1460 if (isPartOfWord(text[wordEnd]) && !mReadOnly)
1463 wordEnd--;
1464 }
1465 wordStart=wordEnd;
1466 //startSelection();
1467
1468 while ((wordEnd < (S32)text.length()) && isPartOfWord( text[wordEnd] ) )
1469 {
1470 wordEnd++;
1471 }
1472 std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart));
1473 if(!glggHunSpell->isSpelledRight(selectedWord))
1474 { 1461 {
1475 //misspelled word here, and you have just right clicked on it! 1462 // Select word the cursor is over
1476 std::vector<std::string> suggs = glggHunSpell->getSuggestionList(selectedWord); 1463 while ((wordEnd > 0) && isPartOfWord(text[wordEnd-1]))
1464 {
1465 wordEnd--;
1466 }
1467 wordStart = wordEnd;
1468 //startSelection();
1477 1469
1478 //menu->setItemVisible("Transep",(suggs.size()>0)); 1470 while ((wordEnd < (S32)text.length()) && isPartOfWord( text[wordEnd] ) )
1479 for(int i = 0;i<(int)suggs.size();i++) 1471 {
1472 wordEnd++;
1473 }
1474 std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart));
1475 if (!glggHunSpell->isSpelledRight(selectedWord))
1480 { 1476 {
1477 //misspelled word here, and you have just right clicked on it!
1478 std::vector<std::string> suggs = glggHunSpell->getSuggestionList(selectedWord);
1479
1480 //menu->setItemVisible("Transep",(suggs.size()>0));
1481 for (int i = 0; i<(int)suggs.size(); i++)
1482 {
1483 SpellMenuBind * tempStruct = new SpellMenuBind;
1484 tempStruct->origin = this;
1485 tempStruct->word = suggs[i];
1486 tempStruct->wordPositionEnd = wordEnd;
1487 tempStruct->wordPositionStart=wordStart;
1488 tempStruct->wordY=y;
1489 LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL(
1490 tempStruct->word, spell_correct, NULL, tempStruct);
1491 tempStruct->menuItem = suggMenuItem;
1492 suggestionMenuItems.push_back(tempStruct);
1493 menu->append(suggMenuItem);
1494 }
1481 SpellMenuBind * tempStruct = new SpellMenuBind; 1495 SpellMenuBind * tempStruct = new SpellMenuBind;
1482 tempStruct->origin = this; 1496 tempStruct->origin = this;
1483 tempStruct->word = suggs[i]; 1497 tempStruct->word = selectedWord;
1484 tempStruct->wordPositionEnd = wordEnd; 1498 tempStruct->wordPositionEnd = wordEnd;
1485 tempStruct->wordPositionStart=wordStart; 1499 tempStruct->wordPositionStart=wordStart;
1486 tempStruct->wordY=y; 1500 tempStruct->wordY=y;
1487 LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( 1501 LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL(
1488 tempStruct->word, spell_correct, NULL, tempStruct); 1502 "Add Word", spell_add, NULL, tempStruct);
1489 tempStruct->menuItem = suggMenuItem; 1503 tempStruct->menuItem = suggMenuItem;
1490 suggestionMenuItems.push_back(tempStruct); 1504 suggestionMenuItems.push_back(tempStruct);
1491 menu->append(suggMenuItem); 1505 menu->append(suggMenuItem);
1492 } 1506 }
1493 SpellMenuBind * tempStruct = new SpellMenuBind;
1494 tempStruct->origin = this;
1495 tempStruct->word = selectedWord;
1496 tempStruct->wordPositionEnd = wordEnd;
1497 tempStruct->wordPositionStart=wordStart;
1498 tempStruct->wordY=y;
1499 LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL(
1500 "Add Word", spell_add, NULL, tempStruct);
1501 tempStruct->menuItem = suggMenuItem;
1502 suggestionMenuItems.push_back(tempStruct);
1503 menu->append(suggMenuItem);
1504 } 1507 }
1505 1508
1506 }
1507 if((!mReadOnly)&&((!glggHunSpell->highlightInRed)
1508 ||(mOverRideAndShowMisspellings)||(mShowLineNumbers)))
1509 {
1510 SpellMenuBind * tempStruct = new SpellMenuBind; 1509 SpellMenuBind * tempStruct = new SpellMenuBind;
1511 tempStruct->origin = this; 1510 tempStruct->origin = this;
1512 if(mOverRideAndShowMisspellings) 1511 if (glggHunSpell->mSpellCheckHighlight)
1512 {
1513 tempStruct->word = "Hide Misspellings"; 1513 tempStruct->word = "Hide Misspellings";
1514 }
1514 else 1515 else
1516 {
1515 tempStruct->word = "Show Misspellings"; 1517 tempStruct->word = "Show Misspellings";
1518 }
1516 LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( 1519 LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL(
1517 tempStruct->word, spell_show, NULL, tempStruct); 1520 tempStruct->word, spell_show, NULL, tempStruct);
1518 tempStruct->menuItem = suggMenuItem; 1521 tempStruct->menuItem = suggMenuItem;
@@ -3077,51 +3080,57 @@ void LLTextEditor::drawSelectionBackground()
3077 } 3080 }
3078 } 3081 }
3079} 3082}
3083
3080void LLTextEditor::autoCorrectText() 3084void LLTextEditor::autoCorrectText()
3081{ 3085{
3082
3083 static BOOL *doAnything = rebind_llcontrol<BOOL>("EmeraldEnableAutoCorrect", &gSavedSettings, true); 3086 static BOOL *doAnything = rebind_llcontrol<BOOL>("EmeraldEnableAutoCorrect", &gSavedSettings, true);
3084 if( (!mReadOnly) && (*doAnything) && (isSpellDirty()) ) 3087 if (!mReadOnly && *doAnything && isSpellDirty())
3085 { 3088 {
3086 S32 wordStart = 0; 3089 S32 wordStart = 0;
3087 S32 wordEnd = mCursorPos-1; 3090 S32 wordEnd = mCursorPos-1;
3088 if(wordEnd<1)return; 3091 if (wordEnd < 1)
3092 {
3093 return;
3094 }
3089 LLWString& text = mWText; 3095 LLWString& text = mWText;
3090 if(text.size()<1)return; 3096 if (text.size() < 1 || LLTextEditor::isPartOfWord(text[wordEnd]))
3091 if( LLTextEditor::isPartOfWord( text[wordEnd] )) return;//we only check on word breaks 3097 {
3098 return;//we only check on word breaks
3099 }
3100
3092 wordEnd--; 3101 wordEnd--;
3093 if( LLTextEditor::isPartOfWord( text[wordEnd] ) ) 3102 if (LLTextEditor::isPartOfWord(text[wordEnd]))
3094 { 3103 {
3095 while ((wordEnd > 0) && (text[wordEnd-1]!=' ')) 3104 while ((wordEnd > 0) && (text[wordEnd-1]!=' '))
3096 { 3105 {
3097 wordEnd--; 3106 wordEnd--;
3098 } 3107 }
3099 wordStart=wordEnd; 3108 wordStart = wordEnd;
3100 while ((wordEnd < (S32)text.length()) && (' '!= text[wordEnd] ) ) 3109 while ((wordEnd < (S32)text.length()) && (' '!= text[wordEnd] ) )
3101 { 3110 {
3102 wordEnd++; 3111 wordEnd++;
3103 } 3112 }
3104 std::string lastTypedWord(std::string(text.begin(), 3113 std::string lastTypedWord(std::string(text.begin(),
3105 text.end()).substr(wordStart,wordEnd-wordStart)); 3114 text.end()).substr(wordStart, wordEnd-wordStart));
3106 3115
3107 std::string regText(text.begin(),text.end()); 3116 std::string regText(text.begin(), text.end());
3108 3117
3109 std::string correctedWord(LGGAutoCorrect::getInstance()->replaceWord(lastTypedWord)); 3118 std::string correctedWord(LGGAutoCorrect::getInstance()->replaceWord(lastTypedWord));
3110 if(correctedWord!=lastTypedWord) 3119 if (correctedWord != lastTypedWord)
3111 { 3120 {
3112 int dif = correctedWord.length()-lastTypedWord.length(); 3121 int dif = correctedWord.length() - lastTypedWord.length();
3113 regText.replace(wordStart,lastTypedWord.length(),correctedWord); 3122 regText.replace(wordStart, lastTypedWord.length(), correctedWord);
3114 mWText=utf8str_to_wstring(regText); 3123 mWText = utf8str_to_wstring(regText);
3115 mCursorPos+=dif; 3124 mCursorPos += dif;
3116 needsReflow(); 3125 needsReflow();
3117 } 3126 }
3118 } 3127 }
3119 } 3128 }
3120} 3129}
3130
3121void LLTextEditor::drawMisspelled() 3131void LLTextEditor::drawMisspelled()
3122{ 3132{
3123 if(mReadOnly)return; 3133 if (!mReadOnly && mShowMisspellings)
3124 if(glggHunSpell->highlightInRed || mOverRideAndShowMisspellings)
3125 { 3134 {
3126 if( 3135 if(
3127 ( ((getLength()<400)||(false)) &&( (S32(mSpellTimer.getElapsedTimeF32() / 1) & 1) )) 3136 ( ((getLength()<400)||(false)) &&( (S32(mSpellTimer.getElapsedTimeF32() / 1) & 1) ))
@@ -3132,80 +3141,86 @@ void LLTextEditor::drawMisspelled()
3132 S32 newSpellStart = getLineStart(mScrollbar->getDocPos());//start at the scroll start 3141 S32 newSpellStart = getLineStart(mScrollbar->getDocPos());//start at the scroll start
3133 S32 newSpellEnd = getLineStart(mScrollbar->getDocPos() + 1 + mScrollbar->getDocSize()-mScrollbar->getDocPosMax());//end at the end o.o 3142 S32 newSpellEnd = getLineStart(mScrollbar->getDocPos() + 1 + mScrollbar->getDocSize()-mScrollbar->getDocPosMax());//end at the end o.o
3134 3143
3135 if(mScrollbar->getDocPos() == mScrollbar->getDocPosMax()) 3144 if (mScrollbar->getDocPos() == mScrollbar->getDocPosMax())
3136 { 3145 {
3137 newSpellEnd=(S32)mWText.length(); 3146 newSpellEnd = (S32)mWText.length();
3138 } 3147 }
3139 if((isSpellDirty())||(newSpellEnd!=spellEnd || newSpellStart!=spellStart)) 3148 if (isSpellDirty() || (newSpellEnd!=spellEnd || newSpellStart!=spellStart))
3140 { 3149 {
3141 spellEnd = newSpellEnd; 3150 spellEnd = newSpellEnd;
3142 spellStart = newSpellStart; 3151 spellStart = newSpellStart;
3143 misspellLocations=getMisspelledWordsPositions(); 3152 misspellLocations = getMisspelledWordsPositions();
3144 } 3153 }
3145 } 3154 }
3146 //draw 3155 //draw
3147 for(int i =0;i<(int)misspellLocations.size();i++) 3156 if (glggHunSpell->mSpellCheckHighlight)
3148 { 3157 {
3149 S32 wstart = misspellLocations[i]; 3158 for (int i = 0; i<(int)misspellLocations.size() ;i++)
3150 S32 wend = misspellLocations[++i];
3151 //start curor code mod
3152 const LLWString &text = mWText;
3153 const S32 text_len = getLength();
3154 // Skip through the lines we aren't drawing.
3155 S32 search_pos = mScrollbar->getDocPos();
3156 S32 num_lines = getLineCount();
3157 if (search_pos >= num_lines)return;
3158 S32 line_start = getLineStart(search_pos);
3159 F32 line_height = mGLFont->getLineHeight();
3160 F32 text_y = (F32)(mTextRect.mTop) - line_height;
3161
3162 F32 word_left = 0.f;
3163 F32 word_right = 0.f;
3164 F32 word_bottom = 0.f;
3165 BOOL word_visible = FALSE;
3166
3167 S32 line_end = 0;
3168 // Determine if the cursor is visible and if so what its coordinates are.
3169 while( (mTextRect.mBottom <= llround(text_y)) && (search_pos < num_lines))
3170 { 3159 {
3171 line_end = text_len + 1; 3160 S32 wstart = misspellLocations[i];
3172 S32 next_line = -1; 3161 S32 wend = misspellLocations[++i];
3173 3162 //start curor code mod
3174 if ((search_pos + 1) < num_lines) 3163 const LLWString &text = mWText;
3164 const S32 text_len = getLength();
3165 // Skip through the lines we aren't drawing.
3166 S32 search_pos = mScrollbar->getDocPos();
3167 S32 num_lines = getLineCount();
3168 if (search_pos >= num_lines)
3175 { 3169 {
3176 next_line = getLineStart(search_pos + 1); 3170 return;
3177 line_end = next_line - 1;
3178 } 3171 }
3179 const llwchar* line = text.c_str() + line_start; 3172 S32 line_start = getLineStart(search_pos);
3180 // Find the cursor and selection bounds 3173 F32 line_height = mGLFont->getLineHeight();
3181 if( line_start <= wstart && wend <= line_end ) 3174 F32 text_y = (F32)(mTextRect.mTop) - line_height;
3175
3176 F32 word_left = 0.f;
3177 F32 word_right = 0.f;
3178 F32 word_bottom = 0.f;
3179 BOOL word_visible = FALSE;
3180
3181 S32 line_end = 0;
3182 // Determine if the cursor is visible and if so what its coordinates are.
3183 while( (mTextRect.mBottom <= llround(text_y)) && (search_pos < num_lines))
3182 { 3184 {
3183 word_visible = TRUE; 3185 line_end = text_len + 1;
3184 word_left = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wstart - line_start, mAllowEmbeddedItems )-1.f; 3186 S32 next_line = -1;
3185 word_right = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wend - line_start, mAllowEmbeddedItems )+1.f; 3187
3186 word_bottom = text_y; 3188 if ((search_pos + 1) < num_lines)
3187 break; 3189 {
3190 next_line = getLineStart(search_pos + 1);
3191 line_end = next_line - 1;
3192 }
3193 const llwchar* line = text.c_str() + line_start;
3194 // Find the cursor and selection bounds
3195 if( line_start <= wstart && wend <= line_end )
3196 {
3197 word_visible = TRUE;
3198 word_left = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wstart - line_start, mAllowEmbeddedItems )-1.f;
3199 word_right = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wend - line_start, mAllowEmbeddedItems )+1.f;
3200 word_bottom = text_y;
3201 break;
3202 }
3203 // move down one line
3204 text_y -= line_height;
3205 line_start = next_line;
3206 search_pos++;
3188 } 3207 }
3189 // move down one line 3208 if (mShowLineNumbers)
3190 text_y -= line_height;
3191 line_start = next_line;
3192 search_pos++;
3193 }
3194 if(mShowLineNumbers)
3195 {
3196 word_left += UI_TEXTEDITOR_LINE_NUMBER_MARGIN;
3197 word_right += UI_TEXTEDITOR_LINE_NUMBER_MARGIN;
3198 }
3199 // Draw the cursor
3200 if( word_visible )
3201 {
3202 //end cursos code mod
3203 gGL.color4ub(255,0,0,200);
3204 while(word_left<word_right)
3205 { 3209 {
3206 gl_line_2d(word_left,word_bottom-2,word_left+3,word_bottom+1); 3210 word_left += UI_TEXTEDITOR_LINE_NUMBER_MARGIN;
3207 gl_line_2d(word_left+3,word_bottom+1,word_left+6,word_bottom-2); 3211 word_right += UI_TEXTEDITOR_LINE_NUMBER_MARGIN;
3208 word_left+=6; 3212 }
3213 // Draw the cursor
3214 if (word_visible)
3215 {
3216 //end cursor code mod
3217 gGL.color4ub(255,0,0,200);
3218 while (word_left<word_right)
3219 {
3220 gl_line_2d(word_left,word_bottom-2, word_left+3,word_bottom+1);
3221 gl_line_2d(word_left+3,word_bottom+1, word_left+6,word_bottom-2);
3222 word_left += 6;
3223 }
3209 } 3224 }
3210 } 3225 }
3211 } 3226 }
@@ -3214,8 +3229,7 @@ void LLTextEditor::drawMisspelled()
3214 3229
3215void LLTextEditor::drawCursor() 3230void LLTextEditor::drawCursor()
3216{ 3231{
3217 if( gFocusMgr.getKeyboardFocus() == this 3232 if (!mReadOnly && gFocusMgr.getKeyboardFocus() == this && gShowTextEditCursor)
3218 && gShowTextEditCursor && !mReadOnly)
3219 { 3233 {
3220 const LLWString &text = mWText; 3234 const LLWString &text = mWText;
3221 const S32 text_len = getLength(); 3235 const S32 text_len = getLength();
@@ -3696,10 +3710,7 @@ void LLTextEditor::draw()
3696 drawPreeditMarker(); 3710 drawPreeditMarker();
3697 drawText(); 3711 drawText();
3698 drawCursor(); 3712 drawCursor();
3699 if(!mShowLineNumbers || mOverRideAndShowMisspellings) 3713 drawMisspelled();
3700 {
3701 drawMisspelled();
3702 }
3703 resetSpellDirty(); 3714 resetSpellDirty();
3704 unbindEmbeddedChars(mGLFont); 3715 unbindEmbeddedChars(mGLFont);
3705 3716
@@ -4879,6 +4890,8 @@ void LLTextEditor::setTextEditorParameters(LLXMLNodePtr node)
4879 4890
4880 node->getAttributeBOOL("track_bottom", mTrackBottom); 4891 node->getAttributeBOOL("track_bottom", mTrackBottom);
4881 4892
4893 node->getAttributeBOOL("spell_check", mShowMisspellings);
4894
4882 LLColor4 color; 4895 LLColor4 color;
4883 if (LLUICtrlFactory::getAttributeColor(node,"cursor_color", color)) 4896 if (LLUICtrlFactory::getAttributeColor(node,"cursor_color", color))
4884 { 4897 {