1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_REFDATA_HXX 25cdf0e10cSrcweir #define SC_REFDATA_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "global.hxx" 28cdf0e10cSrcweir #include "address.hxx" 29cdf0e10cSrcweir #include "scdllapi.h" 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir // Ref-Flags for old (until release 3.1) documents 33cdf0e10cSrcweir 34cdf0e10cSrcweir struct OldSingleRefBools 35cdf0e10cSrcweir { 36cdf0e10cSrcweir sal_uInt8 bRelCol; // Flag values (see further down), 2 bits each in file format 37cdf0e10cSrcweir sal_uInt8 bRelRow; 38cdf0e10cSrcweir sal_uInt8 bRelTab; 39cdf0e10cSrcweir sal_uInt8 bOldFlag3D; // two sal_Bool flags (see further down) 40cdf0e10cSrcweir }; 41cdf0e10cSrcweir 42cdf0e10cSrcweir #define SR_ABSOLUTE 0 // Absolute value 43cdf0e10cSrcweir #define SR_RELABS 1 // Relative value as absolute value (until release 3.1) 44cdf0e10cSrcweir #define SR_RELATIVE 2 // Relative value as delta value (after release 3.1) 45cdf0e10cSrcweir #define SR_DELETED 3 // Deleted col/row/tab 46cdf0e10cSrcweir 47cdf0e10cSrcweir #define SRF_3D 0x01 // 3D reference, was the sal_Bool (before build 304a) 48cdf0e10cSrcweir #define SRF_RELNAME 0x02 // Reference derived from RangeName with relative values 49cdf0e10cSrcweir #define SRF_BITS 0x03 // Mask of possible bits 50cdf0e10cSrcweir 51cdf0e10cSrcweir 52cdf0e10cSrcweir struct SC_DLLPUBLIC ScSingleRefData // Single reference (one address) into the sheet 53cdf0e10cSrcweir { 54cdf0e10cSrcweir SCsCOL nCol; // Absolute values 55cdf0e10cSrcweir SCsROW nRow; 56cdf0e10cSrcweir SCsTAB nTab; 57cdf0e10cSrcweir SCsCOL nRelCol; // Values relative to the position 58cdf0e10cSrcweir SCsROW nRelRow; 59cdf0e10cSrcweir SCsTAB nRelTab; 60cdf0e10cSrcweir 61cdf0e10cSrcweir union 62cdf0e10cSrcweir { 63cdf0e10cSrcweir sal_Bool bFlags; 64cdf0e10cSrcweir struct 65cdf0e10cSrcweir { 66cdf0e10cSrcweir sal_Bool bColRel :1; 67cdf0e10cSrcweir sal_Bool bColDeleted :1; 68cdf0e10cSrcweir sal_Bool bRowRel :1; 69cdf0e10cSrcweir sal_Bool bRowDeleted :1; 70cdf0e10cSrcweir sal_Bool bTabRel :1; 71cdf0e10cSrcweir sal_Bool bTabDeleted :1; 72cdf0e10cSrcweir sal_Bool bFlag3D :1; // 3D-Ref 73cdf0e10cSrcweir sal_Bool bRelName :1; // Reference derived from RangeName with relative values 74cdf0e10cSrcweir }Flags; 75cdf0e10cSrcweir }; 76cdf0e10cSrcweir 77cdf0e10cSrcweir // No default ctor, because used in ScRawToken union, set InitFlags! 78cdf0e10cSrcweir inline void InitFlags() { bFlags = 0; } // all FALSE 79cdf0e10cSrcweir // InitAddress: InitFlags and set address 80cdf0e10cSrcweir inline void InitAddress( const ScAddress& rAdr ); 81cdf0e10cSrcweir inline void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab ); 82cdf0e10cSrcweir // InitAddressRel: InitFlags and set address, everything relative to rPos 83cdf0e10cSrcweir inline void InitAddressRel( const ScAddress& rAdr, const ScAddress& rPos ); 84cdf0e10cSrcweir inline void SetColRel( sal_Bool bVal ) { Flags.bColRel = (bVal ? sal_True : sal_False ); } 85cdf0e10cSrcweir inline sal_Bool IsColRel() const { return Flags.bColRel; } 86cdf0e10cSrcweir inline void SetRowRel( sal_Bool bVal ) { Flags.bRowRel = (bVal ? sal_True : sal_False ); } 87cdf0e10cSrcweir inline sal_Bool IsRowRel() const { return Flags.bRowRel; } 88cdf0e10cSrcweir inline void SetTabRel( sal_Bool bVal ) { Flags.bTabRel = (bVal ? sal_True : sal_False ); } 89cdf0e10cSrcweir inline sal_Bool IsTabRel() const { return Flags.bTabRel; } 90cdf0e10cSrcweir 91cdf0e10cSrcweir inline void SetColDeleted( sal_Bool bVal ) { Flags.bColDeleted = (bVal ? sal_True : sal_False ); } 92cdf0e10cSrcweir inline sal_Bool IsColDeleted() const { return Flags.bColDeleted; } 93cdf0e10cSrcweir inline void SetRowDeleted( sal_Bool bVal ) { Flags.bRowDeleted = (bVal ? sal_True : sal_False ); } 94cdf0e10cSrcweir inline sal_Bool IsRowDeleted() const { return Flags.bRowDeleted; } 95cdf0e10cSrcweir inline void SetTabDeleted( sal_Bool bVal ) { Flags.bTabDeleted = (bVal ? sal_True : sal_False ); } 96cdf0e10cSrcweir inline sal_Bool IsTabDeleted() const { return Flags.bTabDeleted; } 97cdf0e10cSrcweir inline sal_Bool IsDeleted() const { return IsColDeleted() || IsRowDeleted() || IsTabDeleted(); } 98cdf0e10cSrcweir 99cdf0e10cSrcweir inline void SetFlag3D( sal_Bool bVal ) { Flags.bFlag3D = (bVal ? sal_True : sal_False ); } 100cdf0e10cSrcweir inline sal_Bool IsFlag3D() const { return Flags.bFlag3D; } 101cdf0e10cSrcweir inline void SetRelName( sal_Bool bVal ) { Flags.bRelName = (bVal ? sal_True : sal_False ); } 102cdf0e10cSrcweir inline sal_Bool IsRelName() const { return Flags.bRelName; } 103cdf0e10cSrcweir 104cdf0e10cSrcweir inline sal_Bool Valid() const; 105cdf0e10cSrcweir /// In external references nTab is -1 106cdf0e10cSrcweir inline bool ValidExternal() const; 107cdf0e10cSrcweir 108cdf0e10cSrcweir void SmartRelAbs( const ScAddress& rPos ); 109cdf0e10cSrcweir void CalcRelFromAbs( const ScAddress& rPos ); 110cdf0e10cSrcweir void CalcAbsIfRel( const ScAddress& rPos ); 111cdf0e10cSrcweir sal_Bool operator==( const ScSingleRefData& ) const; 112cdf0e10cSrcweir bool operator!=( const ScSingleRefData& ) const; 113cdf0e10cSrcweir }; 114cdf0e10cSrcweir 115cdf0e10cSrcweir inline void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir InitFlags(); 118cdf0e10cSrcweir nCol = nColP; 119cdf0e10cSrcweir nRow = nRowP; 120cdf0e10cSrcweir nTab = nTabP; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir inline void ScSingleRefData::InitAddress( const ScAddress& rAdr ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab()); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir inline void ScSingleRefData::InitAddressRel( const ScAddress& rAdr, 129cdf0e10cSrcweir const ScAddress& rPos ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab()); 132cdf0e10cSrcweir SetColRel( sal_True ); 133cdf0e10cSrcweir SetRowRel( sal_True ); 134cdf0e10cSrcweir SetTabRel( sal_True ); 135cdf0e10cSrcweir CalcRelFromAbs( rPos ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir inline sal_Bool ScSingleRefData::Valid() const 139cdf0e10cSrcweir { 140cdf0e10cSrcweir return nCol >= 0 && nCol <= MAXCOL && 141cdf0e10cSrcweir nRow >= 0 && nRow <= MAXROW && 142cdf0e10cSrcweir nTab >= 0 && nTab <= MAXTAB; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir inline bool ScSingleRefData::ValidExternal() const 146cdf0e10cSrcweir { 147cdf0e10cSrcweir return nCol >= 0 && nCol <= MAXCOL && 148cdf0e10cSrcweir nRow >= 0 && nRow <= MAXROW && 149cdf0e10cSrcweir nTab == -1; 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir 153cdf0e10cSrcweir struct ScComplexRefData // Complex reference (a range) into the sheet 154cdf0e10cSrcweir { 155cdf0e10cSrcweir ScSingleRefData Ref1; 156cdf0e10cSrcweir ScSingleRefData Ref2; 157cdf0e10cSrcweir 158cdf0e10cSrcweir inline void InitFlags() 159cdf0e10cSrcweir { Ref1.InitFlags(); Ref2.InitFlags(); } 160cdf0e10cSrcweir inline void InitRange( const ScRange& rRange ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir Ref1.InitAddress( rRange.aStart ); 163cdf0e10cSrcweir Ref2.InitAddress( rRange.aEnd ); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir inline void InitRangeRel( const ScRange& rRange, const ScAddress& rPos ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir Ref1.InitAddressRel( rRange.aStart, rPos ); 168cdf0e10cSrcweir Ref2.InitAddressRel( rRange.aEnd, rPos ); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir inline void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1, 171cdf0e10cSrcweir SCCOL nCol2, SCROW nRow2, SCTAB nTab2 ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir Ref1.InitAddress( nCol1, nRow1, nTab1 ); 174cdf0e10cSrcweir Ref2.InitAddress( nCol2, nRow2, nTab2 ); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir inline void SmartRelAbs( const ScAddress& rPos ) 177cdf0e10cSrcweir { Ref1.SmartRelAbs( rPos ); Ref2.SmartRelAbs( rPos ); } 178cdf0e10cSrcweir inline void CalcRelFromAbs( const ScAddress& rPos ) 179cdf0e10cSrcweir { Ref1.CalcRelFromAbs( rPos ); Ref2.CalcRelFromAbs( rPos ); } 180cdf0e10cSrcweir inline void CalcAbsIfRel( const ScAddress& rPos ) 181cdf0e10cSrcweir { Ref1.CalcAbsIfRel( rPos ); Ref2.CalcAbsIfRel( rPos ); } 182cdf0e10cSrcweir inline sal_Bool IsDeleted() const 183cdf0e10cSrcweir { return Ref1.IsDeleted() || Ref2.IsDeleted(); } 184cdf0e10cSrcweir inline sal_Bool Valid() const 185cdf0e10cSrcweir { return Ref1.Valid() && Ref2.Valid(); } 186cdf0e10cSrcweir /** In external references nTab is -1 for the start tab and -1 for the end 187cdf0e10cSrcweir tab if one sheet, or >=0 if more than one sheets. */ 188cdf0e10cSrcweir inline bool ValidExternal() const; 189cdf0e10cSrcweir 190cdf0e10cSrcweir /// Absolute references have to be up-to-date when calling this! 191cdf0e10cSrcweir void PutInOrder(); 192cdf0e10cSrcweir inline sal_Bool operator==( const ScComplexRefData& r ) const 193cdf0e10cSrcweir { return Ref1 == r.Ref1 && Ref2 == r.Ref2; } 194cdf0e10cSrcweir /** Enlarge range if reference passed is not within existing range. 195cdf0e10cSrcweir ScAddress position is used to calculate absolute references from 196cdf0e10cSrcweir relative references. */ 197cdf0e10cSrcweir ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos ); 198cdf0e10cSrcweir ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos ); 199cdf0e10cSrcweir }; 200cdf0e10cSrcweir 201cdf0e10cSrcweir inline bool ScComplexRefData::ValidExternal() const 202cdf0e10cSrcweir { 203cdf0e10cSrcweir return Ref1.ValidExternal() && 204cdf0e10cSrcweir Ref2.nCol >= 0 && Ref2.nCol <= MAXCOL && 205cdf0e10cSrcweir Ref2.nRow >= 0 && Ref2.nRow <= MAXROW && 206cdf0e10cSrcweir Ref2.nTab >= Ref1.nTab; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir #endif 210