24#include <com/sun/star/sheet/NamedRangeFlag.hpp>
25#include <osl/diagnose.h>
28#include <tokenarray.hxx>
32#include <compiler.hxx>
34#include <document.hxx>
46 const OUString& rName,
47 const OUString& rSymbol,
56 eTempGrammar( eGrammar ),
60 if (!rSymbol.isEmpty())
76 pCode->SetFromRangeName(
true);
81 const OUString& rName,
95 pCode->SetFromRangeName(
true);
100 const OUString& rName,
115 pCode->AddSingleReference( aRefData );
116 pCode->SetFromRangeName(
true);
119 if (
pCode->GetCodeError() == FormulaError::NONE )
125 aUpperName (rScRangeData.aUpperName),
126 pCode (rScRangeData.pCode ? rScRangeData.pCode->
Clone().release() : new
ScTokenArray(*pDocument)),
127 aPos (pPos ? *pPos : rScRangeData.aPos),
129 rDoc (pDocument ? *pDocument : rScRangeData.rDoc),
130 eTempGrammar(rScRangeData.eTempGrammar),
132 bModified (rScRangeData.bModified)
134 pCode->SetFromRangeName(
true);
145 OSL_FAIL(
"ScRangeData::CompileRangeData: unspecified grammar");
155 pCode->SetFromRangeName(
true);
156 if(
pCode->GetCodeError() != FormulaError::NONE )
180 if (
pCode->GetCodeError() == FormulaError::NoName)
194#if DEBUG_FORMULA_COMPILER
195void ScRangeData::Dump()
const
197 cout <<
"-- ScRangeData" <<
endl;
211 OSL_ENSURE(
aPos ==
ScAddress(),
"position will go lost now");
223 nMinCol = rRef1.
Col();
225 nMinRow = rRef1.
Row();
227 nMinTab = rRef1.
Tab();
233 nMinCol = rRef2.
Col();
235 nMinRow = rRef2.
Row();
237 nMinTab = rRef2.
Tab();
278 bool bChanged =
false;
312 bool bChanged =
false;
344 if (
nIndex != rData.nIndex ||
345 aName != rData.aName ||
346 aPos != rData.aPos ||
347 eType != rData.eType )
return false;
349 sal_uInt16 nLen = pCode->GetLen();
350 if ( nLen != rData.pCode->GetLen() )
return false;
355 for ( sal_uInt16
i=0;
i<nLen;
i++ )
356 if ( ppThis[
i] != ppOther[
i] && !(*ppThis[
i] == *ppOther[
i]) )
367 bRet = ( rBlock == aRange );
382 return pCode->IsReference(rRange, rPos);
390 return pCode->IsValidReference(rRange,
aPos);
428 sal_Int32 nLen = rName.getLength();
432 rName = rName.copy(
nPos);
439 nLen = rName.getLength();
443 rName = rName.replaceAt(
nPos, 1,
u"_" );
450 for (
int nConv = FormulaGrammar::CONV_UNSPECIFIED; ++nConv < FormulaGrammar::CONV_LAST; )
460 if ( rName.indexOf(
'.' ) != -1 )
461 rName = rName.replaceFirst(
".",
"_" );
473 if (rName.indexOf(
a) != -1)
476 sal_Int32 nLen = rName.getLength();
479 while (
nPos < nLen )
486 for (
int nConv = FormulaGrammar::CONV_UNSPECIFIED; ++nConv < FormulaGrammar::CONV_LAST; )
504 for (
int nConv = FormulaGrammar::CONV_UNSPECIFIED; ++nConv < FormulaGrammar::CONV_LAST; )
517 return pCode ?
pCode->GetCodeError() : FormulaError::NONE;
522 return pCode->HasReferences();
527 sal_uInt32 nUnoType = 0;
546 SCTAB nMaxTab = nMinTab;
555 if (aAbs.
Tab() < nMinTab)
556 nMinTab = aAbs.
Tab();
557 if (aAbs.
Tab() > nMaxTab)
558 nMaxTab = aAbs.
Tab();
566 if (aAbs.
Tab() < nMinTab)
567 nMinTab = aAbs.
Tab();
568 if (aAbs.
Tab() > nMaxTab)
569 nMaxTab = aAbs.
Tab();
575 if ( nMaxTab < nTabCount || nMinTab <= 0 )
581 SCTAB nMove = nMinTab;
588 switch (
t->GetType())
624 pCode->SetFromRangeName(
true);
630 if(
pCode->GetCodeError() == FormulaError::NONE )
660 explicit MatchByRange(
const ScRange& rRange) : mrRange(rRange) {}
661 bool operator() (std::pair<OUString
const, std::unique_ptr<ScRangeData>>
const& r)
const
663 return r.second->IsRangeAtBlock(mrRange);
670 : mHasPossibleAddressConflict(false)
671 , mHasPossibleAddressConflictDirty(false)
676 : mHasPossibleAddressConflict( r.mHasPossibleAddressConflict )
677 , mHasPossibleAddressConflictDirty( r.mHasPossibleAddressConflictDirty )
679 for (
auto const& it : r.
m_Data)
681 m_Data.insert(std::make_pair(it.first, std::make_unique<ScRangeData>(*it.second)));
685 for (
auto const& itr :
m_Data)
687 size_t nPos = itr.second->GetIndex() - 1;
690 OSL_FAIL(
"ScRangeName copy-ctor: maIndexToData size doesn't fit");
699 DataType::const_iterator itr = std::find_if(
701 return itr ==
m_Data.end() ? nullptr : itr->second.get();
706 DataType::iterator itr =
m_Data.find(rName);
707 return itr ==
m_Data.end() ? nullptr : itr->second.get();
712 DataType::const_iterator itr =
m_Data.find(rName);
713 return itr ==
m_Data.end() ? nullptr : itr->second.get();
732 for (
auto const& itr :
m_Data)
734 itr.second->UpdateReference(rCxt, nLocalTab);
740 for (
auto const& itr :
m_Data)
742 itr.second->UpdateInsertTab(rCxt, nLocalTab);
748 for (
auto const& itr :
m_Data)
750 itr.second->UpdateDeleteTab(rCxt, nLocalTab);
756 for (
auto const& itr :
m_Data)
758 itr.second->UpdateMoveTab(rCxt, nLocalTab);
764 for (
auto const& itr :
m_Data)
766 itr.second->UpdateTranspose(rSource, rDest);
772 for (
auto const& itr :
m_Data)
774 itr.second->UpdateGrow(rArea, nGrowX, nGrowY);
780 for (
auto const& itr :
m_Data)
782 itr.second->CompileUnresolvedXML(rCxt);
789 for (
auto const& itr :
m_Data)
791 SCTAB nSheet = (nLocalTab < 0) ? nLocalTab : nOldTab;
792 sal_uInt16
nIndex = itr.second->GetIndex();
793 ScAddress aOldPos( itr.second->GetPos());
812 IndexDataType::iterator itr = std::find(
818 p->SetIndex(
nPos + 1);
830 OUString
aName(
p->GetUpperName());
832 pair<DataType::iterator, bool> r =
833 m_Data.insert(std::make_pair(
aName, std::unique_ptr<ScRangeData>(
p)));
837 size_t nPos =
p->GetIndex() - 1;
853 DataType::const_iterator itr =
m_Data.find(rName);
860 sal_uInt16
nIndex = itr->second->GetIndex();
881 for (
auto const& itr :
m_Data)
883 if( itr.second->HasPossibleAddressConflict())
894 [](
const DataType::value_type& lhs,
const DataType::value_type& rhs) {
895 return (lhs.first == rhs.first) && (*lhs.second == *rhs.second);
sal_Int32 compareString(const OUString &s1, const OUString &s2) const
void IncTab(SCTAB nDelta=1)
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const Details &rDetails=detailsOOOa1, ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, sal_Int32 *pSheetEndPos=nullptr, const OUString *pErrRef=nullptr)
@ EXTENDED_ERROR_DETECTION_NAME_NO_BREAK
static bool IsCharFlagAllConventions(OUString const &rStr, sal_Int32 nPos, ScCharFlags nFlags)
If the character is allowed as tested by nFlags (SC_COMPILER_C_... bits) for all known address conven...
void SetExtendedErrorDetection(ExtendedErrorDetection eVal)
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
ScSheetLimits & GetSheetLimits() const
SC_DLLPUBLIC void CheckLinkFormulaNeedingCheck(const ScTokenArray &rCode)
Check token array and set link check if ocDde/ocWebservice is contained.
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
bool CopyAdjustRangeName(SCTAB &rSheet, sal_uInt16 &rIndex, ScRangeData *&rpRangeData, ScDocument &rNewDoc, const ScAddress &rNewPos, const ScAddress &rOldPos, const bool bGlobalNamesToLocal, const bool bUsedByFormula) const
If necessary (name references sheet rOldPos.Tab()) copy and adjust named expression/range from sheet-...
bool IsImportingXML() const
SC_DLLPUBLIC SCTAB GetTableCount() const
static SC_DLLPUBLIC CollatorWrapper & GetCollator()
case-insensitive collator
SC_DLLPUBLIC bool IsReference(ScRange &rRef) const
bool HasType(Type nType) const
void CompileUnresolvedXML(sc::CompileFormulaContext &rCxt)
bool HasPossibleAddressConflict() const
sal_uInt32 GetUnoType() const
std::unique_ptr< ScTokenArray > pCode
formula::FormulaGrammar::Grammar eTempGrammar
SC_DLLPUBLIC FormulaError GetErrCode() const
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt, SCTAB nLocalTab)
SC_DLLPUBLIC void GuessPosition()
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt, SCTAB nLocalTab)
static void MakeValidName(const ScDocument &rDoc, OUString &rName)
void UpdateSymbol(OUStringBuffer &rBuffer, const ScAddress &)
void CompileRangeData(const OUString &rSymbol, bool bSetError)
void UpdateReference(sc::RefUpdateContext &rCxt, SCTAB nLocalTab)
SC_DLLPUBLIC ~ScRangeData()
@ NAME_INVALID_BAD_STRING
SC_DLLPUBLIC bool IsValidReference(ScRange &rRef) const
SC_DLLPUBLIC void SetCode(const ScTokenArray &)
void UpdateTranspose(const ScRange &rSource, const ScAddress &rDest)
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
static SC_DLLPUBLIC IsNameValidType IsNameValid(const OUString &rName, const ScDocument &rDoc)
bool IsRangeAtBlock(const ScRange &) const
SC_DLLPUBLIC OUString GetSymbol(const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
bool HasReferences() const
SC_DLLPUBLIC ScRangeData(ScDocument &rDoc, const OUString &rName, const OUString &rSymbol, const ScAddress &rAdr=ScAddress(), Type nType=Type::Name, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT)
const OUString & GetUpperName() const
bool operator==(const ScRangeData &rData) const
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt, SCTAB nLocalTab)
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt, SCTAB nLocalTab=-1)
void CopyUsedNames(const SCTAB nLocalTab, const SCTAB nOldTab, const SCTAB nNewTab, const ScDocument &rOldDoc, ScDocument &rNewDoc, const bool bGlobalNamesToLocal) const
Copy names while copying a sheet if they reference the sheet to be copied.
SC_DLLPUBLIC ScRangeData * findByIndex(sal_uInt16 i) const
void UpdateReference(sc::RefUpdateContext &rCxt, SCTAB nLocalTab=-1)
void CompileUnresolvedXML(sc::CompileFormulaContext &rCxt)
Compile those names that couldn't be resolved during loading and inserting because they may have refe...
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt, SCTAB nLocalTab=-1)
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt, SCTAB nLocalTab=-1)
IndexDataType maIndexToData
void erase(const ScRangeData &r)
bool mHasPossibleAddressConflictDirty
DataType::const_iterator const_iterator
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
bool mHasPossibleAddressConflict
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
void UpdateTranspose(const ScRange &rSource, const ScAddress &rDest)
void checkHasPossibleAddressConflict() const
SC_DLLPUBLIC const ScRangeData * findByRange(const ScRange &rRange) const
bool operator==(const ScRangeName &r) const
ScRefFlags Parse(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, ScAddress::ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, const OUString *pErrRef=nullptr)
static ScRefUpdateRes UpdateTranspose(const ScDocument &rDoc, const ScRange &rSource, const ScAddress &rDest, ScRange &rRef)
static ScRefUpdateRes UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY, ScRange &rRef)
void setGrammar(formula::FormulaGrammar::Grammar eGram)
void setUpdatedName(SCTAB nTab, sal_uInt16 nIndex)
virtual OUString GetName() const override
PyRef getCharClass(const Runtime &)
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
int ScRangeData_QsortNameCompare(const void *p1, const void *p2)
@ UR_NOTHING
Reference not affected, no change at all.
TOOLS_DLLPUBLIC SvStream & endl(SvStream &rStr)
Complex reference (a range) into the sheet.
SC_DLLPUBLIC ScRange toAbs(const ScSheetLimits &rLimits, const ScAddress &rPos) 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...
static void UpdateDeleteTab(ScAddress &rAddr, const sc::RefUpdateDeleteTabContext &rCxt)
This is for the base-cell-address of a defined name or conditional format, not for references.
Single reference (one address) into the sheet.
void SetAddress(const ScSheetLimits &rLimits, const ScAddress &rAddr, const ScAddress &rPos)
void InitAddress(const ScAddress &rAdr)
InitAddress: InitFlags and set address.
ScAddress toAbs(const ScSheetLimits &rLimits, const ScAddress &rPos) const
bool IsTabDeleted() const
void SetFlag3D(bool bVal)
Context for reference update during shifting, moving or copying of cell ranges.
UpdateRefMode meMode
update mode - insert/delete, copy, or move.
UpdatedRangeNames maUpdatedNames
UpdatedRangeNames maUpdatedNames
UpdatedRangeNames maUpdatedNames
UpdatedRangeNames maUpdatedNames
SCTAB getNewTab(SCTAB nOldTab) const
bool mbReferenceModified
This flag indicates whether any reference in the token array has been modified.