sc/inc/colorscale.hxx              |    3 +++
 sc/inc/conditio.hxx                |    5 +++++
 sc/source/core/data/colorscale.cxx |   21 +++++++++++++++++++++
 sc/source/core/data/conditio.cxx   |   20 ++++++++++++++++++++
 sc/source/core/data/table2.cxx     |    3 +++
 sc/source/filter/html/htmlexp.cxx  |   23 ++++++++++++++++++++++-
 6 files changed, 74 insertions(+), 1 deletion(-)

New commits:
commit 3a8420ae420d475e4e8fbeecc6a8ac74b6bc5b33
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Thu May 11 16:29:55 2023 -0400
Commit:     Aron Budea <aron.bu...@collabora.com>
CommitDate: Wed May 24 19:26:31 2023 +0200

    sc: filter: html: fix missing color scale conditional format
    
    When copying a range cell to an external application that request
    html data, the color scale conditional format does not have an
    associate a set attribute.
    
    Signed-off-by: Henry Castro <hcas...@collabora.com>
    Change-Id: I82b466a2100abc5070e92f844dc706d9b015c2e1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151687
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sc/source/filter/html/htmlexp.cxx 
b/sc/source/filter/html/htmlexp.cxx
index ef6392c02491..1446d5b8d23f 100644
--- a/sc/source/filter/html/htmlexp.cxx
+++ b/sc/source/filter/html/htmlexp.cxx
@@ -64,6 +64,8 @@
 #include <editutil.hxx>
 #include <ftools.hxx>
 #include <cellvalue.hxx>
+#include <conditio.hxx>
+#include <colorscale.hxx>
 #include <mtvelements.hxx>
 
 #include <editeng/flditem.hxx>
@@ -881,10 +883,27 @@ void ScHTMLExport::WriteTables()
 
 void ScHTMLExport::WriteCell( sc::ColumnBlockPosition& rBlockPos, SCCOL nCol, 
SCROW nRow, SCTAB nTab )
 {
+    std::optional<Color> aColorScale;
     ScAddress aPos( nCol, nRow, nTab );
     ScRefCellValue aCell(*pDoc, aPos, rBlockPos);
     const ScPatternAttr* pAttr = pDoc->GetPattern( nCol, nRow, nTab );
     const SfxItemSet* pCondItemSet = pDoc->GetCondResult( nCol, nRow, nTab, 
&aCell );
+    if (!pCondItemSet)
+    {
+        ScConditionalFormatList* pCondList = pDoc->GetCondFormList(nTab);
+        const ScCondFormatItem& rCondItem = pAttr->GetItem(ATTR_CONDITIONAL);
+        const ScCondFormatIndexes& rCondIndex = rCondItem.GetCondFormatData();
+        if (rCondIndex.size() > 0)
+        {
+            ScConditionalFormat* pCondFmt = 
pCondList->GetFormat(rCondIndex[0]);
+            if (pCondFmt)
+            {
+                const ScColorScaleFormat* pEntry = dynamic_cast<const 
ScColorScaleFormat*>(pCondFmt->GetEntry(0));
+                if (pEntry)
+                    aColorScale = pEntry->GetColor(aPos);
+            }
+        }
+    }
 
     const ScMergeFlagAttr& rMergeFlagAttr = pAttr->GetItem( ATTR_MERGE_FLAG, 
pCondItemSet );
     if ( rMergeFlagAttr.IsOverlapped() )
@@ -1023,7 +1042,9 @@ void ScHTMLExport::WriteCell( sc::ColumnBlockPosition& 
rBlockPos, SCCOL nCol, SC
             ATTR_BACKGROUND, pCondItemSet );
 
     Color aBgColor;
-    if ( rBrushItem.GetColor().GetAlpha() == 0 )
+    if ( aColorScale )
+        aBgColor = *aColorScale;
+    else if ( rBrushItem.GetColor().GetAlpha() == 0 )
         aBgColor = aHTMLStyle.aBackgroundColor; // No unwanted background color
     else
         aBgColor = rBrushItem.GetColor();
commit 8ac5e24a3575d140008a6b8d4c6414dc3ef1ef4b
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Thu May 11 16:23:03 2023 -0400
Commit:     Aron Budea <aron.bu...@collabora.com>
CommitDate: Wed May 24 19:26:18 2023 +0200

    sc: copy cache values when clone color conditional format
    
    When clone a conditional format list, also copy the cache
    values that hold the min and max values, otherwise if clone
    occurs when copying to the clipboard the values have wrong
    data due to limiting range cells copied.
    
    Signed-off-by: Henry Castro <hcas...@collabora.com>
    Change-Id: Id9085a1488a3bde24842e0d2e062c9b425074157
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151686
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 9923eac4c572..fc5c34dda287 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -224,6 +224,8 @@ public:
     virtual ~ScColorFormat() override;
 
     const ScRangeList& GetRange() const;
+    void SetCache(const std::vector<double>& aValues);
+    std::vector<double> GetCache() const;
 
     virtual void SetParent(ScConditionalFormat* pParent) override;
 
diff --git a/sc/source/core/data/colorscale.cxx 
b/sc/source/core/data/colorscale.cxx
index a8d94440f237..10f2b05aa092 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -377,6 +377,9 @@ ScColorScaleFormat::ScColorScaleFormat(ScDocument* pDoc, 
const ScColorScaleForma
     {
         maColorScales.emplace_back(new ScColorScaleEntry(pDoc, *rxEntry));
     }
+
+    auto aCache = rFormat.GetCache();
+    SetCache(aCache);
 }
 
 ScColorFormat* ScColorScaleFormat::Clone(ScDocument* pDoc) const
@@ -438,6 +441,18 @@ const ScRangeList& ScColorFormat::GetRange() const
     return mpParent->GetRange();
 }
 
