From 9c0049cfae49c8e4ddef9125a69db2ad134c10c6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 13:48:25 +0200 Subject: Merging upstream version 4:24.2.4. Signed-off-by: Daniel Baumann --- svl/source/items/IndexedStyleSheets.cxx | 12 +++++++++++ svl/source/items/itemset.cxx | 18 ++++++++--------- svl/source/items/style.cxx | 36 +++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 24 deletions(-) (limited to 'svl/source/items') diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx index 57e2dddbf1..3761f0e427 100644 --- a/svl/source/items/IndexedStyleSheets.cxx +++ b/svl/source/items/IndexedStyleSheets.cxx @@ -82,6 +82,18 @@ sal_Int32 IndexedStyleSheets::GetNumberOfStyleSheets() const return mStyleSheets.size(); } +void +IndexedStyleSheets::ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName) +{ + auto it = mPositionsByName.find(rOldName); + if (it != mPositionsByName.end()) + { + unsigned nPos = it->second; + mPositionsByName.erase(it); + mPositionsByName.insert(std::make_pair(rNewName, nPos)); + } +} + void IndexedStyleSheets::AddStyleSheet(const rtl::Reference< SfxStyleSheetBase >& style) { diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx index 66780cb581..fd9cbb1ddd 100644 --- a/svl/source/items/itemset.cxx +++ b/svl/source/items/itemset.cxx @@ -1891,11 +1891,8 @@ static void isMiss() sal_uInt16 WhichRangesContainer::getOffsetFromWhich(sal_uInt16 nWhich) const { - if (empty()) - return INVALID_WHICHPAIR_OFFSET; - // special case for single entry - happens often e.g. UI stuff - if (1 == m_size) + if (m_size == 1) { if( m_pairs->first <= nWhich && nWhich <= m_pairs->second ) return nWhich - m_pairs->first; @@ -1904,6 +1901,9 @@ sal_uInt16 WhichRangesContainer::getOffsetFromWhich(sal_uInt16 nWhich) const return INVALID_WHICHPAIR_OFFSET; } + if (m_size == 0) + return INVALID_WHICHPAIR_OFFSET; + // check if nWhich is inside last successfully used WhichPair if (INVALID_WHICHPAIR_OFFSET != m_aLastWhichPairOffset && m_aLastWhichPairFirst <= nWhich @@ -1949,12 +1949,8 @@ sal_uInt16 WhichRangesContainer::getOffsetFromWhich(sal_uInt16 nWhich) const sal_uInt16 WhichRangesContainer::getWhichFromOffset(sal_uInt16 nOffset) const { - // check for empty, if yes, return null which is an invalid WhichID - if (empty()) - return 0; - // special case for single entry - happens often e.g. UI stuff - if (1 == m_size) + if (m_size == 1) { if (nOffset <= m_pairs->second - m_pairs->first) return m_pairs->first + nOffset; @@ -1963,6 +1959,10 @@ sal_uInt16 WhichRangesContainer::getWhichFromOffset(sal_uInt16 nOffset) const return 0; } + // check for empty, if yes, return null which is an invalid WhichID + if (m_size == 0) + return 0; + // check if nWhich is inside last successfully used WhichPair if (INVALID_WHICHPAIR_OFFSET != m_aLastWhichPairOffset) { diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx index 41551e5064..bfdbac6f3f 100644 --- a/svl/source/items/style.cxx +++ b/svl/source/items/style.cxx @@ -163,24 +163,24 @@ bool SfxStyleSheetBase::SetName(const OUString& rName, bool bReIndexNow) if(rName.isEmpty()) return false; - if( aName != rName ) - { - OUString aOldName = aName; - SfxStyleSheetBase *pOther = m_pPool->Find( rName, nFamily ) ; - if ( pOther && pOther != this ) - return false; + if( aName == rName ) + return true; - if ( !aName.isEmpty() ) - m_pPool->ChangeParent(aName, rName, nFamily, false); + OUString aOldName = aName; + SfxStyleSheetBase *pOther = m_pPool->Find( rName, nFamily ) ; + if ( pOther && pOther != this ) + return false; - if ( aFollow == aName ) - aFollow = rName; - aName = rName; - if (bReIndexNow) - m_pPool->Reindex(); + if ( !aName.isEmpty() ) + m_pPool->ChangeParent(aName, rName, nFamily, false); - m_pPool->Broadcast( SfxStyleSheetModifiedHint( aOldName, *this ) ); - } + if ( aFollow == aName ) + aFollow = rName; + aName = rName; + if (bReIndexNow) + m_pPool->ReindexOnNameChange(aOldName, rName); + + m_pPool->Broadcast( SfxStyleSheetModifiedHint( aOldName, *this ) ); return true; } @@ -890,6 +890,12 @@ SfxStyleSheetBasePool::Reindex() pImpl->mxIndexedStyleSheets->Reindex(); } +void +SfxStyleSheetBasePool::ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName) +{ + pImpl->mxIndexedStyleSheets->ReindexOnNameChange(rOldName, rNewName); +} + const svl::IndexedStyleSheets& SfxStyleSheetBasePool::GetIndexedStyleSheets() const { -- cgit v1.2.3