[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/Library_sc.mk sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Wed Jul 17 13:11:29 PDT 2013


 sc/Library_sc.mk                         |    1 
 sc/inc/column.hxx                        |   22 ----
 sc/inc/document.hxx                      |    9 -
 sc/inc/formulacell.hxx                   |    5 
 sc/inc/refupdatecontext.hxx              |   50 +++++++++
 sc/inc/scopetools.hxx                    |    9 +
 sc/inc/table.hxx                         |    8 -
 sc/source/core/data/colorscale.cxx       |   17 ++-
 sc/source/core/data/column.cxx           |   81 +++++++--------
 sc/source/core/data/documen2.cxx         |   20 ++-
 sc/source/core/data/documen3.cxx         |  164 +++++++++++++++++--------------
 sc/source/core/data/document.cxx         |   52 ++++++---
 sc/source/core/data/formulacell.cxx      |   10 +
 sc/source/core/data/refupdatecontext.cxx |   25 ++++
 sc/source/core/data/table1.cxx           |   25 +++-
 sc/source/core/data/table2.cxx           |   12 +-
 sc/source/core/tool/chgtrack.cxx         |   29 +++--
 sc/source/core/tool/scopetools.cxx       |   11 ++
 18 files changed, 348 insertions(+), 202 deletions(-)

New commits:
commit afdefc84168ca8530fd4b0b3ce3ad921dd7afb52
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Jul 17 16:10:58 2013 -0400

    Use RefUpdateContext to stuff all parameters for UpdateReference.
    
    Because I was getting tired of typing all these parameters every time
    I branch off to a new function.
    
    Change-Id: I1ae14f290af5543150694d0bea27c617cccb9db2

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index c72a967..ce09ab8 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -163,6 +163,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/core/data/pivot2 \
 	sc/source/core/data/poolhelp \
 	sc/source/core/data/postit \
+	sc/source/core/data/refupdatecontext \
 	sc/source/core/data/segmenttree \
 	sc/source/core/data/sheetevents \
 	sc/source/core/data/simpleformulacalc \
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 5676568..00b2a63 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -47,6 +47,7 @@ namespace sc {
     class ColumnSpanSet;
     struct ColumnBlockPosition;
     class SingleColumnSpanSet;
+    struct RefUpdateContext;
 }
 
 class Fraction;
@@ -310,33 +311,16 @@ public:
 
     void        ResetChanged( SCROW nStartRow, SCROW nEndRow );
 
-    bool UpdateReferenceOnCopy(
-        const ScRange& rRange, SCCOL nDx, SCROW nDy, SCTAB nDz, ScDocument* pUndoDoc = NULL );
+    bool UpdateReferenceOnCopy( const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc = NULL );
 
     /**
      * Update reference addresses in formula cell in response to mass cell
      * movement.
      *
-     * @param eUpdateRefMode update mode - insert/delete, copy, or move. The
-     *                       reorder mode (which corresponds with the
-     *                       reordering of sheets) is not used with this
-     *                       method.
-     *
-     * @param rRange range of cells that are about to be moved for
-     *               insert/delete/move modes. For copy mode, it's the
-     *               destination range of cells that are about to be copied.
-     *
-     * @param nDx moved by how many cells in the column direction.
-     * @param nDy moved by how many cells in the row direction.
-     * @param nDz moved by how many sheets in the sheet direction.
-     * @param pUndoDoc undo document instance.
-     *
      * @return true if reference of at least one formula cell has been
      *         updated, false otherwise.
      */
-    bool UpdateReference(
-        UpdateRefMode eUpdateRefMode, const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
-        ScDocument* pUndoDoc = NULL );
+    bool UpdateReference( const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc = NULL );
 
     void UpdateInsertTab(SCTAB nInsPos, SCTAB nNewSheets = 1);
     void UpdateInsertTabOnlyCells(SCTAB nInsPos, SCTAB nNewSheets = 1);
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index d35cc49..d730a6f 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -55,6 +55,7 @@ namespace sc {
     class CopyFromClipContext;
     class ColumnSpanSet;
     struct ColumnBlockPosition;
+    struct RefUpdateContext;
 }
 class SvxFontItem;
 
@@ -1230,11 +1231,9 @@ public:
 
     SC_DLLPUBLIC void           CopyUpdated( ScDocument* pPosDoc, ScDocument* pDestDoc );
 
-    void            UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
-                                     SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
-                                     SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
-                                     ScDocument* pUndoDoc = NULL, bool bIncludeDraw = true,
-                                     bool bUpdateNoteCaptionPos = true );
+    void UpdateReference(
+        const sc::RefUpdateContext& rCxt,  ScDocument* pUndoDoc = NULL, bool bIncludeDraw = true,
+        bool bUpdateNoteCaptionPos = true );
 
     SC_DLLPUBLIC void           UpdateTranspose( const ScAddress& rDestPos, ScDocument* pClipDoc,
                                         const ScMarkData& rMark, ScDocument* pUndoDoc = NULL );
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 0c61371..7012eb1 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -32,6 +32,7 @@ namespace sc {
 
 class StartListeningContext;
 class EndListeningContext;
+struct RefUpdateContext;
 
 }
 
@@ -182,9 +183,7 @@ public:
     bool            HasColRowName() const;
 
     bool UpdateReference(
-        UpdateRefMode eUpdateRefMode, const ScRange& rRange,
-        SCsCOL nDx, SCsROW nDy, SCsTAB nDz, ScDocument* pUndoDoc = NULL,
-        const ScAddress* pUndoCellPos = NULL );
+        const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc = NULL, const ScAddress* pUndoCellPos = NULL );
 
     void            TransposeReference();
     void            UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
