From 2b8d794e448a7d3c573ff79cffe9decc8d960262 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 6 Dec 2024 19:25:07 +0100 Subject: [PATCH] tdf#159549 sw: fix style name in SwXStyle::getParentStyle() For a style that isn't inserted yet, the m_sParentStyleName is converted to UIName by setParentStyle() but isn't converted back to ProgName in getParentStyle(). This caused all of the writerfilter test failures in commit c166d112381f195a171425d1f9c1d38ce579319a. Change-Id: Ib5495785996807a8f3d9339ed2740f286b04d716 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177998 Tested-by: Jenkins Reviewed-by: Michael Stahl --- sw/inc/SwStyleNameMapper.hxx | 2 +- sw/source/core/doc/SwStyleNameMapper.cxx | 3 +- sw/source/core/unocore/unostyle.cxx | 37 +++++++++--------------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/sw/inc/SwStyleNameMapper.hxx b/sw/inc/SwStyleNameMapper.hxx index 4a3b0f1a582b..0fdfb381711a 100644 --- a/sw/inc/SwStyleNameMapper.hxx +++ b/sw/inc/SwStyleNameMapper.hxx @@ -89,7 +89,7 @@ public: // This gets the UI Name from the programmatic name static const OUString& GetUIName(const OUString& rName, SwGetPoolIdFromName); static void FillUIName(const OUString& rName, OUString& rFillName, - SwGetPoolIdFromName, bool bBugfix = false); + SwGetPoolIdFromName); // Get the programmatic Name from the UI name static const OUString& GetProgName(const OUString& rName, diff --git a/sw/source/core/doc/SwStyleNameMapper.cxx b/sw/source/core/doc/SwStyleNameMapper.cxx index 554ab750fe49..62d9f440e986 100644 --- a/sw/source/core/doc/SwStyleNameMapper.cxx +++ b/sw/source/core/doc/SwStyleNameMapper.cxx @@ -295,7 +295,7 @@ void SwStyleNameMapper::FillProgName( // Get the UI name from the programmatic name in rName and put it into rFillName void SwStyleNameMapper::FillUIName( const OUString& rName, OUString& rFillName, - SwGetPoolIdFromName const eFlags, bool const bBugfix) + SwGetPoolIdFromName const eFlags) { OUString aName = rName; if (eFlags == SwGetPoolIdFromName::ChrFmt && rName == "Standard") @@ -306,7 +306,6 @@ void SwStyleNameMapper::FillUIName( { rFillName = aName; if (eFlags != SwGetPoolIdFromName::TxtColl || // FIXME do it for all ids - !bBugfix || // TODO why does it change DOCX imports GetPoolIdFromUIName(aName, eFlags) == USHRT_MAX) { // aName isn't in our Prog name table...check if it has a " (user)" suffix, if so remove it diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 098750ab418d..ae1306b66f0a 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -959,8 +959,7 @@ rtl::Reference SwXStyleFamily::getStyleByName(const OUString& rNam if(!m_pBasePool) throw uno::RuntimeException(); OUString sStyleName; - SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId(), - !m_pDocShell->GetDoc()->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId()); SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family()); if(!pBase) throw container::NoSuchElementException(rName); @@ -1013,8 +1012,7 @@ sal_Bool SwXStyleFamily::hasByName(const OUString& rName) if(!m_pBasePool) throw uno::RuntimeException(); OUString sStyleName; - SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId(), - m_pDocShell && !m_pDocShell->GetDoc()->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId()); SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family()); return nullptr != pBase; } @@ -1025,8 +1023,7 @@ void SwXStyleFamily::insertStyleByName(const OUString& rName, const rtl::Referen if(!m_pBasePool) throw uno::RuntimeException(); OUString sStyleName; - SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId(), - !m_pDocShell->GetDoc()->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId()); SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family()); if (pBase) throw container::ElementExistException(); @@ -1039,8 +1036,7 @@ void SwXStyleFamily::insertByName(const OUString& rName, const uno::Any& rElemen if(!m_pBasePool) throw uno::RuntimeException(); OUString sStyleName; - SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId(), - !m_pDocShell->GetDoc()->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId()); SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family()); if (pBase) throw container::ElementExistException(); @@ -1103,8 +1099,7 @@ void SwXStyleFamily::replaceByName(const OUString& rName, const uno::Any& rEleme if(!m_pBasePool) throw uno::RuntimeException(); OUString sStyleName; - SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId(), - !m_pDocShell->GetDoc()->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId()); SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family()); // replacements only for userdefined styles if(!pBase) @@ -1165,8 +1160,7 @@ void SwXStyleFamily::removeByName(const OUString& rName) if(!m_pBasePool) throw uno::RuntimeException(); OUString sName; - SwStyleNameMapper::FillUIName(rName, sName, m_rEntry.poolId(), - m_pDocShell && !m_pDocShell->GetDoc()->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(rName, sName, m_rEntry.poolId()); SfxStyleSheetBase* pBase = m_pBasePool->Find(sName, m_rEntry.family()); if(!pBase) throw container::NoSuchElementException(); @@ -1439,7 +1433,9 @@ OUString SwXStyle::getParentStyle() { if(!m_bIsDescriptor) throw uno::RuntimeException(); - return m_sParentStyleName; + OUString ret; + SwStyleNameMapper::FillProgName(m_sParentStyleName, ret, lcl_GetSwEnumFromSfxEnum(m_rEntry.family())); + return ret; } SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName, m_rEntry.family()); OUString aString; @@ -1453,8 +1449,7 @@ void SwXStyle::setParentStyle(const OUString& rParentStyle) { SolarMutexGuard aGuard; OUString sParentStyle; - SwStyleNameMapper::FillUIName(rParentStyle, sParentStyle, lcl_GetSwEnumFromSfxEnum ( m_rEntry.family()), - m_pDoc && !m_pDoc->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(rParentStyle, sParentStyle, lcl_GetSwEnumFromSfxEnum(m_rEntry.family())); if(!m_pBasePool) { if(!m_bIsDescriptor) @@ -1760,8 +1755,7 @@ void SwXStyle::SetPropertyValue(const SfxItemPropertyMapEnt return; const auto sValue(rValue.get()); OUString aString; - SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.poolId(), - m_pDoc && !m_pDoc->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.poolId()); o_rStyleBase.getNewBase()->SetFollow(aString); } @@ -1775,8 +1769,7 @@ void SwXStyle::SetPropertyValue(const SfxItemPropertyMapEntry return; const auto sValue(rValue.get()); OUString aString; - SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.poolId(), - m_pDoc && !m_pDoc->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.poolId()); o_rStyleBase.getNewBase()->SetLink(aString); } @@ -1858,8 +1851,7 @@ void SwXStyle::SetPropertyValue(const SfxItemPrope const OUString sValue(rNamedValue.Value.get()); // get UI style name from programmatic style name OUString aStyleName; - SwStyleNameMapper::FillUIName(sValue, aStyleName, lcl_GetSwEnumFromSfxEnum(m_rEntry.family()), - m_pDoc && !m_pDoc->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(sValue, aStyleName, lcl_GetSwEnumFromSfxEnum(m_rEntry.family())); // check for correct context and style name const auto nIdx(GetCommandContextIndex(rNamedValue.Name)); @@ -1903,8 +1895,7 @@ void SwXStyle::SetPropertyValue(const SfxItemProperty aReg.SetWhich(SID_SWREGISTER_MODE); o_rStyleBase.GetItemSet().Put(aReg); OUString aString; - SwStyleNameMapper::FillUIName(sName, aString, SwGetPoolIdFromName::TxtColl, - m_pDoc && !m_pDoc->IsInWriterfilterImport()); + SwStyleNameMapper::FillUIName(sName, aString, SwGetPoolIdFromName::TxtColl); o_rStyleBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) ); } template<>