From f5cbabf65e1c1b94d2e53e682c2435daec6164e1 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Fri, 6 Aug 2010 03:34:19 -0700 Subject: Removed unused LLTabContainerVertical cruft --- linden/indra/llui/CMakeLists.txt | 2 -- linden/indra/llui/lltabcontainer.cpp | 1 - linden/indra/llui/lltabcontainervertical.cpp | 33 ---------------------------- linden/indra/llui/lltabcontainervertical.h | 33 ---------------------------- linden/indra/llui/lluictrlfactory.cpp | 1 - linden/indra/llui/lluifwd.h | 1 - 6 files changed, 71 deletions(-) delete mode 100644 linden/indra/llui/lltabcontainervertical.cpp delete mode 100644 linden/indra/llui/lltabcontainervertical.h (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/CMakeLists.txt b/linden/indra/llui/CMakeLists.txt index f646e63..a0f80b4 100644 --- a/linden/indra/llui/CMakeLists.txt +++ b/linden/indra/llui/CMakeLists.txt @@ -63,7 +63,6 @@ set(llui_SOURCE_FILES llspinctrl.cpp llstyle.cpp lltabcontainer.cpp - lltabcontainervertical.cpp lltextbox.cpp lltexteditor.cpp lltextparser.cpp @@ -119,7 +118,6 @@ set(llui_HEADER_FILES llspinctrl.h llstyle.h lltabcontainer.h - lltabcontainervertical.h lltextbox.h lltexteditor.h lltextparser.h diff --git a/linden/indra/llui/lltabcontainer.cpp b/linden/indra/llui/lltabcontainer.cpp index 1f94191..4be779c 100644 --- a/linden/indra/llui/lltabcontainer.cpp +++ b/linden/indra/llui/lltabcontainer.cpp @@ -40,7 +40,6 @@ #include "lltextbox.h" #include "llcriticaldamp.h" #include "lluictrlfactory.h" -#include "lltabcontainervertical.h" #include "llrender.h" const F32 SCROLL_STEP_TIME = 0.4f; diff --git a/linden/indra/llui/lltabcontainervertical.cpp b/linden/indra/llui/lltabcontainervertical.cpp deleted file mode 100644 index a729c95..0000000 --- a/linden/indra/llui/lltabcontainervertical.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/** - * @file lltabcontainervertical.cpp - * @brief LLTabContainerVertical base class - * - * $LicenseInfo:firstyear=2001&license=viewergpl$ - * - * Copyright (c) 2001-2009, Linden Research, Inc. - * - * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 - * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception - * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. - * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. - * $/LicenseInfo$ - */ - -// deprecated: see LLTabContainer diff --git a/linden/indra/llui/lltabcontainervertical.h b/linden/indra/llui/lltabcontainervertical.h deleted file mode 100644 index ce42367..0000000 --- a/linden/indra/llui/lltabcontainervertical.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * @file lltabcontainervertical.h - * @brief LLTabContainerVertical base class - * - * $LicenseInfo:firstyear=2001&license=viewergpl$ - * - * Copyright (c) 2001-2009, Linden Research, Inc. - * - * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 - * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception - * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. - * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. - * $/LicenseInfo$ - */ - -// deprecated: see LLTabContainer diff --git a/linden/indra/llui/lluictrlfactory.cpp b/linden/indra/llui/lluictrlfactory.cpp index 07eb39b..5cfc3ee 100644 --- a/linden/indra/llui/lluictrlfactory.cpp +++ b/linden/indra/llui/lluictrlfactory.cpp @@ -64,7 +64,6 @@ #include "llmultisliderctrl.h" #include "llspinctrl.h" #include "lltabcontainer.h" -#include "lltabcontainervertical.h" #include "lltextbox.h" #include "lltexteditor.h" #include "llui.h" diff --git a/linden/indra/llui/lluifwd.h b/linden/indra/llui/lluifwd.h index 32d5c9b..f99bb39 100644 --- a/linden/indra/llui/lluifwd.h +++ b/linden/indra/llui/lluifwd.h @@ -53,7 +53,6 @@ class LLSlider; class LLSliderCtrl; class LLSpinCtrl; class LLTabContainer; -class LLTabContainerVertical; class LLTextBox; class LLTextEditor; class LLTextureCtrl; -- cgit v1.1 From 463ccc12fa763f70c5392b89a2ec6cd9d68c40a9 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Tue, 10 Aug 2010 15:06:04 -0700 Subject: Applied patch for SNOW-636: parse links to maps.secondlife.com in chat as slurls (viewer2 slurl format) --- linden/indra/llui/lltexteditor.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 00fa517..2d46943 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -4547,6 +4547,12 @@ BOOL LLTextEditor::findHTML(const std::string &line, S32 *begin, S32 *end) const std::string slurlID = "slurl.com/secondlife/"; strpos = url.find(slurlID); + if (strpos < 0) + { + slurlID="maps.secondlife.com/secondlife/"; + strpos = url.find(slurlID); + } + if (strpos < 0) { slurlID="secondlife://"; -- cgit v1.1 From ded1245db74ae4c97d174c5779f8572ee2f032fa Mon Sep 17 00:00:00 2001 From: Patrick Sapinski Date: Tue, 24 Aug 2010 03:04:20 -0400 Subject: added spellcheck + translation from Emerald Viewer. references to modularsystems.sl should be changed! --- linden/indra/llui/lllineeditor.cpp | 521 +++++++++++++++++++++++++++--- linden/indra/llui/lllineeditor.h | 47 ++- linden/indra/llui/llmenugl.cpp | 25 ++ linden/indra/llui/llmenugl.h | 3 + linden/indra/llui/lltexteditor.cpp | 639 +++++++++++++++++++++++++++++++++---- linden/indra/llui/lltexteditor.h | 74 ++++- 6 files changed, 1193 insertions(+), 116 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 21f0800..5441d0a 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -37,7 +37,6 @@ #include "lllineeditor.h" #include "lltexteditor.h" -#include "audioengine.h" #include "llmath.h" #include "llfontgl.h" #include "llgl.h" @@ -57,6 +56,11 @@ #include "lluictrlfactory.h" #include "llclipboard.h" +#include "../newview/lgghunspell_wrapper.h" +#include "../newview/lltranslate.h" +#include "../newview/llviewercontrol.h" +#include "../newview/lggautocorrect.h" + // // Imported globals // @@ -89,6 +93,34 @@ static LLRegisterWidget r1("line_editor"); // // Member functions // +class LineChatTranslationReceiver : public LLTranslate::TranslationReceiver +{ +public : + LineChatTranslationReceiver(const std::string &toLang, LLLineEditor* line): LLTranslate::TranslationReceiver("", toLang), + m_line(line) + { + } + + static boost::intrusive_ptr build(const std::string &toLang,LLLineEditor* line) + { + return boost::intrusive_ptr(new LineChatTranslationReceiver(toLang,line)); + } + +protected: + void handleResponse(const std::string &translation, const std::string &detectedLanguage) + { + static BOOL* rep = rebind_llcontrol("EmeraldTranslateReplace", &gSavedSettings, true); + if(*rep) + m_line->deleteSelection(); + m_line->insert(((*rep)?"":" (") + translation + ((*rep)?"":")"),m_line->getCursor()); + } + void handleFailure() + { + LLTranslate::TranslationReceiver::handleFailure(); + } +private: + LLLineEditor* m_line; +}; LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, const std::string& default_text, const LLFontGL* font, @@ -104,6 +136,7 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, : LLUICtrl( name, rect, TRUE, commit_callback, userdata, FOLLOWS_TOP | FOLLOWS_LEFT ), mMaxLengthBytes(max_length_bytes), + mPopupMenuHandle(), mCursorPos( 0 ), mScrollHPos( 0 ), mTextPadLeft(0), @@ -137,7 +170,8 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mReadOnly(FALSE), mHaveHistory(FALSE), mImage( sImage ), - mReplaceNewlinesWithSpaces( TRUE ) + mReplaceNewlinesWithSpaces( TRUE ), + mOverRideAndShowMisspellings( FALSE ) { llassert( max_length_bytes > 0 ); @@ -175,6 +209,59 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, sImage = LLUI::getUIImage("sm_rounded_corners_simple.tga"); } mImage = sImage; + // make the popup menu available + //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); + LLMenuGL* menu = new LLMenuGL("wot"); + /*if (!menu) + { + menu = new LLMenuGL(LLStringUtil::null); + }*/ + menu->append(new LLMenuItemCallGL("Cut", context_cut, NULL, this)); + menu->append(new LLMenuItemCallGL("Copy", context_copy, NULL, this)); + menu->append(new LLMenuItemCallGL("Paste", context_paste, NULL, this)); + menu->append(new LLMenuItemCallGL("Delete", context_delete, NULL, this)); + menu->append(new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + menu->appendSeparator("Transep"); + LLMenuGL* translatemenu = new LLMenuGL("Translate To"); + translatemenu->setCanTearOff(FALSE); + SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; + translatemenu->append(new LLMenuItemCallGL("English",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="da"; + translatemenu->append(new LLMenuItemCallGL("Danish",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="de"; + translatemenu->append(new LLMenuItemCallGL("Deutsch(German)",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="es"; + translatemenu->append(new LLMenuItemCallGL("Spanish",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="fr"; + translatemenu->append(new LLMenuItemCallGL("French",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="it"; + translatemenu->append(new LLMenuItemCallGL("Italian",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="hu"; + translatemenu->append(new LLMenuItemCallGL("Hungarian",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="nl"; + translatemenu->append(new LLMenuItemCallGL("Dutch",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="pl"; + translatemenu->append(new LLMenuItemCallGL("Polish",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="pt"; + translatemenu->append(new LLMenuItemCallGL("Portugese",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="ru"; + translatemenu->append(new LLMenuItemCallGL("Russian",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="tr"; + translatemenu->append(new LLMenuItemCallGL("Turkish",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="uk"; + translatemenu->append(new LLMenuItemCallGL("Ukrainian",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="zh"; + translatemenu->append(new LLMenuItemCallGL("Chinese",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="ja"; + translatemenu->append(new LLMenuItemCallGL("Japanese",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="ko"; + translatemenu->append(new LLMenuItemCallGL("Korean",translateText, NULL, t)); + menu->appendMenu(translatemenu); + menu->appendSeparator("Spelsep"); + //menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); + menu->setCanTearOff(FALSE); + menu->setVisible(FALSE); + mPopupMenuHandle = menu->getHandle(); } @@ -188,6 +275,7 @@ LLLineEditor::~LLLineEditor() { gEditMenuHandler = NULL; } + LLView::deleteViewByHandle(mPopupMenuHandle); } @@ -343,7 +431,7 @@ void LLLineEditor::setText(const LLStringExplicit &new_text) // Picks a new cursor position based on the actual screen size of text being drawn. -void LLLineEditor::setCursorAtLocalPos( S32 local_mouse_x ) +S32 LLLineEditor::calculateCursorFromMouse( S32 local_mouse_x ) { const llwchar* wtext = mText.getWString().c_str(); LLWString asterix_text; @@ -351,18 +439,22 @@ void LLLineEditor::setCursorAtLocalPos( S32 local_mouse_x ) { for (S32 i = 0; i < mText.length(); i++) { - asterix_text += (llwchar) 0x2022L; + asterix_text += '*'; } wtext = asterix_text.c_str(); } - S32 cursor_pos = - mScrollHPos + + return mScrollHPos + mGLFont->charFromPixelOffset( wtext, mScrollHPos, (F32)(local_mouse_x - mMinHPixels), (F32)(mMaxHPixels - mMinHPixels + 1)); // min-max range is inclusive - setCursor(cursor_pos); + +} +// Picks a new cursor position based on the actual screen size of text being drawn. +void LLLineEditor::setCursorAtLocalPos( S32 local_mouse_x ) +{ + setCursor(calculateCursorFromMouse(local_mouse_x)); } void LLLineEditor::setCursor( S32 pos ) @@ -418,6 +510,125 @@ void LLLineEditor::deselect() } +void LLLineEditor::context_cut(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + if(line)line->cut(); +} +void LLLineEditor::context_copy(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + if(line)line->copy(); +} +void LLLineEditor::spell_correct(void* data) +{ + SpellMenuBind* tempBind = (SpellMenuBind*)data; + LLLineEditor* line = tempBind->origin; + if(tempBind && line) + { + llinfos << ((LLMenuItemCallGL *)(tempBind->menuItem))->getName() << " : " << tempBind->origin->getName() << " : " << tempBind->word << llendl; + if(line)line->spellReplace(tempBind); + + } +} +void LLLineEditor::translateText(void * data) +{ + SpellMenuBind* t = (SpellMenuBind*)data; + LLLineEditor* line = t->origin; + const std::string &toLang = t->word;//LLTranslate::getTranslateLanguage(); + LLHTTPClient::ResponderPtr result = LineChatTranslationReceiver::build(toLang,line); + S32 left_pos = llmin( line->mSelectionStart, line->mSelectionEnd ); + S32 length = abs( line->mSelectionStart - line->mSelectionEnd ); + LLTranslate::translateMessage(result,"", toLang, line->mText.getString().substr(left_pos, length)); +} +void LLLineEditor::spell_show(void * data) +{ + SpellMenuBind* tempBind = (SpellMenuBind*)data; + LLLineEditor* line = tempBind->origin; + + if(tempBind && line) + { + if(tempBind->word=="Show Misspellings") + { + line->setOverRideAndShowMisspellings(TRUE); + }else + { + line->setOverRideAndShowMisspellings(FALSE); + } + } + + +} +std::vector LLLineEditor::getMisspelledWordsPositions() +{ + std::vector thePosesOfBadWords; + const LLWString& text = mText.getWString(); + + //llinfos << "end of box is at " << cursorloc << " and end of text is at " << text.length() << llendl; + S32 wordStart=0; + S32 wordEnd=mStartSpellHere; + while(wordEnd < mEndSpellHere) + { + //go through all the chars... XD + if( LLTextEditor::isPartOfWord( text[wordEnd] ) ) + + { + // Select word the cursor is over + while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) + { + wordEnd--; + } + wordStart=wordEnd; + while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) + { + wordEnd++; + } + //got a word :D + std::string selectedWord(std::string(text.begin(), + text.end()).substr(wordStart,wordEnd-wordStart)); + + if(!glggHunSpell->isSpelledRight(selectedWord)) + { + //misspelled word here, and you have just right clicked on it! + //get the center of this word.. + //S32 center = llround( (wordEnd-wordStart)/2 ) + wordStart; + //turn this cursor position into a pixel pos + //center = findPixelNearestPos(center-getCursor()); + + thePosesOfBadWords.push_back( + wordStart); + thePosesOfBadWords.push_back(wordEnd); + } + } + wordEnd++; + } + return thePosesOfBadWords; +} +void LLLineEditor::spell_add(void* data) +{ + SpellMenuBind* tempBind = (SpellMenuBind*)data; + if(tempBind) + { + glggHunSpell->addWordToCustomDictionary(tempBind->word); + tempBind->origin->mPrevSpelledText="";//make it update + } +} +void LLLineEditor::context_paste(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + if(line)line->paste(); +} +void LLLineEditor::context_delete(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + if(line)line->doDelete(); +} +void LLLineEditor::context_selectall(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + if(line)line->selectAll(); +} + void LLLineEditor::startSelection() { mIsSelecting = TRUE; @@ -508,6 +719,112 @@ BOOL LLLineEditor::handleDoubleClick(S32 x, S32 y, MASK mask) return TRUE; } + +BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) +{ + setFocus(TRUE); + + //setCursorAtLocalPos( x); + S32 wordStart = 0; + S32 wordEnd = calculateCursorFromMouse(x); + + + LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); + if (menu) + { + if(menu->isOpen()) + menu->setVisible(FALSE); + for(int i = 0;i<(int)suggestionMenuItems.size();i++) + { + SpellMenuBind * tempBind = suggestionMenuItems[i]; + if(tempBind) + { + menu->remove((LLMenuItemCallGL *)tempBind->menuItem); + ((LLMenuItemCallGL *)tempBind->menuItem)->die(); + //delete tempBind->menuItem; + //tempBind->menuItem = NULL; + delete tempBind; + } + } + suggestionMenuItems.clear(); + + menu->setItemVisible("Translate To",!mReadOnly); + menu->setItemVisible("Transep",!mReadOnly); + + const LLWString& text = mText.getWString(); + if(( LLTextEditor::isPartOfWord( text[wordEnd] ) ) + &&(!mReadOnly)) + { + // Select word the cursor is over + while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) + { + wordEnd--; + } + wordStart=wordEnd; + //startSelection(); + + while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) + { + wordEnd++; + } + std::string selectedWord(std::string(text.begin(), + text.end()).substr(wordStart,wordEnd-wordStart)); + if(!glggHunSpell->isSpelledRight(selectedWord)) + { + //misspelled word here, and you have just right clicked on it! + std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); + //menu->setItemVisible("Transep",(suggs.size()>0)); + + for(int i = 0;i<(int)suggs.size();i++) + { + SpellMenuBind * tempStruct = new SpellMenuBind; + tempStruct->origin = this; + tempStruct->word = suggs[i]; + tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionStart=wordStart; + LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( + tempStruct->word, spell_correct, NULL, tempStruct); + //new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + tempStruct->menuItem = suggMenuItem; + suggestionMenuItems.push_back(tempStruct); + menu->append(suggMenuItem); + } + SpellMenuBind * tempStruct = new SpellMenuBind; + tempStruct->origin = this; + tempStruct->word = selectedWord; + tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionStart=wordStart; + LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( + "Add Word", spell_add, NULL, tempStruct); + tempStruct->menuItem = suggMenuItem; + suggestionMenuItems.push_back(tempStruct); + menu->append(suggMenuItem); + } + + } + if((!mReadOnly)&&((!glggHunSpell->highlightInRed) + ||(mOverRideAndShowMisspellings))) + { + SpellMenuBind * tempStruct = new SpellMenuBind; + tempStruct->origin = this; + if(mOverRideAndShowMisspellings) + 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->append(suggMenuItem); + } + + menu->buildDrawLabels(); + menu->updateParent(LLMenuGL::sMenuContainer); + LLMenuGL::showPopup(this, menu, x, y); + } + return TRUE; +} + BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) { // Check first whether the "clear search" button wants to deal with this. @@ -912,7 +1229,7 @@ void LLLineEditor::deleteSelection() if( !mReadOnly && hasSelection() ) { S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); - S32 selection_length = abs( mSelectionStart - mSelectionEnd ); + S32 selection_length = llabs( mSelectionStart - mSelectionEnd ); mText.erase(left_pos, selection_length); deselect(); @@ -935,7 +1252,7 @@ void LLLineEditor::cut() S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); - S32 length = abs( mSelectionStart - mSelectionEnd ); + S32 length = llabs( mSelectionStart - mSelectionEnd ); gClipboard.copyFromSubstring( mText.getWString(), left_pos, length ); deleteSelection(); @@ -966,11 +1283,38 @@ void LLLineEditor::copy() if( canCopy() ) { S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); - S32 length = abs( mSelectionStart - mSelectionEnd ); + S32 length = llabs( mSelectionStart - mSelectionEnd ); gClipboard.copyFromSubstring( mText.getWString(), left_pos, length ); } } +void LLLineEditor::spellReplace(SpellMenuBind* spellData) +{ + mText.erase(spellData->wordPositionStart, + spellData->wordPositionEnd - spellData->wordPositionStart); + insert(spellData->word,spellData->wordPositionStart); + mCursorPos+=spellData->word.length() - (spellData->wordPositionEnd-spellData->wordPositionStart); + + +} +void LLLineEditor::insert(std::string what, S32 wher) +{ + LLLineEditorRollback rollback(this); + LLWString clean_string(utf8str_to_wstring(what)); + LLWStringUtil::replaceTabsWithSpaces(clean_string, 4); + mText.insert(wher, clean_string); + //see if we should move over the cursor acordingly + // Validate new string and rollback the if needed. + BOOL need_to_rollback = ( mPrevalidateFunc && !mPrevalidateFunc( mText.getWString() ) ); + if( need_to_rollback ) + { + rollback.doRollback( this ); + reportBadKeystroke(); + } + else if( mKeystrokeCallback ) + mKeystrokeCallback( this, mCallbackUserData ); +} + BOOL LLLineEditor::canPaste() const { return !mReadOnly && gClipboard.canPasteString(); @@ -993,17 +1337,25 @@ void LLLineEditor::pasteHelper(bool is_primary) { bool can_paste_it; if (is_primary) + { can_paste_it = canPastePrimary(); + } else + { can_paste_it = canPaste(); + } if (can_paste_it) { LLWString paste; if (is_primary) + { paste = gClipboard.getPastePrimaryWString(); + } else + { paste = gClipboard.getPasteWString(); + } if (!paste.empty()) { @@ -1018,7 +1370,7 @@ void LLLineEditor::pasteHelper(bool is_primary) // Clean up string (replace tabs and returns and remove characters that our fonts don't support.) LLWString clean_string(paste); - LLWStringUtil::replaceTabsWithSpaces(clean_string, 1); + LLWStringUtil::replaceTabsWithSpaces(clean_string, 4); //clean_string = wstring_detabify(paste, 1); LLWStringUtil::replaceChar(clean_string, '\n', mReplaceNewlinesWithSpaces ? ' ' : 182); // 182 == paragraph character @@ -1074,7 +1426,7 @@ void LLLineEditor::copyPrimary() if( canCopy() ) { S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); - S32 length = abs( mSelectionStart - mSelectionEnd ); + S32 length = llabs( mSelectionStart - mSelectionEnd ); gClipboard.copyFromPrimarySubstring( mText.getWString(), left_pos, length ); } } @@ -1322,6 +1674,14 @@ BOOL LLLineEditor::handleKeyHere(KEY key, MASK mask ) BOOL handled = FALSE; BOOL selection_modified = FALSE; + // SL-51858: Key presses are not being passed to the Popup menu. + // A proper fix is non-trivial so instead just close the menu. + LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); + if (menu && menu->isOpen()) + { + LLMenuGL::sMenuContainer->hideMenus(); + } + if ( gFocusMgr.getKeyboardFocus() == this ) { LLLineEditorRollback rollback( this ); @@ -1396,6 +1756,13 @@ BOOL LLLineEditor::handleUnicodeCharHere(llwchar uni_char) if ( (gFocusMgr.getKeyboardFocus() == this) && getVisible() && !mReadOnly) { + // SL-51858: Key presses are not being passed to the Popup menu. + // A proper fix is non-trivial so instead just close the menu. + LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); + if (menu && menu->isOpen()) + { + LLMenuGL::sMenuContainer->hideMenus(); + } handled = TRUE; LLLineEditorRollback rollback( this ); @@ -1471,10 +1838,97 @@ void LLLineEditor::doDelete() } } } +void LLLineEditor::autoCorrectText() +{ + static BOOL *doAnything = rebind_llcontrol("EmeraldEnableAutoCorrect", &gSavedSettings, true); + if( (!mReadOnly) && (*doAnything) && (isSpellDirty())) + { + S32 wordStart = 0; + S32 wordEnd = mCursorPos-1; + //llinfos <<"Checking Word, Cursor is at "< 0) && (' '!=text[wordEnd-1])) + { + wordEnd--; + } + wordStart=wordEnd; + while ((wordEnd < (S32)text.length()) && (' '!=text[wordEnd] ) ) + { + wordEnd++; + } + std::string lastTypedWord(std::string(text.begin(), + text.end()).substr(wordStart,wordEnd-wordStart)); + //llinfos << " The last typed word has been chosen, it is "<replaceWord(lastTypedWord)); + if(correctedWord!=lastTypedWord) + { + int dif = correctedWord.length()-lastTypedWord.length(); + std::string regText(mText); + //int wordStart = regText.find(lastTypedWord); + regText.replace(wordStart,lastTypedWord.length(),correctedWord); + mText=regText; + mCursorPos+=dif; + } + } + } +} +void LLLineEditor::drawMisspelled(LLRect background) +{ + if((glggHunSpell->highlightInRed || mOverRideAndShowMisspellings) + &&(!mReadOnly)) + { + S32 newStartSpellHere =mScrollHPos; + S32 cursorloc =calculateCursorFromMouse(mMaxHPixels); + S32 newStopSpellHere = ( ((S32)mText.length())>cursorloc)?cursorloc:(S32)mText.length(); + + F32 elapsed = mSpellTimer.getElapsedTimeF32(); + if(S32(elapsed / 1) & 1) + { + if(isSpellDirty()||(newStartSpellHere!=mStartSpellHere)||(newStopSpellHere!=mEndSpellHere)) + { + mStartSpellHere=newStartSpellHere; + mEndSpellHere= newStopSpellHere; + resetSpellDirty(); + misspellLocations=getMisspelledWordsPositions(); + } + } + for(int i =0;i<(int)misspellLocations.size();i++) + { + S32 wstart =findPixelNearestPos( misspellLocations[i]-getCursor()); + S32 wend = findPixelNearestPos(misspellLocations[++i]-getCursor()); + S32 maxw = getRect().getWidth(); + + if(wend > maxw) + { + wend=maxw; + } + if(wstart > maxw) + { + wstart=maxw; + } + gGL.color4ub(255,0,0,200); + //3 line zig zags.. + while(wstartsetVisible(FALSE); // no more programmatic art. #endif + drawMisspelled(background); + resetSpellDirty(); + // If we're editing... if( gFocusMgr.getKeyboardFocus() == this) { @@ -2164,36 +2621,28 @@ BOOL LLLineEditor::prevalidateASCII(const LLWString &str) BOOL LLLineEditor::evaluateFloat() { - bool success = false; + bool success; + F32 result = 0.f; std::string expr = getText(); + LLStringUtil::toUpper(expr); - // user deleted the contents, nothing to evaluate -- MC - if (expr.empty()) + success = LLCalc::getInstance()->evalString(expr, result); + + if (!success) { - return success; + // Move the cursor to near the error on failure + setCursor(LLCalc::getInstance()->getLastErrorPos()); + // *TODO: Translated error message indicating the type of error? Select error text? } else { - F32 result = 0.f; - success = LLCalc::getInstance()->evalString(expr, result); - - if (!success) - { - // Move the cursor to near the error on failure - setCursor(LLCalc::getInstance()->getLastErrorPos()); - // *TODO: Translated error message indicating the type of error? Select error text? - } - else - { - // Replace the expression with the result - std::ostringstream result_str; - result_str << result; - setText(result_str.str()); - selectAll(); - } - - return success; + // Replace the expression with the result + std::string result_str = llformat("%f",result); + setText(result_str); + selectAll(); } + + return success; } void LLLineEditor::onMouseCaptureLost() diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index fc1b75f..6de57ec 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -78,6 +78,7 @@ public: LLViewBorder::EStyle border_style = LLViewBorder::STYLE_LINE, S32 border_thickness = 1); + virtual ~LLLineEditor(); virtual LLXMLNodePtr getXML(bool save_children = true) const; @@ -91,15 +92,30 @@ public: /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleDoubleClick(S32 x,S32 y,MASK mask); /*virtual*/ BOOL handleMiddleMouseDown(S32 x,S32 y,MASK mask); + /*virtual*/ BOOL handleRightMouseDown( S32 x, S32 y, MASK mask ); /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask ); /*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 virtual void cut(); virtual BOOL canCut() const; + virtual void copy(); virtual BOOL canCopy() const; + virtual void paste(); virtual BOOL canPaste() const; @@ -117,8 +133,20 @@ public: virtual void deselect(); virtual BOOL canDeselect() const; + static void context_cut(void* data); + static void context_copy(void* data); + static void spell_correct(void* data); + static void spell_show(void* data); + static void translateText(void * data); + static void spell_add(void* data); + static void context_paste(void* data); + static void context_delete(void* data); + static void context_selectall(void* data); + std::vector getMisspelledWordsPositions(); // view overrides virtual void draw(); + void autoCorrectText(); + void drawMisspelled(LLRect background); virtual void reshape(S32 width,S32 height,BOOL called_from_parent=TRUE); virtual void onFocusReceived(); virtual void onFocusLost(); @@ -133,6 +161,8 @@ public: virtual void onCommit(); virtual BOOL isDirty() const { return mText.getString() != mPrevText; } // Returns TRUE if user changed value at all virtual void resetDirty() { mPrevText = mText.getString(); } // Clear dirty state + virtual BOOL isSpellDirty() const { return mText.getString() != mPrevSpelledText; } // Returns TRUE if user changed value at all + virtual void resetSpellDirty() { mPrevSpelledText = mText.getString(); } // Clear dirty state // assumes UTF8 text virtual void setValue(const LLSD& value ) { setText(value.asString()); } @@ -168,6 +198,7 @@ public: void setWriteableBgColor( const LLColor4& c ) { mWriteableBgColor = c; } void setReadOnlyBgColor( const LLColor4& c ) { mReadOnlyBgColor = c; } void setFocusBgColor(const LLColor4& c) { mFocusBgColor = c; } + void setOverRideAndShowMisspellings(BOOL b) { mOverRideAndShowMisspellings =b;} const LLColor4& getFgColor() const { return mFgColor; } const LLColor4& getReadOnlyFgColor() const { return mReadOnlyFgColor; } @@ -213,7 +244,7 @@ public: static BOOL prevalidateASCII(const LLWString &str); static BOOL postvalidateFloat(const std::string &str); - + BOOL evaluateFloat(); // line history support: @@ -225,11 +256,12 @@ public: private: // private helper methods - void pasteHelper(bool is_primary); + void pasteHelper(bool is_primary); void removeChar(); void addChar(const llwchar c); void setCursorAtLocalPos(S32 local_mouse_x); + S32 calculateCursorFromMouse(S32 local_mouse_x); S32 findPixelNearestPos(S32 cursor_offset = 0) const; void reportBadKeystroke(); BOOL handleSpecialKey(KEY key, MASK mask); @@ -253,9 +285,18 @@ private: virtual S32 getPreeditFontSize() const; protected: + LLHandle mPopupMenuHandle; LLUIString mText; // The string being edited. std::string mPrevText; // Saved string for 'ESC' revert LLUIString mLabel; // text label that is visible when no user text provided + std::string mPrevSpelledText; // saved string so we know whether to respell or not + std::vector misspellLocations; // where all the mispelled words are + S32 mStartSpellHere; // the position of the first char on the screen, stored so we know when to update + S32 mEndSpellHere; // the location of the last char on the screen + BOOL mOverRideAndShowMisspellings; + LLFrameTimer mSpellTimer; + //to keep track of what we have to remove before showing menu + std::vector suggestionMenuItems; // line history support: BOOL mHaveHistory; // flag for enabled line history @@ -364,6 +405,8 @@ private: BOOL mIsSelecting; S32 mSelectionStart; S32 mSelectionEnd; + + }; // end class LLLineEditorRollback }; // end class LLLineEditor diff --git a/linden/indra/llui/llmenugl.cpp b/linden/indra/llui/llmenugl.cpp index b70f98b..e00700a 100644 --- a/linden/indra/llui/llmenugl.cpp +++ b/linden/indra/llui/llmenugl.cpp @@ -2582,6 +2582,31 @@ BOOL LLMenuGL::appendMenu( LLMenuGL* menu ) return success; } +// Remove a menu item from this menu. +BOOL LLMenuGL::remove( LLMenuItemGL* item ) +{ + if (mSpilloverMenu) + { + cleanupSpilloverBranch(); + } + + item_list_t::iterator found_iter = std::find(mItems.begin(), mItems.end(), item); + if (found_iter != mItems.end()) + { + mItems.erase(found_iter); + } + + removeChild( item ); + + // We keep it around in case someone is pointing at it. + // The caller can delete it if it's safe. + // Note that getMenu() will still not work since its parent isn't a menu. + sMenuContainer->addChild( item ); + + arrange(); + return TRUE; +} + void LLMenuGL::setEnabledSubMenus(BOOL enable) { setEnabled(enable); diff --git a/linden/indra/llui/llmenugl.h b/linden/indra/llui/llmenugl.h index 26fc294..63f9d55 100644 --- a/linden/indra/llui/llmenugl.h +++ b/linden/indra/llui/llmenugl.h @@ -442,6 +442,9 @@ public: // Add the menu item to this menu. virtual BOOL append( LLMenuItemGL* item ); + // Remove a menu item from this menu. + virtual BOOL remove( LLMenuItemGL* item ); + // *NOTE:Mani - appendNoArrange() should be removed when merging to skinning/viewer2.0 // Its added as a fix to a viewer 1.23 bug that has already been address by skinning work. virtual BOOL appendNoArrange( LLMenuItemGL* item ); diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 2d46943..be6d3ef 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -36,7 +36,6 @@ #include "lltexteditor.h" -#include "llerror.h" #include "llfontgl.h" #include "llrender.h" #include "llui.h" @@ -46,7 +45,6 @@ #include "lltimer.h" #include "llmath.h" -#include "audioengine.h" #include "llclipboard.h" #include "llscrollbar.h" #include "llstl.h" @@ -60,7 +58,13 @@ #include "llwindow.h" #include "lltextparser.h" #include -#include + +#include "llmenugl.h" +#include +#include "../newview/lgghunspell_wrapper.h" +#include "../newview/lltranslate.h" +#include "../newview/llviewercontrol.h" +#include "../newview/lggautocorrect.h" // // Globals @@ -96,7 +100,34 @@ LLColor4 LLTextEditor::mLinkColor = LLColor4::blue; void (* LLTextEditor::mURLcallback)(const std::string&) = NULL; bool (* LLTextEditor::mSecondlifeURLcallback)(const std::string&) = NULL; bool (* LLTextEditor::mSecondlifeURLcallbackRightClick)(const std::string&) = NULL; +/////////////////////////////////////////////////////////////////// + +class TextChatTranslationReceiver : public LLTranslate::TranslationReceiver +{ +public : + TextChatTranslationReceiver(const std::string &toLang, LLTextEditor* line): LLTranslate::TranslationReceiver("", toLang), + m_line(line) + { + } + + static boost::intrusive_ptr build(const std::string &toLang,LLTextEditor* line) + { + return boost::intrusive_ptr(new TextChatTranslationReceiver(toLang,line)); + } +protected: + void handleResponse(const std::string &translation, const std::string &detectedLanguage) + { + BOOL rep = gSavedSettings.getBOOL("EmeraldTranslateReplace"); + m_line->insertText((rep?"":" (") + translation +(rep?"":")"),rep); + } + void handleFailure() + { + LLTranslate::TranslationReceiver::handleFailure(); + } +private: + LLTextEditor* m_line; +}; /////////////////////////////////////////////////////////////////// @@ -257,6 +288,7 @@ LLTextEditor::LLTextEditor( LLUICtrl( name, rect, TRUE, NULL, NULL, FOLLOWS_TOP | FOLLOWS_LEFT ), mTextIsUpToDate(TRUE), mMaxTextByteLength( max_length ), + mPopupMenuHandle(), mBaseDocIsPristine(TRUE), mPristineCmd( NULL ), mLastCmd( NULL ), @@ -290,7 +322,8 @@ LLTextEditor::LLTextEditor( mLastSelectionX(-1), mLastSelectionY(-1), mReflowNeeded(FALSE), - mScrollNeeded(FALSE) + mScrollNeeded(FALSE), + mOverRideAndShowMisspellings(FALSE) { mSourceID.generate(); @@ -342,6 +375,60 @@ LLTextEditor::LLTextEditor( mParseHTML=FALSE; mHTML.clear(); + // make the popup menu available + //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); + LLMenuGL* menu = new LLMenuGL("wot"); + /*if (!menu) + { + menu = new LLMenuGL(LLStringUtil::null); + }*/ + menu->append(new LLMenuItemCallGL("Cut", context_cut, NULL, this)); + menu->append(new LLMenuItemCallGL("Copy", context_copy, NULL, this)); + menu->append(new LLMenuItemCallGL("Paste", context_paste, NULL, this)); + menu->append(new LLMenuItemCallGL("Delete", context_delete, NULL, this)); + menu->append(new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + menu->appendSeparator("transep"); + LLMenuGL* translatemenu = new LLMenuGL("Translate To"); + translatemenu->setCanTearOff(FALSE); + SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; + translatemenu->append(new LLMenuItemCallGL("English",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="da"; + translatemenu->append(new LLMenuItemCallGL("Danish",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="de"; + translatemenu->append(new LLMenuItemCallGL("Deutsch(German)",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="es"; + translatemenu->append(new LLMenuItemCallGL("Spanish",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="fr"; + translatemenu->append(new LLMenuItemCallGL("French",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="it"; + translatemenu->append(new LLMenuItemCallGL("Italian",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="hu"; + translatemenu->append(new LLMenuItemCallGL("Hungarian",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="nl"; + translatemenu->append(new LLMenuItemCallGL("Dutch",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="pl"; + translatemenu->append(new LLMenuItemCallGL("Polish",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="pt"; + translatemenu->append(new LLMenuItemCallGL("Portugese",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="ru"; + translatemenu->append(new LLMenuItemCallGL("Russian",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="tr"; + translatemenu->append(new LLMenuItemCallGL("Turkish",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="uk"; + translatemenu->append(new LLMenuItemCallGL("Ukrainian",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="zh"; + translatemenu->append(new LLMenuItemCallGL("Chinese",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="ja"; + translatemenu->append(new LLMenuItemCallGL("Japanese",translateText, NULL, t)); + t=new SpellMenuBind;t->origin=this;t->word="ko"; + translatemenu->append(new LLMenuItemCallGL("Korean",translateText, NULL, t)); + + menu->appendMenu(translatemenu); + menu->appendSeparator("Spelsep"); + //menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); + menu->setCanTearOff(FALSE); + menu->setVisible(FALSE); + mPopupMenuHandle = menu->getHandle(); } @@ -360,6 +447,119 @@ LLTextEditor::~LLTextEditor() std::for_each(mSegments.begin(), mSegments.end(), DeletePointer()); std::for_each(mUndoStack.begin(), mUndoStack.end(), DeletePointer()); + LLView::deleteViewByHandle(mPopupMenuHandle); +} +void LLTextEditor::context_cut(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + if(line)line->cut(); +} +void LLTextEditor::context_copy(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + if(line)line->copy(); +} +void LLTextEditor::translateText(void * data) +{ + SpellMenuBind* t = (SpellMenuBind*)data; + LLTextEditor* line = t->origin; + const std::string &toLang = t->word;//LLTranslate::getTranslateLanguage(); + LLHTTPClient::ResponderPtr result = TextChatTranslationReceiver::build(toLang,line); + + S32 left_pos = llmin( line->mSelectionStart, line->mSelectionEnd ); + S32 length = abs( line->mSelectionStart - line->mSelectionEnd ); + LLTranslate::translateMessage(result,"", toLang, line->getText().substr(left_pos, length)); +} +void LLTextEditor::spell_correct(void* data) +{ + SpellMenuBind* tempBind = (SpellMenuBind*)data; + LLTextEditor* line = tempBind->origin; + if(tempBind && line) + { + llinfos << tempBind->menuItem->getName() << " : " << tempBind->origin->getName() << " : " << tempBind->word << llendl; + if(line)line->spellReplace(tempBind); + + } +} +void LLTextEditor::spell_show(void * data) +{ + SpellMenuBind* tempBind = (SpellMenuBind*)data; + LLTextEditor* line = tempBind->origin; + + if(tempBind && line) + { + if(tempBind->word=="Show Misspellings") + { + line->setOverRideAndShowMisspellings(TRUE); + }else + { + line->setOverRideAndShowMisspellings(FALSE); + } + } +} + +std::vector LLTextEditor::getMisspelledWordsPositions() +{ + resetSpellDirty(); + std::vector thePosesOfBadWords; + LLWString& text = mWText; + S32 wordStart=0; + S32 wordEnd=spellStart;//start at the scroll start + while(wordEnd < spellEnd) + { + //go through all the chars... XD + if( LLTextEditor::isPartOfWord( text[wordEnd] ) ) + { + // Select word the cursor is over + while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) + { + wordEnd--; + } + wordStart=wordEnd; + while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) + { + wordEnd++; + } + //got a word :D + + std::string regText(text.begin(),text.end()); + std::string selectedWord(regText.substr(wordStart,wordEnd-wordStart)); + + if(!glggHunSpell->isSpelledRight(selectedWord)) + { + //misspelled word here, and you have just right clicked on it + + thePosesOfBadWords.push_back(wordStart); + thePosesOfBadWords.push_back(wordEnd); + } + } + wordEnd++; + } + return thePosesOfBadWords; +} +void LLTextEditor::spell_add(void* data) +{ + SpellMenuBind* tempBind = (SpellMenuBind*)data; + if(tempBind) + { + glggHunSpell->addWordToCustomDictionary(tempBind->word); + tempBind->origin->mPrevSpelledText.erase();//make it update + } +} +void LLTextEditor::context_paste(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + if(line)line->paste(); +} +void LLTextEditor::context_delete(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + if(line)line->doDelete(); +} +void LLTextEditor::context_selectall(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + if(line)line->selectAll(); } void LLTextEditor::setTrackColor( const LLColor4& color ) @@ -751,14 +951,7 @@ S32 LLTextEditor::getLineStart( S32 line ) const S32 segoffset = mLineStartList[line].mOffset; LLTextSegment* seg = mSegments[segidx]; S32 res = seg->getStart() + segoffset; - if (res > seg->getEnd()) - { - //llerrs << "wtf" << llendl; - // This happens when creating a new notecard using the AO on certain opensims. - // Play it safe instead of bringing down the viewer - MC - llwarns << "BAD JOOJOO! Text length (" << res << ") greater than text end (" << seg->getEnd() << "). Setting line start to " << seg->getEnd() << llendl; - res = seg->getEnd(); - } + if (res > seg->getEnd()) llerrs << "wtf" << llendl; return res; } @@ -886,11 +1079,6 @@ S32 LLTextEditor::getCursorPosFromLocalCoord( S32 local_x, S32 local_y, BOOL rou void LLTextEditor::setCursor(S32 row, S32 column) { - // Make sure we're not trying to set the cursor anywhere - // it can't go by always setting the min to 0 -- MC - row = (row < 0) ? 0 : row; - column = (column < 0) ? 0 : column; - const llwchar* doc = mWText.c_str(); const char CR = 10; while(row--) @@ -1142,6 +1330,14 @@ BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) { BOOL handled = FALSE; + // SL-51858: Key presses are not being passed to the Popup menu. + // A proper fix is non-trivial so instead just close the menu. + LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); + if (menu && menu->isOpen()) + { + LLMenuGL::sMenuContainer->hideMenus(); + } + // Let scrollbar have first dibs handled = LLView::childrenHandleMouseDown(x, y, mask) != NULL; @@ -1216,6 +1412,107 @@ BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) return handled; } +BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) +{ + + setFocus(TRUE); + + //setCursorAtLocalPos( x, y, TRUE ); + S32 wordStart = 0; + S32 wordEnd = getCursorPosFromLocalCoord(x,y,TRUE); + + LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); + if (menu) + { + for(int i = 0;i<(int)suggestionMenuItems.size();i++) + { + SpellMenuBind * tempBind = suggestionMenuItems[i]; + if(tempBind) + { + menu->remove(tempBind->menuItem); + tempBind->menuItem->die(); + //delete tempBind->menuItem; + //tempBind->menuItem = NULL; + delete tempBind; + } + } + suggestionMenuItems.clear(); + + menu->setItemVisible("Translate To",!mReadOnly); + menu->setItemVisible("Transep",!mReadOnly); + + const LLWString &text = mWText; + + if(( isPartOfWord( text[wordEnd] ) )&&(!mReadOnly)) + { + // Select word the cursor is over + while ((wordEnd > 0) && isPartOfWord(text[wordEnd-1])) + { + wordEnd--; + } + wordStart=wordEnd; + //startSelection(); + + while ((wordEnd < (S32)text.length()) && isPartOfWord( text[wordEnd] ) ) + { + wordEnd++; + } + std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); + if(!glggHunSpell->isSpelledRight(selectedWord)) + { + //misspelled word here, and you have just right clicked on it! + std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); + + //menu->setItemVisible("Transep",(suggs.size()>0)); + for(int i = 0;i<(int)suggs.size();i++) + { + SpellMenuBind * tempStruct = new SpellMenuBind; + tempStruct->origin = this; + tempStruct->word = suggs[i]; + tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionStart=wordStart; + tempStruct->wordY=y; + LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( + tempStruct->word, spell_correct, NULL, tempStruct); + tempStruct->menuItem = suggMenuItem; + suggestionMenuItems.push_back(tempStruct); + menu->append(suggMenuItem); + } + SpellMenuBind * tempStruct = new SpellMenuBind; + tempStruct->origin = this; + tempStruct->word = selectedWord; + tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionStart=wordStart; + tempStruct->wordY=y; + LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( + "Add Word", spell_add, NULL, tempStruct); + tempStruct->menuItem = suggMenuItem; + suggestionMenuItems.push_back(tempStruct); + menu->append(suggMenuItem); + } + + } + if((!mReadOnly)&&((!glggHunSpell->highlightInRed) + ||(mOverRideAndShowMisspellings)||(mShowLineNumbers))) + { + SpellMenuBind * tempStruct = new SpellMenuBind; + tempStruct->origin = this; + if(mOverRideAndShowMisspellings) + 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->append(suggMenuItem); + } + menu->buildDrawLabels(); + menu->updateParent(LLMenuGL::sMenuContainer); + LLMenuGL::showPopup(this, menu, x, y); + } + return TRUE; +} BOOL LLTextEditor::handleMiddleMouseDown(S32 x, S32 y, MASK mask) @@ -1350,11 +1647,6 @@ BOOL LLTextEditor::handleMouseUp(S32 x, S32 y, MASK mask) setCursorAtLocalPos( x, y, TRUE ); endSelection(); - - updateScrollFromCursor(); - - // take selection to primary clipboard - updatePrimary(); } if( !hasSelection() ) @@ -1432,7 +1724,6 @@ BOOL LLTextEditor::handleDoubleClick(S32 x, S32 y, MASK mask) handled = TRUE; } - return handled; } @@ -1913,6 +2204,16 @@ BOOL LLTextEditor::canPaste() const return !mReadOnly && gClipboard.canPasteString(); } +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() { @@ -1932,25 +2233,35 @@ void LLTextEditor::pasteHelper(bool is_primary) { bool can_paste_it; if (is_primary) + { can_paste_it = canPastePrimary(); + } else + { can_paste_it = canPaste(); + } if (!can_paste_it) { return; } + LLUUID source_id; LLWString paste; if (is_primary) + { paste = gClipboard.getPastePrimaryWString(&source_id); + } else + { paste = gClipboard.getPasteWString(&source_id); + } if (paste.empty()) { return; } + // Delete any selected characters (the paste replaces them) if( (!is_primary) && hasSelection() ) { @@ -1995,7 +2306,7 @@ void LLTextEditor::copyPrimary() return; } S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); - S32 length = abs( mSelectionStart - mSelectionEnd ); + S32 length = llabs( mSelectionStart - mSelectionEnd ); gClipboard.copyFromPrimarySubstring(mWText, left_pos, length, mSourceID); } @@ -2262,6 +2573,13 @@ BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask ) BOOL selection_modified = FALSE; BOOL return_key_hit = FALSE; BOOL text_may_have_changed = TRUE; + // SL-51858: Key presses are not being passed to the Popup menu. + // A proper fix is non-trivial so instead just close the menu. + LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); + if (menu && menu->isOpen()) + { + LLMenuGL::sMenuContainer->hideMenus(); + } if ( gFocusMgr.getKeyboardFocus() == this ) { @@ -2306,6 +2624,14 @@ BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask ) } } + // SL-51858: Key presses are not being passed to the Popup menu. + // A proper fix is non-trivial so instead just close the menu. + LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); + if (menu && menu->isOpen()) + { + LLMenuGL::sMenuContainer->hideMenus(); + } + // Handle most keys only if the text editor is writeable. if( !mReadOnly ) { @@ -2739,6 +3065,140 @@ void LLTextEditor::drawSelectionBackground() } } } +void LLTextEditor::autoCorrectText() +{ + + static BOOL *doAnything = rebind_llcontrol("EmeraldEnableAutoCorrect", &gSavedSettings, true); + if( (!mReadOnly) && (*doAnything) && (isSpellDirty()) ) + { + S32 wordStart = 0; + S32 wordEnd = mCursorPos-1; + if(wordEnd<1)return; + LLWString& text = mWText; + if(text.size()<1)return; + if( LLTextEditor::isPartOfWord( text[wordEnd] )) return;//we only check on word breaks + wordEnd--; + if( LLTextEditor::isPartOfWord( text[wordEnd] ) ) + { + while ((wordEnd > 0) && (text[wordEnd-1]!=' ')) + { + wordEnd--; + } + wordStart=wordEnd; + while ((wordEnd < (S32)text.length()) && (' '!= text[wordEnd] ) ) + { + wordEnd++; + } + std::string lastTypedWord(std::string(text.begin(), + text.end()).substr(wordStart,wordEnd-wordStart)); + + std::string regText(text.begin(),text.end()); + + std::string correctedWord(LGGAutoCorrect::getInstance()->replaceWord(lastTypedWord)); + if(correctedWord!=lastTypedWord) + { + int dif = correctedWord.length()-lastTypedWord.length(); + regText.replace(wordStart,lastTypedWord.length(),correctedWord); + mWText=utf8str_to_wstring(regText); + mCursorPos+=dif; + needsReflow(); + } + } + } +} +void LLTextEditor::drawMisspelled() +{ + if(mReadOnly)return; + if(glggHunSpell->highlightInRed || mOverRideAndShowMisspellings) + { + if( + ( ((getLength()<400)||(false)) &&( (S32(mSpellTimer.getElapsedTimeF32() / 1) & 1) )) + || + (S32(mKeystrokeTimer.getElapsedTimeF32() / 1) & 1) + ) + { + S32 newSpellStart = getLineStart(mScrollbar->getDocPos());//start at the scroll start + S32 newSpellEnd = getLineStart(mScrollbar->getDocPos() + 1 + mScrollbar->getDocSize()-mScrollbar->getDocPosMax());//end at the end o.o + + if(mScrollbar->getDocPos() == mScrollbar->getDocPosMax()) + { + newSpellEnd=(S32)mWText.length(); + } + if((isSpellDirty())||(newSpellEnd!=spellEnd || newSpellStart!=spellStart)) + { + spellEnd = newSpellEnd; + spellStart = newSpellStart; + misspellLocations=getMisspelledWordsPositions(); + } + } + //draw + for(int i =0;i<(int)misspellLocations.size();i++) + { + S32 wstart = misspellLocations[i]; + S32 wend = misspellLocations[++i]; + //start curor code mod + const LLWString &text = mWText; + const S32 text_len = getLength(); + // Skip through the lines we aren't drawing. + S32 search_pos = mScrollbar->getDocPos(); + S32 num_lines = getLineCount(); + if (search_pos >= num_lines)return; + S32 line_start = getLineStart(search_pos); + F32 line_height = mGLFont->getLineHeight(); + F32 text_y = (F32)(mTextRect.mTop) - line_height; + + F32 word_left = 0.f; + F32 word_right = 0.f; + F32 word_bottom = 0.f; + BOOL word_visible = FALSE; + + S32 line_end = 0; + // Determine if the cursor is visible and if so what its coordinates are. + while( (mTextRect.mBottom <= llround(text_y)) && (search_pos < num_lines)) + { + line_end = text_len + 1; + S32 next_line = -1; + + if ((search_pos + 1) < num_lines) + { + next_line = getLineStart(search_pos + 1); + line_end = next_line - 1; + } + const llwchar* line = text.c_str() + line_start; + // Find the cursor and selection bounds + if( line_start <= wstart && wend <= line_end ) + { + word_visible = TRUE; + word_left = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wstart - line_start, mAllowEmbeddedItems )-1.f; + word_right = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wend - line_start, mAllowEmbeddedItems )+1.f; + word_bottom = text_y; + break; + } + // move down one line + text_y -= line_height; + line_start = next_line; + search_pos++; + } + if(mShowLineNumbers) + { + word_left += UI_TEXTEDITOR_LINE_NUMBER_MARGIN; + word_right += UI_TEXTEDITOR_LINE_NUMBER_MARGIN; + } + // Draw the cursor + if( word_visible ) + { + //end cursos code mod + gGL.color4ub(255,0,0,200); + while(word_leftsetVisible(true); html->setColor(mLinkColor); @@ -3675,9 +4143,9 @@ void LLTextEditor::appendStyledText(const std::string &new_text, appendHighlightedText(subtext,allow_undo, prepend_newline, part, stylep); } - html->setLinkHREF(text.substr(start,end-start)); + html->setLinkHREF(url); appendText(text.substr(start, end-start),allow_undo, prepend_newline, html); - if (end < (S32)text.length()) + if (end < (S32)text.length()) { text = text.substr(end,text.length() - end); end=0; @@ -3688,6 +4156,7 @@ void LLTextEditor::appendStyledText(const std::string &new_text, break; } } + if (part != (S32)LLTextParser::WHOLE) part=(S32)LLTextParser::END; if (end < (S32)text.length()) appendHighlightedText(text,allow_undo, prepend_newline, part, stylep); } @@ -3784,6 +4253,10 @@ void LLTextEditor::appendText(const std::string &new_text, bool allow_undo, bool { mSelectionStart = selection_start; mSelectionEnd = selection_end; + + + + mIsSelecting = was_selecting; setCursorPos(cursor_pos); } @@ -3952,6 +4425,15 @@ void LLTextEditor::loadKeywords(const std::string& filename, } } +void LLTextEditor::addToken(LLKeywordToken::TOKEN_TYPE type, + const std::string& key, + const LLColor3& color, + const std::string& tool_tip, + const std::string& delimiter) +{ + mKeywords.addToken(type,key,color,tool_tip); +} + void LLTextEditor::updateSegments() { if (mKeywords.isLoaded()) @@ -4417,11 +4899,9 @@ S32 LLTextEditor::findHTMLToken(const std::string &line, S32 pos, BOOL reverse) std::string openers=" \t\n('\"[{<>"; std::string closers=" \t\n)'\"]}><;"; - S32 index = 0; - if (reverse) { - for (index=pos; index >= 0; index--) + for (int index=pos; index >= 0; index--) { char c = line[index]; S32 m2 = openers.find(c); @@ -4430,13 +4910,13 @@ S32 LLTextEditor::findHTMLToken(const std::string &line, S32 pos, BOOL reverse) return index+1; } } - index = 0; // Can't be before first charater + return 0; // index is -1, don't want to return that. } else { // adjust the search slightly, to allow matching parenthesis inside the URL S32 paren_count = 0; - for (index=pos; index<(S32)line.length(); index++) + for (int index=pos; index<(S32)line.length(); index++) { char c = line[index]; @@ -4464,12 +4944,11 @@ S32 LLTextEditor::findHTMLToken(const std::string &line, S32 pos, BOOL reverse) } } } + return line.length(); } - - return index; } -BOOL LLTextEditor::findHTML(const std::string &line, S32 *begin, S32 *end) const +BOOL LLTextEditor::findHTML(const std::string &line, S32 *begin, S32 *end, std::string& url) const { S32 m1,m2,m3; @@ -4481,34 +4960,21 @@ BOOL LLTextEditor::findHTML(const std::string &line, S32 *begin, S32 *end) const { *begin = findHTMLToken(line, m1, TRUE); *end = findHTMLToken(line, m1, FALSE); - - // Can't start before the first char - if(*begin < 0) - { - //*begin = 0; - } //Load_url only handles http and https so don't hilite ftp, smb, etc. - try + m2 = line.substr(*begin,(m1 - *begin)).find("http"); + m3 = line.substr(*begin,(m1 - *begin)).find("secondlife"); + + std::string badneighbors=".,<>?';\"][}{=-+_)(*&^%$#@!~`\t\r\n\\"; + + if (m2 >= 0 || m3>=0) { - m2 = line.substr(*begin,(m1 - *begin)).find("http"); - m3 = line.substr(*begin,(m1 - *begin)).find("secondlife"); - - std::string badneighbors=".,<>?';\"][}{=-+_)(*&^%$#@!~`\t\r\n\\"; - - if (m2 >= 0 || m3>=0) - { - S32 bn = badneighbors.find(line.substr(m1+3,1)); - - if (bn < 0) - { - matched = TRUE; - } + S32 bn = badneighbors.find(line.substr(m1+3,1)); + + if (bn < 0) + { + matched = TRUE; } - } - catch ( std::out_of_range outOfRange ) - { - LL_WARNS("TextEditor") << "got std::out_of_range exception \"" << line << "\"" << LL_ENDL; } } /* matches things like secondlife.com (no http://) needs a whitelist to really be effective. @@ -4541,11 +5007,46 @@ BOOL LLTextEditor::findHTML(const std::string &line, S32 *begin, S32 *end) const { S32 strpos, strpos2; - try + url = line.substr(*begin,*end - *begin); + std::string slurlID = "slurl.com/secondlife/"; + strpos = url.find(slurlID); + + if (strpos < 0) { - std::string url = line.substr(*begin,*end - *begin); - std::string slurlID = "slurl.com/secondlife/"; - strpos = url.find(slurlID); + slurlID="maps.secondlife.com/secondlife/"; + strpos = url.find(slurlID); + } + + if (strpos < 0) + { + slurlID="secondlife://"; + strpos = url.find(slurlID); + } + + if (strpos < 0) + { + slurlID="sl://"; + strpos = url.find(slurlID); + } + + if (strpos >= 0) + { + strpos+=slurlID.length(); + + while ( ( strpos2=url.find("/",strpos) ) == -1 ) + { + if ((*end+2) >= (S32)line.length() || line.substr(*end,1) != " " ) + { + matched=FALSE; + break; + } + + strpos = (*end + 1) - *begin; + + *end = findHTMLToken(line,(*begin + strpos),FALSE); + url = line.substr(*begin,*end - *begin); + } + } if (strpos < 0) { diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index f26bf3b..6b372d7 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -45,6 +45,7 @@ #include "lldarray.h" #include "llpreeditor.h" +#include "llmenugl.h" class LLFontGL; class LLScrollbar; @@ -84,6 +85,7 @@ public: virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks); virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask ); + virtual BOOL handleRightMouseDown( S32 x, S32 y, MASK mask ); virtual BOOL handleMiddleMouseDown(S32 x,S32 y,MASK mask); virtual BOOL handleKeyHere(KEY key, MASK mask ); @@ -108,29 +110,55 @@ public: virtual void setFocus( BOOL b ); virtual BOOL acceptsTextInput() const; 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(); virtual BOOL canUndo() const; virtual void redo(); virtual BOOL canRedo() const; - virtual void cut(); virtual BOOL canCut() const; virtual void copy(); virtual BOOL canCopy() const; virtual void paste(); virtual BOOL canPaste() const; + + virtual void spellReplace(SpellMenuBind* spellData); + virtual void updatePrimary(); virtual void copyPrimary(); virtual void pastePrimary(); virtual BOOL canPastePrimary() const; + virtual void doDelete(); virtual BOOL canDoDelete() const; virtual void selectAll(); virtual BOOL canSelectAll() const; virtual void deselect(); virtual BOOL canDeselect() const; + static void context_cut(void* data); + + static void context_copy(void* data); + static void context_paste(void* data); + static void context_delete(void* data); + static void context_selectall(void* data); + static void translateText(void * data); + static void spell_correct(void* data); + static void spell_add(void* data); + static void spell_show(void* data); + std::vector getMisspelledWordsPositions(); void selectNext(const std::string& search_text_in, BOOL case_insensitive, BOOL wrap = TRUE); BOOL replaceText(const std::string& search_text, const std::string& replace_text, BOOL case_insensitive, BOOL wrap = TRUE); @@ -145,17 +173,17 @@ public: BOOL allowsEmbeddedItems() const { return mAllowEmbeddedItems; } // inserts text at cursor - void insertText(const std::string &text); + void insertText(const std::string &text, BOOL deleteSelection = TRUE); // appends text at end void appendText(const std::string &wtext, bool allow_undo, bool prepend_newline, const LLStyleSP stylep = NULL); - void appendColoredText(const std::string &wtext, bool allow_undo, + void appendColoredText(const std::string &wtext, bool allow_undo, bool prepend_newline, const LLColor4 &color, const std::string& font_name = LLStringUtil::null); // if styled text starts a line, you need to prepend a newline. - void appendStyledText(const std::string &new_text, bool allow_undo, + void appendStyledText(const std::string &new_text, bool allow_undo, bool prepend_newline, LLStyleSP stylep = NULL); void appendHighlightedText(const std::string &new_text, bool allow_undo, @@ -182,6 +210,11 @@ public: const std::vector& funcs, const std::vector& tooltips, const LLColor3& func_color); + void addToken(LLKeywordToken::TOKEN_TYPE type, + const std::string& key, + const LLColor3& color, + const std::string& tool_tip = LLStringUtil::null, + const std::string& delimiter = LLStringUtil::null); LLKeywords::keyword_iterator_t keywordsBegin() { return mKeywords.begin(); } LLKeywords::keyword_iterator_t keywordsEnd() { return mKeywords.end(); } @@ -196,6 +229,7 @@ public: void setThumbColor( const LLColor4& color ); void setHighlightColor( const LLColor4& color ); void setShadowColor( const LLColor4& color ); + void setOverRideAndShowMisspellings(BOOL b){ mOverRideAndShowMisspellings =b;} // Hacky methods to make it into a word-wrapping, potentially scrolling, // read-only text box. @@ -262,7 +296,7 @@ public: const LLTextSegment* getPreviousSegment() const; void getSelectedSegments(std::vector& segments) const; - static bool isPartOfWord(llwchar c) { return (c == '_') || LLStringOps::isAlnum((char)c); } + static bool isPartOfWord(llwchar c) { return ( (c == '_') || (c == '\'') || LLStringOps::isAlnum((char)c)); } BOOL isReadOnly() { return mReadOnly; } protected: @@ -270,11 +304,14 @@ protected: // Methods // + LLHandle mPopupMenuHandle; + S32 getLength() const { return mWText.length(); } void getSegmentAndOffset( S32 startpos, S32* segidxp, S32* offsetp ) const; void drawPreeditMarker(); - +public: void updateLineStartList(S32 startpos = 0); +protected: void updateScrollFromCursor(); void updateTextRect(); const LLRect& getTextRect() const { return mTextRect; } @@ -301,8 +338,13 @@ protected: BOOL handleSelectionKey(const KEY key, const MASK mask); BOOL handleControlKey(const KEY key, const MASK mask); BOOL handleEditKey(const KEY key, const MASK mask); - + // +public: + // BOOL hasSelection() const { return (mSelectionStart !=mSelectionEnd); } + // + protected: + // BOOL selectionContainsLineBreaks(); void startSelection(); void endSelection(); @@ -330,7 +372,7 @@ protected: virtual void unbindEmbeddedChars(const LLFontGL* font) const {} S32 findHTMLToken(const std::string &line, S32 pos, BOOL reverse) const; - BOOL findHTML(const std::string &line, S32 *begin, S32 *end) const; + BOOL findHTML(const std::string &line, S32 *begin, S32 *end, std::string& url) const; // Abstract inner base class representing an undoable editor command. // Concrete sub-classes can be defined for operations such as insert, remove, etc. @@ -400,8 +442,9 @@ protected: // // I-beam is just after the mCursorPos-th character. +public: S32 mCursorPos; - +protected: // Use these to determine if a click on an embedded item is a drag or not. S32 mMouseDownX; S32 mMouseDownY; @@ -447,6 +490,8 @@ private: void drawBackground(); void drawSelectionBackground(); void drawCursor(); + void autoCorrectText(); + void drawMisspelled(); void drawText(); void drawClippedSegment(const LLWString &wtext, S32 seg_start, S32 seg_end, F32 x, F32 y, S32 selection_left, S32 selection_right, const LLStyleSP& color, F32* right_x); @@ -477,6 +522,12 @@ private: mutable std::string mUTF8Text; mutable BOOL mTextIsUpToDate; + LLWString mPrevSpelledText; // saved string so we know whether to respell or not + S32 spellStart; + S32 spellEnd; + std::vector misspellLocations; // where all the mispelled words are + BOOL mOverRideAndShowMisspellings; + S32 mMaxTextByteLength; // Maximum length mText is allowed to be in bytes const LLFontGL* mGLFont; @@ -513,11 +564,16 @@ private: } }; typedef std::vector line_list_t; + + //to keep track of what we have to remove before showing menu + std::vector suggestionMenuItems; + line_list_t mLineStartList; BOOL mReflowNeeded; BOOL mScrollNeeded; LLFrameTimer mKeystrokeTimer; + LLFrameTimer mSpellTimer; LLColor4 mCursorColor; -- cgit v1.1 From e0e982b0f96ea5a3e8e7bff00ea1004f9c349ccc Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Mon, 30 Aug 2010 19:55:44 -0700 Subject: Fixed bad merge in lltexteditor.cpp --- linden/indra/llui/lltexteditor.cpp | 77 +++++++++++--------------------------- 1 file changed, 21 insertions(+), 56 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index be6d3ef..51f7ad6 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -5007,69 +5007,35 @@ BOOL LLTextEditor::findHTML(const std::string &line, S32 *begin, S32 *end, std:: { S32 strpos, strpos2; - url = line.substr(*begin,*end - *begin); - std::string slurlID = "slurl.com/secondlife/"; - strpos = url.find(slurlID); - - if (strpos < 0) - { - slurlID="maps.secondlife.com/secondlife/"; - strpos = url.find(slurlID); - } - - if (strpos < 0) + // Is this try here still needed considering the changes to LLTextEditor::findHTMLToken? - MC + try { - slurlID="secondlife://"; + url = line.substr(*begin,*end - *begin); + std::string slurlID = "slurl.com/secondlife/"; strpos = url.find(slurlID); - } - - if (strpos < 0) - { - slurlID="sl://"; - strpos = url.find(slurlID); - } - - if (strpos >= 0) - { - strpos+=slurlID.length(); - while ( ( strpos2=url.find("/",strpos) ) == -1 ) - { - if ((*end+2) >= (S32)line.length() || line.substr(*end,1) != " " ) - { - matched=FALSE; - break; - } - - strpos = (*end + 1) - *begin; - - *end = findHTMLToken(line,(*begin + strpos),FALSE); - url = line.substr(*begin,*end - *begin); - } - } - if (strpos < 0) - { + { slurlID="maps.secondlife.com/secondlife/"; strpos = url.find(slurlID); } - - if (strpos < 0) - { + + if (strpos < 0) + { slurlID="secondlife://"; strpos = url.find(slurlID); - } - - if (strpos < 0) - { + } + + if (strpos < 0) + { slurlID="sl://"; strpos = url.find(slurlID); - } - - if (strpos >= 0) - { + } + + if (strpos >= 0) + { strpos+=slurlID.length(); - + while ( ( strpos2=url.find("/",strpos) ) == -1 ) { if ((*end+2) >= (S32)line.length() || line.substr(*end,1) != " " ) @@ -5077,19 +5043,18 @@ BOOL LLTextEditor::findHTML(const std::string &line, S32 *begin, S32 *end, std:: matched=FALSE; break; } - + strpos = (*end + 1) - *begin; - + *end = findHTMLToken(line,(*begin + strpos),FALSE); url = line.substr(*begin,*end - *begin); } - } - + } } catch ( std::out_of_range outOfRange ) { - LL_WARNS("TextEditor") << "got std::out_of_range exception \"" << line << "\"" << LL_ENDL; + llwarns << "got std::out_of_range exception \"" << line << "\"" << llendl; } } -- cgit v1.1 From 856b7ad6a941099939039e06180c392301596897 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Mon, 6 Sep 2010 19:49:48 -0700 Subject: Fixed regression of #295 in the 09.04 experimental --- linden/indra/llui/lllineeditor.cpp | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 5441d0a..7d91ece 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -2621,28 +2621,37 @@ BOOL LLLineEditor::prevalidateASCII(const LLWString &str) BOOL LLLineEditor::evaluateFloat() { - bool success; - F32 result = 0.f; + bool success = false; std::string expr = getText(); LLStringUtil::toUpper(expr); - success = LLCalc::getInstance()->evalString(expr, result); - - if (!success) + // user deleted the contents, nothing to evaluate -- MC + if (expr.empty()) { - // Move the cursor to near the error on failure - setCursor(LLCalc::getInstance()->getLastErrorPos()); - // *TODO: Translated error message indicating the type of error? Select error text? + return success; } else { - // Replace the expression with the result - std::string result_str = llformat("%f",result); - setText(result_str); - selectAll(); - } + F32 result = 0.f; + success = LLCalc::getInstance()->evalString(expr, result); - return success; + if (!success) + { + // Move the cursor to near the error on failure + setCursor(LLCalc::getInstance()->getLastErrorPos()); + // *TODO: Translated error message indicating the type of error? Select error text? + } + else + { + // Replace the expression with the result + std::ostringstream result_str; + result_str << result; + setText(result_str.str()); + selectAll(); + } + + return success; + } } void LLLineEditor::onMouseCaptureLost() -- cgit v1.1 From 7106e399b3343702b053547651264ff70ad3fa8f Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Mon, 6 Sep 2010 20:09:32 -0700 Subject: Fixed regression of #245 --- linden/indra/llui/lltexteditor.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 51f7ad6..8123af2 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -1079,6 +1079,11 @@ S32 LLTextEditor::getCursorPosFromLocalCoord( S32 local_x, S32 local_y, BOOL rou void LLTextEditor::setCursor(S32 row, S32 column) { + // Make sure we're not trying to set the cursor anywhere + // it can't go by always setting the min to 0 -- MC + row = (row < 0) ? 0 : row; + column = (column < 0) ? 0 : column; + const llwchar* doc = mWText.c_str(); const char CR = 10; while(row--) -- cgit v1.1 From 1ec02bdd6a6c0f81bdd9bf11dce50baea6a2233f Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Sat, 3 Apr 2010 13:49:04 -0700 Subject: Potential fix for a rare crash when creating notecards in the AO --- linden/indra/llui/lltexteditor.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 8123af2..6e5cdc4 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -951,7 +951,14 @@ S32 LLTextEditor::getLineStart( S32 line ) const S32 segoffset = mLineStartList[line].mOffset; LLTextSegment* seg = mSegments[segidx]; S32 res = seg->getStart() + segoffset; - if (res > seg->getEnd()) llerrs << "wtf" << llendl; + if (res > seg->getEnd()) + { + //llerrs << "wtf" << llendl; + // This happens when creating a new notecard using the AO on certain opensims. + // Play it safe instead of bringing down the viewer - MC + llwarns << "BAD JOOJOO! Text length (" << res << ") greater than text end (" << seg->getEnd() << "). Setting line start to " << seg->getEnd() << llendl; + res = seg->getEnd(); + } return res; } -- cgit v1.1 From c9ba7baf0230dacbf33601ace7f616c10b5d5967 Mon Sep 17 00:00:00 2001 From: Kakurady (Geneko Nemeth) Date: Mon, 16 Nov 2009 14:25:07 -0500 Subject: Use solid circles instead of asterisks for password fields. Regression fix for the 09.04 Experimental --- linden/indra/llui/lllineeditor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 7d91ece..c1d8efa 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -439,7 +439,7 @@ S32 LLLineEditor::calculateCursorFromMouse( S32 local_mouse_x ) { for (S32 i = 0; i < mText.length(); i++) { - asterix_text += '*'; + asterix_text += (llwchar) 0x2022L; } wtext = asterix_text.c_str(); } @@ -1938,7 +1938,7 @@ void LLLineEditor::draw() std::string text; for (S32 i = 0; i < mText.length(); i++) { - text += '*'; + text += "\xe2\x80\xa2"; } mText = text; } -- cgit v1.1 From 0819763a22fa70a3808197ed5bedf0a98ccf1293 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 8 Sep 2010 01:17:37 -0700 Subject: Replace '>' glyph in cascading menus with a proper triangle(backport from Viewer 2) --- linden/indra/llui/llmenugl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llmenugl.cpp b/linden/indra/llui/llmenugl.cpp index e00700a..8bca58a 100644 --- a/linden/indra/llui/llmenugl.cpp +++ b/linden/indra/llui/llmenugl.cpp @@ -102,7 +102,7 @@ const S32 TEAROFF_SEPARATOR_HEIGHT_PIXELS = 10; const S32 MENU_ITEM_PADDING = 4; const std::string BOOLEAN_TRUE_PREFIX( "X" ); -const std::string BRANCH_SUFFIX( ">" ); +const std::string BRANCH_SUFFIX( "\xE2\x96\xB6" ); // U+25B6 BLACK RIGHT-POINTING TRIANGLE const std::string ARROW_UP ("^^^^^^^"); const std::string ARROW_DOWN("vvvvvvv"); -- cgit v1.1 From b98e28160cfdc19cab4fba69f8aeb6c4a690e65c Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 8 Sep 2010 12:34:00 -0700 Subject: Changed the menu enabled 'x' to a checkmark --- linden/indra/llui/llmenugl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llmenugl.cpp b/linden/indra/llui/llmenugl.cpp index 8bca58a..91bb581 100644 --- a/linden/indra/llui/llmenugl.cpp +++ b/linden/indra/llui/llmenugl.cpp @@ -101,7 +101,7 @@ const U32 SEPARATOR_HEIGHT_PIXELS = 8; const S32 TEAROFF_SEPARATOR_HEIGHT_PIXELS = 10; const S32 MENU_ITEM_PADDING = 4; -const std::string BOOLEAN_TRUE_PREFIX( "X" ); +const std::string BOOLEAN_TRUE_PREFIX( "\xe2\x9c\x93" ); // U+2714 -- MC const std::string BRANCH_SUFFIX( "\xE2\x96\xB6" ); // U+25B6 BLACK RIGHT-POINTING TRIANGLE const std::string ARROW_UP ("^^^^^^^"); const std::string ARROW_DOWN("vvvvvvv"); -- cgit v1.1 From d14cf874b7b09ed9d845d7176f0c406a2e79f203 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 15 Sep 2010 03:33:05 -0700 Subject: First commit in the long overhaul of making spell check consistent and workable. Contains code cleanup and a change in logic. Spell check is now only available on text/line editors that have spell_check set to true in xml --- linden/indra/llui/lllineeditor.cpp | 207 +++++++++++++++------------- linden/indra/llui/lllineeditor.h | 4 +- linden/indra/llui/lltexteditor.cpp | 267 +++++++++++++++++++------------------ linden/indra/llui/lltexteditor.h | 4 +- 4 files changed, 260 insertions(+), 222 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index c1d8efa..e95af79 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -171,7 +171,7 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mHaveHistory(FALSE), mImage( sImage ), mReplaceNewlinesWithSpaces( TRUE ), - mOverRideAndShowMisspellings( FALSE ) + mShowMisspellings( FALSE ) { llassert( max_length_bytes > 0 ); @@ -546,19 +546,19 @@ void LLLineEditor::spell_show(void * data) SpellMenuBind* tempBind = (SpellMenuBind*)data; LLLineEditor* line = tempBind->origin; - if(tempBind && line) + if( tempBind && line) { - if(tempBind->word=="Show Misspellings") + if (tempBind->word=="Show Misspellings") { - line->setOverRideAndShowMisspellings(TRUE); - }else + line->setShowMisspellings(TRUE); + } + else { - line->setOverRideAndShowMisspellings(FALSE); + line->setShowMisspellings(FALSE); } } - - } + std::vector LLLineEditor::getMisspelledWordsPositions() { std::vector thePosesOfBadWords; @@ -604,25 +604,29 @@ std::vector LLLineEditor::getMisspelledWordsPositions() } return thePosesOfBadWords; } + void LLLineEditor::spell_add(void* data) { SpellMenuBind* tempBind = (SpellMenuBind*)data; - if(tempBind) + if (tempBind) { glggHunSpell->addWordToCustomDictionary(tempBind->word); tempBind->origin->mPrevSpelledText="";//make it update } } + void LLLineEditor::context_paste(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->paste(); } + void LLLineEditor::context_delete(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->doDelete(); } + void LLLineEditor::context_selectall(void* data) { LLLineEditor* line = (LLLineEditor*)data; @@ -728,16 +732,17 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) S32 wordStart = 0; S32 wordEnd = calculateCursorFromMouse(x); - LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); if (menu) { if(menu->isOpen()) + { menu->setVisible(FALSE); - for(int i = 0;i<(int)suggestionMenuItems.size();i++) + } + for (int i = 0;i<(int)suggestionMenuItems.size();i++) { SpellMenuBind * tempBind = suggestionMenuItems[i]; - if(tempBind) + if (tempBind) { menu->remove((LLMenuItemCallGL *)tempBind->menuItem); ((LLMenuItemCallGL *)tempBind->menuItem)->die(); @@ -748,69 +753,74 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - menu->setItemVisible("Translate To",!mReadOnly); - menu->setItemVisible("Transep",!mReadOnly); + menu->setItemVisible("Translate To", !mReadOnly); + menu->setItemVisible("Transep", !mReadOnly); - const LLWString& text = mText.getWString(); - if(( LLTextEditor::isPartOfWord( text[wordEnd] ) ) - &&(!mReadOnly)) + // spell_check="true" in xui + if (!mReadOnly && mShowMisspellings) { - // Select word the cursor is over - while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) - { - wordEnd--; - } - wordStart=wordEnd; - //startSelection(); + const LLWString& text = mText.getWString(); - while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) + // search for word matches + if (LLTextEditor::isPartOfWord(text[wordEnd])) { - wordEnd++; - } - std::string selectedWord(std::string(text.begin(), - text.end()).substr(wordStart,wordEnd-wordStart)); - if(!glggHunSpell->isSpelledRight(selectedWord)) - { - //misspelled word here, and you have just right clicked on it! - std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); - //menu->setItemVisible("Transep",(suggs.size()>0)); + // Select word the cursor is over + while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) + { + wordEnd--; + } + wordStart = wordEnd; + //startSelection(); - for(int i = 0;i<(int)suggs.size();i++) + while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) { + wordEnd++; + } + std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); + + if (!glggHunSpell->isSpelledRight(selectedWord)) + { + //misspelled word here, and you have just right clicked on it! + std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); + //menu->setItemVisible("Transep",(suggs.size()>0)); + + for (int i = 0; i<(int)suggs.size() ;i++) + { + SpellMenuBind * tempStruct = new SpellMenuBind; + tempStruct->origin = this; + tempStruct->word = suggs[i]; + tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionStart=wordStart; + LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( + tempStruct->word, spell_correct, NULL, tempStruct); + //new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + tempStruct->menuItem = suggMenuItem; + suggestionMenuItems.push_back(tempStruct); + menu->append(suggMenuItem); + } SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - tempStruct->word = suggs[i]; + tempStruct->word = selectedWord; tempStruct->wordPositionEnd = wordEnd; tempStruct->wordPositionStart=wordStart; LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - tempStruct->word, spell_correct, NULL, tempStruct); - //new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + "Add Word", spell_add, NULL, tempStruct); tempStruct->menuItem = suggMenuItem; suggestionMenuItems.push_back(tempStruct); menu->append(suggMenuItem); } - SpellMenuBind * tempStruct = new SpellMenuBind; - tempStruct->origin = this; - tempStruct->word = selectedWord; - tempStruct->wordPositionEnd = wordEnd; - tempStruct->wordPositionStart=wordStart; - LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - "Add Word", spell_add, NULL, tempStruct); - tempStruct->menuItem = suggMenuItem; - suggestionMenuItems.push_back(tempStruct); - menu->append(suggMenuItem); } - } - if((!mReadOnly)&&((!glggHunSpell->highlightInRed) - ||(mOverRideAndShowMisspellings))) - { SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if(mOverRideAndShowMisspellings) + if (glggHunSpell->mSpellCheckHighlight) + { tempStruct->word = "Hide Misspellings"; + } else + { tempStruct->word = "Show Misspellings"; + } LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( tempStruct->word, spell_show, NULL, tempStruct); tempStruct->menuItem = suggMenuItem; @@ -1838,36 +1848,43 @@ void LLLineEditor::doDelete() } } } + void LLLineEditor::autoCorrectText() { static BOOL *doAnything = rebind_llcontrol("EmeraldEnableAutoCorrect", &gSavedSettings, true); - if( (!mReadOnly) && (*doAnything) && (isSpellDirty())) + if (!mReadOnly && *doAnything && isSpellDirty()) { S32 wordStart = 0; S32 wordEnd = mCursorPos-1; //llinfos <<"Checking Word, Cursor is at "< 0) && (' '!=text[wordEnd-1])) { wordEnd--; } - wordStart=wordEnd; + wordStart = wordEnd; while ((wordEnd < (S32)text.length()) && (' '!=text[wordEnd] ) ) { wordEnd++; } std::string lastTypedWord(std::string(text.begin(), - text.end()).substr(wordStart,wordEnd-wordStart)); + text.end()).substr(wordStart, wordEnd-wordStart)); //llinfos << " The last typed word has been chosen, it is "<replaceWord(lastTypedWord)); - if(correctedWord!=lastTypedWord) + if(correctedWord != lastTypedWord) { int dif = correctedWord.length()-lastTypedWord.length(); std::string regText(mText); @@ -1879,53 +1896,56 @@ void LLLineEditor::autoCorrectText() } } } + void LLLineEditor::drawMisspelled(LLRect background) { - if((glggHunSpell->highlightInRed || mOverRideAndShowMisspellings) - &&(!mReadOnly)) + if (!mReadOnly && mShowMisspellings) { - S32 newStartSpellHere =mScrollHPos; - S32 cursorloc =calculateCursorFromMouse(mMaxHPixels); - S32 newStopSpellHere = ( ((S32)mText.length())>cursorloc)?cursorloc:(S32)mText.length(); + S32 newStartSpellHere = mScrollHPos; + S32 cursorloc = calculateCursorFromMouse(mMaxHPixels); + S32 newStopSpellHere = (((S32)mText.length())>cursorloc) ? cursorloc : (S32)mText.length(); F32 elapsed = mSpellTimer.getElapsedTimeF32(); - if(S32(elapsed / 1) & 1) + if (S32(elapsed / 1) & 1) { - if(isSpellDirty()||(newStartSpellHere!=mStartSpellHere)||(newStopSpellHere!=mEndSpellHere)) + if (isSpellDirty() || (newStartSpellHere != mStartSpellHere) || ( newStopSpellHere != mEndSpellHere)) { - mStartSpellHere=newStartSpellHere; - mEndSpellHere= newStopSpellHere; + mStartSpellHere = newStartSpellHere; + mEndSpellHere = newStopSpellHere; resetSpellDirty(); misspellLocations=getMisspelledWordsPositions(); } } - for(int i =0;i<(int)misspellLocations.size();i++) - { - S32 wstart =findPixelNearestPos( misspellLocations[i]-getCursor()); - S32 wend = findPixelNearestPos(misspellLocations[++i]-getCursor()); - S32 maxw = getRect().getWidth(); - if(wend > maxw) - { - wend=maxw; - } - if(wstart > maxw) - { - wstart=maxw; - } - gGL.color4ub(255,0,0,200); - //3 line zig zags.. - while(wstartmSpellCheckHighlight) + { + for (int i =0; i<(int)misspellLocations.size(); i++) { - gl_line_2d(wstart,background.mBottom-1,wstart+3,background.mBottom+2); - gl_line_2d(wstart+3,background.mBottom+2,wstart+6,background.mBottom-1); - wstart+=6; - } + S32 wstart =findPixelNearestPos( misspellLocations[i]-getCursor()); + S32 wend = findPixelNearestPos(misspellLocations[++i]-getCursor()); + S32 maxw = getRect().getWidth(); + if (wend > maxw) + { + wend = maxw; + } + if (wstart > maxw) + { + wstart = maxw; + } + gGL.color4ub(255,0,0,200); + //3 line zig zags.. + while (wstart < wend) + { + gl_line_2d(wstart, background.mBottom-1, wstart+3, background.mBottom+2); + gl_line_2d(wstart+3, background.mBottom+2, wstart+6, background.mBottom-1); + wstart+=6; + } + } } } - } + void LLLineEditor::draw() { autoCorrectText(); @@ -2797,6 +2817,11 @@ LLView* LLLineEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory { line_editor->setCommitOnFocusLost(commit_on_focus_lost); } + BOOL show_misspellings = FALSE; + if (node->getAttributeBOOL("spell_check", show_misspellings)) + { + line_editor->setShowMisspellings(show_misspellings); + } line_editor->setColorParameters(node); diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 6de57ec..1d24803 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -198,7 +198,7 @@ public: void setWriteableBgColor( const LLColor4& c ) { mWriteableBgColor = c; } void setReadOnlyBgColor( const LLColor4& c ) { mReadOnlyBgColor = c; } void setFocusBgColor(const LLColor4& c) { mFocusBgColor = c; } - void setOverRideAndShowMisspellings(BOOL b) { mOverRideAndShowMisspellings =b;} + void setShowMisspellings(BOOL b) { mShowMisspellings = b;} const LLColor4& getFgColor() const { return mFgColor; } const LLColor4& getReadOnlyFgColor() const { return mReadOnlyFgColor; } @@ -293,7 +293,7 @@ protected: std::vector misspellLocations; // where all the mispelled words are S32 mStartSpellHere; // the position of the first char on the screen, stored so we know when to update S32 mEndSpellHere; // the location of the last char on the screen - BOOL mOverRideAndShowMisspellings; + BOOL mShowMisspellings; LLFrameTimer mSpellTimer; //to keep track of what we have to remove before showing menu std::vector suggestionMenuItems; 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( mLastSelectionY(-1), mReflowNeeded(FALSE), mScrollNeeded(FALSE), - mOverRideAndShowMisspellings(FALSE) + mShowMisspellings(FALSE) { mSourceID.generate(); @@ -490,10 +490,10 @@ void LLTextEditor::spell_show(void * data) { if(tempBind->word=="Show Misspellings") { - line->setOverRideAndShowMisspellings(TRUE); + line->setShowMisspellings(TRUE); }else { - line->setOverRideAndShowMisspellings(FALSE); + line->setShowMisspellings(FALSE); } } } @@ -1426,7 +1426,6 @@ BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) } BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) { - setFocus(TRUE); //setCursorAtLocalPos( x, y, TRUE ); @@ -1450,69 +1449,73 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - menu->setItemVisible("Translate To",!mReadOnly); - menu->setItemVisible("Transep",!mReadOnly); - - const LLWString &text = mWText; + menu->setItemVisible("Translate To", !mReadOnly); + menu->setItemVisible("Transep", !mReadOnly); - if(( isPartOfWord( text[wordEnd] ) )&&(!mReadOnly)) + // spell_check="true" in xui + if (!mReadOnly && mShowMisspellings) { - // Select word the cursor is over - while ((wordEnd > 0) && isPartOfWord(text[wordEnd-1])) - { - wordEnd--; - } - wordStart=wordEnd; - //startSelection(); - - while ((wordEnd < (S32)text.length()) && isPartOfWord( text[wordEnd] ) ) - { - wordEnd++; - } - std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); - if(!glggHunSpell->isSpelledRight(selectedWord)) + const LLWString &text = mWText; + + if (isPartOfWord(text[wordEnd]) && !mReadOnly) { - //misspelled word here, and you have just right clicked on it! - std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); + // Select word the cursor is over + while ((wordEnd > 0) && isPartOfWord(text[wordEnd-1])) + { + wordEnd--; + } + wordStart = wordEnd; + //startSelection(); - //menu->setItemVisible("Transep",(suggs.size()>0)); - for(int i = 0;i<(int)suggs.size();i++) + while ((wordEnd < (S32)text.length()) && isPartOfWord( text[wordEnd] ) ) + { + wordEnd++; + } + std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); + if (!glggHunSpell->isSpelledRight(selectedWord)) { + //misspelled word here, and you have just right clicked on it! + std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); + + //menu->setItemVisible("Transep",(suggs.size()>0)); + for (int i = 0; i<(int)suggs.size(); i++) + { + SpellMenuBind * tempStruct = new SpellMenuBind; + tempStruct->origin = this; + tempStruct->word = suggs[i]; + tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionStart=wordStart; + tempStruct->wordY=y; + LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( + tempStruct->word, spell_correct, NULL, tempStruct); + tempStruct->menuItem = suggMenuItem; + suggestionMenuItems.push_back(tempStruct); + menu->append(suggMenuItem); + } SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - tempStruct->word = suggs[i]; + tempStruct->word = selectedWord; tempStruct->wordPositionEnd = wordEnd; tempStruct->wordPositionStart=wordStart; tempStruct->wordY=y; LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - tempStruct->word, spell_correct, NULL, tempStruct); + "Add Word", spell_add, NULL, tempStruct); tempStruct->menuItem = suggMenuItem; suggestionMenuItems.push_back(tempStruct); menu->append(suggMenuItem); } - SpellMenuBind * tempStruct = new SpellMenuBind; - tempStruct->origin = this; - tempStruct->word = selectedWord; - tempStruct->wordPositionEnd = wordEnd; - tempStruct->wordPositionStart=wordStart; - tempStruct->wordY=y; - LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( - "Add Word", spell_add, NULL, tempStruct); - tempStruct->menuItem = suggMenuItem; - suggestionMenuItems.push_back(tempStruct); - menu->append(suggMenuItem); } - } - if((!mReadOnly)&&((!glggHunSpell->highlightInRed) - ||(mOverRideAndShowMisspellings)||(mShowLineNumbers))) - { SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if(mOverRideAndShowMisspellings) + if (glggHunSpell->mSpellCheckHighlight) + { tempStruct->word = "Hide Misspellings"; + } else + { tempStruct->word = "Show Misspellings"; + } LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( tempStruct->word, spell_show, NULL, tempStruct); tempStruct->menuItem = suggMenuItem; @@ -3077,51 +3080,57 @@ void LLTextEditor::drawSelectionBackground() } } } + void LLTextEditor::autoCorrectText() -{ - +{ static BOOL *doAnything = rebind_llcontrol("EmeraldEnableAutoCorrect", &gSavedSettings, true); - if( (!mReadOnly) && (*doAnything) && (isSpellDirty()) ) + if (!mReadOnly && *doAnything && isSpellDirty()) { S32 wordStart = 0; S32 wordEnd = mCursorPos-1; - if(wordEnd<1)return; + if (wordEnd < 1) + { + return; + } LLWString& text = mWText; - if(text.size()<1)return; - if( LLTextEditor::isPartOfWord( text[wordEnd] )) return;//we only check on word breaks + if (text.size() < 1 || LLTextEditor::isPartOfWord(text[wordEnd])) + { + return;//we only check on word breaks + } + wordEnd--; - if( LLTextEditor::isPartOfWord( text[wordEnd] ) ) + if (LLTextEditor::isPartOfWord(text[wordEnd])) { while ((wordEnd > 0) && (text[wordEnd-1]!=' ')) { wordEnd--; } - wordStart=wordEnd; + wordStart = wordEnd; while ((wordEnd < (S32)text.length()) && (' '!= text[wordEnd] ) ) { wordEnd++; } std::string lastTypedWord(std::string(text.begin(), - text.end()).substr(wordStart,wordEnd-wordStart)); + text.end()).substr(wordStart, wordEnd-wordStart)); - std::string regText(text.begin(),text.end()); + std::string regText(text.begin(), text.end()); std::string correctedWord(LGGAutoCorrect::getInstance()->replaceWord(lastTypedWord)); - if(correctedWord!=lastTypedWord) + if (correctedWord != lastTypedWord) { - int dif = correctedWord.length()-lastTypedWord.length(); - regText.replace(wordStart,lastTypedWord.length(),correctedWord); - mWText=utf8str_to_wstring(regText); - mCursorPos+=dif; + int dif = correctedWord.length() - lastTypedWord.length(); + regText.replace(wordStart, lastTypedWord.length(), correctedWord); + mWText = utf8str_to_wstring(regText); + mCursorPos += dif; needsReflow(); } } } } + void LLTextEditor::drawMisspelled() { - if(mReadOnly)return; - if(glggHunSpell->highlightInRed || mOverRideAndShowMisspellings) + if (!mReadOnly && mShowMisspellings) { if( ( ((getLength()<400)||(false)) &&( (S32(mSpellTimer.getElapsedTimeF32() / 1) & 1) )) @@ -3132,80 +3141,86 @@ void LLTextEditor::drawMisspelled() S32 newSpellStart = getLineStart(mScrollbar->getDocPos());//start at the scroll start S32 newSpellEnd = getLineStart(mScrollbar->getDocPos() + 1 + mScrollbar->getDocSize()-mScrollbar->getDocPosMax());//end at the end o.o - if(mScrollbar->getDocPos() == mScrollbar->getDocPosMax()) + if (mScrollbar->getDocPos() == mScrollbar->getDocPosMax()) { - newSpellEnd=(S32)mWText.length(); + newSpellEnd = (S32)mWText.length(); } - if((isSpellDirty())||(newSpellEnd!=spellEnd || newSpellStart!=spellStart)) + if (isSpellDirty() || (newSpellEnd!=spellEnd || newSpellStart!=spellStart)) { spellEnd = newSpellEnd; spellStart = newSpellStart; - misspellLocations=getMisspelledWordsPositions(); + misspellLocations = getMisspelledWordsPositions(); } } //draw - for(int i =0;i<(int)misspellLocations.size();i++) + if (glggHunSpell->mSpellCheckHighlight) { - S32 wstart = misspellLocations[i]; - S32 wend = misspellLocations[++i]; - //start curor code mod - const LLWString &text = mWText; - const S32 text_len = getLength(); - // Skip through the lines we aren't drawing. - S32 search_pos = mScrollbar->getDocPos(); - S32 num_lines = getLineCount(); - if (search_pos >= num_lines)return; - S32 line_start = getLineStart(search_pos); - F32 line_height = mGLFont->getLineHeight(); - F32 text_y = (F32)(mTextRect.mTop) - line_height; - - F32 word_left = 0.f; - F32 word_right = 0.f; - F32 word_bottom = 0.f; - BOOL word_visible = FALSE; - - S32 line_end = 0; - // Determine if the cursor is visible and if so what its coordinates are. - while( (mTextRect.mBottom <= llround(text_y)) && (search_pos < num_lines)) + for (int i = 0; i<(int)misspellLocations.size() ;i++) { - line_end = text_len + 1; - S32 next_line = -1; - - if ((search_pos + 1) < num_lines) + S32 wstart = misspellLocations[i]; + S32 wend = misspellLocations[++i]; + //start curor code mod + const LLWString &text = mWText; + const S32 text_len = getLength(); + // Skip through the lines we aren't drawing. + S32 search_pos = mScrollbar->getDocPos(); + S32 num_lines = getLineCount(); + if (search_pos >= num_lines) { - next_line = getLineStart(search_pos + 1); - line_end = next_line - 1; + return; } - const llwchar* line = text.c_str() + line_start; - // Find the cursor and selection bounds - if( line_start <= wstart && wend <= line_end ) + S32 line_start = getLineStart(search_pos); + F32 line_height = mGLFont->getLineHeight(); + F32 text_y = (F32)(mTextRect.mTop) - line_height; + + F32 word_left = 0.f; + F32 word_right = 0.f; + F32 word_bottom = 0.f; + BOOL word_visible = FALSE; + + S32 line_end = 0; + // Determine if the cursor is visible and if so what its coordinates are. + while( (mTextRect.mBottom <= llround(text_y)) && (search_pos < num_lines)) { - word_visible = TRUE; - word_left = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wstart - line_start, mAllowEmbeddedItems )-1.f; - word_right = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wend - line_start, mAllowEmbeddedItems )+1.f; - word_bottom = text_y; - break; + line_end = text_len + 1; + S32 next_line = -1; + + if ((search_pos + 1) < num_lines) + { + next_line = getLineStart(search_pos + 1); + line_end = next_line - 1; + } + const llwchar* line = text.c_str() + line_start; + // Find the cursor and selection bounds + if( line_start <= wstart && wend <= line_end ) + { + word_visible = TRUE; + word_left = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wstart - line_start, mAllowEmbeddedItems )-1.f; + word_right = (F32)mTextRect.mLeft + mGLFont->getWidthF32(line, 0, wend - line_start, mAllowEmbeddedItems )+1.f; + word_bottom = text_y; + break; + } + // move down one line + text_y -= line_height; + line_start = next_line; + search_pos++; } - // move down one line - text_y -= line_height; - line_start = next_line; - search_pos++; - } - if(mShowLineNumbers) - { - word_left += UI_TEXTEDITOR_LINE_NUMBER_MARGIN; - word_right += UI_TEXTEDITOR_LINE_NUMBER_MARGIN; - } - // Draw the cursor - if( word_visible ) - { - //end cursos code mod - gGL.color4ub(255,0,0,200); - while(word_leftgetAttributeBOOL("track_bottom", mTrackBottom); + node->getAttributeBOOL("spell_check", mShowMisspellings); + LLColor4 color; if (LLUICtrlFactory::getAttributeColor(node,"cursor_color", color)) { diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index 6b372d7..c5c3af8 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -229,7 +229,7 @@ public: void setThumbColor( const LLColor4& color ); void setHighlightColor( const LLColor4& color ); void setShadowColor( const LLColor4& color ); - void setOverRideAndShowMisspellings(BOOL b){ mOverRideAndShowMisspellings =b;} + void setShowMisspellings(BOOL b) { mShowMisspellings = b; } // Hacky methods to make it into a word-wrapping, potentially scrolling, // read-only text box. @@ -526,7 +526,7 @@ private: S32 spellStart; S32 spellEnd; std::vector misspellLocations; // where all the mispelled words are - BOOL mOverRideAndShowMisspellings; + BOOL mShowMisspellings; // set in xui as "spell_check". Default value for a field S32 mMaxTextByteLength; // Maximum length mText is allowed to be in bytes -- cgit v1.1 From 465e1f011fa5b44b2873030e09fbf1631b069046 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 15 Sep 2010 11:20:50 -0700 Subject: More spell checking cleanup --- linden/indra/llui/lllineeditor.cpp | 6 +++--- linden/indra/llui/lltexteditor.cpp | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index e95af79..9c68fec 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -548,7 +548,7 @@ void LLLineEditor::spell_show(void * data) if( tempBind && line) { - if (tempBind->word=="Show Misspellings") + if (tempBind->word == "Show Misspellings") { line->setShowMisspellings(TRUE); } @@ -813,7 +813,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if (glggHunSpell->mSpellCheckHighlight) + if (glggHunSpell->getSpellCheckHighlight()) { tempStruct->word = "Hide Misspellings"; } @@ -1917,7 +1917,7 @@ void LLLineEditor::drawMisspelled(LLRect background) } } - if (glggHunSpell->mSpellCheckHighlight) + if (glggHunSpell->getSpellCheckHighlight()) { for (int i =0; i<(int)misspellLocations.size(); i++) { diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index d2469c3..cf35ee7 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -486,12 +486,13 @@ void LLTextEditor::spell_show(void * data) SpellMenuBind* tempBind = (SpellMenuBind*)data; LLTextEditor* line = tempBind->origin; - if(tempBind && line) + if (tempBind && line) { - if(tempBind->word=="Show Misspellings") + if (tempBind->word == "Show Misspellings") { line->setShowMisspellings(TRUE); - }else + } + else { line->setShowMisspellings(FALSE); } @@ -1508,7 +1509,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if (glggHunSpell->mSpellCheckHighlight) + if (glggHunSpell->getSpellCheckHighlight()) { tempStruct->word = "Hide Misspellings"; } @@ -3153,7 +3154,7 @@ void LLTextEditor::drawMisspelled() } } //draw - if (glggHunSpell->mSpellCheckHighlight) + if (glggHunSpell->getSpellCheckHighlight()) { for (int i = 0; i<(int)misspellLocations.size() ;i++) { -- cgit v1.1 From 215327d375c72d07949314a164faa0fdcbad94dc Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Thu, 16 Sep 2010 00:21:54 -0700 Subject: Fixed up the logic for the Hide Misspellings/Show Misspellings menu options. They now toggle spell check for a specific line/text editor consistently --- linden/indra/llui/lllineeditor.cpp | 28 ++++++++++++++++++---------- linden/indra/llui/lllineeditor.h | 5 +++-- linden/indra/llui/lltexteditor.cpp | 22 +++++++++++++++------- linden/indra/llui/lltexteditor.h | 5 +++-- 4 files changed, 39 insertions(+), 21 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 9c68fec..66ef4c6 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -171,7 +171,8 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mHaveHistory(FALSE), mImage( sImage ), mReplaceNewlinesWithSpaces( TRUE ), - mShowMisspellings( FALSE ) + mSpellCheckable( FALSE ), + mShowMisspellings(FALSE) { llassert( max_length_bytes > 0 ); @@ -209,6 +210,13 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, sImage = LLUI::getUIImage("sm_rounded_corners_simple.tga"); } mImage = sImage; + + // in other words, highlighting requires a restart + if (glggHunSpell->getSpellCheckHighlight()) + { + mShowMisspellings = TRUE; + } + // make the popup menu available //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); LLMenuGL* menu = new LLMenuGL("wot"); @@ -550,11 +558,11 @@ void LLLineEditor::spell_show(void * data) { if (tempBind->word == "Show Misspellings") { - line->setShowMisspellings(TRUE); + line->mShowMisspellings = TRUE; } else { - line->setShowMisspellings(FALSE); + line->mShowMisspellings = FALSE; } } } @@ -757,7 +765,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) menu->setItemVisible("Transep", !mReadOnly); // spell_check="true" in xui - if (!mReadOnly && mShowMisspellings) + if (!mReadOnly && mSpellCheckable) { const LLWString& text = mText.getWString(); @@ -813,7 +821,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if (glggHunSpell->getSpellCheckHighlight()) + if (mShowMisspellings) { tempStruct->word = "Hide Misspellings"; } @@ -1899,7 +1907,7 @@ void LLLineEditor::autoCorrectText() void LLLineEditor::drawMisspelled(LLRect background) { - if (!mReadOnly && mShowMisspellings) + if (!mReadOnly && mSpellCheckable) { S32 newStartSpellHere = mScrollHPos; S32 cursorloc = calculateCursorFromMouse(mMaxHPixels); @@ -1917,7 +1925,7 @@ void LLLineEditor::drawMisspelled(LLRect background) } } - if (glggHunSpell->getSpellCheckHighlight()) + if (mShowMisspellings) { for (int i =0; i<(int)misspellLocations.size(); i++) { @@ -2817,10 +2825,10 @@ LLView* LLLineEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory { line_editor->setCommitOnFocusLost(commit_on_focus_lost); } - BOOL show_misspellings = FALSE; - if (node->getAttributeBOOL("spell_check", show_misspellings)) + BOOL spell_checking = FALSE; + if (node->getAttributeBOOL("spell_check", spell_checking)) { - line_editor->setShowMisspellings(show_misspellings); + line_editor->setSpellCheckable(spell_checking); } line_editor->setColorParameters(node); diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 1d24803..147b232 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -198,7 +198,7 @@ public: void setWriteableBgColor( const LLColor4& c ) { mWriteableBgColor = c; } void setReadOnlyBgColor( const LLColor4& c ) { mReadOnlyBgColor = c; } void setFocusBgColor(const LLColor4& c) { mFocusBgColor = c; } - void setShowMisspellings(BOOL b) { mShowMisspellings = b;} + void setSpellCheckable(BOOL b) { mSpellCheckable = b; } const LLColor4& getFgColor() const { return mFgColor; } const LLColor4& getReadOnlyFgColor() const { return mReadOnlyFgColor; } @@ -293,7 +293,8 @@ protected: std::vector misspellLocations; // where all the mispelled words are S32 mStartSpellHere; // the position of the first char on the screen, stored so we know when to update S32 mEndSpellHere; // the location of the last char on the screen - BOOL mShowMisspellings; + BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field + BOOL mShowMisspellings; // show misspellings as highlighted (initialized in the ctor) LLFrameTimer mSpellTimer; //to keep track of what we have to remove before showing menu std::vector suggestionMenuItems; diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index cf35ee7..b101588 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -323,6 +323,7 @@ LLTextEditor::LLTextEditor( mLastSelectionY(-1), mReflowNeeded(FALSE), mScrollNeeded(FALSE), + mSpellCheckable(FALSE), mShowMisspellings(FALSE) { mSourceID.generate(); @@ -375,6 +376,13 @@ LLTextEditor::LLTextEditor( mParseHTML=FALSE; mHTML.clear(); + + // in other words, highlighting requires a restart + if (glggHunSpell->getSpellCheckHighlight()) + { + mShowMisspellings = TRUE; + } + // make the popup menu available //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); LLMenuGL* menu = new LLMenuGL("wot"); @@ -490,11 +498,11 @@ void LLTextEditor::spell_show(void * data) { if (tempBind->word == "Show Misspellings") { - line->setShowMisspellings(TRUE); + glggHunSpell->setSpellCheckHighlight(TRUE); } else { - line->setShowMisspellings(FALSE); + glggHunSpell->setSpellCheckHighlight(FALSE); } } } @@ -1454,7 +1462,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) menu->setItemVisible("Transep", !mReadOnly); // spell_check="true" in xui - if (!mReadOnly && mShowMisspellings) + if (!mReadOnly && mSpellCheckable) { const LLWString &text = mWText; @@ -1509,7 +1517,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if (glggHunSpell->getSpellCheckHighlight()) + if (mShowMisspellings) { tempStruct->word = "Hide Misspellings"; } @@ -3131,7 +3139,7 @@ void LLTextEditor::autoCorrectText() void LLTextEditor::drawMisspelled() { - if (!mReadOnly && mShowMisspellings) + if (!mReadOnly && mSpellCheckable) { if( ( ((getLength()<400)||(false)) &&( (S32(mSpellTimer.getElapsedTimeF32() / 1) & 1) )) @@ -3154,7 +3162,7 @@ void LLTextEditor::drawMisspelled() } } //draw - if (glggHunSpell->getSpellCheckHighlight()) + if (mShowMisspellings) { for (int i = 0; i<(int)misspellLocations.size() ;i++) { @@ -4891,7 +4899,7 @@ void LLTextEditor::setTextEditorParameters(LLXMLNodePtr node) node->getAttributeBOOL("track_bottom", mTrackBottom); - node->getAttributeBOOL("spell_check", mShowMisspellings); + node->getAttributeBOOL("spell_check", mSpellCheckable); LLColor4 color; if (LLUICtrlFactory::getAttributeColor(node,"cursor_color", color)) diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index c5c3af8..57a6bbd 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -229,7 +229,7 @@ public: void setThumbColor( const LLColor4& color ); void setHighlightColor( const LLColor4& color ); void setShadowColor( const LLColor4& color ); - void setShowMisspellings(BOOL b) { mShowMisspellings = b; } + void setSpellCheckable(BOOL b) { mSpellCheckable = b; } // Hacky methods to make it into a word-wrapping, potentially scrolling, // read-only text box. @@ -526,7 +526,8 @@ private: S32 spellStart; S32 spellEnd; std::vector misspellLocations; // where all the mispelled words are - BOOL mShowMisspellings; // set in xui as "spell_check". Default value for a field + BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field + BOOL mShowMisspellings; // show misspellings as highlighted (initialized in the ctor) S32 mMaxTextByteLength; // Maximum length mText is allowed to be in bytes -- cgit v1.1 From 35df5441d3e2789663532c948731aff3a1e04728 Mon Sep 17 00:00:00 2001 From: Armin Weatherwax Date: Mon, 14 Jun 2010 12:04:49 +0200 Subject: llmediaplugins first step --- linden/indra/llui/CMakeLists.txt | 15 ++++-- linden/indra/llui/llbutton.cpp | 5 ++ linden/indra/llui/llbutton.h | 3 +- linden/indra/llui/llfloater.cpp | 8 ++-- linden/indra/llui/llfocusmgr.cpp | 84 +++++++++++++++++++++++++++++---- linden/indra/llui/llfocusmgr.h | 49 +++++++++++++++---- linden/indra/llui/lliconctrl.cpp | 6 +++ linden/indra/llui/lliconctrl.h | 2 + linden/indra/llui/llmultisliderctrl.cpp | 3 -- linden/indra/llui/llpanel.cpp | 19 ++++++-- linden/indra/llui/llpanel.h | 3 ++ linden/indra/llui/llsliderctrl.cpp | 2 - linden/indra/llui/llspinctrl.cpp | 1 - linden/indra/llui/lltextparser.cpp | 48 ++----------------- linden/indra/llui/lltextparser.h | 7 +-- linden/indra/llui/llui.cpp | 1 - linden/indra/llui/lluictrl.cpp | 55 +++------------------ linden/indra/llui/lluictrl.h | 26 +--------- linden/indra/llui/llview.cpp | 7 +-- linden/indra/llui/llview.h | 14 ++++-- 20 files changed, 186 insertions(+), 172 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/CMakeLists.txt b/linden/indra/llui/CMakeLists.txt index a0f80b4..e6b3b63 100644 --- a/linden/indra/llui/CMakeLists.txt +++ b/linden/indra/llui/CMakeLists.txt @@ -3,11 +3,9 @@ project(llui) include(00-Common) -include(LLAudio) include(LLCommon) include(LLImage) include(LLMath) -include(LLMedia) include(LLMessage) include(LLRender) include(LLWindow) @@ -15,11 +13,9 @@ include(LLVFS) include(LLXML) include_directories( - ${LLAUDIO_INCLUDE_DIRS} ${LLCOMMON_INCLUDE_DIRS} ${LLIMAGE_INCLUDE_DIRS} ${LLMATH_INCLUDE_DIRS} - ${LLMEDIA_INCLUDE_DIRS} ${LLMESSAGE_INCLUDE_DIRS} ${LLRENDER_INCLUDE_DIRS} ${LLWINDOW_INCLUDE_DIRS} @@ -141,3 +137,14 @@ set_source_files_properties(${llui_HEADER_FILES} list(APPEND llui_SOURCE_FILES ${llui_HEADER_FILES}) add_library (llui ${llui_SOURCE_FILES}) +# Libraries on which this library depends, needed for Linux builds +# Sort by high-level to low-level +target_link_libraries(llui + llrender + llwindow + llimage + llvfs # ugh, just for LLDir + llxml + llcommon # must be after llimage, llwindow, llrender + llmath + ) diff --git a/linden/indra/llui/llbutton.cpp b/linden/indra/llui/llbutton.cpp index 1a6c705..702e34e 100644 --- a/linden/indra/llui/llbutton.cpp +++ b/linden/indra/llui/llbutton.cpp @@ -840,6 +840,11 @@ void LLButton::setColor(const LLColor4& color) setImageColor(color); } +void LLButton::setAlpha(F32 alpha) +{ + mImageColor.setAlpha(alpha); + mDisabledImageColor.setAlpha(alpha * 0.5f); +} void LLButton::setImageDisabled(LLPointer image) { diff --git a/linden/indra/llui/llbutton.h b/linden/indra/llui/llbutton.h index 724b775..2174d95 100644 --- a/linden/indra/llui/llbutton.h +++ b/linden/indra/llui/llbutton.h @@ -136,7 +136,8 @@ public: void setImageColor(const std::string& color_control); void setImageColor(const LLColor4& c); - virtual void setColor(const LLColor4& c); + /*virtual*/ void setColor(const LLColor4& c); + /*virtual*/ void setAlpha(F32 alpha); void setImages(const std::string &image_name, const std::string &selected_name); void setDisabledImages(const std::string &image_name, const std::string &selected_name); diff --git a/linden/indra/llui/llfloater.cpp b/linden/indra/llui/llfloater.cpp index f6451a1..bb42ca3 100644 --- a/linden/indra/llui/llfloater.cpp +++ b/linden/indra/llui/llfloater.cpp @@ -1459,9 +1459,9 @@ void LLFloater::draw() { if (hasFocus() && getDefaultButton()->getEnabled()) { - LLUICtrl* focus_ctrl = gFocusMgr.getKeyboardFocus(); + LLFocusableElement* focus_ctrl = gFocusMgr.getKeyboardFocus(); // is this button a direct descendent and not a nested widget (e.g. checkbox)? - BOOL focus_is_child_button = dynamic_cast(focus_ctrl) != NULL && focus_ctrl->getParent() == this; + BOOL focus_is_child_button = dynamic_cast(focus_ctrl) != NULL && dynamic_cast(focus_ctrl)->getParent() == this; // only enable default button when current focus is not a button getDefaultButton()->setBorderEnabled(!focus_is_child_button); } @@ -1481,7 +1481,7 @@ void LLFloater::draw() else { // draw children - LLView* focused_child = gFocusMgr.getKeyboardFocus(); + LLView* focused_child = dynamic_cast(gFocusMgr.getKeyboardFocus()); BOOL focused_child_visible = FALSE; if (focused_child && focused_child->getParent() == this) { @@ -2239,7 +2239,7 @@ BOOL LLFloaterView::allChildrenClosed() LLView* viewp = *it; LLFloater* floaterp = (LLFloater*)viewp; - if (floaterp->getVisible() && !floaterp->isDead() && floaterp->canClose()) + if (floaterp->getVisible() && !floaterp->isDead() && floaterp->isCloseable()) { return false; } diff --git a/linden/indra/llui/llfocusmgr.cpp b/linden/indra/llui/llfocusmgr.cpp index 661ffdd..96b01b9 100644 --- a/linden/indra/llui/llfocusmgr.cpp +++ b/linden/indra/llui/llfocusmgr.cpp @@ -38,6 +38,68 @@ const F32 FOCUS_FADE_TIME = 0.3f; +// NOTE: the LLFocusableElement implementation has been here from lluictrl.cpp. + +LLFocusableElement::LLFocusableElement() +: mFocusLostCallback(NULL), + mFocusReceivedCallback(NULL), + mFocusChangedCallback(NULL), + mFocusCallbackUserData(NULL) +{ +} + +// virtual +BOOL LLFocusableElement::handleKey(KEY key, MASK mask, BOOL called_from_parent) +{ + return FALSE; +} + +// virtual +BOOL LLFocusableElement::handleUnicodeChar(llwchar uni_char, BOOL called_from_parent) +{ + return FALSE; +} + +// virtual +LLFocusableElement::~LLFocusableElement() +{ +} + +void LLFocusableElement::onFocusReceived() +{ + if( mFocusReceivedCallback ) + { + mFocusReceivedCallback( this, mFocusCallbackUserData ); + } + if( mFocusChangedCallback ) + { + mFocusChangedCallback( this, mFocusCallbackUserData ); + } +} + +void LLFocusableElement::onFocusLost() +{ + if( mFocusLostCallback ) + { + mFocusLostCallback( this, mFocusCallbackUserData ); + } + + if( mFocusChangedCallback ) + { + mFocusChangedCallback( this, mFocusCallbackUserData ); + } +} + +BOOL LLFocusableElement::hasFocus() const +{ + return gFocusMgr.getKeyboardFocus() == this; +} + +void LLFocusableElement::setFocus(BOOL b) +{ +} + + LLFocusMgr gFocusMgr; LLFocusMgr::LLFocusMgr() @@ -87,11 +149,13 @@ void LLFocusMgr::releaseFocusIfNeeded( const LLView* view ) } -void LLFocusMgr::setKeyboardFocus(LLUICtrl* new_focus, BOOL lock, BOOL keystrokes_only) +void LLFocusMgr::setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock, BOOL keystrokes_only) { if (mLockedView && (new_focus == NULL || - (new_focus != mLockedView && !new_focus->hasAncestor(mLockedView)))) + (new_focus != mLockedView + && dynamic_cast(new_focus) + && !dynamic_cast(new_focus)->hasAncestor(mLockedView)))) { // don't allow focus to go to anything that is not the locked focus // or one of its descendants @@ -121,7 +185,8 @@ void LLFocusMgr::setKeyboardFocus(LLUICtrl* new_focus, BOOL lock, BOOL keystroke mFocusTimer.reset(); #ifdef _DEBUG - mKeyboardFocusName = new_focus ? new_focus->getName() : std::string("none"); + LLUICtrl* focus_ctrl = dynamic_cast(new_focus); + mKeyboardFocusName = focus_ctrl ? focus_ctrl->getName() : std::string("none"); #endif // If we've got a default keyboard focus, and the caller is @@ -131,8 +196,8 @@ void LLFocusMgr::setKeyboardFocus(LLUICtrl* new_focus, BOOL lock, BOOL keystroke mDefaultKeyboardFocus->setFocus(TRUE); } - LLView* focus_subtree = mKeyboardFocus; - LLView* viewp = mKeyboardFocus; + LLView* focus_subtree = dynamic_cast(mKeyboardFocus); + LLView* viewp = dynamic_cast(mKeyboardFocus); // find root-most focus root while(viewp) { @@ -146,7 +211,8 @@ void LLFocusMgr::setKeyboardFocus(LLUICtrl* new_focus, BOOL lock, BOOL keystroke if (focus_subtree) { - mFocusHistory[focus_subtree->getHandle()] = mKeyboardFocus ? mKeyboardFocus->getHandle() : LLHandle(); + LLView* focused_view = dynamic_cast(mKeyboardFocus); + mFocusHistory[focus_subtree->getHandle()] = focused_view ? focused_view->getHandle() : LLHandle(); } } @@ -160,7 +226,7 @@ void LLFocusMgr::setKeyboardFocus(LLUICtrl* new_focus, BOOL lock, BOOL keystroke // Returns TRUE is parent or any descedent of parent has keyboard focus. BOOL LLFocusMgr::childHasKeyboardFocus(const LLView* parent ) const { - LLView* focus_view = mKeyboardFocus; + LLView* focus_view = dynamic_cast(mKeyboardFocus); while( focus_view ) { if( focus_view == parent ) @@ -190,7 +256,7 @@ BOOL LLFocusMgr::childHasMouseCapture( const LLView* parent ) const return FALSE; } -void LLFocusMgr::removeKeyboardFocusWithoutCallback( const LLView* focus ) +void LLFocusMgr::removeKeyboardFocusWithoutCallback( const LLFocusableElement* focus ) { // should be ok to unlock here, as you have to know the locked view // in order to unlock it @@ -313,7 +379,7 @@ void LLFocusMgr::removeTopCtrlWithoutCallback( const LLUICtrl* top_view ) void LLFocusMgr::lockFocus() { - mLockedView = mKeyboardFocus; + mLockedView = dynamic_cast(mKeyboardFocus); } void LLFocusMgr::unlockFocus() diff --git a/linden/indra/llui/llfocusmgr.h b/linden/indra/llui/llfocusmgr.h index aaeb25a..88ede1a 100644 --- a/linden/indra/llui/llfocusmgr.h +++ b/linden/indra/llui/llfocusmgr.h @@ -37,10 +37,39 @@ #include "llstring.h" #include "llframetimer.h" -#include "llview.h" +#include "llui.h" class LLUICtrl; class LLMouseHandler; +class LLView; + +class LLFocusableElement +{ + friend class LLFocusMgr; // allow access to focus change handlers +public: + LLFocusableElement(); + virtual ~LLFocusableElement(); + + virtual void setFocus( BOOL b ); + virtual BOOL hasFocus() const; + + void setFocusLostCallback(void (*cb)(LLFocusableElement* caller, void*), void* user_data = NULL) { mFocusLostCallback = cb; mFocusCallbackUserData = user_data; } + void setFocusReceivedCallback( void (*cb)(LLFocusableElement*, void*), void* user_data = NULL) { mFocusReceivedCallback = cb; mFocusCallbackUserData = user_data; } + void setFocusChangedCallback( void (*cb)(LLFocusableElement*, void*), void* user_data = NULL ) { mFocusChangedCallback = cb; mFocusCallbackUserData = user_data; } + + // These were brought up the hierarchy from LLView so that we don't have to use dynamic_cast when dealing with keyboard focus. + virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent); + +protected: + virtual void onFocusReceived(); + virtual void onFocusLost(); + void (*mFocusLostCallback)( LLFocusableElement* caller, void* userdata ); + void (*mFocusReceivedCallback)( LLFocusableElement* ctrl, void* userdata ); + void (*mFocusChangedCallback)( LLFocusableElement* ctrl, void* userdata ); + void* mFocusCallbackUserData; +}; + class LLFocusMgr { @@ -55,11 +84,11 @@ public: BOOL childHasMouseCapture( const LLView* parent ) const; // Keyboard Focus - void setKeyboardFocus(LLUICtrl* new_focus, BOOL lock = FALSE, BOOL keystrokes_only = FALSE); // new_focus = NULL to release the focus. - LLUICtrl* getKeyboardFocus() const { return mKeyboardFocus; } - LLUICtrl* getLastKeyboardFocus() const { return mLastKeyboardFocus; } + void setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock = FALSE, BOOL keystrokes_only = FALSE); // new_focus = NULL to release the focus. + LLFocusableElement* getKeyboardFocus() const { return mKeyboardFocus; } + LLFocusableElement* getLastKeyboardFocus() const { return mLastKeyboardFocus; } BOOL childHasKeyboardFocus( const LLView* parent ) const; - void removeKeyboardFocusWithoutCallback( const LLView* focus ); + void removeKeyboardFocusWithoutCallback( const LLFocusableElement* focus ); BOOL getKeystrokesOnly() { return mKeystrokesOnly; } void setKeystrokesOnly(BOOL keystrokes_only) { mKeystrokesOnly = keystrokes_only; } @@ -75,8 +104,8 @@ public: // If setKeyboardFocus(NULL) is called, and there is a non-NULL default // keyboard focus view, focus goes there. JC - void setDefaultKeyboardFocus(LLUICtrl* default_focus) { mDefaultKeyboardFocus = default_focus; } - LLUICtrl* getDefaultKeyboardFocus() const { return mDefaultKeyboardFocus; } + void setDefaultKeyboardFocus(LLFocusableElement* default_focus) { mDefaultKeyboardFocus = default_focus; } + LLFocusableElement* getDefaultKeyboardFocus() const { return mDefaultKeyboardFocus; } // Top View @@ -98,9 +127,9 @@ private: LLMouseHandler* mMouseCaptor; // Mouse events are premptively routed to this object // Keyboard Focus - LLUICtrl* mKeyboardFocus; // Keyboard events are preemptively routed to this object - LLUICtrl* mLastKeyboardFocus; // who last had focus - LLUICtrl* mDefaultKeyboardFocus; + LLFocusableElement* mKeyboardFocus; // Keyboard events are preemptively routed to this object + LLFocusableElement* mLastKeyboardFocus; // who last had focus + LLFocusableElement* mDefaultKeyboardFocus; BOOL mKeystrokesOnly; // Top View diff --git a/linden/indra/llui/lliconctrl.cpp b/linden/indra/llui/lliconctrl.cpp index e73c8fe..0df960e 100644 --- a/linden/indra/llui/lliconctrl.cpp +++ b/linden/indra/llui/lliconctrl.cpp @@ -112,6 +112,12 @@ void LLIconCtrl::draw() LLUICtrl::draw(); } +// virtual +void LLIconCtrl::setAlpha(F32 alpha) +{ + mColor.setAlpha(alpha); +} + // virtual void LLIconCtrl::setValue(const LLSD& value ) { diff --git a/linden/indra/llui/lliconctrl.h b/linden/indra/llui/lliconctrl.h index 50778cf..2506fb2 100644 --- a/linden/indra/llui/lliconctrl.h +++ b/linden/indra/llui/lliconctrl.h @@ -65,6 +65,8 @@ public: virtual void setValue(const LLSD& value ); virtual LLSD getValue() const; + /*virtual*/ void setAlpha(F32 alpha); + void setColor(const LLColor4& color) { mColor = color; } virtual LLXMLNodePtr getXML(bool save_children = true) const; diff --git a/linden/indra/llui/llmultisliderctrl.cpp b/linden/indra/llui/llmultisliderctrl.cpp index b76c2f6..f9ec6d5 100644 --- a/linden/indra/llui/llmultisliderctrl.cpp +++ b/linden/indra/llui/llmultisliderctrl.cpp @@ -34,9 +34,6 @@ #include "llmultisliderctrl.h" -#include "audioengine.h" -#include "sound_ids.h" - #include "llmath.h" #include "llfontgl.h" #include "llgl.h" diff --git a/linden/indra/llui/llpanel.cpp b/linden/indra/llui/llpanel.cpp index 709342b..26137d7 100644 --- a/linden/indra/llui/llpanel.cpp +++ b/linden/indra/llui/llpanel.cpp @@ -203,6 +203,12 @@ void LLPanel::draw() LLView::draw(); } +/*virtual*/ +void LLPanel::setAlpha(F32 alpha) +{ + mBgColorOpaque.setAlpha(alpha); +} + void LLPanel::updateDefaultBtn() { // This method does not call LLView::draw() so callers will need @@ -213,8 +219,7 @@ void LLPanel::updateDefaultBtn() { if (gFocusMgr.childHasKeyboardFocus( this ) && mDefaultBtn->getEnabled()) { - LLUICtrl* focus_ctrl = gFocusMgr.getKeyboardFocus(); - LLButton* buttonp = dynamic_cast(focus_ctrl); + LLButton* buttonp = dynamic_cast(gFocusMgr.getKeyboardFocus()); BOOL focus_is_child_button = buttonp && buttonp->getCommitOnReturn(); // only enable default button when current focus is not a return-capturing button mDefaultBtn->setBorderEnabled(!focus_is_child_button); @@ -276,7 +281,7 @@ BOOL LLPanel::handleKeyHere( KEY key, MASK mask ) { BOOL handled = FALSE; - LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus(); + LLUICtrl* cur_focus = dynamic_cast(gFocusMgr.getKeyboardFocus()); // handle user hitting ESC to defocus if (key == KEY_ESCAPE) @@ -800,6 +805,14 @@ void LLPanel::childSetColor(const std::string& id, const LLColor4& color) child->setColor(color); } } +void LLPanel::childSetAlpha(const std::string& id, F32 alpha) +{ + LLUICtrl* child = getChild(id, true); + if (child) + { + child->setAlpha(alpha); + } +} LLCtrlSelectionInterface* LLPanel::childGetSelectionInterface(const std::string& id) const { diff --git a/linden/indra/llui/llpanel.h b/linden/indra/llui/llpanel.h index 756d02e..378b357 100644 --- a/linden/indra/llui/llpanel.h +++ b/linden/indra/llui/llpanel.h @@ -82,6 +82,8 @@ public: // From LLFocusableElement /*virtual*/ void setFocus( BOOL b ); + virtual void setAlpha(F32 alpha); + // New virtuals virtual void refresh(); // called in setFocus() @@ -174,6 +176,7 @@ public: void childSetUserData(const std::string& id, void* userdata); void childSetColor(const std::string& id, const LLColor4& color); + void childSetAlpha(const std::string& id, F32 alpha); LLCtrlSelectionInterface* childGetSelectionInterface(const std::string& id) const; LLCtrlListInterface* childGetListInterface(const std::string& id) const; diff --git a/linden/indra/llui/llsliderctrl.cpp b/linden/indra/llui/llsliderctrl.cpp index 8a13ed4..51d43fb 100644 --- a/linden/indra/llui/llsliderctrl.cpp +++ b/linden/indra/llui/llsliderctrl.cpp @@ -34,8 +34,6 @@ #include "llsliderctrl.h" -#include "audioengine.h" - #include "llmath.h" #include "llfontgl.h" #include "llgl.h" diff --git a/linden/indra/llui/llspinctrl.cpp b/linden/indra/llui/llspinctrl.cpp index 7eccaca..e66b20e 100644 --- a/linden/indra/llui/llspinctrl.cpp +++ b/linden/indra/llui/llspinctrl.cpp @@ -45,7 +45,6 @@ #include "lltextbox.h" #include "llkeyboard.h" #include "llmath.h" -#include "audioengine.h" #include "llcontrol.h" #include "llfocusmgr.h" #include "llresmgr.h" diff --git a/linden/indra/llui/lltextparser.cpp b/linden/indra/llui/lltextparser.cpp index 925b118..707dd0a 100644 --- a/linden/indra/llui/lltextparser.cpp +++ b/linden/indra/llui/lltextparser.cpp @@ -1,6 +1,5 @@ /** - * @file lltexteditor.cpp - * @brief LLTextEditor base class + * @file lltextparser.cpp * * $LicenseInfo:firstyear=2001&license=viewergpl$ * @@ -32,6 +31,8 @@ #include "linden_common.h" +#include "lltextparser.h" + #include "llsd.h" #include "llsdserialize.h" #include "llerror.h" @@ -40,23 +41,13 @@ #include "message.h" #include "llmath.h" #include "v4color.h" -#include "audioengine.h" -#include "llwindow.h" #include "lldir.h" -#include "lltextparser.h" -//#include "lltexttospeech.h" - // Routines used for parsing text for TextParsers and html LLTextParser* LLTextParser::sInstance = NULL; // -// Constants -// -const F32 SOUND_GAIN = 1.0f; - -// // Member Functions // @@ -76,38 +67,7 @@ LLTextParser* LLTextParser::getInstance() return sInstance; } -void LLTextParser::triggerAlerts(LLUUID agent_id, LLVector3d position, std::string text, LLWindow* viewer_window) -{ -// bool spoken=FALSE; - for (S32 i=0;i= 0 ) - { - if(gAudiop) - { - if ((std::string)mHighlights[i]["sound_lluuid"] != LLUUID::null.asString()) - { - gAudiop->triggerSound(mHighlights[i]["sound_lluuid"].asUUID(), agent_id, SOUND_GAIN, LLAudioEngine::AUDIO_TYPE_UI, position); - } -/* - if (!spoken) - { - LLTextToSpeech* text_to_speech = NULL; - text_to_speech = LLTextToSpeech::getInstance(); - spoken = text_to_speech->speak((LLString)mHighlights[i]["voice"],text); - } - */ - } - if (mHighlights[i]["flash"]) - { - if (viewer_window && viewer_window->getMinimized()) - { - viewer_window->flashIcon(5.f); - } - } - } - } -} +// Moved triggerAlerts() to llfloaterchat.cpp to break llui/llaudio library dependency. S32 LLTextParser::findPattern(const std::string &text, LLSD highlight) { diff --git a/linden/indra/llui/lltextparser.h b/linden/indra/llui/lltextparser.h index d69e3a2..32343a2 100644 --- a/linden/indra/llui/lltextparser.h +++ b/linden/indra/llui/lltextparser.h @@ -34,12 +34,8 @@ #ifndef LL_LLTEXTPARSER_H #define LL_LLTEXTPARSER_H -#include -#include "linden_common.h" +#include "llsd.h" -#include "lltextparser.h" - -class LLSD; class LLUUID; class LLVector3d; class LLColor4; @@ -59,7 +55,6 @@ public: S32 findPattern(const std::string &text, LLSD highlight); LLSD parsePartialLineHighlights(const std::string &text,const LLColor4 &color,S32 part=WHOLE, S32 index=0); bool parseFullLineHighlights(const std::string &text, LLColor4 *color); - void triggerAlerts(LLUUID agent_id, LLVector3d position, std::string text, LLWindow* viewer_window); std::string getFileName(); LLSD loadFromDisk(); diff --git a/linden/indra/llui/llui.cpp b/linden/indra/llui/llui.cpp index 57ce13c..75a4467 100644 --- a/linden/indra/llui/llui.cpp +++ b/linden/indra/llui/llui.cpp @@ -38,7 +38,6 @@ #include // Linden library includes -#include "audioengine.h" #include "v2math.h" #include "v4color.h" #include "llrender.h" diff --git a/linden/indra/llui/lluictrl.cpp b/linden/indra/llui/lluictrl.cpp index 9d97312..3f4ab5e 100644 --- a/linden/indra/llui/lluictrl.cpp +++ b/linden/indra/llui/lluictrl.cpp @@ -39,54 +39,7 @@ static LLRegisterWidget r("ui_ctrl"); -LLFocusableElement::LLFocusableElement() -: mFocusLostCallback(NULL), - mFocusReceivedCallback(NULL), - mFocusChangedCallback(NULL), - mFocusCallbackUserData(NULL) -{ -} - -//virtual -LLFocusableElement::~LLFocusableElement() -{ -} - -void LLFocusableElement::onFocusReceived() -{ - if( mFocusReceivedCallback ) - { - mFocusReceivedCallback( this, mFocusCallbackUserData ); - } - if( mFocusChangedCallback ) - { - mFocusChangedCallback( this, mFocusCallbackUserData ); - } -} - -void LLFocusableElement::onFocusLost() -{ - if( mFocusLostCallback ) - { - mFocusLostCallback( this, mFocusCallbackUserData ); - } - - if( mFocusChangedCallback ) - { - mFocusChangedCallback( this, mFocusCallbackUserData ); - } -} - -BOOL LLFocusableElement::hasFocus() const -{ - return FALSE; -} - -void LLFocusableElement::setFocus(BOOL b) -{ -} - - +// NOTE: the LLFocusableElement implementation has been moved to llfocusmgr.cpp, to mirror the header where the class is defined. LLUICtrl::LLUICtrl() : mCommitCallback(NULL), @@ -212,7 +165,7 @@ void LLUICtrl::onFocusReceived() // find first view in hierarchy above new focus that is a LLUICtrl LLView* viewp = getParent(); - LLUICtrl* last_focus = gFocusMgr.getLastKeyboardFocus(); + LLUICtrl* last_focus = dynamic_cast(gFocusMgr.getLastKeyboardFocus()); while (viewp && !viewp->isCtrl()) { @@ -590,6 +543,10 @@ void LLUICtrl::setDoubleClickCallback( void (*cb)(void*) ) // virtual void LLUICtrl::setColor(const LLColor4& color) { } +// virtual + +void LLUICtrl::setAlpha(F32 alpha) +{ } // virtual void LLUICtrl::setMinValue(LLSD min_value) diff --git a/linden/indra/llui/lluictrl.h b/linden/indra/llui/lluictrl.h index db41af8..be8e863 100644 --- a/linden/indra/llui/lluictrl.h +++ b/linden/indra/llui/lluictrl.h @@ -39,31 +39,8 @@ #include "llsd.h" -class LLFocusableElement -{ - friend class LLFocusMgr; // allow access to focus change handlers -public: - LLFocusableElement(); - virtual ~LLFocusableElement(); - - virtual void setFocus( BOOL b ); - virtual BOOL hasFocus() const; - - void setFocusLostCallback(void (*cb)(LLFocusableElement* caller, void*), void* user_data = NULL) { mFocusLostCallback = cb; mFocusCallbackUserData = user_data; } - void setFocusReceivedCallback( void (*cb)(LLFocusableElement*, void*), void* user_data = NULL) { mFocusReceivedCallback = cb; mFocusCallbackUserData = user_data; } - void setFocusChangedCallback( void (*cb)(LLFocusableElement*, void*), void* user_data = NULL ) { mFocusChangedCallback = cb; mFocusCallbackUserData = user_data; } - -protected: - virtual void onFocusReceived(); - virtual void onFocusLost(); - void (*mFocusLostCallback)( LLFocusableElement* caller, void* userdata ); - void (*mFocusReceivedCallback)( LLFocusableElement* ctrl, void* userdata ); - void (*mFocusChangedCallback)( LLFocusableElement* ctrl, void* userdata ); - void* mFocusCallbackUserData; -}; - class LLUICtrl -: public LLView, public LLFocusableElement +: public LLView { public: typedef void (*LLUICtrlCallback)(LLUICtrl* ctrl, void* userdata); @@ -117,6 +94,7 @@ public: virtual void clear(); virtual void setDoubleClickCallback( void (*cb)(void*) ); virtual void setColor(const LLColor4& color); + virtual void setAlpha(F32 alpha); virtual void setMinValue(LLSD min_value); virtual void setMaxValue(LLSD max_value); diff --git a/linden/indra/llui/llview.cpp b/linden/indra/llui/llview.cpp index 8de376f..1f76696 100644 --- a/linden/indra/llui/llview.cpp +++ b/linden/indra/llui/llview.cpp @@ -136,11 +136,6 @@ LLView::~LLView() { //llinfos << "Deleting view " << mName << ":" << (void*) this << llendl; // llassert(LLView::sIsDrawing == FALSE); - if( gFocusMgr.getKeyboardFocus() == this ) - { - llwarns << "View holding keyboard focus deleted: " << getName() << ". Keyboard focus removed." << llendl; - gFocusMgr.removeKeyboardFocusWithoutCallback( this ); - } if( hasMouseCapture() ) { @@ -1327,7 +1322,7 @@ void LLView::draw() LLRect screenRect; // draw focused control on top of everything else - LLView* focus_view = gFocusMgr.getKeyboardFocus(); + LLUICtrl* focus_view = dynamic_cast(gFocusMgr.getKeyboardFocus()); if (focus_view && focus_view->getParent() != this) { focus_view = NULL; diff --git a/linden/indra/llui/llview.h b/linden/indra/llui/llview.h index 7e09dfa..1c8ab31 100644 --- a/linden/indra/llui/llview.h +++ b/linden/indra/llui/llview.h @@ -53,6 +53,7 @@ #include "stdenums.h" #include "lluistring.h" #include "llcursortypes.h" +#include "llfocusmgr.h" const U32 FOLLOWS_NONE = 0x00; const U32 FOLLOWS_LEFT = 0x01; @@ -207,7 +208,7 @@ public: } }; -class LLView : public LLMouseHandler, public LLMortician +class LLView : public LLMouseHandler, public LLMortician, public LLFocusableElement { public: @@ -398,9 +399,11 @@ public: virtual BOOL canSnapTo(const LLView* other_view); virtual void snappedTo(const LLView* snap_view); + + // inherited from LLFocusableElement + /* virtual */ BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent); + /* virtual */ BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent); - virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent); - virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent); virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void* cargo_data, @@ -421,8 +424,9 @@ public: BOOL getSaveToXML() const { return mSaveToXML; } void setSaveToXML(BOOL b) { mSaveToXML = b; } - virtual void onFocusLost(); - virtual void onFocusReceived(); + // inherited from LLFocusableElement + /* virtual */ void onFocusLost(); + /* virtual */ void onFocusReceived(); typedef enum e_hit_test_type { -- cgit v1.1 From cd097fee7848f2e78c0865d0fad7d510a661aa20 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Thu, 23 Sep 2010 19:39:56 +0200 Subject: Fix LLTextEditor context menu translator returning "()" when nothing is selected. New behavior is to translate the word under the mouse if nothing is selected. --- linden/indra/llui/lltexteditor.cpp | 83 +++++++++++++++++++++++++++++++++----- linden/indra/llui/lltexteditor.h | 4 ++ 2 files changed, 77 insertions(+), 10 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index b101588..4bae155 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -105,21 +105,23 @@ bool (* LLTextEditor::mSecondlifeURLcallbackRightClick)(const std::string&) = class TextChatTranslationReceiver : public LLTranslate::TranslationReceiver { public : - TextChatTranslationReceiver(const std::string &toLang, LLTextEditor* line): LLTranslate::TranslationReceiver("", toLang), - m_line(line) + TextChatTranslationReceiver(const std::string &toLang, LLTextEditor* line, const S32 start, const S32 len): + LLTranslate::TranslationReceiver("", toLang), + m_line(line), + m_position(start), + m_origLength(len) { } - static boost::intrusive_ptr build(const std::string &toLang,LLTextEditor* line) + static boost::intrusive_ptr build(const std::string &toLang,LLTextEditor* line, const S32 start, const S32 len) { - return boost::intrusive_ptr(new TextChatTranslationReceiver(toLang,line)); + return boost::intrusive_ptr(new TextChatTranslationReceiver(toLang, line, start, len)); } protected: void handleResponse(const std::string &translation, const std::string &detectedLanguage) { - BOOL rep = gSavedSettings.getBOOL("EmeraldTranslateReplace"); - m_line->insertText((rep?"":" (") + translation +(rep?"":")"),rep); + m_line->translationReplace(translation, m_position, m_origLength); } void handleFailure() { @@ -127,6 +129,8 @@ protected: } private: LLTextEditor* m_line; + S32 m_position; + S32 m_origLength; }; /////////////////////////////////////////////////////////////////// @@ -321,6 +325,8 @@ LLTextEditor::LLTextEditor( mMouseDownY(0), mLastSelectionX(-1), mLastSelectionY(-1), + mLastContextMenuX(-1), + mLastContextMenuY(-1), mReflowNeeded(FALSE), mScrollNeeded(FALSE), mSpellCheckable(FALSE), @@ -467,17 +473,36 @@ void LLTextEditor::context_copy(void* data) LLTextEditor* line = (LLTextEditor*)data; if(line)line->copy(); } + void LLTextEditor::translateText(void * data) { SpellMenuBind* t = (SpellMenuBind*)data; LLTextEditor* line = t->origin; const std::string &toLang = t->word;//LLTranslate::getTranslateLanguage(); - LLHTTPClient::ResponderPtr result = TextChatTranslationReceiver::build(toLang,line); - S32 left_pos = llmin( line->mSelectionStart, line->mSelectionEnd ); - S32 length = abs( line->mSelectionStart - line->mSelectionEnd ); - LLTranslate::translateMessage(result,"", toLang, line->getText().substr(left_pos, length)); + bool has_text = false; + S32 start, length; + if (line->hasSelection()) + { + // translate selection + start = llmin(line->mSelectionStart, line->mSelectionEnd); + length = abs(line->mSelectionEnd - line->mSelectionStart); + has_text = length > 0; + } + else + { + // translate one word as click position + S32 at = line->getCursorPosFromLocalCoord(line->mLastContextMenuX, line->mLastContextMenuY, TRUE); + has_text = line->getWordBoundriesAt(at, &start, &length); + } + + if (has_text) + { + LLHTTPClient::ResponderPtr result = TextChatTranslationReceiver::build(toLang, line, start, length); + LLTranslate::translateMessage(result,"", toLang, line->getText().substr(start, length)); + } } + void LLTextEditor::spell_correct(void* data) { SpellMenuBind* tempBind = (SpellMenuBind*)data; @@ -947,6 +972,26 @@ S32 LLTextEditor::nextWordPos(S32 cursorPos) const return cursorPos; } +BOOL LLTextEditor::getWordBoundriesAt(const S32 at, S32* word_begin, S32* word_length) const +{ + S32 pos = at; + if (isPartOfWord(mWText[pos])) + { + while ( (pos > 0) && isPartOfWord(mWText[pos - 1]) ) + { + pos--; + } + *word_begin = pos; + while ( (pos < getLength()) && isPartOfWord(mWText[pos]) ) + { + pos++; + } + *word_length = pos - *word_begin; + return TRUE; + } + return FALSE; +} + S32 LLTextEditor::getLineStart( S32 line ) const { S32 num_lines = getLineCount(); @@ -1531,6 +1576,8 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) suggestionMenuItems.push_back(tempStruct); menu->append(suggMenuItem); } + mLastContextMenuX = x; + mLastContextMenuY = y; menu->buildDrawLabels(); menu->updateParent(LLMenuGL::sMenuContainer); LLMenuGL::showPopup(this, menu, x, y); @@ -2238,6 +2285,22 @@ void LLTextEditor::spellReplace(SpellMenuBind* spellData) needsReflow(); } +void LLTextEditor::translationReplace(const std::string &translation, const S32 orig_start, const S32 orig_length) +{ + //*TODO: should probably check if the content was modified since the http query + // was made, so we don't insert text in the wrong place. + BOOL replace = gSavedSettings.getBOOL("EmeraldTranslateReplace"); + LLWString wtext = utf8str_to_wstring(replace ? translation : " (" + translation + ")"); + S32 pos = replace ? orig_start : orig_start + orig_length; + if (replace) + { + remove(orig_start, orig_length, FALSE); + } + insert(pos, wtext, FALSE); + setCursorPos(pos + wtext.length()); + needsReflow(); +} + // paste from clipboard void LLTextEditor::paste() { diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index 57a6bbd..f6669c4 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -136,6 +136,7 @@ public: virtual BOOL canPaste() const; virtual void spellReplace(SpellMenuBind* spellData); + virtual void translationReplace(const std::string &translation, const S32 orig_start, const S32 orig_length); virtual void updatePrimary(); virtual void copyPrimary(); @@ -352,6 +353,7 @@ public: S32 prevWordPos(S32 cursorPos) const; S32 nextWordPos(S32 cursorPos) const; + BOOL getWordBoundriesAt(const S32 at, S32* word_begin, S32* word_length) const; S32 getLineCount() const { return mLineStartList.size(); } S32 getLineStart( S32 line ) const; @@ -568,6 +570,8 @@ private: //to keep track of what we have to remove before showing menu std::vector suggestionMenuItems; + S32 mLastContextMenuX; + S32 mLastContextMenuY; line_list_t mLineStartList; BOOL mReflowNeeded; -- cgit v1.1 From f6f5603b946a56059987071b7151a1c2e64c45d5 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Fri, 24 Sep 2010 02:29:58 +0200 Subject: Fix LLLineEditor context menu translator returning "()" when nothing is selected. New behavior is to translate the word under the mouse if nothing is selected. --- linden/indra/llui/lllineeditor.cpp | 90 +++++++++++++++++++++++++++++++++----- linden/indra/llui/lllineeditor.h | 3 ++ 2 files changed, 81 insertions(+), 12 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 66ef4c6..27a1d50 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -96,23 +96,23 @@ static LLRegisterWidget r1("line_editor"); class LineChatTranslationReceiver : public LLTranslate::TranslationReceiver { public : - LineChatTranslationReceiver(const std::string &toLang, LLLineEditor* line): LLTranslate::TranslationReceiver("", toLang), - m_line(line) + LineChatTranslationReceiver(const std::string &toLang, LLLineEditor* line, const S32 start, const S32 len): + LLTranslate::TranslationReceiver("", toLang), + m_line(line), + m_position(start), + m_origLength(len) { } - static boost::intrusive_ptr build(const std::string &toLang,LLLineEditor* line) + static boost::intrusive_ptr build(const std::string &toLang,LLLineEditor* line, const S32 start, const S32 len) { - return boost::intrusive_ptr(new LineChatTranslationReceiver(toLang,line)); + return boost::intrusive_ptr(new LineChatTranslationReceiver(toLang, line, start, len)); } protected: void handleResponse(const std::string &translation, const std::string &detectedLanguage) { - static BOOL* rep = rebind_llcontrol("EmeraldTranslateReplace", &gSavedSettings, true); - if(*rep) - m_line->deleteSelection(); - m_line->insert(((*rep)?"":" (") + translation + ((*rep)?"":")"),m_line->getCursor()); + m_line->translationReplace(translation, m_position, m_origLength); } void handleFailure() { @@ -120,6 +120,8 @@ protected: } private: LLLineEditor* m_line; + S32 m_position; + S32 m_origLength; }; LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, @@ -151,6 +153,7 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mLastSelectionY(-1), mLastSelectionStart(-1), mLastSelectionEnd(-1), + mLastContextMenuX(-1), mPrevalidateFunc( prevalidate_func ), mCursorColor( LLUI::sColorsGroup->getColor( "TextCursorColor" ) ), mFgColor( LLUI::sColorsGroup->getColor( "TextFgColor" ) ), @@ -539,16 +542,36 @@ void LLLineEditor::spell_correct(void* data) } } + void LLLineEditor::translateText(void * data) { SpellMenuBind* t = (SpellMenuBind*)data; LLLineEditor* line = t->origin; const std::string &toLang = t->word;//LLTranslate::getTranslateLanguage(); - LLHTTPClient::ResponderPtr result = LineChatTranslationReceiver::build(toLang,line); - S32 left_pos = llmin( line->mSelectionStart, line->mSelectionEnd ); - S32 length = abs( line->mSelectionStart - line->mSelectionEnd ); - LLTranslate::translateMessage(result,"", toLang, line->mText.getString().substr(left_pos, length)); + + bool has_text = false; + S32 start, length; + if (line->hasSelection()) + { + // translate selection + start = llmin(line->mSelectionStart, line->mSelectionEnd); + length = abs(line->mSelectionEnd - line->mSelectionStart); + has_text = length > 0; + } + else + { + // translate one word at click position + S32 at = line->calculateCursorFromMouse(line->mLastContextMenuX); + has_text = line->getWordBoundriesAt(at, &start, &length); + } + + if (has_text) + { + LLHTTPClient::ResponderPtr result = LineChatTranslationReceiver::build(toLang, line, start, length); + LLTranslate::translateMessage(result,"", toLang, line->getText().substr(start, length)); + } } + void LLLineEditor::spell_show(void * data) { SpellMenuBind* tempBind = (SpellMenuBind*)data; @@ -836,6 +859,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) menu->append(suggMenuItem); } + mLastContextMenuX = x; menu->buildDrawLabels(); menu->updateParent(LLMenuGL::sMenuContainer); LLMenuGL::showPopup(this, menu, x, y); @@ -1152,6 +1176,26 @@ S32 LLLineEditor::nextWordPos(S32 cursorPos) const return cursorPos; } +BOOL LLLineEditor::getWordBoundriesAt(const S32 at, S32* word_begin, S32* word_length) const +{ + const LLWString& wtext = mText.getWString(); + S32 pos = at; + if (LLTextEditor::isPartOfWord(wtext[pos])) + { + while ( (pos > 0) && LLTextEditor::isPartOfWord(wtext[pos - 1]) ) + { + pos--; + } + *word_begin = pos; + while ( (pos < getLength()) && LLTextEditor::isPartOfWord(wtext[pos]) ) + { + pos++; + } + *word_length = pos - *word_begin; + return TRUE; + } + return FALSE; +} BOOL LLLineEditor::handleSelectionKey(KEY key, MASK mask) { @@ -1315,6 +1359,28 @@ void LLLineEditor::spellReplace(SpellMenuBind* spellData) } + +void LLLineEditor::translationReplace(const std::string &translation, const S32 orig_start, const S32 orig_length) +{ + //*TODO: should probably check if the content was modified since the http query + // was made, so we don't insert text in the wrong place. + BOOL replace = gSavedSettings.getBOOL("EmeraldTranslateReplace"); + std::string text = replace ? translation : " (" + translation + ")"; + S32 pos = replace ? orig_start : orig_start + orig_length; + if (replace) + { + mText.erase(orig_start, orig_length); + } + insert(text, pos); + + if (hasSelection()) + { + mSelectionStart = pos; + mSelectionEnd = pos + text.length(); + } + setCursor(pos + text.length()); +} + void LLLineEditor::insert(std::string what, S32 wher) { LLLineEditorRollback rollback(this); diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 147b232..af37f62 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -107,6 +107,7 @@ public: }; virtual void spellReplace(SpellMenuBind* spellData); + virtual void translationReplace(const std::string &translation, const S32 orig_start, const S32 orig_length); virtual void insert(std::string what,S32 wher); // LLEditMenuHandler overrides @@ -215,6 +216,7 @@ public: // get the cursor position of the beginning/end of the prev/next word in the text S32 prevWordPos(S32 cursorPos) const; S32 nextWordPos(S32 cursorPos) const; + BOOL getWordBoundriesAt(const S32 at, S32* word_begin, S32* word_length) const; BOOL hasSelection() const { return (mSelectionStart != mSelectionEnd); } void startSelection(); @@ -298,6 +300,7 @@ protected: LLFrameTimer mSpellTimer; //to keep track of what we have to remove before showing menu std::vector suggestionMenuItems; + S32 mLastContextMenuX; // line history support: BOOL mHaveHistory; // flag for enabled line history -- cgit v1.1 From 6cd906519bf090dff532b3cf4d206fd1a25c6504 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Sat, 25 Sep 2010 01:14:51 +0200 Subject: More LLLineEditor context translator bugfixes: - Use LLWString when doing size calculations (potential crashes and misplaced text) - Weird selection range after translating selected text. --- linden/indra/llui/lllineeditor.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 27a1d50..5f2a314 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -567,8 +567,9 @@ void LLLineEditor::translateText(void * data) if (has_text) { + std::string to_translate = wstring_to_utf8str(line->getWText().substr(start, length)); LLHTTPClient::ResponderPtr result = LineChatTranslationReceiver::build(toLang, line, start, length); - LLTranslate::translateMessage(result,"", toLang, line->getText().substr(start, length)); + LLTranslate::translateMessage(result,"", toLang, to_translate); } } @@ -1133,13 +1134,11 @@ void LLLineEditor::setSelection(S32 start, S32 end) { S32 len = mText.length(); - mIsSelecting = TRUE; - // JC, yes, this seems odd, but I think you have to presume a // selection dragged from the end towards the start. mSelectionStart = llclamp(end, 0, len); mSelectionEnd = llclamp(start, 0, len); - setCursor(start); + setCursor(end); } void LLLineEditor::setDrawAsterixes(BOOL b) @@ -1187,7 +1186,7 @@ BOOL LLLineEditor::getWordBoundriesAt(const S32 at, S32* word_begin, S32* word_l pos--; } *word_begin = pos; - while ( (pos < getLength()) && LLTextEditor::isPartOfWord(wtext[pos]) ) + while ( (pos < wtext.length()) && LLTextEditor::isPartOfWord(wtext[pos]) ) { pos++; } @@ -1373,12 +1372,12 @@ void LLLineEditor::translationReplace(const std::string &translation, const S32 } insert(text, pos); + S32 text_wlen = utf8str_to_wstring(text).length(); if (hasSelection()) { - mSelectionStart = pos; - mSelectionEnd = pos + text.length(); + setSelection(pos, pos + text_wlen); } - setCursor(pos + text.length()); + setCursor(pos + text_wlen); } void LLLineEditor::insert(std::string what, S32 wher) -- cgit v1.1 From 8f30fb06d1361d7d74f018d5bbaf5e82b846d8a4 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Sat, 25 Sep 2010 04:04:26 +0200 Subject: LLLineEditor context translator: re-select text properly. --- linden/indra/llui/lllineeditor.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 5f2a314..503a1bd 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -1134,10 +1134,8 @@ void LLLineEditor::setSelection(S32 start, S32 end) { S32 len = mText.length(); - // JC, yes, this seems odd, but I think you have to presume a - // selection dragged from the end towards the start. - mSelectionStart = llclamp(end, 0, len); - mSelectionEnd = llclamp(start, 0, len); + mSelectionStart = llclamp(start, 0, len); + mSelectionEnd = llclamp(end, 0, len); setCursor(end); } -- cgit v1.1 From f5006e8a2f34afa390f0bbcf0f6af15218cf4105 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Sat, 25 Sep 2010 12:58:56 +0200 Subject: LLLineEditor context translator: - Added a xui attribute "allow_translate", default to off (not enabled in any xml file yet.) - Only show translate menu if clicked on a word, or something is selected. --- linden/indra/llui/lllineeditor.cpp | 35 ++++++++++++++++------------------- linden/indra/llui/lllineeditor.h | 2 ++ 2 files changed, 18 insertions(+), 19 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 503a1bd..05966d6 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -175,7 +175,8 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mImage( sImage ), mReplaceNewlinesWithSpaces( TRUE ), mSpellCheckable( FALSE ), - mShowMisspellings(FALSE) + mShowMisspellings(FALSE), + mAllowTranslate(FALSE) { llassert( max_length_bytes > 0 ); @@ -762,7 +763,8 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) //setCursorAtLocalPos( x); S32 wordStart = 0; - S32 wordEnd = calculateCursorFromMouse(x); + S32 wordEnd = 0; + S32 pos = calculateCursorFromMouse(x); LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); if (menu) @@ -785,29 +787,19 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - menu->setItemVisible("Translate To", !mReadOnly); - menu->setItemVisible("Transep", !mReadOnly); + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); + // allow_translate="true" in xui + bool can_translate = mAllowTranslate && !mReadOnly && (is_word_part || hasSelection()); + menu->setItemVisible("Translate To", can_translate); + menu->setItemVisible("Transep", can_translate); // spell_check="true" in xui if (!mReadOnly && mSpellCheckable) { - const LLWString& text = mText.getWString(); - // search for word matches - if (LLTextEditor::isPartOfWord(text[wordEnd])) + if (is_word_part) { - // Select word the cursor is over - while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) - { - wordEnd--; - } - wordStart = wordEnd; - //startSelection(); - - while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) - { - wordEnd++; - } + const LLWString& text = mText.getWString(); std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); if (!glggHunSpell->isSpelledRight(selectedWord)) @@ -2893,6 +2885,11 @@ LLView* LLLineEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory { line_editor->setSpellCheckable(spell_checking); } + BOOL allow_translate = FALSE; + if (node->getAttributeBOOL("allow_translate", allow_translate)) + { + line_editor->setAllowTranslate(allow_translate); + } line_editor->setColorParameters(node); diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index af37f62..0ad415a 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -200,6 +200,7 @@ public: void setReadOnlyBgColor( const LLColor4& c ) { mReadOnlyBgColor = c; } void setFocusBgColor(const LLColor4& c) { mFocusBgColor = c; } void setSpellCheckable(BOOL b) { mSpellCheckable = b; } + void setAllowTranslate(BOOL b) { mAllowTranslate = b; } const LLColor4& getFgColor() const { return mFgColor; } const LLColor4& getReadOnlyFgColor() const { return mReadOnlyFgColor; } @@ -301,6 +302,7 @@ protected: //to keep track of what we have to remove before showing menu std::vector suggestionMenuItems; S32 mLastContextMenuX; + BOOL mAllowTranslate; // set in xui as "allow_translate". // line history support: BOOL mHaveHistory; // flag for enabled line history -- cgit v1.1 From 81a3df503aece6b46e1efbdb7e274253cb898660 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Sat, 25 Sep 2010 15:00:50 +0200 Subject: LLTextEditor context translator: - Added a xui attribute "allow_translate", default to off (not enabled in any xml file yet.) - Only show translate menu if clicked on a word, or something is selected. --- linden/indra/llui/lltexteditor.cpp | 34 +++++++++++++++------------------- linden/indra/llui/lltexteditor.h | 1 + 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 4bae155..adf0260 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -330,7 +330,8 @@ LLTextEditor::LLTextEditor( mReflowNeeded(FALSE), mScrollNeeded(FALSE), mSpellCheckable(FALSE), - mShowMisspellings(FALSE) + mShowMisspellings(FALSE), + mAllowTranslate(FALSE) { mSourceID.generate(); @@ -1484,7 +1485,8 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) //setCursorAtLocalPos( x, y, TRUE ); S32 wordStart = 0; - S32 wordEnd = getCursorPosFromLocalCoord(x,y,TRUE); + S32 wordEnd = 0; + S32 pos = getCursorPosFromLocalCoord(x,y,TRUE); LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); if (menu) @@ -1503,29 +1505,21 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - menu->setItemVisible("Translate To", !mReadOnly); - menu->setItemVisible("Transep", !mReadOnly); + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); + + // allow_translate="true" in xui + bool can_translate = mAllowTranslate && !mReadOnly && (is_word_part || hasSelection()); + menu->setItemVisible("Translate To", can_translate); + menu->setItemVisible("Transep", can_translate); // spell_check="true" in xui if (!mReadOnly && mSpellCheckable) { - const LLWString &text = mWText; - - if (isPartOfWord(text[wordEnd]) && !mReadOnly) + if (is_word_part) { - // Select word the cursor is over - while ((wordEnd > 0) && isPartOfWord(text[wordEnd-1])) - { - wordEnd--; - } - wordStart = wordEnd; - //startSelection(); - - while ((wordEnd < (S32)text.length()) && isPartOfWord( text[wordEnd] ) ) - { - wordEnd++; - } + const LLWString &text = mWText; std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); + if (!glggHunSpell->isSpelledRight(selectedWord)) { //misspelled word here, and you have just right clicked on it! @@ -4964,6 +4958,8 @@ void LLTextEditor::setTextEditorParameters(LLXMLNodePtr node) node->getAttributeBOOL("spell_check", mSpellCheckable); + node->getAttributeBOOL("allow_translate", mAllowTranslate); + LLColor4 color; if (LLUICtrlFactory::getAttributeColor(node,"cursor_color", color)) { diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index f6669c4..3269e17 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -530,6 +530,7 @@ private: std::vector misspellLocations; // where all the mispelled words are BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field BOOL mShowMisspellings; // show misspellings as highlighted (initialized in the ctor) + BOOL mAllowTranslate; // set in xui as "allow_translate". S32 mMaxTextByteLength; // Maximum length mText is allowed to be in bytes -- cgit v1.1 From 2760d30363716b8d469134d197a9874eccea6aa3 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Sat, 25 Sep 2010 16:14:11 +0200 Subject: LLTextEditor context translator: set selection after translation. --- linden/indra/llui/lltexteditor.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index adf0260..d59eed6 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -499,8 +499,9 @@ void LLTextEditor::translateText(void * data) if (has_text) { + const std::string to_translate = wstring_to_utf8str(line->getWText().substr(start, length)); LLHTTPClient::ResponderPtr result = TextChatTranslationReceiver::build(toLang, line, start, length); - LLTranslate::translateMessage(result,"", toLang, line->getText().substr(start, length)); + LLTranslate::translateMessage(result,"", toLang, to_translate); } } @@ -2290,8 +2291,13 @@ void LLTextEditor::translationReplace(const std::string &translation, const S32 { remove(orig_start, orig_length, FALSE); } - insert(pos, wtext, FALSE); - setCursorPos(pos + wtext.length()); + S32 inserted = insert(pos, wtext, FALSE); + if (hasSelection()) + { + mSelectionStart = llclamp(pos, 0, getLength()); + mSelectionEnd = llclamp(pos + inserted, mSelectionStart, getLength()); + } + setCursorPos(pos + inserted); needsReflow(); } -- cgit v1.1 From 702b44426e036495c5568e7422e8cd77a46f1966 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Sat, 25 Sep 2010 16:18:20 +0200 Subject: Context translator: default to enabled. Set the default of the xui attribute "allow_translate" to true, and add allow_translate="false" to panel_login.xml. This probably needs to be disabled in other places as well. --- linden/indra/llui/lllineeditor.cpp | 4 ++-- linden/indra/llui/lltexteditor.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 05966d6..8d88ce9 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -176,7 +176,7 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mReplaceNewlinesWithSpaces( TRUE ), mSpellCheckable( FALSE ), mShowMisspellings(FALSE), - mAllowTranslate(FALSE) + mAllowTranslate(TRUE) { llassert( max_length_bytes > 0 ); @@ -2885,7 +2885,7 @@ LLView* LLLineEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory { line_editor->setSpellCheckable(spell_checking); } - BOOL allow_translate = FALSE; + BOOL allow_translate = TRUE; if (node->getAttributeBOOL("allow_translate", allow_translate)) { line_editor->setAllowTranslate(allow_translate); diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index d59eed6..5ee94c8 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -331,7 +331,7 @@ LLTextEditor::LLTextEditor( mScrollNeeded(FALSE), mSpellCheckable(FALSE), mShowMisspellings(FALSE), - mAllowTranslate(FALSE) + mAllowTranslate(TRUE) { mSourceID.generate(); -- cgit v1.1 From 4e943ed4f4e48012c37d81e4d734056c22017878 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Sat, 25 Sep 2010 17:14:07 +0200 Subject: Fixed typo causing menu seperator to not hide. --- linden/indra/llui/lltexteditor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 5ee94c8..e2335c9 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -402,7 +402,7 @@ LLTextEditor::LLTextEditor( menu->append(new LLMenuItemCallGL("Paste", context_paste, NULL, this)); menu->append(new LLMenuItemCallGL("Delete", context_delete, NULL, this)); menu->append(new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); - menu->appendSeparator("transep"); + menu->appendSeparator("Transep"); LLMenuGL* translatemenu = new LLMenuGL("Translate To"); translatemenu->setCanTearOff(FALSE); SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; -- cgit v1.1 From 13b1fd24af265af8eb14585121958bf1e4bc89fd Mon Sep 17 00:00:00 2001 From: thickbrick Date: Tue, 28 Sep 2010 18:06:43 +0200 Subject: Context menu translator: - Don't hide the translate menu, instead only enable the options that make sense in the context (translate languages, copy/paste/etc.) - Made highlighting misspellings a global option, with immediate effect. - Convert newview/lgghunspell_wrapper.cpp to UTF-8. --- linden/indra/llui/lllineeditor.cpp | 127 +++++++++++++++++++++++-------------- linden/indra/llui/lllineeditor.h | 19 ++++-- linden/indra/llui/lltexteditor.cpp | 125 ++++++++++++++++++++++-------------- linden/indra/llui/lltexteditor.h | 12 +++- 4 files changed, 178 insertions(+), 105 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 8d88ce9..49fe3be 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -175,7 +175,6 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mImage( sImage ), mReplaceNewlinesWithSpaces( TRUE ), mSpellCheckable( FALSE ), - mShowMisspellings(FALSE), mAllowTranslate(TRUE) { llassert( max_length_bytes > 0 ); @@ -215,12 +214,6 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, } mImage = sImage; - // in other words, highlighting requires a restart - if (glggHunSpell->getSpellCheckHighlight()) - { - mShowMisspellings = TRUE; - } - // make the popup menu available //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); LLMenuGL* menu = new LLMenuGL("wot"); @@ -228,46 +221,49 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, { menu = new LLMenuGL(LLStringUtil::null); }*/ - menu->append(new LLMenuItemCallGL("Cut", context_cut, NULL, this)); - menu->append(new LLMenuItemCallGL("Copy", context_copy, NULL, this)); - menu->append(new LLMenuItemCallGL("Paste", context_paste, NULL, this)); - menu->append(new LLMenuItemCallGL("Delete", context_delete, NULL, this)); - menu->append(new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + + menu->append(new LLMenuItemCallGL("Cut", context_cut, context_enable_cut, this)); + menu->append(new LLMenuItemCallGL("Copy", context_copy, context_enable_copy, this)); + menu->append(new LLMenuItemCallGL("Paste", context_paste, context_enable_paste, this)); + menu->append(new LLMenuItemCallGL("Delete", context_delete, context_enable_delete, this)); + menu->append(new LLMenuItemCallGL("Select All", context_selectall, context_enable_selectall, this)); + menu->appendSeparator("Transep"); LLMenuGL* translatemenu = new LLMenuGL("Translate To"); translatemenu->setCanTearOff(FALSE); SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; - translatemenu->append(new LLMenuItemCallGL("English",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("English", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="da"; - translatemenu->append(new LLMenuItemCallGL("Danish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Danish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="de"; - translatemenu->append(new LLMenuItemCallGL("Deutsch(German)",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Deutsch(German)", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="es"; - translatemenu->append(new LLMenuItemCallGL("Spanish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Spanish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="fr"; - translatemenu->append(new LLMenuItemCallGL("French",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("French", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="it"; - translatemenu->append(new LLMenuItemCallGL("Italian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Italian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="hu"; - translatemenu->append(new LLMenuItemCallGL("Hungarian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Hungarian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="nl"; - translatemenu->append(new LLMenuItemCallGL("Dutch",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Dutch", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="pl"; - translatemenu->append(new LLMenuItemCallGL("Polish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Polish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="pt"; - translatemenu->append(new LLMenuItemCallGL("Portugese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Portugese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ru"; - translatemenu->append(new LLMenuItemCallGL("Russian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Russian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="tr"; - translatemenu->append(new LLMenuItemCallGL("Turkish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Turkish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="uk"; - translatemenu->append(new LLMenuItemCallGL("Ukrainian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Ukrainian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="zh"; - translatemenu->append(new LLMenuItemCallGL("Chinese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Chinese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ja"; - translatemenu->append(new LLMenuItemCallGL("Japanese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Japanese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ko"; - translatemenu->append(new LLMenuItemCallGL("Korean",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Korean", context_translate, context_enable_translate, t)); + menu->appendMenu(translatemenu); menu->appendSeparator("Spelsep"); //menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); @@ -443,7 +439,7 @@ void LLLineEditor::setText(const LLStringExplicit &new_text) // Picks a new cursor position based on the actual screen size of text being drawn. -S32 LLLineEditor::calculateCursorFromMouse( S32 local_mouse_x ) +S32 LLLineEditor::calculateCursorFromMouse( S32 local_mouse_x ) const { const llwchar* wtext = mText.getWString().c_str(); LLWString asterix_text; @@ -521,17 +517,30 @@ void LLLineEditor::deselect() mIsSelecting = FALSE; } +BOOL LLLineEditor::context_enable_cut(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line && line->canCut()); +} void LLLineEditor::context_cut(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->cut(); } + +BOOL LLLineEditor::context_enable_copy(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line &&line->canCopy()); +} + void LLLineEditor::context_copy(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->copy(); } + void LLLineEditor::spell_correct(void* data) { SpellMenuBind* tempBind = (SpellMenuBind*)data; @@ -544,7 +553,13 @@ void LLLineEditor::spell_correct(void* data) } } -void LLLineEditor::translateText(void * data) +BOOL LLLineEditor::context_enable_translate(void* data) +{ + SpellMenuBind* t = (SpellMenuBind*)data; + return (t && t->origin && t->origin->canTranslate()); +} + +void LLLineEditor::context_translate(void * data) { SpellMenuBind* t = (SpellMenuBind*)data; LLLineEditor* line = t->origin; @@ -579,16 +594,10 @@ void LLLineEditor::spell_show(void * data) SpellMenuBind* tempBind = (SpellMenuBind*)data; LLLineEditor* line = tempBind->origin; - if( tempBind && line) + if (tempBind && line) { - if (tempBind->word == "Show Misspellings") - { - line->mShowMisspellings = TRUE; - } - else - { - line->mShowMisspellings = FALSE; - } + BOOL show = (tempBind->word == "Show Misspellings"); + glggHunSpell->setSpellCheckHighlight(show); } } @@ -648,18 +657,36 @@ void LLLineEditor::spell_add(void* data) } } +BOOL LLLineEditor::context_enable_paste(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line && line->canPaste()); +} + void LLLineEditor::context_paste(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->paste(); } +BOOL LLLineEditor::context_enable_delete(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line && line->canDoDelete()); +} + void LLLineEditor::context_delete(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->doDelete(); } +BOOL LLLineEditor::context_enable_selectall(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line && line->canSelectAll()); +} + void LLLineEditor::context_selectall(void* data) { LLLineEditor* line = (LLLineEditor*)data; @@ -787,16 +814,12 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); - // allow_translate="true" in xui - bool can_translate = mAllowTranslate && !mReadOnly && (is_word_part || hasSelection()); - menu->setItemVisible("Translate To", can_translate); - menu->setItemVisible("Transep", can_translate); - // spell_check="true" in xui + menu->setItemVisible("Spelsep", !mReadOnly && mSpellCheckable); if (!mReadOnly && mSpellCheckable) { // search for word matches + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); if (is_word_part) { const LLWString& text = mText.getWString(); @@ -806,7 +829,6 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) { //misspelled word here, and you have just right clicked on it! std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); - //menu->setItemVisible("Transep",(suggs.size()>0)); for (int i = 0; i<(int)suggs.size() ;i++) { @@ -837,7 +859,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if (mShowMisspellings) + if (glggHunSpell->getSpellCheckHighlight()) { tempStruct->word = "Hide Misspellings"; } @@ -1370,6 +1392,15 @@ void LLLineEditor::translationReplace(const std::string &translation, const S32 setCursor(pos + text_wlen); } +BOOL LLLineEditor::canTranslate() const +{ + // if allow_translate="true" in xui, and if other factors permit, we allow it + S32 pos = calculateCursorFromMouse(mLastContextMenuX); + const LLWString& wtext = getWText(); + bool is_word_part = (pos > -1) && LLTextEditor::isPartOfWord(wtext[pos]); + return (mAllowTranslate && !mReadOnly && (is_word_part || hasSelection())); +} + void LLLineEditor::insert(std::string what, S32 wher) { LLLineEditorRollback rollback(this); @@ -1980,7 +2011,7 @@ void LLLineEditor::drawMisspelled(LLRect background) } } - if (mShowMisspellings) + if (glggHunSpell->getSpellCheckHighlight()) { for (int i =0; i<(int)misspellLocations.size(); i++) { diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 0ad415a..f9e0621 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -108,6 +108,7 @@ public: virtual void spellReplace(SpellMenuBind* spellData); virtual void translationReplace(const std::string &translation, const S32 orig_start, const S32 orig_length); + virtual BOOL canTranslate() const; virtual void insert(std::string what,S32 wher); // LLEditMenuHandler overrides @@ -134,15 +135,22 @@ public: virtual void deselect(); virtual BOOL canDeselect() const; + static BOOL context_enable_cut(void* data); static void context_cut(void* data); + static BOOL context_enable_copy(void* data); static void context_copy(void* data); - static void spell_correct(void* data); - static void spell_show(void* data); - static void translateText(void * data); - static void spell_add(void* data); + static BOOL context_enable_paste(void* data); static void context_paste(void* data); + static BOOL context_enable_delete(void* data); static void context_delete(void* data); + static BOOL context_enable_selectall(void* data); static void context_selectall(void* data); + static BOOL context_enable_translate(void * data); + static void context_translate(void * data); + static void spell_correct(void* data); + static void spell_show(void* data); + static void spell_add(void* data); + std::vector getMisspelledWordsPositions(); // view overrides virtual void draw(); @@ -264,7 +272,7 @@ private: void removeChar(); void addChar(const llwchar c); void setCursorAtLocalPos(S32 local_mouse_x); - S32 calculateCursorFromMouse(S32 local_mouse_x); + S32 calculateCursorFromMouse(S32 local_mouse_x) const; S32 findPixelNearestPos(S32 cursor_offset = 0) const; void reportBadKeystroke(); BOOL handleSpecialKey(KEY key, MASK mask); @@ -297,7 +305,6 @@ protected: S32 mStartSpellHere; // the position of the first char on the screen, stored so we know when to update S32 mEndSpellHere; // the location of the last char on the screen BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field - BOOL mShowMisspellings; // show misspellings as highlighted (initialized in the ctor) LLFrameTimer mSpellTimer; //to keep track of what we have to remove before showing menu std::vector suggestionMenuItems; diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index e2335c9..8dcb014 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -330,7 +330,6 @@ LLTextEditor::LLTextEditor( mReflowNeeded(FALSE), mScrollNeeded(FALSE), mSpellCheckable(FALSE), - mShowMisspellings(FALSE), mAllowTranslate(TRUE) { mSourceID.generate(); @@ -384,12 +383,6 @@ LLTextEditor::LLTextEditor( mParseHTML=FALSE; mHTML.clear(); - // in other words, highlighting requires a restart - if (glggHunSpell->getSpellCheckHighlight()) - { - mShowMisspellings = TRUE; - } - // make the popup menu available //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); LLMenuGL* menu = new LLMenuGL("wot"); @@ -397,46 +390,46 @@ LLTextEditor::LLTextEditor( { menu = new LLMenuGL(LLStringUtil::null); }*/ - menu->append(new LLMenuItemCallGL("Cut", context_cut, NULL, this)); - menu->append(new LLMenuItemCallGL("Copy", context_copy, NULL, this)); - menu->append(new LLMenuItemCallGL("Paste", context_paste, NULL, this)); - menu->append(new LLMenuItemCallGL("Delete", context_delete, NULL, this)); - menu->append(new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + menu->append(new LLMenuItemCallGL("Cut", context_cut, context_enable_cut, this)); + menu->append(new LLMenuItemCallGL("Copy", context_copy, context_enable_copy, this)); + menu->append(new LLMenuItemCallGL("Paste", context_paste, context_enable_paste, this)); + menu->append(new LLMenuItemCallGL("Delete", context_delete, context_enable_delete, this)); + menu->append(new LLMenuItemCallGL("Select All", context_selectall, context_enable_selectall, this)); menu->appendSeparator("Transep"); LLMenuGL* translatemenu = new LLMenuGL("Translate To"); translatemenu->setCanTearOff(FALSE); SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; - translatemenu->append(new LLMenuItemCallGL("English",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("English", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="da"; - translatemenu->append(new LLMenuItemCallGL("Danish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Danish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="de"; - translatemenu->append(new LLMenuItemCallGL("Deutsch(German)",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Deutsch(German)", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="es"; - translatemenu->append(new LLMenuItemCallGL("Spanish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Spanish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="fr"; - translatemenu->append(new LLMenuItemCallGL("French",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("French", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="it"; - translatemenu->append(new LLMenuItemCallGL("Italian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Italian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="hu"; - translatemenu->append(new LLMenuItemCallGL("Hungarian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Hungarian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="nl"; - translatemenu->append(new LLMenuItemCallGL("Dutch",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Dutch", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="pl"; - translatemenu->append(new LLMenuItemCallGL("Polish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Polish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="pt"; - translatemenu->append(new LLMenuItemCallGL("Portugese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Portugese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ru"; - translatemenu->append(new LLMenuItemCallGL("Russian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Russian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="tr"; - translatemenu->append(new LLMenuItemCallGL("Turkish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Turkish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="uk"; - translatemenu->append(new LLMenuItemCallGL("Ukrainian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Ukrainian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="zh"; - translatemenu->append(new LLMenuItemCallGL("Chinese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Chinese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ja"; - translatemenu->append(new LLMenuItemCallGL("Japanese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Japanese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ko"; - translatemenu->append(new LLMenuItemCallGL("Korean",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Korean", context_translate, context_enable_translate, t)); menu->appendMenu(translatemenu); menu->appendSeparator("Spelsep"); @@ -446,7 +439,6 @@ LLTextEditor::LLTextEditor( mPopupMenuHandle = menu->getHandle(); } - LLTextEditor::~LLTextEditor() { gFocusMgr.releaseFocusIfNeeded( this ); // calls onCommit() @@ -464,18 +456,38 @@ LLTextEditor::~LLTextEditor() std::for_each(mUndoStack.begin(), mUndoStack.end(), DeletePointer()); LLView::deleteViewByHandle(mPopupMenuHandle); } + +BOOL LLTextEditor::context_enable_cut(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return (line && line->canCut()); +} + void LLTextEditor::context_cut(void* data) { LLTextEditor* line = (LLTextEditor*)data; if(line)line->cut(); } + +BOOL LLTextEditor::context_enable_copy(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return (line && line->canCopy()); +} + void LLTextEditor::context_copy(void* data) { LLTextEditor* line = (LLTextEditor*)data; if(line)line->copy(); } -void LLTextEditor::translateText(void * data) +BOOL LLTextEditor::context_enable_translate(void * data) +{ + SpellMenuBind* t = (SpellMenuBind*)data; + return (t && t->origin && t->origin->canTranslate()); +} + +void LLTextEditor::context_translate(void * data) { SpellMenuBind* t = (SpellMenuBind*)data; LLTextEditor* line = t->origin; @@ -523,14 +535,8 @@ void LLTextEditor::spell_show(void * data) if (tempBind && line) { - if (tempBind->word == "Show Misspellings") - { - glggHunSpell->setSpellCheckHighlight(TRUE); - } - else - { - glggHunSpell->setSpellCheckHighlight(FALSE); - } + BOOL show = (tempBind->word == "Show Misspellings"); + glggHunSpell->setSpellCheckHighlight(show); } } @@ -582,16 +588,37 @@ void LLTextEditor::spell_add(void* data) tempBind->origin->mPrevSpelledText.erase();//make it update } } + +BOOL LLTextEditor::context_enable_paste(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return(line && line->canPaste()); +} + void LLTextEditor::context_paste(void* data) { LLTextEditor* line = (LLTextEditor*)data; if(line)line->paste(); } + +BOOL LLTextEditor::context_enable_delete(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return (line && line->canDoDelete()); +} + void LLTextEditor::context_delete(void* data) { LLTextEditor* line = (LLTextEditor*)data; if(line)line->doDelete(); } + +BOOL LLTextEditor::context_enable_selectall(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return (line && line->canSelectAll()); +} + void LLTextEditor::context_selectall(void* data) { LLTextEditor* line = (LLTextEditor*)data; @@ -1506,16 +1533,11 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); - - // allow_translate="true" in xui - bool can_translate = mAllowTranslate && !mReadOnly && (is_word_part || hasSelection()); - menu->setItemVisible("Translate To", can_translate); - menu->setItemVisible("Transep", can_translate); - // spell_check="true" in xui + menu->setItemVisible("Spelsep", !mReadOnly && mSpellCheckable); if (!mReadOnly && mSpellCheckable) { + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); if (is_word_part) { const LLWString &text = mWText; @@ -1526,7 +1548,6 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) //misspelled word here, and you have just right clicked on it! std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); - //menu->setItemVisible("Transep",(suggs.size()>0)); for (int i = 0; i<(int)suggs.size(); i++) { SpellMenuBind * tempStruct = new SpellMenuBind; @@ -1557,7 +1578,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if (mShowMisspellings) + if (glggHunSpell->getSpellCheckHighlight()) { tempStruct->word = "Hide Misspellings"; } @@ -2301,6 +2322,14 @@ void LLTextEditor::translationReplace(const std::string &translation, const S32 needsReflow(); } +BOOL LLTextEditor::canTranslate() const +{ + // if allow_translate="true" in xui, and if other factors permit, we allow it + S32 pos = getCursorPosFromLocalCoord(mLastContextMenuX, mLastContextMenuY, TRUE); + bool is_word_part = (pos > -1) && isPartOfWord(mWText[pos]); + return (mAllowTranslate && !mReadOnly && (is_word_part || hasSelection())); +} + // paste from clipboard void LLTextEditor::paste() { @@ -3225,7 +3254,7 @@ void LLTextEditor::drawMisspelled() } } //draw - if (mShowMisspellings) + if (glggHunSpell->getSpellCheckHighlight()) { for (int i = 0; i<(int)misspellLocations.size() ;i++) { diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index 3269e17..f2a831b 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -137,6 +137,7 @@ public: virtual void spellReplace(SpellMenuBind* spellData); virtual void translationReplace(const std::string &translation, const S32 orig_start, const S32 orig_length); + virtual BOOL canTranslate() const; virtual void updatePrimary(); virtual void copyPrimary(); @@ -149,13 +150,19 @@ public: virtual BOOL canSelectAll() const; virtual void deselect(); virtual BOOL canDeselect() const; - static void context_cut(void* data); + static BOOL context_enable_cut(void* data); + static void context_cut(void* data); + static BOOL context_enable_copy(void* data); static void context_copy(void* data); + static BOOL context_enable_paste(void* data); static void context_paste(void* data); + static BOOL context_enable_delete(void* data); static void context_delete(void* data); + static BOOL context_enable_selectall(void* data); static void context_selectall(void* data); - static void translateText(void * data); + static BOOL context_enable_translate(void * data); + static void context_translate(void * data); static void spell_correct(void* data); static void spell_add(void* data); static void spell_show(void* data); @@ -529,7 +536,6 @@ private: S32 spellEnd; std::vector misspellLocations; // where all the mispelled words are BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field - BOOL mShowMisspellings; // show misspellings as highlighted (initialized in the ctor) BOOL mAllowTranslate; // set in xui as "allow_translate". S32 mMaxTextByteLength; // Maximum length mText is allowed to be in bytes -- cgit v1.1 From 34e0818d69ade72b7bb312db7ade3454c52096be Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 29 Sep 2010 20:02:43 -0700 Subject: Fixed Windows compile error introduced in 13b1fd24 --- linden/indra/llui/lllineeditor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 49fe3be..b3da7fd 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -1198,7 +1198,7 @@ BOOL LLLineEditor::getWordBoundriesAt(const S32 at, S32* word_begin, S32* word_l pos--; } *word_begin = pos; - while ( (pos < wtext.length()) && LLTextEditor::isPartOfWord(wtext[pos]) ) + while ( (pos < (S32)wtext.length()) && LLTextEditor::isPartOfWord(wtext[pos]) ) { pos++; } -- cgit v1.1 From cf47ba8754b6a8928efed885913ccbca5fad77a8 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Tue, 28 Sep 2010 03:06:39 +0200 Subject: RED-556: SNOW-800: Massively duplicated objects See http://redmine.imprudenceviewer.org/issues/556 --- linden/indra/llui/lluixmltags.h | 192 ++++++++++++++++++++-------------------- 1 file changed, 96 insertions(+), 96 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lluixmltags.h b/linden/indra/llui/lluixmltags.h index 4166131..6bbb788 100644 --- a/linden/indra/llui/lluixmltags.h +++ b/linden/indra/llui/lluixmltags.h @@ -32,100 +32,100 @@ #ifndef LL_UI_XML_TAGS_H #define LL_UI_XML_TAGS_H -const std::string - LL_BUTTON_TAG("button"), - LL_UI_CTRL_LOCATE_TAG("locate"), - LL_PAD_TAG("pad"), - LL_CHECK_BOX_CTRL_TAG("check_box"), - LL_COMBO_BOX_TAG("combo_box"), - LL_DRAG_HANDLE_TOP_TAG("drag_handle_top"), - LL_DRAG_HANDLE_LEFT_TAG("drag_handle_left"), - LL_FLOATER_TAG("floater"), - LL_FLOATER_VIEW_TAG("floater_view"), - LL_MULTI_FLOATER_TAG("multi_floater"), - LL_ICON_CTRL_TAG("icon"), - LL_LINE_EDITOR_TAG("line_editor"), - LL_SEARCH_EDITOR_TAG("search_editor"), - LL_MENU_ITEM_TAG("menu_item"), - LL_MENU_GL_TAG("menu"), - LL_MENU_BAR_GL_TAG("menu_bar"), - LL_MENU_HOLDER_GL_TAG("menu_holder"), - LL_PANEL_TAG("panel"), - LL_RADIO_GROUP_TAG("radio_group"), - LL_RESIZE_BAR_TAG("resize_bar"), - LL_RESIZE_HANDLE_TAG("resize_handle"), - LL_SCROLLBAR_TAG("scrollbar"), - LL_SCROLLABLE_CONTAINER_VIEW_TAG("scroll_container"), - LL_SCROLL_LIST_CTRL_TAG("scroll_list"), - LL_SLIDER_CTRL_TAG("slider"), - LL_SLIDER_TAG("slider_bar"), - LL_MULTI_SLIDER_CTRL_TAG("multi_slider"), - LL_MULTI_SLIDER_TAG("multi_slider_bar"), - LL_SPIN_CTRL_TAG("spinner"), - LL_TAB_CONTAINER_COMMON_TAG("tab_container"), - LL_TEXT_BOX_TAG("text"), - LL_TEXT_EDITOR_TAG("text_editor"), - LL_VIEW_BORDER_TAG("view_border"), - LL_COLOR_SWATCH_TAG("color_swatch"), - LL_INVENTORY_PANEL_TAG("inventory_panel"), - LL_NAME_EDITOR_TAG("name_editor"), - LL_NAME_LIST_TAG("name_list"), - LL_TEXTURE_PICKER_TAG("texture_picker"), - LL_VOLUME_SLIDER_CTRL_TAG("volume_slider"), - LL_WEB_BROWSER_CTRL_TAG("web_browser"), - LL_STAT_VIEW_TAG("stat_view"), - LL_PROGRESS_VIEW_TAG("progress_view"), - LL_STAT_BAR_TAG("stat_bar"), - LL_STATUS_BAR_TAG("status_bar"), - LL_VIEWER_TEXT_EDITOR_TAG("viewer_text_editor"), - LL_TALK_VIEW_TAG("talk_view"), - LL_COLOR_SWATCH_CTRL_TAG("color_swatch"), - LL_GL_TEX_MEM_BAR_TAG("tex_mem_bar"), - LL_TEXTURE_CTRL_TAG("texture_picker"), - LL_TEXTURE_VIEW_TAG("texture_view"), - LL_NAME_LIST_CTRL_TAG("name_list"), - LL_STAT_GRAPH_TAG("stat_graph"), - LL_DROP_TARGET_TAG("drop_target"), - LL_OVERLAY_BAR_TAG("overlay_bar"), - LL_NET_MAP_TAG("net_map"), - LL_HUD_VIEW_TAG("hud_view"), - LL_MEMORY_VIEW_TAG("memory_view"), - LL_MEDIA_REMOTE_CTRL_TAG("media_remote"), - LL_MORPH_VIEW_TAG("morph_view"), - LL_FRAME_STAT_VIEW_TAG("frame_stat_view"), - LL_FOLDER_VIEW_TAG("folder_view"), - LL_SNAPSHOT_LIVE_PREVIEW_TAG("snapshot_preview"), - LL_HOVER_VIEW_TAG("hover_view"), - LL_VELOCITY_BAR_TAG("velocity_bar"), - LL_PERMISSIONS_VIEW_TAG("permissions_view"), - LL_SCROLLING_PANEL_LIST_TAG("scrolling_panel_list"), - LL_CONTAINER_VIEW_TAG("container_view"), - LL_CONSOLE_TAG("console"), - LL_DEBUG_VIEW_TAG("debug_view"), - LL_AUDIOSTATUS_TAG("audio_status"), - LL_FAST_TIMER_VIEW_TAG("fast_timer_view"), - LL_MENU_ITEM_TEAR_OFF_GL_TAG("tearoff_menu"), - LL_MENU_ITEM_BLANK_GL_TAG("menu_item_blank"), - LL_MENU_ITEM_CALL_GL_TAG("menu_item_call"), - LL_MENU_ITEM_CHECK_GL_TAG("menu_item_check"), - LL_MENU_ITEM_BRANCH_GL_TAG("menu_item_branch"), - LL_MENU_ITEM_BRANCH_DOWN_GL_TAG("menu_item_branch_down"), - LL_PIE_MENU_BRANCH_TAG("pie_menu_branch"), - LL_PIE_MENU_TAG("pie_menu"), - LL_MENU_ITEM_SEPARATOR_GL_TAG("menu_item_separator"), - LL_MENU_ITEM_VERTICAL_SEPARATOR_GL_TAG("menu_item_vertical_separator"), - LL_ROOT_VIEW_TAG("root_view"), - LL_FOLDER_VIEW_ITEM_TAG("folder_item"), - LL_FOLDER_VIEW_FOLDER_TAG("folder"), - LL_TEXTURE_BAR_TAG("texture_bar"), - LL_JOYSTICK_SLIDE("joystick_slide"), - LL_JOYSTICK_TURN("joystick_turn"), - LL_GROUP_DROP_TARGET_TAG("group_drop_target"), - LL_LAYOUT_STACK_TAG("layout_stack"), - LL_LAYOUT_PANEL_TAG("layout_panel"), - LL_FLYOUT_BUTTON_TAG("flyout_button"), - LL_FLYOUT_BUTTON_ITEM_TAG("flyout_button_item"), - LL_SIMPLE_TEXT_EDITOR_TAG("simple_text_editor"), - LL_RADIO_ITEM_TAG("radio_item"), - LL_PROGRESS_BAR_TAG("progress_bar"); +char const* const LL_BUTTON_TAG = "button"; +char const* const LL_UI_CTRL_LOCATE_TAG = "locate"; +char const* const LL_PAD_TAG = "pad"; +char const* const LL_CHECK_BOX_CTRL_TAG = "check_box"; +char const* const LL_COMBO_BOX_TAG = "combo_box"; +char const* const LL_DRAG_HANDLE_TOP_TAG = "drag_handle_top"; +char const* const LL_DRAG_HANDLE_LEFT_TAG = "drag_handle_left"; +char const* const LL_FLOATER_TAG = "floater"; +char const* const LL_FLOATER_VIEW_TAG = "floater_view"; +char const* const LL_MULTI_FLOATER_TAG = "multi_floater"; +char const* const LL_ICON_CTRL_TAG = "icon"; +char const* const LL_LINE_EDITOR_TAG = "line_editor"; +char const* const LL_SEARCH_EDITOR_TAG = "search_editor"; +char const* const LL_MENU_ITEM_TAG = "menu_item"; +char const* const LL_MENU_GL_TAG = "menu"; +char const* const LL_MENU_BAR_GL_TAG = "menu_bar"; +char const* const LL_MENU_HOLDER_GL_TAG = "menu_holder"; +char const* const LL_PANEL_TAG = "panel"; +char const* const LL_RADIO_GROUP_TAG = "radio_group"; +char const* const LL_RESIZE_BAR_TAG = "resize_bar"; +char const* const LL_RESIZE_HANDLE_TAG = "resize_handle"; +char const* const LL_SCROLLBAR_TAG = "scrollbar"; +char const* const LL_SCROLLABLE_CONTAINER_VIEW_TAG = "scroll_container"; +char const* const LL_SCROLL_LIST_CTRL_TAG = "scroll_list"; +char const* const LL_SLIDER_CTRL_TAG = "slider"; +char const* const LL_SLIDER_TAG = "slider_bar"; +char const* const LL_MULTI_SLIDER_CTRL_TAG = "multi_slider"; +char const* const LL_MULTI_SLIDER_TAG = "multi_slider_bar"; +char const* const LL_SPIN_CTRL_TAG = "spinner"; +char const* const LL_TAB_CONTAINER_COMMON_TAG = "tab_container"; +char const* const LL_TEXT_BOX_TAG = "text"; +char const* const LL_TEXT_EDITOR_TAG = "text_editor"; +char const* const LL_VIEW_BORDER_TAG = "view_border"; +char const* const LL_COLOR_SWATCH_TAG = "color_swatch"; +char const* const LL_INVENTORY_PANEL_TAG = "inventory_panel"; +char const* const LL_NAME_EDITOR_TAG = "name_editor"; +char const* const LL_NAME_LIST_TAG = "name_list"; +char const* const LL_TEXTURE_PICKER_TAG = "texture_picker"; +char const* const LL_VOLUME_SLIDER_CTRL_TAG = "volume_slider"; +char const* const LL_WEB_BROWSER_CTRL_TAG = "web_browser"; +char const* const LL_STAT_VIEW_TAG = "stat_view"; +char const* const LL_PROGRESS_VIEW_TAG = "progress_view"; +char const* const LL_STAT_BAR_TAG = "stat_bar"; +char const* const LL_STATUS_BAR_TAG = "status_bar"; +char const* const LL_VIEWER_TEXT_EDITOR_TAG = "viewer_text_editor"; +char const* const LL_TALK_VIEW_TAG = "talk_view"; +char const* const LL_COLOR_SWATCH_CTRL_TAG = "color_swatch"; +char const* const LL_GL_TEX_MEM_BAR_TAG = "tex_mem_bar"; +char const* const LL_TEXTURE_CTRL_TAG = "texture_picker"; +char const* const LL_TEXTURE_VIEW_TAG = "texture_view"; +char const* const LL_NAME_LIST_CTRL_TAG = "name_list"; +char const* const LL_STAT_GRAPH_TAG = "stat_graph"; +char const* const LL_DROP_TARGET_TAG = "drop_target"; +char const* const LL_OVERLAY_BAR_TAG = "overlay_bar"; +char const* const LL_NET_MAP_TAG = "net_map"; +char const* const LL_HUD_VIEW_TAG = "hud_view"; +char const* const LL_MEMORY_VIEW_TAG = "memory_view"; +char const* const LL_MEDIA_REMOTE_CTRL_TAG = "media_remote"; +char const* const LL_MORPH_VIEW_TAG = "morph_view"; +char const* const LL_FRAME_STAT_VIEW_TAG = "frame_stat_view"; +char const* const LL_FOLDER_VIEW_TAG = "folder_view"; +char const* const LL_SNAPSHOT_LIVE_PREVIEW_TAG = "snapshot_preview"; +char const* const LL_HOVER_VIEW_TAG = "hover_view"; +char const* const LL_VELOCITY_BAR_TAG = "velocity_bar"; +char const* const LL_PERMISSIONS_VIEW_TAG = "permissions_view"; +char const* const LL_SCROLLING_PANEL_LIST_TAG = "scrolling_panel_list"; +char const* const LL_CONTAINER_VIEW_TAG = "container_view"; +char const* const LL_CONSOLE_TAG = "console"; +char const* const LL_DEBUG_VIEW_TAG = "debug_view"; +char const* const LL_AUDIOSTATUS_TAG = "audio_status"; +char const* const LL_FAST_TIMER_VIEW_TAG = "fast_timer_view"; +char const* const LL_MENU_ITEM_TEAR_OFF_GL_TAG = "tearoff_menu"; +char const* const LL_MENU_ITEM_BLANK_GL_TAG = "menu_item_blank"; +char const* const LL_MENU_ITEM_CALL_GL_TAG = "menu_item_call"; +char const* const LL_MENU_ITEM_CHECK_GL_TAG = "menu_item_check"; +char const* const LL_MENU_ITEM_BRANCH_GL_TAG = "menu_item_branch"; +char const* const LL_MENU_ITEM_BRANCH_DOWN_GL_TAG = "menu_item_branch_down"; +char const* const LL_PIE_MENU_BRANCH_TAG = "pie_menu_branch"; +char const* const LL_PIE_MENU_TAG = "pie_menu"; +char const* const LL_MENU_ITEM_SEPARATOR_GL_TAG = "menu_item_separator"; +char const* const LL_MENU_ITEM_VERTICAL_SEPARATOR_GL_TAG = "menu_item_vertical_separator"; +char const* const LL_ROOT_VIEW_TAG = "root_view"; +char const* const LL_FOLDER_VIEW_ITEM_TAG = "folder_item"; +char const* const LL_FOLDER_VIEW_FOLDER_TAG = "folder"; +char const* const LL_TEXTURE_BAR_TAG = "texture_bar"; +char const* const LL_JOYSTICK_SLIDE = "joystick_slide"; +char const* const LL_JOYSTICK_TURN = "joystick_turn"; +char const* const LL_GROUP_DROP_TARGET_TAG = "group_drop_target"; +char const* const LL_LAYOUT_STACK_TAG = "layout_stack"; +char const* const LL_LAYOUT_PANEL_TAG = "layout_panel"; +char const* const LL_FLYOUT_BUTTON_TAG = "flyout_button"; +char const* const LL_FLYOUT_BUTTON_ITEM_TAG = "flyout_button_item"; +char const* const LL_SIMPLE_TEXT_EDITOR_TAG = "simple_text_editor"; +char const* const LL_RADIO_ITEM_TAG = "radio_item"; +char const* const LL_PROGRESS_BAR_TAG = "progress_bar"; + #endif -- cgit v1.1 From 6be58f1de21c276018aac9575fad81aa17a63ed2 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Mon, 4 Oct 2010 00:11:18 +0200 Subject: Don't leak SpellMenuBind structs when destroying LLLineEditor/LLTextEditor objects. --- linden/indra/llui/lllineeditor.cpp | 67 ++++++++++++++++---------------------- linden/indra/llui/lltexteditor.cpp | 67 ++++++++++++++++---------------------- 2 files changed, 56 insertions(+), 78 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index b3da7fd..4581ec7 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -231,38 +231,22 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, menu->appendSeparator("Transep"); LLMenuGL* translatemenu = new LLMenuGL("Translate To"); translatemenu->setCanTearOff(FALSE); - SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; - translatemenu->append(new LLMenuItemCallGL("English", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="da"; - translatemenu->append(new LLMenuItemCallGL("Danish", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="de"; - translatemenu->append(new LLMenuItemCallGL("Deutsch(German)", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="es"; - translatemenu->append(new LLMenuItemCallGL("Spanish", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="fr"; - translatemenu->append(new LLMenuItemCallGL("French", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="it"; - translatemenu->append(new LLMenuItemCallGL("Italian", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="hu"; - translatemenu->append(new LLMenuItemCallGL("Hungarian", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="nl"; - translatemenu->append(new LLMenuItemCallGL("Dutch", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="pl"; - translatemenu->append(new LLMenuItemCallGL("Polish", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="pt"; - translatemenu->append(new LLMenuItemCallGL("Portugese", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="ru"; - translatemenu->append(new LLMenuItemCallGL("Russian", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="tr"; - translatemenu->append(new LLMenuItemCallGL("Turkish", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="uk"; - translatemenu->append(new LLMenuItemCallGL("Ukrainian", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="zh"; - translatemenu->append(new LLMenuItemCallGL("Chinese", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="ja"; - translatemenu->append(new LLMenuItemCallGL("Japanese", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="ko"; - translatemenu->append(new LLMenuItemCallGL("Korean", context_translate, context_enable_translate, t)); + translatemenu->append(new LLMenuItemCallGL("en", "English", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("da", "Danish", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("de", "Deutsch(German)", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("es", "Spanish", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("fr", "French", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("it", "Italian", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("hu", "Hungarian", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("nl", "Dutch", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("pl", "Polish", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("pt", "Portugese", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("ru", "Russian", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("tr", "Turkish", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("uk", "Ukrainian", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("zh", "Chinese", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("ja", "Japanese", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("ko", "Korean", context_translate, context_enable_translate, this)); menu->appendMenu(translatemenu); menu->appendSeparator("Spelsep"); @@ -555,15 +539,20 @@ void LLLineEditor::spell_correct(void* data) BOOL LLLineEditor::context_enable_translate(void* data) { - SpellMenuBind* t = (SpellMenuBind*)data; - return (t && t->origin && t->origin->canTranslate()); + LLLineEditor* line = (LLLineEditor*)data; + return line && line->canTranslate(); } void LLLineEditor::context_translate(void * data) { - SpellMenuBind* t = (SpellMenuBind*)data; - LLLineEditor* line = t->origin; - const std::string &toLang = t->word;//LLTranslate::getTranslateLanguage(); + LLLineEditor* line = (LLLineEditor*)data; + LLMenuGL* menu = line ? (LLMenuGL*)(line->mPopupMenuHandle.get()) : NULL; + LLMenuGL* translate_menu = menu ? menu->getChildMenuByName("Translate To", TRUE) : NULL; + if (!translate_menu) + { + return; + } + const std::string to_lang = translate_menu->getHighlightedItem()->getName(); bool has_text = false; S32 start, length; @@ -584,8 +573,8 @@ void LLLineEditor::context_translate(void * data) if (has_text) { std::string to_translate = wstring_to_utf8str(line->getWText().substr(start, length)); - LLHTTPClient::ResponderPtr result = LineChatTranslationReceiver::build(toLang, line, start, length); - LLTranslate::translateMessage(result,"", toLang, to_translate); + LLHTTPClient::ResponderPtr result = LineChatTranslationReceiver::build(to_lang, line, start, length); + LLTranslate::translateMessage(result,"", to_lang, to_translate); } } diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 8dcb014..369eb1e 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -398,38 +398,22 @@ LLTextEditor::LLTextEditor( menu->appendSeparator("Transep"); LLMenuGL* translatemenu = new LLMenuGL("Translate To"); translatemenu->setCanTearOff(FALSE); - SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; - translatemenu->append(new LLMenuItemCallGL("English", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="da"; - translatemenu->append(new LLMenuItemCallGL("Danish", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="de"; - translatemenu->append(new LLMenuItemCallGL("Deutsch(German)", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="es"; - translatemenu->append(new LLMenuItemCallGL("Spanish", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="fr"; - translatemenu->append(new LLMenuItemCallGL("French", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="it"; - translatemenu->append(new LLMenuItemCallGL("Italian", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="hu"; - translatemenu->append(new LLMenuItemCallGL("Hungarian", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="nl"; - translatemenu->append(new LLMenuItemCallGL("Dutch", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="pl"; - translatemenu->append(new LLMenuItemCallGL("Polish", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="pt"; - translatemenu->append(new LLMenuItemCallGL("Portugese", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="ru"; - translatemenu->append(new LLMenuItemCallGL("Russian", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="tr"; - translatemenu->append(new LLMenuItemCallGL("Turkish", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="uk"; - translatemenu->append(new LLMenuItemCallGL("Ukrainian", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="zh"; - translatemenu->append(new LLMenuItemCallGL("Chinese", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="ja"; - translatemenu->append(new LLMenuItemCallGL("Japanese", context_translate, context_enable_translate, t)); - t=new SpellMenuBind;t->origin=this;t->word="ko"; - translatemenu->append(new LLMenuItemCallGL("Korean", context_translate, context_enable_translate, t)); + translatemenu->append(new LLMenuItemCallGL("en", "English", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("da", "Danish", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("de", "Deutsch(German)", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("es", "Spanish", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("fr", "French", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("it", "Italian", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("hu", "Hungarian", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("nl", "Dutch", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("pl", "Polish", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("pt", "Portugese", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("ru", "Russian", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("tr", "Turkish", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("uk", "Ukrainian", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("zh", "Chinese", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("ja", "Japanese", context_translate, context_enable_translate, this)); + translatemenu->append(new LLMenuItemCallGL("ko", "Korean", context_translate, context_enable_translate, this)); menu->appendMenu(translatemenu); menu->appendSeparator("Spelsep"); @@ -483,15 +467,20 @@ void LLTextEditor::context_copy(void* data) BOOL LLTextEditor::context_enable_translate(void * data) { - SpellMenuBind* t = (SpellMenuBind*)data; - return (t && t->origin && t->origin->canTranslate()); + LLTextEditor* editor = (LLTextEditor*)data; + return editor && editor->canTranslate(); } void LLTextEditor::context_translate(void * data) { - SpellMenuBind* t = (SpellMenuBind*)data; - LLTextEditor* line = t->origin; - const std::string &toLang = t->word;//LLTranslate::getTranslateLanguage(); + LLTextEditor* line = (LLTextEditor*)data; + LLMenuGL* menu = line ? (LLMenuGL*)(line->mPopupMenuHandle.get()) : NULL; + LLMenuGL* translate_menu = menu ? menu->getChildMenuByName("Translate To", TRUE) : NULL; + if (!translate_menu) + { + return; + } + const std::string to_lang = translate_menu->getHighlightedItem()->getName(); bool has_text = false; S32 start, length; @@ -512,8 +501,8 @@ void LLTextEditor::context_translate(void * data) if (has_text) { const std::string to_translate = wstring_to_utf8str(line->getWText().substr(start, length)); - LLHTTPClient::ResponderPtr result = TextChatTranslationReceiver::build(toLang, line, start, length); - LLTranslate::translateMessage(result,"", toLang, to_translate); + LLHTTPClient::ResponderPtr result = TextChatTranslationReceiver::build(to_lang, line, start, length); + LLTranslate::translateMessage(result,"", to_lang, to_translate); } } -- cgit v1.1 From 1eee67b68de88e1f2a7e0f1d55b3e993e819a419 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Thu, 7 Oct 2010 18:20:33 +0200 Subject: Fix bug #611: Context menu spell checker suggestions broken. This fixes a confusion between word end position and word length, causing an empty spell checker suggestion list, or possibly crashes. I caused this bug in f5006e8a2f34afa390f0bbcf0f6af15218cf4105. Oops. --- linden/indra/llui/lllineeditor.cpp | 10 +++++----- linden/indra/llui/lltexteditor.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 4581ec7..e73b287 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -779,7 +779,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) //setCursorAtLocalPos( x); S32 wordStart = 0; - S32 wordEnd = 0; + S32 wordLen = 0; S32 pos = calculateCursorFromMouse(x); LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); @@ -808,11 +808,11 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) if (!mReadOnly && mSpellCheckable) { // search for word matches - bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordLen); if (is_word_part) { const LLWString& text = mText.getWString(); - std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); + std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordLen)); if (!glggHunSpell->isSpelledRight(selectedWord)) { @@ -824,7 +824,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; tempStruct->word = suggs[i]; - tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionEnd = wordStart + wordLen; tempStruct->wordPositionStart=wordStart; LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( tempStruct->word, spell_correct, NULL, tempStruct); @@ -836,7 +836,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; tempStruct->word = selectedWord; - tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionEnd = wordStart + wordLen; tempStruct->wordPositionStart=wordStart; LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( "Add Word", spell_add, NULL, tempStruct); diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 369eb1e..fdf8bcf 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -1502,7 +1502,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) //setCursorAtLocalPos( x, y, TRUE ); S32 wordStart = 0; - S32 wordEnd = 0; + S32 wordLen = 0; S32 pos = getCursorPosFromLocalCoord(x,y,TRUE); LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); @@ -1526,11 +1526,11 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) menu->setItemVisible("Spelsep", !mReadOnly && mSpellCheckable); if (!mReadOnly && mSpellCheckable) { - bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordLen); if (is_word_part) { const LLWString &text = mWText; - std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); + std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordLen)); if (!glggHunSpell->isSpelledRight(selectedWord)) { @@ -1542,7 +1542,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; tempStruct->word = suggs[i]; - tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionEnd = wordStart + wordLen; tempStruct->wordPositionStart=wordStart; tempStruct->wordY=y; LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( @@ -1554,7 +1554,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; tempStruct->word = selectedWord; - tempStruct->wordPositionEnd = wordEnd; + tempStruct->wordPositionEnd = wordStart + wordLen; tempStruct->wordPositionStart=wordStart; tempStruct->wordY=y; LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( -- cgit v1.1 From 0e86bfee3d1dd0e42fef23293242f52793f08583 Mon Sep 17 00:00:00 2001 From: Robin Cornelius Date: Sat, 9 Oct 2010 10:20:10 +0100 Subject: Fix some STL errors highlighted by MSVC debug --- linden/indra/llui/lllineeditor.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index e73b287..a3785e4 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -416,7 +416,16 @@ void LLLineEditor::setText(const LLStringExplicit &new_text) setCursor(llmin((S32)mText.length(), getCursor())); // Set current history line to end of history. - mCurrentHistoryLine = mLineHistory.end() - 1; + // RC Fix, its really not safe to just take 1 of the end itterator, if end==begin + // that leaves an invalid state upseting the secure STL checks + if(mLineHistory.empty()) + { + mCurrentHistoryLine = mLineHistory.begin(); + } + else + { + mCurrentHistoryLine = mLineHistory.end() - 1; + } mPrevText = mText; } -- cgit v1.1 From b6ca1620c712288268913dfb616fbd3d96c1fcf5 Mon Sep 17 00:00:00 2001 From: Robin Cornelius Date: Sat, 9 Oct 2010 10:20:10 +0100 Subject: Fix some STL errors highlighted by MSVC debug --- linden/indra/llui/lllineeditor.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index e73b287..a3785e4 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -416,7 +416,16 @@ void LLLineEditor::setText(const LLStringExplicit &new_text) setCursor(llmin((S32)mText.length(), getCursor())); // Set current history line to end of history. - mCurrentHistoryLine = mLineHistory.end() - 1; + // RC Fix, its really not safe to just take 1 of the end itterator, if end==begin + // that leaves an invalid state upseting the secure STL checks + if(mLineHistory.empty()) + { + mCurrentHistoryLine = mLineHistory.begin(); + } + else + { + mCurrentHistoryLine = mLineHistory.end() - 1; + } mPrevText = mText; } -- cgit v1.1 From b2d616b732943817b7e705fc8f6c4be9beee3def Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Fri, 15 Oct 2010 18:02:40 +0200 Subject: Rename LLRect::isNull to LLRect::isEmpty (a random thing I picked up from snowglobe 2.x). --- linden/indra/llui/llpanel.cpp | 2 +- linden/indra/llui/llview.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llpanel.cpp b/linden/indra/llui/llpanel.cpp index 26137d7..07e78ed 100644 --- a/linden/indra/llui/llpanel.cpp +++ b/linden/indra/llui/llpanel.cpp @@ -1171,7 +1171,7 @@ void LLLayoutStack::draw() LLLocalClipRect clip(clip_rect); // only force drawing invisible children if visible amount is non-zero - drawChild(panelp, 0, 0, !clip_rect.isNull()); + drawChild(panelp, 0, 0, !clip_rect.isEmpty()); } } diff --git a/linden/indra/llui/llview.cpp b/linden/indra/llui/llview.cpp index 1f76696..d4eda8f 100644 --- a/linden/indra/llui/llview.cpp +++ b/linden/indra/llui/llview.cpp @@ -1542,7 +1542,7 @@ void LLView::updateBoundingRect() LLRect child_bounding_rect = childp->getBoundingRect(); - if (local_bounding_rect.isNull()) + if (local_bounding_rect.isEmpty()) { // start out with bounding rect equal to first visible child's bounding rect local_bounding_rect = child_bounding_rect; @@ -1550,7 +1550,7 @@ void LLView::updateBoundingRect() else { // accumulate non-null children rectangles - if (!child_bounding_rect.isNull()) + if (!child_bounding_rect.isEmpty()) { local_bounding_rect.unionWith(child_bounding_rect); } -- cgit v1.1 From 2f4e17af336c9a399a0274b7836f40fc7ff56e21 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Wed, 20 Oct 2010 18:31:42 +0200 Subject: LindenUserDir fixes. The LindenUserDir (~/.imprudence/first_last/) cannot be initialized before the user logged in. However, several singletons (that only can be initialized once) depend on this directory for initialization. Therefore we have to take care not to instantiate those singletons until after the user logged in. With regard to webit, this fixes the browser_profile (cache and cookies) directory that the builtin browser uses. --- linden/indra/llui/lltexteditor.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index fdf8bcf..004d063 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -57,6 +57,7 @@ #include "llimagegl.h" #include "llwindow.h" #include "lltextparser.h" +#include "lldir.h" #include #include "llmenugl.h" @@ -4205,7 +4206,10 @@ void LLTextEditor::appendColoredText(const std::string &new_text, const std::string& font_name) { LLColor4 lcolor=color; - if (mParseHighlights) + // If LindenUserDir is empty then we didn't login yet. + // In that case we can't instantiate LLTextParser, which + // is initialized per user. + if (mParseHighlights && !gDirUtilp->getLindenUserDir(true).empty()) { LLTextParser* highlight = LLTextParser::getInstance(); highlight->parseFullLineHighlights(new_text, &lcolor); @@ -4285,7 +4289,10 @@ void LLTextEditor::appendHighlightedText(const std::string &new_text, S32 highlight_part, LLStyleSP stylep) { - if (mParseHighlights) + // If LindenUserDir is empty then we didn't login yet. + // In that case we can't instantiate LLTextParser, which + // is initialized per user. + if (mParseHighlights && !gDirUtilp->getLindenUserDir(true).empty()) { LLTextParser* highlight = LLTextParser::getInstance(); -- cgit v1.1 From 95e77d7378654904990ea5cd9947cbc4dd40b386 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Sat, 23 Oct 2010 22:59:56 +0200 Subject: IMP-663: WARNING: replaceSubstitutionStrings: replaceSubstituionStrings FAILURE: value: ignoretext repl: Caused by missing ignoretext in notifications.xml. Also fixed typos in debug output messages. --- linden/indra/llui/llnotifications.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llnotifications.cpp b/linden/indra/llui/llnotifications.cpp index 2459110..4d3ff46 100644 --- a/linden/indra/llui/llnotifications.cpp +++ b/linden/indra/llui/llnotifications.cpp @@ -1190,13 +1190,13 @@ void replaceSubstitutionStrings(LLXMLNodePtr node, StringMap& replacements) if (found != replacements.end()) { replacement = found->second; - //llwarns << "replaceSubstituionStrings: value: " << value << " repl: " << replacement << llendl; + //llinfos << "replaceSubstitutionStrings: value: \"" << value << "\" repl: \"" << replacement << "\"." << llendl; it->second->setValue(replacement); } else { - llwarns << "replaceSubstituionStrings FAILURE: value: " << value << " repl: " << replacement << llendl; + llwarns << "replaceSubstitutionStrings FAILURE: could not find replacement \"" << value << "\"." << llendl; } } } -- cgit v1.1 From 72c4d73706267a32bb31d93e14425b1c0c8a5715 Mon Sep 17 00:00:00 2001 From: RevolutionSmythe Date: Sat, 23 Oct 2010 20:51:07 -0500 Subject: Merges the Message log and Message builder from Inertia in. --- linden/indra/llui/llscrolllistctrl.cpp | 17 +++++++++++++++++ linden/indra/llui/llscrolllistctrl.h | 11 +++++++++++ 2 files changed, 28 insertions(+) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llscrolllistctrl.cpp b/linden/indra/llui/llscrolllistctrl.cpp index 3c2293f..9635f99 100644 --- a/linden/indra/llui/llscrolllistctrl.cpp +++ b/linden/indra/llui/llscrolllistctrl.cpp @@ -103,6 +103,10 @@ struct SortScrollListItem LLScrollListIcon::LLScrollListIcon(LLUIImagePtr icon, S32 width) : LLScrollListCell(width), mIcon(icon), + // + mCallback(NULL), + mUserData(NULL), + // mColor(LLColor4::white) { } @@ -145,6 +149,19 @@ void LLScrollListIcon::setValue(const LLSD& value) } } +// +void LLScrollListIcon::setClickCallback(BOOL (*callback)(void*), void* user_data) +{ + mCallback = callback; + mUserData = user_data; +} + +BOOL LLScrollListIcon::handleClick() +{ + if(mCallback) return mCallback(mUserData); + return FALSE; +} +// void LLScrollListIcon::setColor(const LLColor4& color) { diff --git a/linden/indra/llui/llscrolllistctrl.h b/linden/indra/llui/llscrolllistctrl.h index 516e4f1..e875d7a 100644 --- a/linden/indra/llui/llscrolllistctrl.h +++ b/linden/indra/llui/llscrolllistctrl.h @@ -163,10 +163,18 @@ public: virtual void setColor(const LLColor4&); virtual BOOL isText()const { return FALSE; } virtual void setValue(const LLSD& value); + // + void setClickCallback(BOOL (*callback)(void*), void* user_data); + virtual BOOL handleClick(); + // private: LLUIImagePtr mIcon; LLColor4 mColor; + // + BOOL (*mCallback)(void*); + void* mUserData; + // }; /* @@ -493,6 +501,9 @@ public: virtual S32 getScrollPos() const; virtual void setScrollPos( S32 pos ); + // + S32 getPageLines() { return mPageLines; } + // S32 getSearchColumn(); void setSearchColumn(S32 column) { mSearchColumn = column; } S32 getColumnIndexFromOffset(S32 x); -- cgit v1.1 From b0446b980cc30d01644ef16f3775372109b612e3 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Wed, 3 Nov 2010 17:58:09 +0100 Subject: Rename hippo* files to lower case (PART 2 OF 2) There was a problem with #include "hippolimits.h" because the file is called hippoLimits.h (with an uppercase L). After some discussion on IRC it was reluctantly decided that filenames should be lowercase, as is done for every Linden file. This is part 2 or 2 (the first part just renamed the files). This part changes all files to make the viewer compile again after the renaming. --- linden/indra/llui/llnotifications.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llnotifications.cpp b/linden/indra/llui/llnotifications.cpp index 4d3ff46..77f2ff7 100644 --- a/linden/indra/llui/llnotifications.cpp +++ b/linden/indra/llui/llnotifications.cpp @@ -40,7 +40,7 @@ #include #include -#include "../newview/hippoGridManager.h" +#include "../newview/hippogridmanager.h" const std::string NOTIFICATION_PERSIST_VERSION = "0.93"; -- cgit v1.1 From 5b4356cefbaa7dbdc8656e7283c110a893b1a89c Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Sun, 7 Nov 2010 16:55:50 +0100 Subject: IMP-692: SNOW-713: Global objects in libllcommon duplicated in plugins See http://jira.secondlife.com/browse/SNOW-713 This patch makes llcommon shared. It contains the following snowglobe (SVN) changesets: 3478, 3479, 3480, 3481, 3482, 3485, 3496, 3498, 3500, 3519 and 3531, plus the fix for all rejects. Note that changes to scripts/automated_build_scripts/opensrc-build.sh (changesets 3500 and 3625) were ignored as we don't have scripts/automated_build_scripts. --- linden/indra/llui/llfunctorregistry.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llfunctorregistry.cpp b/linden/indra/llui/llfunctorregistry.cpp index 0c5b165..5f9644f 100644 --- a/linden/indra/llui/llfunctorregistry.cpp +++ b/linden/indra/llui/llfunctorregistry.cpp @@ -31,6 +31,7 @@ * $/LicenseInfo$ **/ +#include "linden_common.h" #include "llfunctorregistry.h" // This is a default functor always resident in the system. -- cgit v1.1 From 44c07eb2c58c4898752ad813d46c224ccd7229f1 Mon Sep 17 00:00:00 2001 From: Armin Weatherwax Date: Mon, 8 Nov 2010 19:51:32 +0100 Subject: feature: add a tiny context menu to areasearch scroll list items rightclick one of the results and teleport or cam to the object or bring it in edit mode --- linden/indra/llui/llscrolllistctrl.cpp | 38 ++++++++++++++++++++++++++++++++++ linden/indra/llui/llscrolllistctrl.h | 4 ++++ 2 files changed, 42 insertions(+) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llscrolllistctrl.cpp b/linden/indra/llui/llscrolllistctrl.cpp index 9635f99..1248a9a 100644 --- a/linden/indra/llui/llscrolllistctrl.cpp +++ b/linden/indra/llui/llscrolllistctrl.cpp @@ -605,6 +605,7 @@ LLScrollListCtrl::LLScrollListCtrl(const std::string& name, const LLRect& rect, mHighlightedColor( LLUI::sColorsGroup->getColor("ScrollHighlightedColor") ), mBorderThickness( 2 ), mOnDoubleClickCallback( NULL ), + mOnRightMouseDownCallback( NULL ), mOnMaximumSelectCallback( NULL ), mOnSortChangedCallback( NULL ), mHighlightedItem(-1), @@ -2082,6 +2083,27 @@ BOOL LLScrollListCtrl::handleDoubleClick(S32 x, S32 y, MASK mask) return TRUE; } +BOOL LLScrollListCtrl::handleRightMouseDown(S32 x, S32 y, MASK mask) +{ + //BOOL handled = FALSE; + BOOL handled = handleClick(x, y, mask); + + if (!handled) + { + // Offer the click to the children, even if we aren't enabled + // so the scroll bars will work. + if (NULL == LLView::childrenHandleRightMouseDown(x, y, mask)) + { + if( mCanSelect && mOnRightMouseDownCallback ) + { + mOnRightMouseDownCallback( x, y, mCallbackUserData ); + } + } + } + + return TRUE; +} + BOOL LLScrollListCtrl::handleClick(S32 x, S32 y, MASK mask) { // which row was clicked on? @@ -3631,6 +3653,22 @@ BOOL LLColumnHeader::handleDoubleClick(S32 x, S32 y, MASK mask) return TRUE; } +BOOL LLColumnHeader::handleRightMouseDown(S32 x, S32 y, MASK mask) +{ + if (canResize() && mResizeBar->getRect().pointInRect(x, y)) + { + // reshape column to max content width + LLRect column_rect = getRect(); + column_rect.mRight = column_rect.mLeft + mColumn->mMaxContentWidth; + userSetShape(column_rect); + } + else + { + onClick(this); + } + return TRUE; +} + void LLColumnHeader::setImage(const std::string &image_name) { if (mButton) diff --git a/linden/indra/llui/llscrolllistctrl.h b/linden/indra/llui/llscrolllistctrl.h index e875d7a..4be7ff7 100644 --- a/linden/indra/llui/llscrolllistctrl.h +++ b/linden/indra/llui/llscrolllistctrl.h @@ -241,6 +241,7 @@ public: /*virtual*/ void draw(); /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask); + /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask); /*virtual*/ void showList(); /*virtual*/ LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding); @@ -431,6 +432,7 @@ public: void highlightNthItem( S32 index ); void setDoubleClickCallback( void (*cb)(void*) ) { mOnDoubleClickCallback = cb; } + void setRightMouseDownCallback( void (*cb)(S32 x, S32 y, void*) ) { mOnRightMouseDownCallback = cb; } void setMaximumSelectCallback( void (*cb)(void*) ) { mOnMaximumSelectCallback = cb; } void setSortChangedCallback( void (*cb)(void*) ) { mOnSortChangedCallback = cb; } @@ -517,6 +519,7 @@ public: /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask); + /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask); /*virtual*/ BOOL handleUnicodeCharHere(llwchar uni_char); @@ -660,6 +663,7 @@ private: S32 mBorderThickness; void (*mOnDoubleClickCallback)(void* userdata); + void (*mOnRightMouseDownCallback)(S32 x, S32 y, void* userdata); void (*mOnMaximumSelectCallback)(void* userdata ); void (*mOnSortChangedCallback)(void* userdata); -- cgit v1.1 From 16ce373d14199b94729caffcb099d8a6bd37f882 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 9 Mar 2011 20:37:53 -0700 Subject: #787: Horizontal mouse scrolling support, patch by Kakurady Drakenar --- linden/indra/llui/lllineeditor.cpp | 5 ++++ linden/indra/llui/lllineeditor.h | 1 + linden/indra/llui/llscrollbar.cpp | 5 ++++ linden/indra/llui/llscrollbar.h | 1 + linden/indra/llui/llscrollcontainer.cpp | 17 ++++++++++++++ linden/indra/llui/llscrollcontainer.h | 1 + linden/indra/llui/llview.cpp | 41 +++++++++++++++++++++++++++++++++ linden/indra/llui/llview.h | 2 ++ 8 files changed, 73 insertions(+) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index a3785e4..76b8927 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -1034,6 +1034,11 @@ BOOL LLLineEditor::handleHover(S32 x, S32 y, MASK mask) return handled; } +BOOL LLLineEditor::handleHScrollWheel(S32 x, S32 y, S32 clicks) +{ + mScrollHPos = llclamp(mScrollHPos + clicks * 3, 0, mText.length()); + return TRUE; +} BOOL LLLineEditor::handleMouseUp(S32 x, S32 y, MASK mask) diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index f9e0621..d217859 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -90,6 +90,7 @@ public: /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask); + /*virtual*/ BOOL handleHScrollWheel(S32 x, S32 y, S32 clicks); /*virtual*/ BOOL handleDoubleClick(S32 x,S32 y,MASK mask); /*virtual*/ BOOL handleMiddleMouseDown(S32 x,S32 y,MASK mask); /*virtual*/ BOOL handleRightMouseDown( S32 x, S32 y, MASK mask ); diff --git a/linden/indra/llui/llscrollbar.cpp b/linden/indra/llui/llscrollbar.cpp index 65086d8..11e6239 100644 --- a/linden/indra/llui/llscrollbar.cpp +++ b/linden/indra/llui/llscrollbar.cpp @@ -426,6 +426,11 @@ BOOL LLScrollbar::handleScrollWheel(S32 x, S32 y, S32 clicks) changeLine( clicks * mStepSize, TRUE ); return TRUE; } +BOOL LLScrollbar::handleHScrollWheel(S32 x, S32 y, S32 clicks) +{ + changeLine( clicks * mStepSize, TRUE ); + return TRUE; +} BOOL LLScrollbar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string &tooltip_msg) diff --git a/linden/indra/llui/llscrollbar.h b/linden/indra/llui/llscrollbar.h index 0bbf866..6969662 100644 --- a/linden/indra/llui/llscrollbar.h +++ b/linden/indra/llui/llscrollbar.h @@ -69,6 +69,7 @@ public: virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks); + virtual BOOL handleHScrollWheel(S32 x, S32 y, S32 clicks); virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string &tooltip_msg); diff --git a/linden/indra/llui/llscrollcontainer.cpp b/linden/indra/llui/llscrollcontainer.cpp index 6f037e2..8737a70 100644 --- a/linden/indra/llui/llscrollcontainer.cpp +++ b/linden/indra/llui/llscrollcontainer.cpp @@ -239,6 +239,23 @@ BOOL LLScrollableContainerView::handleScrollWheel( S32 x, S32 y, S32 clicks ) return TRUE; } +BOOL LLScrollableContainerView::handleHScrollWheel( S32 x, S32 y, S32 clicks ) +{ + for( S32 i = SCROLLBAR_COUNT - 1; i >= 0; i++ ) + { + // Note: tries horizontal and then vertical + + // Pretend the mouse is over the scrollbar + if( mScrollbar[i]->handleScrollWheel( 0, 0, clicks ) ) + { + return TRUE; + } + } + + // Eat scroll wheel event (to avoid scrolling nested containers?) + return TRUE; +} + BOOL LLScrollableContainerView::needsToScroll(S32 x, S32 y, LLScrollableContainerView::SCROLL_ORIENTATION axis) const { if(mScrollbar[axis]->getVisible()) diff --git a/linden/indra/llui/llscrollcontainer.h b/linden/indra/llui/llscrollcontainer.h index 70fc908..c18a0db 100644 --- a/linden/indra/llui/llscrollcontainer.h +++ b/linden/indra/llui/llscrollcontainer.h @@ -91,6 +91,7 @@ public: virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); virtual BOOL handleKeyHere(KEY key, MASK mask); virtual BOOL handleScrollWheel( S32 x, S32 y, S32 clicks ); + virtual BOOL handleHScrollWheel( S32 x, S32 y, S32 clicks ); virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void* cargo_data, diff --git a/linden/indra/llui/llview.cpp b/linden/indra/llui/llview.cpp index d4eda8f..507c5f5 100644 --- a/linden/indra/llui/llview.cpp +++ b/linden/indra/llui/llview.cpp @@ -960,6 +960,19 @@ BOOL LLView::handleScrollWheel(S32 x, S32 y, S32 clicks) return handled; } +BOOL LLView::handleHScrollWheel(S32 x, S32 y, S32 clicks) +{ + BOOL handled = FALSE; + if( getVisible() && getEnabled() ) + { + handled = childrenHandleHScrollWheel( x, y, clicks ) != NULL; + if( !handled && blockMouseEvent(x, y) ) + { + handled = TRUE; + } + } + return handled; +} BOOL LLView::handleRightMouseDown(S32 x, S32 y, MASK mask) { BOOL handled = childrenHandleRightMouseDown( x, y, mask ) != NULL; @@ -1032,6 +1045,34 @@ LLView* LLView::childrenHandleScrollWheel(S32 x, S32 y, S32 clicks) return handled_view; } +LLView* LLView::childrenHandleHScrollWheel(S32 x, S32 y, S32 clicks) +{ + LLView* handled_view = NULL; + if (getVisible() && getEnabled() ) + { + for ( child_list_iter_t child_it = mChildList.begin(); child_it != mChildList.end(); ++child_it) + { + LLView* viewp = *child_it; + S32 local_x = x - viewp->getRect().mLeft; + S32 local_y = y - viewp->getRect().mBottom; + if (viewp->pointInView(local_x, local_y) + && viewp->getVisible() + && viewp->getEnabled() + && viewp->handleHScrollWheel( local_x, local_y, clicks )) + { + if (sDebugMouseHandling) + { + sMouseHandlerMessage = std::string("->") + viewp->mName + sMouseHandlerMessage; + } + + handled_view = viewp; + break; + } + } + } + return handled_view; +} + LLView* LLView::childrenHandleHover(S32 x, S32 y, MASK mask) { LLView* handled_view = NULL; diff --git a/linden/indra/llui/llview.h b/linden/indra/llui/llview.h index 1c8ab31..9243f4f 100644 --- a/linden/indra/llui/llview.h +++ b/linden/indra/llui/llview.h @@ -473,6 +473,7 @@ public: /*virtual*/ BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleScrollWheel(S32 x, S32 y, S32 clicks); + /*virtual*/ BOOL handleHScrollWheel(S32 x, S32 y, S32 clicks); /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleRightMouseUp(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleToolTip(S32 x, S32 y, std::string& msg, LLRect* sticky_rect); // Display mToolTipMsg if no child handles it. @@ -613,6 +614,7 @@ protected: LLView* childrenHandleMiddleMouseDown(S32 x, S32 y, MASK mask); LLView* childrenHandleDoubleClick(S32 x, S32 y, MASK mask); LLView* childrenHandleScrollWheel(S32 x, S32 y, S32 clicks); + LLView* childrenHandleHScrollWheel(S32 x, S32 y, S32 clicks); LLView* childrenHandleRightMouseDown(S32 x, S32 y, MASK mask); LLView* childrenHandleRightMouseUp(S32 x, S32 y, MASK mask); -- cgit v1.1 From 9e11339ee6be8161c676fe16c34edb5bc089a9bf Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Tue, 22 Mar 2011 01:59:52 -0700 Subject: Support username logins on Linden grids. Seems to cover most edge cases with our current grid manager, but really exposes the weaknesses of not saving login info with the grid, usability-wise. (Note: autologin and the command line need to be tested) --- linden/indra/llui/lllineeditor.cpp | 20 +++++++++++++++++++- linden/indra/llui/lllineeditor.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 76b8927..a21ad5d 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -2696,7 +2696,6 @@ BOOL LLLineEditor::prevalidatePrintableNotPipe(const LLWString &str) return rv; } - // static BOOL LLLineEditor::prevalidatePrintableNoSpace(const LLWString &str) { @@ -2721,6 +2720,25 @@ BOOL LLLineEditor::prevalidatePrintableNoSpace(const LLWString &str) } // static +BOOL LLLineEditor::prevalidatePrintableSpace(const LLWString &str) +{ + BOOL rv = TRUE; + S32 len = str.length(); + if(len == 0) return rv; + while(len--) + { + if( !(LLStringOps::isAlnum((char)str[len]) || + LLStringOps::isPunct((char)str[len]) || + ' ' == str[len]) ) + { + rv = FALSE; + break; + } + } + return rv; +} + +// static BOOL LLLineEditor::prevalidateASCII(const LLWString &str) { BOOL rv = TRUE; diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index d217859..43ce869 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -253,6 +253,7 @@ public: static BOOL prevalidateAlphaNumSpace(const LLWString &str ); static BOOL prevalidatePrintableNotPipe(const LLWString &str); static BOOL prevalidatePrintableNoSpace(const LLWString &str); + static BOOL prevalidatePrintableSpace(const LLWString &str); static BOOL prevalidateASCII(const LLWString &str); static BOOL postvalidateFloat(const std::string &str); -- cgit v1.1 From e92f6be91988665591b2b99c698552d295e98fef Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 23 Mar 2011 22:00:03 -0700 Subject: Comboboxes can now use the font= xui setting --- linden/indra/llui/llcombobox.cpp | 25 ++++++++++++++++++++----- linden/indra/llui/llcombobox.h | 4 +++- linden/indra/llui/llscrolllistctrl.cpp | 28 +++++++++++++++++++++------- linden/indra/llui/llscrolllistctrl.h | 3 +++ 4 files changed, 47 insertions(+), 13 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llcombobox.cpp b/linden/indra/llui/llcombobox.cpp index be34325..a93dc9b 100644 --- a/linden/indra/llui/llcombobox.cpp +++ b/linden/indra/llui/llcombobox.cpp @@ -43,6 +43,7 @@ // newview includes #include "llbutton.h" +#include "llfont.h" #include "llkeyboard.h" #include "llscrolllistctrl.h" #include "llwindow.h" @@ -60,7 +61,7 @@ S32 MAX_COMBO_WIDTH = 500; static LLRegisterWidget r1("combo_box"); -LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std::string& label, +LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std::string& label, const LLFontGL* font, void (*commit_callback)(LLUICtrl*,void*), void *callback_userdata ) @@ -76,6 +77,15 @@ LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std:: mTextEntryCallback( NULL ), mLabel(label) { + if (font) + { + mGLFont = font; + } + else + { + mGLFont = LLFontGL::getFontSansSerifSmall(); + } + // Always use text box // Text label button mButton = new LLButton(mLabel, @@ -89,14 +99,14 @@ LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std:: mButton->setScaleImage(TRUE); mButton->setMouseDownCallback(onButtonDown); - mButton->setFont(LLFontGL::getFontSansSerifSmall()); + mButton->setFont(mGLFont); mButton->setFollows(FOLLOWS_LEFT | FOLLOWS_BOTTOM | FOLLOWS_RIGHT); mButton->setHAlign( LLFontGL::LEFT ); mButton->setRightHPad(2); addChild(mButton); // disallow multiple selection - mList = new LLScrollListCtrl(std::string("ComboBox"), LLRect(), + mList = new LLScrollListCtrl(std::string("ComboBox"), LLRect(), mGLFont, &LLComboBox::onItemSelected, this, FALSE); mList->setVisible(FALSE); mList->setBgWriteableColor( LLColor4(1,1,1,1) ); @@ -167,11 +177,14 @@ LLView* LLComboBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory * S32 max_chars = 20; node->getAttributeS32("max_chars", max_chars); + LLFontGL* font = LLView::selectFont(node); + LLUICtrlCallback callback = NULL; LLComboBox* combo_box = new LLComboBox(name, rect, label, + font, callback, NULL); combo_box->setAllowTextEntry(allow_text_entry, max_chars); @@ -540,7 +553,7 @@ void LLComboBox::updateLayout() mTextEntry = new LLLineEditor(std::string("combo_text_entry"), text_entry_rect, LLStringUtil::null, - LLFontGL::getFontSansSerifSmall(), + mGLFont, mMaxChars, onTextCommit, onTextEntry, @@ -1153,7 +1166,7 @@ LLFlyoutButton::LLFlyoutButton( const std::string& label, void (*commit_callback)(LLUICtrl*, void*) , void *callback_userdata) -: LLComboBox(name, rect, LLStringUtil::null, commit_callback, callback_userdata), +: LLComboBox(name, rect, LLStringUtil::null, NULL, commit_callback, callback_userdata), mToggleState(FALSE), mActionButton(NULL) { @@ -1214,6 +1227,8 @@ LLXMLNodePtr LLFlyoutButton::getXML(bool save_children) const } } + node->createChild("font", TRUE)->setStringValue(LLFontGL::nameFromFont(mGLFont)); + return node; } diff --git a/linden/indra/llui/llcombobox.h b/linden/indra/llui/llcombobox.h index 95ad17a..596f659 100644 --- a/linden/indra/llui/llcombobox.h +++ b/linden/indra/llui/llcombobox.h @@ -67,7 +67,8 @@ public: LLComboBox( const std::string& name, const LLRect &rect, - const std::string& label, + const std::string& label, + const LLFontGL* font = NULL, void (*commit_callback)(LLUICtrl*, void*) = NULL, void *callback_userdata = NULL ); @@ -190,6 +191,7 @@ protected: EPreferredPosition mListPosition; LLPointer mArrowImage; std::string mLabel; + const LLFontGL* mGLFont; private: S32 mButtonPadding; diff --git a/linden/indra/llui/llscrolllistctrl.cpp b/linden/indra/llui/llscrolllistctrl.cpp index 1248a9a..1b93abf 100644 --- a/linden/indra/llui/llscrolllistctrl.cpp +++ b/linden/indra/llui/llscrolllistctrl.cpp @@ -570,7 +570,7 @@ void LLScrollListItemSeparator::draw(const LLRect& rect, const LLColor4& fg_colo // LLScrollListCtrl //--------------------------------------------------------------------------- -LLScrollListCtrl::LLScrollListCtrl(const std::string& name, const LLRect& rect, +LLScrollListCtrl::LLScrollListCtrl(const std::string& name, const LLRect& rect, const LLFontGL* font, void (*commit_callback)(LLUICtrl* ctrl, void* userdata), void* callback_user_data, BOOL allow_multiple_selection, @@ -619,6 +619,15 @@ LLScrollListCtrl::LLScrollListCtrl(const std::string& name, const LLRect& rect, mOriginalSelection(-1), mDrewSelected(FALSE) { + if (font) + { + mGLFont = font; + } + else + { + mGLFont = LLFontGL::getFontSansSerifSmall(); + } + mItemListRect.setOriginAndSize( mBorderThickness, mBorderThickness, @@ -987,14 +996,14 @@ void LLScrollListCtrl::calcColumnWidths() column->setWidth(new_width); // update max content width for this column, by looking at all items - column->mMaxContentWidth = column->mHeader ? LLFontGL::getFontSansSerifSmall()->getWidth(column->mLabel) + mColumnPadding + HEADING_TEXT_PADDING : 0; + column->mMaxContentWidth = column->mHeader ? mGLFont->getWidth(column->mLabel) + mColumnPadding + HEADING_TEXT_PADDING : 0; item_list::iterator iter; for (iter = mItemList.begin(); iter != mItemList.end(); iter++) { LLScrollListCell* cellp = (*iter)->getColumn(column->mIndex); if (!cellp) continue; - column->mMaxContentWidth = llmax(LLFontGL::getFontSansSerifSmall()->getWidth(cellp->getValue().asString()) + mColumnPadding + COLUMN_TEXT_PADDING, column->mMaxContentWidth); + column->mMaxContentWidth = llmax(mGLFont->getWidth(cellp->getValue().asString()) + mColumnPadding + COLUMN_TEXT_PADDING, column->mMaxContentWidth); } max_item_width += column->mMaxContentWidth; @@ -1642,7 +1651,7 @@ LLScrollListItem* LLScrollListCtrl::addStringUUIDItem(const std::string& item_te if (getItemCount() < mMaxItemCount) { item = new LLScrollListItem( enabled, NULL, id ); - item->addColumn(item_text, LLResMgr::getInstance()->getRes(LLFONT_SANSSERIF_SMALL), column_width); + item->addColumn(item_text, mGLFont, column_width); addItem( item, pos ); } return item; @@ -2900,6 +2909,7 @@ LLView* LLScrollListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFac LLScrollListCtrl* scroll_list = new LLScrollListCtrl( name, rect, + NULL, callback, NULL, multi_select, @@ -3374,7 +3384,11 @@ LLScrollListItem* LLScrollListCtrl::addElement(const LLSD& value, EAddPosition p const LLFontGL *font = LLResMgr::getInstance()->getRes(fontname); if (!font) { - font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); + font = mGLFont; + if (!font) + { + font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); + } } U8 font_style = LLFontGL::getStyleFromString(fontstyle); @@ -3446,7 +3460,7 @@ LLScrollListItem* LLScrollListCtrl::addElement(const LLSD& value, EAddPosition p if (new_item->getColumn(column_idx) == NULL) { LLScrollListColumn* column_ptr = &column_it->second; - new_item->setColumn(column_idx, new LLScrollListText(LLStringUtil::null, LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ), column_ptr->getWidth(), LLFontGL::NORMAL)); + new_item->setColumn(column_idx, new LLScrollListText(LLStringUtil::null, mGLFont, column_ptr->getWidth(), LLFontGL::NORMAL)); } } @@ -3466,7 +3480,7 @@ LLScrollListItem* LLScrollListCtrl::addSimpleElement(const std::string& value, E LLScrollListItem *new_item = new LLScrollListItem(entry_id); - const LLFontGL *font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); + const LLFontGL *font = mGLFont; new_item->addColumn(value, font, getRect().getWidth()); diff --git a/linden/indra/llui/llscrolllistctrl.h b/linden/indra/llui/llscrolllistctrl.h index 4be7ff7..1b7105f 100644 --- a/linden/indra/llui/llscrolllistctrl.h +++ b/linden/indra/llui/llscrolllistctrl.h @@ -353,6 +353,7 @@ public: LLScrollListCtrl( const std::string& name, const LLRect& rect, + const LLFontGL* font, void (*commit_callback)(LLUICtrl*, void*), void* callback_userdata, BOOL allow_multiple_selection, @@ -694,6 +695,8 @@ private: // HACK: Did we draw one selected item this frame? BOOL mDrewSelected; + + const LLFontGL* mGLFont; }; // end class LLScrollListCtrl -- cgit v1.1 From 0de9bb9ceca63a66e396c009ed4e291d5c862de7 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Thu, 24 Mar 2011 02:18:34 -0700 Subject: Added a new default font size FontSansSerifBigger and fixed FontSansSerifBig not being named FontSansSerifLarge --- linden/indra/llui/llresmgr.cpp | 3 ++- linden/indra/llui/llresmgr.h | 3 ++- linden/indra/llui/llstyle.cpp | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llresmgr.cpp b/linden/indra/llui/llresmgr.cpp index 32d3d1f..f242f12 100644 --- a/linden/indra/llui/llresmgr.cpp +++ b/linden/indra/llui/llresmgr.cpp @@ -58,7 +58,8 @@ LLResMgr::LLResMgr() mUSAFonts[ LLFONT_OCRA ] = LLFontGL::getFontMonospace(); mUSAFonts[ LLFONT_SANSSERIF ] = LLFontGL::getFontSansSerif(); mUSAFonts[ LLFONT_SANSSERIF_SMALL ] = LLFontGL::getFontSansSerifSmall(); - mUSAFonts[ LLFONT_SANSSERIF_BIG ] = LLFontGL::getFontSansSerifBig(); + mUSAFonts[ LLFONT_SANSSERIF_BIGGER ]= LLFontGL::getFontSansSerifBigger(); + mUSAFonts[ LLFONT_SANSSERIF_LARGE ] = LLFontGL::getFontSansSerifLarge(); mUSAFonts[ LLFONT_SMALL ] = LLFontGL::getFontMonospace(); /* // USA Strings diff --git a/linden/indra/llui/llresmgr.h b/linden/indra/llui/llresmgr.h index d54505c..3008244 100644 --- a/linden/indra/llui/llresmgr.h +++ b/linden/indra/llui/llresmgr.h @@ -51,7 +51,8 @@ enum LLFONT_ID LLFONT_OCRA, LLFONT_SANSSERIF, LLFONT_SANSSERIF_SMALL, - LLFONT_SANSSERIF_BIG, + LLFONT_SANSSERIF_BIGGER, + LLFONT_SANSSERIF_LARGE, LLFONT_SMALL, LLFONT_COUNT // Number of values in this enum. Keep at end. }; diff --git a/linden/indra/llui/llstyle.cpp b/linden/indra/llui/llstyle.cpp index a716cbb..61a025e 100644 --- a/linden/indra/llui/llstyle.cpp +++ b/linden/indra/llui/llstyle.cpp @@ -128,9 +128,13 @@ void LLStyle::setFontName(const std::string& fontname) { mFontID = LLFONT_SMALL; } - else if ((fontname_lc == "sansserifbig")) + else if ((fontname_lc == "sansserifbigger")) { - mFontID = LLFONT_SANSSERIF_BIG; + mFontID = LLFONT_SANSSERIF_BIGGER; + } + else if ((fontname_lc == "sansserifhuge")) + { + mFontID = LLFONT_SANSSERIF_LARGE; } else if (fontname_lc == "small") { -- cgit v1.1 From fbceec72a5d9a8325234cf10313809de943300ad Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sat, 2 Apr 2011 14:24:54 -0500 Subject: Fixed a crash on login introduced by the new font size labels. --- linden/indra/llui/llresmgr.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llresmgr.cpp b/linden/indra/llui/llresmgr.cpp index f242f12..22610ca 100644 --- a/linden/indra/llui/llresmgr.cpp +++ b/linden/indra/llui/llresmgr.cpp @@ -422,7 +422,8 @@ const std::string LLFONT_ID_NAMES[] = std::string("OCRA"), std::string("SANSSERIF"), std::string("SANSSERIF_SMALL"), - std::string("SANSSERIF_BIG"), + std::string("SANSSERIF_BIGGER"), + std::string("SANSSERIF_LARGE"), std::string("SMALL"), }; -- cgit v1.1 From 8f27533c22c940ef22d2c9f5170742a488a1da9a Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Sun, 10 Apr 2011 22:56:40 -0700 Subject: Added search to the Debug Settings --- linden/indra/llui/llcombobox.cpp | 7 +++++++ linden/indra/llui/llcombobox.h | 1 + 2 files changed, 8 insertions(+) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llcombobox.cpp b/linden/indra/llui/llcombobox.cpp index a93dc9b..f3ef83e 100644 --- a/linden/indra/llui/llcombobox.cpp +++ b/linden/indra/llui/llcombobox.cpp @@ -591,6 +591,13 @@ void LLComboBox::updateLayout() } } + +void LLComboBox::getAllData(std::vector& item_list) const +{ + item_list = mList->getAllData(); +} + + void* LLComboBox::getCurrentUserdata() { LLScrollListItem* item = mList->getFirstSelected(); diff --git a/linden/indra/llui/llcombobox.h b/linden/indra/llui/llcombobox.h index 596f659..f92fe44 100644 --- a/linden/indra/llui/llcombobox.h +++ b/linden/indra/llui/llcombobox.h @@ -169,6 +169,7 @@ public: //======================================================================== + void getAllData(std::vector& item_list) const; void* getCurrentUserdata(); void setPrearrangeCallback( void (*cb)(LLUICtrl*,void*) ) { mPrearrangeCallback = cb; } -- cgit v1.1 From 84ba6c134cd7f75e8f3be86b444c9e7f57660c18 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Mon, 11 Apr 2011 20:11:26 -0700 Subject: Applied customizableTranslationMenu.patch by Grandma Bates for #533: Right Click menus are transparent on the login screen and #534: Right click menus aren't translatable --- linden/indra/llui/lllineeditor.cpp | 122 ++++++++++++++------- linden/indra/llui/lllineeditor.h | 6 +- linden/indra/llui/llmenugl.cpp | 219 +++++++++++++++++++++++++++++++++++-- linden/indra/llui/llmenugl.h | 114 ++++++++++++++++++- linden/indra/llui/lltexteditor.cpp | 111 ++++++++++++------- linden/indra/llui/lltexteditor.h | 1 + 6 files changed, 482 insertions(+), 91 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index a21ad5d..1d998be 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -55,17 +55,24 @@ #include "llui.h" #include "lluictrlfactory.h" #include "llclipboard.h" +#include "llmemberlistener.h" #include "../newview/lgghunspell_wrapper.h" #include "../newview/lltranslate.h" #include "../newview/llviewercontrol.h" #include "../newview/lggautocorrect.h" + // // Imported globals // // +// Globals + + + +// // Constants // @@ -90,6 +97,8 @@ static LLRegisterWidget r1("line_editor"); /* static */ LLPointer LLLineEditor::sImage; +typedef LLMemberListener text_edit_listener_t; + // // Member functions // @@ -214,46 +223,18 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, } mImage = sImage; - // make the popup menu available - //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); - LLMenuGL* menu = new LLMenuGL("wot"); - /*if (!menu) - { - menu = new LLMenuGL(LLStringUtil::null); - }*/ - - menu->append(new LLMenuItemCallGL("Cut", context_cut, context_enable_cut, this)); - menu->append(new LLMenuItemCallGL("Copy", context_copy, context_enable_copy, this)); - menu->append(new LLMenuItemCallGL("Paste", context_paste, context_enable_paste, this)); - menu->append(new LLMenuItemCallGL("Delete", context_delete, context_enable_delete, this)); - menu->append(new LLMenuItemCallGL("Select All", context_selectall, context_enable_selectall, this)); - - menu->appendSeparator("Transep"); - LLMenuGL* translatemenu = new LLMenuGL("Translate To"); - translatemenu->setCanTearOff(FALSE); - translatemenu->append(new LLMenuItemCallGL("en", "English", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("da", "Danish", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("de", "Deutsch(German)", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("es", "Spanish", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("fr", "French", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("it", "Italian", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("hu", "Hungarian", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("nl", "Dutch", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("pl", "Polish", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("pt", "Portugese", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("ru", "Russian", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("tr", "Turkish", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("uk", "Ukrainian", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("zh", "Chinese", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("ja", "Japanese", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("ko", "Korean", context_translate, context_enable_translate, this)); - - menu->appendMenu(translatemenu); - menu->appendSeparator("Spelsep"); - //menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); - menu->setCanTearOff(FALSE); - menu->setVisible(FALSE); + + LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_rightclick_text.xml",this); + if (!menu) + { + menu = new LLMenuGL(LLStringUtil::null); + } + + defineMenuCallbacks(menu); mPopupMenuHandle = menu->getHandle(); + menu->setBorderColor(gColors.getColor("MenuItemDisabledColor")); + menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); + } @@ -556,7 +537,7 @@ void LLLineEditor::context_translate(void * data) { LLLineEditor* line = (LLLineEditor*)data; LLMenuGL* menu = line ? (LLMenuGL*)(line->mPopupMenuHandle.get()) : NULL; - LLMenuGL* translate_menu = menu ? menu->getChildMenuByName("Translate To", TRUE) : NULL; + LLMenuGL* translate_menu = menu ? menu->getChildMenuByName("Translation Options", TRUE) : NULL; if (!translate_menu) { return; @@ -1318,6 +1299,67 @@ BOOL LLLineEditor::canCut() const return !mReadOnly && !mDrawAsterixes && hasSelection(); } +// method to define the associated callbacks +void LLLineEditor::defineMenuCallbacks(LLMenuGL* menu) { + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Cut Text", + this, + (void*)context_enable_cut); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Cut Text", + this, + (void*)context_cut); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Copy Text", + this, + (void*)context_enable_copy); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Copy Text", + this, + (void*)context_copy); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Paste Text", + this, + (void*)context_enable_paste); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Paste Text", + this, + (void*)context_paste); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Delete Text", + this, + (void*)context_enable_delete); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Delete Text", + this, + (void*)context_delete); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Select All Text", + this, + (void*)context_enable_selectall); + menu->setCtrlResponse(1+LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Select All Text", + this, + (void*)context_selectall); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Translate Text", + this, + (void*)context_enable_translate); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_TRANSLATE, + "Translate Text", + this, + (void*)context_translate); + + + +} + // cut selection to clipboard void LLLineEditor::cut() { diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 43ce869..54c0146 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -55,6 +55,7 @@ class LLFontGL; class LLLineEditorRollback; class LLButton; +class LLMenuGL; typedef BOOL (*LLLinePrevalidateFunc)(const LLWString &wstr); @@ -112,7 +113,8 @@ public: virtual BOOL canTranslate() const; virtual void insert(std::string what,S32 wher); - // LLEditMenuHandler overrides + // LLEditMenuHandler overrides and menu set up methods. + void defineMenuCallbacks(LLMenuGL* menu); virtual void cut(); virtual BOOL canCut() const; @@ -468,4 +470,6 @@ private: }; + + #endif // LL_LINEEDITOR_ diff --git a/linden/indra/llui/llmenugl.cpp b/linden/indra/llui/llmenugl.cpp index 91bb581..d5e1186 100644 --- a/linden/indra/llui/llmenugl.cpp +++ b/linden/indra/llui/llmenugl.cpp @@ -149,6 +149,18 @@ LLMenuItemGL::LLMenuItemGL( const std::string& name, const std::string& label, K setLabel( label ); } +LLMenuItemGL::~LLMenuItemGL() { + + // Delete all the entries in the mFutureCallbackRequests vector + for(std::vector::iterator iter= mFutureCallbackRequests.begin(); + iter!=mFutureCallbackRequests.end(); + ++iter) { + delete (*iter); + } + +} + + // virtual LLXMLNodePtr LLMenuItemGL::getXML(bool save_children) const { @@ -517,6 +529,18 @@ BOOL LLMenuItemGL::setLabelArg( const std::string& key, const LLStringExplicit& return TRUE; } + +void LLMenuItemGL::addCallbackType(U8 theType, + const std::string& name, + const std::string& userdata) { + + // Add the new callback information to the list of callbacks that are being tracked. + mFutureCallbackRequests.push_back(new LLCallbackInformation(theType,name,userdata)); + +} + + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Class LLMenuItemSeparatorGL // @@ -541,6 +565,12 @@ public: virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual U32 getNominalHeight( void ) const { return SEPARATOR_HEIGHT_PIXELS; } + + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { return FALSE; } ; + }; LLMenuItemSeparatorGL::LLMenuItemSeparatorGL( const std::string &name ) : @@ -726,6 +756,11 @@ public: } virtual void doIt( void ) {} virtual void draw( void ) {} + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { return FALSE; } ; + }; @@ -805,6 +840,8 @@ LLMenuItemCallGL::LLMenuItemCallGL(const std::string& name, if(!enabled) setEnabled(FALSE); } + + void LLMenuItemCallGL::setEnabledControl(std::string enabled_control, LLView *context) { // Register new listener @@ -921,6 +958,53 @@ BOOL LLMenuItemCallGL::handleAcceleratorKey( KEY key, MASK mask ) return LLMenuItemGL::handleAcceleratorKey(key, mask); } + + +// Method to add a callback function for the given type and name. +BOOL LLMenuItemCallGL::setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { + + // Loop through all of the menu items and check to see which ones + // match the name and callback type given. + BOOL result = FALSE; + std::vector::iterator item_iter; + for (item_iter = mFutureCallbackRequests.begin(); + item_iter != mFutureCallbackRequests.end(); + ++item_iter) + { + if( ((*item_iter)->getTypeOfCallback()==llMenuItemCallType) && + ((*item_iter)->getCallbackName()==name)) { + + // Found a match. Set the user data and then determine what type it is. + setUserData(user_data); + + if(llMenuItemCallType == LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK) + { + setMenuCallback((menu_callback)callback_fcn,user_data); + } + + else if (llMenuItemCallType == LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE) + { + setEnabledCallback((enabled_callback)callback_fcn); + } + + else if (llMenuItemCallType == LLCallbackInformation::LL_MENU_ITEM_CALL_GL_TRANSLATE) { + setName((*item_iter)->getCallbackUserData()); + setMenuCallback((menu_callback)callback_fcn,user_data); + } + + } + } + + + return result; + +} + + + ///============================================================================ /// Class LLMenuItemCheckGL ///============================================================================ @@ -1379,6 +1463,17 @@ void LLMenuItemBranchGL::openMenu() } +BOOL LLMenuItemBranchGL::setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { + + // Get the menu branch and set the callback functions on all its children. + return(getBranch()->setCtrlResponse(llMenuItemCallType,name,user_data,callback_fcn)); + +} + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Class LLMenuItemBranchDownGL // @@ -1982,13 +2077,31 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory LLSimpleListener* callback = parent->getListenerByName(callback_name); - if (!callback) + if (callback) { - lldebugs << "Ignoring \"on_click\" \"" << item_name << "\" because \"" << callback_name << "\" is not registered" << llendl; - continue; + new_item->addListener(callback, "on_click", callback_data); + } + else { + + // A callback for this item has not yet been + // specified. Add it to the list of options + // that do not yet have callbacks. + if (call_child->hasAttribute("translate")) + { + new_item->addCallbackType + (LLCallbackInformation::LL_MENU_ITEM_CALL_GL_TRANSLATE, + item_name, + callback_data); + } + + else + { + new_item->addCallbackType + (LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + item_name, + callback_data); + } } - - new_item->addListener(callback, "on_click", callback_data); } if (call_child->hasName("on_enable")) { @@ -2016,13 +2129,22 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory LLSimpleListener* callback = parent->getListenerByName(callback_name); - if (!callback) + if (callback) { - lldebugs << "Ignoring \"on_enable\" \"" << item_name << "\" because \"" << callback_name << "\" is not registered" << llendl; - continue; + new_item->addListener(callback, "on_build", userdata); + } else { + + // A callback for this item has not yet been + // specified. Add it to the list of options + // that do not yet have callbacks. + + new_item->addCallbackType + (LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + item_name, + callback_data); } - new_item->addListener(callback, "on_build", userdata); + } else if (call_child->hasAttribute("control")) { @@ -2188,7 +2310,7 @@ LLView* LLMenuGL::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *fa LLColor4 color(0,0,0,1); if (opaque && LLUICtrlFactory::getAttributeColor(node,"color", color)) { - menu->setBackgroundColor(color); + menu->setBackgroundColor(color); } BOOL create_jump_keys = FALSE; @@ -2977,7 +3099,8 @@ void LLMenuGL::draw( void ) if( mBgVisible ) { - gl_rect_2d( 0, getRect().getHeight(), getRect().getWidth(), 0, mBackgroundColor ); + gl_rect_2d( -1, getRect().getHeight()+2, getRect().getWidth()+2, -2, mBorderColor,FALSE); + gl_rect_2d( 0, getRect().getHeight(), getRect().getWidth(), 0, mBackgroundColor ); } LLView::draw(); } @@ -3033,6 +3156,41 @@ LLMenuGL* LLMenuGL::getChildMenuByName(const std::string& name, BOOL recurse) co return NULL; } + +void LLMenuGL::setBackgroundColor( const LLColor4& color ) { + + mBackgroundColor = color; + item_list_t::iterator item_iter; + for (item_iter = mItems.begin(); item_iter != mItems.end(); ++item_iter) + { + if((*item_iter)->getType()=="menu") + { + LLMenuItemBranchGL *menuBranchItem = (LLMenuItemBranchGL*)(*item_iter); + menuBranchItem->getBranch()->setBackgroundColor(color); + } + } + + +} + + +void LLMenuGL::setBorderColor( const LLColor4& color ) { + + mBorderColor = color; + item_list_t::iterator item_iter; + for (item_iter = mItems.begin(); item_iter != mItems.end(); ++item_iter) + { + if((*item_iter)->getType()=="menu") + { + LLMenuItemBranchGL *menuBranchItem = (LLMenuItemBranchGL*)(*item_iter); + menuBranchItem->getBranch()->setBorderColor(color); + } + } + + +} + + BOOL LLMenuGL::clearHoverItem() { for ( child_list_const_iter_t child_it = getChildList()->begin(); child_it != getChildList()->end(); ++child_it) @@ -3098,6 +3256,26 @@ void LLMenuGL::showPopup(LLView* spawning_view, LLMenuGL* menu, S32 x, S32 y) menu->getParent()->sendChildToFront(menu); } + +BOOL LLMenuGL::setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) +{ + + // Go through all of the children on this menu and set the callback function. + BOOL result = FALSE; + item_list_t::iterator item_iter; + for (item_iter = mItems.begin(); item_iter != mItems.end(); ++item_iter) + { + result |= (*item_iter)->setCtrlResponse(llMenuItemCallType,name,user_data,callback_fcn); + } + + return result; +} + + + //----------------------------------------------------------------------------- // class LLPieMenuBranch // A branch to another pie menu @@ -3117,6 +3295,12 @@ public: LLPieMenu* getBranch() { return mBranch; } + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { return FALSE; } ; + + protected: LLPieMenu* mBranch; }; @@ -4581,3 +4765,16 @@ void LLTearOffMenu::onClose(bool app_quitting) destroy(); } + +///============================================================================ +/// Class LLCallbackInformation +///============================================================================ + +LLCallbackInformation::LLCallbackInformation(U8 theType, + const std::string& theName, + const std::string& userData) + : callbackName(theName), + callbackUserData(userData) +{ + setTypeOfCallback(theType); +} diff --git a/linden/indra/llui/llmenugl.h b/linden/indra/llui/llmenugl.h index 63f9d55..9a9d1b0 100644 --- a/linden/indra/llui/llmenugl.h +++ b/linden/indra/llui/llmenugl.h @@ -70,6 +70,57 @@ typedef BOOL (*check_callback)(void*); // contents. Put the contents of the label in the provided parameter. typedef void (*label_callback)(std::string&,void*); + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Class LLCallbackInformation +// +// The LLCallbackInformation class is used to keep track of callback +// information for menus that might be requested at a future time. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +class LLCallbackInformation +{ + +public : + + // Constants used for keeping track of what type of callback is required. + static const U8 LL_MENU_ITEM_CALL_GL_NONE = 0; + static const U8 LL_MENU_ITEM_CALL_GL_ON_CLICK = 1; + static const U8 LL_MENU_ITEM_CALL_GL_ON_ENABLE = 2; + static const U8 LL_MENU_ITEM_CALL_GL_TRANSLATE = 3; + + + LLCallbackInformation(U8 theType=LLCallbackInformation::LL_MENU_ITEM_CALL_GL_NONE, + const std::string& theName = LLStringUtil::null, + const std::string& userData = LLStringUtil::null); + ~LLCallbackInformation() {}; + + void setTypeOfCallback(U8 theType) {typeOfCallback = theType; } + void setCallbackName(const std::string& name) {callbackName = name; } + void setCallbackUserData(const std::string& userdata) {callbackUserData = userdata; } + + U8 getTypeOfCallback() {return(typeOfCallback); } + const std::string& getCallbackName() {return(callbackName); } + const std::string& getCallbackUserData() {return(callbackUserData); } + + BOOL isTypeMatch(U8 type) { return(type == typeOfCallback);} + BOOL isNameMatch(const std::string& name) { return(name == callbackName);} + +protected: + +private: + + U8 typeOfCallback; + std::string callbackName; + std::string callbackUserData; + +}; + + + + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Class LLMenuItemGL // @@ -79,6 +130,7 @@ typedef void (*label_callback)(std::string&,void*); class LLMenuItemGL : public LLView { public: + // static functions to control the global color scheme. static void setEnabledColor( const LLColor4& color ) { sEnabledColor = color; } static const LLColor4& getEnabledColor() { return sEnabledColor; } @@ -90,7 +142,7 @@ public: static const LLColor4& getHighlightFGColor() { return sHighlightForeground; } LLMenuItemGL( const std::string& name, const std::string& label, KEY key = KEY_NONE, MASK = MASK_NONE ); - virtual ~LLMenuItemGL() {}; + virtual ~LLMenuItemGL(); virtual void setValue(const LLSD& value) { setLabel(value.asString()); } @@ -174,6 +226,14 @@ public: void setDrawTextDisabled(BOOL disabled) { mDrawTextDisabled = disabled; } BOOL getDrawTextDisabled() const { return mDrawTextDisabled; } + // functionality for adding callbacks after the menu is constucted + void addCallbackType(U8 theType,const std::string& name,const std::string& userdata); + + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) = 0; + protected: void setHover(BOOL hover) { mGotHover = hover; } @@ -194,6 +254,11 @@ protected: LLUIString mDrawBranchLabel; BOOL mHighlight; + + // variables used for tracking callback types that will be + // requested after the widget is in place. + std::vector mFutureCallbackRequests; + private: static LLColor4 sEnabledColor; static LLColor4 sDisabledColor; @@ -214,6 +279,7 @@ private: BOOL mDrawTextDisabled; KEY mJumpKey; + }; @@ -262,6 +328,7 @@ public: KEY key = KEY_NONE, MASK mask = MASK_NONE, BOOL enabled = TRUE, on_disabled_callback on_disabled_c = NULL); + virtual LLXMLNodePtr getXML(bool save_children = true) const; virtual std::string getType() const { return "call"; } @@ -288,6 +355,13 @@ public: //virtual void draw(); + // Functionality for tracking callback types for setting after widget is in place. + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn); + + private: menu_callback mCallback; @@ -382,6 +456,12 @@ public: // LLView Functionality //virtual void draw( void ); + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { return FALSE; } ; + + private: BOOL* mToggle; }; @@ -434,8 +514,10 @@ public: // background colors static void setDefaultBackgroundColor( const LLColor4& color ) { sDefaultBackgroundColor = color; } - void setBackgroundColor( const LLColor4& color ) { mBackgroundColor = color; } + void setBackgroundColor( const LLColor4& color ); + void setBorderColor( const LLColor4& color ); const LLColor4& getBackgroundColor() const { return mBackgroundColor; } + const LLColor4& getBorderColor() const { return mBorderColor; } void setBackgroundVisible( BOOL b ) { mBgVisible = b; } void setCanTearOff(BOOL tear_off, LLHandle parent_floater_handle = LLHandle()); @@ -525,6 +607,8 @@ public: static BOOL getKeyboardMode() { return sKeyboardMode; } static class LLMenuHolderGL* sMenuContainer; + + BOOL setCtrlResponse(U8 llMenuItemCallType,const std::string& name,void* user_data,void *callback_fcn); protected: void createSpilloverBranch(); @@ -547,6 +631,7 @@ private: static BOOL sKeyboardMode; LLColor4 mBackgroundColor; + LLColor4 mBorderColor; BOOL mBgVisible; LLMenuItemGL* mParentMenuItem; LLUIString mLabel; @@ -623,6 +708,12 @@ public: virtual LLView* getChildView(const std::string& name, BOOL recurse = TRUE, BOOL create_if_missing = TRUE) const; + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn); + + private: LLHandle mBranch; }; // end class LLMenuItemBranchGL @@ -668,6 +759,12 @@ public: void show(S32 x, S32 y, BOOL mouse_down); void hide(BOOL item_selected); + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { return FALSE; } ; + + private: LLMenuItemGL *pieItemFromXY(S32 x, S32 y); S32 pieItemIndexFromXY(S32 x, S32 y); @@ -729,6 +826,12 @@ public: void resetMenuTrigger() { mAltKeyTrigger = FALSE; } + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { return FALSE; } ; + + private: void checkMenuTrigger(); @@ -814,6 +917,12 @@ public: virtual void draw(void); virtual U32 getNominalHeight() const; + virtual BOOL setCtrlResponse(U8 llMenuItemCallType, + const std::string& name, + void* user_data, + void *callback_fcn) { return FALSE; } ; + + private: LLHandle mParentHandle; }; @@ -832,4 +941,5 @@ private: LLEditMenuHandlerMgr() {}; }; + #endif // LL_LLMENUGL_H diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 004d063..0cafd4b 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -385,43 +385,18 @@ LLTextEditor::LLTextEditor( mHTML.clear(); // make the popup menu available - //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); - LLMenuGL* menu = new LLMenuGL("wot"); - /*if (!menu) - { - menu = new LLMenuGL(LLStringUtil::null); - }*/ - menu->append(new LLMenuItemCallGL("Cut", context_cut, context_enable_cut, this)); - menu->append(new LLMenuItemCallGL("Copy", context_copy, context_enable_copy, this)); - menu->append(new LLMenuItemCallGL("Paste", context_paste, context_enable_paste, this)); - menu->append(new LLMenuItemCallGL("Delete", context_delete, context_enable_delete, this)); - menu->append(new LLMenuItemCallGL("Select All", context_selectall, context_enable_selectall, this)); - menu->appendSeparator("Transep"); - LLMenuGL* translatemenu = new LLMenuGL("Translate To"); - translatemenu->setCanTearOff(FALSE); - translatemenu->append(new LLMenuItemCallGL("en", "English", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("da", "Danish", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("de", "Deutsch(German)", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("es", "Spanish", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("fr", "French", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("it", "Italian", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("hu", "Hungarian", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("nl", "Dutch", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("pl", "Polish", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("pt", "Portugese", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("ru", "Russian", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("tr", "Turkish", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("uk", "Ukrainian", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("zh", "Chinese", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("ja", "Japanese", context_translate, context_enable_translate, this)); - translatemenu->append(new LLMenuItemCallGL("ko", "Korean", context_translate, context_enable_translate, this)); - - menu->appendMenu(translatemenu); - menu->appendSeparator("Spelsep"); - //menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); - menu->setCanTearOff(FALSE); - menu->setVisible(FALSE); + + LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_rightclick_text.xml",this); + if (!menu) + { + menu = new LLMenuGL(LLStringUtil::null); + } + + defineMenuCallbacks(menu); mPopupMenuHandle = menu->getHandle(); + menu->setBorderColor(gColors.getColor("MenuItemDisabledColor")); + menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); + } LLTextEditor::~LLTextEditor() @@ -476,7 +451,7 @@ void LLTextEditor::context_translate(void * data) { LLTextEditor* line = (LLTextEditor*)data; LLMenuGL* menu = line ? (LLMenuGL*)(line->mPopupMenuHandle.get()) : NULL; - LLMenuGL* translate_menu = menu ? menu->getChildMenuByName("Translate To", TRUE) : NULL; + LLMenuGL* translate_menu = menu ? menu->getChildMenuByName("Translation Options", TRUE) : NULL; if (!translate_menu) { return; @@ -615,6 +590,68 @@ void LLTextEditor::context_selectall(void* data) if(line)line->selectAll(); } +// method to define the associated callbacks +void LLTextEditor::defineMenuCallbacks(LLMenuGL* menu) { + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Cut Text", + this, + (void*)context_enable_cut); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Cut Text", + this, + (void*)context_cut); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Copy Text", + this, + (void*)context_enable_copy); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Copy Text", + this, + (void*)context_copy); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Paste Text", + this, + (void*)context_enable_paste); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Paste Text", + this, + (void*)context_paste); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Delete Text", + this, + (void*)context_enable_delete); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Delete Text", + this, + (void*)context_delete); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Select All Text", + this, + (void*)context_enable_selectall); + menu->setCtrlResponse(1+LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, + "Select All Text", + this, + (void*)context_selectall); + + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, + "Translate Text", + this, + (void*)context_enable_translate); + menu->setCtrlResponse(LLCallbackInformation::LL_MENU_ITEM_CALL_GL_TRANSLATE, + "Translate Text", + this, + (void*)context_translate); + + + +} + + void LLTextEditor::setTrackColor( const LLColor4& color ) { mScrollbar->setTrackColor(color); diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index f2a831b..1d7a735 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -167,6 +167,7 @@ public: static void spell_add(void* data); static void spell_show(void* data); std::vector getMisspelledWordsPositions(); + void defineMenuCallbacks(LLMenuGL* menu); void selectNext(const std::string& search_text_in, BOOL case_insensitive, BOOL wrap = TRUE); BOOL replaceText(const std::string& search_text, const std::string& replace_text, BOOL case_insensitive, BOOL wrap = TRUE); -- cgit v1.1 From cf8be1ce5466f1005f89e0a49693e6450e280fa3 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 13 Apr 2011 16:19:40 -0700 Subject: Fixed crash in spellchecking when deleting selections while lagging --- linden/indra/llui/lllineeditor.cpp | 31 +++++++++++++++++-------------- linden/indra/llui/lltexteditor.cpp | 23 +++++++++++++---------- 2 files changed, 30 insertions(+), 24 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 1d998be..7618985 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -604,21 +604,24 @@ std::vector LLLineEditor::getMisspelledWordsPositions() { wordEnd++; } - //got a word :D - std::string selectedWord(std::string(text.begin(), - text.end()).substr(wordStart,wordEnd-wordStart)); - if(!glggHunSpell->isSpelledRight(selectedWord)) - { - //misspelled word here, and you have just right clicked on it! - //get the center of this word.. - //S32 center = llround( (wordEnd-wordStart)/2 ) + wordStart; - //turn this cursor position into a pixel pos - //center = findPixelNearestPos(center-getCursor()); + //got a word? -- MC + if (wordStart != wordEnd) + { + std::string selectedWord(std::string(text.begin(), + text.end()).substr(wordStart,wordEnd-wordStart)); + + if(!selectedWord.empty() && !glggHunSpell->isSpelledRight(selectedWord)) + { + //misspelled word here, and you have just right clicked on it! + //get the center of this word.. + //S32 center = llround( (wordEnd-wordStart)/2 ) + wordStart; + //turn this cursor position into a pixel pos + //center = findPixelNearestPos(center-getCursor()); - thePosesOfBadWords.push_back( - wordStart); - thePosesOfBadWords.push_back(wordEnd); + thePosesOfBadWords.push_back(wordStart); + thePosesOfBadWords.push_back(wordEnd); + } } } wordEnd++; @@ -2056,7 +2059,7 @@ void LLLineEditor::drawMisspelled(LLRect background) } } - if (glggHunSpell->getSpellCheckHighlight()) + if (!misspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) { for (int i =0; i<(int)misspellLocations.size(); i++) { diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 0cafd4b..963eede 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -527,17 +527,20 @@ std::vector LLTextEditor::getMisspelledWordsPositions() { wordEnd++; } - //got a word :D - - std::string regText(text.begin(),text.end()); - std::string selectedWord(regText.substr(wordStart,wordEnd-wordStart)); - if(!glggHunSpell->isSpelledRight(selectedWord)) - { - //misspelled word here, and you have just right clicked on it + //got a word? -- MC + if (wordStart != wordEnd) + { + std::string regText(text.begin(),text.end()); + std::string selectedWord(regText.substr(wordStart,wordEnd-wordStart)); + + if(!selectedWord.empty() && !glggHunSpell->isSpelledRight(selectedWord)) + { + //misspelled word here, and you have just right clicked on it - thePosesOfBadWords.push_back(wordStart); - thePosesOfBadWords.push_back(wordEnd); + thePosesOfBadWords.push_back(wordStart); + thePosesOfBadWords.push_back(wordEnd); + } } } wordEnd++; @@ -3281,7 +3284,7 @@ void LLTextEditor::drawMisspelled() } } //draw - if (glggHunSpell->getSpellCheckHighlight()) + if (!misspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) { for (int i = 0; i<(int)misspellLocations.size() ;i++) { -- cgit v1.1 From 6cbe685381ddafa788bb96e0865dc938ee2521d1 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 13 Apr 2011 16:56:48 -0700 Subject: Don't create temporary vectors in spellchecking on every draw --- linden/indra/llui/lllineeditor.cpp | 19 +++++++++---------- linden/indra/llui/lllineeditor.h | 5 +++-- linden/indra/llui/lltexteditor.cpp | 20 ++++++++++---------- linden/indra/llui/lltexteditor.h | 8 +++++--- 4 files changed, 27 insertions(+), 25 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 7618985..719b71a 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -580,9 +580,9 @@ void LLLineEditor::spell_show(void * data) } } -std::vector LLLineEditor::getMisspelledWordsPositions() +void LLLineEditor::getMisspelledWordsPositions(std::vector& misspell_positions) { - std::vector thePosesOfBadWords; + misspell_positions.clear(); const LLWString& text = mText.getWString(); //llinfos << "end of box is at " << cursorloc << " and end of text is at " << text.length() << llendl; @@ -619,14 +619,13 @@ std::vector LLLineEditor::getMisspelledWordsPositions() //turn this cursor position into a pixel pos //center = findPixelNearestPos(center-getCursor()); - thePosesOfBadWords.push_back(wordStart); - thePosesOfBadWords.push_back(wordEnd); + misspell_positions.push_back(wordStart); + misspell_positions.push_back(wordEnd); } } } wordEnd++; } - return thePosesOfBadWords; } void LLLineEditor::spell_add(void* data) @@ -2055,16 +2054,16 @@ void LLLineEditor::drawMisspelled(LLRect background) mStartSpellHere = newStartSpellHere; mEndSpellHere = newStopSpellHere; resetSpellDirty(); - misspellLocations=getMisspelledWordsPositions(); + getMisspelledWordsPositions(mMisspellLocations); } } - if (!misspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) + if (!mMisspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) { - for (int i =0; i<(int)misspellLocations.size(); i++) + for (int i =0; i<(int)mMisspellLocations.size(); i++) { - S32 wstart =findPixelNearestPos( misspellLocations[i]-getCursor()); - S32 wend = findPixelNearestPos(misspellLocations[++i]-getCursor()); + S32 wstart =findPixelNearestPos( mMisspellLocations[i]-getCursor()); + S32 wend = findPixelNearestPos(mMisspellLocations[++i]-getCursor()); S32 maxw = getRect().getWidth(); if (wend > maxw) diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 54c0146..677d1b1 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -154,7 +154,8 @@ public: static void spell_show(void* data); static void spell_add(void* data); - std::vector getMisspelledWordsPositions(); + void getMisspelledWordsPositions(std::vector& misspell_positions); + // view overrides virtual void draw(); void autoCorrectText(); @@ -305,7 +306,7 @@ protected: std::string mPrevText; // Saved string for 'ESC' revert LLUIString mLabel; // text label that is visible when no user text provided std::string mPrevSpelledText; // saved string so we know whether to respell or not - std::vector misspellLocations; // where all the mispelled words are + std::vector mMisspellLocations; // where all the mispelled words are S32 mStartSpellHere; // the position of the first char on the screen, stored so we know when to update S32 mEndSpellHere; // the location of the last char on the screen BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 963eede..5bddcbc 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -505,10 +505,10 @@ void LLTextEditor::spell_show(void * data) } } -std::vector LLTextEditor::getMisspelledWordsPositions() +void LLTextEditor::getMisspelledWordsPositions(std::vector& misspell_positions) { resetSpellDirty(); - std::vector thePosesOfBadWords; + misspell_positions.clear(); LLWString& text = mWText; S32 wordStart=0; S32 wordEnd=spellStart;//start at the scroll start @@ -538,15 +538,15 @@ std::vector LLTextEditor::getMisspelledWordsPositions() { //misspelled word here, and you have just right clicked on it - thePosesOfBadWords.push_back(wordStart); - thePosesOfBadWords.push_back(wordEnd); + misspell_positions.push_back(wordStart); + misspell_positions.push_back(wordEnd); } } } wordEnd++; } - return thePosesOfBadWords; } + void LLTextEditor::spell_add(void* data) { SpellMenuBind* tempBind = (SpellMenuBind*)data; @@ -3280,16 +3280,16 @@ void LLTextEditor::drawMisspelled() { spellEnd = newSpellEnd; spellStart = newSpellStart; - misspellLocations = getMisspelledWordsPositions(); + getMisspelledWordsPositions(mMisspellLocations); } } //draw - if (!misspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) + if (!mMisspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) { - for (int i = 0; i<(int)misspellLocations.size() ;i++) + for (int i = 0; i<(int)mMisspellLocations.size() ;i++) { - S32 wstart = misspellLocations[i]; - S32 wend = misspellLocations[++i]; + S32 wstart = mMisspellLocations[i]; + S32 wend = mMisspellLocations[++i]; //start curor code mod const LLWString &text = mWText; const S32 text_len = getLength(); diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index 1d7a735..759cd69 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -166,8 +166,10 @@ public: static void spell_correct(void* data); static void spell_add(void* data); static void spell_show(void* data); - std::vector getMisspelledWordsPositions(); - void defineMenuCallbacks(LLMenuGL* menu); + + void getMisspelledWordsPositions(std::vector& misspell_positions); + + void defineMenuCallbacks(LLMenuGL* menu); void selectNext(const std::string& search_text_in, BOOL case_insensitive, BOOL wrap = TRUE); BOOL replaceText(const std::string& search_text, const std::string& replace_text, BOOL case_insensitive, BOOL wrap = TRUE); @@ -535,7 +537,7 @@ private: LLWString mPrevSpelledText; // saved string so we know whether to respell or not S32 spellStart; S32 spellEnd; - std::vector misspellLocations; // where all the mispelled words are + std::vector mMisspellLocations; // where all the mispelled words are BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field BOOL mAllowTranslate; // set in xui as "allow_translate". -- cgit v1.1 From 36934849d9bc886ccff1d33316ef9f5e2278ce9b Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 13 Apr 2011 17:23:32 -0700 Subject: Don't create temporary LLRect objects for spellchecking in every draw either --- linden/indra/llui/lllineeditor.cpp | 2 +- linden/indra/llui/lllineeditor.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 719b71a..453bb50 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -2038,7 +2038,7 @@ void LLLineEditor::autoCorrectText() } } -void LLLineEditor::drawMisspelled(LLRect background) +void LLLineEditor::drawMisspelled(const LLRect& background) { if (!mReadOnly && mSpellCheckable) { diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 677d1b1..b3e21ce 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -159,7 +159,7 @@ public: // view overrides virtual void draw(); void autoCorrectText(); - void drawMisspelled(LLRect background); + void drawMisspelled(const LLRect& background); virtual void reshape(S32 width,S32 height,BOOL called_from_parent=TRUE); virtual void onFocusReceived(); virtual void onFocusLost(); -- cgit v1.1