diff --git a/sc/inc/refupdatecontext.hxx b/sc/inc/refupdatecontext.hxx
new file mode 100644
index 0000000..80fdd74
--- /dev/null
+++ b/sc/inc/refupdatecontext.hxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef SC_REFUPDATECONTEXT_HXX
+#define SC_REFUPDATECONTEXT_HXX
+
+#include "global.hxx"
+#include "address.hxx"
+
+namespace sc {
+
+struct RefUpdateContext
+{
+    /**
+     * update mode - insert/delete, copy, or move. The reorder mode (which
+     * corresponds with the reordering of sheets) is not used with this
+     * context.
+     */
+    UpdateRefMode meMode;
+
+    /**
+     * Range of cells that are about to be moved for insert/delete/move modes.
+     * For copy mode, it's the destination range of cells that are about to be
+     * pasted.
+     */
+    ScRange maRange;
+
+    /** Amount and direction of movement in the column direction. */
+    SCCOL mnColDelta;
+    /** Amount and direction of movement in the row direction. */
+    SCROW mnRowDelta;
+    /** Amount and direction of movement in the sheet direction. */
+    SCTAB mnTabDelta;
+
+    RefUpdateContext();
+
+    bool hasDelta() const;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/scopetools.hxx b/sc/inc/scopetools.hxx
index 590ccbf..3544b79 100644
--- a/sc/inc/scopetools.hxx
+++ b/sc/inc/scopetools.hxx
@@ -26,6 +26,15 @@ public:
     ~AutoCalcSwitch();
 };
 
+class ExpandRefsSwitch
+{
+    ScDocument& mrDoc;
+    bool mbOldValue;
+public:
+    ExpandRefsSwitch(ScDocument& rDoc, bool bExpandRefs);
+    ~ExpandRefsSwitch();
+};
+
 }
 
 #endif
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index a8d5128..0e4305a 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -59,6 +59,7 @@ namespace sc {
     class MixDocContext;
     class ColumnSpanSet;
     struct ColumnBlockPosition;
+    struct RefUpdateContext;
 }
 
 class SfxItemSet;
@@ -500,10 +501,9 @@ public:
 
     bool CompileErrorCells(sal_uInt16 nErrCode);
 
