1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SC_REFDATA_HXX
21 #define SC_REFDATA_HXX
24 #include "address.hxx"
28 // Ref-Flags for old (until release 3.1) documents
30 struct OldSingleRefBools
32 sal_uInt8 bRelCol
; // Flag values (see further down), 2 bits each in file format
35 sal_uInt8 bOldFlag3D
; // two sal_Bool flags (see further down)
38 struct SC_DLLPUBLIC ScSingleRefData
// Single reference (one address) into the sheet
40 SCsCOL nCol
; // Absolute values
43 SCsCOL nRelCol
; // Values relative to the position
53 sal_Bool bColDeleted
:1;
55 sal_Bool bRowDeleted
:1;
57 sal_Bool bTabDeleted
:1;
58 sal_Bool bFlag3D
:1; // 3D-Ref
59 sal_Bool bRelName
:1; // Reference derived from RangeName with relative values
63 // No default ctor, because used in ScRawToken union, set InitFlags!
64 inline void InitFlags() { bFlags
= 0; } // all FALSE
65 // InitAddress: InitFlags and set address
66 inline void InitAddress( const ScAddress
& rAdr
);
67 inline void InitAddress( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
68 // InitAddressRel: InitFlags and set address, everything relative to rPos
69 inline void InitAddressRel( const ScAddress
& rAdr
, const ScAddress
& rPos
);
70 inline void SetColRel( sal_Bool bVal
) { Flags
.bColRel
= (bVal
? sal_True
: false ); }
71 inline sal_Bool
IsColRel() const { return Flags
.bColRel
; }
72 inline void SetRowRel( sal_Bool bVal
) { Flags
.bRowRel
= (bVal
? sal_True
: false ); }
73 inline sal_Bool
IsRowRel() const { return Flags
.bRowRel
; }
74 inline void SetTabRel( sal_Bool bVal
) { Flags
.bTabRel
= (bVal
? sal_True
: false ); }
75 inline sal_Bool
IsTabRel() const { return Flags
.bTabRel
; }
77 inline void SetColDeleted( sal_Bool bVal
) { Flags
.bColDeleted
= (bVal
? sal_True
: false ); }
78 inline sal_Bool
IsColDeleted() const { return Flags
.bColDeleted
; }
79 inline void SetRowDeleted( sal_Bool bVal
) { Flags
.bRowDeleted
= (bVal
? sal_True
: false ); }
80 inline sal_Bool
IsRowDeleted() const { return Flags
.bRowDeleted
; }
81 inline void SetTabDeleted( sal_Bool bVal
) { Flags
.bTabDeleted
= (bVal
? sal_True
: false ); }
82 inline sal_Bool
IsTabDeleted() const { return Flags
.bTabDeleted
; }
83 inline sal_Bool
IsDeleted() const { return IsColDeleted() || IsRowDeleted() || IsTabDeleted(); }
85 inline void SetFlag3D( sal_Bool bVal
) { Flags
.bFlag3D
= (bVal
? sal_True
: false ); }
86 inline sal_Bool
IsFlag3D() const { return Flags
.bFlag3D
; }
87 inline void SetRelName( sal_Bool bVal
) { Flags
.bRelName
= (bVal
? sal_True
: false ); }
88 inline sal_Bool
IsRelName() const { return Flags
.bRelName
; }
90 inline sal_Bool
Valid() const;
91 /// In external references nTab is -1
92 inline bool ValidExternal() const;
94 ScAddress
toAbs( const ScAddress
& rPos
) const;
96 void SmartRelAbs( const ScAddress
& rPos
);
97 void CalcRelFromAbs( const ScAddress
& rPos
);
98 void CalcAbsIfRel( const ScAddress
& rPos
);
99 sal_Bool
operator==( const ScSingleRefData
& ) const;
100 bool operator!=( const ScSingleRefData
& ) const;
103 inline void ScSingleRefData::InitAddress( SCCOL nColP
, SCROW nRowP
, SCTAB nTabP
)
111 inline void ScSingleRefData::InitAddress( const ScAddress
& rAdr
)
113 InitAddress( rAdr
.Col(), rAdr
.Row(), rAdr
.Tab());
116 inline void ScSingleRefData::InitAddressRel( const ScAddress
& rAdr
,
117 const ScAddress
& rPos
)
119 InitAddress( rAdr
.Col(), rAdr
.Row(), rAdr
.Tab());
120 SetColRel( sal_True
);
121 SetRowRel( sal_True
);
122 SetTabRel( sal_True
);
123 CalcRelFromAbs( rPos
);
126 inline sal_Bool
ScSingleRefData::Valid() const
128 return nCol
>= 0 && nCol
<= MAXCOL
&&
129 nRow
>= 0 && nRow
<= MAXROW
&&
130 nTab
>= 0 && nTab
<= MAXTAB
;
133 inline bool ScSingleRefData::ValidExternal() const
135 return nCol
>= 0 && nCol
<= MAXCOL
&&
136 nRow
>= 0 && nRow
<= MAXROW
&&
141 struct ScComplexRefData
// Complex reference (a range) into the sheet
143 ScSingleRefData Ref1
;
144 ScSingleRefData Ref2
;
146 inline void InitFlags()
147 { Ref1
.InitFlags(); Ref2
.InitFlags(); }
148 inline void InitRange( const ScRange
& rRange
)
150 Ref1
.InitAddress( rRange
.aStart
);
151 Ref2
.InitAddress( rRange
.aEnd
);
153 inline void InitRangeRel( const ScRange
& rRange
, const ScAddress
& rPos
)
155 Ref1
.InitAddressRel( rRange
.aStart
, rPos
);
156 Ref2
.InitAddressRel( rRange
.aEnd
, rPos
);
158 inline void InitRange( SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
159 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
)
161 Ref1
.InitAddress( nCol1
, nRow1
, nTab1
);
162 Ref2
.InitAddress( nCol2
, nRow2
, nTab2
);
164 inline void SmartRelAbs( const ScAddress
& rPos
)
165 { Ref1
.SmartRelAbs( rPos
); Ref2
.SmartRelAbs( rPos
); }
166 inline void CalcRelFromAbs( const ScAddress
& rPos
)
167 { Ref1
.CalcRelFromAbs( rPos
); Ref2
.CalcRelFromAbs( rPos
); }
168 inline void CalcAbsIfRel( const ScAddress
& rPos
)
169 { Ref1
.CalcAbsIfRel( rPos
); Ref2
.CalcAbsIfRel( rPos
); }
170 inline sal_Bool
IsDeleted() const
171 { return Ref1
.IsDeleted() || Ref2
.IsDeleted(); }
172 inline sal_Bool
Valid() const
173 { return Ref1
.Valid() && Ref2
.Valid(); }
174 /** In external references nTab is -1 for the start tab and -1 for the end
175 tab if one sheet, or >=0 if more than one sheets. */
176 inline bool ValidExternal() const;
178 /// Absolute references have to be up-to-date when calling this!
180 inline sal_Bool
operator==( const ScComplexRefData
& r
) const
181 { return Ref1
== r
.Ref1
&& Ref2
== r
.Ref2
; }
182 /** Enlarge range if reference passed is not within existing range.
183 ScAddress position is used to calculate absolute references from
184 relative references. */
185 ScComplexRefData
& Extend( const ScSingleRefData
& rRef
, const ScAddress
& rPos
);
186 ScComplexRefData
& Extend( const ScComplexRefData
& rRef
, const ScAddress
& rPos
);
189 inline bool ScComplexRefData::ValidExternal() const
191 return Ref1
.ValidExternal() &&
192 Ref2
.nCol
>= 0 && Ref2
.nCol
<= MAXCOL
&&
193 Ref2
.nRow
>= 0 && Ref2
.nRow
<= MAXROW
&&
194 Ref2
.nTab
>= Ref1
.nTab
;
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */