From 52d568f29994fbfcda675e4a519d3c50543c9703 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Wed, 23 Dec 2015 20:29:24 +0100 Subject: refactor SwXStyle::get/setParentStyle Change-Id: Ifb578244d511af153484d14ee92c5c22c2db0a3f --- sw/source/core/unocore/unostyle.cxx | 74 +++++++++++++++---------------------- 1 file changed, 29 insertions(+), 45 deletions(-) (limited to 'sw/source/core') diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 9b8d860dc4bc..c66a434a95d9 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1238,68 +1238,52 @@ sal_Bool SwXStyle::isInUse() throw( uno::RuntimeException, std::exception ) OUString SwXStyle::getParentStyle() throw( uno::RuntimeException, std::exception ) { SolarMutexGuard aGuard; - OUString aString; - if(m_pBasePool) + if(!m_pBasePool) { - m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); - SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); - if(pBase) - aString = pBase->GetParent(); + if(!m_bIsDescriptor) + throw uno::RuntimeException(); + return m_sParentStyleName; } - else if(m_bIsDescriptor) - aString = m_sParentStyleName; - else - throw uno::RuntimeException(); - SwStyleNameMapper::FillProgName(aString, aString, lcl_GetSwEnumFromSfxEnum ( m_rEntry.m_eFamily ), true ); + m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); + SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); + OUString aString; + if(pBase) + aString = pBase->GetParent(); + SwStyleNameMapper::FillProgName(aString, aString, lcl_GetSwEnumFromSfxEnum(m_rEntry.m_eFamily), true); return aString; } -void SwXStyle::setParentStyle(const OUString& rParentStyle) - throw( container::NoSuchElementException, uno::RuntimeException, std::exception ) +void SwXStyle::setParentStyle(const OUString& rParentStyle) throw( container::NoSuchElementException, uno::RuntimeException, std::exception ) { SolarMutexGuard aGuard; OUString sParentStyle; SwStyleNameMapper::FillUIName(rParentStyle, sParentStyle, lcl_GetSwEnumFromSfxEnum ( m_rEntry.m_eFamily ), true ); - if(m_pBasePool) + if(!m_pBasePool) { - m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); - bool bExcept = false; - SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); - if(pBase) - { - rtl::Reference< SwDocStyleSheet > xBase( new SwDocStyleSheet(*static_cast(pBase)) ); - //make it a 'real' style - necessary for pooled styles - xBase->GetItemSet(); - if(xBase->GetParent() != sParentStyle) - { - bExcept = !xBase->SetParent(sParentStyle); - } - } - else - bExcept = true; - if(bExcept) + if(!m_bIsDescriptor) throw uno::RuntimeException(); - } - else if(m_bIsDescriptor) - { m_sParentStyleName = sParentStyle; try { - uno::Any aAny = m_xStyleFamily->getByName ( sParentStyle ); - aAny >>= m_xStyleData; - } - catch ( container::NoSuchElementException& ) - { - } - catch ( lang::WrappedTargetException& ) - { - } - catch ( uno::RuntimeException& ) - { + const auto aAny = m_xStyleFamily->getByName(sParentStyle); + m_xStyleData = aAny.get(); } + catch(...) + { } + return; } - else + m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); + SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); + if(!pBase) throw uno::RuntimeException(); + rtl::Reference xBase(new SwDocStyleSheet(*static_cast(pBase))); + //make it a 'real' style - necessary for pooled styles + xBase->GetItemSet(); + if(xBase->GetParent() != sParentStyle) + { + if(!xBase->SetParent(sParentStyle)) + throw uno::RuntimeException(); + } } static uno::Reference< beans::XPropertySetInfo > lcl_getPropertySetInfo( SfxStyleFamily eFamily, bool bIsConditional ) -- cgit v1.2.3