Kaydet (Commit) 5ca0cd55 authored tarafından Michael Meeks's avatar Michael Meeks

sw: better encapsulate StyleSheet iterator's list.

Change-Id: I4fc06c739009a4754282854c4a0fce633213e50f
üst bfb97833
......@@ -36,15 +36,6 @@ class SwTxtFmtColl;
class SwFrmFmt;
class SwNumRule;
// Local helper class.
class SwPoolFmtList : public std::vector<OUString>
{
public:
SwPoolFmtList() {}
void Append( char cChar, const OUString& rStr );
void Erase();
};
// Temporary StyleSheet.
class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase
{
......@@ -146,10 +137,25 @@ public:
// Iterator for Pool.
class SwStyleSheetIterator : public SfxStyleSheetIterator, public SfxListener
{
// Local helper class.
class SwPoolFmtList
{
std::vector<OUString> maImpl;
public:
SwPoolFmtList() {}
void Append( char cChar, const OUString& rStr );
void Erase() { maImpl.clear(); }
size_t size() { return maImpl.size(); }
bool empty() { return maImpl.empty(); }
sal_uInt32 FindName(SfxStyleFamily eFam, const OUString &rName);
void RemoveName(SfxStyleFamily eFam, const OUString &rName);
const OUString &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
};
rtl::Reference< SwDocStyleSheet > mxIterSheet;
rtl::Reference< SwDocStyleSheet > mxStyleSheet;
SwPoolFmtList aLst;
sal_uInt16 nLastPos;
sal_uInt32 nLastPos;
bool bFirstCalled;
void AppendStyleList(const ::std::vector<OUString>& rLst,
......
......@@ -288,10 +288,10 @@ static const SwNumRule* lcl_FindNumRule( SwDoc& rDoc,
return pRule;
}
static sal_uInt16 lcl_FindName(const SwPoolFmtList& rLst, SfxStyleFamily eFam,
const OUString& rName)
sal_uInt32 SwStyleSheetIterator::SwPoolFmtList::FindName(SfxStyleFamily eFam,
const OUString &rName)
{
if(!rLst.empty())
if(!maImpl.empty())
{
sal_Unicode cStyle(0);
switch( eFam )
......@@ -316,27 +316,32 @@ static sal_uInt16 lcl_FindName(const SwPoolFmtList& rLst, SfxStyleFamily eFam,
break;
}
const OUString sSrch = OUString(cStyle) + rName;
for(size_t i = 0; i < rLst.size(); ++i)
if(rLst[i] == sSrch)
for(size_t i = 0; i < maImpl.size(); ++i)
if(maImpl[i] == sSrch)
return i;
}
return USHRT_MAX;
return SAL_MAX_UINT32;
}
void SwStyleSheetIterator::SwPoolFmtList::RemoveName(SfxStyleFamily eFam,
const OUString &rName)
{
sal_uInt32 nTmpPos = FindName( eFam, rName );
if( nTmpPos < maImpl.size() )
maImpl.erase(maImpl.begin() + nTmpPos);
}
// Add Strings to the list of templates
void SwPoolFmtList::Append( char cChar, const OUString& rStr )
void SwStyleSheetIterator::SwPoolFmtList::Append( char cChar, const OUString& rStr )
{
const OUString aStr = OUString(cChar) + rStr;
for(std::vector<OUString>::const_iterator i = begin(); i != end(); ++i)
for(std::vector<OUString>::const_iterator i = maImpl.begin();
i != maImpl.end(); ++i)
{
if(*i == aStr)
return;
push_back(aStr);
}
// Erase the list completely
void SwPoolFmtList::Erase()
{
clear();
}
maImpl.push_back(aStr);
}
// UI-sided implementation of StyleSheets
......@@ -2840,7 +2845,7 @@ SfxStyleSheetBase* SwStyleSheetIterator::First()
if(!aLst.empty())
{
nLastPos = USHRT_MAX;
nLastPos = SAL_MAX_UINT32;
return Next();
}
return 0;
......@@ -2850,7 +2855,7 @@ SfxStyleSheetBase* SwStyleSheetIterator::Next()
{
assert(bFirstCalled);
++nLastPos;
if(!aLst.empty() && nLastPos < aLst.size())
if(nLastPos < aLst.size())
{
mxIterSheet->PresetNameAndFamily(aLst[nLastPos]);
mxIterSheet->SetPhysical( false );
......@@ -2871,8 +2876,8 @@ SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName)
if( !bFirstCalled )
First();
nLastPos = lcl_FindName( aLst, nSearchFamily, rName );
if( USHRT_MAX != nLastPos )
nLastPos = aLst.FindName( nSearchFamily, rName );
if( SAL_MAX_UINT32 != nLastPos )
{
// found
mxStyleSheet->PresetNameAndFamily(aLst[nLastPos]);
......@@ -2967,12 +2972,7 @@ void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint )
SfxStyleSheetBase* pStyle = ((SfxStyleSheetHint&)rHint).GetStyleSheet();
if (pStyle)
{
sal_uInt16 nTmpPos = lcl_FindName( aLst, pStyle->GetFamily(),
pStyle->GetName() );
if( nTmpPos < aLst.size() )
aLst.erase(aLst.begin() + nTmpPos);
}
aLst.RemoveName(pStyle->GetFamily(), pStyle->GetName());
}
}
......
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