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