From debf3e06bc5330b227dc9dd55e49930cb3da522a Mon Sep 17 00:00:00 2001 From: Maxim Monastirsky Date: Fri, 17 Mar 2023 14:51:25 +0200 Subject: sc drawstyles: Add a style UNO property to shapes Change-Id: I5c8eb3c3e182d9efefc385020b97d768e615a20a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149278 Tested-by: Jenkins Reviewed-by: Maxim Monastirsky --- sc/source/ui/unoobj/shapeuno.cxx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'sc/source/ui/unoobj') diff --git a/sc/source/ui/unoobj/shapeuno.cxx b/sc/source/ui/unoobj/shapeuno.cxx index 2dfd6ca10701..67931eab9a83 100644 --- a/sc/source/ui/unoobj/shapeuno.cxx +++ b/sc/source/ui/unoobj/shapeuno.cxx @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include using namespace ::com::sun::star; @@ -59,6 +61,7 @@ static o3tl::span lcl_GetShapeMap() { SC_UNONAME_MOVEPROTECT, 0, cppu::UnoType::get(), 0, 0 }, { SC_UNONAME_HYPERLINK, 0, cppu::UnoType::get(), 0, 0 }, { SC_UNONAME_URL, 0, cppu::UnoType::get(), 0, 0 }, + { SC_UNONAME_STYLE, 0, cppu::UnoType::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, }; return aShapeMap_Impl; } @@ -649,6 +652,22 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& aPropertyName, const pObj->SetMoveProtect( aProt ); } } + else if ( aPropertyName == SC_UNONAME_STYLE ) + { + if (SdrObject* pObj = GetSdrObject()) + { + uno::Reference xStyle(aValue, uno::UNO_QUERY); + auto pStyleSheetObj = dynamic_cast(xStyle.get()); + if (!pStyleSheetObj) + throw lang::IllegalArgumentException(); + + auto pStyleSheet = pStyleSheetObj->GetStyle_Impl(); + auto pOldStyleSheet = pObj->GetStyleSheet(); + + if (pStyleSheet != pOldStyleSheet) + pObj->SetStyleSheet(static_cast(pStyleSheet), false); + } + } else { GetShapePropertySet(); @@ -843,6 +862,20 @@ uno::Any SAL_CALL ScShapeObj::getPropertyValue( const OUString& aPropertyName ) aProt = pObj->IsMoveProtect(); aAny <<= aProt; } + else if ( aPropertyName == SC_UNONAME_STYLE ) + { + if (SdrObject* pObj = GetSdrObject()) + { + if (auto pStyleSheet = pObj->GetStyleSheet()) + { + ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject())); + ScDocument* pDoc = rModel.GetDocument(); + aAny <<= uno::Reference(new ScStyleObj( + static_cast(pDoc ? pDoc->GetDocumentShell() : nullptr), + SfxStyleFamily::Frame, pStyleSheet->GetName())); + } + } + } else { if(!pShapePropertySet) //performance consideration -- cgit v1.2.3