sw/inc/unobasestyle.hxx | 26 ++++++++ sw/inc/unostyle.hxx | 17 +++-- sw/inc/unoxstyle.hxx | 8 +- sw/source/core/unocore/unostyle.cxx | 58 +++++++++++++++---- sw/source/writerfilter/dmapper/DomainMapper.cxx | 4 - sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 6 - sw/source/writerfilter/dmapper/PropertyMap.cxx | 15 +--- sw/source/writerfilter/dmapper/StyleSheetTable.cxx | 2 8 files changed, 99 insertions(+), 37 deletions(-)
New commits: commit 3e05f32dbe8416ec95736174d036cab758f76c1f Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Aug 4 08:52:32 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun Aug 4 16:58:39 2024 +0200 use more concrete UNO type in writerfilter Change-Id: If112eea759f828cb07a9a42bd3d86d43078b4bf7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171455 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/unobasestyle.hxx b/sw/inc/unobasestyle.hxx new file mode 100644 index 000000000000..12254d3fcc5e --- /dev/null +++ b/sw/inc/unobasestyle.hxx @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +class SAL_DLLPUBLIC_RTTI SwXBaseStyle + : public cppu::WeakImplHelper<css::style::XStyle, css::beans::XPropertySet> +{ +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/unostyle.hxx b/sw/inc/unostyle.hxx index b6f4d9abd96b..d4618570bd9e 100644 --- a/sw/inc/unostyle.hxx +++ b/sw/inc/unostyle.hxx @@ -36,6 +36,7 @@ #include "coreframestyle.hxx" #include "istyleaccess.hxx" +#include "unobasestyle.hxx" #include <memory> #include <map> @@ -235,10 +236,9 @@ public: typedef std::map<OUString, sal_Int32> CellStyleNameMap; /// A text table style is a UNO API wrapper for a SwTableAutoFormat -class SwXTextTableStyle final : public cppu::WeakImplHelper +class SwXTextTableStyle final : public cppu::ImplInheritanceHelper < - css::style::XStyle, - css::beans::XPropertySet, + SwXBaseStyle, css::container::XNameContainer, css::lang::XServiceInfo > @@ -328,10 +328,9 @@ public: }; /// A text cell style is a UNO API wrapper for a SwBoxAutoFormat core class -class SwXTextCellStyle final : public cppu::WeakImplHelper +class SwXTextCellStyle final : public cppu::ImplInheritanceHelper < - css::style::XStyle, - css::beans::XPropertySet, + SwXBaseStyle, css::beans::XPropertyState, css::lang::XServiceInfo > @@ -451,6 +450,12 @@ public: virtual OUString SAL_CALL getImplementationName() override; virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + rtl::Reference<SwXBaseStyle> getStyleByName(const OUString& rName); + rtl::Reference<SwXPageStyle> getPageStyleByName(const OUString& rName); + void insertStyleByName(const OUString& Name, const rtl::Reference<SwXStyle>& Element); +private: + void insertStyleByNameImpl(const rtl::Reference<SwXStyle>& Element, const OUString& sStyleName); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/unoxstyle.hxx b/sw/inc/unoxstyle.hxx index 3a57b5b2087e..a70f5081565f 100644 --- a/sw/inc/unoxstyle.hxx +++ b/sw/inc/unoxstyle.hxx @@ -27,6 +27,7 @@ #include <com/sun/star/beans/XMultiPropertyStates.hpp> #include <cppuhelper/implbase.hxx> #include "coreframestyle.hxx" +#include "unobasestyle.hxx" class StyleFamilyEntry; class SwStyleBase_Impl; @@ -35,10 +36,9 @@ class SvxSetItem; struct SfxItemPropertyMapEntry; class SAL_DLLPUBLIC_RTTI SwXStyle - : public cppu::WeakImplHelper<css::style::XStyle, css::beans::XPropertySet, - css::beans::XMultiPropertySet, css::lang::XServiceInfo, - css::lang::XUnoTunnel, css::beans::XPropertyState, - css::beans::XMultiPropertyStates>, + : public cppu::ImplInheritanceHelper< + SwXBaseStyle, css::beans::XMultiPropertySet, css::lang::XServiceInfo, + css::lang::XUnoTunnel, css::beans::XPropertyState, css::beans::XMultiPropertyStates>, public SfxListener, public SvtListener { diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index eadcc025a665..3de7cdfe92a1 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -916,6 +916,19 @@ uno::Any SwXStyleFamily::getByIndex(sal_Int32 nIndex) } uno::Any SwXStyleFamily::getByName(const OUString& rName) +{ + return uno::Any(uno::Reference<style::XStyle>(getStyleByName(rName))); +} + +rtl::Reference<SwXPageStyle> SwXStyleFamily::getPageStyleByName(const OUString& rName) +{ + rtl::Reference<SwXBaseStyle> xStyle = getStyleByName(rName); + rtl::Reference<SwXPageStyle> xPageStyle = dynamic_cast<SwXPageStyle*>(xStyle.get()); + assert(bool(xStyle) == bool(xPageStyle)); + return xPageStyle; +} + +rtl::Reference<SwXBaseStyle> SwXStyleFamily::getStyleByName(const OUString& rName) { SolarMutexGuard aGuard; OUString sStyleName; @@ -925,7 +938,7 @@ uno::Any SwXStyleFamily::getByName(const OUString& rName) SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family()); if(!pBase) throw container::NoSuchElementException(rName); - uno::Reference<style::XStyle> xStyle = FindStyle(sStyleName); + rtl::Reference<SwXBaseStyle> xStyle = FindStyle(sStyleName); if(!xStyle.is()) switch (m_rEntry.family()) { @@ -949,7 +962,7 @@ uno::Any SwXStyleFamily::getByName(const OUString& rName) default: assert(false); } - return uno::Any(xStyle); + return xStyle; } uno::Sequence<OUString> SwXStyleFamily::getElementNames() @@ -979,6 +992,19 @@ sal_Bool SwXStyleFamily::hasByName(const OUString& rName) return nullptr != pBase; } +void SwXStyleFamily::insertStyleByName(const OUString& rName, const rtl::Reference<SwXStyle>& pNewStyle) +{ + SolarMutexGuard aGuard; + if(!m_pBasePool) + throw uno::RuntimeException(); + OUString sStyleName; + SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.poolId()); + SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, m_rEntry.family()); + if (pBase) + throw container::ElementExistException(); + insertStyleByNameImpl(pNewStyle, sStyleName); +} + void SwXStyleFamily::insertByName(const OUString& rName, const uno::Any& rElement) { SolarMutexGuard aGuard; @@ -1019,21 +1045,29 @@ void SwXStyleFamily::insertByName(const OUString& rName, const uno::Any& rElemen { uno::Reference<lang::XUnoTunnel> xStyleTunnel = rElement.get<uno::Reference<lang::XUnoTunnel>>(); SwXStyle* pNewStyle = comphelper::getFromUnoTunnel<SwXStyle>(xStyleTunnel); - if (!pNewStyle || !pNewStyle->IsDescriptor() || pNewStyle->GetFamily() != m_rEntry.family()) + if (!pNewStyle) throw lang::IllegalArgumentException(); - SfxStyleSearchBits nMask = SfxStyleSearchBits::All; - if(m_rEntry.family() == SfxStyleFamily::Para && !pNewStyle->IsConditional()) - nMask &= ~SfxStyleSearchBits::SwCondColl; - auto pStyle = &m_pBasePool->Make(sStyleName, m_rEntry.family(), nMask); - pNewStyle->SetDoc(m_pDocShell->GetDoc(), m_pBasePool); - pNewStyle->SetStyleName(sStyleName); - pStyle->SetParent(pNewStyle->GetParentStyleName()); - // after all, we still need to apply the properties of the descriptor - pNewStyle->ApplyDescriptorProperties(); + insertStyleByNameImpl(pNewStyle, sStyleName); } } +void SwXStyleFamily::insertStyleByNameImpl(const rtl::Reference<SwXStyle>& pNewStyle, const OUString& sStyleName) +{ + if (!pNewStyle->IsDescriptor() || pNewStyle->GetFamily() != m_rEntry.family()) + throw lang::IllegalArgumentException(); + + SfxStyleSearchBits nMask = SfxStyleSearchBits::All; + if(m_rEntry.family() == SfxStyleFamily::Para && !pNewStyle->IsConditional()) + nMask &= ~SfxStyleSearchBits::SwCondColl; + auto pStyle = &m_pBasePool->Make(sStyleName, m_rEntry.family(), nMask); + pNewStyle->SetDoc(m_pDocShell->GetDoc(), m_pBasePool); + pNewStyle->SetStyleName(sStyleName); + pStyle->SetParent(pNewStyle->GetParentStyleName()); + // after all, we still need to apply the properties of the descriptor + pNewStyle->ApplyDescriptorProperties(); +} + void SwXStyleFamily::replaceByName(const OUString& rName, const uno::Any& rElement) { SolarMutexGuard aGuard; diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx b/sw/source/writerfilter/dmapper/DomainMapper.cxx index d4399269eec6..23ce1fc4553b 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx @@ -1440,8 +1440,8 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) const uno::Reference<beans::XPropertySet> xFillPropertySet(xFill, uno::UNO_QUERY); const uno::Reference<beans::XPropertySetInfo> xFillInfo = xFillPropertySet->getPropertySetInfo(); - uno::Reference<beans::XPropertySet> xPS( - m_pImpl->GetPageStyles()->getByName(u"Standard"_ustr), uno::UNO_QUERY_THROW); + rtl::Reference<SwXBaseStyle> xPS = + m_pImpl->GetPageStyles()->getStyleByName(u"Standard"_ustr); for (const beans::Property& rProp : xPS->getPropertySetInfo()->getProperties()) { if (rProp.Name == "FillComplexColor" || rProp.Name == "FillGradientName" diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 942f0d516d17..805173b27cf2 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -3091,7 +3091,7 @@ void DomainMapper_Impl::applyToggleAttributes(const PropertyMapPtr& pPropertyMap sal_Int16 nCharStyleStrikeThrough = awt::FontStrikeout::NONE; bool bCharStyleHidden = false; - uno::Reference<beans::XPropertySet> xCharStylePropertySet = GetCharacterStyles()->getByName(sCharStyleName).get<uno::Reference<beans::XPropertySet>>(); + rtl::Reference<SwXBaseStyle> xCharStylePropertySet = GetCharacterStyles()->getStyleByName(sCharStyleName); xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_WEIGHT)) >>= fCharStyleBold; xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_WEIGHT_COMPLEX)) >>= fCharStyleBoldComplex; xCharStylePropertySet->getPropertyValue(getPropertyName(PROP_CHAR_POSTURE)) >>= eCharStylePosture; @@ -3106,8 +3106,8 @@ void DomainMapper_Impl::applyToggleAttributes(const PropertyMapPtr& pPropertyMap nCharStyleRelief != css::awt::FontRelief::NONE || bCharStyleContoured || bCharStyleShadowed || nCharStyleStrikeThrough == awt::FontStrikeout::SINGLE || bCharStyleHidden) { - uno::Reference<beans::XPropertySet> const xParaStylePropertySet = - GetParagraphStyles()->getByName(m_StreamStateStack.top().sCurrentParaStyleName).get<uno::Reference<beans::XPropertySet>>(); + rtl::Reference<SwXBaseStyle> const xParaStylePropertySet = + GetParagraphStyles()->getStyleByName(m_StreamStateStack.top().sCurrentParaStyleName); float fParaStyleBold = css::awt::FontWeight::NORMAL; float fParaStyleBoldComplex = css::awt::FontWeight::NORMAL; css::awt::FontSlant eParaStylePosture = css::awt::FontSlant_NONE; diff --git a/sw/source/writerfilter/dmapper/PropertyMap.cxx b/sw/source/writerfilter/dmapper/PropertyMap.cxx index 21638e5180c5..c033995a80dd 100644 --- a/sw/source/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/source/writerfilter/dmapper/PropertyMap.cxx @@ -496,14 +496,11 @@ rtl::Reference<SwXPageStyle> SectionPropertyMap::GetPageStyle(DomainMapper_Impl& m_sPageStyleName = rDM_Impl.GetUnusedPageStyleName(); m_aPageStyle = rDM_Impl.GetTextDocument()->createPageStyle(); - xPageStyles->insertByName(m_sPageStyleName, uno::Any(uno::Reference<style::XStyle>(m_aPageStyle))); + xPageStyles->insertStyleByName(m_sPageStyleName, m_aPageStyle); } else if (!m_aPageStyle.is() && xPageStyles.is()) { - uno::Reference<style::XStyle> xTmpStyle; - xPageStyles->getByName(m_sPageStyleName) >>= xTmpStyle; - m_aPageStyle = dynamic_cast<SwXPageStyle*>(xTmpStyle.get()); - assert(bool(xTmpStyle) == bool(m_aPageStyle) && "expect null or a SwXPageStyle here"); + m_aPageStyle = xPageStyles->getPageStyleByName(m_sPageStyleName); } xReturnPageStyle = m_aPageStyle; } @@ -1200,8 +1197,8 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl) } else if (rDM_Impl.m_bCopyStandardPageStyleFill) // complex fill: graphics/gradients/patterns { - uno::Reference<beans::XPropertySet> xDefaultPageStyle( - rDM_Impl.GetPageStyles()->getByName(u"Standard"_ustr), uno::UNO_QUERY_THROW); + rtl::Reference<SwXBaseStyle> xDefaultPageStyle = + rDM_Impl.GetPageStyles()->getStyleByName(u"Standard"_ustr); for (const beans::Property& rProp : m_aPageStyle->getPropertySetInfo()->getProperties()) { try @@ -1510,7 +1507,7 @@ void SectionPropertyMap::CreateEvenOddPageStyleCopy(DomainMapper_Impl& rDM_Impl, } evenOddStyle->setPropertyValue(u"FollowStyle"_ustr, uno::Any(m_sPageStyleName)); - rDM_Impl.GetPageStyles()->insertByName(evenOddStyleName, uno::Any(uno::Reference<style::XStyle>(evenOddStyle))); + rDM_Impl.GetPageStyles()->insertStyleByName(evenOddStyleName, evenOddStyle); if (rDM_Impl.IsNewDoc()) { @@ -1698,7 +1695,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) OUString aPageDescName; if ((xPropertySet->getPropertyValue(u"PageDescName"_ustr) >>= aPageDescName) && !aPageDescName.isEmpty()) { - uno::Reference<beans::XPropertySet> xPageStyle(rDM_Impl.GetPageStyles()->getByName(aPageDescName), uno::UNO_QUERY); + rtl::Reference<SwXBaseStyle> xPageStyle(rDM_Impl.GetPageStyles()->getStyleByName(aPageDescName)); xPageStyle->setPropertyValue(u"FollowStyle"_ustr, uno::Any(m_sPageStyleName)); m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), uno::Any(true)); } diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx index 18adf5b764a6..012177cda9d9 100644 --- a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx +++ b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx @@ -2164,7 +2164,7 @@ OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProp TOOLS_WARN_EXCEPTION( "writerfilter", "StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue"); } } - xCharStyles->insertByName( sListLabel, uno::Any( uno::Reference<style::XStyle>(xStyle) ) ); + xCharStyles->insertStyleByName( sListLabel, xStyle ); m_pImpl->m_aListCharStylePropertyVector.emplace_back( sListLabel, std::vector(rCharProperties) ); } catch( const uno::Exception& )