summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-06-17 17:12:49 +0200
committerEike Rathke <erack@redhat.com>2015-06-18 02:47:29 +0200
commita60fc4bf72bd4cecda8b50a4b62b0c14101f8a58 (patch)
treeb84058293847b8d22273c8949d4e3a356566615e
parenta4d223689df8049be83589bafb2d1e3f4bbc8fc5 (diff)
properly inherit relative and 3D flags when extending, tdf#83365 related
Commit 194e9f9bae28bdf22a9ed4779c1656ee693f3302 oversimplified things. Change-Id: Iea6a84c4a7be49af036690afbb1512ae2c1045a2 (cherry picked from commit e503addfbbe45efe1a3c06392c66fb79c3c72d07)
-rw-r--r--sc/source/core/tool/refdata.cxx49
1 files changed, 48 insertions, 1 deletions
diff --git a/sc/source/core/tool/refdata.cxx b/sc/source/core/tool/refdata.cxx
index d508247ad641..af18610297e5 100644
--- a/sc/source/core/tool/refdata.cxx
+++ b/sc/source/core/tool/refdata.cxx
@@ -259,8 +259,22 @@ void ScSingleRefData::Dump( int nIndent ) const
ScComplexRefData& ScComplexRefData::Extend( const ScSingleRefData & rRef, const ScAddress & rPos )
{
+ bool bInherit3D = (Ref1.IsFlag3D() && !Ref2.IsFlag3D() && !rRef.IsFlag3D());
ScRange aAbsRange = toAbs(rPos);
- ScAddress aAbs = rRef.toAbs(rPos);
+
+ ScSingleRefData aRef = rRef;
+ // If no sheet was given in the extending part, let it point to the same
+ // sheet as this reference's end point, inheriting the absolute/relative
+ // mode.
+ // [$]Sheet1.A5:A6:A7 on Sheet2 do still reference only Sheet1.
+ if (!rRef.IsFlag3D())
+ {
+ if (Ref2.IsTabRel())
+ aRef.SetRelTab( Ref2.Tab());
+ else
+ aRef.SetAbsTab( Ref2.Tab());
+ }
+ ScAddress aAbs = aRef.toAbs(rPos);
if (aAbs.Col() < aAbsRange.aStart.Col())
aAbsRange.aStart.SetCol(aAbs.Col());
@@ -280,6 +294,39 @@ ScComplexRefData& ScComplexRefData::Extend( const ScSingleRefData & rRef, const
if (aAbsRange.aEnd.Tab() < aAbs.Tab())
aAbsRange.aEnd.SetTab(aAbs.Tab());
+ // In Ref2 inherit absolute/relative addressing from the extending part.
+ // A$5:A5 => A$5:A$5:A5 => A$5:A5, and not A$5:A$5
+ // A$6:$A5 => A$6:A$6:$A5 => A5:$A$6
+ if (aAbsRange.aEnd.Col() == aAbs.Col())
+ Ref2.SetColRel( rRef.IsColRel());
+ if (aAbsRange.aEnd.Row() == aAbs.Row())
+ Ref2.SetRowRel( rRef.IsRowRel());
+
+ // In Ref1 inherit relative sheet from extending part if given.
+ if (aAbsRange.aStart.Tab() == aAbs.Tab() && rRef.IsFlag3D())
+ Ref1.SetTabRel( rRef.IsTabRel());
+
+ // In Ref2 inherit relative sheet from either Ref1 or extending part.
+ // Use the original 3D flags to determine which.
+ // $Sheet1.$A$5:$A$6 => $Sheet1.$A$5:$A$5:$A$6 => $Sheet1.$A$5:$A$6, and
+ // not $Sheet1.$A$5:Sheet1.$A$6 (with invisible second 3D, but relative).
+ if (aAbsRange.aEnd.Tab() == aAbs.Tab())
+ Ref2.SetTabRel( bInherit3D ? Ref1.IsTabRel() : rRef.IsTabRel());
+
+ // Force 3D flag in Ref1 if different sheet or more than one sheet
+ // referenced.
+ if (aAbsRange.aStart.Tab() != rPos.Tab() || aAbsRange.aStart.Tab() != aAbsRange.aEnd.Tab())
+ Ref1.SetFlag3D(true);
+
+ // Force 3D flag in Ref2 if more than one sheet referenced.
+ if (aAbsRange.aStart.Tab() != aAbsRange.aEnd.Tab())
+ Ref2.SetFlag3D(true);
+
+ // Inherit 3D flag in Ref1 from extending part in case range wasn't
+ // extended as in A5:A5:Sheet1.A5 if on Sheet1.
+ if (rRef.IsFlag3D())
+ Ref1.SetFlag3D( true);
+
SetRange(aAbsRange, rPos);
return *this;