[Libreoffice-commits] core.git: offapi/com offapi/UnoApi_offapi.mk sc/source

Markus Mohrhard markus.mohrhard at collabora.co.uk
Mon Mar 30 02:04:44 PDT 2015


 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(+)

New commits:
commit 6e6f822e2be39e2ceb146c6eeed10b965ae6e0b9
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Mon Mar 30 10:14:19 2015 +0200

    finally implement and define also date formatting
    
    Change-Id: I261e6d3199573fc2e37d940e4249a1fce105e6eb

diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index e1ba224..df73e01 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -1206,6 +1206,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_noheader,offapi,com/sun/star/sheet,\
 	DatabaseRange \
 	DatabaseRanges \
 	DatabaseRangesEnumeration \
+	DateCondition \
 	DocumentSettings \
 	FormulaParser \
 	FunctionAccess \
@@ -3369,6 +3370,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,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 0000000..0536b67
--- /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 <com/sun/star/sheet/XConditionEntry.idl>
+
+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 0000000..9aed4a6
--- /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 99e5dec..e801f58 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<com::sun::star::beans::XPropertySet,
+                                com::sun::star::sheet::XConditionEntry>
+{
+public:
+    ScCondDateFormatObj(rtl::Reference<ScCondFormatObj> 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<ScCondFormatObj> 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 4398b6b..676903f 100644
--- a/sc/source/ui/unoobj/condformatuno.cxx
+++ b/sc/source/ui/unoobj/condformatuno.cxx
@@ -31,6 +31,7 @@
 #include <com/sun/star/sheet/ColorScaleEntryType.hpp>
 #include <com/sun/star/sheet/IconSetFormatEntry.hpp>
 #include <com/sun/star/sheet/ConditionEntryType.hpp>
+#include <com/sun/star/sheet/DateType.hpp>
 
 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<OUString>::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<beans::XPropertySet> createConditionEntry(const ScFormatEntry* pE
                     static_cast<const ScIconSetFormat*>(pEntry));
         break;
         case condformat::DATE:
+            return new ScCondDateFormatObj(xParent,
+                    static_cast<const ScCondDateFormatEntry*>(pEntry));
         break;
         default:
         break;
@@ -1743,4 +1785,160 @@ void ScIconSetEntryObj::setFormula(const OUString& rFormula)
     }
 }
 
+ScCondDateFormatObj::ScCondDateFormatObj(rtl::Reference<ScCondFormatObj> 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<ScCondDateFormatEntry*>(mpFormat);
+
+    throw lang::IllegalArgumentException();
+}
+
+sal_Int32 ScCondDateFormatObj::getType()
+    throw(uno::RuntimeException, std::exception)
+{
+    return sheet::ConditionEntryType::DATE;
+}
+
+uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCondDateFormatObj::getPropertySetInfo()
+    throw(uno::RuntimeException, std::exception)
+{
+    SolarMutexGuard aGuard;
+    static uno::Reference<beans::XPropertySetInfo> 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<beans::XPropertyChangeListener>& /* 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<beans::XPropertyChangeListener>& /* 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<beans::XVetoableChangeListener>&)
+                            throw(beans::UnknownPropertyException,
+                                lang::WrappedTargetException, uno::RuntimeException, std::exception)
+{
+    SAL_WARN("sc", "not implemented");
+}
+
+void SAL_CALL ScCondDateFormatObj::removeVetoableChangeListener( const OUString&,
+                            const uno::Reference<beans::XVetoableChangeListener>&)
+                            throw(beans::UnknownPropertyException,
+                                lang::WrappedTargetException, uno::RuntimeException, std::exception)
+{
+    SAL_WARN("sc", "not implemented");
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list