nss: upgrade to release 3.73
[LibreOffice.git] / sc / inc / refdata.hxx
blob7674794a9a80b18ce3eec7fadb2dfb858a08955b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 #include "scdllapi.h"
25 #include "calcmacros.hxx"
27 struct ScSheetLimits;
29 /// Single reference (one address) into the sheet
30 struct SC_DLLPUBLIC ScSingleRefData
32 private:
33 SCCOL mnCol;
34 SCROW mnRow;
35 SCTAB mnTab;
37 union
39 sal_uInt8 mnFlagValue;
40 struct
42 bool bColRel :1;
43 bool bColDeleted :1;
44 bool bRowRel :1;
45 bool bRowDeleted :1;
46 bool bTabRel :1;
47 bool bTabDeleted :1;
48 bool bFlag3D :1; ///< 3D-Ref
49 bool bRelName :1; ///< Reference derived from RangeName with relative values
50 } Flags;
53 public:
54 /// No default ctor, because used in ScRawToken union, set InitFlags!
55 void InitFlags() { mnFlagValue = 0; } ///< all FALSE
56 /// InitAddress: InitFlags and set address
57 void InitAddress( const ScAddress& rAdr );
58 void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab );
59 /// InitAddressRel: InitFlags and set address, everything relative to rPos
60 void InitAddressRel( const ScDocument& rDoc, const ScAddress& rAdr, const ScAddress& rPos );
61 /// InitFlags and set address, relative to rPos if rRef says so.
62 void InitFromRefAddress( const ScDocument& rDoc, const ScRefAddress& rRef, const ScAddress& rPos );
63 sal_uInt8 FlagValue() const { return mnFlagValue;}
65 void SetColRel( bool bVal ) { Flags.bColRel = bVal; }
66 bool IsColRel() const { return Flags.bColRel; }
67 void SetRowRel( bool bVal ) { Flags.bRowRel = bVal; }
68 bool IsRowRel() const { return Flags.bRowRel; }
69 void SetTabRel( bool bVal ) { Flags.bTabRel = bVal; }
70 bool IsTabRel() const { return Flags.bTabRel; }
72 void SetAbsCol( SCCOL nVal );
73 void SetRelCol( SCCOL nVal );
74 void IncCol( SCCOL nInc );
75 void SetAbsRow( SCROW nVal );
76 void SetRelRow( SCROW nVal );
77 void IncRow( SCROW nInc );
78 void SetAbsTab( SCTAB nVal );
79 void SetRelTab( SCTAB nVal );
80 void IncTab( SCTAB nInc );
82 void SetColDeleted( bool bVal );
83 bool IsColDeleted() const { return Flags.bColDeleted;}
84 void SetRowDeleted( bool bVal );
85 bool IsRowDeleted() const { return Flags.bRowDeleted;}
86 void SetTabDeleted( bool bVal );
87 bool IsTabDeleted() const { return Flags.bTabDeleted;}
88 bool IsDeleted() const;
90 void SetFlag3D( bool bVal ) { Flags.bFlag3D = bVal; }
91 bool IsFlag3D() const { return Flags.bFlag3D; }
92 void SetRelName( bool bVal ) { Flags.bRelName = bVal; }
93 bool IsRelName() const { return Flags.bRelName; }
95 bool Valid(const ScDocument& rDoc) const;
96 bool ColValid(const ScDocument& rDoc) const;
97 bool RowValid(const ScDocument& rDoc) const;
98 bool TabValid() const;
99 /** In external references nTab is -1 if the external document was not
100 loaded but the sheet was cached, or >=0 if the external document was
101 loaded. */
102 bool ValidExternal(const ScDocument& rDoc) const;
104 ScAddress toAbs( const ScSheetLimits& rLimits, const ScAddress& rPos ) const;
105 ScAddress toAbs( const ScDocument& rDoc, const ScAddress& rPos ) const;
106 void SetAddress( const ScSheetLimits& rLimits, const ScAddress& rAddr, const ScAddress& rPos );
107 SCROW Row() const;
108 SCCOL Col() const;
109 SCTAB Tab() const;
111 /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
112 static void PutInOrder( ScSingleRefData& rRef1, ScSingleRefData& rRef2, const ScAddress& rPos );
114 bool operator==( const ScSingleRefData& ) const;
115 bool operator!=( const ScSingleRefData& ) const;
117 #if DEBUG_FORMULA_COMPILER
118 void Dump( int nIndent = 0 ) const;
119 #endif
122 /// Complex reference (a range) into the sheet
123 struct ScComplexRefData
125 ScSingleRefData Ref1;
126 ScSingleRefData Ref2;
127 bool bTrimToData = false;
129 void InitFlags()
130 { Ref1.InitFlags(); Ref2.InitFlags(); }
131 void InitRange( const ScRange& rRange )
133 Ref1.InitAddress( rRange.aStart );
134 Ref2.InitAddress( rRange.aEnd );
136 void InitRangeRel( const ScDocument& rDoc, const ScRange& rRange, const ScAddress& rPos )
138 Ref1.InitAddressRel( rDoc, rRange.aStart, rPos );
139 Ref2.InitAddressRel( rDoc, rRange.aEnd, rPos );
141 void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
142 SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
144 Ref1.InitAddress( nCol1, nRow1, nTab1 );
145 Ref2.InitAddress( nCol2, nRow2, nTab2 );
148 /// InitFlags and set range, relative to rPos if rRef1 and rRef2 say so.
149 void InitFromRefAddresses( const ScDocument& rDoc, const ScRefAddress& rRef1, const ScRefAddress& rRef2, const ScAddress& rPos );
151 bool Valid(const ScDocument& rDoc) const;
153 /** In external references nTab is -1 for the start tab and -1 for the end
154 tab if one sheet and the external document was not loaded but sheet was
155 cached, or >=0 also if more than one sheets. */
156 bool ValidExternal(const ScDocument& rDoc) const;
158 /** Whether this references entire columns, A:A */
159 bool IsEntireCol() const
161 // Both row anchors must be absolute.
162 return Ref1.Row() == 0 && Ref2.Row() == MAXROW && !Ref1.IsRowRel() && !Ref2.IsRowRel();
165 /** Whether this references entire rows, 1:1 */
166 bool IsEntireRow() const
168 // Both column anchors must be absolute.
169 return Ref1.Col() == 0 && Ref2.Col() == MAXCOL && !Ref1.IsColRel() && !Ref2.IsColRel();
172 SC_DLLPUBLIC ScRange toAbs( const ScSheetLimits& rLimits, const ScAddress& rPos ) const;
173 SC_DLLPUBLIC ScRange toAbs( const ScDocument& rDoc, const ScAddress& rPos ) const;
175 /** Set a new range, assuming that the ordering of the range matches the
176 ordering of the reference data flags already set. */
177 void SetRange( const ScSheetLimits& rLimits, const ScRange& rRange, const ScAddress& rPos );
179 /** Adjust ordering (front-top-left/rear-bottom-right) to a new position. */
180 void PutInOrder( const ScAddress& rPos );
182 bool operator==( const ScComplexRefData& r ) const
183 { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
184 /** Enlarge range if reference passed is not within existing range.
185 ScAddress position is used to calculate absolute references from
186 relative references. */
187 ScComplexRefData& Extend( const ScSheetLimits& rLimits, const ScSingleRefData & rRef, const ScAddress & rPos );
188 ScComplexRefData& Extend( const ScSheetLimits& rLimits, const ScComplexRefData & rRef, const ScAddress & rPos );
190 /** Increment or decrement end column unless or until sticky.
191 @see ScRange::IncEndColSticky()
192 @return TRUE if changed. */
193 bool IncEndColSticky( const ScDocument& rDoc, SCCOL nDelta, const ScAddress& rPos );
195 /** Increment or decrement end row unless or until sticky.
196 @see ScRange::IncEndRowSticky()
197 @return TRUE if changed. */
198 bool IncEndRowSticky( const ScDocument& rDoc, SCROW nDelta, const ScAddress& rPos );
200 bool IsDeleted() const;
202 bool IsTrimToData() const { return bTrimToData; }
203 void SetTrimToData(bool bSet) { bTrimToData = bSet; }
205 #if DEBUG_FORMULA_COMPILER
206 void Dump( int nIndent = 0 ) const;
207 #endif
210 #endif
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */