#88286# ValidateTabRefs

This commit is contained in:
Niklas Nebel 2001-06-15 12:39:13 +00:00
parent 06cb4957ae
commit de4992baf8
2 changed files with 69 additions and 4 deletions

View file

@ -2,9 +2,9 @@
*
* $RCSfile: rangenam.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: nn $ $Date: 2000-10-06 13:44:06 $
* last change: $Author: nn $ $Date: 2001-06-15 13:37:06 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -186,6 +186,8 @@ public:
void UpdateTabRef(USHORT nOldTable, USHORT nFlag, USHORT nNewTable);
void TransferTabRef( USHORT nOldTab, USHORT nNewTab );
void ValidateTabRefs();
void ReplaceRangeNamesInUse( const ScIndexMap& rMap );
BOOL IsBeyond( USHORT nMaxRow ) const;

View file

@ -2,9 +2,9 @@
*
* $RCSfile: rangenam.cxx,v $
*
* $Revision: 1.5 $
* $Revision: 1.6 $
*
* last change: $Author: er $ $Date: 2001-03-14 18:10:21 $
* last change: $Author: nn $ $Date: 2001-06-15 13:39:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -659,6 +659,69 @@ void ScRangeData::ReplaceRangeNamesInUse( const ScIndexMap& rMap )
}
void ScRangeData::ValidateTabRefs()
{
// try to make sure all relative references and the reference position
// are within existing tables, so they can be represented as text
// (if the range of used tables is more than the existing tables,
// the result may still contain invalid tables, because the relative
// references aren't changed so formulas stay the same)
// find range of used tables
USHORT nMinTab = aPos.Tab();
USHORT nMaxTab = nMinTab;
ScToken* t;
pCode->Reset();
while ( t = pCode->GetNextReference() )
{
SingleRefData& rRef1 = t->GetSingleRef();
if ( rRef1.IsTabRel() && !rRef1.IsTabDeleted() )
{
if ( rRef1.nTab < nMinTab )
nMinTab = rRef1.nTab;
if ( rRef1.nTab > nMaxTab )
nMaxTab = rRef1.nTab;
}
if ( t->GetType() == svDoubleRef )
{
SingleRefData& rRef2 = t->GetDoubleRef().Ref2;
if ( rRef2.IsTabRel() && !rRef2.IsTabDeleted() )
{
if ( rRef2.nTab < nMinTab )
nMinTab = rRef2.nTab;
if ( rRef2.nTab > nMaxTab )
nMaxTab = rRef2.nTab;
}
}
}
USHORT nTabCount = pDoc->GetTableCount();
if ( nMaxTab >= nTabCount && nMinTab > 0 )
{
// move position and relative tab refs
// The formulas that use the name are not changed by this
USHORT nMove = nMinTab;
aPos.SetTab( aPos.Tab() - nMove );
pCode->Reset();
while ( t = pCode->GetNextReference() )
{
SingleRefData& rRef1 = t->GetSingleRef();
if ( rRef1.IsTabRel() && !rRef1.IsTabDeleted() )
rRef1.nTab -= nMove;
if ( t->GetType() == svDoubleRef )
{
SingleRefData& rRef2 = t->GetDoubleRef().Ref2;
if ( rRef2.IsTabRel() && !rRef2.IsTabDeleted() )
rRef2.nTab -= nMove;
}
}
}
}
int
#ifdef WNT
__cdecl