+std::vector<double> ScColorFormat::GetCache() const
+{
+    std::vector<double> empty;
+    return mpCache ? mpCache->maValues : empty;
+}
+
+void ScColorFormat::SetCache(const std::vector<double>& aValues)
+{
+    mpCache.reset(new ScColorFormatCache);
+    mpCache->maValues = aValues;
+}
+
 std::vector<double>& ScColorFormat::getValues() const
 {
     if(!mpCache)
commit 1751877e646667793dd3593dff95665790100b69
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Thu May 11 16:07:10 2023 -0400
Commit:     Aron Budea <aron.bu...@collabora.com>
CommitDate: Wed May 24 19:26:04 2023 +0200

    sc: add "updateValues" method to conditional format list
    
    When copying a range cells to a clipboard, if exists a
    color scale conditional format from different ranges,
    it should update the min and max values, otherwise
    the color scale conditional format could not calculate
    min and max values due to limiting range cell copied.
    
    Signed-off-by: Henry Castro <hcas...@collabora.com>
    Change-Id: I660e18090a60b99ddf2b55ce1f713fd41121290e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151685
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index de74030dbc85..9923eac4c572 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -229,6 +229,7 @@ public:
 
     virtual void startRendering() override;
     virtual void endRendering() override;
+    virtual void updateValues() override;
 
 protected:
     std::vector<double>& getValues() const;
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index 5a131e5f6a10..08f188a7c5a9 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -252,6 +252,7 @@ public:
 
     virtual void startRendering();
     virtual void endRendering();
+    virtual void updateValues();
 protected:
     ScDocument* mpDoc;
 
@@ -599,6 +600,8 @@ public:
     void startRendering();
     void endRendering();
 
+    void updateValues();
+
     // Forced recalculation for formulas
     void CalcAll();
 };
@@ -684,6 +687,8 @@ public:
     void startRendering();
     void endRendering();
 
+    void updateValues();
+
     sal_uInt32 getMaxKey() const;
 
     /// Forced recalculation of formulas
diff --git a/sc/source/core/data/colorscale.cxx 
b/sc/source/core/data/colorscale.cxx
index 5cbf21cf8094..a8d94440f237 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -510,6 +510,12 @@ void ScColorFormat::endRendering()
     mpCache.reset();
 }
 
+void ScColorFormat::updateValues()
+{
+    getMinValue();
+    getMaxValue();
+}
+
 namespace {
 
 sal_uInt8 GetColorValue( double nVal, double nVal1, sal_uInt8 nColVal1, double 
nVal2, sal_uInt8 nColVal2 )
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index dc41b0ba28d3..864b3543a5c1 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -74,6 +74,10 @@ void ScFormatEntry::endRendering()
 {
 }
 
+void ScFormatEntry::updateValues()
+{
+}
+
 static bool lcl_HasRelRef( ScDocument* pDoc, const ScTokenArray* pFormula, 
sal_uInt16 nRecursion = 0 )
 {
     if (pFormula)
@@ -2041,6 +2045,14 @@ void ScConditionalFormat::endRendering()
     }
 }
 
+void ScConditionalFormat::updateValues()
+{
+    for(auto& rxEntry : maEntries)
+    {
+        rxEntry->updateValues();
+    }
+}
+
 void ScConditionalFormat::CalcAll()
 {
     for(const auto& rxEntry : maEntries)
@@ -2288,6 +2300,14 @@ void ScConditionalFormatList::endRendering()
     }
 }
 
+void ScConditionalFormatList::updateValues()
+{
+    for (auto const& it : m_ConditionalFormats)
+    {
+        it->updateValues();
+    }
+}
+
 void ScConditionalFormatList::clear()
 {
     m_ConditionalFormats.clear();
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index b56f07d52a0f..9646bc9b3c38 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -522,7 +522,10 @@ void ScTable::CopyToClip(
         for (SCCOL i = nCol1; i <= nCol2; i++)
             pTable->aCol[i].RemoveProtected(nRow1, nRow2);
 
+    mpCondFormatList->startRendering();
+    mpCondFormatList->updateValues();
     pTable->mpCondFormatList.reset(new 
ScConditionalFormatList(pTable->rDocument, *mpCondFormatList));
+    mpCondFormatList->endRendering();
 }
 
 void ScTable::CopyToClip(

Reply via email to