sw/inc/tblafmt.hxx | 15 +++++++++------ sw/source/core/doc/tblafmt.cxx | 6 ++++++ sw/source/core/unocore/unostyle.cxx | 33 ++++++++++++++------------------- 3 files changed, 29 insertions(+), 25 deletions(-)
New commits: commit 6f6a31d3e3b2ff113d5cc3a1ea960059cf09ceae Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Tue Apr 18 21:20:12 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Apr 19 08:07:08 2023 +0200 use more concrete UNO type in SwBoxAutoFormat rather than hiding the relationship behind XInterface Change-Id: Ie5e6e527d39ab2b4a26ae7830a196b354d2a6f04 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150586 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx index 2f6c8f788f11..d007130f1fa8 100644 --- a/sw/inc/tblafmt.hxx +++ b/sw/inc/tblafmt.hxx @@ -34,6 +34,8 @@ #include <editeng/frmdiritem.hxx> #include <editeng/shaditem.hxx> #include <svx/autoformathelper.hxx> +#include <unotools/weakref.hxx> +#include <rtl/ref.hxx> #include "fmtornt.hxx" #include "swdllapi.h" @@ -41,8 +43,9 @@ struct SwAfVersions; class SvNumberFormatter; class SwTable; +class SwXTextCellStyle; -class SwBoxAutoFormat : public AutoFormatBase +class SW_DLLPUBLIC SwBoxAutoFormat : public AutoFormatBase { private: // Writer specific @@ -54,7 +57,8 @@ private: LanguageType m_eSysLanguage; LanguageType m_eNumFormatLanguage; - css::uno::WeakReference<css::uno::XInterface> m_wXObject; + // associated UNO object, if such exists + unotools::WeakReference<SwXTextCellStyle> m_xAutoFormatUnoObject; public: SwBoxAutoFormat(); @@ -89,10 +93,9 @@ public: void SetSysLanguage(const LanguageType& rNew) { m_eSysLanguage = rNew; } void SetNumFormatLanguage(const LanguageType& rNew) { m_eNumFormatLanguage = rNew; } - css::uno::WeakReference<css::uno::XInterface> const& GetXObject() const - { return m_wXObject; } - void SetXObject(css::uno::Reference<css::uno::XInterface> const& xObject) - { m_wXObject = xObject; } + unotools::WeakReference<SwXTextCellStyle> const& GetXObject() const + { return m_xAutoFormatUnoObject; } + void SetXObject(rtl::Reference<SwXTextCellStyle> const& xObject); bool Load( SvStream& rStream, const SwAfVersions& rVersions, sal_uInt16 nVer ); bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const; diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx index d90760532a44..858441f87b6c 100644 --- a/sw/source/core/doc/tblafmt.cxx +++ b/sw/source/core/doc/tblafmt.cxx @@ -62,6 +62,7 @@ #include <svx/algitem.hxx> #include <svx/rotmodit.hxx> #include <legacyitem.hxx> +#include <unostyle.hxx> #include <memory> #include <utility> @@ -361,6 +362,11 @@ bool SwBoxAutoFormat::Save( SvStream& rStream, sal_uInt16 fileVersion ) const return ERRCODE_NONE == rStream.GetError(); } +void SwBoxAutoFormat::SetXObject(rtl::Reference<SwXTextCellStyle> const& xObject) +{ + m_xAutoFormatUnoObject = xObject.get(); +} + SwTableAutoFormat::SwTableAutoFormat( OUString aName ) : m_aName( std::move(aName) ) , m_nStrResId( USHRT_MAX ) diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 81f74230b6de..d6272e3a5f59 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -4314,7 +4314,7 @@ void SwXTextTableStyle::UpdateCellStylesMapping() for (sal_Int32 i=0; i<STYLE_COUNT; ++i) { SwBoxAutoFormat* pBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]); - uno::Reference<style::XStyle> xCellStyle(pBoxFormat->GetXObject(), uno::UNO_QUERY); + rtl::Reference<SwXTextCellStyle> xCellStyle(pBoxFormat->GetXObject()); if (!xCellStyle.is()) { xCellStyle.set(new SwXTextCellStyle(m_pDocShell, pBoxFormat, m_pTableAutoFormat->GetName())); @@ -4383,12 +4383,11 @@ void SwXTextTableStyle::SetPhysical() for (size_t i=0; i<aTableTemplateMap.size(); ++i) { SwBoxAutoFormat* pOldBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]); - uno::Reference<style::XStyle> xCellStyle(pOldBoxFormat->GetXObject(), uno::UNO_QUERY); + rtl::Reference<SwXTextCellStyle> xCellStyle(pOldBoxFormat->GetXObject()); if (!xCellStyle.is()) continue; - SwXTextCellStyle& rStyle = dynamic_cast<SwXTextCellStyle&>(*xCellStyle); SwBoxAutoFormat& rNewBoxFormat = pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]); - rStyle.SetBoxFormat(&rNewBoxFormat); + xCellStyle->SetBoxFormat(&rNewBoxFormat); rNewBoxFormat.SetXObject(xCellStyle); } m_pTableAutoFormat_Impl = nullptr; @@ -4549,30 +4548,26 @@ void SAL_CALL SwXTextTableStyle::replaceByName(const OUString& rName, const uno: throw container::NoSuchElementException(); const sal_Int32 nCellStyle = iter->second; - uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>(); - if (!xStyle.is()) + rtl::Reference<SwXTextCellStyle> xStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(rElement.get<uno::Reference<style::XStyle>>().get()); + if (!xStyleToReplaceWith.is()) throw lang::IllegalArgumentException(); - SwXTextCellStyle* pStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(xStyle.get()); - if (!pStyleToReplaceWith) - throw lang::IllegalArgumentException(); - // replace only with physical ... - if (!pStyleToReplaceWith->IsPhysical()) + if (!xStyleToReplaceWith->IsPhysical()) throw lang::IllegalArgumentException(); const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap(); const sal_Int32 nBoxFormat = rTableTemplateMap[nCellStyle]; // move SwBoxAutoFormat to dest. SwTableAutoFormat - m_pTableAutoFormat->SetBoxFormat(*pStyleToReplaceWith->GetBoxFormat(), nBoxFormat); + m_pTableAutoFormat->SetBoxFormat(*xStyleToReplaceWith->GetBoxFormat(), nBoxFormat); // remove unassigned SwBoxAutoFormat, which is not anymore in use anyways - m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(xStyle->getName()); + m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(xStyleToReplaceWith->getName()); // make SwXTextCellStyle use new, moved SwBoxAutoFormat - pStyleToReplaceWith->SetBoxFormat(&m_pTableAutoFormat->GetBoxFormat(nBoxFormat)); - m_pTableAutoFormat->GetBoxFormat(nBoxFormat).SetXObject(xStyle); + xStyleToReplaceWith->SetBoxFormat(&m_pTableAutoFormat->GetBoxFormat(nBoxFormat)); + m_pTableAutoFormat->GetBoxFormat(nBoxFormat).SetXObject(xStyleToReplaceWith); // make this SwXTextTableStyle use new SwXTextCellStyle - m_aCellStyles[nCellStyle] = xStyle; + m_aCellStyles[nCellStyle] = xStyleToReplaceWith; } void SAL_CALL SwXTextTableStyle::removeByName(const OUString& /*Name*/) @@ -4647,7 +4642,7 @@ void SwXTextCellStyle::SetPhysical() m_bPhysical = true; m_pBoxAutoFormat_Impl = nullptr; m_pBoxAutoFormat = pBoxAutoFormat; - m_pBoxAutoFormat->SetXObject(uno::Reference<style::XStyle>(this)); + m_pBoxAutoFormat->SetXObject(this); } else SAL_WARN("sw.uno", "setting style physical, but SwBoxAutoFormat in document not found"); @@ -4703,7 +4698,7 @@ SwBoxAutoFormat* SwXTextCellStyle::GetBoxAutoFormat(SwDocShell* pDocShell, std:: css::uno::Reference<css::style::XStyle> SwXTextCellStyle::CreateXTextCellStyle(SwDocShell* pDocShell, const OUString& sName) { - uno::Reference<style::XStyle> xTextCellStyle; + rtl::Reference<SwXTextCellStyle> xTextCellStyle; if (!sName.isEmpty()) // create a cell style for a physical box { @@ -4718,7 +4713,7 @@ css::uno::Reference<css::style::XStyle> SwXTextCellStyle::CreateXTextCellStyle(S pBoxFormat = &aDefaultBoxFormat; } - xTextCellStyle.set(pBoxFormat->GetXObject(), uno::UNO_QUERY); + xTextCellStyle = pBoxFormat->GetXObject(); if (!xTextCellStyle.is()) { xTextCellStyle.set(new SwXTextCellStyle(pDocShell, pBoxFormat, sParentName));