diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2023-03-17 14:51:25 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2023-03-22 10:16:03 +0000 |
commit | debf3e06bc5330b227dc9dd55e49930cb3da522a (patch) | |
tree | fc6a21ecf8c80c77ef84822885cb982f9d3bb311 | |
parent | a49019618be881520a454550454c3f2d078d17fa (diff) |
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 <momonasmon@gmail.com>
-rw-r--r-- | sc/inc/styleuno.hxx | 2 | ||||
-rw-r--r-- | sc/inc/unonames.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/unoobj/shapeuno.cxx | 33 |
3 files changed, 35 insertions, 1 deletions
diff --git a/sc/inc/styleuno.hxx b/sc/inc/styleuno.hxx index d19feed3563a..07bf2cb7b12d 100644 --- a/sc/inc/styleuno.hxx +++ b/sc/inc/styleuno.hxx @@ -170,7 +170,6 @@ private: OUString aStyleName; SfxStyleSheetBase* pStyle_cached; - SfxStyleSheetBase* GetStyle_Impl( bool bUseCachedValue = false ); const SfxItemSet* GetStyleItemSet_Impl( std::u16string_view rPropName, const SfxItemPropertyMapEntry*& rpEntry ); /// @throws css::beans::UnknownPropertyException /// @throws css::uno::RuntimeException @@ -198,6 +197,7 @@ public: bool IsInserted() const { return pDocShell != nullptr; } SfxStyleFamily GetFamily() const { return eFamily; } void InitDoc( ScDocShell* pNewDocSh, const OUString& rNewName ); + SfxStyleSheetBase* GetStyle_Impl( bool bUseCachedValue = false ); virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; diff --git a/sc/inc/unonames.hxx b/sc/inc/unonames.hxx index abb09c334c10..4617bcf46700 100644 --- a/sc/inc/unonames.hxx +++ b/sc/inc/unonames.hxx @@ -198,6 +198,7 @@ inline constexpr OUStringLiteral SC_UNONAME_HORIPOS = u"HoriOrientPosit inline constexpr OUStringLiteral SC_UNONAME_VERTPOS = u"VertOrientPosition"; inline constexpr OUStringLiteral SC_UNONAME_HYPERLINK = u"Hyperlink"; inline constexpr OUStringLiteral SC_UNONAME_MOVEPROTECT = u"MoveProtect"; +inline constexpr OUStringLiteral SC_UNONAME_STYLE = u"Style"; // other cell properties inline constexpr OUStringLiteral SC_UNONAME_CHCOLHDR = u"ChartColumnAsLabel"; 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 <cppuhelper/supportsservice.hxx> #include <comphelper/diagnose_ex.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/drawing/XShape.hpp> #include <com/sun/star/lang/NoSupportException.hpp> @@ -44,6 +45,7 @@ #include <drwlayer.hxx> #include <userdat.hxx> #include <unonames.hxx> +#include <styleuno.hxx> using namespace ::com::sun::star; @@ -59,6 +61,7 @@ static o3tl::span<const SfxItemPropertyMapEntry> lcl_GetShapeMap() { SC_UNONAME_MOVEPROTECT, 0, cppu::UnoType<sal_Bool>::get(), 0, 0 }, { SC_UNONAME_HYPERLINK, 0, cppu::UnoType<OUString>::get(), 0, 0 }, { SC_UNONAME_URL, 0, cppu::UnoType<OUString>::get(), 0, 0 }, + { SC_UNONAME_STYLE, 0, cppu::UnoType<style::XStyle>::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<style::XStyle> xStyle(aValue, uno::UNO_QUERY); + auto pStyleSheetObj = dynamic_cast<ScStyleObj*>(xStyle.get()); + if (!pStyleSheetObj) + throw lang::IllegalArgumentException(); + + auto pStyleSheet = pStyleSheetObj->GetStyle_Impl(); + auto pOldStyleSheet = pObj->GetStyleSheet(); + + if (pStyleSheet != pOldStyleSheet) + pObj->SetStyleSheet(static_cast<SfxStyleSheet*>(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<style::XStyle>(new ScStyleObj( + static_cast<ScDocShell*>(pDoc ? pDoc->GetDocumentShell() : nullptr), + SfxStyleFamily::Frame, pStyleSheet->GetName())); + } + } + } else { if(!pShapePropertySet) //performance consideration |