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))
97 if (!
p->GetSingleRef()->ValidExternal(rDoc))
103 if (!
p->GetDoubleRef()->ValidExternal(rDoc))
108 if (
p->GetString().isEmpty())
113 if (
p->GetOpCode() == ocName)
126 rRefTokens.emplace_back(
p->Clone());
138 switch (pToken->GetType())
160 rRange = rRefData.
toAbs(*pDoc, rPos);
165 if (pToken->GetOpCode() ==
ocName)
182 for (
const auto& rToken : rTokens)
193 aData.InitRange(rRange);
194 aData.Ref1.SetFlag3D(
true);
205 vector<ScTokenRef> aTokens;
207 aTokens.reserve(nCount);
210 const ScRange & rRange = rRanges[
i];
213 aTokens.push_back(pToken);
215 pTokens.swap(aTokens);
220 switch (pToken->GetType())
235 switch (pToken->GetType())
254 sal_uInt16 nFileId = bExternal ? pToken->GetIndex() : 0;
270 if (bExternal && nFileId !=
p->GetIndex())
282class JoinRefTokenRanges
294 join(pDoc, rTokens, pToken, rPos);
310 static bool overlaps(T nMin1, T nMax1, T nMin2, T nMax2, T& rNewMin, T& rNewMax)
312 bool bDisjoint1 = (nMin1 > nMax2) && (nMin1 - nMax2 > 1);
313 bool bDisjoint2 = (nMin2 > nMax1) && (nMin2 - nMax1 > 1);
314 if (bDisjoint1 || bDisjoint2)
318 T nMin = std::min(nMin1, nMin2);
319 T nMax = std::max(nMax1, nMax2);
336 sal_uInt16 nFileId = bExternal ? pToken->GetIndex() : 0;
339 bool bJoined =
false;
353 if (nFileId != pOldToken->GetIndex())
357 if (aTabName != pOldToken->GetString())
368 if (aNew.aStart.Tab() != aOld.
aStart.
Tab() || aNew.aEnd.Tab() != aOld.
aEnd.
Tab())
376 bool bSameRows = (aNew.aStart.Row() == aOld.
aStart.
Row()) && (aNew.aEnd.Row() == aOld.
aEnd.
Row());
377 bool bSameCols = (aNew.aStart.Col() == aOld.
aStart.
Col()) && (aNew.aEnd.Col() == aOld.
aEnd.
Col());
379 bool bJoinRanges =
false;
382 SCCOL nNewMin, nNewMax;
383 bJoinRanges = overlaps(
389 aNew.aStart.SetCol(nNewMin);
390 aNew.aEnd.SetCol(nNewMax);
396 SCROW nNewMin, nNewMax;
397 bJoinRanges = overlaps(
403 aNew.aStart.SetRow(nNewMin);
404 aNew.aEnd.SetRow(nNewMax);
423 if (rTokens.size() == 1)
430 join(pDoc, rTokens, p, rPos);
433 rTokens.push_back(pToken);
441 JoinRefTokenRanges
join;
442 join(pDoc, rTokens, pToken, rPos);
447 switch (pToken->GetType())
461 rData = *pToken->GetDoubleRef();
ScSheetLimits & GetSheetLimits() const
ScRangeData * FindRangeNameBySheetAndIndex(SCTAB nTab, sal_uInt16 nIndex) const
Find a named expression / range name in either global or a local scope.
SC_DLLPUBLIC bool IsReference(ScRange &rRef) const
bool HasReferences() const
void push_back(const ScRange &rRange)
static void GetTokenByOffset(OUString &rToken, std::u16string_view rString, sal_Int32 &nOffset, sal_Unicode cSeparator=' ', sal_Unicode cQuote='\'')
bool Intersects(const ScRange &rRange) const
bool Contains(const ScAddress &) const
is Address& fully in Range?
static const SharedString & getEmptyString()
constexpr OUStringLiteral aData
bool SC_DLLPUBLIC isRef(const ScTokenRef &pToken)
void getRangeListFromTokens(const ScDocument *pDoc, ScRangeList &rRangeList, const ::std::vector< ScTokenRef > &pTokens, const ScAddress &rPos)
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.
ScTokenRef createRefToken(const ScDocument &rDoc, const ScAddress &rAddr)
void getTokensFromRangeList(const ScDocument *pDoc, ::std::vector< ScTokenRef > &pTokens, const ScRangeList &rRanges)
bool getRangeFromToken(const ScDocument *pDoc, ScRange &rRange, const ScTokenRef &pToken, const ScAddress &rPos, bool bExternal=false)
bool SC_DLLPUBLIC intersects(const ScDocument *pDoc, const ::std::vector< ScTokenRef > &rTokens, const ScTokenRef &pToken, const ScAddress &rPos)
void getTokenFromRange(const ScDocument *pDoc, ScTokenRef &pToken, const ScRange &rRange)
Create a double reference token from a range object.
bool SC_DLLPUBLIC isExternalRef(const ScTokenRef &pToken)
void SC_DLLPUBLIC join(const ScDocument *pDoc, ::std::vector< ScTokenRef > &rTokens, const ScTokenRef &pToken, const ScAddress &rPos)
bool getDoubleRefDataFromToken(ScComplexRefData &rData, const ScTokenRef &pToken)
Complex reference (a range) into the sheet.
SC_DLLPUBLIC ScRange toAbs(const ScSheetLimits &rLimits, const ScAddress &rPos) const
void InitRange(const ScRange &rRange)
bool Valid(const ScDocument &rDoc) const
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...
Single reference (one address) into the sheet.
void InitAddress(const ScAddress &rAdr)
InitAddress: InitFlags and set address.
bool Valid(const ScDocument &rDoc) const
ScAddress toAbs(const ScSheetLimits &rLimits, const ScAddress &rPos) const
void SetFlag3D(bool bVal)
::boost::intrusive_ptr< formula::FormulaToken > ScTokenRef