summaryrefslogtreecommitdiff
path: root/sc/source/core/data/colorscale.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/core/data/colorscale.cxx')
-rw-r--r--sc/source/core/data/colorscale.cxx72
1 files changed, 62 insertions, 10 deletions
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 4ea3606e48b8..e35083b639fe 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -36,6 +36,13 @@ ScFormulaListener::ScFormulaListener(ScDocument* pDoc):
{
}
+ScFormulaListener::ScFormulaListener(ScDocument* pDoc, const ScRangeList& rRange):
+ mbDirty(false),
+ mpDoc(pDoc)
+{
+ startListening(rRange);
+}
+
void ScFormulaListener::startListening(const ScTokenArray* pArr, const ScRange& rRange)
{
if (!pArr || mpDoc->IsClipOrUndo())
@@ -88,6 +95,19 @@ void ScFormulaListener::startListening(const ScTokenArray* pArr, const ScRange&
}
}
+void ScFormulaListener::startListening(const ScRangeList& rRange)
+{
+ if (mpDoc->IsClipOrUndo())
+ return;
+
+ size_t nLength = rRange.size();
+ for (size_t i = 0; i < nLength; ++i)
+ {
+ const ScRange& aRange = rRange[i];
+ mpDoc->StartListeningArea(aRange, false, this);
+ }
+}
+
void ScFormulaListener::addTokenArray(const ScTokenArray* pArray, const ScRange& rRange)
{
startListening(pArray, rRange);
@@ -150,6 +170,7 @@ ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry):
meType(rEntry.meType),
mpFormat(rEntry.mpFormat)
{
+ setListener();
if(rEntry.mpCell)
{
mpCell.reset(new ScFormulaCell(*rEntry.mpCell, *rEntry.mpCell->GetDocument(), rEntry.mpCell->aPos, ScCloneFlags::NoMakeAbsExternal));
@@ -165,6 +186,7 @@ ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry&
meType(rEntry.meType),
mpFormat(rEntry.mpFormat)
{
+ setListener();
if(rEntry.mpCell)
{
mpCell.reset(new ScFormulaCell(*rEntry.mpCell, *rEntry.mpCell->GetDocument(), rEntry.mpCell->aPos, ScCloneFlags::NoMakeAbsExternal));
@@ -229,12 +251,16 @@ void ScColorScaleEntry::SetValue(double nValue)
{
mnVal = nValue;
mpCell.reset();
+ setListener();
}
void ScColorScaleEntry::UpdateReference( const sc::RefUpdateContext& rCxt )
{
if (!mpCell)
+ {
+ setListener();
return;
+ }
mpCell->UpdateReference(rCxt);
mpListener.reset(new ScFormulaListener(mpCell.get()));
@@ -244,7 +270,10 @@ void ScColorScaleEntry::UpdateReference( const sc::RefUpdateContext& rCxt )
void ScColorScaleEntry::UpdateInsertTab( const sc::RefUpdateInsertTabContext& rCxt )
{
if (!mpCell)
+ {
+ setListener();
return;
+ }
mpCell->UpdateInsertTab(rCxt);
mpListener.reset(new ScFormulaListener(mpCell.get()));
@@ -254,7 +283,10 @@ void ScColorScaleEntry::UpdateInsertTab( const sc::RefUpdateInsertTabContext& rC
void ScColorScaleEntry::UpdateDeleteTab( const sc::RefUpdateDeleteTabContext& rCxt )
{
if (!mpCell)
+ {
+ setListener();
return;
+ }
mpCell->UpdateDeleteTab(rCxt);
mpListener.reset(new ScFormulaListener(mpCell.get()));
@@ -264,7 +296,10 @@ void ScColorScaleEntry::UpdateDeleteTab( const sc::RefUpdateDeleteTabContext& rC
void ScColorScaleEntry::UpdateMoveTab( const sc::RefUpdateMoveTabContext& rCxt )
{
if (!mpCell)
+ {
+ setListener();
return;
+ }
SCTAB nTabNo = rCxt.getNewTab(mpCell->aPos.Tab());
mpCell->UpdateMoveTab(rCxt, nTabNo);
@@ -280,10 +315,37 @@ void ScColorScaleEntry::SetColor(const Color& rColor)
void ScColorScaleEntry::SetRepaintCallback(ScConditionalFormat* pFormat)
{
mpFormat = pFormat;
+ setListener();
if (mpFormat && mpListener)
mpListener->setCallback([&]() { mpFormat->DoRepaint();});
}
+void ScColorScaleEntry::SetType( ScColorScaleEntryType eType )
+{
+ meType = eType;
+ if(eType != COLORSCALE_FORMULA)
+ {
+ mpCell.reset();
+ mpListener.reset();
+ }
+
+ setListener();
+}
+
+void ScColorScaleEntry::setListener()
+{
+ if (!mpFormat)
+ return;
+
+ if (meType == COLORSCALE_PERCENT || meType == COLORSCALE_PERCENTILE
+ || meType == COLORSCALE_MIN || meType == COLORSCALE_MAX
+ || meType == COLORSCALE_AUTO)
+ {
+ mpListener.reset(new ScFormulaListener(mpFormat->GetDocument(), mpFormat->GetRange()));
+ mpListener->setCallback([&]() { mpFormat->DoRepaint();});
+ }
+}
+
ScColorFormat::ScColorFormat(ScDocument* pDoc)
: ScFormatEntry(pDoc)
, mpParent(nullptr)
@@ -337,16 +399,6 @@ void ScColorScaleFormat::AddEntry( ScColorScaleEntry* pEntry )
maColorScales.back()->SetRepaintCallback(mpParent);
}
-void ScColorScaleEntry::SetType( ScColorScaleEntryType eType )
-{
- meType = eType;
- if(eType != COLORSCALE_FORMULA)
- {
- mpCell.reset();
- mpListener.reset();
- }
-}
-
double ScColorScaleFormat::GetMinValue() const
{
ScColorScaleEntries::const_iterator itr = maColorScales.begin();