From fe7c777c142382f7214996e9e479e38cf6c7624e Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Mon, 30 Mar 2015 10:14:19 +0200 Subject: finally implement and define also date formatting Change-Id: I261e6d3199573fc2e37d940e4249a1fce105e6eb --- offapi/UnoApi_offapi.mk | 2 + offapi/com/sun/star/sheet/DateCondition.idl | 34 +++++ offapi/com/sun/star/sheet/DateType.idl | 49 +++++++ sc/source/ui/inc/condformatuno.hxx | 64 +++++++++ sc/source/ui/unoobj/condformatuno.cxx | 198 ++++++++++++++++++++++++++++ 5 files changed, 347 insertions(+) create mode 100644 offapi/com/sun/star/sheet/DateCondition.idl create mode 100644 offapi/com/sun/star/sheet/DateType.idl diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 1411c5425a1f..aca71492b9ea 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -1192,6 +1192,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_noheader,offapi,offapi/com/sun/star/sheet,\ DatabaseRange \ DatabaseRanges \ DatabaseRangesEnumeration \ + DateCondition \ DocumentSettings \ FormulaParser \ FunctionAccess \ @@ -3338,6 +3339,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,offapi/com/sun/star/sheet,\ ConditionOperator2 \ DataBarAxis \ DataBarEntryType \ + DateType \ DDEItemInfo \ DDELinkInfo \ DDELinkMode \ diff --git a/offapi/com/sun/star/sheet/DateCondition.idl b/offapi/com/sun/star/sheet/DateCondition.idl new file mode 100644 index 000000000000..0536b672c32b --- /dev/null +++ b/offapi/com/sun/star/sheet/DateCondition.idl @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef __com_sun_star_sheet_DateCondition_idl__ +#define __com_sun_star_sheet_DateCondition_idl__ + +#include + +module com { module sun { module star { module sheet { + +service DateCondition +{ + interface XConditionEntry; + + [property] string StyleName; + + /** + * See com.sun.star.sheet.DateType for possible values + */ + [property] long DateType; +}; + + +}; }; }; }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/offapi/com/sun/star/sheet/DateType.idl b/offapi/com/sun/star/sheet/DateType.idl new file mode 100644 index 000000000000..9aed4a6c1eda --- /dev/null +++ b/offapi/com/sun/star/sheet/DateType.idl @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef __com_sun_star_sheet_DateType_idl__ +#define __com_sun_star_sheet_DateType_idl__ + +module com { module sun { module star { module sheet { + +constants DateType +{ + const long TODAY = 0; + + const long YESTERDAY = 1; + + const long TOMORROW = 2; + + const long LAST7DAYS = 3; + + const long THISWEEK = 4; + + const long LASTWEEK = 5; + + const long NEXTWEEK = 6; + + const long THISMONTH = 7; + + const long LASTMONTH = 8; + + const long NEXTMONTH = 9; + + const long THISYEAR = 10; + + const long LASTYEAR = 11; + + const long NEXTYEAR = 12; +}; + + +}; }; }; }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/condformatuno.hxx b/sc/source/ui/inc/condformatuno.hxx index fd56c05a433f..bab142585da7 100644 --- a/sc/source/ui/inc/condformatuno.hxx +++ b/sc/source/ui/inc/condformatuno.hxx @@ -35,6 +35,7 @@ class ScDataBarFormat; class ScColorScaleFormat; class ScCondFormatEntry; class ScColorScaleEntry; +class ScCondDateFormatEntry; using namespace com::sun::star; @@ -515,6 +516,69 @@ private: size_t mnPos; }; +class ScCondDateFormatObj : public cppu::WeakImplHelper2 +{ +public: + ScCondDateFormatObj(rtl::Reference xParent, + const ScCondDateFormatEntry* pFormat); + + virtual ~ScCondDateFormatObj(); + + ScCondDateFormatEntry* getCoreObject(); + + // XConditionEntry + virtual sal_Int32 SAL_CALL getType() + throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > + SAL_CALL getPropertySetInfo() + throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, + const ::com::sun::star::uno::Any& aValue ) + throw(::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::beans::PropertyVetoException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( + const OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw(::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + +private: + ScDocShell* mpDocShell; + rtl::Reference mxParent; + SfxItemPropertySet maPropSet; + const ScCondDateFormatEntry* mpFormat; +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx index 26f34e3daee9..eb44beeedf62 100644 --- a/sc/source/ui/unoobj/condformatuno.cxx +++ b/sc/source/ui/unoobj/condformatuno.cxx @@ -31,6 +31,7 @@ #include #include #include +#include namespace { @@ -263,6 +264,45 @@ IconSetEntryTypeApiMap aIconSetEntryTypeMap[] = { COLORSCALE_PERCENTILE, sheet::IconSetFormatEntry::ICONSET_PERCENTILE } }; +enum DateProperties +{ + Date_StyleName, + DateType +}; + +const SfxItemPropertyMapEntry* getCondDatePropSet() +{ + static const SfxItemPropertyMapEntry aCondDatePropertyMap_Impl[] = + { + {OUString("StyleName"), StyleName, cppu::UnoType::get(), 0, 0}, + {OUString(), 0, css::uno::Type(), 0, 0} + }; + return aCondDatePropertyMap_Impl; +} + +struct DateTypeApiMap +{ + condformat::ScCondFormatDateType eType; + sal_Int32 nApiType; +}; + +DateTypeApiMap aDateTypeApiMap[] = +{ + { condformat::TODAY, sheet::DateType::TODAY }, + { condformat::YESTERDAY, sheet::DateType::YESTERDAY }, + { condformat::TOMORROW, sheet::DateType::TOMORROW }, + { condformat::LAST7DAYS, sheet::DateType::LAST7DAYS }, + { condformat::THISWEEK, sheet::DateType::THISWEEK }, + { condformat::LASTWEEK, sheet::DateType::LASTWEEK }, + { condformat::NEXTWEEK, sheet::DateType::NEXTWEEK }, + { condformat::THISMONTH, sheet::DateType::THISMONTH }, + { condformat::LASTMONTH, sheet::DateType::LASTMONTH }, + { condformat::NEXTMONTH, sheet::DateType::NEXTMONTH }, + { condformat::THISYEAR, sheet::DateType::THISYEAR }, + { condformat::LASTYEAR, sheet::DateType::LASTYEAR }, + { condformat::NEXTYEAR, sheet::DateType::NEXTYEAR } +}; + } ScCondFormatsObj::ScCondFormatsObj(ScDocShell* pDocShell, SCTAB nTab): @@ -371,6 +411,8 @@ uno::Reference createConditionEntry(const ScFormatEntry* pE static_cast(pEntry)); break; case condformat::DATE: + return new ScCondDateFormatObj(xParent, + static_cast(pEntry)); break; default: break; @@ -1743,4 +1785,160 @@ void ScIconSetEntryObj::setFormula(const OUString& rFormula) } } +ScCondDateFormatObj::ScCondDateFormatObj(rtl::Reference xParent, + const ScCondDateFormatEntry* pFormat): + mpDocShell(xParent->getDocShell()), + mxParent(xParent), + maPropSet(getCondDatePropSet()), + mpFormat(pFormat) +{ +} + +ScCondDateFormatObj::~ScCondDateFormatObj() +{ +} + +ScCondDateFormatEntry* ScCondDateFormatObj::getCoreObject() +{ + ScConditionalFormat* pFormat = mxParent->getCoreObject(); + if (isObjectStillAlive(pFormat, mpFormat)) + return const_cast(mpFormat); + + throw lang::IllegalArgumentException(); +} + +sal_Int32 ScCondDateFormatObj::getType() + throw(uno::RuntimeException, std::exception) +{ + return sheet::ConditionEntryType::DATE; +} + +uno::Reference SAL_CALL ScCondDateFormatObj::getPropertySetInfo() + throw(uno::RuntimeException, std::exception) +{ + SolarMutexGuard aGuard; + static uno::Reference aRef( + new SfxItemPropertySetInfo( maPropSet.getPropertyMap() )); + return aRef; +} + +void SAL_CALL ScCondDateFormatObj::setPropertyValue( + const OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException, std::exception) +{ + SolarMutexGuard aGuard; + + const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class + const SfxItemPropertySimpleEntry* pEntry = rPropertyMap.getByName( aPropertyName ); + if ( !pEntry ) + throw beans::UnknownPropertyException(); + + switch(pEntry->nWID) + { + case Date_StyleName: + { + OUString aStyleName; + if (aValue >>= aStyleName) + { + getCoreObject()->SetStyleName(aStyleName); + } + else + throw lang::IllegalArgumentException(); + } + break; + case DateType: + { + sal_Int32 nApiType = -1; + if (!(aValue >>= nApiType)) + throw lang::IllegalArgumentException(); + + for (size_t i = 0; i < SAL_N_ELEMENTS(aDateTypeApiMap); ++i) + { + if (aDateTypeApiMap[i].nApiType == nApiType) + { + getCoreObject()->SetDateType(aDateTypeApiMap[i].eType); + break; + } + } + } + break; + default: + break; + } +} + +uno::Any SAL_CALL ScCondDateFormatObj::getPropertyValue( const OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException, std::exception) +{ + SolarMutexGuard aGuard; + + const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class + const SfxItemPropertySimpleEntry* pEntry = rPropertyMap.getByName( aPropertyName ); + if ( !pEntry ) + throw beans::UnknownPropertyException(); + + uno::Any aAny; + + switch(pEntry->nWID) + { + case Date_StyleName: + { + OUString aStyleName = getCoreObject()->GetStyleName(); + aAny <<= aStyleName; + } + break; + case DateType: + { + condformat::ScCondFormatDateType eType = getCoreObject()->GetDateType(); + for (size_t i = 0; i < SAL_N_ELEMENTS(aDateTypeApiMap); ++i) + { + if (aDateTypeApiMap[i].eType == eType) + { + aAny <<= aDateTypeApiMap[i].nApiType; + break; + } + } + } + break; + default: + SAL_WARN("sc", "unknown property"); + } + return aAny; +} + +void SAL_CALL ScCondDateFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */, + const uno::Reference& /* aListener */) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException, std::exception) +{ + SAL_WARN("sc", "not implemented"); +} + +void SAL_CALL ScCondDateFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */, + const uno::Reference& /* aListener */) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException, std::exception) +{ + SAL_WARN("sc", "not implemented"); +} + +void SAL_CALL ScCondDateFormatObj::addVetoableChangeListener( const OUString&, + const uno::Reference&) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException, std::exception) +{ + SAL_WARN("sc", "not implemented"); +} + +void SAL_CALL ScCondDateFormatObj::removeVetoableChangeListener( const OUString&, + const uno::Reference&) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException, std::exception) +{ + SAL_WARN("sc", "not implemented"); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit