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