1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: refdata.hxx,v $
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
40 // Ref-Flags for old (until release 3.1) documents
42 struct OldSingleRefBools
44 BYTE bRelCol
; // Flag values (see further down), 2 bits each in file format
47 BYTE bOldFlag3D
; // two BOOL flags (see further down)
50 #define SR_ABSOLUTE 0 // Absolute value
51 #define SR_RELABS 1 // Relative value as absolute value (until release 3.1)
52 #define SR_RELATIVE 2 // Relative value as delta value (after release 3.1)
53 #define SR_DELETED 3 // Deleted col/row/tab
55 #define SRF_3D 0x01 // 3D reference, was the BOOL (before build 304a)
56 #define SRF_RELNAME 0x02 // Reference derived from RangeName with relative values
57 #define SRF_BITS 0x03 // Mask of possible bits
60 struct SingleRefData
// Single reference (one address) into the sheet
62 INT16 nCol
; // Absolute values
65 INT16 nRelCol
; // Values relative to the position
80 BOOL bFlag3D
:1; // 3D-Ref
81 BOOL bRelName
:1; // Reference derived from RangeName with relative values
85 // No default ctor, because used in ScRawToken union, set InitFlags!
86 inline void InitFlags() { bFlags
= 0; } // all FALSE
87 // InitAddress: InitFlags and set address
88 inline void InitAddress( const ScAddress
& rAdr
);
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 void OldBoolsToNewFlags( const OldSingleRefBools
& );
117 BYTE
CreateStoreByteFromFlags() const;
118 void CreateFlagsFromLoadByte( BYTE
);
119 BOOL
operator==( const SingleRefData
& ) const;
122 inline void SingleRefData::InitAddress( const ScAddress
& rAdr
)
130 inline void SingleRefData::InitAddressRel( const ScAddress
& rAdr
,
131 const ScAddress
& rPos
)
140 CalcRelFromAbs( rPos
);
143 inline BOOL
SingleRefData::Valid() const
145 return nCol
>= 0 && nCol
<= MAXCOL
&&
146 nRow
>= 0 && nRow
<= MAXROW
&&
147 nTab
>= 0 && nTab
<= MAXTAB
;
151 struct ComplRefData
// Complex reference (a range) into the sheet
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 SmartRelAbs( const ScAddress
& rPos
)
169 { Ref1
.SmartRelAbs( rPos
); Ref2
.SmartRelAbs( rPos
); }
170 inline void CalcRelFromAbs( const ScAddress
& rPos
)
171 { Ref1
.CalcRelFromAbs( rPos
); Ref2
.CalcRelFromAbs( rPos
); }
172 inline void CalcAbsIfRel( const ScAddress
& rPos
)
173 { Ref1
.CalcAbsIfRel( rPos
); Ref2
.CalcAbsIfRel( rPos
); }
174 inline BOOL
Valid() const
175 { return Ref1
.Valid() && Ref2
.Valid(); }
177 inline BOOL
operator==( const ComplRefData
& r
) const
178 { return Ref1
== r
.Ref1
&& Ref2
== r
.Ref2
; }
181 } //namespace binfilter