-    void        UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
-                                    SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
-                                    SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
-                                    ScDocument* pUndoDoc = NULL, bool bIncludeDraw = true, bool bUpdateNoteCaptionPos = true );
+    void UpdateReference(
+        const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc = NULL,
+        bool bIncludeDraw = true, bool bUpdateNoteCaptionPos = true );
 
     void        UpdateDrawRef( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
                                     SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index a96711a..6169e52 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -14,6 +14,7 @@
 #include "iconsets.hrc"
 #include "scresid.hxx"
 #include "tokenarray.hxx"
+#include "refupdatecontext.hxx"
 
 #include "formula/token.hxx"
 
@@ -246,11 +247,17 @@ void ScColorScaleEntry::UpdateMoveTab( SCTAB nOldTab, SCTAB nNewTab, SCTAB nTabN
 void ScColorScaleEntry::UpdateReference( UpdateRefMode eUpdateRefMode,
             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
 {
-    if(mpCell)
-    {
-        mpCell->UpdateReference( eUpdateRefMode, rRange, nDx, nDy, nDz );
-        mpListener.reset(new ScFormulaListener(mpCell.get()));
-    }
+    if (!mpCell)
+        return;
+
+    sc::RefUpdateContext aCxt;
+    aCxt.meMode = eUpdateRefMode;
+    aCxt.maRange = rRange;
+    aCxt.mnColDelta = nDx;
+    aCxt.mnRowDelta = nDy;
+    aCxt.mnTabDelta = nDz;
+    mpCell->UpdateReference(aCxt);
+    mpListener.reset(new ScFormulaListener(mpCell.get()));
 }
 
 bool ScColorScaleEntry::NeedsRepaint() const
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index e9f4b80..ac1ede1 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -40,6 +40,7 @@
 #include "columnspanset.hxx"
 #include "scopetools.hxx"
 #include "sharedformula.hxx"
+#include "refupdatecontext.hxx"
 
 #include <svl/poolcach.hxx>
 #include <svl/zforlist.hxx>
@@ -1120,9 +1121,12 @@ namespace {
  */
 void updateRefInFormulaCell( ScFormulaCell& rCell, SCCOL nCol, SCTAB nTab, SCCOL nColDiff )
 {
-    ScRange aRange(ScAddress(nCol, 0, nTab), ScAddress(nCol, MAXROW, nTab));
     rCell.aPos.SetCol(nCol);
-    rCell.UpdateReference(URM_MOVE, aRange, nColDiff, 0, 0);
+    sc::RefUpdateContext aCxt;
+    aCxt.meMode = URM_MOVE;
+    aCxt.maRange = ScRange(ScAddress(nCol, 0, nTab), ScAddress(nCol, MAXROW, nTab));
+    aCxt.mnColDelta = nColDiff;
+    rCell.UpdateReference(aCxt);
 }
 
 }
@@ -2032,8 +2036,11 @@ void ScColumn::CopyScenarioFrom( const ScColumn& rSrcCol )
 
             //  UpdateUsed not needed, already done in TestCopyScenario (obsolete comment ?)
 
-            SCsTAB nDz = nTab - rSrcCol.nTab;
-            UpdateReferenceOnCopy(ScRange(nCol, nStart, nTab, nCol, nEnd, nTab), 0, 0, nDz, NULL);
+            sc::RefUpdateContext aRefCxt;
+            aRefCxt.meMode = URM_COPY;
+            aRefCxt.maRange = ScRange(nCol, nStart, nTab, nCol, nEnd, nTab);
+            aRefCxt.mnTabDelta = nTab - rSrcCol.nTab;
+            UpdateReferenceOnCopy(aRefCxt, NULL);
             UpdateCompile();
         }
 
@@ -2060,10 +2067,11 @@ void ScColumn::CopyScenarioTo( ScColumn& rDestCol ) const
 
             //  UpdateUsed not needed, is already done in TestCopyScenario (obsolete comment ?)
 
-            SCsTAB nDz = rDestCol.nTab - nTab;
-            rDestCol.UpdateReferenceOnCopy(
-                ScRange(rDestCol.nCol, nStart, rDestCol.nTab, rDestCol.nCol, nEnd, rDestCol.nTab),
-                0, 0, nDz, NULL);
+            sc::RefUpdateContext aRefCxt;
+            aRefCxt.meMode = URM_COPY;
+            aRefCxt.maRange = ScRange(rDestCol.nCol, nStart, rDestCol.nTab, rDestCol.nCol, nEnd, rDestCol.nTab);
+            aRefCxt.mnTabDelta = rDestCol.nTab - nTab;
+            rDestCol.UpdateReferenceOnCopy(aRefCxt, NULL);
             rDestCol.UpdateCompile();
         }
 
@@ -2239,17 +2247,13 @@ namespace {
 
 class UpdateRefOnCopy
 {
-protected:
-    ScRange maRange;
-    SCCOL mnDx;
-    SCROW mnDy;
-    SCTAB mnDz;
+    const sc::RefUpdateContext& mrCxt;
     ScDocument* mpUndoDoc;
     bool mbUpdated;
 
 public:
-    UpdateRefOnCopy(const ScRange& rRange, SCCOL nDx, SCROW nDy, SCTAB nDz, ScDocument* pUndoDoc) :
-        maRange(rRange), mnDx(nDx), mnDy(nDy), mnDz(nDz), mpUndoDoc(pUndoDoc), mbUpdated(false) {}
+    UpdateRefOnCopy(const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc) :
+        mrCxt(rCxt), mpUndoDoc(pUndoDoc), mbUpdated(false) {}
 
     bool isUpdated() const { return mbUpdated; }
 
@@ -2266,7 +2270,7 @@ public:
         for (; it != itEnd; ++it)
         {
             ScFormulaCell& rCell = **it;
-            mbUpdated |= rCell.UpdateReference(URM_COPY, maRange, mnDx, mnDy, mnDz, mpUndoDoc);
+            mbUpdated |= rCell.UpdateReference(mrCxt, mpUndoDoc);
         }
     }
 };
@@ -2275,26 +2279,21 @@ class UpdateRefOnNonCopy
 {
     SCCOL mnCol;
     SCROW mnTab;
-    ScRange maRange;
-    SCCOL mnDx;
-    SCROW mnDy;
-    SCTAB mnDz;
-    UpdateRefMode meMode;
+    const sc::RefUpdateContext& mrCxt;
     ScDocument* mpUndoDoc;
     bool mbUpdated;
 
 public:
     UpdateRefOnNonCopy(
-        SCCOL nCol, SCTAB nTab, const ScRange& rRange,
-        SCCOL nDx, SCROW nDy, SCTAB nDz, UpdateRefMode eMode,
+        SCCOL nCol, SCTAB nTab, const sc::RefUpdateContext& rCxt,
         ScDocument* pUndoDoc) :
-        mnCol(nCol), mnTab(nTab), maRange(rRange),
-        mnDx(nDx), mnDy(nDy), mnDz(nDz), meMode(eMode), mpUndoDoc(pUndoDoc), mbUpdated(false) {}
+        mnCol(nCol), mnTab(nTab), mrCxt(rCxt),
+        mpUndoDoc(pUndoDoc), mbUpdated(false) {}
 
     void operator() (size_t nRow, ScFormulaCell* pCell)
     {
         ScAddress aUndoPos(mnCol, nRow, mnTab);
-        mbUpdated |= pCell->UpdateReference(meMode, maRange, mnDx, mnDy, mnDz, mpUndoDoc, &aUndoPos);
+        mbUpdated |= pCell->UpdateReference(mrCxt, mpUndoDoc, &aUndoPos);
     }
 
     bool isUpdated() const { return mbUpdated; }
@@ -2302,47 +2301,45 @@ public:
 
 }
 
-bool ScColumn::UpdateReferenceOnCopy(
-    const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz, ScDocument* pUndoDoc )
+bool ScColumn::UpdateReferenceOnCopy( const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc )
 {
     // When copying, the range equals the destination range where cells
     // are pasted, and the dx, dy, dz refer to the distance from the
     // source range.
 
-    UpdateRefOnCopy aHandler(rRange, nDx, nDy, nDz, pUndoDoc);
-    sc::CellStoreType::position_type aPos = maCells.position(rRange.aStart.Row());
-    sc::ProcessBlock(aPos.first, maCells, aHandler, rRange.aStart.Row(), rRange.aEnd.Row());
+    UpdateRefOnCopy aHandler(rCxt, pUndoDoc);
+    sc::CellStoreType::position_type aPos = maCells.position(rCxt.maRange.aStart.Row());
+    sc::ProcessBlock(aPos.first, maCells, aHandler, rCxt.maRange.aStart.Row(), rCxt.maRange.aEnd.Row());
 
     // The formula groups at the top and bottom boundaries are expected to
     // have been split prior to this call. Here, we only do the joining.
     sc::SharedFormulaUtil::joinFormulaCellAbove(aPos);
-    if (rRange.aEnd.Row() < MAXROW)
+    if (rCxt.maRange.aEnd.Row() < MAXROW)
     {
-        aPos = maCells.position(aPos.first, rRange.aEnd.Row()+1);
+        aPos = maCells.position(aPos.first, rCxt.maRange.aEnd.Row()+1);
         sc::SharedFormulaUtil::joinFormulaCellAbove(aPos);
     }
 
     return aHandler.isUpdated();
 }
 
-bool ScColumn::UpdateReference(
-    UpdateRefMode eUpdateRefMode, const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
-    ScDocument* pUndoDoc )
+bool ScColumn::UpdateReference( const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc )
 {
-    if (eUpdateRefMode == URM_COPY)
-        return UpdateReferenceOnCopy(rRange, nDx, nDy, nDz, pUndoDoc);
+    if (rCxt.meMode == URM_COPY)
+        return UpdateReferenceOnCopy(rCxt, pUndoDoc);
 
-    bool bThisColShifted = (rRange.aStart.Tab() <= nTab && nTab <= rRange.aEnd.Tab() && rRange.aStart.Col() <= nCol && nCol <= rRange.aEnd.Col());
+    bool bThisColShifted = (rCxt.maRange.aStart.Tab() <= nTab && nTab <= rCxt.maRange.aEnd.Tab() &&
+                            rCxt.maRange.aStart.Col() <= nCol && nCol <= rCxt.maRange.aEnd.Col());
     if (bThisColShifted)
     {
         // Cells in this column is being shifted.  Split formula grouping at
         // the top and bottom boundaries before they get shifted.
-        SCROW nSplitPos = rRange.aStart.Row();
+        SCROW nSplitPos = rCxt.maRange.aStart.Row();
         if (ValidRow(nSplitPos))
         {
             sc::CellStoreType::position_type aPos = maCells.position(nSplitPos);
             sc::SharedFormulaUtil::splitFormulaCellGroup(aPos);
-            nSplitPos = rRange.aEnd.Row() + 1;
+            nSplitPos = rCxt.maRange.aEnd.Row() + 1;
             if (ValidRow(nSplitPos))
             {
                 aPos = maCells.position(aPos.first, nSplitPos);
@@ -2351,7 +2348,7 @@ bool ScColumn::UpdateReference(
         }
     }
 
-    UpdateRefOnNonCopy aHandler(nCol, nTab, rRange, nDx, nDy, nDz, eUpdateRefMode, pUndoDoc);
+    UpdateRefOnNonCopy aHandler(nCol, nTab, rCxt, pUndoDoc);
     sc::ProcessFormula(maCells, aHandler);
     return aHandler.isUpdated();
 }
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index b1b3160..dade7be 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -86,6 +86,7 @@
 #include "macromgr.hxx"
 #include "formulacell.hxx"
 #include "clipcontext.hxx"
+#include "refupdatecontext.hxx"
 
 using namespace com::sun::star;
 
@@ -841,14 +842,18 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
     if (bValid)
     {
         sc::CopyToDocContext aCxt(*this);
+
         SetNoListening( true );     // noch nicht bei CopyToTable/Insert
         maTabs[nOldPos]->CopyToTable(aCxt, 0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL),
                                         maTabs[nNewPos], pOnlyMarked );
         maTabs[nNewPos]->SetTabBgColor(maTabs[nOldPos]->GetTabBgColor());
 
-        SCsTAB nDz = (static_cast<SCsTAB>(nNewPos)) - static_cast<SCsTAB>(nOldPos);
-        maTabs[nNewPos]->UpdateReference(URM_COPY, 0, 0, nNewPos , MAXCOL, MAXROW,
-                                        nNewPos, 0, 0, nDz, NULL);
+        SCTAB nDz = nNewPos - nOldPos;
+        sc::RefUpdateContext aRefCxt;
+        aRefCxt.meMode = URM_COPY;
+        aRefCxt.maRange = ScRange(0, 0, nNewPos, MAXCOL, MAXROW, nNewPos);
+        aRefCxt.mnTabDelta = nDz;
+        maTabs[nNewPos]->UpdateReference(aRefCxt, NULL);
 
         maTabs[nNewPos]->UpdateInsertTabAbs(nNewPos); // alle abs. um eins hoch!!
         maTabs[nOldPos]->UpdateInsertTab(nNewPos);
@@ -963,11 +968,12 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
 
         if ( !bResultsOnly )
         {
+            sc::RefUpdateContext aRefCxt;
+            aRefCxt.meMode = URM_COPY;
+            aRefCxt.maRange = ScRange(0, 0, nDestPos, MAXCOL, MAXROW, nDestPos);
+            aRefCxt.mnTabDelta = nDestPos - nSrcPos;
+            maTabs[nDestPos]->UpdateReference(aRefCxt, NULL);
 
-            SCsTAB nDz = ((SCsTAB)nDestPos) - (SCsTAB)nSrcPos;
-            maTabs[nDestPos]->UpdateReference(URM_COPY, 0, 0, nDestPos,
-                                                     MAXCOL, MAXROW, nDestPos,
-                                                     0, 0, nDz, NULL);
             // Readjust self-contained absolute references to this sheet
             maTabs[nDestPos]->TestTabRefAbs(nSrcPos);
             maTabs[nDestPos]->CompileAll();
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index e10a43f..53769ef 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -69,9 +69,12 @@
 #include "colorscale.hxx"
 #include "queryentry.hxx"
 #include "formulacell.hxx"
+#include "refupdatecontext.hxx"
+#include "scopetools.hxx"
 
 #include "globalnames.hxx"
 #include <memory>
+#include <boost/scoped_ptr.hpp>
 
 using namespace com::sun::star;
 
@@ -971,86 +974,101 @@ sal_Int64 ScDocument::GetNewUnoId()
     return ++nUnoObjectId;
 }
 
-void ScDocument::UpdateReference( UpdateRefMode eUpdateRefMode,
-                                    SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
-                                    SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
-                                    SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
-                                    ScDocument* pUndoDoc, bool bIncludeDraw,
-                                    bool bUpdateNoteCaptionPos )
+void ScDocument::UpdateReference(
+    const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc, bool bIncludeDraw, bool bUpdateNoteCaptionPos )
 {
-    PutInOrder( nCol1, nCol2 );
-    PutInOrder( nRow1, nRow2 );
-    PutInOrder( nTab1, nTab2 );
-    if (ValidTab(nTab1) && ValidTab(nTab2))
+    if (!ValidRange(rCxt.maRange))
+        return;
+
+    boost::scoped_ptr<sc::ExpandRefsSwitch> pExpandRefsSwitch;
+    if (rCxt.meMode == URM_INSDEL && rCxt.hasDelta())
+        pExpandRefsSwitch.reset(new sc::ExpandRefsSwitch(*this, SC_MOD()->GetInputOptions().GetExpandRefs()));
+
+    size_t nFirstTab, nLastTab;
+    if (rCxt.meMode == URM_COPY)
     {
-        bool bExpandRefsOld = IsExpandRefs();
-        if ( eUpdateRefMode == URM_INSDEL && (nDx > 0 || nDy > 0 || nDz > 0) )
-            SetExpandRefs( SC_MOD()->GetInputOptions().GetExpandRefs() );
-        SCTAB i;
-        SCTAB iMax;
-        if ( eUpdateRefMode == URM_COPY )
-        {
-            i = nTab1;
-            iMax = nTab2;
-        }
-        else
-        {
-            ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
-            xColNameRanges->UpdateReference( eUpdateRefMode, this, aRange, nDx, nDy, nDz );
-            xRowNameRanges->UpdateReference( eUpdateRefMode, this, aRange, nDx, nDy, nDz );
-            pDBCollection->UpdateReference( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz );
-            if (pRangeName)
-                pRangeName->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz );
-            if ( pDPCollection )
-                pDPCollection->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz );
-            UpdateChartRef( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz );
-            UpdateRefAreaLinks( eUpdateRefMode, aRange, nDx, nDy, nDz );
-            if ( pValidationList )
-                pValidationList->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz );
-            if ( pDetOpList )
-                pDetOpList->UpdateReference( this, eUpdateRefMode, aRange, nDx, nDy, nDz );
-            if ( pUnoBroadcaster )
-                pUnoBroadcaster->Broadcast( ScUpdateRefHint(
-                                    eUpdateRefMode, aRange, nDx, nDy, nDz ) );
-            i = 0;
-            iMax = static_cast<SCTAB>(maTabs.size())-1;
-        }
-        for ( ; i<=iMax && i < static_cast<SCTAB>(maTabs.size()); i++)
-            if (maTabs[i])
-                maTabs[i]->UpdateReference(
-                    eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2,
-                    nDx, nDy, nDz, pUndoDoc, bIncludeDraw, bUpdateNoteCaptionPos );
+        nFirstTab = rCxt.maRange.aStart.Tab();
+        nLastTab = rCxt.maRange.aEnd.Tab();
+    }
+    else
+    {
+        // TODO: Have these methods use the context object directly.
+        ScRange aRange = rCxt.maRange;
+        UpdateRefMode eUpdateRefMode = rCxt.meMode;
+        SCCOL nDx = rCxt.mnColDelta;
+        SCROW nDy = rCxt.mnRowDelta;
+        SCTAB nDz = rCxt.mnTabDelta;
+        SCCOL nCol1 = rCxt.maRange.aStart.Col(), nCol2 = rCxt.maRange.aEnd.Col();
+        SCROW nRow1 = rCxt.maRange.aStart.Row(), nRow2 = rCxt.maRange.aEnd.Row();
+        SCTAB nTab1 = rCxt.maRange.aStart.Tab(), nTab2 = rCxt.maRange.aEnd.Tab();
+
+        xColNameRanges->UpdateReference( eUpdateRefMode, this, aRange, nDx, nDy, nDz );
+        xRowNameRanges->UpdateReference( eUpdateRefMode, this, aRange, nDx, nDy, nDz );
+        pDBCollection->UpdateReference( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz );
+        if (pRangeName)
+            pRangeName->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz );
+        if ( pDPCollection )
+            pDPCollection->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz );
+        UpdateChartRef( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz );
+        UpdateRefAreaLinks( eUpdateRefMode, aRange, nDx, nDy, nDz );
+        if ( pValidationList )
+            pValidationList->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz );
+        if ( pDetOpList )
+            pDetOpList->UpdateReference( this, eUpdateRefMode, aRange, nDx, nDy, nDz );
+        if ( pUnoBroadcaster )
+            pUnoBroadcaster->Broadcast( ScUpdateRefHint(
+                                eUpdateRefMode, aRange, nDx, nDy, nDz ) );
+
+        nFirstTab = 0;
+        nLastTab = maTabs.size()-1;
+    }
 
-        if ( bIsEmbedded )
-        {
-            SCCOL theCol1;
-            SCROW theRow1;
-            SCTAB theTab1;
-            SCCOL theCol2;
-            SCROW theRow2;
-            SCTAB theTab2;
-            theCol1 = aEmbedRange.aStart.Col();
-            theRow1 = aEmbedRange.aStart.Row();
-            theTab1 = aEmbedRange.aStart.Tab();
-            theCol2 = aEmbedRange.aEnd.Col();
-            theRow2 = aEmbedRange.aEnd.Row();
-            theTab2 = aEmbedRange.aEnd.Tab();
-            if ( ScRefUpdate::Update( this, eUpdateRefMode, nCol1,nRow1,nTab1, nCol2,nRow2,nTab2,
-                                        nDx,nDy,nDz, theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) )
-            {
-                aEmbedRange = ScRange( theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 );
-            }
-        }
-        SetExpandRefs( bExpandRefsOld );
+    for (size_t i = nFirstTab, n = maTabs.size() ; i <= nLastTab && i < n; ++i)
+    {
+        if (!maTabs[i])
+            continue;
+
+        maTabs[i]->UpdateReference(rCxt, pUndoDoc, bIncludeDraw, bUpdateNoteCaptionPos);
+    }
 
-        // after moving, no clipboard move ref-updates are possible
-        if ( eUpdateRefMode != URM_COPY && IsClipboardSource() )
+    if ( bIsEmbedded )
+    {
+        SCCOL theCol1;
+        SCROW theRow1;
+        SCTAB theTab1;
+        SCCOL theCol2;
+        SCROW theRow2;
+        SCTAB theTab2;
+        theCol1 = aEmbedRange.aStart.Col();
+        theRow1 = aEmbedRange.aStart.Row();
+        theTab1 = aEmbedRange.aStart.Tab();
+        theCol2 = aEmbedRange.aEnd.Col();
+        theRow2 = aEmbedRange.aEnd.Row();
+        theTab2 = aEmbedRange.aEnd.Tab();
+
+        // TODO: Have ScRefUpdate::Update() use the context object directly.
+        UpdateRefMode eUpdateRefMode = rCxt.meMode;
+        SCCOL nDx = rCxt.mnColDelta;
+        SCROW nDy = rCxt.mnRowDelta;
+        SCTAB nDz = rCxt.mnTabDelta;
+        SCCOL nCol1 = rCxt.maRange.aStart.Col(), nCol2 = rCxt.maRange.aEnd.Col();
+        SCROW nRow1 = rCxt.maRange.aStart.Row(), nRow2 = rCxt.maRange.aEnd.Row();
+        SCTAB nTab1 = rCxt.maRange.aStart.Tab(), nTab2 = rCxt.maRange.aEnd.Tab();
+
+        if ( ScRefUpdate::Update( this, eUpdateRefMode, nCol1,nRow1,nTab1, nCol2,nRow2,nTab2,
+                                    nDx,nDy,nDz, theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) )
         {
-            ScDocument* pClipDoc = SC_MOD()->GetClipDoc();
-            if (pClipDoc)
-                pClipDoc->GetClipParam().mbCutMode = false;
+            aEmbedRange = ScRange( theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 );
         }
     }
+
+    // after moving, no clipboard move ref-updates are possible
+    if (rCxt.meMode != URM_COPY && IsClipboardSource())
+    {
+        ScDocument* pClipDoc = SC_MOD()->GetClipDoc();
+        if (pClipDoc)
+            pClipDoc->GetClipParam().mbCutMode = false;
+    }
 }
 
 void ScDocument::UpdateTranspose( const ScAddress& rDestPos, ScDocument* pClipDoc,
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 5fa205c..aa23775 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -93,6 +93,7 @@
 #include "clipcontext.hxx"
 #include "listenercontext.hxx"
 #include "scopetools.hxx"
+#include "refupdatecontext.hxx"
 
 #include <map>
 #include <limits>
@@ -1162,11 +1163,14 @@ bool ScDocument::InsertRow( SCCOL nStartCol, SCTAB nStartTab,
         while ( lcl_GetNextTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ) );
 
         lcl_GetFirstTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) );
+
+        sc::RefUpdateContext aCxt;
+        aCxt.meMode = URM_INSDEL;
+        aCxt.maRange = ScRange(nStartCol, nStartRow, nTabRangeStart, nEndCol, MAXROW, nTabRangeEnd);
+        aCxt.mnRowDelta = nSize;
         do
         {
-            UpdateReference( URM_INSDEL, nStartCol, nStartRow, nTabRangeStart,
-                             nEndCol, MAXROW, nTabRangeEnd,
-                             0, static_cast<SCsROW>(nSize), 0, pRefUndoDoc, false );        // without drawing objects
+            UpdateReference(aCxt, pRefUndoDoc, false);        // without drawing objects
         }
         while ( lcl_GetNextTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ) );
 
@@ -1263,11 +1267,13 @@ void ScDocument::DeleteRow( SCCOL nStartCol, SCTAB nStartTab,
     if ( ValidRow(nStartRow+nSize) )
     {
         lcl_GetFirstTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) );
+        sc::RefUpdateContext aCxt;
+        aCxt.meMode = URM_INSDEL;
+        aCxt.maRange = ScRange(nStartCol, nStartRow+nSize, nTabRangeStart, nEndCol, MAXROW, nTabRangeEnd);
+        aCxt.mnRowDelta = -(static_cast<SCROW>(nSize));
         do
         {
-            UpdateReference( URM_INSDEL, nStartCol, nStartRow+nSize, nTabRangeStart,
-                             nEndCol, MAXROW, nTabRangeEnd,
-                             0, -(static_cast<SCsROW>(nSize)), 0, pRefUndoDoc, true, false );
+            UpdateReference(aCxt, pRefUndoDoc, true, false);
         }
         while ( lcl_GetNextTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ) );
     }
@@ -1366,11 +1372,14 @@ bool ScDocument::InsertCol( SCROW nStartRow, SCTAB nStartTab,
         while ( lcl_GetNextTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ) );
 
         lcl_GetFirstTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) );
+
+        sc::RefUpdateContext aCxt;
+        aCxt.meMode = URM_INSDEL;
+        aCxt.maRange = ScRange(nStartCol, nStartRow, nTabRangeStart, MAXCOL, nEndRow, nTabRangeEnd);
+        aCxt.mnColDelta = nSize;
         do
         {
-            UpdateReference( URM_INSDEL, nStartCol, nStartRow, nTabRangeStart,
-                             MAXCOL, nEndRow, nTabRangeEnd,
-                             static_cast<SCsCOL>(nSize), 0, 0, pRefUndoDoc, true, false );
+            UpdateReference(aCxt, pRefUndoDoc, true, false);
         }
         while ( lcl_GetNextTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ) );
 
@@ -1457,11 +1466,13 @@ void ScDocument::DeleteCol(SCROW nStartRow, SCTAB nStartTab, SCROW nEndRow, SCTA
     if ( ValidCol(sal::static_int_cast<SCCOL>(nStartCol+nSize)) )
     {
         lcl_GetFirstTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) );
+        sc::RefUpdateContext aCxt;
+        aCxt.meMode = URM_INSDEL;
+        aCxt.maRange = ScRange(sal::static_int_cast<SCCOL>(nStartCol+nSize), nStartRow, nTabRangeStart, MAXCOL, nEndRow, nTabRangeEnd);
+        aCxt.mnColDelta = -(static_cast<SCCOL>(nSize));
         do
         {
-            UpdateReference( URM_INSDEL, sal::static_int_cast<SCCOL>(nStartCol+nSize), nStartRow, nTabRangeStart,
-                             MAXCOL, nEndRow, nTabRangeEnd,
-                             -static_cast<SCsCOL>(nSize), 0, 0, pRefUndoDoc, true, false );
+            UpdateReference(aCxt, pRefUndoDoc, true, false);
         }
         while ( lcl_GetNextTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ) );
     }
