[Libreoffice-commits] core.git: 4 commits - offapi/com sc/inc sc/source

Markus Mohrhard markus.mohrhard at googlemail.com
Fri Apr 3 08:45:20 PDT 2015


 offapi/com/sun/star/sheet/XConditionalFormat.idl  |   11 ++
 offapi/com/sun/star/sheet/XConditionalFormats.idl |    2 
 sc/inc/colorscale.hxx                             |   18 ++++
 sc/source/core/data/colorscale.cxx                |   85 +++++++++++++++-------
 sc/source/ui/inc/condformatuno.hxx                |   11 +-
 sc/source/ui/unoobj/condformatuno.cxx             |   80 +++++++++++++++++---
 6 files changed, 162 insertions(+), 45 deletions(-)

New commits:
commit 2ec69c6fea4594f3f00c22ac9bb31a888483b318
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Apr 3 16:51:36 2015 +0200

    document a few missing pieces
    
    Change-Id: I88a48ada4f9e261e425127bc1b0d3db83f1fabba

diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx
index 0acab07..74899e6 100644
--- a/sc/source/ui/unoobj/condformatuno.cxx
+++ b/sc/source/ui/unoobj/condformatuno.cxx
@@ -962,6 +962,10 @@ void SAL_CALL ScColorScaleFormatObj::setPropertyValue(
             uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries;
             if (aValue >>= aEntries)
             {
+                if (aEntries.getLength() < 2)
+                    throw lang::IllegalArgumentException();
+
+                // TODO: we need to make sure that there are enough entries
                 size_t n = size_t(aEntries.getLength());
                 for (size_t i = 0; i < n; ++i)
                 {
@@ -1663,6 +1667,7 @@ void SAL_CALL ScIconSetFormatObj::setPropertyValue(
                 throw lang::IllegalArgumentException();
             }
 
+            // TODO: we need to make sure that there are enough entries
             getCoreObject()->GetIconSetData()->eIconSetType = eType;
         }
         break;
@@ -1671,6 +1676,8 @@ void SAL_CALL ScIconSetFormatObj::setPropertyValue(
             uno::Sequence<uno::Reference<sheet::XIconSetEntry> > aEntries;
             if (aValue >>= aEntries)
             {
+                // TODO: we need to check that the number of entries
+                // corresponds to the icon type
                 sal_Int32 nLength = aEntries.getLength();
                 for (size_t i = 0; i < size_t(nLength); ++i)
                 {
commit 5b75b4e1ec77515db811be9d7895bb7bd9d23088
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Apr 3 16:44:51 2015 +0200

    first part for correct handling of new cond format entries
    
    Change-Id: I82f66218bf02898e523e4f69fec9166aa00d0b83

diff --git a/offapi/com/sun/star/sheet/XConditionalFormat.idl b/offapi/com/sun/star/sheet/XConditionalFormat.idl
index 62f9962..aed1fec 100644
--- a/offapi/com/sun/star/sheet/XConditionalFormat.idl
+++ b/offapi/com/sun/star/sheet/XConditionalFormat.idl
@@ -17,7 +17,16 @@ module com { module sun { module star { module sheet {
 
 interface XConditionalFormat : com::sun::star::container::XIndexAccess
 {
-    void addEntry( [in] com::sun::star::sheet::XConditionEntry entry );
+    /**
+     * Creates a new conditional format entry and insert its at the position.
+     *
+     * @param Type: a com.sun.star.sheet.ConditionFormatEntryType specifying the
+     *              type of the new entry
+     *
+     * @param Position: the position in the conditional format
+     *
+     */
+    void createEntry( [in] long Type, [in] long Position );
 
     void removeByIndex( [in] long Index );
 };
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 7409706..110a27a 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -284,6 +284,12 @@ public:
     ScColorScaleEntry* GetEntry(size_t nPos);
 
     size_t size() const;
+
+    /**
+     * Makes sure that the maColorScales contain at least 2 entries.
+     * Should be called when it is not sure that the format is valid.
+     */
+    void EnsureSize();
 };
 
 class SC_DLLPUBLIC ScDataBarFormat : public ScColorFormat
@@ -309,6 +315,12 @@ public:
 
     virtual condformat::ScFormatEntryType GetType() const SAL_OVERRIDE;
 
+    /**
+     * Makes sure that the mpFormatData does not contain valid entries.
+     * Should be called when it is not sure that the format is valid.
+     */
+    void EnsureSize();
+
 private:
     double getMin(double nMin, double nMax) const;
     double getMax(double nMin, double nMax) const;
@@ -370,6 +382,12 @@ public:
 
     size_t size() const;
 
+    /**
+     * Makes sure that the mpFormatData does not contain valid entries.
+     * Should be called when it is not sure that the format is valid.
+     */
+    void EnsureSize();
+
 private:
 
     double GetMinValue() const;
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 9f02077..ed1956f 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -684,6 +684,14 @@ size_t ScColorScaleFormat::size() const
     return maColorScales.size();
 }
 
+void ScColorScaleFormat::EnsureSize()
+{
+    if (maColorScales.size() < 2)
+    {
+        // TODO: create 2 valid entries
+    }
+}
+
 ScDataBarFormat::ScDataBarFormat(ScDocument* pDoc):
     ScColorFormat(pDoc)
 {
@@ -944,6 +952,18 @@ ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const
     return pInfo;
 }
 
+void ScDataBarFormat::EnsureSize()
+{
+    if (!mpFormatData->mpLowerLimit)
+    {
+        // TODO: implement
+    }
+    if (!mpFormatData->mpUpperLimit)
+    {
+        // TODO: implement
+    }
+}
+
 ScIconSetFormat::ScIconSetFormat(ScDocument* pDoc):
     ScColorFormat(pDoc),
     mpFormatData(new ScIconSetFormatData)
@@ -1156,32 +1176,35 @@ double ScIconSetFormat::CalcValue(double nMin, double nMax, ScIconSetFormat::con
     return itr->GetValue();
 }
 
-ScIconSetMap* ScIconSetFormat::getIconSetMap()
-{
+namespace {
+
+ScIconSetMap aIconSetMap[] = {
+    { "3Arrows", IconSet_3Arrows, 3 },
+    { "3ArrowsGray", IconSet_3ArrowsGray, 3 },
+    { "3Flags", IconSet_3Flags, 3 },
+    { "3TrafficLights1", IconSet_3TrafficLights1, 3 },
+    { "3TrafficLights2", IconSet_3TrafficLights2, 3 },
+    { "3Signs", IconSet_3Signs, 3 },
+    { "3Symbols", IconSet_3Symbols, 3 },
+    { "3Symbols2", IconSet_3Symbols2, 3 },
+    { "3Smilies", IconSet_3Smilies, 3 },
+    { "3ColorSmilies", IconSet_3ColorSmilies, 3 },
+    { "4Arrows", IconSet_4Arrows, 4 },
+    { "4ArrowsGray", IconSet_4ArrowsGray, 4 },
+    { "4RedToBlack", IconSet_4RedToBlack, 4 },
+    { "4Rating", IconSet_4Rating, 4 },
+    { "4TrafficLights", IconSet_4TrafficLights, 4 },
+    { "5Arrows", IconSet_5Arrows, 5 },
+    { "5ArrowsGray", IconSet_5ArrowsGray, 5 },
+    { "5Rating", IconSet_5Ratings, 5 },
+    { "5Quarters", IconSet_5Quarters, 5 },
+    { NULL, IconSet_3Arrows, 0 }
+};
 
-    static ScIconSetMap aIconSetMap[] = {
-        { "3Arrows", IconSet_3Arrows, 3 },
-        { "3ArrowsGray", IconSet_3ArrowsGray, 3 },
-        { "3Flags", IconSet_3Flags, 3 },
-        { "3TrafficLights1", IconSet_3TrafficLights1, 3 },
-        { "3TrafficLights2", IconSet_3TrafficLights2, 3 },
-        { "3Signs", IconSet_3Signs, 3 },
-        { "3Symbols", IconSet_3Symbols, 3 },
-        { "3Symbols2", IconSet_3Symbols2, 3 },
-        { "3Smilies", IconSet_3Smilies, 3 },
-        { "3ColorSmilies", IconSet_3ColorSmilies, 3 },
-        { "4Arrows", IconSet_4Arrows, 4 },
-        { "4ArrowsGray", IconSet_4ArrowsGray, 4 },
-        { "4RedToBlack", IconSet_4RedToBlack, 4 },
-        { "4Rating", IconSet_4Rating, 4 },
-        { "4TrafficLights", IconSet_4TrafficLights, 4 },
-        { "5Arrows", IconSet_5Arrows, 5 },
-        { "5ArrowsGray", IconSet_5ArrowsGray, 5 },
-        { "5Rating", IconSet_5Ratings, 5 },
-        { "5Quarters", IconSet_5Quarters, 5 },
-        { NULL, IconSet_3Arrows, 0 }
-    };
+}
 
+ScIconSetMap* ScIconSetFormat::getIconSetMap()
+{
     return aIconSetMap;
 }
 
@@ -1329,4 +1352,18 @@ BitmapEx& ScIconSetFormat::getBitmap( ScIconSetType eType, sal_Int32 nIndex )
     return itrNew.first->second;
 }
 
+void ScIconSetFormat::EnsureSize()
+{
+    ScIconSetType eType = mpFormatData->eIconSetType;
+    for (size_t i = 0; i < SAL_N_ELEMENTS(aIconSetMap); ++i)
+    {
+        if (aIconSetMap[i].eType == eType)
+        {
+            size_t nElements = aIconSetMap[i].nElements;
+            // TODO: implement
+            break;
+        }
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/condformatuno.hxx b/sc/source/ui/inc/condformatuno.hxx
index b5839e4..0e70a85 100644
--- a/sc/source/ui/inc/condformatuno.hxx
+++ b/sc/source/ui/inc/condformatuno.hxx
@@ -96,9 +96,8 @@ public:
     ScDocShell* getDocShell();
 
     // XConditionalFormat
-    virtual void SAL_CALL addEntry(const uno::Reference<sheet::XConditionEntry>& xEntry)
-                                throw(::com::sun::star::uno::RuntimeException,
-                                      std::exception) SAL_OVERRIDE;
+    virtual void SAL_CALL createEntry(const sal_Int32 nType, const sal_Int32 nPos)
+        throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
 
     virtual void SAL_CALL removeByIndex(const sal_Int32 nIndex)
                                 throw(::com::sun::star::uno::RuntimeException,
diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx
index 8efdc94..0acab07 100644
--- a/sc/source/ui/unoobj/condformatuno.cxx
+++ b/sc/source/ui/unoobj/condformatuno.cxx
@@ -470,9 +470,43 @@ ScDocShell* ScCondFormatObj::getDocShell()
     return mpDocShell;
 }
 
-void ScCondFormatObj::addEntry(const uno::Reference<sheet::XConditionEntry>& /*xEntry*/)
+void ScCondFormatObj::createEntry(const sal_Int32 nType, const sal_Int32 nPos)
     throw(uno::RuntimeException, std::exception)
 {
+    SolarMutexGuard aGuard;
+    ScConditionalFormat* pFormat = getCoreObject();
+    if (nPos > sal_Int32(pFormat->size()))
+        throw lang::IllegalArgumentException();
+
+    ScFormatEntry* pNewEntry = NULL;
+    ScDocument* pDoc = &mpDocShell->GetDocument();
+    switch (nType)
+    {
+        case sheet::ConditionEntryType::CONDITION:
+            pNewEntry = new ScCondFormatEntry(SC_COND_EQUAL, "", "",
+                    pDoc, pFormat->GetRange().GetTopLeftCorner(), "");
+        break;
+        case sheet::ConditionEntryType::COLORSCALE:
+            pNewEntry = new ScColorScaleFormat(pDoc);
+            static_cast<ScColorScaleFormat*>(pNewEntry)->EnsureSize();
+        break;
+        case sheet::ConditionEntryType::DATABAR:
+            pNewEntry = new ScDataBarFormat(pDoc);
+            static_cast<ScDataBarFormat*>(pNewEntry)->EnsureSize();
+        break;
+        case sheet::ConditionEntryType::ICONSET:
+            pNewEntry = new ScIconSetFormat(pDoc);
+            static_cast<ScIconSetFormat*>(pNewEntry)->EnsureSize();
+        break;
+        case sheet::ConditionEntryType::DATE:
+            pNewEntry = new ScCondDateFormatEntry(pDoc);
+        break;
+        default:
+            SAL_WARN("sc", "unknown conditional format type");
+            throw lang::IllegalArgumentException();
+    }
+
+    pFormat->AddEntry(pNewEntry);
 }
 
 void ScCondFormatObj::removeByIndex(const sal_Int32 nIndex)
commit eedf546acb878cb7c5856d33aad7496c1ad23269
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Apr 3 04:33:18 2015 +0200

    correct implementation
    
    Change-Id: Ie195e46e1cb14b39875efd1c9689db0f13968e87

diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx
index ce46c42..8efdc94 100644
--- a/sc/source/ui/unoobj/condformatuno.cxx
+++ b/sc/source/ui/unoobj/condformatuno.cxx
@@ -332,16 +332,35 @@ void ScCondFormatsObj::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
     }
 }
 
-sal_Int32 ScCondFormatsObj::createByRange(const uno::Reference< sheet::XSheetCellRanges >& /*xRanges*/)
+sal_Int32 ScCondFormatsObj::createByRange(const uno::Reference< sheet::XSheetCellRanges >& xRanges)
     throw(uno::RuntimeException, std::exception)
 {
     SolarMutexGuard aGuard;
-    /*
-    ScCondFormatObj* pFormatObj = ScCondFormatObj::getImplementation(xCondFormat);
-    ScConditionalFormat* pFormat = pFormatObj->getCoreObject();
-    mpFormatList->InsertNew(pFormat);
-    */
-    return 0;
+    if (!mpDocShell)
+        throw lang::IllegalArgumentException();
+
+    if (!xRanges.is())
+        throw lang::IllegalArgumentException();
+
+    uno::Sequence<table::CellRangeAddress> aRanges =
+        xRanges->getRangeAddresses();
+
+    ScRangeList aCoreRange;
+    for (sal_Int32 i = 0, n = aRanges.getLength(); i < n; ++i)
+    {
+        ScRange aRange;
+        ScUnoConversion::FillScRange(aRange, aRanges[i]);
+        aCoreRange.Join(aRange);
+    }
+
+    if (aCoreRange.empty())
+        throw lang::IllegalArgumentException();
+
+    SCTAB nTab = aCoreRange[0]->aStart.Tab();
+
+    ScConditionalFormat* pNewFormat = new ScConditionalFormat(0, &mpDocShell->GetDocument());
+    pNewFormat->SetRange(aCoreRange);
+    return mpDocShell->GetDocument().AddCondFormat(pNewFormat, nTab);
 }
 
 void ScCondFormatsObj::removeByID(const sal_Int32 nID)
commit be8e63cdded81446810dce46c98518b0a6b52711
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Apr 3 04:10:23 2015 +0200

    rename UNO API method for cond format
    
    My first idea does not work that well as it introduces some nasty
    problems with the lifecycle. THe new approach will only allow to use
    cond format objects of the same document.
    
    Change-Id: I276c3750ef24cdee6d63162c678ec839d4845b08

diff --git a/offapi/com/sun/star/sheet/XConditionalFormats.idl b/offapi/com/sun/star/sheet/XConditionalFormats.idl
index 6641d08..7230fe5 100644
--- a/offapi/com/sun/star/sheet/XConditionalFormats.idl
+++ b/offapi/com/sun/star/sheet/XConditionalFormats.idl
@@ -22,7 +22,7 @@ interface XConditionalFormats : com::sun::star::uno::XInterface
      * adds a conditional format to the existing list
      * returns the id of the inserted conditional format
      */
-    long addByRange( [in] com::sun::star::sheet::XConditionalFormat conditionalFormat, [in] com::sun::star::sheet::XSheetCellRanges range);
+    long createByRange( [in] com::sun::star::sheet::XSheetCellRanges range);
 
     void removeByID( [in] long ID);
 
diff --git a/sc/source/ui/inc/condformatuno.hxx b/sc/source/ui/inc/condformatuno.hxx
index 322c642..b5839e4 100644
--- a/sc/source/ui/inc/condformatuno.hxx
+++ b/sc/source/ui/inc/condformatuno.hxx
@@ -62,10 +62,8 @@ public:
     static ScCondFormatsObj* getImplementation( uno::Reference< com::sun::star::sheet::XConditionalFormats > xCondFormat );
 
     // XConditionalFormats
-    virtual sal_Int32 SAL_CALL addByRange( const uno::Reference< sheet::XConditionalFormat >& xCondFormat,
-            const uno::Reference<sheet::XSheetCellRanges>& xRanges)
-                                throw(::com::sun::star::uno::RuntimeException,
-                                      std::exception) SAL_OVERRIDE;
+    virtual sal_Int32 SAL_CALL createByRange(const uno::Reference<sheet::XSheetCellRanges>& xRanges)
+        throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
 
     virtual void SAL_CALL removeByID( const sal_Int32 nID )
                                 throw(::com::sun::star::uno::RuntimeException,
diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx
index 3d12b97..ce46c42 100644
--- a/sc/source/ui/unoobj/condformatuno.cxx
+++ b/sc/source/ui/unoobj/condformatuno.cxx
@@ -332,13 +332,9 @@ void ScCondFormatsObj::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
     }
 }
 
-sal_Int32 ScCondFormatsObj::addByRange(const uno::Reference< sheet::XConditionalFormat >& xCondFormat,
-        const uno::Reference< sheet::XSheetCellRanges >& /*xRanges*/)
+sal_Int32 ScCondFormatsObj::createByRange(const uno::Reference< sheet::XSheetCellRanges >& /*xRanges*/)
     throw(uno::RuntimeException, std::exception)
 {
-    if (!xCondFormat.is())
-        return 0;
-
     SolarMutexGuard aGuard;
     /*
     ScCondFormatObj* pFormatObj = ScCondFormatObj::getImplementation(xCondFormat);


More information about the Libreoffice-commits mailing list