summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2012-07-25 12:07:33 +0200
committerMichael Stahl <mstahl@redhat.com>2012-07-25 14:13:46 +0200
commit0031210b26bfae38be4243f9c92d90fa213b9eb0 (patch)
tree13fd775310b614741146d0ad9673044ac947f8d1
parenttblrwcl.cxx: convert 2 sorted_vectors to 1 map (diff)
downloadcore-0031210b26bfae38be4243f9c92d90fa213b9eb0.tar.gz
core-0031210b26bfae38be4243f9c92d90fa213b9eb0.zip
autocomplete: replace horrible use of SvStringsISortDtor...
... to store not Strings but derived SwAutoCompleteStrings with something far saner: an abstract base class with virtual dtor. Change-Id: I7d966f385dd41154ee1c4cdb43b56ff1aace9b5e
-rw-r--r--cui/source/inc/autocdlg.hxx4
-rw-r--r--cui/source/tabpages/autocdlg.cxx28
-rw-r--r--editeng/inc/editeng/swafopt.hxx44
-rw-r--r--editeng/source/misc/swafopt.cxx4
-rw-r--r--sw/inc/acmplwrd.hxx20
-rw-r--r--sw/source/core/doc/acmplwrd.cxx84
-rw-r--r--sw/source/ui/app/docsh2.cxx8
7 files changed, 123 insertions, 69 deletions
diff --git a/cui/source/inc/autocdlg.hxx b/cui/source/inc/autocdlg.hxx
index 7fab79e9276c..90395416cd1d 100644
--- a/cui/source/inc/autocdlg.hxx
+++ b/cui/source/inc/autocdlg.hxx
@@ -40,6 +40,8 @@ class CharClass;
class CollatorWrapper;
class SmartTagMgr;
+namespace editeng { class SortedAutoCompleteStrings; }
+
// class OfaAutoCorrDlg --------------------------------------------------
class OfaAutoCorrDlg : public SfxTabDialog
@@ -439,7 +441,7 @@ class OfaAutoCompleteTabPage : public SfxTabPage
NumericField aNFMaxEntries;
AutoCompleteMultiListBox aLBEntries;
PushButton aPBEntries;
- SvStringsISortDtor* pAutoCmpltList;
+ editeng::SortedAutoCompleteStrings* m_pAutoCompleteList;
sal_uInt16 nAutoCmpltListCnt;
DECL_LINK( CheckHdl, CheckBox* );
diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx
index 2808cf2c791b..a44e5d3d977e 100644
--- a/cui/source/tabpages/autocdlg.cxx
+++ b/cui/source/tabpages/autocdlg.cxx
@@ -2224,7 +2224,7 @@ OfaAutoCompleteTabPage::OfaAutoCompleteTabPage( Window* pParent,
aNFMaxEntries (this, CUI_RES(NF_MAX_ENTRIES)),
aLBEntries (*this, CUI_RES(LB_ENTRIES)),
aPBEntries (this, CUI_RES(PB_ENTRIES)),
- pAutoCmpltList( 0 ),
+ m_pAutoCompleteList( 0 ),
nAutoCmpltListCnt( 0 )
{
FreeResource();
@@ -2303,10 +2303,10 @@ sal_Bool OfaAutoCompleteTabPage::FillItemSet( SfxItemSet& )
pOpt->nAutoCmpltExpandKey = (sal_uInt16)nKey;
}
- if( pAutoCmpltList && nAutoCmpltListCnt != aLBEntries.GetEntryCount() )
+ if (m_pAutoCompleteList && nAutoCmpltListCnt != aLBEntries.GetEntryCount())
{
bModified = sal_True;
- pOpt->pAutoCmpltList = pAutoCmpltList;
+ pOpt->m_pAutoCompleteList = m_pAutoCompleteList;
}
if( bModified )
{
@@ -2342,14 +2342,16 @@ void OfaAutoCompleteTabPage::Reset( const SfxItemSet& )
}
}
- if( pOpt->pAutoCmpltList && pOpt->pAutoCmpltList->size() )
+ if (pOpt->m_pAutoCompleteList && pOpt->m_pAutoCompleteList->size())
{
- pAutoCmpltList = (SvStringsISortDtor*)pOpt->pAutoCmpltList;
- pOpt->pAutoCmpltList = 0;
- nAutoCmpltListCnt = pAutoCmpltList->size();
- for( sal_uInt16 n = 0; n < nAutoCmpltListCnt; ++n )
+ m_pAutoCompleteList = const_cast<editeng::SortedAutoCompleteStrings*>(
+ pOpt->m_pAutoCompleteList);
+ pOpt->m_pAutoCompleteList = 0;
+ nAutoCmpltListCnt = m_pAutoCompleteList->size();
+ for (size_t n = 0; n < nAutoCmpltListCnt; ++n)
{
- const StringPtr pStr = (*pAutoCmpltList)[ n ];
+ const String* pStr =
+ &(*m_pAutoCompleteList)[n]->GetAutoCompleteString();
sal_uInt16 nPos = aLBEntries.InsertEntry( *pStr );
aLBEntries.SetEntryData( nPos, (void*)pStr );
}
@@ -2371,13 +2373,15 @@ void OfaAutoCompleteTabPage::ActivatePage( const SfxItemSet& )
IMPL_LINK_NOARG(OfaAutoCompleteTabPage, DeleteHdl)
{
- sal_uInt16 nSelCnt = pAutoCmpltList ? aLBEntries.GetSelectEntryCount() : 0;
+ sal_uInt16 nSelCnt =
+ (m_pAutoCompleteList) ? aLBEntries.GetSelectEntryCount() : 0;
while( nSelCnt )
{
sal_uInt16 nPos = aLBEntries.GetSelectEntryPos( --nSelCnt );
StringPtr pStr = (StringPtr)aLBEntries.GetEntryData( nPos );
aLBEntries.RemoveEntry( nPos );
- pAutoCmpltList->erase( pStr );
+ editeng::IAutoCompleteString hack(*pStr); // UGLY
+ m_pAutoCompleteList->erase(&hack);
}
return 0;
}
@@ -2400,7 +2404,7 @@ IMPL_LINK( OfaAutoCompleteTabPage, CheckHdl, CheckBox*, pBox )
void OfaAutoCompleteTabPage::CopyToClipboard() const
{
sal_uInt16 nSelCnt = aLBEntries.GetSelectEntryCount();
- if( pAutoCmpltList && nSelCnt )
+ if (m_pAutoCompleteList && nSelCnt)
{
TransferDataContainer* pCntnr = new TransferDataContainer;
::com::sun::star::uno::Reference<
diff --git a/editeng/inc/editeng/swafopt.hxx b/editeng/inc/editeng/swafopt.hxx
index 38072e699d9e..684a1838c731 100644
--- a/editeng/inc/editeng/swafopt.hxx
+++ b/editeng/inc/editeng/swafopt.hxx
@@ -16,21 +16,57 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#ifndef _SVXSWAFOPT_HXX
-#define _SVXSWAFOPT_HXX
+
+#ifndef EE_SVXSWAFOPT_HXX
+#define EE_SVXSWAFOPT_HXX
+
+#include <o3tl/sorted_vector.hxx>
+
+#include <tools/string.hxx>
#include <vcl/font.hxx>
#include "editeng/editengdllapi.h"
-class SvStringsISortDtor;
class SmartTagMgr;
+namespace editeng {
+
+class EDITENG_DLLPUBLIC IAutoCompleteString
+{
+private:
+ String m_String;
+public:
+ explicit IAutoCompleteString(String const& rString) : m_String(rString) {}
+ virtual ~IAutoCompleteString() {}
+ String const& GetAutoCompleteString() const { return m_String; }
+};
+
+struct CompareAutoCompleteString
+{
+ bool operator()(IAutoCompleteString *const& lhs,
+ IAutoCompleteString *const& rhs) const
+ {
+ return lhs->GetAutoCompleteString().CompareIgnoreCaseToAscii(
+ rhs->GetAutoCompleteString()) == COMPARE_LESS;
+ }
+};
+
+class SortedAutoCompleteStrings
+ : public o3tl::sorted_vector<IAutoCompleteString*, CompareAutoCompleteString>
+{
+public:
+ ~SortedAutoCompleteStrings() { DeleteAndDestroyAll(); }
+};
+
+} // namespace editeng
+
// Class of options for AutoFormat
struct EDITENG_DLLPUBLIC SvxSwAutoFmtFlags
{
Font aBulletFont;
Font aByInputBulletFont;
- const SvStringsISortDtor* pAutoCmpltList; // only valid inside the Dialog!!!
+ /// only valid inside the Dialog!!!
+ const editeng::SortedAutoCompleteStrings * m_pAutoCompleteList;
SmartTagMgr* pSmartTagMgr;
sal_Unicode cBullet;
diff --git a/editeng/source/misc/swafopt.cxx b/editeng/source/misc/swafopt.cxx
index 3bdf5730b28f..00f1a832c674 100644
--- a/editeng/source/misc/swafopt.cxx
+++ b/editeng/source/misc/swafopt.cxx
@@ -86,7 +86,7 @@ SvxSwAutoFmtFlags::SvxSwAutoFmtFlags()
nAutoCmpltWordLen = 10;
nAutoCmpltListLen = 500;
- pAutoCmpltList = 0;
+ m_pAutoCompleteList = 0;
pSmartTagMgr = 0;
}
@@ -140,7 +140,7 @@ SvxSwAutoFmtFlags& SvxSwAutoFmtFlags::operator=( const SvxSwAutoFmtFlags& rAFFla
bAutoCmpltEndless = rAFFlags.bAutoCmpltEndless;
bAutoCmpltAppendBlanc = rAFFlags.bAutoCmpltAppendBlanc;
bAutoCmpltShowAsTip = rAFFlags.bAutoCmpltShowAsTip;
- pAutoCmpltList = rAFFlags.pAutoCmpltList;
+ m_pAutoCompleteList = rAFFlags.m_pAutoCompleteList;
pSmartTagMgr = rAFFlags.pSmartTagMgr;
nAutoCmpltExpandKey = rAFFlags.nAutoCmpltExpandKey;
diff --git a/sw/inc/acmplwrd.hxx b/sw/inc/acmplwrd.hxx
index 34d9abca1f46..46281699f697 100644
--- a/sw/inc/acmplwrd.hxx
+++ b/sw/inc/acmplwrd.hxx
@@ -25,10 +25,13 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-#ifndef _ACMPLWRD_HXX
-#define _ACMPLWRD_HXX
-#include <svl/svstdarr.hxx>
+#ifndef SW_ACMPLWRD_HXX
+#define SW_ACMPLWRD_HXX
+
+#include <deque>
+
+#include <editeng/swafopt.hxx>
class SwDoc;
class SwAutoCompleteWord_Impl;
@@ -41,7 +44,8 @@ class SwAutoCompleteWord
{
friend class SwAutoCompleteClient;
- SvStringsISortDtor aWordLst; // contains extended strings carrying source information
+ /// contains extended strings carrying source information
+ editeng::SortedAutoCompleteStrings m_WordList;
SwAutoCompleteStringPtrDeque aLRULst;
SwAutoCompleteWord_Impl* pImpl;
@@ -57,7 +61,8 @@ public:
sal_Bool GetRange( const String& rWord, sal_uInt16& rStt, sal_uInt16& rEnd ) const;
- const String& operator[]( sal_uInt16 n ) const { return *aWordLst[ n ]; }
+ const String& operator[](size_t n) const
+ { return m_WordList[n]->GetAutoCompleteString(); }
bool IsLockWordLstLocked() const { return bLockWordLst; }
void SetLockWordLstLocked( bool bFlag ) { bLockWordLst = bFlag; }
@@ -67,8 +72,9 @@ public:
sal_uInt16 GetMinWordLen() const { return nMinWrdLen; }
void SetMinWordLen( sal_uInt16 n );
- const SvStringsISortDtor& GetWordList() const { return aWordLst; }
- void CheckChangedList( const SvStringsISortDtor& rNewLst );
+ const editeng::SortedAutoCompleteStrings& GetWordList() const
+ { return m_WordList; }
+ void CheckChangedList(const editeng::SortedAutoCompleteStrings& rNewLst);
};
diff --git a/sw/source/core/doc/acmplwrd.cxx b/sw/source/core/doc/acmplwrd.cxx
index 87c070288412..ebeb0b88ea29 100644
--- a/sw/source/core/doc/acmplwrd.cxx
+++ b/sw/source/core/doc/acmplwrd.cxx
@@ -85,7 +85,8 @@ public:
typedef const SwDoc* SwDocPtr;
typedef std::vector<SwDocPtr> SwDocPtrVector;
-class SwAutoCompleteString : public String
+class SwAutoCompleteString
+ : public editeng::IAutoCompleteString
{
#if OSL_DEBUG_LEVEL > 0
static sal_uLong nSwAutoCompleteStringCount;
@@ -184,8 +185,9 @@ void SwAutoCompleteWord_Impl::RemoveDocument(const SwDoc& rDoc)
}
}
-SwAutoCompleteString::SwAutoCompleteString(const String& rStr, xub_StrLen nPos, xub_StrLen nLen) :
- String( rStr, nPos, nLen )
+SwAutoCompleteString::SwAutoCompleteString(
+ const String& rStr, xub_StrLen const nPos, xub_StrLen const nLen)
+ : editeng::IAutoCompleteString(String(rStr, nPos, nLen))
{
#if OSL_DEBUG_LEVEL > 0
++nSwAutoCompleteStringCount;
@@ -223,7 +225,7 @@ bool SwAutoCompleteString::RemoveDocument(const SwDoc& rDoc)
}
SwAutoCompleteWord::SwAutoCompleteWord( sal_uInt16 nWords, sal_uInt16 nMWrdLen )
- : aWordLst(),
+ :
pImpl(new SwAutoCompleteWord_Impl(*this)),
nMaxCount( nWords ),
nMinWrdLen( nMWrdLen ),
@@ -233,12 +235,7 @@ SwAutoCompleteWord::SwAutoCompleteWord( sal_uInt16 nWords, sal_uInt16 nMWrdLen )
SwAutoCompleteWord::~SwAutoCompleteWord()
{
- for(sal_uInt16 nPos = aWordLst.size(); nPos; nPos--)
- {
- SwAutoCompleteString* pCurrent = (SwAutoCompleteString*)aWordLst[ nPos - 1 ];
- aWordLst.erase( aWordLst.begin() + nPos - 1 );
- delete pCurrent;
- }
+ m_WordList.DeleteAndDestroyAll(); // so the assertion below works
delete pImpl;
#if OSL_DEBUG_LEVEL > 0
sal_uLong nStrings = SwAutoCompleteString::GetElementCount();
@@ -273,8 +270,9 @@ sal_Bool SwAutoCompleteWord::InsertWord( const String& rWord, SwDoc& rDoc )
{
SwAutoCompleteString* pNew = new SwAutoCompleteString( aNewWord, 0, nWrdLen );
pNew->AddDocument(rDoc);
- std::pair<SvStringsISortDtor::const_iterator, bool> aInsPair;
- if( (aInsPair = aWordLst.insert( pNew )).second )
+ std::pair<editeng::SortedAutoCompleteStrings::const_iterator, bool>
+ aInsPair = m_WordList.insert(pNew);
+ if (aInsPair.second)
{
bRet = sal_True;
if (aLRULst.size() >= nMaxCount)
@@ -283,7 +281,7 @@ sal_Bool SwAutoCompleteWord::InsertWord( const String& rWord, SwDoc& rDoc )
// so that there is space for the first one
SwAutoCompleteString* pDel = aLRULst.back();
aLRULst.pop_back();
- aWordLst.erase( pDel );
+ m_WordList.erase(pDel);
delete pDel;
}
aLRULst.push_front(pNew);
@@ -316,15 +314,13 @@ void SwAutoCompleteWord::SetMaxCount( sal_uInt16 nNewMax )
{
// remove the trailing ones
sal_uInt16 nLRUIndex = nNewMax-1;
- while( nNewMax < aWordLst.size() && nLRUIndex < aLRULst.size())
+ while (nNewMax < m_WordList.size() && nLRUIndex < aLRULst.size())
{
- SvStringsISortDtor::const_iterator it =
- aWordLst.find( aLRULst[ nLRUIndex++ ] );
- OSL_ENSURE( aWordLst.end() != it, "String not found" );
- //FIXME this is utterly horrid: SwAutoCompleteString should
- // NOT derive from String
- SwAutoCompleteString* pDel = (SwAutoCompleteString*) *it;
- aWordLst.erase( it );
+ editeng::SortedAutoCompleteStrings::const_iterator it =
+ m_WordList.find(aLRULst[ nLRUIndex++ ]);
+ OSL_ENSURE( m_WordList.end() != it, "String not found" );
+ editeng::IAutoCompleteString *const pDel = *it;
+ m_WordList.erase(it);
delete pDel;
}
aLRULst.erase( aLRULst.begin() + nNewMax - 1, aLRULst.end() );
@@ -337,11 +333,12 @@ void SwAutoCompleteWord::SetMinWordLen( sal_uInt16 n )
// Do you really want to remove all words that are less than the minWrdLen?
if( n < nMinWrdLen )
{
- for( sal_uInt16 nPos = 0; nPos < aWordLst.size(); ++nPos )
- if( aWordLst[ nPos ]->Len() < n )
+ for (size_t nPos = 0; nPos < m_WordList.size(); ++nPos)
+ if (m_WordList[ nPos ]->GetAutoCompleteString().Len() < n)
{
- SwAutoCompleteString* pDel = (SwAutoCompleteString*) aWordLst[ nPos ];
- aWordLst.erase(aWordLst.begin() + nPos);
+ SwAutoCompleteString *const pDel =
+ dynamic_cast<SwAutoCompleteString*>(m_WordList[nPos]);
+ m_WordList.erase(nPos);
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pDel );
OSL_ENSURE( aLRULst.end() != it, "String not found" );
@@ -358,28 +355,34 @@ sal_Bool SwAutoCompleteWord::GetRange( const String& rWord, sal_uInt16& rStt,
sal_uInt16& rEnd ) const
{
const StringPtr pStr = (StringPtr)&rWord;
- rStt = aWordLst.find( pStr ) - aWordLst.begin();
+ editeng::IAutoCompleteString hack(*pStr); // UGLY
+ rStt = m_WordList.find(&hack) - m_WordList.begin();
rEnd = rStt;
const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
- while( rEnd < aWordLst.size() && rSCmp.isMatch( rWord, *aWordLst[ rEnd ]))
+ while (rEnd < m_WordList.size() &&
+ rSCmp.isMatch(rWord, m_WordList[rEnd]->GetAutoCompleteString()))
+ {
++rEnd;
+ }
return rStt < rEnd;
}
-void SwAutoCompleteWord::CheckChangedList( const SvStringsISortDtor& rNewLst )
+void SwAutoCompleteWord::CheckChangedList(
+ const editeng::SortedAutoCompleteStrings& rNewLst)
{
- sal_uInt16 nMyLen = aWordLst.size(), nNewLen = rNewLst.size();
- sal_uInt16 nMyPos = 0, nNewPos = 0;
+ size_t nMyLen = m_WordList.size(), nNewLen = rNewLst.size();
+ size_t nMyPos = 0, nNewPos = 0;
for( ; nMyPos < nMyLen && nNewPos < nNewLen; ++nMyPos, ++nNewPos )
{
- const StringPtr pStr = rNewLst[ nNewPos ];
- while( aWordLst[ nMyPos ] != pStr )
+ const editeng::IAutoCompleteString * pStr = rNewLst[ nNewPos ];
+ while (m_WordList[nMyPos] != pStr)
{
- SwAutoCompleteString* pDel = (SwAutoCompleteString*) aWordLst[ nMyPos ];
- aWordLst.erase(aWordLst.begin() + nMyPos);
+ SwAutoCompleteString *const pDel =
+ dynamic_cast<SwAutoCompleteString*>(m_WordList[nMyPos]);
+ m_WordList.erase(nMyPos);
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pDel );
OSL_ENSURE( aLRULst.end() != it, "String not found" );
@@ -395,14 +398,16 @@ void SwAutoCompleteWord::CheckChangedList( const SvStringsISortDtor& rNewLst )
// clear LRU array first then delete the string object
for( ; nNewPos < nMyLen; ++nNewPos )
{
- SwAutoCompleteString* pDel = (SwAutoCompleteString*) aWordLst[ nNewPos ];
+ SwAutoCompleteString *const pDel =
+ dynamic_cast<SwAutoCompleteString*>(m_WordList[nNewPos]);
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pDel );
OSL_ENSURE( aLRULst.end() != it, "String not found" );
aLRULst.erase( it );
delete pDel;
}
// remove from array
- aWordLst.erase( aWordLst.begin() + nMyPos, aWordLst.begin() + nMyLen);
+ m_WordList.erase(m_WordList.begin() + nMyPos,
+ m_WordList.begin() + nMyLen);
}
}
@@ -412,12 +417,13 @@ void SwAutoCompleteWord::DocumentDying(const SwDoc& rDoc)
SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
const sal_Bool bDelete = !pACorr->GetSwFlags().bAutoCmpltKeepList;
- for(sal_uInt16 nPos = aWordLst.size(); nPos; nPos--)
+ for (size_t nPos = m_WordList.size(); nPos; nPos--)
{
- SwAutoCompleteString* pCurrent = (SwAutoCompleteString*)aWordLst[ nPos - 1 ];
+ SwAutoCompleteString *const pCurrent =
+ dynamic_cast<SwAutoCompleteString*>(m_WordList[nPos - 1]);
if(pCurrent->RemoveDocument(rDoc) && bDelete)
{
- aWordLst.erase( aWordLst.begin() + nPos - 1 );
+ m_WordList.erase(nPos - 1);
SwAutoCompleteStringPtrDeque::iterator it = std::find( aLRULst.begin(), aLRULst.end(), pCurrent );
OSL_ENSURE( aLRULst.end() != it, "word not found in LRU list" );
aLRULst.erase( it );
diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx
index 32ee54712484..6138d48be0d3 100644
--- a/sw/source/ui/app/docsh2.cxx
+++ b/sw/source/ui/app/docsh2.cxx
@@ -642,8 +642,8 @@ void SwDocShell::Execute(SfxRequest& rReq)
rACW.SetLockWordLstLocked( true );
- SvStringsISortDtor aTmpLst( rACW.GetWordList() );
- pAFlags->pAutoCmpltList = &aTmpLst;
+ editeng::SortedAutoCompleteStrings aTmpLst( rACW.GetWordList() );
+ pAFlags->m_pAutoCompleteList = &aTmpLst;
SfxApplication* pApp = SFX_APP();
SfxRequest aAppReq(SID_AUTO_CORRECT_DLG, SFX_CALLMODE_SYNCHRON, pApp->GetPool());
@@ -670,11 +670,11 @@ void SwDocShell::Execute(SfxRequest& rReq)
SwEditShell::SetAutoFmtFlags( pAFlags );
rACW.SetMinWordLen( pAFlags->nAutoCmpltWordLen );
rACW.SetMaxCount( pAFlags->nAutoCmpltListLen );
- if( pAFlags->pAutoCmpltList ) // any changes?
+ if (pAFlags->m_pAutoCompleteList) // any changes?
{
rACW.CheckChangedList( aTmpLst );
// clear the temp WordList pointer
- pAFlags->pAutoCmpltList = 0;
+ pAFlags->m_pAutoCompleteList = 0;
}
// remove all pointer we never delete the strings
aTmpLst.clear();