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 INCLUDED_SC_INC_REFDATA_HXX
21 #define INCLUDED_SC_INC_REFDATA_HXX
23 #include "address.hxx"
25 #include "calcmacros.hxx"
27 /// Single reference (one address) into the sheet
28 struct SC_DLLPUBLIC ScSingleRefData
37 sal_uInt8 mnFlagValue
;
46 bool bFlag3D
:1; ///< 3D-Ref
47 bool bRelName
:1; ///< Reference derived from RangeName with relative values
52 /// No default ctor, because used in ScRawToken union, set InitFlags!
53 void InitFlags() { mnFlagValue
= 0; } ///< all FALSE
54 /// InitAddress: InitFlags and set address
55 void InitAddress( const ScAddress
& rAdr
);
56 void InitAddress( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
57 /// InitAddressRel: InitFlags and set address, everything relative to rPos
58 void InitAddressRel( const ScAddress
& rAdr
, const ScAddress
& rPos
);
59 /// InitFlags and set address, relative to rPos if rRef says so.
60 void InitFromRefAddress( const ScRefAddress
& rRef
, const ScAddress
& rPos
);
61 sal_uInt8
FlagValue() const { return mnFlagValue
;}
63 void SetColRel( bool bVal
) { Flags
.bColRel
= bVal
; }
64 bool IsColRel() const { return Flags
.bColRel
; }
65 void SetRowRel( bool bVal
) { Flags
.bRowRel
= bVal
; }
66 bool IsRowRel() const { return Flags
.bRowRel
; }
67 void SetTabRel( bool bVal
) { Flags
.bTabRel
= bVal
; }
68 bool IsTabRel() const { return Flags
.bTabRel
; }
70 void SetAbsCol( SCCOL nVal
);
71 void SetRelCol( SCCOL nVal
);
72 void IncCol( SCCOL nInc
);
73 void SetAbsRow( SCROW nVal
);
74 void SetRelRow( SCROW nVal
);
75 void IncRow( SCROW nInc
);
76 void SetAbsTab( SCTAB nVal
);
77 void SetRelTab( SCTAB nVal
);
78 void IncTab( SCTAB nInc
);
80 void SetColDeleted( bool bVal
);
81 bool IsColDeleted() const { return Flags
.bColDeleted
;}
82 void SetRowDeleted( bool bVal
);
83 bool IsRowDeleted() const { return Flags
.bRowDeleted
;}
84 void SetTabDeleted( bool bVal
);
85 bool IsTabDeleted() const { return Flags
.bTabDeleted
;}
86 bool IsDeleted() const;
88 void SetFlag3D( bool bVal
) { Flags
.bFlag3D
= bVal
; }
89 bool IsFlag3D() const { return Flags
.bFlag3D
; }
90 void SetRelName( bool bVal
) { Flags
.bRelName
= bVal
; }
91 bool IsRelName() const { return Flags
.bRelName
; }
93 bool Valid(const ScDocument
* pDoc
) const;
94 bool ColValid(const ScDocument
* pDoc
) const;
95 bool RowValid(const ScDocument
* pDoc
) const;
96 bool TabValid() const;
97 /** In external references nTab is -1 if the external document was not
98 loaded but the sheet was cached, or >=0 if the external document was
100 bool ValidExternal(const ScDocument
* pDoc
) const;
102 ScAddress
toAbs( const ScAddress
& rPos
) const;
103 void SetAddress( const ScAddress
& rAddr
, const ScAddress
& rPos
);
108 /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
109 static void PutInOrder( ScSingleRefData
& rRef1
, ScSingleRefData
& rRef2
, const ScAddress
& rPos
);
111 bool operator==( const ScSingleRefData
& ) const;
112 bool operator!=( const ScSingleRefData
& ) const;
114 #if DEBUG_FORMULA_COMPILER
115 void Dump( int nIndent
= 0 ) const;
119 /// Complex reference (a range) into the sheet
120 struct ScComplexRefData
122 ScSingleRefData Ref1
;
123 ScSingleRefData Ref2
;
126 { Ref1
.InitFlags(); Ref2
.InitFlags(); }
127 void InitRange( const ScRange
& rRange
)
129 Ref1
.InitAddress( rRange
.aStart
);
130 Ref2
.InitAddress( rRange
.aEnd
);
132 void InitRangeRel( const ScRange
& rRange
, const ScAddress
& rPos
)
134 Ref1
.InitAddressRel( rRange
.aStart
, rPos
);
135 Ref2
.InitAddressRel( rRange
.aEnd
, rPos
);
137 void InitRange( SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
138 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
)
140 Ref1
.InitAddress( nCol1
, nRow1
, nTab1
);
141 Ref2
.InitAddress( nCol2
, nRow2
, nTab2
);
144 /// InitFlags and set range, relative to rPos if rRef1 and rRef2 say so.
145 void InitFromRefAddresses( const ScRefAddress
& rRef1
, const ScRefAddress
& rRef2
, const ScAddress
& rPos
);
147 bool Valid(const ScDocument
* pDoc
) const;
149 /** In external references nTab is -1 for the start tab and -1 for the end
150 tab if one sheet and the external document was not loaded but sheet was
151 cached, or >=0 also if more than one sheets. */
152 bool ValidExternal(const ScDocument
* pDoc
) const;
154 /** Whether this references entire columns, A:A */
155 bool IsEntireCol() const
157 // Both row anchors must be absolute.
158 return Ref1
.Row() == 0 && Ref2
.Row() == MAXROW
&& !Ref1
.IsRowRel() && !Ref2
.IsRowRel();
161 /** Whether this references entire rows, 1:1 */
162 bool IsEntireRow() const
164 // Both column anchors must be absolute.
165 return Ref1
.Col() == 0 && Ref2
.Col() == MAXCOL
&& !Ref1
.IsColRel() && !Ref2
.IsColRel();
168 SC_DLLPUBLIC ScRange
toAbs( const ScAddress
& rPos
) const;
170 /** Set a new range, assuming that the ordering of the range matches the
171 ordering of the reference data flags already set. */
172 void SetRange( const ScRange
& rRange
, const ScAddress
& rPos
);
174 /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
175 void PutInOrder( const ScAddress
& rPos
);
177 bool operator==( const ScComplexRefData
& r
) const
178 { return Ref1
== r
.Ref1
&& Ref2
== r
.Ref2
; }
179 /** Enlarge range if reference passed is not within existing range.
180 ScAddress position is used to calculate absolute references from
181 relative references. */
182 ScComplexRefData
& Extend( const ScSingleRefData
& rRef
, const ScAddress
& rPos
);
183 ScComplexRefData
& Extend( const ScComplexRefData
& rRef
, const ScAddress
& rPos
);
185 /** Increment or decrement end column unless or until sticky.
186 @see ScRange::IncEndColSticky()
187 @return TRUE if changed. */
188 bool IncEndColSticky( const ScDocument
* pDoc
, SCCOL nDelta
, const ScAddress
& rPos
);
190 /** Increment or decrement end row unless or until sticky.
191 @see ScRange::IncEndRowSticky()
192 @return TRUE if changed. */
193 bool IncEndRowSticky( const ScDocument
* pDoc
, SCROW nDelta
, const ScAddress
& rPos
);
195 bool IsDeleted() const;
197 #if DEBUG_FORMULA_COMPILER
198 void Dump( int nIndent
= 0 ) const;
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */