summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-07-07 09:48:38 +0200
committerEike Rathke <erack@redhat.com>2015-07-07 12:40:32 +0200
commitad3d2b6c2e88d191d76f90eb5be927f7ca76c670 (patch)
treecf8c1845e1dae9ec6bb2540e5caf79feca99784f /sc
parentd24c6a0280b0287ee6c23ca89068323c6b7c3dd7 (diff)
(re-)introduce ScComplexRefData::PutInOrder(), tdf#92468
Change-Id: If551e02a77a416b95f74266de896391d1d72eb3c
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/refdata.hxx9
-rw-r--r--sc/source/core/tool/refdata.cxx92
2 files changed, 101 insertions, 0 deletions
diff --git a/sc/inc/refdata.hxx b/sc/inc/refdata.hxx
index c49682f67534..b96acb7a7eec 100644
--- a/sc/inc/refdata.hxx
+++ b/sc/inc/refdata.hxx
@@ -104,6 +104,9 @@ public:
SCCOL Col() const;
SCTAB Tab() const;
+ /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
+ static void PutInOrder( ScSingleRefData& rRef1, ScSingleRefData& rRef2, const ScAddress& rPos );
+
bool operator==( const ScSingleRefData& ) const;
bool operator!=( const ScSingleRefData& ) const;
@@ -161,8 +164,14 @@ struct ScComplexRefData
}
SC_DLLPUBLIC ScRange toAbs( const ScAddress& rPos ) const;
+
+ /** Set a new range, assuming that the ordering of the range matches the
+ ordering of the reference data flags already set. */
void SetRange( const ScRange& rRange, const ScAddress& rPos );
+ /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
+ void PutInOrder( const ScAddress& rPos );
+
inline bool operator==( const ScComplexRefData& r ) const
{ return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
/** Enlarge range if reference passed is not within existing range.
diff --git a/sc/source/core/tool/refdata.cxx b/sc/source/core/tool/refdata.cxx
index 97d419c03105..4a814dba1f3f 100644
--- a/sc/source/core/tool/refdata.cxx
+++ b/sc/source/core/tool/refdata.cxx
@@ -239,6 +239,93 @@ SCTAB ScSingleRefData::Tab() const
return mnTab;
}
+// static
+void ScSingleRefData::PutInOrder( ScSingleRefData& rRef1, ScSingleRefData& rRef2, const ScAddress& rPos )
+{
+ sal_uInt8 nRelState1 = rRef1.Flags.bRelName ?
+ ((rRef1.Flags.bTabRel ? 4 : 0) |
+ (rRef1.Flags.bRowRel ? 2 : 0) |
+ (rRef1.Flags.bColRel ? 1 : 0)) :
+ 0;
+
+ sal_uInt8 nRelState2 = rRef2.Flags.bRelName ?
+ ((rRef2.Flags.bTabRel ? 4 : 0) |
+ (rRef2.Flags.bRowRel ? 2 : 0) |
+ (rRef2.Flags.bColRel ? 1 : 0)) :
+ 0;
+
+ SCCOL nCol1 = rRef1.Flags.bColRel ? rPos.Col() + rRef1.mnCol : rRef1.mnCol;
+ SCCOL nCol2 = rRef2.Flags.bColRel ? rPos.Col() + rRef2.mnCol : rRef2.mnCol;
+ if (nCol2 < nCol1)
+ {
+ rRef1.mnCol = rRef2.Flags.bColRel ? nCol2 - rPos.Col() : nCol2;
+ rRef2.mnCol = rRef1.Flags.bColRel ? nCol1 - rPos.Col() : nCol1;
+ if (rRef1.Flags.bRelName && rRef1.Flags.bColRel)
+ nRelState2 |= 1;
+ else
+ nRelState2 &= ~1;
+ if (rRef2.Flags.bRelName && rRef2.Flags.bColRel)
+ nRelState1 |= 1;
+ else
+ nRelState1 &= ~1;
+ bool bTmp = rRef1.Flags.bColRel;
+ rRef1.Flags.bColRel = rRef2.Flags.bColRel;
+ rRef2.Flags.bColRel = bTmp;
+ bTmp = rRef1.Flags.bColDeleted;
+ rRef1.Flags.bColDeleted = rRef2.Flags.bColDeleted;
+ rRef2.Flags.bColDeleted = bTmp;
+ }
+
+ SCROW nRow1 = rRef1.Flags.bRowRel ? rPos.Row() + rRef1.mnRow : rRef1.mnRow;
+ SCROW nRow2 = rRef2.Flags.bRowRel ? rPos.Row() + rRef2.mnRow : rRef2.mnRow;
+ if (nRow2 < nRow1)
+ {
+ rRef1.mnRow = rRef2.Flags.bRowRel ? nRow2 - rPos.Row() : nRow2;
+ rRef2.mnRow = rRef1.Flags.bRowRel ? nRow1 - rPos.Row() : nRow1;
+ if (rRef1.Flags.bRelName && rRef1.Flags.bRowRel)
+ nRelState2 |= 2;
+ else
+ nRelState2 &= ~2;
+ if (rRef2.Flags.bRelName && rRef2.Flags.bRowRel)
+ nRelState1 |= 2;
+ else
+ nRelState1 &= ~2;
+ bool bTmp = rRef1.Flags.bRowRel;
+ rRef1.Flags.bRowRel = rRef2.Flags.bRowRel;
+ rRef2.Flags.bRowRel = bTmp;
+ bTmp = rRef1.Flags.bRowDeleted;
+ rRef1.Flags.bRowDeleted = rRef2.Flags.bRowDeleted;
+ rRef2.Flags.bRowDeleted = bTmp;
+ }
+
+ SCTAB nTab1 = rRef1.Flags.bTabRel ? rPos.Tab() + rRef1.mnTab : rRef1.mnTab;
+ SCTAB nTab2 = rRef2.Flags.bTabRel ? rPos.Tab() + rRef2.mnTab : rRef2.mnTab;
+ if (nTab2 < nTab1)
+ {
+ rRef1.mnTab = rRef2.Flags.bTabRel ? nTab2 - rPos.Tab() : nTab2;
+ rRef2.mnTab = rRef1.Flags.bTabRel ? nTab1 - rPos.Tab() : nTab1;
+ if (rRef1.Flags.bRelName && rRef1.Flags.bTabRel)
+ nRelState2 |= 4;
+ else
+ nRelState2 &= ~4;
+ if (rRef2.Flags.bRelName && rRef2.Flags.bTabRel)
+ nRelState1 |= 4;
+ else
+ nRelState1 &= ~4;
+ bool bTmp = rRef1.Flags.bTabRel;
+ rRef1.Flags.bTabRel = rRef2.Flags.bTabRel;
+ rRef2.Flags.bTabRel = bTmp;
+ bTmp = rRef1.Flags.bTabDeleted;
+ rRef1.Flags.bTabDeleted = rRef2.Flags.bTabDeleted;
+ rRef2.Flags.bTabDeleted = bTmp;
+ }
+
+ // bFlag3D stays the same on both references.
+
+ rRef1.Flags.bRelName = (nRelState1 != 0);
+ rRef2.Flags.bRelName = (nRelState2 != 0);
+}
+
bool ScSingleRefData::operator==( const ScSingleRefData& r ) const
{
return mnFlagValue == r.mnFlagValue && mnCol == r.mnCol && mnRow == r.mnRow && mnTab == r.mnTab;
@@ -382,6 +469,11 @@ void ScComplexRefData::SetRange( const ScRange& rRange, const ScAddress& rPos )
Ref2.SetAddress(rRange.aEnd, rPos);
}
+void ScComplexRefData::PutInOrder( const ScAddress& rPos )
+{
+ ScSingleRefData::PutInOrder( Ref1, Ref2, rPos);
+}
+
#if DEBUG_FORMULA_COMPILER
void ScComplexRefData::Dump( int nIndent ) const
{