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
24 #include "address.hxx"
26 #include "calcmacros.hxx"
28 /// Single reference (one address) into the sheet
29 struct SC_DLLPUBLIC ScSingleRefData
38 sal_uInt8 mnFlagValue
;
47 bool bFlag3D
:1; ///< 3D-Ref
48 bool bRelName
:1; ///< Reference derived from RangeName with relative values
53 /// No default ctor, because used in ScRawToken union, set InitFlags!
54 void InitFlags() { mnFlagValue
= 0; } ///< all FALSE
55 /// InitAddress: InitFlags and set address
56 void InitAddress( const ScAddress
& rAdr
);
57 void InitAddress( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
58 /// InitAddressRel: InitFlags and set address, everything relative to rPos
59 void InitAddressRel( const ScAddress
& rAdr
, const ScAddress
& rPos
);
60 /// InitFlags and set address, relative to rPos if rRef says so.
61 void InitFromRefAddress( const ScRefAddress
& rRef
, const ScAddress
& rPos
);
62 sal_uInt8
FlagValue() const { return mnFlagValue
;}
64 void SetColRel( bool bVal
) { Flags
.bColRel
= bVal
; }
65 bool IsColRel() const { return Flags
.bColRel
; }
66 void SetRowRel( bool bVal
) { Flags
.bRowRel
= bVal
; }
67 bool IsRowRel() const { return Flags
.bRowRel
; }
68 void SetTabRel( bool bVal
) { Flags
.bTabRel
= bVal
; }
69 bool IsTabRel() const { return Flags
.bTabRel
; }
71 void SetAbsCol( SCCOL nVal
);
72 void SetRelCol( SCCOL nVal
);
73 void IncCol( SCCOL nInc
);
74 void SetAbsRow( SCROW nVal
);
75 void SetRelRow( SCROW nVal
);
76 void IncRow( SCROW nInc
);
77 void SetAbsTab( SCTAB nVal
);
78 void SetRelTab( SCTAB nVal
);
79 void IncTab( SCTAB nInc
);
81 void SetColDeleted( bool bVal
);
82 bool IsColDeleted() const { return Flags
.bColDeleted
;}
83 void SetRowDeleted( bool bVal
);
84 bool IsRowDeleted() const { return Flags
.bRowDeleted
;}
85 void SetTabDeleted( bool bVal
);
86 bool IsTabDeleted() const { return Flags
.bTabDeleted
;}
87 bool IsDeleted() const;
89 void SetFlag3D( bool bVal
) { Flags
.bFlag3D
= bVal
; }
90 bool IsFlag3D() const { return Flags
.bFlag3D
; }
91 void SetRelName( bool bVal
) { Flags
.bRelName
= bVal
; }
92 bool IsRelName() const { return Flags
.bRelName
; }
95 bool ColValid() const;
96 bool RowValid() const;
97 bool TabValid() const;
98 /// In external references nTab is -1
99 bool ValidExternal() const;
101 ScAddress
toAbs( const ScAddress
& rPos
) const;
102 void SetAddress( const ScAddress
& rAddr
, const ScAddress
& rPos
);
107 /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
108 static void PutInOrder( ScSingleRefData
& rRef1
, ScSingleRefData
& rRef2
, const ScAddress
& rPos
);
110 bool operator==( const ScSingleRefData
& ) const;
111 bool operator!=( const ScSingleRefData
& ) const;
113 #if DEBUG_FORMULA_COMPILER
114 void Dump( int nIndent
= 0 ) const;
118 /// Complex reference (a range) into the sheet
119 struct ScComplexRefData
121 ScSingleRefData Ref1
;
122 ScSingleRefData Ref2
;
125 { Ref1
.InitFlags(); Ref2
.InitFlags(); }
126 void InitRange( const ScRange
& rRange
)
128 Ref1
.InitAddress( rRange
.aStart
);
129 Ref2
.InitAddress( rRange
.aEnd
);
131 void InitRangeRel( const ScRange
& rRange
, const ScAddress
& rPos
)
133 Ref1
.InitAddressRel( rRange
.aStart
, rPos
);
134 Ref2
.InitAddressRel( rRange
.aEnd
, rPos
);
136 void InitRange( SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
137 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
)
139 Ref1
.InitAddress( nCol1
, nRow1
, nTab1
);
140 Ref2
.InitAddress( nCol2
, nRow2
, nTab2
);
143 /// InitFlags and set range, relative to rPos if rRef1 and rRef2 say so.
144 void InitFromRefAddresses( const ScRefAddress
& rRef1
, const ScRefAddress
& rRef2
, const ScAddress
& rPos
);
148 /** In external references nTab is -1 for the start tab and -1 for the end
149 tab if one sheet, or >=0 if more than one sheets. */
150 bool ValidExternal() const;
152 /** Whether this references entire columns, A:A */
153 bool IsEntireCol() const
155 // Both row anchors must be absolute.
156 return Ref1
.Row() == 0 && Ref2
.Row() == MAXROW
&& !Ref1
.IsRowRel() && !Ref2
.IsRowRel();
159 /** Whether this references entire rows, 1:1 */
160 bool IsEntireRow() const
162 // Both column anchors must be absolute.
163 return Ref1
.Col() == 0 && Ref2
.Col() == MAXCOL
&& !Ref1
.IsColRel() && !Ref2
.IsColRel();
166 SC_DLLPUBLIC ScRange
toAbs( const ScAddress
& rPos
) const;
168 /** Set a new range, assuming that the ordering of the range matches the
169 ordering of the reference data flags already set. */
170 void SetRange( const ScRange
& rRange
, const ScAddress
& rPos
);
172 /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
173 void PutInOrder( const ScAddress
& rPos
);
175 bool operator==( const ScComplexRefData
& r
) const
176 { return Ref1
== r
.Ref1
&& Ref2
== r
.Ref2
; }
177 /** Enlarge range if reference passed is not within existing range.
178 ScAddress position is used to calculate absolute references from
179 relative references. */
180 ScComplexRefData
& Extend( const ScSingleRefData
& rRef
, const ScAddress
& rPos
);
181 ScComplexRefData
& Extend( const ScComplexRefData
& rRef
, const ScAddress
& rPos
);
183 /** Increment or decrement end column unless or until sticky.
184 @see ScRange::IncEndColSticky()
185 @return TRUE if changed. */
186 bool IncEndColSticky( SCCOL nDelta
, const ScAddress
& rPos
);
188 /** Increment or decrement end row unless or until sticky.
189 @see ScRange::IncEndRowSticky()
190 @return TRUE if changed. */
191 bool IncEndRowSticky( SCROW nDelta
, const ScAddress
& rPos
);
193 bool IsDeleted() const;
195 #if DEBUG_FORMULA_COMPILER
196 void Dump( int nIndent
= 0 ) const;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */