diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2015-03-29 19:54:09 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2015-03-30 04:34:23 +0200 |
commit | e21e3b26646e9642d3e72269c44cbe3b781f9782 (patch) | |
tree | 1fe1afb748d8ca16c15bc56749d0774764bc0c15 /sc | |
parent | 97054f533f8c7153545a1c08dae12ca92f069122 (diff) |
correct lifecycle handling for more objects
Change-Id: I456019c298c73bc872b49b55b628af1e0233be73
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/condformatuno.hxx | 15 | ||||
-rw-r--r-- | 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 a7140e74e05c..497285f417e8 100644 --- a/sc/source/ui/inc/condformatuno.hxx +++ b/sc/source/ui/inc/condformatuno.hxx @@ -177,7 +177,8 @@ class ScConditionEntryObj : public cppu::WeakImplHelper2<com::sun::star::beans:: { public: - ScConditionEntryObj(rtl::Reference<ScCondFormatObj> xParent); + ScConditionEntryObj(rtl::Reference<ScCondFormatObj> xParent, + const ScCondFormatEntry* pFormat); virtual ~ScConditionEntryObj(); static ScConditionEntryObj* getImplementation(uno::Reference<sheet::XConditionEntry> xCondition); @@ -233,13 +234,14 @@ private: ScDocShell* mpDocShell; rtl::Reference<ScCondFormatObj> mxParent; SfxItemPropertySet maPropSet; + const ScCondFormatEntry* mpFormat; }; class ScColorScaleFormatObj : public cppu::WeakImplHelper1<com::sun::star::beans::XPropertySet> { public: - ScColorScaleFormatObj(rtl::Reference<ScCondFormatObj> xParent); + ScColorScaleFormatObj(rtl::Reference<ScCondFormatObj> xParent, const ScColorScaleFormat* pFormat); virtual ~ScColorScaleFormatObj(); static ScColorScaleFormatObj* getImplementation(uno::Reference<beans::XPropertySet> xPropSet); @@ -291,12 +293,14 @@ private: ScDocShell* mpDocShell; rtl::Reference<ScCondFormatObj> mxParent; SfxItemPropertySet maPropSet; + const ScColorScaleFormat* mpFormat; }; class ScDataBarFormatObj : public cppu::WeakImplHelper1<com::sun::star::beans::XPropertySet> { public: - ScDataBarFormatObj(rtl::Reference<ScCondFormatObj> xParent); + ScDataBarFormatObj(rtl::Reference<ScCondFormatObj> xParent, + const ScDataBarFormat* pFormat); virtual ~ScDataBarFormatObj(); static ScDataBarFormatObj* getImplementation(uno::Reference<beans::XPropertySet> xPropSet); @@ -348,12 +352,14 @@ private: ScDocShell* mpDocShell; rtl::Reference<ScCondFormatObj> mxParent; SfxItemPropertySet maPropSet; + const ScDataBarFormat* mpFormat; }; class ScIconSetFormatObj : public cppu::WeakImplHelper1<com::sun::star::beans::XPropertySet> { public: - ScIconSetFormatObj(rtl::Reference<ScCondFormatObj> xParent); + ScIconSetFormatObj(rtl::Reference<ScCondFormatObj> xParent, + const ScIconSetFormat* pFormat); virtual ~ScIconSetFormatObj(); static ScIconSetFormatObj* getImplementation(uno::Reference<beans::XPropertySet> xPropSet); @@ -405,6 +411,7 @@ private: ScDocShell* mpDocShell; rtl::Reference<ScCondFormatObj> 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<beans::XPropertySet> createConditionEntry(const ScFormatEntry* pE switch (pEntry->GetType()) { case condformat::CONDITION: - return new ScConditionEntryObj(xParent); + return new ScConditionEntryObj(xParent, + static_cast<const ScCondFormatEntry*>(pEntry)); break; case condformat::COLORSCALE: - return new ScColorScaleFormatObj(xParent); + return new ScColorScaleFormatObj(xParent, + static_cast<const ScColorScaleFormat*>(pEntry)); break; case condformat::DATABAR: - return new ScDataBarFormatObj(xParent); + return new ScDataBarFormatObj(xParent, + static_cast<const ScDataBarFormat*>(pEntry)); break; case condformat::ICONSET: - return new ScIconSetFormatObj(xParent); + return new ScIconSetFormatObj(xParent, + static_cast<const ScIconSetFormat*>(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<ScCondFormatObj> 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<ScCondFormatObj> 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<ScCondFormatEntry*>(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<ScCondFormatObj> xParent): +ScColorScaleFormatObj::ScColorScaleFormatObj(rtl::Reference<ScCondFormatObj> 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<ScColorScaleFormat*>(mpFormat); + + throw lang::IllegalArgumentException(); } uno::Reference<beans::XPropertySetInfo> SAL_CALL ScColorScaleFormatObj::getPropertySetInfo() @@ -799,10 +829,12 @@ void SAL_CALL ScColorScaleFormatObj::removeVetoableChangeListener( const OUStrin SAL_WARN("sc", "not implemented"); } -ScDataBarFormatObj::ScDataBarFormatObj(rtl::Reference<ScCondFormatObj> xParent): +ScDataBarFormatObj::ScDataBarFormatObj(rtl::Reference<ScCondFormatObj> 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<ScDataBarFormat*>(mpFormat); + + throw lang::IllegalArgumentException(); } uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDataBarFormatObj::getPropertySetInfo() @@ -1028,10 +1064,12 @@ void SAL_CALL ScDataBarFormatObj::removeVetoableChangeListener( const OUString&, SAL_WARN("sc", "not implemented"); } -ScIconSetFormatObj::ScIconSetFormatObj(rtl::Reference<ScCondFormatObj> xParent): +ScIconSetFormatObj::ScIconSetFormatObj(rtl::Reference<ScCondFormatObj> 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<ScIconSetFormat*>(mpFormat); + + throw lang::IllegalArgumentException(); } uno::Reference<beans::XPropertySetInfo> SAL_CALL ScIconSetFormatObj::getPropertySetInfo() |