summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-07-30 11:02:31 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-07-30 11:04:49 -0400
commitb2ee0235e88dc4da715b5766295ed88f27974fbd (patch)
tree0c98f64a6064d33ccb8ff36ac43ef8feb95ae823 /sc/source
parentd0125712494ac0be512aa5e3fd7315e0cab2b323 (diff)
fdo#80501: Ensure that we notify each listener only once.
Change-Id: If2ce4643ff58c7c2ba326d749698dd5196a108dc
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/data/column.cxx27
-rw-r--r--sc/source/core/data/column4.cxx3
-rw-r--r--sc/source/core/data/documen7.cxx40
-rw-r--r--sc/source/core/data/table2.cxx7
-rw-r--r--sc/source/core/data/table7.cxx10
5 files changed, 51 insertions, 36 deletions
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index c32fb011b3fe..e2cfc745bd8a 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -3052,33 +3052,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 131f8cc2a984..3f26db17752c 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -950,6 +950,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 d973fc73c2a1..5a4df60f1abf 100644
--- a/sc/source/core/data/documen7.cxx
+++ b/sc/source/core/data/documen7.cxx
@@ -126,6 +126,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)
@@ -146,6 +162,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);
@@ -157,8 +195,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 ce14a5f9fcf8..657ab6fdeba3 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1704,13 +1704,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 6763565b62e7..407a8ba0d155 100644
--- a/sc/source/core/data/table7.cxx
+++ b/sc/source/core/data/table7.cxx
@@ -149,4 +149,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: */