add tests for tdf#117809

Change-Id: Ifbd48879a10acfbc6fdb0f2799321ff0684cdcc4
Reviewed-on: https://gerrit.libreoffice.org/57407
Tested-by: Jenkins
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 13328cc..45d536d 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -77,6 +77,7 @@ public:
    void SetType( ScColorScaleEntryType eType );

    void SetRepaintCallback(ScConditionalFormat* pParent);
    void SetRepaintCallback(std::function<void()> func);
};

namespace databar
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index a81a452..60cee22 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -522,6 +522,7 @@ public:
    void testCondFormatUndoList();
    void testMultipleSingleCellCondFormatCopyPaste();
    void testDeduplicateMultipleCondFormats();
    void testCondFormatListenToOwnRange();

    void testImportStream();
    void testDeleteContents();
diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx
index b2febe4..62b0ba9 100644
--- a/sc/qa/unit/ucalc_condformat.cxx
+++ b/sc/qa/unit/ucalc_condformat.cxx
@@ -1188,4 +1188,42 @@ void Test::testDeduplicateMultipleCondFormats()
    m_pDoc->DeleteTab(0);
}

void Test::testCondFormatListenToOwnRange()
{
    m_pDoc->InsertTab(0, "Test");

    ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0);

    ScConditionalFormat* pFormat = new ScConditionalFormat(1, m_pDoc);
    ScRangeList aRangeList(ScRange(0,0,0,10,0,0));
    pFormat->SetRange(aRangeList);

    ScIconSetFormat* pEntry = new ScIconSetFormat(m_pDoc);
    ScIconSetFormatData* pData = new ScIconSetFormatData;
    pData->m_Entries.push_back(o3tl::make_unique<ScColorScaleEntry>(0, COL_BLUE));
    pData->m_Entries.push_back(o3tl::make_unique<ScColorScaleEntry>(1, COL_GREEN));
    pData->m_Entries.push_back(o3tl::make_unique<ScColorScaleEntry>(2, COL_RED));
    pEntry->SetIconSetData(pData);
    pEntry->SetParent(pFormat);

    m_pDoc->AddCondFormatData(pFormat->GetRange(), 0, 1);
    pFormat->AddEntry(pEntry);
    pList->InsertNew(pFormat);

    bool bFirstCallbackCalled = false;
    bool bSecondCallbackCalled = false;
    bool bThirdCallbackCalled = false;
    std::function<void()> aFirstCallback = [&]() {bFirstCallbackCalled = true;};
    std::function<void()> aSecondCallback = [&]() {bSecondCallbackCalled = true;};
    std::function<void()> aThirdCallback = [&]() {bThirdCallbackCalled = true;};
    pData->m_Entries[0]->SetType(COLORSCALE_PERCENT);
    pData->m_Entries[0]->SetRepaintCallback(aFirstCallback);

    m_pDoc->SetValue(0, 0, 0, -1.0);

    CPPUNIT_ASSERT(bFirstCallbackCalled);

    m_pDoc->DeleteTab(0);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index e35083b..3617dcf 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -346,6 +346,11 @@ void ScColorScaleEntry::setListener()
    }
}

void ScColorScaleEntry::SetRepaintCallback(std::function<void()> func)
{
    mpListener->setCallback(func);
}

ScColorFormat::ScColorFormat(ScDocument* pDoc)
    : ScFormatEntry(pDoc)
    , mpParent(nullptr)