From b5ae9467d8979efaecd9f136122fb03b522d1ff9 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sun, 29 Mar 2015 19:54:09 +0200 Subject: correct lifecycle handling for more objects Change-Id: I456019c298c73bc872b49b55b628af1e0233be73 --- sc/source/ui/inc/condformatuno.hxx | 15 +++++-- sc/source/ui/unoobj/condformatuno.cxx | 74 +++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/sc/source/ui/inc/condformatuno.hxx b/sc/source/ui/inc/condformatuno.hxx index 04acec2a0d56..6333775949a9 100644 --- a/sc/source/ui/inc/condformatuno.hxx +++ b/sc/source/ui/inc/condformatuno.hxx @@ -177,7 +177,8 @@ class ScConditionEntryObj : public cppu::WeakImplHelper2 xParent); + ScConditionEntryObj(rtl::Reference xParent, + const ScCondFormatEntry* pFormat); virtual ~ScConditionEntryObj(); static ScConditionEntryObj* getImplementation(uno::Reference xCondition); @@ -233,13 +234,14 @@ private: ScDocShell* mpDocShell; rtl::Reference mxParent; SfxItemPropertySet maPropSet; + const ScCondFormatEntry* mpFormat; }; class ScColorScaleFormatObj : public cppu::WeakImplHelper1 { public: - ScColorScaleFormatObj(rtl::Reference xParent); + ScColorScaleFormatObj(rtl::Reference xParent, const ScColorScaleFormat* pFormat); virtual ~ScColorScaleFormatObj(); static ScColorScaleFormatObj* getImplementation(uno::Reference xPropSet); @@ -291,12 +293,14 @@ private: ScDocShell* mpDocShell; rtl::Reference mxParent; SfxItemPropertySet maPropSet; + const ScColorScaleFormat* mpFormat; }; class ScDataBarFormatObj : public cppu::WeakImplHelper1 { public: - ScDataBarFormatObj(rtl::Reference xParent); + ScDataBarFormatObj(rtl::Reference xParent, + const ScDataBarFormat* pFormat); virtual ~ScDataBarFormatObj(); static ScDataBarFormatObj* getImplementation(uno::Reference xPropSet); @@ -348,12 +352,14 @@ private: ScDocShell* mpDocShell; rtl::Reference mxParent; SfxItemPropertySet maPropSet; + const ScDataBarFormat* mpFormat; }; class ScIconSetFormatObj : public cppu::WeakImplHelper1 { public: - ScIconSetFormatObj(rtl::Reference xParent); + ScIconSetFormatObj(rtl::Reference xParent, + const ScIconSetFormat* pFormat); virtual ~ScIconSetFormatObj(); static ScIconSetFormatObj* getImplementation(uno::Reference xPropSet); @@ -405,6 +411,7 @@ private: ScDocShell* mpDocShell; rtl::Reference mxParent; SfxItemPropertySet maPropSet; + const ScIconSetFormat* mpFormat; }; #endif diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx index aee40f72f240..1a5af16d68a7 100644 --- a/sc/source/ui/unoobj/condformatuno.cxx +++ b/sc/source/ui/unoobj/condformatuno.cxx @@ -303,16 +303,20 @@ uno::Reference createConditionEntry(const ScFormatEntry* pE switch (pEntry->GetType()) { case condformat::CONDITION: - return new ScConditionEntryObj(xParent); + return new ScConditionEntryObj(xParent, + static_cast(pEntry)); break; case condformat::COLORSCALE: - return new ScColorScaleFormatObj(xParent); + return new ScColorScaleFormatObj(xParent, + static_cast(pEntry)); break; case condformat::DATABAR: - return new ScDataBarFormatObj(xParent); + return new ScDataBarFormatObj(xParent, + static_cast(pEntry)); break; case condformat::ICONSET: - return new ScIconSetFormatObj(xParent); + return new ScIconSetFormatObj(xParent, + static_cast(pEntry)); break; case condformat::DATE: break; @@ -519,10 +523,26 @@ void SAL_CALL ScCondFormatObj::removeVetoableChangeListener( const OUString&, SAL_WARN("sc", "not implemented"); } -ScConditionEntryObj::ScConditionEntryObj(rtl::Reference xParent): +namespace { + +bool isObjectStillAlive(ScConditionalFormat* pFormat, const ScFormatEntry* pEntry) +{ + for(size_t i = 0, n= pFormat->size(); i < n; ++i) + { + if (pFormat->GetEntry(i) == pEntry) + return true; + } + return false; +} + +} + +ScConditionEntryObj::ScConditionEntryObj(rtl::Reference xParent, + const ScCondFormatEntry* pFormat): mpDocShell(xParent->getDocShell()), mxParent(xParent), - maPropSet(getConditionEntryrPropSet()) + maPropSet(getConditionEntryrPropSet()), + mpFormat(pFormat) { } @@ -532,7 +552,11 @@ ScConditionEntryObj::~ScConditionEntryObj() ScCondFormatEntry* ScConditionEntryObj::getCoreObject() { - return NULL; + ScConditionalFormat* pFormat = mxParent->getCoreObject(); + if (isObjectStillAlive(pFormat, mpFormat)) + return const_cast(mpFormat); + + throw lang::IllegalArgumentException(); } sal_Int32 ScConditionEntryObj::getType() @@ -697,10 +721,12 @@ void SAL_CALL ScConditionEntryObj::removeVetoableChangeListener( const OUString& SAL_WARN("sc", "not implemented"); } -ScColorScaleFormatObj::ScColorScaleFormatObj(rtl::Reference xParent): +ScColorScaleFormatObj::ScColorScaleFormatObj(rtl::Reference xParent, + const ScColorScaleFormat* pFormat): mpDocShell(xParent->getDocShell()), mxParent(xParent), - maPropSet(getColorScalePropSet()) + maPropSet(getColorScalePropSet()), + mpFormat(pFormat) { } @@ -710,7 +736,11 @@ ScColorScaleFormatObj::~ScColorScaleFormatObj() ScColorScaleFormat* ScColorScaleFormatObj::getCoreObject() { - return NULL; + ScConditionalFormat* pFormat = mxParent->getCoreObject(); + if (isObjectStillAlive(pFormat, mpFormat)) + return const_cast(mpFormat); + + throw lang::IllegalArgumentException(); } uno::Reference SAL_CALL ScColorScaleFormatObj::getPropertySetInfo() @@ -799,10 +829,12 @@ void SAL_CALL ScColorScaleFormatObj::removeVetoableChangeListener( const OUStrin SAL_WARN("sc", "not implemented"); } -ScDataBarFormatObj::ScDataBarFormatObj(rtl::Reference xParent): +ScDataBarFormatObj::ScDataBarFormatObj(rtl::Reference xParent, + const ScDataBarFormat* pFormat): mpDocShell(xParent->getDocShell()), mxParent(xParent), - maPropSet(getDataBarPropSet()) + maPropSet(getDataBarPropSet()), + mpFormat(pFormat) { } @@ -812,7 +844,11 @@ ScDataBarFormatObj::~ScDataBarFormatObj() ScDataBarFormat* ScDataBarFormatObj::getCoreObject() { - return NULL; + ScConditionalFormat* pFormat = mxParent->getCoreObject(); + if (isObjectStillAlive(pFormat, mpFormat)) + return const_cast(mpFormat); + + throw lang::IllegalArgumentException(); } uno::Reference SAL_CALL ScDataBarFormatObj::getPropertySetInfo() @@ -1028,10 +1064,12 @@ void SAL_CALL ScDataBarFormatObj::removeVetoableChangeListener( const OUString&, SAL_WARN("sc", "not implemented"); } -ScIconSetFormatObj::ScIconSetFormatObj(rtl::Reference xParent): +ScIconSetFormatObj::ScIconSetFormatObj(rtl::Reference xParent, + const ScIconSetFormat* pFormat): mpDocShell(xParent->getDocShell()), mxParent(xParent), - maPropSet(getIconSetPropSet()) + maPropSet(getIconSetPropSet()), + mpFormat(pFormat) { } @@ -1041,7 +1079,11 @@ ScIconSetFormatObj::~ScIconSetFormatObj() ScIconSetFormat* ScIconSetFormatObj::getCoreObject() { - return NULL; + ScConditionalFormat* pFormat = mxParent->getCoreObject(); + if (isObjectStillAlive(pFormat, mpFormat)) + return const_cast(mpFormat); + + throw lang::IllegalArgumentException(); } uno::Reference SAL_CALL ScIconSetFormatObj::getPropertySetInfo() -- cgit