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_TOKENARRAY_HXX
21 #define INCLUDED_SC_INC_TOKENARRAY_HXX
23 #include <formula/token.hxx>
26 #include "calcmacros.hxx"
27 #include "address.hxx"
29 #include <formula/tokenarray.hxx>
33 struct RefUpdateContext
;
34 struct RefUpdateInsertTabContext
;
35 struct RefUpdateDeleteTabContext
;
36 struct RefUpdateMoveTabContext
;
37 struct RefUpdateResult
;
38 struct TokenStringContext
;
43 struct ScSingleRefData
;
44 struct ScComplexRefData
;
46 class SC_DLLPUBLIC ScTokenArray
: public formula::FormulaTokenArray
48 friend class ScCompiler
;
50 bool ImplGetReference( ScRange
& rRange
, const ScAddress
& rPos
, bool bValidOnly
) const;
53 ScFormulaVectorState meVectorState
;
57 /// Assignment with references to ScToken entries (not copied!)
58 ScTokenArray( const ScTokenArray
& );
59 virtual ~ScTokenArray();
60 ScTokenArray
* Clone() const; /// True copy!
63 size_t GetHash() const;
65 ScFormulaVectorState
GetVectorState() const;
68 * If the array contains at least one relative row reference or named
69 * expression, it's variant. Otherwise invariant.
71 bool IsInvariant() const;
73 /// Exactly and only one range (valid or deleted)
74 bool IsReference( ScRange
& rRange
, const ScAddress
& rPos
) const;
75 /// Exactly and only one valid range (no #REF!s)
76 bool IsValidReference( ScRange
& rRange
, const ScAddress
& rPos
) const;
79 /** Determines the extent of direct adjacent
80 references. Only use with real functions, e.g.
81 GetOuterFuncOpCode() == ocSum ! */
82 bool GetAdjacentExtendOfOuterFuncRefs( SCCOLROW
& nExtend
,
83 const ScAddress
& rPos
, ScDirection
);
85 formula::FormulaToken
* AddRawToken( const ScRawToken
& );
86 virtual bool AddFormulaToken(
87 const css::sheet::FormulaToken
& rToken
,
88 svl::SharedStringPool
& rSPool
,
89 formula::ExternalReferenceHelper
* _pRef
) SAL_OVERRIDE
;
90 virtual void CheckToken( const formula::FormulaToken
& r
) SAL_OVERRIDE
;
91 virtual formula::FormulaToken
* AddOpCode( OpCode eCode
) SAL_OVERRIDE
;
92 /** ScSingleRefToken with ocPush. */
93 formula::FormulaToken
* AddSingleReference( const ScSingleRefData
& rRef
);
94 /** ScSingleRefOpToken with ocMatRef. */
95 formula::FormulaToken
* AddMatrixSingleReference( const ScSingleRefData
& rRef
);
96 formula::FormulaToken
* AddDoubleReference( const ScComplexRefData
& rRef
);
97 formula::FormulaToken
* AddRangeName( sal_uInt16 n
, bool bGlobal
);
98 formula::FormulaToken
* AddDBRange( sal_uInt16 n
);
99 formula::FormulaToken
* AddExternalName( sal_uInt16 nFileId
, const OUString
& rName
);
100 formula::FormulaToken
* AddExternalSingleReference( sal_uInt16 nFileId
, const OUString
& rTabName
, const ScSingleRefData
& rRef
);
101 formula::FormulaToken
* AddExternalDoubleReference( sal_uInt16 nFileId
, const OUString
& rTabName
, const ScComplexRefData
& rRef
);
102 formula::FormulaToken
* AddMatrix( const ScMatrixRef
& p
);
103 /** ScSingleRefOpToken with ocColRowName. */
104 formula::FormulaToken
* AddColRowName( const ScSingleRefData
& rRef
);
105 virtual formula::FormulaToken
* MergeArray( ) SAL_OVERRIDE
;
107 /** Merge very last SingleRef+ocRange+SingleRef combination into DoubleRef
108 and adjust pCode array, or do nothing if conditions not met.
109 Unconditionally returns last token from the resulting pCode array, or
110 NULL if there is no pCode (which actually would be caller's fault). */
111 formula::FormulaToken
* MergeRangeReference( const ScAddress
& rPos
);
113 /// Assign XML string placeholder to the array
114 void AssignXMLString( const OUString
&rText
, const OUString
&rFormulaNmsp
);
116 /// Assignment with references to ScToken entries (not copied!)
117 ScTokenArray
& operator=( const ScTokenArray
& );
119 /// Make 3D references point to old referenced position even if relative
120 void ReadjustRelative3DReferences(
121 const ScAddress
& rOldPos
,
122 const ScAddress
& rNewPos
);
125 * Make all absolute references external references pointing to the old document
127 * @param pOldDoc old document
128 * @param pNewDoc new document
129 * @param rPos position of the cell to determine if the reference is in the copied area
130 * @param bRangeName set for range names, range names have special handling for absolute sheet ref + relative col/row ref
132 void ReadjustAbsolute3DReferences( const ScDocument
* pOldDoc
, const ScDocument
* pNewDoc
, const ScAddress
& rPos
, bool bRangeName
= false );
135 * Make all absolute references pointing to the copied range if the range is copied too
136 * @param bCheckCopyArea should references pointing into the copy area be adjusted independently from being absolute, should be true only for copy&paste between documents
138 void AdjustAbsoluteRefs( const ScDocument
* pOldDoc
, const ScAddress
& rOldPos
, const ScAddress
& rNewPos
, bool bRangeName
= false, bool bCheckCopyArea
= false );
141 * Adjust all references in response to shifting of cells during cell
142 * insertion and deletion.
144 * @param rCxt context that stores details of shifted region.
145 * @param rOldPos old cell position prior to shifting.
147 sc::RefUpdateResult
AdjustReferenceOnShift( const sc::RefUpdateContext
& rCxt
, const ScAddress
& rOldPos
);
149 sc::RefUpdateResult
AdjustReferenceOnMove(
150 const sc::RefUpdateContext
& rCxt
, const ScAddress
& rOldPos
, const ScAddress
& rNewPos
);
153 * Move reference positions that are within specified moved range.
155 * @param rPos position of this formula cell
156 * @param rMovedRange range that has been moved.
157 * @param rDelta movement vector.
160 const ScAddress
& rPos
, const ScRange
& rMovedRange
, const ScAddress
& rDelta
);
163 * Move reference positions in response to column reordering. A range
164 * reference gets moved only when the whole range fits in a single column.
166 * @param rPos position of this formula cell
167 * @param nTab sheet where columns are reordered.
168 * @param nRow1 top row of reordered range.
169 * @param nRow2 bottom row of reordered range.
170 * @param rColMap old-to-new column mapping.
172 void MoveReferenceColReorder(
173 const ScAddress
& rPos
, SCTAB nTab
, SCROW nRow1
, SCROW nRow2
,
174 const sc::ColRowReorderMapType
& rColMap
);
176 void MoveReferenceRowReorder(
177 const ScAddress
& rPos
, SCTAB nTab
, SCCOL nCol1
, SCCOL nCol2
,
178 const sc::ColRowReorderMapType
& rRowMap
);
181 * Adjust all references in named expression. In named expression, we only
182 * update absolute positions, and leave relative positions intact.
184 * @param rCxt context that stores details of shifted region
186 * @return update result.
188 sc::RefUpdateResult
AdjustReferenceInName( const sc::RefUpdateContext
& rCxt
, const ScAddress
& rPos
);
190 sc::RefUpdateResult
AdjustReferenceInMovedName( const sc::RefUpdateContext
& rCxt
, const ScAddress
& rPos
);
193 * Adjust all references on sheet deletion.
195 * @param nDelPos position of sheet being deleted.
196 * @param nSheets number of sheets to delete.
197 * @param rOldPos position of formula cell prior to the deletion.
199 * @return true if at least one reference has changed its sheet reference.
201 sc::RefUpdateResult
AdjustReferenceOnDeletedTab( sc::RefUpdateDeleteTabContext
& rCxt
, const ScAddress
& rOldPos
);
203 sc::RefUpdateResult
AdjustReferenceOnInsertedTab( sc::RefUpdateInsertTabContext
& rCxt
, const ScAddress
& rOldPos
);
205 sc::RefUpdateResult
AdjustReferenceOnMovedTab( sc::RefUpdateMoveTabContext
& rCxt
, const ScAddress
& rOldPos
);
208 * Adjust all internal references on base position change.
210 void AdjustReferenceOnMovedOrigin( const ScAddress
& rOldPos
, const ScAddress
& rNewPos
);
213 * Adjust all internal references on base position change if they point to
214 * a sheet other than the one of rOldPos.
216 void AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress
& rOldPos
, const ScAddress
& rNewPos
);
219 * Clear sheet deleted flag from internal reference tokens if the sheet
220 * index falls within specified range. Note that when a reference is on a
221 * sheet that's been deleted, its referenced sheet index retains the
222 * original index of the deleted sheet.
224 * @param rPos position of formula cell
225 * @param nStartTab index of first sheet, inclusive.
226 * @param nEndTab index of last sheet, inclusive.
228 void ClearTabDeleted( const ScAddress
& rPos
, SCTAB nStartTab
, SCTAB nEndTab
);
230 void CheckRelativeReferenceBounds(
231 const sc::RefUpdateContext
& rCxt
, const ScAddress
& rPos
, SCROW nGroupLen
, std::vector
<SCROW
>& rBounds
) const;
233 void CheckRelativeReferenceBounds(
234 const ScAddress
& rPos
, SCROW nGroupLen
, const ScRange
& rRange
, std::vector
<SCROW
>& rBounds
) const;
236 void CheckExpandReferenceBounds(
237 const sc::RefUpdateContext
& rCxt
, const ScAddress
& rPos
, SCROW nGroupLen
, std::vector
<SCROW
>& rBounds
) const;
240 * Create a string representation of formula token array without modifying
241 * the internal state of the token array.
243 OUString
CreateString( sc::TokenStringContext
& rCxt
, const ScAddress
& rPos
) const;
245 void WrapReference( const ScAddress
& rPos
, SCCOL nMaxCol
, SCROW nMaxRow
);
247 #if DEBUG_FORMULA_COMPILER
252 #endif // INCLUDED_SC_INC_TOKENARRAY_HXX
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */