summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-11-17 23:25:28 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-11-17 23:25:28 -0500
commit738b6fb605ef3176d525f0634a0165b823e86c76 (patch)
treeb6968357ccc168812df790e7c1a7024e53711c4d
parentUnused local variable. (diff)
downloadcore-738b6fb605ef3176d525f0634a0165b823e86c76.tar.gz
core-738b6fb605ef3176d525f0634a0165b823e86c76.zip
Register group area listeners as needed when inserting/deleting cells.
Change-Id: I583ace5d134d526d660d4ff0bbf4a16aa10cbe5a
-rw-r--r--sc/inc/column.hxx2
-rw-r--r--sc/inc/table.hxx2
-rw-r--r--sc/source/core/data/column3.cxx35
-rw-r--r--sc/source/core/data/document.cxx40
-rw-r--r--sc/source/core/data/table2.cxx4
5 files changed, 50 insertions, 33 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 5a0f70cf5b3f..780076388021 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -492,7 +492,7 @@ public:
void StartListening( sc::StartListeningContext& rCxt, SCROW nRow, SvtListener& rListener );
void EndListening( sc::EndListeningContext& rCxt, SCROW nRow, SvtListener& rListener );
void StartAllListeners();
- void StartNeededListeners(); // only for cells where NeedsListening()==true
+ void StartNeededListeners( sc::StartListeningContext& rCxt ); // only for cells where NeedsListening()==true
void SetDirtyIfPostponed();
void BroadcastRecalcOnRefMove();
void TransferListeners( ScColumn& rDestCol, SCROW nRow1, SCROW nRow2, SCROW nRowDelta );
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 7d802e3295e2..074b5d0812ec 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -916,7 +916,7 @@ public:
* Have formula cells with NeedsListening() == true start listening to the
* document.
*/
- void StartNeededListeners();
+ void StartNeededListeners( sc::StartListeningContext& rCxt );
/**
* Mark formula cells dirty that have the mbPostponedDirty flag set or
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index b2a115ff6031..353a97421879 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1506,16 +1506,34 @@ public:
}
};
-class StartNeededListenerHandler
+class StartNeededListenersHandler
{
- ScDocument* mpDoc;
+ sc::StartListeningContext* mpCxt;
public:
- StartNeededListenerHandler(ScDocument* pDoc) : mpDoc(pDoc) {}
+ StartNeededListenersHandler( sc::StartListeningContext& rCxt ) : mpCxt(&rCxt) {}
- void operator() (size_t, ScFormulaCell* p)
+ void operator() ( sc::CellStoreType::value_type& aBlk )
{
- if (p->NeedsListening())
- p->StartListeningTo(mpDoc);
+ if (aBlk.type != sc::element_type_formula)
+ return;
+
+ ScFormulaCell** pp = &sc::formula_block::at(*aBlk.data, 0);
+ ScFormulaCell** ppEnd = pp + aBlk.size;
+
+ for (; pp != ppEnd; ++pp)
+ {
+ ScFormulaCell& rFC = **pp;
+ if (!rFC.NeedsListening())
+ continue;
+
+ if (rFC.IsSharedTop())
+ {
+ sc::SharedFormulaUtil::startListeningAsGroup(*mpCxt, pp);
+ pp += rFC.GetSharedLength() - 1; // Move to the last cell in the group.
+ }
+ else
+ rFC.StartListeningTo(*mpCxt);
+ }
}
};
@@ -1527,10 +1545,9 @@ void ScColumn::StartAllListeners()
sc::ProcessFormula(maCells, aFunc);
}
-void ScColumn::StartNeededListeners()
+void ScColumn::StartNeededListeners( sc::StartListeningContext& rCxt )
{
- StartNeededListenerHandler aFunc(pDocument);
- sc::ProcessFormula(maCells, aFunc);
+ std::for_each(maCells.begin(), maCells.end(), StartNeededListenersHandler(rCxt));
}
namespace {
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index d6bb230d1a69..c5b409038ddc 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1164,12 +1164,16 @@ bool ScDocument::CanInsertRow( const ScRange& rRange ) const
namespace {
-struct StartNeededListenersHandler : std::unary_function<ScTable*, void>
+class StartNeededListenersHandler : std::unary_function<ScTable*, void>
{
+ boost::shared_ptr<sc::StartListeningContext> mpCxt;
+public:
+ StartNeededListenersHandler( ScDocument& rDoc ) : mpCxt(new sc::StartListeningContext(rDoc)) {}
+
void operator() (ScTable* p)
{
if (p)
- p->StartNeededListeners();
+ p->StartNeededListeners(*mpCxt);
}
};
@@ -1264,14 +1268,12 @@ bool ScDocument::InsertRow( SCCOL nStartCol, SCTAB nStartTab,
}
else
{ // Listeners have been removed in UpdateReference
- TableContainer::iterator it = maTabs.begin();
- for (; it != maTabs.end(); ++it)
- if (*it)
- (*it)->StartNeededListeners();
+ std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this));
+
// At least all cells using range names pointing relative to the
// moved range must be recalculated, and all cells marked postponed
// dirty.
- it = maTabs.begin();
+ TableContainer::iterator it = maTabs.begin();
for (; it != maTabs.end(); ++it)
if (*it)
(*it)->SetDirtyIfPostponed();
@@ -1357,14 +1359,13 @@ void ScDocument::DeleteRow( SCCOL nStartCol, SCTAB nStartTab,
maTabs[i]->DeleteRow(aCxt.maRegroupCols, nStartCol, nEndCol, nStartRow, nSize, pUndoOutline);
if ( ValidRow(nStartRow+nSize) )
- { // Listeners have been removed in UpdateReference
- TableContainer::iterator it = maTabs.begin();
- for (; it != maTabs.end(); ++it)
- if (*it)
- (*it)->StartNeededListeners();
+ {
+ // Listeners have been removed in UpdateReference
+ std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this));
+
// At least all cells using range names pointing relative to the moved
// range must be recalculated, and all cells marked postponed dirty.
- it = maTabs.begin();
+ TableContainer::iterator it = maTabs.begin();
for (; it != maTabs.end(); ++it)
if (*it)
(*it)->SetDirtyIfPostponed();
@@ -1466,7 +1467,7 @@ bool ScDocument::InsertCol( SCROW nStartRow, SCTAB nStartTab,
else
{
// Listeners have been removed in UpdateReference
- std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler());
+ std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this));
// At least all cells using range names pointing relative to the
// moved range must be recalculated, and all cells marked postponed
// dirty.
@@ -1553,14 +1554,13 @@ void ScDocument::DeleteCol(SCROW nStartRow, SCTAB nStartTab, SCROW nEndRow, SCTA
}
if ( ValidCol(sal::static_int_cast<SCCOL>(nStartCol+nSize)) )
- {// Listeners have been removed in UpdateReference
- TableContainer::iterator it = maTabs.begin();
- for (; it != maTabs.end(); ++it)
- if (*it)
- (*it)->StartNeededListeners();
+ {
+ // Listeners have been removed in UpdateReference
+ std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this));
+
// At least all cells using range names pointing relative to the moved
// range must be recalculated, and all cells marked postponed dirty.
- it = maTabs.begin();
+ TableContainer::iterator it = maTabs.begin();
for (; it != maTabs.end(); ++it)
if (*it)
(*it)->SetDirtyIfPostponed();
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 6a4647caa0a9..d3b7ec0d2f16 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1043,10 +1043,10 @@ void ScTable::DetachFormulaCells(
aCol[nCol].DetachFormulaCells(rCxt, nRow1, nRow2);
}
-void ScTable::StartNeededListeners()
+void ScTable::StartNeededListeners( sc::StartListeningContext& rCxt )
{
for (SCCOL i=0; i<=MAXCOL; i++)
- aCol[i].StartNeededListeners();
+ aCol[i].StartNeededListeners(rCxt);
}
void ScTable::SetDirtyFromClip(