diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index 9916c9465..0683c2493 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -443,28 +443,9 @@ void LLLineEditor::deselect() } -void LLLineEditor::spell_correct(void* data) +void LLLineEditor::spell_show(void* show) { - SpellMenuBind* tempBind = (SpellMenuBind*)data; - LLLineEditor* line = tempBind->origin; - if(tempBind && line) - { - LL_INFOS() << ((LLMenuItemCallGL *)(tempBind->menuItem))->getName() << " : " << tempBind->origin->getName() << " : " << tempBind->word << LL_ENDL; - if(line)line->spellReplace(tempBind); - } -} - - -void LLLineEditor::spell_show(void * data) -{ - SpellMenuBind* tempBind = (SpellMenuBind*)data; - LLLineEditor* line = tempBind->origin; - - if (tempBind && line) - { - BOOL show = (tempBind->word == "Show Misspellings"); - glggHunSpell->setSpellCheckHighlight(show); - } + glggHunSpell->setSpellCheckHighlight(!!show); } std::vector LLLineEditor::getMisspelledWordsPositions() @@ -516,11 +497,12 @@ std::vector LLLineEditor::getMisspelledWordsPositions() void LLLineEditor::spell_add(void* data) { - SpellMenuBind* tempBind = (SpellMenuBind*)data; - if(tempBind) + auto self = static_cast(data); + S32 wordStart = 0, wordLen = 0; + if (self->getWordBoundriesAt(self->calculateCursorFromMouse(self->mLastContextMenuX), &wordStart, &wordLen)) { - glggHunSpell->addWordToCustomDictionary(tempBind->word); - tempBind->origin->mPrevSpelledText="";//make it update + glggHunSpell->addWordToCustomDictionary(wstring_to_utf8str(self->getWText().substr(wordStart, wordLen))); + self->mPrevSpelledText.clear(); //make it update } } @@ -1149,12 +1131,19 @@ void LLLineEditor::copy() } -void LLLineEditor::spellReplace(SpellMenuBind* spellData) +void LLLineEditor::spell_correct(void* data) { - mText.erase(spellData->wordPositionStart, - spellData->wordPositionEnd - spellData->wordPositionStart); - insert(spellData->word,spellData->wordPositionStart); - mCursorPos+=spellData->word.length() - (spellData->wordPositionEnd-spellData->wordPositionStart); + auto self = static_cast(data); + S32 wordStart = 0, wordLen = 0; + if (self->getWordBoundriesAt(self->calculateCursorFromMouse(self->mLastContextMenuX), &wordStart, &wordLen)) + { + auto word = utf8str_to_wstring(LLMenuGL::sMenuContainer->getActivatedItem()->getLabel()); + LLWStringUtil::replaceTabsWithSpaces(word, 4); + + self->mText.erase(wordStart, wordLen); + self->mText.insert(wordStart, word); + self->mCursorPos += word.length() - wordLen; + } } @@ -3017,15 +3006,6 @@ void LLLineEditor::showContextMenu(S32 x, S32 y) { gEditMenuHandler = this; - /*S32 screen_x, screen_y; - localPointToScreen(x, y, &screen_x, &screen_y); - menu->show(screen_x, screen_y);*/ - - - //setCursorAtLocalPos( x); - S32 wordStart = 0; - S32 wordLen = 0; - S32 pos = calculateCursorFromMouse(x); LLMenuGL* menu = (LLMenuGL*)mContextMenuHandle.get(); if (menu) @@ -3034,77 +3014,33 @@ void LLLineEditor::showContextMenu(S32 x, S32 y) { menu->setVisible(FALSE); } - for (int i = 0;i<(int)suggestionMenuItems.size();i++) - { - SpellMenuBind * tempBind = suggestionMenuItems[i]; - if(tempBind) - { - menu->removeChild((LLMenuItemCallGL *)tempBind->menuItem); - ((LLMenuItemCallGL *)tempBind->menuItem)->die(); - //delete tempBind->menuItem; - //tempBind->menuItem = NULL; - delete tempBind; - } - } - suggestionMenuItems.clear(); // spell_check="true" in xui - menu->setItemVisible("Spelsep", !mReadOnly && mSpellCheckable); if (!mReadOnly && mSpellCheckable) { // search for word matches - bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordLen); - if (is_word_part) + S32 wordStart = 0; + S32 wordLen = 0; + S32 pos = calculateCursorFromMouse(x); + if (getWordBoundriesAt(pos, &wordStart, &wordLen)) { - const LLWString& text = mText.getWString(); - std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordLen)); - - if (!glggHunSpell->isSpelledRight(selectedWord)) - { - //misspelled word here, and you have just right clicked on it! - std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); + const auto selectedWord = wstring_to_utf8str(getWText().substr(wordStart, wordLen)); - for (int i = 0; i<(int)suggs.size() ;i++) + if (!glggHunSpell->isSpelledRight(selectedWord)) + { + //misspelled word here, and you have just right clicked on it! + + for (const auto& word : glggHunSpell->getSuggestionList(selectedWord)) { - SpellMenuBind * tempStruct = new SpellMenuBind; - tempStruct->origin = this; - tempStruct->word = suggs[i]; - tempStruct->wordPositionEnd = wordStart + wordLen; - tempStruct->wordPositionStart=wordStart; - LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - tempStruct->word, spell_correct, NULL, tempStruct); - tempStruct->menuItem = suggMenuItem; - suggestionMenuItems.push_back(tempStruct); - menu->addChild(suggMenuItem); + menu->addChild(new LLMenuItemCallGL(word, spell_correct, nullptr, this)); } - SpellMenuBind * tempStruct = new SpellMenuBind; - tempStruct->origin = this; - tempStruct->word = selectedWord; - tempStruct->wordPositionEnd = wordStart + wordLen; - tempStruct->wordPositionStart=wordStart; - LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - "Add Word", spell_add, NULL, tempStruct); - tempStruct->menuItem = suggMenuItem; - suggestionMenuItems.push_back(tempStruct); - menu->addChild(suggMenuItem); + menu->addChild(new LLMenuItemCallGL("Add Word", spell_add, nullptr, this)); } } - SpellMenuBind * tempStruct = new SpellMenuBind; - tempStruct->origin = this; - if (glggHunSpell->getSpellCheckHighlight()) - { - tempStruct->word = "Hide Misspellings"; - } - else - { - tempStruct->word = "Show Misspellings"; - } - LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - tempStruct->word, spell_show, NULL, tempStruct); - tempStruct->menuItem = suggMenuItem; - suggestionMenuItems.push_back(tempStruct); - menu->addChild(suggMenuItem); + bool show = !glggHunSpell->getSpellCheckHighlight(); + auto word = show ? "Show Misspellings" : "Hide Misspellings"; + menu->addChild(new LLMenuItemCallGL(word, spell_show, nullptr, show ? &show : nullptr)); } mLastContextMenuX = x; diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h index c6712b7cf..440407cd8 100644 --- a/indra/llui/lllineeditor.h +++ b/indra/llui/lllineeditor.h @@ -101,16 +101,6 @@ public: /*virtual*/ BOOL handleUnicodeCharHere(llwchar uni_char); /*virtual*/ void onMouseCaptureLost(); - struct SpellMenuBind - { - LLLineEditor* origin; - void * menuItem; - std::string word; - S32 wordPositionStart; - S32 wordPositionEnd; - }; - - virtual void spellReplace(SpellMenuBind* spellData); virtual void insert(std::string what,S32 wher); // LLEditMenuHandler overrides @@ -304,7 +294,6 @@ protected: S32 mEndSpellHere; // the location of the last char on the screen BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field LLFrameTimer mSpellTimer; - std::vector suggestionMenuItems; S32 mLastContextMenuX; // line history support: diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index c4cdbbdf8..bb29e1782 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -508,26 +508,23 @@ public: void LLTextEditor::spell_correct(void* data) { - SpellMenuBind* tempBind = (SpellMenuBind*)data; - LLTextEditor* line = tempBind->origin; - if(tempBind && line) + auto self = static_cast(data); + S32 wordStart = 0, wordLen = 0; + if (self->getWordBoundriesAt(self->getCursorPosFromLocalCoord(self->mLastContextMenuX, self->mLastContextMenuY, TRUE), &wordStart, &wordLen)) { - LL_INFOS() << tempBind->menuItem->getName() << " : " << tempBind->origin->getName() << " : " << tempBind->word << LL_ENDL; - if(line)line->spellReplace(tempBind); + const auto& word = utf8str_to_wstring(LLMenuGL::sMenuContainer->getActivatedItem()->getLabel()); + + self->remove(wordStart, wordLen, TRUE); + self->insert(wordStart, word, FALSE); + self->mCursorPos += word.length() - wordLen; + self->needsReflow(); } } -void LLTextEditor::spell_show(void * data) +void LLTextEditor::spell_show(void* show) { - SpellMenuBind* tempBind = (SpellMenuBind*)data; - LLTextEditor* line = tempBind->origin; - - if(tempBind && line) - { - BOOL show = (tempBind->word == "Show Misspellings"); - glggHunSpell->setSpellCheckHighlight(show); - } + glggHunSpell->setSpellCheckHighlight(!!show); } @@ -574,11 +571,12 @@ std::vector LLTextEditor::getMisspelledWordsPositions() void LLTextEditor::spell_add(void* data) { - SpellMenuBind* tempBind = (SpellMenuBind*)data; - if(tempBind) + auto self = static_cast(data); + S32 wordStart = 0, wordLen = 0; + if (self->getWordBoundriesAt(self->getCursorPosFromLocalCoord(self->mLastContextMenuX, self->mLastContextMenuY, TRUE), &wordStart, &wordLen)) { - glggHunSpell->addWordToCustomDictionary(tempBind->word); - tempBind->origin->mPrevSpelledText.erase();//make it update + glggHunSpell->addWordToCustomDictionary(wstring_to_utf8str(self->getWText().substr(wordStart, wordLen))); + self->mPrevSpelledText.erase(); //make it update } } @@ -1531,35 +1529,13 @@ BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) } BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) { - setFocus(TRUE); - //setCursorAtLocalPos( x, y, TRUE ); - S32 wordStart = 0; - S32 wordLen = 0; - S32 pos = getCursorPosFromLocalCoord(x,y,TRUE); - - LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); - if (menu) - { - for (auto tempBind : suggestionMenuItems) - { - if (tempBind) - { - menu->removeChild(tempBind->menuItem); - tempBind->menuItem->die(); - delete tempBind; - } - } - suggestionMenuItems.clear(); - menu->die(); - } - auto segment = getSegmentAtLocalPos(x, y); const LLStyleSP style = segment ? segment->getStyle() : nullptr; auto submenu = (style && style->isLink()) ? createUrlContextMenu(x, y, style->getLinkHREF()) : nullptr; // Add url menu to base menu if we have a selection, otherwise make it the menu. - menu = (submenu && !hasSelection()) ? submenu : LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", LLMenuGL::sMenuContainer); + auto menu = (submenu && !hasSelection()) ? submenu : LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", LLMenuGL::sMenuContainer); mPopupMenuHandle = menu->getHandle(); if (menu) { @@ -1572,62 +1548,29 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) // spell_check="true" in xui if (!mReadOnly && mSpellCheckable) { - bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordLen); - if (is_word_part) + S32 wordStart = 0; + S32 wordLen = 0; + S32 pos = getCursorPosFromLocalCoord(x, y, TRUE); + if (getWordBoundriesAt(pos, &wordStart, &wordLen)) { - const LLWString &text = mWText; - std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart, wordLen)); + const auto selectedWord = wstring_to_utf8str(getWText().substr(wordStart, wordLen)); if (!glggHunSpell->isSpelledRight(selectedWord)) { //misspelled word here, and you have just right clicked on it! - std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); menu->addSeparator(); - for (auto word : suggs) + for (const auto& word : glggHunSpell->getSuggestionList(selectedWord)) { - SpellMenuBind * tempStruct = new SpellMenuBind; - tempStruct->origin = this; - tempStruct->word = word; - tempStruct->wordPositionEnd = wordStart + wordLen; - tempStruct->wordPositionStart = wordStart; - tempStruct->wordY = y; - LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - tempStruct->word, spell_correct, NULL, tempStruct); - tempStruct->menuItem = suggMenuItem; - suggestionMenuItems.push_back(tempStruct); - menu->addChild(suggMenuItem); + menu->addChild(new LLMenuItemCallGL(word, spell_correct, nullptr, this)); } - SpellMenuBind * tempStruct = new SpellMenuBind; - tempStruct->origin = this; - tempStruct->word = selectedWord; - tempStruct->wordPositionEnd = wordStart + wordLen; - tempStruct->wordPositionStart = wordStart; - tempStruct->wordY = y; - LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - "Add Word", spell_add, NULL, tempStruct); - tempStruct->menuItem = suggMenuItem; - suggestionMenuItems.push_back(tempStruct); - menu->addChild(suggMenuItem); + menu->addChild(new LLMenuItemCallGL("Add Word", spell_add, nullptr, this)); } } - SpellMenuBind * tempStruct = new SpellMenuBind; - tempStruct->origin = this; - if (glggHunSpell->getSpellCheckHighlight()) - { - tempStruct->word = "Hide Misspellings"; - } - else - { - tempStruct->word = "Show Misspellings"; - } - - LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - tempStruct->word, spell_show, NULL, tempStruct); - tempStruct->menuItem = suggMenuItem; - suggestionMenuItems.push_back(tempStruct); - menu->addChild(suggMenuItem); + bool show = !glggHunSpell->getSpellCheckHighlight(); + auto word = show ? "Show Misspellings" : "Hide Misspellings"; + menu->addChild(new LLMenuItemCallGL(word, spell_show, nullptr, show ? &show : nullptr)); } mLastContextMenuX = x; @@ -2423,17 +2366,6 @@ BOOL LLTextEditor::canPaste() const } -void LLTextEditor::spellReplace(SpellMenuBind* spellData) -{ - remove( spellData->wordPositionStart, - spellData->wordPositionEnd - spellData->wordPositionStart, TRUE ); - LLWString clean_string = utf8str_to_wstring(spellData->word); - insert(spellData->wordPositionStart, clean_string, FALSE); - mCursorPos+=clean_string.length() - (spellData->wordPositionEnd-spellData->wordPositionStart); - needsReflow(); -} - - // paste from clipboard void LLTextEditor::paste() { diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index b5d3eb699..081210b0e 100644 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -126,16 +126,6 @@ public: virtual BOOL isDirty() const { return( mLastCmd != NULL || (mPristineCmd && (mPristineCmd != mLastCmd)) ); } BOOL isSpellDirty() const { return mWText != mPrevSpelledText; } // Returns TRUE if user changed value at all void resetSpellDirty() { mPrevSpelledText = mWText; } // Clear dirty state - - struct SpellMenuBind - { - LLTextEditor* origin; - LLMenuItemCallGL * menuItem; - std::string word; - S32 wordPositionStart; - S32 wordPositionEnd; - S32 wordY; - }; // LLEditMenuHandler interface virtual void undo(); @@ -151,8 +141,6 @@ public: virtual void paste(); virtual BOOL canPaste() const; - virtual void spellReplace(SpellMenuBind* spellData); - virtual void updatePrimary(); virtual void copyPrimary(); virtual void pastePrimary(); @@ -580,7 +568,6 @@ private: typedef std::vector line_list_t; //to keep track of what we have to remove before showing menu - std::vector suggestionMenuItems; S32 mLastContextMenuX; S32 mLastContextMenuY;