sw/inc/unotxdoc.hxx | 2 ++ sw/source/uibase/uno/unotxdoc.cxx | 14 ++++++++++++++ sw/source/writerfilter/dmapper/StyleSheetTable.cxx | 20 ++++++++++---------- 3 files changed, 26 insertions(+), 10 deletions(-)
New commits: commit ed015246b9b27e1ea1f87bc125262850d7128c0f Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Apr 25 16:26:59 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed May 1 09:09:07 2024 +0200 use more concrete UNO classes in writerfilter (SwXStyle) Change-Id: Ic1eb574efa2e4ce57185670d6570f24d1d8c9bb3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166936 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index b690a290b7b9..4bc4296633c2 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -531,6 +531,8 @@ public: SW_DLLPUBLIC rtl::Reference<SwXTextFrame> createTextFrame(); SW_DLLPUBLIC rtl::Reference<SwXTextGraphicObject> createTextGraphicObject(); SW_DLLPUBLIC rtl::Reference<SwXStyle> createNumberingStyle(); + SW_DLLPUBLIC rtl::Reference<SwXStyle> createCharacterStyle(); + SW_DLLPUBLIC rtl::Reference<SwXStyle> createParagraphStyle(); SW_DLLPUBLIC rtl::Reference<SwXPageStyle> createPageStyle(); SW_DLLPUBLIC rtl::Reference<SwXContentControl> createContentControl(); SW_DLLPUBLIC rtl::Reference<SwXFootnote> createFootnote(); diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index d9debd315fab..156f9aabad1f 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -1729,6 +1729,20 @@ rtl::Reference< SwXStyle > SwXTextDocument::createNumberingStyle() return SwXStyleFamilies::CreateStyleCharOrParaOrPseudo(SfxStyleFamily::Pseudo, GetDocOrThrow()); } +rtl::Reference< SwXStyle > SwXTextDocument::createCharacterStyle() +{ + SolarMutexGuard aGuard; + ThrowIfInvalid(); + return SwXStyleFamilies::CreateStyleCharOrParaOrPseudo(SfxStyleFamily::Char, GetDocOrThrow()); +} + +rtl::Reference< SwXStyle > SwXTextDocument::createParagraphStyle() +{ + SolarMutexGuard aGuard; + ThrowIfInvalid(); + return SwXStyleFamilies::CreateStyleCharOrParaOrPseudo(SfxStyleFamily::Para, GetDocOrThrow()); +} + rtl::Reference< SwXPageStyle > SwXTextDocument::createPageStyle() { SolarMutexGuard aGuard; diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx index 6fb1b60c6d91..51bb40ddbc8c 100644 --- a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx +++ b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx @@ -53,6 +53,7 @@ #include <comphelper/diagnose_ex.hxx> #include <o3tl/sorted_vector.hxx> #include <unotxdoc.hxx> +#include <unoxstyle.hxx> #include <SwXTextDefaults.hxx> using namespace ::com::sun::star; @@ -1153,11 +1154,12 @@ void StyleSheetTable::ApplyStyleSheetsImpl(const FontTablePtr& rFontTable, std:: else { bInsert = true; - xStyle.set(m_pImpl->m_xTextDocument->createInstance( - bParaStyle ? - getPropertyName( PROP_SERVICE_PARA_STYLE ) : - (bListStyle ? OUString("com.sun.star.style.NumberingStyle") : getPropertyName( PROP_SERVICE_CHAR_STYLE ))), - uno::UNO_QUERY_THROW); + if (bParaStyle) + xStyle = m_pImpl->m_xTextDocument->createParagraphStyle(); + else if (bListStyle) + xStyle = m_pImpl->m_xTextDocument->createNumberingStyle(); + else + xStyle = m_pImpl->m_xTextDocument->createCharacterStyle(); // Numbering styles have to be inserted early, as e.g. the NumberingRules property is only available after insertion. if (bListStyle) @@ -1799,21 +1801,19 @@ OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProp throw uno::RuntimeException(); try { - uno::Reference< style::XStyle > xStyle( m_pImpl->m_xTextDocument->createInstance( - getPropertyName( PROP_SERVICE_CHAR_STYLE )), uno::UNO_QUERY_THROW); - uno::Reference< beans::XPropertySet > xStyleProps(xStyle, uno::UNO_QUERY_THROW ); + rtl::Reference< SwXStyle > xStyle = m_pImpl->m_xTextDocument->createCharacterStyle(); for( const auto& rCharProp : rCharProperties) { try { - xStyleProps->setPropertyValue( rCharProp.Name, rCharProp.Value ); + xStyle->setPropertyValue( rCharProp.Name, rCharProp.Value ); } catch( const uno::Exception& ) { TOOLS_WARN_EXCEPTION( "writerfilter", "StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue"); } } - xCharStyles->insertByName( sListLabel, uno::Any( xStyle) ); + xCharStyles->insertByName( sListLabel, uno::Any( uno::Reference<style::XStyle>(xStyle) ) ); m_pImpl->m_aListCharStylePropertyVector.emplace_back( sListLabel, std::vector(rCharProperties) ); } catch( const uno::Exception& )