21 #include <document.hxx>
23 #include <compiler.hxx>
24 #include <tokenarray.hxx>
26 #include <rtl/ustring.hxx>
37 vector<ScTokenRef>& rRefTokens,
const OUString& rRangeStr,
ScDocument& rDoc,
41 OUString aRangeStr = rRangeStr;
42 while( (aRangeStr.getLength() >= 2) && (aRangeStr[ 0 ] ==
'(') && (aRangeStr[ aRangeStr.getLength() - 1 ] ==
')') )
43 aRangeStr = aRangeStr.copy( 1, aRangeStr.getLength() - 2 );
45 bool bFailure =
false;
46 sal_Int32 nOffset = 0;
47 while (nOffset >= 0 && !bFailure)
55 std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(aToken));
59 sal_uInt16 nLen = pArray->GetLen();
80 if (!rRef.
Valid(rDoc))
82 else if (bOnly3DRef && !rRef.
IsFlag3D())
89 if (!rRef.
Valid(rDoc))
116 rRefTokens.emplace_back(p->
Clone());
128 switch (pToken->GetType())
150 rRange = rRefData.
toAbs(*pDoc, rPos);
162 for (
const auto& rToken : rTokens)
185 vector<ScTokenRef> aTokens;
187 aTokens.reserve(nCount);
188 for (
size_t i = 0;
i < nCount; ++
i)
190 const ScRange & rRange = rRanges[
i];
193 aTokens.push_back(pToken);
195 pTokens.swap(aTokens);
200 switch (pToken->GetType())
215 switch (pToken->GetType())
234 sal_uInt16 nFileId = bExternal ? pToken->GetIndex() : 0;
250 if (bExternal && nFileId != p->
GetIndex())
262 class JoinRefTokenRanges
274 join(pDoc, rTokens, pToken, rPos);
290 static bool overlaps(T nMin1, T nMax1, T nMin2, T nMax2, T& rNewMin, T& rNewMax)
292 bool bDisjoint1 = (nMin1 > nMax2) && (nMin1 - nMax2 > 1);
293 bool bDisjoint2 = (nMin2 > nMax1) && (nMin2 - nMax1 > 1);
294 if (bDisjoint1 || bDisjoint2)
298 T nMin = std::min(nMin1, nMin2);
299 T nMax = std::max(nMax1, nMax2);
316 sal_uInt16 nFileId = bExternal ? pToken->GetIndex() : 0;
319 bool bJoined =
false;
333 if (nFileId != pOldToken->GetIndex())
337 if (aTabName != pOldToken->GetString())
348 if (aNew.aStart.Tab() != aOld.
aStart.
Tab() || aNew.aEnd.Tab() != aOld.
aEnd.
Tab())
356 bool bSameRows = (aNew.aStart.Row() == aOld.
aStart.
Row()) && (aNew.aEnd.Row() == aOld.
aEnd.
Row());
357 bool bSameCols = (aNew.aStart.Col() == aOld.
aStart.
Col()) && (aNew.aEnd.Col() == aOld.
aEnd.
Col());
359 bool bJoinRanges =
false;
362 SCCOL nNewMin, nNewMax;
363 bJoinRanges = overlaps(
369 aNew.aStart.SetCol(nNewMin);
370 aNew.aEnd.SetCol(nNewMax);
376 SCROW nNewMin, nNewMax;
377 bJoinRanges = overlaps(
383 aNew.aStart.SetRow(nNewMin);
384 aNew.aEnd.SetRow(nNewMax);
403 if (rTokens.size() == 1)
410 join(pDoc, rTokens, p, rPos);
413 rTokens.push_back(pToken);
421 JoinRefTokenRanges
join;
422 join(pDoc, rTokens, pToken, rPos);
427 switch (pToken->GetType())
441 rData = *pToken->GetDoubleRef();
void compileRangeRepresentation(::std::vector< ScTokenRef > &rRefTokens, const OUString &rRangeStr, ScDocument &rDoc, const sal_Unicode cSep,::formula::FormulaGrammar::Grammar eGrammar, bool bOnly3DRef=false)
Compile an array of reference tokens from a data source range string.
bool SC_DLLPUBLIC isExternalRef(const ScTokenRef &pToken)
void getTokenFromRange(const ScDocument *pDoc, ScTokenRef &pToken, const ScRange &rRange)
Create a double reference token from a range object.
static SharedString getEmptyString()
SC_DLLPUBLIC ScRange toAbs(const ScSheetLimits &rLimits, const ScAddress &rPos) const
bool Valid(const ScDocument &rDoc) const
Single reference (one address) into the sheet.
ScAddress toAbs(const ScSheetLimits &rLimits, const ScAddress &rPos) const
SC_DLLPUBLIC bool Intersects(const ScRange &rRange) const
void getRangeListFromTokens(const ScDocument *pDoc, ScRangeList &rRangeList, const ::std::vector< ScTokenRef > &pTokens, const ScAddress &rPos)
void SC_DLLPUBLIC join(const ScDocument *pDoc,::std::vector< ScTokenRef > &rTokens, const ScTokenRef &pToken, const ScAddress &rPos)
bool SC_DLLPUBLIC isRef(const ScTokenRef &pToken)
void push_back(const ScRange &rRange)
ScTokenRef createRefToken(const ScDocument &rDoc, const ScAddress &rAddr)
constexpr OUStringLiteral aData
bool ValidExternal(const ScDocument &rDoc) const
In external references nTab is -1 if the external document was not loaded but the sheet was cached...
void SetFlag3D(bool bVal)
void InitAddress(const ScAddress &rAdr)
InitAddress: InitFlags and set address.
bool getDoubleRefDataFromToken(ScComplexRefData &rData, const ScTokenRef &pToken)
ScSheetLimits & GetSheetLimits() const
bool In(const ScAddress &) const
is Address& in Range?
bool Valid(const ScDocument &rDoc) const
void InitRange(const ScRange &rRange)
::boost::intrusive_ptr< formula::FormulaToken > ScTokenRef
void SetRange(const ScSheetLimits &rLimits, const ScRange &rRange, const ScAddress &rPos)
Set a new range, assuming that the ordering of the range matches the ordering of the reference data f...
bool ValidExternal(const ScDocument &rDoc) const
In external references nTab is -1 for the start tab and -1 for the end tab if one sheet and the exter...
Complex reference (a range) into the sheet.
bool SC_DLLPUBLIC intersects(const ScDocument *pDoc, const ::std::vector< ScTokenRef > &rTokens, const ScTokenRef &pToken, const ScAddress &rPos)
bool getRangeFromToken(const ScDocument *pDoc, ScRange &rRange, const ScTokenRef &pToken, const ScAddress &rPos, bool bExternal=false)
static void GetTokenByOffset(OUString &rToken, const OUString &rString, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
void getTokensFromRangeList(const ScDocument *pDoc,::std::vector< ScTokenRef > &pTokens, const ScRangeList &rRanges)