diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-11-17 23:25:28 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-11-18 08:31:58 -0500 |
commit | 1acc10db8c6fd413567ced4feb2543ac8f150eb0 (patch) | |
tree | 87256f9f3ff755324a4b101e67b55ebf86256541 /sc/source/core/data | |
parent | 087b6041794a6a04c2e957ebf9a03fd223fa0fb3 (diff) |
Register group area listeners as needed when inserting/deleting cells.
Change-Id: I583ace5d134d526d660d4ff0bbf4a16aa10cbe5a
Diffstat (limited to 'sc/source/core/data')
-rw-r--r-- | sc/source/core/data/column3.cxx | 35 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 40 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 4 |
3 files changed, 48 insertions, 31 deletions
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 67c51be7e39e..bba48f2e029c 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 f23da4a4c361..fb6e2403c9ab 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 8855d655f0e1..f1d2d50ca5b0 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( |