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 void SmartRelAbs( const ScAddress
& rPos
);
95 void CalcRelFromAbs( const ScAddress
& rPos
);
96 void CalcAbsIfRel( const ScAddress
& rPos
);
97 sal_Bool
operator==( const ScSingleRefData
& ) const;
98 bool operator!=( const ScSingleRefData
& ) const;
101 inline void ScSingleRefData::InitAddress( SCCOL nColP
, SCROW nRowP
, SCTAB nTabP
)
109 inline void ScSingleRefData::InitAddress( const ScAddress
& rAdr
)
111 InitAddress( rAdr
.Col(), rAdr
.Row(), rAdr
.Tab());
114 inline void ScSingleRefData::InitAddressRel( const ScAddress
& rAdr
,
115 const ScAddress
& rPos
)
117 InitAddress( rAdr
.Col(), rAdr
.Row(), rAdr
.Tab());
118 SetColRel( sal_True
);
119 SetRowRel( sal_True
);
120 SetTabRel( sal_True
);
121 CalcRelFromAbs( rPos
);
124 inline sal_Bool
ScSingleRefData::Valid() const
126 return nCol
>= 0 && nCol
<= MAXCOL
&&
127 nRow
>= 0 && nRow
<= MAXROW
&&
128 nTab
>= 0 && nTab
<= MAXTAB
;
131 inline bool ScSingleRefData::ValidExternal() const
133 return nCol
>= 0 && nCol
<= MAXCOL
&&
134 nRow
>= 0 && nRow
<= MAXROW
&&
139 struct ScComplexRefData
// Complex reference (a range) into the sheet
141 ScSingleRefData Ref1
;
142 ScSingleRefData Ref2
;
144 inline void InitFlags()
145 { Ref1
.InitFlags(); Ref2
.InitFlags(); }
146 inline void InitRange( const ScRange
& rRange
)
148 Ref1
.InitAddress( rRange
.aStart
);
149 Ref2
.InitAddress( rRange
.aEnd
);
151 inline void InitRangeRel( const ScRange
& rRange
, const ScAddress
& rPos
)
153 Ref1
.InitAddressRel( rRange
.aStart
, rPos
);
154 Ref2
.InitAddressRel( rRange
.aEnd
, rPos
);
156 inline void InitRange( SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
157 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
)
159 Ref1
.InitAddress( nCol1
, nRow1
, nTab1
);
160 Ref2
.InitAddress( nCol2
, nRow2
, nTab2
);
162 inline void SmartRelAbs( const ScAddress
& rPos
)
163 { Ref1
.SmartRelAbs( rPos
); Ref2
.SmartRelAbs( rPos
); }
164 inline void CalcRelFromAbs( const ScAddress
& rPos
)
165 { Ref1
.CalcRelFromAbs( rPos
); Ref2
.CalcRelFromAbs( rPos
); }
166 inline void CalcAbsIfRel( const ScAddress
& rPos
)
167 { Ref1
.CalcAbsIfRel( rPos
); Ref2
.CalcAbsIfRel( rPos
); }
168 inline sal_Bool
IsDeleted() const
169 { return Ref1
.IsDeleted() || Ref2
.IsDeleted(); }
170 inline sal_Bool
Valid() const
171 { return Ref1
.Valid() && Ref2
.Valid(); }
172 /** In external references nTab is -1 for the start tab and -1 for the end
173 tab if one sheet, or >=0 if more than one sheets. */
174 inline bool ValidExternal() const;
176 /// Absolute references have to be up-to-date when calling this!
178 inline sal_Bool
operator==( const ScComplexRefData
& r
) const
179 { return Ref1
== r
.Ref1
&& Ref2
== r
.Ref2
; }
180 /** Enlarge range if reference passed is not within existing range.
181 ScAddress position is used to calculate absolute references from
182 relative references. */
183 ScComplexRefData
& Extend( const ScSingleRefData
& rRef
, const ScAddress
& rPos
);
184 ScComplexRefData
& Extend( const ScComplexRefData
& rRef
, const ScAddress
& rPos
);
187 inline bool ScComplexRefData::ValidExternal() const
189 return Ref1
.ValidExternal() &&
190 Ref2
.nCol
>= 0 && Ref2
.nCol
<= MAXCOL
&&
191 Ref2
.nRow
>= 0 && Ref2
.nRow
<= MAXROW
&&
192 Ref2
.nTab
>= Ref1
.nTab
;
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */