Kaydet (Commit) d7a6815f authored tarafından Brad Sowden's avatar Brad Sowden Kaydeden (comit) Michael Stahl

Replace SvStringsISortDtor in edtwin.cxx and gloslst.[ch]xx

Note that the replacement vector stores all strings first and then
sort and "unique" are applied (ASCII treated as case-insensitive).
Previously strings were inserted sequentially and only the first
version of a string would be stored (case-insensitive ASCII
comparision). This should have no material impact as the strings
retreived from SwAutoCompleteWord are already unique (case-
insensitive ASCII comparison) and the capitalization of the string
is generally changed anyway to match the capitalization of the word
to be auto-completed. Also, there appears to be no logical reason
to store the first inserted version of a string over of the first
version post-sort.

Change-Id: I132865bbb9b382d417fb2cff9de351fdb2cbfb13
üst 4f182120
...@@ -143,6 +143,7 @@ ...@@ -143,6 +143,7 @@
#include <PostItMgr.hxx> #include <PostItMgr.hxx>
#include <algorithm> #include <algorithm>
#include <vector>
#include "../../core/inc/rootfrm.hxx" #include "../../core/inc/rootfrm.hxx"
...@@ -271,33 +272,39 @@ public: ...@@ -271,33 +272,39 @@ public:
struct QuickHelpData struct QuickHelpData
{ {
SvStringsISortDtor aArr; std::vector<String> *pHelpStrings;
sal_uInt16* pAttrs; sal_uInt16* pAttrs;
CommandExtTextInputData* pCETID; CommandExtTextInputData* pCETID;
sal_uLong nTipId; sal_uLong nTipId;
sal_uInt16 nLen, nCurArrPos; sal_uInt16 nLen, nCurArrPos;
sal_Bool bClear : 1, bChkInsBlank : 1, bIsTip : 1, bIsAutoText : 1; sal_Bool bClear : 1, bChkInsBlank : 1, bIsTip : 1, bIsAutoText : 1;
QuickHelpData() : pAttrs( 0 ), pCETID( 0 ) { ClearCntnt(); } QuickHelpData() : pAttrs( 0 ), pCETID( 0 )
{
pHelpStrings = new std::vector<String>;
ClearCntnt();
}
~QuickHelpData() { delete pHelpStrings; }
void Move( QuickHelpData& rCpy ); void Move( QuickHelpData& rCpy );
void ClearCntnt(); void ClearCntnt();
void Start( SwWrtShell& rSh, sal_uInt16 nWrdLen ); void Start( SwWrtShell& rSh, sal_uInt16 nWrdLen );
void Stop( SwWrtShell& rSh ); void Stop( SwWrtShell& rSh );
sal_Bool HasCntnt() const { return aArr.Count() && 0 != nLen; } sal_Bool HasCntnt() const { return !pHelpStrings->empty() && 0 != nLen; }
void Inc( sal_Bool bEndLess ) void Inc( sal_Bool bEndLess )
{ {
if( ++nCurArrPos >= aArr.Count() ) if( ++nCurArrPos >= pHelpStrings->size() )
nCurArrPos = (bEndLess && !bIsAutoText )? 0 : nCurArrPos-1; nCurArrPos = (bEndLess && !bIsAutoText ) ? 0 : nCurArrPos-1;
} }
void Dec( sal_Bool bEndLess ) void Dec( sal_Bool bEndLess )
{ {
if( 0 == nCurArrPos-- ) if( 0 == nCurArrPos-- )
nCurArrPos = (bEndLess && !bIsAutoText ) ? aArr.Count()-1 : 0; nCurArrPos = (bEndLess && !bIsAutoText ) ? pHelpStrings->size()-1 : 0;
} }
void FillStrArr( SwWrtShell& rSh, const String& rWord ); void FillStrArr( SwWrtShell& rSh, const String& rWord );
void SortAndFilter();
}; };
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -2468,7 +2475,7 @@ KEYINPUT_CHECKTABLE_INSDEL: ...@@ -2468,7 +2475,7 @@ KEYINPUT_CHECKTABLE_INSDEL:
// replace the word or abbreviation with the auto text // replace the word or abbreviation with the auto text
rSh.StartUndo( UNDO_START ); rSh.StartUndo( UNDO_START );
String sFnd( *aTmpQHD.aArr[ aTmpQHD.nCurArrPos ] ); String sFnd( (*aTmpQHD.pHelpStrings)[ aTmpQHD.nCurArrPos ] );
if( aTmpQHD.bIsAutoText ) if( aTmpQHD.bIsAutoText )
{ {
SwGlossaryList* pList = ::GetGlossaryList(); SwGlossaryList* pList = ::GetGlossaryList();
...@@ -5464,9 +5471,9 @@ uno::Reference< ::com::sun::star::accessibility::XAccessible > SwEditWin::Create ...@@ -5464,9 +5471,9 @@ uno::Reference< ::com::sun::star::accessibility::XAccessible > SwEditWin::Create
void QuickHelpData::Move( QuickHelpData& rCpy ) void QuickHelpData::Move( QuickHelpData& rCpy )
{ {
// move pointer pHelpStrings->clear();
aArr.Insert( &rCpy.aArr ); std::swap( pHelpStrings, rCpy.pHelpStrings );
rCpy.aArr.Remove( (sal_uInt16)0, rCpy.aArr.Count() );
bClear = rCpy.bClear; bClear = rCpy.bClear;
nLen = rCpy.nLen; nLen = rCpy.nLen;
nCurArrPos = rCpy.nCurArrPos; nCurArrPos = rCpy.nCurArrPos;
...@@ -5478,8 +5485,7 @@ void QuickHelpData::Move( QuickHelpData& rCpy ) ...@@ -5478,8 +5485,7 @@ void QuickHelpData::Move( QuickHelpData& rCpy )
pCETID = rCpy.pCETID; pCETID = rCpy.pCETID;
rCpy.pCETID = 0; rCpy.pCETID = 0;
if( pAttrs ) delete[] pAttrs;
delete[] pAttrs;
pAttrs = rCpy.pAttrs; pAttrs = rCpy.pAttrs;
rCpy.pAttrs = 0; rCpy.pAttrs = 0;
} }
...@@ -5489,7 +5495,7 @@ void QuickHelpData::ClearCntnt() ...@@ -5489,7 +5495,7 @@ void QuickHelpData::ClearCntnt()
nLen = nCurArrPos = 0; nLen = nCurArrPos = 0;
bClear = bChkInsBlank = sal_False; bClear = bChkInsBlank = sal_False;
nTipId = 0; nTipId = 0;
aArr.DeleteAndDestroy( 0 , aArr.Count() ); pHelpStrings->clear();
bIsTip = sal_True; bIsTip = sal_True;
bIsAutoText = sal_True; bIsAutoText = sal_True;
delete pCETID, pCETID = 0; delete pCETID, pCETID = 0;
...@@ -5498,8 +5504,11 @@ void QuickHelpData::ClearCntnt() ...@@ -5498,8 +5504,11 @@ void QuickHelpData::ClearCntnt()
void QuickHelpData::Start( SwWrtShell& rSh, sal_uInt16 nWrdLen ) void QuickHelpData::Start( SwWrtShell& rSh, sal_uInt16 nWrdLen )
{ {
if( pCETID ) delete pCETID, pCETID = 0; delete pCETID;
if( pAttrs ) delete[] pAttrs, pAttrs = 0; pCETID = 0;
delete[] pAttrs;
pAttrs = 0;
if( USHRT_MAX != nWrdLen ) if( USHRT_MAX != nWrdLen )
{ {
...@@ -5515,12 +5524,12 @@ void QuickHelpData::Start( SwWrtShell& rSh, sal_uInt16 nWrdLen ) ...@@ -5515,12 +5524,12 @@ void QuickHelpData::Start( SwWrtShell& rSh, sal_uInt16 nWrdLen )
rSh.GetCharRect().Pos() ))); rSh.GetCharRect().Pos() )));
aPt.Y() -= 3; aPt.Y() -= 3;
nTipId = Help::ShowTip( &rWin, Rectangle( aPt, Size( 1, 1 )), nTipId = Help::ShowTip( &rWin, Rectangle( aPt, Size( 1, 1 )),
*aArr[ nCurArrPos ], (*pHelpStrings)[ nCurArrPos ],
QUICKHELP_LEFT | QUICKHELP_BOTTOM ); QUICKHELP_LEFT | QUICKHELP_BOTTOM );
} }
else else
{ {
String sStr( *aArr[ nCurArrPos ] ); String sStr( (*pHelpStrings)[ nCurArrPos ] );
sStr.Erase( 0, nLen ); sStr.Erase( 0, nLen );
sal_uInt16 nL = sStr.Len(); sal_uInt16 nL = sStr.Len();
pAttrs = new sal_uInt16[ nL ]; pAttrs = new sal_uInt16[ nL ];
...@@ -5573,9 +5582,7 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord ) ...@@ -5573,9 +5582,7 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord )
COMPARE_EQUAL == rWord.CompareIgnoreCaseToAscii( COMPARE_EQUAL == rWord.CompareIgnoreCaseToAscii(
sStr, rWord.Len() )) sStr, rWord.Len() ))
{ {
String* pNew = new String( sStr ); pHelpStrings->push_back( sStr );
if( !aArr.Insert( pNew ) )
delete pNew;
} }
} }
if( !n ) // get data for the second loop if( !n ) // get data for the second loop
...@@ -5616,15 +5623,42 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord ) ...@@ -5616,15 +5623,42 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord )
else // mixed case - use what we have else // mixed case - use what we have
aMatch = rS; aMatch = rS;
String *pNew = new String( aMatch ); pHelpStrings->push_back( aMatch );
if (!aArr.Insert( pNew ))
delete pNew;
} }
++nStt; ++nStt;
} }
} }
} }
// TODO - implement an i18n aware sort
void QuickHelpData::SortAndFilter()
{
struct CompareIgnoreCaseAscii
{
bool operator()(const String& s1, const String& s2) const
{
return s1.CompareIgnoreCaseToAscii(s2) == COMPARE_LESS;
}
};
std::sort( pHelpStrings->begin(),
pHelpStrings->end(),
CompareIgnoreCaseAscii() );
struct EqualIgnoreCaseAscii
{
bool operator()(const String& s1, const String& s2) const
{
return s1.CompareIgnoreCaseToAscii(s2) == COMPARE_EQUAL;
}
};
std::vector<String>::iterator it = std::unique( pHelpStrings->begin(),
pHelpStrings->end(),
EqualIgnoreCaseAscii() );
pHelpStrings->erase( it, pHelpStrings->end() );
nCurArrPos = 0;
}
void SwEditWin::ShowAutoTextCorrectQuickHelp( void SwEditWin::ShowAutoTextCorrectQuickHelp(
const String& rWord, SvxAutoCorrCfg* pACfg, SvxAutoCorrect* pACorr, const String& rWord, SvxAutoCorrCfg* pACfg, SvxAutoCorrect* pACorr,
sal_Bool bFromIME ) sal_Bool bFromIME )
...@@ -5634,10 +5668,10 @@ void SwEditWin::ShowAutoTextCorrectQuickHelp( ...@@ -5634,10 +5668,10 @@ void SwEditWin::ShowAutoTextCorrectQuickHelp(
if( pACfg->IsAutoTextTip() ) if( pACfg->IsAutoTextTip() )
{ {
SwGlossaryList* pList = ::GetGlossaryList(); SwGlossaryList* pList = ::GetGlossaryList();
pList->HasLongName( rWord, &pQuickHlpData->aArr ); pList->HasLongName( rWord, pQuickHlpData->pHelpStrings );
} }
if( pQuickHlpData->aArr.Count() ) if( !pQuickHlpData->pHelpStrings->empty() )
{ {
pQuickHlpData->bIsTip = sal_True; pQuickHlpData->bIsTip = sal_True;
pQuickHlpData->bIsAutoText = sal_True; pQuickHlpData->bIsAutoText = sal_True;
...@@ -5652,8 +5686,12 @@ void SwEditWin::ShowAutoTextCorrectQuickHelp( ...@@ -5652,8 +5686,12 @@ void SwEditWin::ShowAutoTextCorrectQuickHelp(
pQuickHlpData->FillStrArr( rSh, rWord ); pQuickHlpData->FillStrArr( rSh, rWord );
} }
if( pQuickHlpData->aArr.Count() )
if( !pQuickHlpData->pHelpStrings->empty() )
{
pQuickHlpData->SortAndFilter();
pQuickHlpData->Start( rSh, rWord.Len() ); pQuickHlpData->Start( rSh, rWord.Len() );
}
} }
void SwEditWin::ShowHeaderFooterSeparator( bool bShowHeader, bool bShowFooter ) void SwEditWin::ShowHeaderFooterSeparator( bool bShowHeader, bool bShowFooter )
......
...@@ -33,10 +33,9 @@ ...@@ -33,10 +33,9 @@
#include <tools/datetime.hxx> #include <tools/datetime.hxx>
#include <tools/string.hxx> #include <tools/string.hxx>
#include <vcl/timer.hxx> #include <vcl/timer.hxx>
#include <svl/svarray.hxx>
class SwGlossaries; class SwGlossaries;
class SvStringsISortDtor; class vector;
struct AutoTextGroup struct AutoTextGroup
{ {
...@@ -66,7 +65,7 @@ public: ...@@ -66,7 +65,7 @@ public:
SwGlossaryList(); SwGlossaryList();
~SwGlossaryList(); ~SwGlossaryList();
sal_Bool HasLongName(const String& rBegin, SvStringsISortDtor* pLongNames ); bool HasLongName(const String& rBegin, std::vector<String> *pLongNames);
sal_Bool GetShortName(const String& rLongName, sal_Bool GetShortName(const String& rLongName,
String& rShortName, String& rGroupName ); String& rShortName, String& rGroupName );
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
* *
************************************************************************/ ************************************************************************/
#include <svl/svstdarr.hxx>
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <vcl/dialog.hxx> #include <vcl/dialog.hxx>
#include <vcl/msgbox.hxx> #include <vcl/msgbox.hxx>
...@@ -423,7 +422,7 @@ void SwGlossaryList::FillGroup(AutoTextGroup* pGroup, SwGlossaries* pGlossaries) ...@@ -423,7 +422,7 @@ void SwGlossaryList::FillGroup(AutoTextGroup* pGroup, SwGlossaries* pGlossaries)
passendem Anfang zurueckgeben passendem Anfang zurueckgeben
********************************************************************/ ********************************************************************/
sal_Bool SwGlossaryList::HasLongName(const String& rBegin, SvStringsISortDtor* pLongNames ) bool SwGlossaryList::HasLongName(const String& rBegin, std::vector<String> *pLongNames)
{ {
if(!bFilled) if(!bFilled)
Update(); Update();
...@@ -441,8 +440,7 @@ sal_Bool SwGlossaryList::HasLongName(const String& rBegin, SvStringsISortDtor* p ...@@ -441,8 +440,7 @@ sal_Bool SwGlossaryList::HasLongName(const String& rBegin, SvStringsISortDtor* p
if( rSCmp.isEqual( sBlock.Copy(0, nBeginLen), rBegin ) && if( rSCmp.isEqual( sBlock.Copy(0, nBeginLen), rBegin ) &&
nBeginLen + 1 < sBlock.Len()) nBeginLen + 1 < sBlock.Len())
{ {
String* pBlock = new String(sBlock); pLongNames->push_back( sBlock );
pLongNames->Insert(pBlock);
nFound++; nFound++;
if(FIND_MAX_GLOS == nFound) if(FIND_MAX_GLOS == nFound)
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment