fdo#78402: Adjust references of validity entries as appropriate.

Change-Id: I7fd62153c7267a3d606b86d74bebecf6b8d75250
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 43dc94e..49f2fea 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -513,13 +513,38 @@ void ScConditionEntry::UpdateReference( sc::RefUpdateContext& rCxt )

    if (pFormula1)
    {
        sc::RefUpdateResult aRes = pFormula1->AdjustReferenceInName(rCxt, aOldSrcPos);
        sc::RefUpdateResult aRes;
        switch (rCxt.meMode)
        {
            case URM_INSDEL:
                aRes = pFormula1->AdjustReferenceOnShift(rCxt, aOldSrcPos);
            break;
            case URM_MOVE:
                aRes = pFormula1->AdjustReferenceOnMove(rCxt, aOldSrcPos, aSrcPos);
            break;
            default:
                ;
        }

        if (aRes.mbReferenceModified || bChangedPos)
            DELETEZ(pFCell1);       // is created again in IsValid
    }

    if (pFormula2)
    {
        sc::RefUpdateResult aRes = pFormula2->AdjustReferenceInName(rCxt, aOldSrcPos);
        sc::RefUpdateResult aRes;
        switch (rCxt.meMode)
        {
            case URM_INSDEL:
                aRes = pFormula2->AdjustReferenceOnShift(rCxt, aOldSrcPos);
            break;
            case URM_MOVE:
                aRes = pFormula2->AdjustReferenceOnMove(rCxt, aOldSrcPos, aSrcPos);
            break;
            default:
                ;
        }

        if (aRes.mbReferenceModified || bChangedPos)
            DELETEZ(pFCell2);       // is created again in IsValid
    }
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index e414337..e4fb73f 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -1867,6 +1867,8 @@ void ScInterpreter::QueryMatrixType(ScMatrixRef& xMat, short& rRetTypeExpr, sal_
{
    if (xMat)
    {
        SCSIZE nCols, nRows;
        xMat->GetDimensions(nCols, nRows);
        ScMatrixValue nMatVal = xMat->Get(0, 0);
        ScMatValType nMatValType = nMatVal.nType;
        if (ScMatrix::IsNonValueType( nMatValType))
@@ -1874,14 +1876,14 @@ void ScInterpreter::QueryMatrixType(ScMatrixRef& xMat, short& rRetTypeExpr, sal_
            if ( xMat->IsEmptyPath( 0, 0))
            {   // result of empty FALSE jump path
                FormulaTokenRef xRes = new FormulaDoubleToken( 0.0);
                PushTempToken( new ScMatrixCellResultToken( xMat, xRes.get()));
                PushTempToken( new ScMatrixFormulaCellToken(nCols, nRows, xMat, xRes.get()));
                rRetTypeExpr = NUMBERFORMAT_LOGICAL;
            }
            else
            {
                svl::SharedString aStr( nMatVal.GetString());
                FormulaTokenRef xRes = new FormulaStringToken( aStr);
                PushTempToken( new ScMatrixCellResultToken( xMat, xRes.get()));
                PushTempToken( new ScMatrixFormulaCellToken(nCols, nRows, xMat, xRes.get()));
                rRetTypeExpr = NUMBERFORMAT_TEXT;
            }
        }
@@ -1893,7 +1895,7 @@ void ScInterpreter::QueryMatrixType(ScMatrixRef& xMat, short& rRetTypeExpr, sal_
                xRes = new FormulaErrorToken( nErr);
            else
                xRes = new FormulaDoubleToken( nMatVal.fVal);
            PushTempToken( new ScMatrixCellResultToken( xMat, xRes.get()));
            PushTempToken( new ScMatrixFormulaCellToken(nCols, nRows, xMat, xRes.get()));
            if ( rRetTypeExpr != NUMBERFORMAT_LOGICAL )
                rRetTypeExpr = NUMBERFORMAT_NUMBER;
        }
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index fefa95f..dd0577e 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -49,6 +49,8 @@
#include "sc.hrc"
#include <rowheightcontext.hxx>
#include <refhint.hxx>
#include <refupdatecontext.hxx>
#include <validat.hxx>

#include <set>
#include <boost/scoped_ptr.hpp>
@@ -1264,6 +1266,19 @@ void ScUndoDragDrop::Undo()
        SCTAB nTabDelta = aSrcRange.aStart.Tab() - aDestRange.aStart.Tab();
        sc::RefMovedHint aHint(aDestRange, ScAddress(nColDelta, nRowDelta, nTabDelta));
        pDoc->BroadcastRefMoved(aHint);

        ScValidationDataList* pValidList = pDoc->GetValidationList();
        if (pValidList)
        {
            // Update the references of validation entries.
            sc::RefUpdateContext aCxt(*pDoc);
            aCxt.meMode = URM_MOVE;
            aCxt.maRange = aSrcRange;
            aCxt.mnColDelta = nColDelta;
            aCxt.mnRowDelta = nRowDelta;
            aCxt.mnTabDelta = nTabDelta;
            pValidList->UpdateReference(aCxt);
        }
    }

    DoUndo(aDestRange);