diff options
author | Tomaž Vajngerl <quikee@gmail.com> | 2012-07-30 23:37:30 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2012-07-30 23:43:48 +0200 |
commit | d602a3b280fcc1cf16660d8719cd8eb8797dd2ad (patch) | |
tree | a95c7f891933bc7a7c8997e6114e9e4b6f7c297e /sw | |
parent | fa351042bc425f0437bfb50d09220bedbc257948 (diff) |
First step to change sorted vector with LookupTree for word autocompletion.
With this commit autocompletion words are inserted into a LookupTree
instance and used when autocompleting words. Previouslly used sorted
vector is still used for the GUI.
Change-Id: Ib5aed38d575fbef7221afbebe824a440d4ffbc7e
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/acmplwrd.hxx | 5 | ||||
-rw-r--r-- | sw/source/core/doc/acmplwrd.cxx | 33 | ||||
-rw-r--r-- | sw/source/core/txtnode/txtedt.cxx | 4 | ||||
-rw-r--r-- | sw/source/ui/docvw/edtwin.cxx | 34 |
4 files changed, 39 insertions, 37 deletions
diff --git a/sw/inc/acmplwrd.hxx b/sw/inc/acmplwrd.hxx index 46281699f697..72421c384c7b 100644 --- a/sw/inc/acmplwrd.hxx +++ b/sw/inc/acmplwrd.hxx @@ -32,6 +32,7 @@ #include <deque> #include <editeng/swafopt.hxx> +#include <editeng/LatinLookupTree.hxx> class SwDoc; class SwAutoCompleteWord_Impl; @@ -46,6 +47,7 @@ class SwAutoCompleteWord /// contains extended strings carrying source information editeng::SortedAutoCompleteStrings m_WordList; + LookupTree* m_LookupTree; SwAutoCompleteStringPtrDeque aLRULst; SwAutoCompleteWord_Impl* pImpl; @@ -74,7 +76,10 @@ public: const editeng::SortedAutoCompleteStrings& GetWordList() const { return m_WordList; } + void CheckChangedList(const editeng::SortedAutoCompleteStrings& rNewLst); + + bool GetWordsMatching(String aMatch, std::vector<String>& aWords) const; }; diff --git a/sw/source/core/doc/acmplwrd.cxx b/sw/source/core/doc/acmplwrd.cxx index f7ff984ea445..d569e16edc7a 100644 --- a/sw/source/core/doc/acmplwrd.cxx +++ b/sw/source/core/doc/acmplwrd.cxx @@ -224,18 +224,19 @@ bool SwAutoCompleteString::RemoveDocument(const SwDoc& rDoc) return false; } -SwAutoCompleteWord::SwAutoCompleteWord( sal_uInt16 nWords, sal_uInt16 nMWrdLen ) - : +SwAutoCompleteWord::SwAutoCompleteWord( sal_uInt16 nWords, sal_uInt16 nMWrdLen ) : pImpl(new SwAutoCompleteWord_Impl(*this)), nMaxCount( nWords ), nMinWrdLen( nMWrdLen ), bLockWordLst( sal_False ) { + m_LookupTree = new LatinLookupTree(OUString("default")); } SwAutoCompleteWord::~SwAutoCompleteWord() { m_WordList.DeleteAndDestroyAll(); // so the assertion below works + delete m_LookupTree; delete pImpl; #if OSL_DEBUG_LEVEL > 0 sal_uLong nStrings = SwAutoCompleteString::GetElementCount(); @@ -272,6 +273,9 @@ sal_Bool SwAutoCompleteWord::InsertWord( const String& rWord, SwDoc& rDoc ) pNew->AddDocument(rDoc); std::pair<editeng::SortedAutoCompleteStrings::const_iterator, bool> aInsPair = m_WordList.insert(pNew); + + m_LookupTree->insert( OUString(aNewWord) ); + if (aInsPair.second) { bRet = sal_True; @@ -351,22 +355,19 @@ void SwAutoCompleteWord::SetMinWordLen( sal_uInt16 n ) nMinWrdLen = n; } -sal_Bool SwAutoCompleteWord::GetRange( const String& rWord, sal_uInt16& rStt, - sal_uInt16& rEnd ) const +bool SwAutoCompleteWord::GetWordsMatching(String aMatch, std::vector<String>& aWords) const { - const String * pStr = &rWord; - editeng::IAutoCompleteString hack(*pStr); // UGLY - rStt = m_WordList.find(&hack) - m_WordList.begin(); - rEnd = rStt; - - const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore(); - while (rEnd < m_WordList.size() && - rSCmp.isMatch(rWord, m_WordList[rEnd]->GetAutoCompleteString())) - { - ++rEnd; - } + OUString aStringRoot = OUString(aMatch); + m_LookupTree->gotoNode( aStringRoot ); + OUString aAutocompleteWord = m_LookupTree->suggestAutoCompletion(); + if (aAutocompleteWord.isEmpty()) + return false; + + OUString aCompleteWord = aStringRoot + aAutocompleteWord; + + aWords.push_back( String(aCompleteWord) ); - return rStt < rEnd; + return true; } void SwAutoCompleteWord::CheckChangedList( diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index bde558876bec..daeda95e491f 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -1377,10 +1377,10 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, xub_StrLen /*nActPos*/ rtl::OUString aExpandText = aConversionMap.getViewText(); // Ownership ov ConversionMap is passed to SwXTextMarkup object! - Reference< com::sun::star::text::XTextMarkup > xTextMarkup = + com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xTextMarkup = new SwXTextMarkup( *pNode, aConversionMap ); - Reference< ::com::sun::star::frame::XController > xController = pNode->GetDoc()->GetDocShell()->GetController(); + com::sun::star::uno::Reference< ::com::sun::star::frame::XController > xController = pNode->GetDoc()->GetDocShell()->GetController(); xub_StrLen nLangBegin = nBegin; xub_StrLen nLangEnd = nEnd; diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx index 09e96336b065..e3b3933d872d 100644 --- a/sw/source/ui/docvw/edtwin.cxx +++ b/sw/source/ui/docvw/edtwin.cxx @@ -5612,31 +5612,27 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord ) // Add matching words from AutoCompleteWord list const SwAutoCompleteWord& rACList = rSh.GetAutoCompleteWords(); - sal_uInt16 nPos, nEnd; - // TODO - GetRange only performs a case insensitive match for ASCII - if ( rACList.GetRange( rWord, nPos, nEnd ) ) + std::vector<String> strings; + if ( rACList.GetWordsMatching( rWord, strings ) ) { - for ( ; nPos < nEnd; ++nPos ) + for (unsigned int i= 0; i<strings.size(); i++) { - const String& rStr = rACList[nPos]; - // Check string longer than word - if ( rStr.Len() > rWord.Len() ) + String aCompletedString = strings[i]; + if ( aWordCase == CASE_LOWER ) + m_aHelpStrings.push_back( rCC.lowercase( aCompletedString ) ); + else if ( aWordCase == CASE_SENTENCE ) { - if ( aWordCase == CASE_LOWER ) - m_aHelpStrings.push_back( rCC.lowercase( rStr ) ); - else if ( aWordCase == CASE_SENTENCE ) - { - String sTmp = rCC.lowercase( rStr ); - sTmp.SetChar( 0, rStr.GetChar(0) ); - m_aHelpStrings.push_back( sTmp ); - } - else if ( aWordCase == CASE_UPPER ) - m_aHelpStrings.push_back( rCC.uppercase( rStr ) ); - else // CASE_OTHER - use retrieved capitalization - m_aHelpStrings.push_back( rStr ); + String sTmp = rCC.lowercase( aCompletedString ); + sTmp.SetChar( 0, aCompletedString.GetChar(0) ); + m_aHelpStrings.push_back( sTmp ); } + else if ( aWordCase == CASE_UPPER ) + m_aHelpStrings.push_back( rCC.uppercase( aCompletedString ) ); + else // CASE_OTHER - use retrieved capitalization + m_aHelpStrings.push_back( aCompletedString ); } } + } namespace { |