@@ -2435,19 +2446,24 @@ void ScDocument::CopyBlockFromClip(
                         && rClipTabs[(nClipTab + nFollow + 1) % static_cast<SCTAB>(rClipTabs.size())] )
                     ++nFollow;
 
+                sc::RefUpdateContext aRefCxt;
+                aRefCxt.maRange = ScRange(nCol1, nRow1, i, nCol2, nRow2, i+nFollow);
+                aRefCxt.mnColDelta = nDx;
+                aRefCxt.mnRowDelta = nDy;
+                aRefCxt.mnTabDelta = nDz;
                 if (rCxt.getClipDoc()->GetClipParam().mbCutMode)
                 {
                     bool bOldInserting = IsInsertingFromOtherDoc();
                     SetInsertingFromOtherDoc( true);
-                    UpdateReference( URM_MOVE,
-                        nCol1, nRow1, i, nCol2, nRow2, i+nFollow,
-                        nDx, nDy, nDz, rCxt.getUndoDoc(), false );
+                    aRefCxt.meMode = URM_MOVE;
+                    UpdateReference(aRefCxt, rCxt.getUndoDoc(), false);
                     SetInsertingFromOtherDoc( bOldInserting);
                 }
                 else
-                    UpdateReference( URM_COPY,
-                        nCol1, nRow1, i, nCol2, nRow2, i+nFollow,
-                        nDx, nDy, nDz, rCxt.getUndoDoc(), false );
+                {
+                    aRefCxt.meMode = URM_COPY;
+                    UpdateReference(aRefCxt, rCxt.getUndoDoc(), false);
+                }
 
                 nClipTab = (nClipTab+nFollow+1) % (static_cast<SCTAB>(rClipTabs.size()));
                 i = sal::static_int_cast<SCTAB>( i + nFollow );
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index b02334e..acb5d46 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -47,6 +47,7 @@
 #include "listenercontext.hxx"
 #include "types.hxx"
 #include "scopetools.hxx"
+#include "refupdatecontext.hxx"
 
 #include <boost/scoped_ptr.hpp>
 
@@ -2117,11 +2118,14 @@ bool ScFormulaCell::HasColRowName() const
 }
 
 bool ScFormulaCell::UpdateReference(
-    UpdateRefMode eUpdateRefMode, const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
-    ScDocument* pUndoDoc, const ScAddress* pUndoCellPos )
+    const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc, const ScAddress* pUndoCellPos )
 {
     bool bCellStateChanged = false;
-
+    UpdateRefMode eUpdateRefMode = rCxt.meMode;
+    const ScRange& rRange = rCxt.maRange;
+    SCCOL nDx = rCxt.mnColDelta;
+    SCROW nDy = rCxt.mnRowDelta;
+    SCTAB nDz = rCxt.mnTabDelta;
     SCCOL nCol1 = rRange.aStart.Col();
     SCROW nRow1 = rRange.aStart.Row();
     SCCOL nCol = aPos.Col();
diff --git a/sc/source/core/data/refupdatecontext.cxx b/sc/source/core/data/refupdatecontext.cxx
new file mode 100644
index 0000000..a5c8616
--- /dev/null
+++ b/sc/source/core/data/refupdatecontext.cxx
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "refupdatecontext.hxx"
+
+namespace sc {
+
+RefUpdateContext::RefUpdateContext() :
+    meMode(URM_INSDEL), mnColDelta(0), mnRowDelta(0), mnTabDelta(0) {}
+
+bool RefUpdateContext::hasDelta() const
+{
+    return (mnColDelta > 0 || mnRowDelta > 0 || mnTabDelta > 0);
+}
+
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 9b1ea3d..ba9ada3 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -47,6 +47,7 @@
 #include "globalnames.hxx"
 #include "cellvalue.hxx"
 #include "scmatrix.hxx"
+#include "refupdatecontext.hxx"
 
 #include <vector>
 
@@ -1446,17 +1447,16 @@ void ScTable::UpdateDrawRef( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nR
     }
 }
 
-void ScTable::UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
-                     SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
-                     ScDocument* pUndoDoc, bool bIncludeDraw, bool bUpdateNoteCaptionPos )
+void ScTable::UpdateReference(
+    const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc, bool bIncludeDraw, bool bUpdateNoteCaptionPos )
 {
     bool bUpdated = false;
     SCCOL i;
     SCCOL iMax;
-    if ( eUpdateRefMode == URM_COPY )
+    if (rCxt.meMode == URM_COPY )
     {
-        i = nCol1;
-        iMax = nCol2;
+        i = rCxt.maRange.aStart.Col();
+        iMax = rCxt.maRange.aEnd.Col();
     }
     else
     {
@@ -1464,14 +1464,21 @@ void ScTable::UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW
         iMax = MAXCOL;
     }
 
-    ScRange aRange(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2);
+    ScRange aRange = rCxt.maRange;
+    UpdateRefMode eUpdateRefMode = rCxt.meMode;
+    SCCOL nDx = rCxt.mnColDelta;
+    SCROW nDy = rCxt.mnRowDelta;
+    SCTAB nDz = rCxt.mnTabDelta;
+    SCCOL nCol1 = rCxt.maRange.aStart.Col(), nCol2 = rCxt.maRange.aEnd.Col();
+    SCROW nRow1 = rCxt.maRange.aStart.Row(), nRow2 = rCxt.maRange.aEnd.Row();
+    SCTAB nTab1 = rCxt.maRange.aStart.Tab(), nTab2 = rCxt.maRange.aEnd.Tab();
 
     // Named expressions need to be updated before formulas acessing them.
     if (mpRangeName)
         mpRangeName->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz, true );
 
     for ( ; i<=iMax; i++)
