From 7ff8519d5e6a0ff66eb673ee5f5038b4d14bbd29 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Mon, 30 Mar 2015 01:47:13 +0200 Subject: add color scale entries Change-Id: If88822765b5ec738f3204a4ef7c76c3d529e6be2 --- sc/inc/colorscale.hxx | 2 + sc/source/core/data/colorscale.cxx | 8 +++ sc/source/ui/inc/condformatuno.hxx | 32 +++++++++ sc/source/ui/unoobj/condformatuno.cxx | 121 ++++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+) diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx index 22cd36945cfe..f2aa47c1b66b 100644 --- a/sc/inc/colorscale.hxx +++ b/sc/inc/colorscale.hxx @@ -251,6 +251,8 @@ public: iterator end(); const_iterator end() const; + ScColorScaleEntry* GetEntry(size_t nPos); + size_t size() const; }; diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index bf6fc69de9a2..f80e3c9dd31e 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -504,6 +504,14 @@ ScColorScaleFormat::const_iterator ScColorScaleFormat::end() const return maColorScales.end(); } +ScColorScaleEntry* ScColorScaleFormat::GetEntry(size_t nPos) +{ + if (maColorScales.size() <= nPos) + return NULL; + + return &maColorScales[nPos]; +} + size_t ScColorScaleFormat::size() const { return maColorScales.size(); diff --git a/sc/source/ui/inc/condformatuno.hxx b/sc/source/ui/inc/condformatuno.hxx index 7088bd394c5c..7200a2a9577d 100644 --- a/sc/source/ui/inc/condformatuno.hxx +++ b/sc/source/ui/inc/condformatuno.hxx @@ -297,6 +297,38 @@ private: const ScColorScaleFormat* mpFormat; }; +class ScColorScaleEntryObj : public cppu::WeakImplHelper1 +{ +public: + ScColorScaleEntryObj(rtl::Reference xParent, size_t nPos); + + virtual ~ScColorScaleEntryObj(); + + virtual com::sun::star::util::Color SAL_CALL getColor() + throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + virtual void SAL_CALL setColor(com::sun::star::util::Color aColor) + throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + virtual sal_Int32 SAL_CALL getType() + throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + virtual void SAL_CALL setType(sal_Int32 nType) + throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + virtual OUString SAL_CALL getFormula() + throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + virtual void SAL_CALL setFormula(const OUString& rString) + throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + +private: + ScColorScaleEntry* getCoreObject(); + + rtl::Reference mxParent; + size_t mnPos; +}; + class ScDataBarFormatObj : public cppu::WeakImplHelper1 { public: diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx index c0c20f0a2256..e7295f950bfb 100644 --- a/sc/source/ui/unoobj/condformatuno.cxx +++ b/sc/source/ui/unoobj/condformatuno.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include namespace { @@ -121,6 +122,22 @@ const SfxItemPropertyMapEntry* getColorScalePropSet() return aColorScalePropertyMap_Impl; } +struct ColorScaleEntryTypeApiMap +{ + ScColorScaleEntryType eType; + sal_Int32 nApiType; +}; + +ColorScaleEntryTypeApiMap aColorScaleEntryTypeMap[] = +{ + { COLORSCALE_MIN, sheet::ColorScaleEntryType::COLORSCALE_MIN }, + { COLORSCALE_MAX, sheet::ColorScaleEntryType::COLORSCALE_MAX }, + { COLORSCALE_VALUE, sheet::ColorScaleEntryType::COLORSCALE_VALUE }, + { COLORSCALE_FORMULA, sheet::ColorScaleEntryType::COLORSCALE_FORMULA }, + { COLORSCALE_PERCENT, sheet::ColorScaleEntryType::COLORSCALE_PERCENT }, + { COLORSCALE_PERCENTILE, sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE } +}; + enum DataBarProperties { AxisPosition, @@ -823,6 +840,14 @@ uno::Any SAL_CALL ScColorScaleFormatObj::getPropertyValue( const OUString& aProp switch(pEntry->nWID) { case ColorScaleEntries: + { + uno::Sequence > aEntries(getCoreObject()->size()); + for (size_t i = 0; i < getCoreObject()->size(); ++i) + { + aEntries[i] = new ScColorScaleEntryObj(this, i); + } + aAny <<= aEntries; + } break; default: SAL_WARN("sc", "unknown property"); @@ -863,6 +888,102 @@ void SAL_CALL ScColorScaleFormatObj::removeVetoableChangeListener( const OUStrin SAL_WARN("sc", "not implemented"); } +ScColorScaleEntryObj::ScColorScaleEntryObj(rtl::Reference xParent, + size_t nPos): + mxParent(xParent), + mnPos(nPos) +{ +} + +ScColorScaleEntryObj::~ScColorScaleEntryObj() +{ +} + +ScColorScaleEntry* ScColorScaleEntryObj::getCoreObject() +{ + ScColorScaleFormat* pFormat = mxParent->getCoreObject(); + if (pFormat->size() <= mnPos) + throw lang::IllegalArgumentException(); + + return pFormat->GetEntry(mnPos); +} + +util::Color ScColorScaleEntryObj::getColor() + throw(uno::RuntimeException, std::exception) +{ + Color aColor = getCoreObject()->GetColor(); + return aColor.GetColor(); +} + +void ScColorScaleEntryObj::setColor(util::Color aColor) + throw(uno::RuntimeException, std::exception) +{ + getCoreObject()->SetColor(Color(aColor)); +} + +sal_Int32 ScColorScaleEntryObj::getType() + throw(uno::RuntimeException, std::exception) +{ + ScColorScaleEntry* pEntry = getCoreObject(); + for (size_t i = 0; i < SAL_N_ELEMENTS(aColorScaleEntryTypeMap); ++i) + { + if (aColorScaleEntryTypeMap[i].eType == pEntry->GetType()) + { + return aColorScaleEntryTypeMap[i].nApiType; + } + } + + throw lang::IllegalArgumentException(); +} + +void ScColorScaleEntryObj::setType(sal_Int32 nType) + throw(uno::RuntimeException, std::exception) +{ + ScColorScaleEntry* pEntry = getCoreObject(); + for (size_t i = 0; i < SAL_N_ELEMENTS(aColorScaleEntryTypeMap); ++i) + { + if (aColorScaleEntryTypeMap[i].nApiType == nType) + { + pEntry->SetType(aColorScaleEntryTypeMap[i].eType); + return; + } + } + throw lang::IllegalArgumentException(); +} + +OUString ScColorScaleEntryObj::getFormula() + throw(uno::RuntimeException, std::exception) +{ + ScColorScaleEntry* pEntry = getCoreObject(); + switch (pEntry->GetType()) + { + case COLORSCALE_FORMULA: + // TODO: Implement + break; + default: + return OUString::number(pEntry->GetValue()); + } + + return OUString(); +} + +void ScColorScaleEntryObj::setFormula(const OUString& rFormula) + throw(uno::RuntimeException, std::exception) +{ + ScColorScaleEntry* pEntry = getCoreObject(); + switch (pEntry->GetType()) + { + case COLORSCALE_FORMULA: + // TODO: Implement + // pEntry->SetFormula(rFormula); + break; + default: + pEntry->SetValue(rFormula.toDouble()); + break; + } +} + + ScDataBarFormatObj::ScDataBarFormatObj(rtl::Reference xParent, const ScDataBarFormat* pFormat): mpDocShell(xParent->getDocShell()), -- cgit