diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-07-30 11:02:31 -0400 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2014-08-21 21:24:38 +0200 |
commit | 4119f3aef36bf1097638ed372f31bdfab281f63c (patch) | |
tree | 35e40677fff25606a4af95cece6ea1e69e5bc8c2 /sc | |
parent | 22a2efe047b790deee3dc9759c0355accd2bbc4f (diff) |
fdo#80501: Ensure that we notify each listener only once.
Change-Id: If2ce4643ff58c7c2ba326d749698dd5196a108dc
(cherry picked from commit b2ee0235e88dc4da715b5766295ed88f27974fbd)
Reviewed-on: https://gerrit.libreoffice.org/10647
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/column.hxx | 1 | ||||
-rw-r--r-- | sc/inc/table.hxx | 5 | ||||
-rw-r--r-- | sc/source/core/data/column.cxx | 27 | ||||
-rw-r--r-- | sc/source/core/data/column4.cxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/documen7.cxx | 40 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 7 | ||||
-rw-r--r-- | sc/source/core/data/table7.cxx | 10 |
7 files changed, 52 insertions, 41 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 89624227035b..66cd52442132 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -478,7 +478,6 @@ public: void StartNeededListeners(); // only for cells where NeedsListening()==true void SetDirtyIfPostponed(); void BroadcastRecalcOnRefMove(); - void BroadcastRefMoved( const sc::RefMovedHint& rHint ); void TransferListeners( ScColumn& rDestCol, SCROW nRow1, SCROW nRow2, SCROW nRowDelta ); void CollectListeners( std::vector<SvtListener*>& rListeners, SCROW nRow1, SCROW nRow2 ); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index ab354005cbc4..bd279267028a 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -927,10 +927,7 @@ public: */ void BroadcastRecalcOnRefMove(); - /** - * Broadcast all listeners of specified range that the range have moved. - */ - void BroadcastRefMoved( const sc::RefMovedHint& rHint ); + void CollectListeners( std::vector<SvtListener*>& rListeners, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ); void TransferListeners( ScTable& rDestTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 2d0a01872303..10da725f64a7 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -3119,33 +3119,6 @@ void ScColumn::BroadcastRecalcOnRefMove() namespace { -class BroadcastRefMovedHandler -{ - const sc::RefMovedHint& mrHint; -public: - BroadcastRefMovedHandler( const sc::RefMovedHint& rHint ) : mrHint(rHint) {} - - void operator() ( size_t, SvtBroadcaster* p ) - { - p->Broadcast(mrHint); - } -}; - -} - -void ScColumn::BroadcastRefMoved( const sc::RefMovedHint& rHint ) -{ - const ScRange& rRange = rHint.getRange(); - SCROW nRow1 = rRange.aStart.Row(); - SCROW nRow2 = rRange.aEnd.Row(); - - // Notify all listeners within specified rows. - BroadcastRefMovedHandler aFunc(rHint); - sc::ProcessBroadcaster(maBroadcasters.begin(), maBroadcasters, nRow1, nRow2, aFunc); -} - -namespace { - class TransferListenersHandler { public: diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index bf3b8178b475..d1aacddf4adb 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -533,6 +533,9 @@ public: void ScColumn::CollectListeners( std::vector<SvtListener*>& rListeners, SCROW nRow1, SCROW nRow2 ) { + if (nRow2 < nRow1 || !ValidRow(nRow1) || !ValidRow(nRow2)) + return; + ListenerCollector aFunc(rListeners); sc::ProcessBroadcaster(maBroadcasters.begin(), maBroadcasters, nRow1, nRow2, aFunc); } diff --git a/sc/source/core/data/documen7.cxx b/sc/source/core/data/documen7.cxx index 02a75fb2add2..a960c5a7011b 100644 --- a/sc/source/core/data/documen7.cxx +++ b/sc/source/core/data/documen7.cxx @@ -130,6 +130,22 @@ void ScDocument::BroadcastCells( const ScRange& rRange, sal_uLong nHint ) BroadcastUno(SfxSimpleHint(SC_HINT_DATACHANGED)); } +namespace { + +class RefMovedNotifier : std::unary_function<SvtListener*, void> +{ + const sc::RefMovedHint& mrHint; +public: + RefMovedNotifier( const sc::RefMovedHint& rHint ) : mrHint(rHint) {} + + void operator() ( SvtListener* p ) + { + p->Notify(mrHint); + } +}; + +} + void ScDocument::BroadcastRefMoved( const sc::RefMovedHint& rHint ) { if (!pBASM) @@ -150,6 +166,28 @@ void ScDocument::BroadcastRefMoved( const sc::RefMovedHint& rHint ) } } + // Collect all listeners listening into the range. + std::vector<SvtListener*> aListeners; + for (SCTAB nTab = rSrcRange.aStart.Tab(); nTab <= rSrcRange.aEnd.Tab(); ++nTab) + { + ScTable* pTab = FetchTable(nTab); + if (!pTab) + continue; + + pTab->CollectListeners( + aListeners, + rSrcRange.aStart.Col(), rSrcRange.aStart.Row(), + rSrcRange.aEnd.Col(), rSrcRange.aEnd.Row()); + } + + // Remove any duplicate listener entries. We must ensure that we notify + // each unique listener only once. + std::sort(aListeners.begin(), aListeners.end()); + aListeners.erase(std::unique(aListeners.begin(), aListeners.end()), aListeners.end()); + + // Notify the listeners. + std::for_each(aListeners.begin(), aListeners.end(), RefMovedNotifier(rHint)); + for (SCTAB nTab = rSrcRange.aStart.Tab(); nTab <= rSrcRange.aEnd.Tab(); ++nTab) { ScTable* pTab = FetchTable(nTab); @@ -161,8 +199,6 @@ void ScDocument::BroadcastRefMoved( const sc::RefMovedHint& rHint ) if (!pDestTab) continue; - // Adjust the references. - pTab->BroadcastRefMoved(rHint); // Move the listeners from the old location to the new. pTab->TransferListeners( *pDestTab, rSrcRange.aStart.Col(), rSrcRange.aStart.Row(), diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 5986a8ebe975..56a27687e6b1 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1739,13 +1739,6 @@ void ScTable::BroadcastRecalcOnRefMove() aCol[i].BroadcastRecalcOnRefMove(); } -void ScTable::BroadcastRefMoved( const sc::RefMovedHint& rHint ) -{ - const ScRange& rRange = rHint.getRange(); - for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol) - aCol[nCol].BroadcastRefMoved(rHint); -} - void ScTable::TransferListeners( ScTable& rDestTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCCOL nColDelta, SCROW nRowDelta ) diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx index 1ede729829dc..ff976a21d25e 100644 --- a/sc/source/core/data/table7.cxx +++ b/sc/source/core/data/table7.cxx @@ -110,4 +110,14 @@ void ScTable::RegroupFormulaCells( SCCOL nCol ) aCol[nCol].RegroupFormulaCells(); } +void ScTable::CollectListeners( + std::vector<SvtListener*>& rListeners, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) +{ + if (nCol2 < nCol1 || !ValidCol(nCol1) || !ValidCol(nCol2)) + return; + + for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol) + aCol[nCol].CollectListeners(rListeners, nRow1, nRow2); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |