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; ...@@ -36,15 +36,6 @@ class SwTxtFmtColl;
class SwFrmFmt; class SwFrmFmt;
class SwNumRule; class SwNumRule;
// Local helper class.
class SwPoolFmtList : public std::vector<OUString>
{
public:
SwPoolFmtList() {}
void Append( char cChar, const OUString& rStr );
void Erase();
};
// Temporary StyleSheet. // Temporary StyleSheet.
class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase
{ {
...@@ -146,10 +137,25 @@ public: ...@@ -146,10 +137,25 @@ public:
// Iterator for Pool. // Iterator for Pool.
class SwStyleSheetIterator : public SfxStyleSheetIterator, public SfxListener 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 > mxIterSheet;
rtl::Reference< SwDocStyleSheet > mxStyleSheet; rtl::Reference< SwDocStyleSheet > mxStyleSheet;
SwPoolFmtList aLst; SwPoolFmtList aLst;
sal_uInt16 nLastPos; sal_uInt32 nLastPos;
bool bFirstCalled; bool bFirstCalled;
void AppendStyleList(const ::std::vector<OUString>& rLst, void AppendStyleList(const ::std::vector<OUString>& rLst,
......
...@@ -288,10 +288,10 @@ static const SwNumRule* lcl_FindNumRule( SwDoc& rDoc, ...@@ -288,10 +288,10 @@ static const SwNumRule* lcl_FindNumRule( SwDoc& rDoc,
return pRule; return pRule;
} }
static sal_uInt16 lcl_FindName(const SwPoolFmtList& rLst, SfxStyleFamily eFam, sal_uInt32 SwStyleSheetIterator::SwPoolFmtList::FindName(SfxStyleFamily eFam,
const OUString& rName) const OUString &rName)
{ {
if(!rLst.empty()) if(!maImpl.empty())
{ {
sal_Unicode cStyle(0); sal_Unicode cStyle(0);
switch( eFam ) switch( eFam )
...@@ -316,27 +316,32 @@ static sal_uInt16 lcl_FindName(const SwPoolFmtList& rLst, SfxStyleFamily eFam, ...@@ -316,27 +316,32 @@ static sal_uInt16 lcl_FindName(const SwPoolFmtList& rLst, SfxStyleFamily eFam,
break; break;
} }
const OUString sSrch = OUString(cStyle) + rName; const OUString sSrch = OUString(cStyle) + rName;
for(size_t i = 0; i < rLst.size(); ++i) for(size_t i = 0; i < maImpl.size(); ++i)
if(rLst[i] == sSrch) if(maImpl[i] == sSrch)
return i; 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 // 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; 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) if(*i == aStr)
return; return;
push_back(aStr); }
} maImpl.push_back(aStr);
// Erase the list completely
void SwPoolFmtList::Erase()
{
clear();
} }
// UI-sided implementation of StyleSheets // UI-sided implementation of StyleSheets
...@@ -2481,7 +2486,7 @@ sal_uInt16 SwStyleSheetIterator::Count() ...@@ -2481,7 +2486,7 @@ sal_uInt16 SwStyleSheetIterator::Count()
return aLst.size(); return aLst.size();
} }
SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_uInt16 nIdx ) SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_uInt16 nIdx )
{ {
// found // found
if( !bFirstCalled ) if( !bFirstCalled )
...@@ -2840,17 +2845,17 @@ SfxStyleSheetBase* SwStyleSheetIterator::First() ...@@ -2840,17 +2845,17 @@ SfxStyleSheetBase* SwStyleSheetIterator::First()
if(!aLst.empty()) if(!aLst.empty())
{ {
nLastPos = USHRT_MAX; nLastPos = SAL_MAX_UINT32;
return Next(); return Next();
} }
return 0; return 0;
} }
SfxStyleSheetBase* SwStyleSheetIterator::Next() SfxStyleSheetBase* SwStyleSheetIterator::Next()
{ {
assert(bFirstCalled); assert(bFirstCalled);
++nLastPos; ++nLastPos;
if(!aLst.empty() && nLastPos < aLst.size()) if(nLastPos < aLst.size())
{ {
mxIterSheet->PresetNameAndFamily(aLst[nLastPos]); mxIterSheet->PresetNameAndFamily(aLst[nLastPos]);
mxIterSheet->SetPhysical( false ); mxIterSheet->SetPhysical( false );
...@@ -2865,14 +2870,14 @@ SfxStyleSheetBase* SwStyleSheetIterator::Next() ...@@ -2865,14 +2870,14 @@ SfxStyleSheetBase* SwStyleSheetIterator::Next()
return 0; return 0;
} }
SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName) SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName)
{ {
// searching // searching
if( !bFirstCalled ) if( !bFirstCalled )
First(); First();
nLastPos = lcl_FindName( aLst, nSearchFamily, rName ); nLastPos = aLst.FindName( nSearchFamily, rName );
if( USHRT_MAX != nLastPos ) if( SAL_MAX_UINT32 != nLastPos )
{ {
// found // found
mxStyleSheet->PresetNameAndFamily(aLst[nLastPos]); mxStyleSheet->PresetNameAndFamily(aLst[nLastPos]);
...@@ -2948,7 +2953,7 @@ void SwDocStyleSheetPool::InvalidateIterator() ...@@ -2948,7 +2953,7 @@ void SwDocStyleSheetPool::InvalidateIterator()
dynamic_cast<SwStyleSheetIterator&>(GetIterator_Impl()).InvalidateIterator(); dynamic_cast<SwStyleSheetIterator&>(GetIterator_Impl()).InvalidateIterator();
} }
void SwStyleSheetIterator::InvalidateIterator() void SwStyleSheetIterator::InvalidateIterator()
{ {
// potentially we could send an SfxHint to Notify but currently it's // potentially we could send an SfxHint to Notify but currently it's
// iterating over the vector anyway so would still be slow - why does // iterating over the vector anyway so would still be slow - why does
...@@ -2958,7 +2963,7 @@ void SwStyleSheetIterator::InvalidateIterator() ...@@ -2958,7 +2963,7 @@ void SwStyleSheetIterator::InvalidateIterator()
aLst.Erase(); aLst.Erase();
} }
void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint ) void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint )
{ {
// search and remove from View-List!! // search and remove from View-List!!
if( rHint.ISA( SfxStyleSheetHint ) && if( rHint.ISA( SfxStyleSheetHint ) &&
...@@ -2967,12 +2972,7 @@ void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint ) ...@@ -2967,12 +2972,7 @@ void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint )
SfxStyleSheetBase* pStyle = ((SfxStyleSheetHint&)rHint).GetStyleSheet(); SfxStyleSheetBase* pStyle = ((SfxStyleSheetHint&)rHint).GetStyleSheet();
if (pStyle) if (pStyle)
{ aLst.RemoveName(pStyle->GetFamily(), pStyle->GetName());
sal_uInt16 nTmpPos = lcl_FindName( aLst, pStyle->GetFamily(),
pStyle->GetName() );
if( nTmpPos < aLst.size() )
aLst.erase(aLst.begin() + nTmpPos);
}
} }
} }
......
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