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!
InitFlagsScSingleRefData78 inline void InitFlags() { bFlags = 0; } // all FALSE
79
80 // #123870# Make it possible to init members to some defined values
InitMembersScSingleRefData81 inline void InitMembers() { nRow = nRelRow = 0; nCol = nRelCol = 0; nTab = nRelTab = 0; }
82
83 // InitAddress: InitFlags and set address
84 inline void InitAddress( const ScAddress& rAdr );
85 inline void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab );
86 // InitAddressRel: InitFlags and set address, everything relative to rPos
87 inline void InitAddressRel( const ScAddress& rAdr, const ScAddress& rPos );
SetColRelScSingleRefData88 inline void SetColRel( sal_Bool bVal ) { Flags.bColRel = (bVal ? sal_True : sal_False ); }
IsColRelScSingleRefData89 inline sal_Bool IsColRel() const { return Flags.bColRel; }
SetRowRelScSingleRefData90 inline void SetRowRel( sal_Bool bVal ) { Flags.bRowRel = (bVal ? sal_True : sal_False ); }
IsRowRelScSingleRefData91 inline sal_Bool IsRowRel() const { return Flags.bRowRel; }
SetTabRelScSingleRefData92 inline void SetTabRel( sal_Bool bVal ) { Flags.bTabRel = (bVal ? sal_True : sal_False ); }
IsTabRelScSingleRefData93 inline sal_Bool IsTabRel() const { return Flags.bTabRel; }
94
SetColDeletedScSingleRefData95 inline void SetColDeleted( sal_Bool bVal ) { Flags.bColDeleted = (bVal ? sal_True : sal_False ); }
IsColDeletedScSingleRefData96 inline sal_Bool IsColDeleted() const { return Flags.bColDeleted; }
SetRowDeletedScSingleRefData97 inline void SetRowDeleted( sal_Bool bVal ) { Flags.bRowDeleted = (bVal ? sal_True : sal_False ); }
IsRowDeletedScSingleRefData98 inline sal_Bool IsRowDeleted() const { return Flags.bRowDeleted; }
SetTabDeletedScSingleRefData99 inline void SetTabDeleted( sal_Bool bVal ) { Flags.bTabDeleted = (bVal ? sal_True : sal_False ); }
IsTabDeletedScSingleRefData100 inline sal_Bool IsTabDeleted() const { return Flags.bTabDeleted; }
IsDeletedScSingleRefData101 inline sal_Bool IsDeleted() const { return IsColDeleted() || IsRowDeleted() || IsTabDeleted(); }
102
SetFlag3DScSingleRefData103 inline void SetFlag3D( sal_Bool bVal ) { Flags.bFlag3D = (bVal ? sal_True : sal_False ); }
IsFlag3DScSingleRefData104 inline sal_Bool IsFlag3D() const { return Flags.bFlag3D; }
SetRelNameScSingleRefData105 inline void SetRelName( sal_Bool bVal ) { Flags.bRelName = (bVal ? sal_True : sal_False ); }
IsRelNameScSingleRefData106 inline sal_Bool IsRelName() const { return Flags.bRelName; }
107
108 inline sal_Bool Valid() const;
109 /// In external references nTab is -1
110 inline bool ValidExternal() const;
111
112 void SmartRelAbs( const ScAddress& rPos );
113 void CalcRelFromAbs( const ScAddress& rPos );
114 void CalcAbsIfRel( const ScAddress& rPos );
115 sal_Bool operator==( const ScSingleRefData& ) const;
116 bool operator!=( const ScSingleRefData& ) const;
117 };
118
InitAddress(SCCOL nColP,SCROW nRowP,SCTAB nTabP)119 inline void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP )
120 {
121 InitFlags();
122 nCol = nColP;
123 nRow = nRowP;
124 nTab = nTabP;
125 }
126
InitAddress(const ScAddress & rAdr)127 inline void ScSingleRefData::InitAddress( const ScAddress& rAdr )
128 {
129 InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
130 }
131
InitAddressRel(const ScAddress & rAdr,const ScAddress & rPos)132 inline void ScSingleRefData::InitAddressRel( const ScAddress& rAdr,
133 const ScAddress& rPos )
134 {
135 InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
136 SetColRel( sal_True );
137 SetRowRel( sal_True );
138 SetTabRel( sal_True );
139 CalcRelFromAbs( rPos );
140 }
141
Valid() const142 inline sal_Bool ScSingleRefData::Valid() const
143 {
144 return nCol >= 0 && nCol <= MAXCOL &&
145 nRow >= 0 && nRow <= MAXROW &&
146 nTab >= 0 && nTab <= MAXTAB;
147 }
148
ValidExternal() const149 inline bool ScSingleRefData::ValidExternal() const
150 {
151 return nCol >= 0 && nCol <= MAXCOL &&
152 nRow >= 0 && nRow <= MAXROW &&
153 nTab == -1;
154 }
155
156
157 struct ScComplexRefData // Complex reference (a range) into the sheet
158 {
159 ScSingleRefData Ref1;
160 ScSingleRefData Ref2;
161
InitFlagsScComplexRefData162 inline void InitFlags()
163 { Ref1.InitFlags(); Ref2.InitFlags(); }
164
165 // #123870# Make it possible to init members to some defined values
InitMembersScComplexRefData166 inline void InitMembers()
167 {
168 Ref1.InitMembers();
169 Ref2.InitMembers();
170 }
171
InitRangeScComplexRefData172 inline void InitRange( const ScRange& rRange )
173 {
174 Ref1.InitAddress( rRange.aStart );
175 Ref2.InitAddress( rRange.aEnd );
176 }
InitRangeRelScComplexRefData177 inline void InitRangeRel( const ScRange& rRange, const ScAddress& rPos )
178 {
179 Ref1.InitAddressRel( rRange.aStart, rPos );
180 Ref2.InitAddressRel( rRange.aEnd, rPos );
181 }
InitRangeScComplexRefData182 inline void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
183 SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
184 {
185 Ref1.InitAddress( nCol1, nRow1, nTab1 );
186 Ref2.InitAddress( nCol2, nRow2, nTab2 );
187 }
SmartRelAbsScComplexRefData188 inline void SmartRelAbs( const ScAddress& rPos )
189 { Ref1.SmartRelAbs( rPos ); Ref2.SmartRelAbs( rPos ); }
CalcRelFromAbsScComplexRefData190 inline void CalcRelFromAbs( const ScAddress& rPos )
191 { Ref1.CalcRelFromAbs( rPos ); Ref2.CalcRelFromAbs( rPos ); }
CalcAbsIfRelScComplexRefData192 inline void CalcAbsIfRel( const ScAddress& rPos )
193 { Ref1.CalcAbsIfRel( rPos ); Ref2.CalcAbsIfRel( rPos ); }
IsDeletedScComplexRefData194 inline sal_Bool IsDeleted() const
195 { return Ref1.IsDeleted() || Ref2.IsDeleted(); }
ValidScComplexRefData196 inline sal_Bool Valid() const
197 { return Ref1.Valid() && Ref2.Valid(); }
198 /** In external references nTab is -1 for the start tab and -1 for the end
199 tab if one sheet, or >=0 if more than one sheets. */
200 inline bool ValidExternal() const;
201
202 /// Absolute references have to be up-to-date when calling this!
203 void PutInOrder();
operator ==ScComplexRefData204 inline sal_Bool operator==( const ScComplexRefData& r ) const
205 { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
206 /** Enlarge range if reference passed is not within existing range.
207 ScAddress position is used to calculate absolute references from
208 relative references. */
209 ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos );
210 ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos );
211 };
212
ValidExternal() const213 inline bool ScComplexRefData::ValidExternal() const
214 {
215 return Ref1.ValidExternal() &&
216 Ref2.nCol >= 0 && Ref2.nCol <= MAXCOL &&
217 Ref2.nRow >= 0 && Ref2.nRow <= MAXROW &&
218 Ref2.nTab >= Ref1.nTab;
219 }
220
221 #endif
222