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