update ooo310-m15
[ooovba.git] / sc / inc / refdata.hxx
blob933999a036b6950f6b215baa8d67d5b16ead0787
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;
113 void SmartRelAbs( const ScAddress& rPos );
114 void CalcRelFromAbs( const ScAddress& rPos );
115 void CalcAbsIfRel( const ScAddress& rPos );
116 BOOL operator==( const ScSingleRefData& ) const;
117 bool operator!=( const ScSingleRefData& ) const;
120 inline void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP )
122 InitFlags();
123 nCol = nColP;
124 nRow = nRowP;
125 nTab = nTabP;
128 inline void ScSingleRefData::InitAddress( const ScAddress& rAdr )
130 InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
133 inline void ScSingleRefData::InitAddressRel( const ScAddress& rAdr,
134 const ScAddress& rPos )
136 InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
137 SetColRel( TRUE );
138 SetRowRel( TRUE );
139 SetTabRel( TRUE );
140 CalcRelFromAbs( rPos );
143 inline BOOL ScSingleRefData::Valid() const
145 return nCol >= 0 && nCol <= MAXCOL &&
146 nRow >= 0 && nRow <= MAXROW &&
147 nTab >= 0 && nTab <= MAXTAB;
151 struct ScComplexRefData // Complex reference (a range) into the sheet
153 ScSingleRefData Ref1;
154 ScSingleRefData Ref2;
156 inline void InitFlags()
157 { Ref1.InitFlags(); Ref2.InitFlags(); }
158 inline void InitRange( const ScRange& rRange )
160 Ref1.InitAddress( rRange.aStart );
161 Ref2.InitAddress( rRange.aEnd );
163 inline void InitRangeRel( const ScRange& rRange, const ScAddress& rPos )
165 Ref1.InitAddressRel( rRange.aStart, rPos );
166 Ref2.InitAddressRel( rRange.aEnd, rPos );
168 inline void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
169 SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
171 Ref1.InitAddress( nCol1, nRow1, nTab1 );
172 Ref2.InitAddress( nCol2, nRow2, nTab2 );
174 inline void SmartRelAbs( const ScAddress& rPos )
175 { Ref1.SmartRelAbs( rPos ); Ref2.SmartRelAbs( rPos ); }
176 inline void CalcRelFromAbs( const ScAddress& rPos )
177 { Ref1.CalcRelFromAbs( rPos ); Ref2.CalcRelFromAbs( rPos ); }
178 inline void CalcAbsIfRel( const ScAddress& rPos )
179 { Ref1.CalcAbsIfRel( rPos ); Ref2.CalcAbsIfRel( rPos ); }
180 inline BOOL IsDeleted() const
181 { return Ref1.IsDeleted() || Ref2.IsDeleted(); }
182 inline BOOL Valid() const
183 { return Ref1.Valid() && Ref2.Valid(); }
184 /// Absolute references have to be up-to-date when calling this!
185 void PutInOrder();
186 inline BOOL operator==( const ScComplexRefData& r ) const
187 { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
188 /** Enlarge range if reference passed is not within existing range.
189 ScAddress position is used to calculate absolute references from
190 relative references. */
191 ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos );
192 ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos );
195 #endif