diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2014-06-28 21:08:57 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2014-06-30 15:36:27 +0100 |
commit | 5ca0cd55a19c522f1479737d7164947ae1ca4a6b (patch) | |
tree | e28bf7322a345a9acf613201200601e61746d11d | |
parent | bfb978334cea775b8ae5c40ceea050ea0660d80a (diff) |
sw: better encapsulate StyleSheet iterator's list.
Change-Id: I4fc06c739009a4754282854c4a0fce633213e50f
-rw-r--r-- | sw/inc/docstyle.hxx | 26 | ||||
-rw-r--r-- | sw/source/uibase/app/docstyle.cxx | 60 |
2 files changed, 46 insertions, 40 deletions
diff --git a/sw/inc/docstyle.hxx b/sw/inc/docstyle.hxx index 957be859dc69..63a30e020de5 100644 --- a/sw/inc/docstyle.hxx +++ b/sw/inc/docstyle.hxx @@ -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, diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx index 1ca2960b8c07..fb5845ea11e4 100644 --- a/sw/source/uibase/app/docstyle.cxx +++ b/sw/source/uibase/app/docstyle.cxx @@ -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 @@ -2481,7 +2486,7 @@ sal_uInt16 SwStyleSheetIterator::Count() return aLst.size(); } -SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_uInt16 nIdx ) +SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_uInt16 nIdx ) { // found if( !bFirstCalled ) @@ -2840,17 +2845,17 @@ SfxStyleSheetBase* SwStyleSheetIterator::First() if(!aLst.empty()) { - nLastPos = USHRT_MAX; + nLastPos = SAL_MAX_UINT32; return Next(); } return 0; } -SfxStyleSheetBase* SwStyleSheetIterator::Next() +SfxStyleSheetBase* SwStyleSheetIterator::Next() { assert(bFirstCalled); ++nLastPos; - if(!aLst.empty() && nLastPos < aLst.size()) + if(nLastPos < aLst.size()) { mxIterSheet->PresetNameAndFamily(aLst[nLastPos]); mxIterSheet->SetPhysical( false ); @@ -2865,14 +2870,14 @@ SfxStyleSheetBase* SwStyleSheetIterator::Next() return 0; } -SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName) +SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName) { // searching 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]); @@ -2948,7 +2953,7 @@ void SwDocStyleSheetPool::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 // iterating over the vector anyway so would still be slow - why does @@ -2958,7 +2963,7 @@ void SwStyleSheetIterator::InvalidateIterator() aLst.Erase(); } -void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint ) +void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint ) { // search and remove from View-List!! if( rHint.ISA( SfxStyleSheetHint ) && @@ -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()); } } |