-        bUpdated |= aCol[i].UpdateReference(eUpdateRefMode, aRange, nDx, nDy, nDz, pUndoDoc);
+        bUpdated |= aCol[i].UpdateReference(rCxt, pUndoDoc);
 
     if ( bIncludeDraw )
         UpdateDrawRef( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz, bUpdateNoteCaptionPos );
@@ -1557,7 +1564,7 @@ void ScTable::UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW
         SetStreamValid(false);
 
     if(mpCondFormatList)
-        mpCondFormatList->UpdateReference( eUpdateRefMode, ScRange(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2), nDx, nDy, nDz);
+        mpCondFormatList->UpdateReference(eUpdateRefMode, rCxt.maRange, nDx, nDy, nDz);
 }
 
 void ScTable::UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 62dd91e..c8bb3ae 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -47,6 +47,7 @@
 #include "types.hxx"
 #include "editutil.hxx"
 #include "mtvcellfunc.hxx"
+#include "refupdatecontext.hxx"
 
 #include "scitems.hxx"
 #include <editeng/boxitem.hxx>
@@ -3511,10 +3512,13 @@ void ScTable::CopyData( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW n
 
             if (aCell.meType == CELLTYPE_FORMULA)
             {
-                aCell.mpFormula->UpdateReference( URM_COPY, aRange,
-                                ((SCsCOL) nDestCol) - ((SCsCOL) nStartCol),
-                                ((SCsROW) nDestRow) - ((SCsROW) nStartRow),
-                                ((SCsTAB) nDestTab) - ((SCsTAB) nTab) );
+                sc::RefUpdateContext aCxt;
+                aCxt.meMode = URM_COPY;
+                aCxt.maRange = aRange;
+                aCxt.mnColDelta = nDestCol - nStartCol;
+                aCxt.mnRowDelta = nDestRow - nStartRow;
+                aCxt.mnTabDelta = nDestTab - nTab;
+                aCell.mpFormula->UpdateReference(aCxt);
                 aCell.mpFormula->aPos = aDest;
             }
 
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index 8072440..29dfcc6 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -32,6 +32,7 @@
 #include "globstr.hrc"
 #include "editutil.hxx"
 #include "tokenarray.hxx"
+#include "refupdatecontext.hxx"
 
 #include <tools/shl.hxx>        // SHL_CALC
 #include <tools/rtti.hxx>
@@ -1302,12 +1303,13 @@ bool ScChangeActionMove::Reject( ScDocument* pDoc )
     pDoc->DeleteAreaTab( aToRange, IDF_ALL );
     pDoc->DeleteAreaTab( aFrmRange, IDF_ALL );
     // Formeln im Dokument anpassen
-    pDoc->UpdateReference( URM_MOVE,
-        aFrmRange.aStart.Col(), aFrmRange.aStart.Row(), aFrmRange.aStart.Tab(),
-        aFrmRange.aEnd.Col(), aFrmRange.aEnd.Row(), aFrmRange.aEnd.Tab(),
-        (SCsCOL) aFrmRange.aStart.Col() - aToRange.aStart.Col(),
-        (SCsROW) aFrmRange.aStart.Row() - aToRange.aStart.Row(),
-        (SCsTAB) aFrmRange.aStart.Tab() - aToRange.aStart.Tab(), NULL );
+    sc::RefUpdateContext aCxt;
+    aCxt.meMode = URM_MOVE;
+    aCxt.maRange = aFrmRange;
+    aCxt.mnColDelta = aFrmRange.aStart.Col() - aToRange.aStart.Col();
+    aCxt.mnRowDelta = aFrmRange.aStart.Row() - aToRange.aStart.Row();
+    aCxt.mnTabDelta = aFrmRange.aStart.Tab() - aToRange.aStart.Tab();
+    pDoc->UpdateReference(aCxt, NULL);
 
     // LinkDependent freigeben, nachfolgendes UpdateReference-Undo setzt
     // ToRange->FromRange Dependents
@@ -2095,12 +2097,19 @@ void ScChangeActionContent::UpdateReference( const ScChangeTrack* pTrack,
             }
         }
         ScRange aRange( aTmpRange.MakeRange() );
+
+        sc::RefUpdateContext aRefCxt;
+        aRefCxt.meMode = eMode;
+        aRefCxt.maRange = aRange;
+        aRefCxt.mnColDelta = nDx;
+        aRefCxt.mnRowDelta = nDy;
+        aRefCxt.mnTabDelta = nDz;
+
         if ( bOldFormula )
-            maOldCell.mpFormula->UpdateReference( eMode, aRange,
-                (SCsCOL) nDx, (SCsROW) nDy, (SCsTAB) nDz, NULL );
+            maOldCell.mpFormula->UpdateReference(aRefCxt, NULL);
         if ( bNewFormula )
-            maNewCell.mpFormula->UpdateReference( eMode, aRange,
-                (SCsCOL) nDx, (SCsROW) nDy, (SCsTAB) nDz, NULL );
+            maNewCell.mpFormula->UpdateReference(aRefCxt, NULL);
+
         if ( !aBigRange.aStart.IsValid( pTrack->GetDocument() ) )
         {   //! HACK!
             //! UpdateReference kann nicht mit Positionen ausserhalb des
diff --git a/sc/source/core/tool/scopetools.cxx b/sc/source/core/tool/scopetools.cxx
index 5a317bb..af65cff 100644
--- a/sc/source/core/tool/scopetools.cxx
+++ b/sc/source/core/tool/scopetools.cxx
@@ -23,6 +23,17 @@ AutoCalcSwitch::~AutoCalcSwitch()
     mrDoc.SetAutoCalc(mbOldValue);
 }
 
+ExpandRefsSwitch::ExpandRefsSwitch(ScDocument& rDoc, bool bExpandRefs) :
+    mrDoc(rDoc), mbOldValue(rDoc.IsExpandRefs())
+{
+    mrDoc.SetExpandRefs(bExpandRefs);
+}
+
+ExpandRefsSwitch::~ExpandRefsSwitch()
+{
+    mrDoc.SetExpandRefs(mbOldValue);
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list