diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llui/lllineeditor.cpp | 207 |
1 files changed, 116 insertions, 91 deletions
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, | |||
171 | mHaveHistory(FALSE), | 171 | mHaveHistory(FALSE), |
172 | mImage( sImage ), | 172 | mImage( sImage ), |
173 | mReplaceNewlinesWithSpaces( TRUE ), | 173 | mReplaceNewlinesWithSpaces( TRUE ), |
174 | mOverRideAndShowMisspellings( FALSE ) | 174 | mShowMisspellings( FALSE ) |
175 | { | 175 | { |
176 | llassert( max_length_bytes > 0 ); | 176 | llassert( max_length_bytes > 0 ); |
177 | 177 | ||
@@ -546,19 +546,19 @@ void LLLineEditor::spell_show(void * data) | |||
546 | SpellMenuBind* tempBind = (SpellMenuBind*)data; | 546 | SpellMenuBind* tempBind = (SpellMenuBind*)data; |
547 | LLLineEditor* line = tempBind->origin; | 547 | LLLineEditor* line = tempBind->origin; |
548 | 548 | ||
549 | if(tempBind && line) | 549 | if( tempBind && line) |
550 | { | 550 | { |
551 | if(tempBind->word=="Show Misspellings") | 551 | if (tempBind->word=="Show Misspellings") |
552 | { | 552 | { |
553 | line->setOverRideAndShowMisspellings(TRUE); | 553 | line->setShowMisspellings(TRUE); |
554 | }else | 554 | } |
555 | else | ||
555 | { | 556 | { |
556 | line->setOverRideAndShowMisspellings(FALSE); | 557 | line->setShowMisspellings(FALSE); |
557 | } | 558 | } |
558 | } | 559 | } |
559 | |||
560 | |||
561 | } | 560 | } |
561 | |||
562 | std::vector<S32> LLLineEditor::getMisspelledWordsPositions() | 562 | std::vector<S32> LLLineEditor::getMisspelledWordsPositions() |
563 | { | 563 | { |
564 | std::vector<S32> thePosesOfBadWords; | 564 | std::vector<S32> thePosesOfBadWords; |
@@ -604,25 +604,29 @@ std::vector<S32> LLLineEditor::getMisspelledWordsPositions() | |||
604 | } | 604 | } |
605 | return thePosesOfBadWords; | 605 | return thePosesOfBadWords; |
606 | } | 606 | } |
607 | |||
607 | void LLLineEditor::spell_add(void* data) | 608 | void LLLineEditor::spell_add(void* data) |
608 | { | 609 | { |
609 | SpellMenuBind* tempBind = (SpellMenuBind*)data; | 610 | SpellMenuBind* tempBind = (SpellMenuBind*)data; |
610 | if(tempBind) | 611 | if (tempBind) |
611 | { | 612 | { |
612 | glggHunSpell->addWordToCustomDictionary(tempBind->word); | 613 | glggHunSpell->addWordToCustomDictionary(tempBind->word); |
613 | tempBind->origin->mPrevSpelledText="";//make it update | 614 | tempBind->origin->mPrevSpelledText="";//make it update |
614 | } | 615 | } |
615 | } | 616 | } |
617 | |||
616 | void LLLineEditor::context_paste(void* data) | 618 | void LLLineEditor::context_paste(void* data) |
617 | { | 619 | { |
618 | LLLineEditor* line = (LLLineEditor*)data; | 620 | LLLineEditor* line = (LLLineEditor*)data; |
619 | if(line)line->paste(); | 621 | if(line)line->paste(); |
620 | } | 622 | } |
623 | |||
621 | void LLLineEditor::context_delete(void* data) | 624 | void LLLineEditor::context_delete(void* data) |
622 | { | 625 | { |
623 | LLLineEditor* line = (LLLineEditor*)data; | 626 | LLLineEditor* line = (LLLineEditor*)data; |
624 | if(line)line->doDelete(); | 627 | if(line)line->doDelete(); |
625 | } | 628 | } |
629 | |||
626 | void LLLineEditor::context_selectall(void* data) | 630 | void LLLineEditor::context_selectall(void* data) |
627 | { | 631 | { |
628 | LLLineEditor* line = (LLLineEditor*)data; | 632 | LLLineEditor* line = (LLLineEditor*)data; |
@@ -728,16 +732,17 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) | |||
728 | S32 wordStart = 0; | 732 | S32 wordStart = 0; |
729 | S32 wordEnd = calculateCursorFromMouse(x); | 733 | S32 wordEnd = calculateCursorFromMouse(x); |
730 | 734 | ||
731 | |||
732 | LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); | 735 | LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); |
733 | if (menu) | 736 | if (menu) |
734 | { | 737 | { |
735 | if(menu->isOpen()) | 738 | if(menu->isOpen()) |
739 | { | ||
736 | menu->setVisible(FALSE); | 740 | menu->setVisible(FALSE); |
737 | for(int i = 0;i<(int)suggestionMenuItems.size();i++) | 741 | } |
742 | for (int i = 0;i<(int)suggestionMenuItems.size();i++) | ||
738 | { | 743 | { |
739 | SpellMenuBind * tempBind = suggestionMenuItems[i]; | 744 | SpellMenuBind * tempBind = suggestionMenuItems[i]; |
740 | if(tempBind) | 745 | if (tempBind) |
741 | { | 746 | { |
742 | menu->remove((LLMenuItemCallGL *)tempBind->menuItem); | 747 | menu->remove((LLMenuItemCallGL *)tempBind->menuItem); |
743 | ((LLMenuItemCallGL *)tempBind->menuItem)->die(); | 748 | ((LLMenuItemCallGL *)tempBind->menuItem)->die(); |
@@ -748,69 +753,74 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) | |||
748 | } | 753 | } |
749 | suggestionMenuItems.clear(); | 754 | suggestionMenuItems.clear(); |
750 | 755 | ||
751 | menu->setItemVisible("Translate To",!mReadOnly); | 756 | menu->setItemVisible("Translate To", !mReadOnly); |
752 | menu->setItemVisible("Transep",!mReadOnly); | 757 | menu->setItemVisible("Transep", !mReadOnly); |
753 | 758 | ||
754 | const LLWString& text = mText.getWString(); | 759 | // spell_check="true" in xui |
755 | if(( LLTextEditor::isPartOfWord( text[wordEnd] ) ) | 760 | if (!mReadOnly && mShowMisspellings) |
756 | &&(!mReadOnly)) | ||
757 | { | 761 | { |
758 | // Select word the cursor is over | 762 | const LLWString& text = mText.getWString(); |
759 | while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) | ||
760 | { | ||
761 | wordEnd--; | ||
762 | } | ||
763 | wordStart=wordEnd; | ||
764 | //startSelection(); | ||
765 | 763 | ||
766 | while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) | 764 | // search for word matches |
765 | if (LLTextEditor::isPartOfWord(text[wordEnd])) | ||
767 | { | 766 | { |
768 | wordEnd++; | 767 | // Select word the cursor is over |
769 | } | 768 | while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) |
770 | std::string selectedWord(std::string(text.begin(), | 769 | { |
771 | text.end()).substr(wordStart,wordEnd-wordStart)); | 770 | wordEnd--; |
772 | if(!glggHunSpell->isSpelledRight(selectedWord)) | 771 | } |
773 | { | 772 | wordStart = wordEnd; |
774 | //misspelled word here, and you have just right clicked on it! | 773 | //startSelection(); |
775 | std::vector<std::string> suggs = glggHunSpell->getSuggestionList(selectedWord); | ||
776 | //menu->setItemVisible("Transep",(suggs.size()>0)); | ||
777 | 774 | ||
778 | for(int i = 0;i<(int)suggs.size();i++) | 775 | while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) |
779 | { | 776 | { |
777 | wordEnd++; | ||
778 | } | ||
779 | std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); | ||
780 | |||
781 | if (!glggHunSpell->isSpelledRight(selectedWord)) | ||
782 | { | ||
783 | //misspelled word here, and you have just right clicked on it! | ||
784 | std::vector<std::string> suggs = glggHunSpell->getSuggestionList(selectedWord); | ||
785 | //menu->setItemVisible("Transep",(suggs.size()>0)); | ||
786 | |||
787 | for (int i = 0; i<(int)suggs.size() ;i++) | ||
788 | { | ||
789 | SpellMenuBind * tempStruct = new SpellMenuBind; | ||
790 | tempStruct->origin = this; | ||
791 | tempStruct->word = suggs[i]; | ||
792 | tempStruct->wordPositionEnd = wordEnd; | ||
793 | tempStruct->wordPositionStart=wordStart; | ||
794 | LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( | ||
795 | tempStruct->word, spell_correct, NULL, tempStruct); | ||
796 | //new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); | ||
797 | tempStruct->menuItem = suggMenuItem; | ||
798 | suggestionMenuItems.push_back(tempStruct); | ||
799 | menu->append(suggMenuItem); | ||
800 | } | ||
780 | SpellMenuBind * tempStruct = new SpellMenuBind; | 801 | SpellMenuBind * tempStruct = new SpellMenuBind; |
781 | tempStruct->origin = this; | 802 | tempStruct->origin = this; |
782 | tempStruct->word = suggs[i]; | 803 | tempStruct->word = selectedWord; |
783 | tempStruct->wordPositionEnd = wordEnd; | 804 | tempStruct->wordPositionEnd = wordEnd; |
784 | tempStruct->wordPositionStart=wordStart; | 805 | tempStruct->wordPositionStart=wordStart; |
785 | LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( | 806 | LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( |
786 | tempStruct->word, spell_correct, NULL, tempStruct); | 807 | "Add Word", spell_add, NULL, tempStruct); |
787 | //new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); | ||
788 | tempStruct->menuItem = suggMenuItem; | 808 | tempStruct->menuItem = suggMenuItem; |
789 | suggestionMenuItems.push_back(tempStruct); | 809 | suggestionMenuItems.push_back(tempStruct); |
790 | menu->append(suggMenuItem); | 810 | menu->append(suggMenuItem); |
791 | } | 811 | } |
792 | SpellMenuBind * tempStruct = new SpellMenuBind; | ||
793 | tempStruct->origin = this; | ||
794 | tempStruct->word = selectedWord; | ||
795 | tempStruct->wordPositionEnd = wordEnd; | ||
796 | tempStruct->wordPositionStart=wordStart; | ||
797 | LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( | ||
798 | "Add Word", spell_add, NULL, tempStruct); | ||
799 | tempStruct->menuItem = suggMenuItem; | ||
800 | suggestionMenuItems.push_back(tempStruct); | ||
801 | menu->append(suggMenuItem); | ||
802 | } | 812 | } |
803 | 813 | ||
804 | } | ||
805 | if((!mReadOnly)&&((!glggHunSpell->highlightInRed) | ||
806 | ||(mOverRideAndShowMisspellings))) | ||
807 | { | ||
808 | SpellMenuBind * tempStruct = new SpellMenuBind; | 814 | SpellMenuBind * tempStruct = new SpellMenuBind; |
809 | tempStruct->origin = this; | 815 | tempStruct->origin = this; |
810 | if(mOverRideAndShowMisspellings) | 816 | if (glggHunSpell->mSpellCheckHighlight) |
817 | { | ||
811 | tempStruct->word = "Hide Misspellings"; | 818 | tempStruct->word = "Hide Misspellings"; |
819 | } | ||
812 | else | 820 | else |
821 | { | ||
813 | tempStruct->word = "Show Misspellings"; | 822 | tempStruct->word = "Show Misspellings"; |
823 | } | ||
814 | LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( | 824 | LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL( |
815 | tempStruct->word, spell_show, NULL, tempStruct); | 825 | tempStruct->word, spell_show, NULL, tempStruct); |
816 | tempStruct->menuItem = suggMenuItem; | 826 | tempStruct->menuItem = suggMenuItem; |
@@ -1838,36 +1848,43 @@ void LLLineEditor::doDelete() | |||
1838 | } | 1848 | } |
1839 | } | 1849 | } |
1840 | } | 1850 | } |
1851 | |||
1841 | void LLLineEditor::autoCorrectText() | 1852 | void LLLineEditor::autoCorrectText() |
1842 | { | 1853 | { |
1843 | static BOOL *doAnything = rebind_llcontrol<BOOL>("EmeraldEnableAutoCorrect", &gSavedSettings, true); | 1854 | static BOOL *doAnything = rebind_llcontrol<BOOL>("EmeraldEnableAutoCorrect", &gSavedSettings, true); |
1844 | if( (!mReadOnly) && (*doAnything) && (isSpellDirty())) | 1855 | if (!mReadOnly && *doAnything && isSpellDirty()) |
1845 | { | 1856 | { |
1846 | S32 wordStart = 0; | 1857 | S32 wordStart = 0; |
1847 | S32 wordEnd = mCursorPos-1; | 1858 | S32 wordEnd = mCursorPos-1; |
1848 | //llinfos <<"Checking Word, Cursor is at "<<mCursorPos<<" and text is "<<mText.getString().c_str()<<llendl; | 1859 | //llinfos <<"Checking Word, Cursor is at "<<mCursorPos<<" and text is "<<mText.getString().c_str()<<llendl; |
1849 | if(wordEnd<1)return; | 1860 | if (wordEnd < 1) |
1861 | { | ||
1862 | return; | ||
1863 | } | ||
1850 | const LLWString& text = mText.getWString(); | 1864 | const LLWString& text = mText.getWString(); |
1851 | if(text.size()<1)return; | 1865 | if (text.size() < 1 || LLTextEditor::isPartOfWord(text[wordEnd])) |
1852 | if( LLTextEditor::isPartOfWord( text[wordEnd] )) return;//we only check on word breaks | 1866 | { |
1867 | return;//we only check on word breaks | ||
1868 | } | ||
1869 | |||
1853 | wordEnd--; | 1870 | wordEnd--; |
1854 | if( LLTextEditor::isPartOfWord( text[wordEnd] ) ) | 1871 | if (LLTextEditor::isPartOfWord(text[wordEnd])) |
1855 | { | 1872 | { |
1856 | while ((wordEnd > 0) && (' '!=text[wordEnd-1])) | 1873 | while ((wordEnd > 0) && (' '!=text[wordEnd-1])) |
1857 | { | 1874 | { |
1858 | wordEnd--; | 1875 | wordEnd--; |
1859 | } | 1876 | } |
1860 | wordStart=wordEnd; | 1877 | wordStart = wordEnd; |
1861 | while ((wordEnd < (S32)text.length()) && (' '!=text[wordEnd] ) ) | 1878 | while ((wordEnd < (S32)text.length()) && (' '!=text[wordEnd] ) ) |
1862 | { | 1879 | { |
1863 | wordEnd++; | 1880 | wordEnd++; |
1864 | } | 1881 | } |
1865 | std::string lastTypedWord(std::string(text.begin(), | 1882 | std::string lastTypedWord(std::string(text.begin(), |
1866 | text.end()).substr(wordStart,wordEnd-wordStart)); | 1883 | text.end()).substr(wordStart, wordEnd-wordStart)); |
1867 | //llinfos << " The last typed word has been chosen, it is "<<lastTypedWord.c_str()<<llendl; | 1884 | //llinfos << " The last typed word has been chosen, it is "<<lastTypedWord.c_str()<<llendl; |
1868 | 1885 | ||
1869 | std::string correctedWord(LGGAutoCorrect::getInstance()->replaceWord(lastTypedWord)); | 1886 | std::string correctedWord(LGGAutoCorrect::getInstance()->replaceWord(lastTypedWord)); |
1870 | if(correctedWord!=lastTypedWord) | 1887 | if(correctedWord != lastTypedWord) |
1871 | { | 1888 | { |
1872 | int dif = correctedWord.length()-lastTypedWord.length(); | 1889 | int dif = correctedWord.length()-lastTypedWord.length(); |
1873 | std::string regText(mText); | 1890 | std::string regText(mText); |
@@ -1879,53 +1896,56 @@ void LLLineEditor::autoCorrectText() | |||
1879 | } | 1896 | } |
1880 | } | 1897 | } |
1881 | } | 1898 | } |
1899 | |||
1882 | void LLLineEditor::drawMisspelled(LLRect background) | 1900 | void LLLineEditor::drawMisspelled(LLRect background) |
1883 | { | 1901 | { |
1884 | if((glggHunSpell->highlightInRed || mOverRideAndShowMisspellings) | 1902 | if (!mReadOnly && mShowMisspellings) |
1885 | &&(!mReadOnly)) | ||
1886 | { | 1903 | { |
1887 | S32 newStartSpellHere =mScrollHPos; | 1904 | S32 newStartSpellHere = mScrollHPos; |
1888 | S32 cursorloc =calculateCursorFromMouse(mMaxHPixels); | 1905 | S32 cursorloc = calculateCursorFromMouse(mMaxHPixels); |
1889 | S32 newStopSpellHere = ( ((S32)mText.length())>cursorloc)?cursorloc:(S32)mText.length(); | 1906 | S32 newStopSpellHere = (((S32)mText.length())>cursorloc) ? cursorloc : (S32)mText.length(); |
1890 | 1907 | ||
1891 | F32 elapsed = mSpellTimer.getElapsedTimeF32(); | 1908 | F32 elapsed = mSpellTimer.getElapsedTimeF32(); |
1892 | if(S32(elapsed / 1) & 1) | 1909 | if (S32(elapsed / 1) & 1) |
1893 | { | 1910 | { |
1894 | if(isSpellDirty()||(newStartSpellHere!=mStartSpellHere)||(newStopSpellHere!=mEndSpellHere)) | 1911 | if (isSpellDirty() || (newStartSpellHere != mStartSpellHere) || ( newStopSpellHere != mEndSpellHere)) |
1895 | { | 1912 | { |
1896 | mStartSpellHere=newStartSpellHere; | 1913 | mStartSpellHere = newStartSpellHere; |
1897 | mEndSpellHere= newStopSpellHere; | 1914 | mEndSpellHere = newStopSpellHere; |
1898 | resetSpellDirty(); | 1915 | resetSpellDirty(); |
1899 | misspellLocations=getMisspelledWordsPositions(); | 1916 | misspellLocations=getMisspelledWordsPositions(); |
1900 | } | 1917 | } |
1901 | } | 1918 | } |
1902 | for(int i =0;i<(int)misspellLocations.size();i++) | ||
1903 | { | ||
1904 | S32 wstart =findPixelNearestPos( misspellLocations[i]-getCursor()); | ||
1905 | S32 wend = findPixelNearestPos(misspellLocations[++i]-getCursor()); | ||
1906 | S32 maxw = getRect().getWidth(); | ||
1907 | 1919 | ||
1908 | if(wend > maxw) | 1920 | if (glggHunSpell->mSpellCheckHighlight) |
1909 | { | 1921 | { |
1910 | wend=maxw; | 1922 | for (int i =0; i<(int)misspellLocations.size(); i++) |
1911 | } | ||
1912 | if(wstart > maxw) | ||
1913 | { | ||
1914 | wstart=maxw; | ||
1915 | } | ||
1916 | gGL.color4ub(255,0,0,200); | ||
1917 | //3 line zig zags.. | ||
1918 | while(wstart<wend) | ||
1919 | { | 1923 | { |
1920 | gl_line_2d(wstart,background.mBottom-1,wstart+3,background.mBottom+2); | 1924 | S32 wstart =findPixelNearestPos( misspellLocations[i]-getCursor()); |
1921 | gl_line_2d(wstart+3,background.mBottom+2,wstart+6,background.mBottom-1); | 1925 | S32 wend = findPixelNearestPos(misspellLocations[++i]-getCursor()); |
1922 | wstart+=6; | 1926 | S32 maxw = getRect().getWidth(); |
1923 | } | ||
1924 | 1927 | ||
1928 | if (wend > maxw) | ||
1929 | { | ||
1930 | wend = maxw; | ||
1931 | } | ||
1932 | if (wstart > maxw) | ||
1933 | { | ||
1934 | wstart = maxw; | ||
1935 | } | ||
1936 | gGL.color4ub(255,0,0,200); | ||
1937 | //3 line zig zags.. | ||
1938 | while (wstart < wend) | ||
1939 | { | ||
1940 | gl_line_2d(wstart, background.mBottom-1, wstart+3, background.mBottom+2); | ||
1941 | gl_line_2d(wstart+3, background.mBottom+2, wstart+6, background.mBottom-1); | ||
1942 | wstart+=6; | ||
1943 | } | ||
1944 | } | ||
1925 | } | 1945 | } |
1926 | } | 1946 | } |
1927 | |||
1928 | } | 1947 | } |
1948 | |||
1929 | void LLLineEditor::draw() | 1949 | void LLLineEditor::draw() |
1930 | { | 1950 | { |
1931 | autoCorrectText(); | 1951 | autoCorrectText(); |
@@ -2797,6 +2817,11 @@ LLView* LLLineEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory | |||
2797 | { | 2817 | { |
2798 | line_editor->setCommitOnFocusLost(commit_on_focus_lost); | 2818 | line_editor->setCommitOnFocusLost(commit_on_focus_lost); |
2799 | } | 2819 | } |
2820 | BOOL show_misspellings = FALSE; | ||
2821 | if (node->getAttributeBOOL("spell_check", show_misspellings)) | ||
2822 | { | ||
2823 | line_editor->setShowMisspellings(show_misspellings); | ||
2824 | } | ||
2800 | 2825 | ||
2801 | line_editor->setColorParameters(node); | 2826 | line_editor->setColorParameters(node); |
2802 | 2827 | ||