2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2011-11-18 21:03:31 +00:00
|
|
|
#include <comphelper/string.hxx>
|
2010-07-14 16:42:33 +02:00
|
|
|
#include <tools/urlobj.hxx>
|
2000-09-18 23:08:29 +00:00
|
|
|
#include <hintids.hxx>
|
2008-03-05 15:52:50 +00:00
|
|
|
#include <hints.hxx>
|
2001-09-05 09:26:15 +00:00
|
|
|
#include <unotools/transliterationwrapper.hxx>
|
2000-09-18 23:08:29 +00:00
|
|
|
#include <acmplwrd.hxx>
|
|
|
|
#include <doc.hxx>
|
|
|
|
#include <ndindex.hxx>
|
|
|
|
#include <docary.hxx>
|
|
|
|
#include <ndtxt.hxx>
|
|
|
|
#include <pam.hxx>
|
2002-08-06 07:37:50 +00:00
|
|
|
#include <pagedesc.hxx>
|
|
|
|
#include <poolfmt.hxx>
|
|
|
|
#include <calbck.hxx>
|
2010-01-08 18:32:51 +01:00
|
|
|
#include <editeng/svxacorr.hxx>
|
2002-08-06 07:37:50 +00:00
|
|
|
|
2010-01-08 18:32:51 +01:00
|
|
|
#include <editeng/acorrcfg.hxx>
|
2008-12-09 07:49:49 +00:00
|
|
|
#include <sfx2/docfile.hxx>
|
|
|
|
#include <docsh.hxx>
|
2004-02-03 13:35:24 +00:00
|
|
|
|
2002-08-06 07:37:50 +00:00
|
|
|
#include <vector>
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2002-08-06 07:37:50 +00:00
|
|
|
class SwAutoCompleteClient : public SwClient
|
|
|
|
{
|
2003-04-01 14:19:44 +00:00
|
|
|
SwAutoCompleteWord* pAutoCompleteWord;
|
|
|
|
SwDoc* pDoc;
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2011-01-17 15:06:54 +01:00
|
|
|
static sal_uLong nSwAutoCompleteClientCount;
|
2002-08-06 07:37:50 +00:00
|
|
|
#endif
|
|
|
|
public:
|
|
|
|
SwAutoCompleteClient(SwAutoCompleteWord& rToTell, SwDoc& rSwDoc);
|
|
|
|
SwAutoCompleteClient(const SwAutoCompleteClient& rClient);
|
|
|
|
~SwAutoCompleteClient();
|
|
|
|
|
2003-04-01 14:19:44 +00:00
|
|
|
SwAutoCompleteClient& operator=(const SwAutoCompleteClient& rClient);
|
2002-08-06 07:37:50 +00:00
|
|
|
|
2003-04-01 14:19:44 +00:00
|
|
|
const SwDoc& GetDoc(){return *pDoc;}
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2011-01-17 15:06:54 +01:00
|
|
|
static sal_uLong GetElementCount() {return nSwAutoCompleteClientCount;}
|
2002-08-06 07:37:50 +00:00
|
|
|
#endif
|
2010-12-17 09:02:23 +01:00
|
|
|
protected:
|
|
|
|
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
|
2002-08-06 07:37:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<SwAutoCompleteClient> SwAutoCompleteClientVector;
|
|
|
|
|
|
|
|
class SwAutoCompleteWord_Impl
|
|
|
|
{
|
|
|
|
SwAutoCompleteClientVector aClientVector;
|
|
|
|
SwAutoCompleteWord& rAutoCompleteWord;
|
|
|
|
public:
|
|
|
|
SwAutoCompleteWord_Impl(SwAutoCompleteWord& rParent) :
|
|
|
|
rAutoCompleteWord(rParent){}
|
|
|
|
void AddDocument(SwDoc& rDoc);
|
|
|
|
void RemoveDocument(const SwDoc& rDoc);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef const SwDoc* SwDocPtr;
|
|
|
|
typedef std::vector<SwDocPtr> SwDocPtrVector;
|
2012-07-25 12:07:33 +02:00
|
|
|
class SwAutoCompleteString
|
|
|
|
: public editeng::IAutoCompleteString
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2011-01-17 15:06:54 +01:00
|
|
|
static sal_uLong nSwAutoCompleteStringCount;
|
2002-08-06 07:37:50 +00:00
|
|
|
#endif
|
|
|
|
SwDocPtrVector aSourceDocs;
|
|
|
|
public:
|
2014-01-15 10:14:52 +00:00
|
|
|
SwAutoCompleteString(const OUString& rStr, sal_Int32 nPos, sal_Int32 nLen);
|
2002-08-06 07:37:50 +00:00
|
|
|
|
|
|
|
~SwAutoCompleteString();
|
|
|
|
void AddDocument(const SwDoc& rDoc);
|
|
|
|
//returns true if last document reference has been removed
|
2012-06-27 18:06:17 +02:00
|
|
|
bool RemoveDocument(const SwDoc& rDoc);
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2011-01-17 15:06:54 +01:00
|
|
|
static sal_uLong GetElementCount() {return nSwAutoCompleteStringCount;}
|
2002-08-06 07:37:50 +00:00
|
|
|
#endif
|
|
|
|
};
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong SwAutoCompleteClient::nSwAutoCompleteClientCount = 0;
|
|
|
|
sal_uLong SwAutoCompleteString::nSwAutoCompleteStringCount = 0;
|
2002-08-06 07:37:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
SwAutoCompleteClient::SwAutoCompleteClient(SwAutoCompleteWord& rToTell, SwDoc& rSwDoc) :
|
2003-04-01 14:19:44 +00:00
|
|
|
pAutoCompleteWord(&rToTell),
|
|
|
|
pDoc(&rSwDoc)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
2003-04-01 14:19:44 +00:00
|
|
|
pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2002-08-06 07:37:50 +00:00
|
|
|
++nSwAutoCompleteClientCount;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SwAutoCompleteClient::SwAutoCompleteClient(const SwAutoCompleteClient& rClient) :
|
2007-09-27 07:32:16 +00:00
|
|
|
SwClient(),
|
2003-04-01 14:19:44 +00:00
|
|
|
pAutoCompleteWord(rClient.pAutoCompleteWord),
|
|
|
|
pDoc(rClient.pDoc)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
2003-04-01 14:19:44 +00:00
|
|
|
pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2002-08-06 07:37:50 +00:00
|
|
|
++nSwAutoCompleteClientCount;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SwAutoCompleteClient::~SwAutoCompleteClient()
|
|
|
|
{
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2002-08-06 07:37:50 +00:00
|
|
|
--nSwAutoCompleteClientCount;
|
|
|
|
#endif
|
|
|
|
}
|
2003-04-01 14:19:44 +00:00
|
|
|
|
|
|
|
SwAutoCompleteClient& SwAutoCompleteClient::operator=(const SwAutoCompleteClient& rClient)
|
|
|
|
{
|
|
|
|
pAutoCompleteWord = rClient.pAutoCompleteWord;
|
|
|
|
pDoc = rClient.pDoc;
|
|
|
|
if(rClient.GetRegisteredIn())
|
2010-12-17 09:02:23 +01:00
|
|
|
((SwModify*)rClient.GetRegisteredIn())->Add(this);
|
2003-04-01 14:19:44 +00:00
|
|
|
else if(GetRegisteredIn())
|
2010-12-17 09:02:23 +01:00
|
|
|
GetRegisteredInNonConst()->Remove(this);
|
2003-04-01 14:19:44 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2002-08-06 07:37:50 +00:00
|
|
|
|
2010-12-17 09:02:23 +01:00
|
|
|
void SwAutoCompleteClient::Modify( const SfxPoolItem* pOld, const SfxPoolItem *)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
|
|
|
switch( pOld ? pOld->Which() : 0 )
|
|
|
|
{
|
|
|
|
case RES_REMOVE_UNO_OBJECT:
|
|
|
|
case RES_OBJECTDYING:
|
|
|
|
if( (void*)GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject )
|
|
|
|
((SwModify*)GetRegisteredIn())->Remove(this);
|
2012-12-20 14:08:36 +01:00
|
|
|
pAutoCompleteWord->DocumentDying(*pDoc);
|
2002-08-06 07:37:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwAutoCompleteWord_Impl::AddDocument(SwDoc& rDoc)
|
|
|
|
{
|
|
|
|
SwAutoCompleteClientVector::iterator aIt;
|
2010-12-23 15:07:14 +00:00
|
|
|
for(aIt = aClientVector.begin(); aIt != aClientVector.end(); ++aIt)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
|
|
|
if(&aIt->GetDoc() == &rDoc)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aClientVector.push_back(SwAutoCompleteClient(rAutoCompleteWord, rDoc));
|
|
|
|
}
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2002-08-06 07:37:50 +00:00
|
|
|
void SwAutoCompleteWord_Impl::RemoveDocument(const SwDoc& rDoc)
|
|
|
|
{
|
|
|
|
SwAutoCompleteClientVector::iterator aIt;
|
2010-12-23 15:07:14 +00:00
|
|
|
for(aIt = aClientVector.begin(); aIt != aClientVector.end(); ++aIt)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
|
|
|
if(&aIt->GetDoc() == &rDoc)
|
|
|
|
{
|
|
|
|
aClientVector.erase(aIt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-25 12:07:33 +02:00
|
|
|
SwAutoCompleteString::SwAutoCompleteString(
|
2014-01-15 10:14:52 +00:00
|
|
|
const OUString& rStr, sal_Int32 const nPos, sal_Int32 const nLen)
|
2013-10-16 11:18:56 +02:00
|
|
|
: editeng::IAutoCompleteString(rStr.copy(nPos, nLen))
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2002-08-06 07:37:50 +00:00
|
|
|
++nSwAutoCompleteStringCount;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SwAutoCompleteString::~SwAutoCompleteString()
|
|
|
|
{
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2002-08-06 07:37:50 +00:00
|
|
|
--nSwAutoCompleteStringCount;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwAutoCompleteString::AddDocument(const SwDoc& rDoc)
|
|
|
|
{
|
2012-06-27 18:06:17 +02:00
|
|
|
for(SwDocPtrVector::iterator aIt = aSourceDocs.begin(); aIt != aSourceDocs.end(); ++aIt)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
2012-06-27 18:06:17 +02:00
|
|
|
if( *aIt == &rDoc )
|
2002-08-06 07:37:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-06-27 18:06:17 +02:00
|
|
|
aSourceDocs.push_back(&rDoc);
|
2002-08-06 07:37:50 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 18:06:17 +02:00
|
|
|
bool SwAutoCompleteString::RemoveDocument(const SwDoc& rDoc)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
2012-06-27 18:06:17 +02:00
|
|
|
for(SwDocPtrVector::iterator aIt = aSourceDocs.begin(); aIt != aSourceDocs.end(); ++aIt)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
2012-06-27 18:06:17 +02:00
|
|
|
if( *aIt == &rDoc )
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
|
|
|
aSourceDocs.erase(aIt);
|
2012-05-19 15:09:08 +02:00
|
|
|
return aSourceDocs.empty();
|
2002-08-06 07:37:50 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-27 18:06:17 +02:00
|
|
|
return false;
|
2002-08-06 07:37:50 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 23:37:30 +02:00
|
|
|
SwAutoCompleteWord::SwAutoCompleteWord( sal_uInt16 nWords, sal_uInt16 nMWrdLen ) :
|
2002-08-06 07:37:50 +00:00
|
|
|
pImpl(new SwAutoCompleteWord_Impl(*this)),
|
2000-09-18 23:08:29 +00:00
|
|
|
nMaxCount( nWords ),
|
|
|
|
nMinWrdLen( nMWrdLen ),
|
2011-01-17 15:06:54 +01:00
|
|
|
bLockWordLst( sal_False )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwAutoCompleteWord::~SwAutoCompleteWord()
|
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
m_WordList.DeleteAndDestroyAll(); // so the assertion below works
|
2002-08-06 07:37:50 +00:00
|
|
|
delete pImpl;
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong nStrings = SwAutoCompleteString::GetElementCount();
|
|
|
|
sal_uLong nClients = SwAutoCompleteClient::GetElementCount();
|
2011-03-15 13:50:53 +00:00
|
|
|
OSL_ENSURE(!nStrings && !nClients, "AutoComplete: clients or string count mismatch");
|
2002-08-06 07:37:50 +00:00
|
|
|
#endif
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 11:07:56 +02:00
|
|
|
bool SwAutoCompleteWord::InsertWord( const OUString& rWord, SwDoc& rDoc )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2008-12-09 07:49:49 +00:00
|
|
|
SwDocShell* pDocShell = rDoc.GetDocShell();
|
|
|
|
SfxMedium* pMedium = pDocShell ? pDocShell->GetMedium() : 0;
|
|
|
|
// strings from help module should not be added
|
|
|
|
if( pMedium )
|
|
|
|
{
|
|
|
|
const INetURLObject& rURL = pMedium->GetURLObject();
|
|
|
|
if ( rURL.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
2013-10-16 09:32:03 +02:00
|
|
|
OUString aNewWord(rWord);
|
2011-11-18 21:03:31 +00:00
|
|
|
aNewWord = comphelper::string::remove(aNewWord, CH_TXTATR_INWORD);
|
|
|
|
aNewWord = comphelper::string::remove(aNewWord, CH_TXTATR_BREAKWORD);
|
2003-09-11 08:39:27 +00:00
|
|
|
|
2002-08-06 07:37:50 +00:00
|
|
|
pImpl->AddDocument(rDoc);
|
2012-10-07 09:44:43 +09:00
|
|
|
bool bRet = false;
|
2013-10-28 15:41:25 +02:00
|
|
|
sal_Int32 nWrdLen = aNewWord.getLength();
|
2013-10-16 09:32:03 +02:00
|
|
|
while( nWrdLen && '.' == aNewWord[ nWrdLen-1 ])
|
2000-09-18 23:08:29 +00:00
|
|
|
--nWrdLen;
|
|
|
|
|
2003-04-01 14:19:44 +00:00
|
|
|
if( !bLockWordLst && nWrdLen >= nMinWrdLen )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-06-27 18:06:17 +02:00
|
|
|
SwAutoCompleteString* pNew = new SwAutoCompleteString( aNewWord, 0, nWrdLen );
|
|
|
|
pNew->AddDocument(rDoc);
|
2012-07-25 12:07:33 +02:00
|
|
|
std::pair<editeng::SortedAutoCompleteStrings::const_iterator, bool>
|
|
|
|
aInsPair = m_WordList.insert(pNew);
|
2012-07-30 23:37:30 +02:00
|
|
|
|
2013-06-11 23:13:14 +02:00
|
|
|
m_LookupTree.insert( OUString(aNewWord).copy(0, nWrdLen) );
|
2012-07-30 23:37:30 +02:00
|
|
|
|
2012-07-25 12:07:33 +02:00
|
|
|
if (aInsPair.second)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-10-07 09:44:43 +09:00
|
|
|
bRet = true;
|
2012-07-04 22:07:13 +02:00
|
|
|
if (aLRULst.size() >= nMaxCount)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2011-10-28 02:23:02 +02:00
|
|
|
// the last one needs to be removed
|
|
|
|
// so that there is space for the first one
|
2012-06-27 18:06:17 +02:00
|
|
|
SwAutoCompleteString* pDel = aLRULst.back();
|
|
|
|
aLRULst.pop_back();
|
2012-07-25 12:07:33 +02:00
|
|
|
m_WordList.erase(pDel);
|
2012-06-27 18:06:17 +02:00
|
|
|
delete pDel;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
2012-07-04 22:07:13 +02:00
|
|
|
aLRULst.push_front(pNew);
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-27 18:06:17 +02:00
|
|
|
delete pNew;
|
2011-10-28 02:23:02 +02:00
|
|
|
// then move "up"
|
2012-07-19 12:46:29 +02:00
|
|
|
pNew = (SwAutoCompleteString*)(*aInsPair.first);
|
2002-08-06 07:37:50 +00:00
|
|
|
|
2011-10-28 02:23:02 +02:00
|
|
|
// add the document to the already inserted string
|
2012-06-27 18:06:17 +02:00
|
|
|
pNew->AddDocument(rDoc);
|
2002-08-06 07:37:50 +00:00
|
|
|
|
2012-06-27 18:06:17 +02:00
|
|
|
// move pNew to the front of the LRU list
|
|
|
|
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pNew );
|
|
|
|
OSL_ENSURE( aLRULst.end() != it, "String not found" );
|
|
|
|
if ( aLRULst.begin() != it && aLRULst.end() != it )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-06-27 18:06:17 +02:00
|
|
|
aLRULst.erase( it );
|
|
|
|
aLRULst.push_front( pNew );
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
void SwAutoCompleteWord::SetMaxCount( sal_uInt16 nNewMax )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-06-27 18:06:17 +02:00
|
|
|
if( nNewMax < nMaxCount && aLRULst.size() > nNewMax )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2011-10-28 02:23:02 +02:00
|
|
|
// remove the trailing ones
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nLRUIndex = nNewMax-1;
|
2012-07-25 12:07:33 +02:00
|
|
|
while (nNewMax < m_WordList.size() && nLRUIndex < aLRULst.size())
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
editeng::SortedAutoCompleteStrings::const_iterator it =
|
|
|
|
m_WordList.find(aLRULst[ nLRUIndex++ ]);
|
|
|
|
OSL_ENSURE( m_WordList.end() != it, "String not found" );
|
|
|
|
editeng::IAutoCompleteString *const pDel = *it;
|
2012-07-25 16:21:05 +02:00
|
|
|
m_WordList.erase(it - m_WordList.begin());
|
2012-06-27 18:06:17 +02:00
|
|
|
delete pDel;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
2012-06-27 18:06:17 +02:00
|
|
|
aLRULst.erase( aLRULst.begin() + nNewMax - 1, aLRULst.end() );
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
nMaxCount = nNewMax;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
void SwAutoCompleteWord::SetMinWordLen( sal_uInt16 n )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2011-10-28 02:23:02 +02:00
|
|
|
// Do you really want to remove all words that are less than the minWrdLen?
|
2000-09-18 23:08:29 +00:00
|
|
|
if( n < nMinWrdLen )
|
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
for (size_t nPos = 0; nPos < m_WordList.size(); ++nPos)
|
2013-09-05 11:51:31 +02:00
|
|
|
if (m_WordList[ nPos ]->GetAutoCompleteString().getLength() < n)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
SwAutoCompleteString *const pDel =
|
|
|
|
dynamic_cast<SwAutoCompleteString*>(m_WordList[nPos]);
|
|
|
|
m_WordList.erase(nPos);
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2012-06-27 18:06:17 +02:00
|
|
|
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pDel );
|
|
|
|
OSL_ENSURE( aLRULst.end() != it, "String not found" );
|
|
|
|
aLRULst.erase( it );
|
2000-09-18 23:08:29 +00:00
|
|
|
--nPos;
|
2012-06-27 18:06:17 +02:00
|
|
|
delete pDel;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nMinWrdLen = n;
|
|
|
|
}
|
|
|
|
|
2013-04-07 21:11:09 +02:00
|
|
|
/** Return all words matching a given prefix
|
|
|
|
*
|
|
|
|
* @param aMatch the prefix to search for
|
|
|
|
* @param aWords the words to search in
|
|
|
|
*/
|
2013-10-14 11:00:19 +02:00
|
|
|
bool SwAutoCompleteWord::GetWordsMatching(OUString aMatch, std::vector<OUString>& aWords) const
|
2012-09-02 22:09:38 +02:00
|
|
|
{
|
2013-10-14 11:00:19 +02:00
|
|
|
OUString aStringRoot = aMatch;
|
2012-09-02 22:09:38 +02:00
|
|
|
|
2013-06-11 23:13:14 +02:00
|
|
|
std::vector<OUString> suggestions;
|
|
|
|
m_LookupTree.findSuggestions(aStringRoot, suggestions);
|
|
|
|
|
|
|
|
if (suggestions.empty())
|
2012-09-02 22:09:38 +02:00
|
|
|
{
|
2012-07-30 23:37:30 +02:00
|
|
|
return false;
|
2012-09-02 22:09:38 +02:00
|
|
|
}
|
2012-07-30 23:37:30 +02:00
|
|
|
|
2013-06-11 23:13:14 +02:00
|
|
|
for (size_t i = 0; i < suggestions.size(); i++)
|
|
|
|
{
|
2013-10-14 11:00:19 +02:00
|
|
|
aWords.push_back( suggestions[i] );
|
2013-06-11 23:13:14 +02:00
|
|
|
}
|
|
|
|
|
2012-07-30 23:37:30 +02:00
|
|
|
return true;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2012-07-25 12:07:33 +02:00
|
|
|
void SwAutoCompleteWord::CheckChangedList(
|
|
|
|
const editeng::SortedAutoCompleteStrings& rNewLst)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
size_t nMyLen = m_WordList.size(), nNewLen = rNewLst.size();
|
|
|
|
size_t nMyPos = 0, nNewPos = 0;
|
2000-09-18 23:08:29 +00:00
|
|
|
|
|
|
|
for( ; nMyPos < nMyLen && nNewPos < nNewLen; ++nMyPos, ++nNewPos )
|
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
const editeng::IAutoCompleteString * pStr = rNewLst[ nNewPos ];
|
|
|
|
while (m_WordList[nMyPos] != pStr)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
SwAutoCompleteString *const pDel =
|
|
|
|
dynamic_cast<SwAutoCompleteString*>(m_WordList[nMyPos]);
|
|
|
|
m_WordList.erase(nMyPos);
|
2012-06-27 18:06:17 +02:00
|
|
|
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pDel );
|
|
|
|
OSL_ENSURE( aLRULst.end() != it, "String not found" );
|
|
|
|
aLRULst.erase( it );
|
|
|
|
delete pDel;
|
2000-09-18 23:08:29 +00:00
|
|
|
if( nMyPos >= --nMyLen )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-28 02:23:02 +02:00
|
|
|
// remove the elements at the end of the array
|
2000-09-18 23:08:29 +00:00
|
|
|
if( nMyPos < nMyLen )
|
|
|
|
{
|
2011-10-28 02:23:02 +02:00
|
|
|
// clear LRU array first then delete the string object
|
2000-09-18 23:08:29 +00:00
|
|
|
for( ; nNewPos < nMyLen; ++nNewPos )
|
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
SwAutoCompleteString *const pDel =
|
|
|
|
dynamic_cast<SwAutoCompleteString*>(m_WordList[nNewPos]);
|
2012-06-27 18:06:17 +02:00
|
|
|
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pDel );
|
|
|
|
OSL_ENSURE( aLRULst.end() != it, "String not found" );
|
|
|
|
aLRULst.erase( it );
|
|
|
|
delete pDel;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
2011-10-28 02:23:02 +02:00
|
|
|
// remove from array
|
2012-07-25 12:07:33 +02:00
|
|
|
m_WordList.erase(m_WordList.begin() + nMyPos,
|
|
|
|
m_WordList.begin() + nMyLen);
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-06 07:37:50 +00:00
|
|
|
void SwAutoCompleteWord::DocumentDying(const SwDoc& rDoc)
|
|
|
|
{
|
|
|
|
pImpl->RemoveDocument(rDoc);
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2011-05-20 09:06:56 +01:00
|
|
|
SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
|
2002-08-06 07:37:50 +00:00
|
|
|
const sal_Bool bDelete = !pACorr->GetSwFlags().bAutoCmpltKeepList;
|
2012-07-25 12:07:33 +02:00
|
|
|
for (size_t nPos = m_WordList.size(); nPos; nPos--)
|
2002-08-06 07:37:50 +00:00
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
SwAutoCompleteString *const pCurrent =
|
|
|
|
dynamic_cast<SwAutoCompleteString*>(m_WordList[nPos - 1]);
|
2002-08-06 07:37:50 +00:00
|
|
|
if(pCurrent->RemoveDocument(rDoc) && bDelete)
|
|
|
|
{
|
2012-07-25 12:07:33 +02:00
|
|
|
m_WordList.erase(nPos - 1);
|
2012-06-27 18:06:17 +02:00
|
|
|
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pCurrent );
|
|
|
|
OSL_ENSURE( aLRULst.end() != it, "word not found in LRU list" );
|
|
|
|
aLRULst.erase( it );
|
2002-08-06 07:37:50 +00:00
|
|
|
delete pCurrent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-14 08:30:41 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|