tdf#125181 maxY is 50000 in prstGeom for star24 and star32
[LibreOffice.git] / sc / inc / tokenarray.hxx
blobe0237000c0ed4065609760ed4cb385b0700f0275
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_TOKENARRAY_HXX
21 #define INCLUDED_SC_INC_TOKENARRAY_HXX
23 #include <formula/token.hxx>
24 #include "scdllapi.h"
25 #include "types.hxx"
26 #include "calcmacros.hxx"
27 #include "address.hxx"
28 #include "global.hxx"
29 #include <formula/tokenarray.hxx>
31 namespace sc {
33 struct RefUpdateContext;
34 struct RefUpdateInsertTabContext;
35 struct RefUpdateDeleteTabContext;
36 struct RefUpdateMoveTabContext;
37 struct RefUpdateResult;
38 struct TokenStringContext;
39 class ColRowReorderMapType;
43 struct ScRawToken;
44 struct ScSingleRefData;
45 struct ScComplexRefData;
47 class SAL_WARN_UNUSED SC_DLLPUBLIC ScTokenArray : public formula::FormulaTokenArray
49 friend class ScCompiler;
51 bool ImplGetReference( ScRange& rRange, const ScAddress& rPos, bool bValidOnly ) const;
53 size_t mnHashValue;
54 ScFormulaVectorState meVectorState : 4; // Only 4 bits
55 bool mbOpenCLEnabled : 1;
56 bool mbThreadingEnabled : 1;
58 void CheckForThreading( const formula::FormulaToken& r );
60 public:
61 ScTokenArray();
62 /** Assignment with incrementing references of FormulaToken entries
63 (not copied!) */
64 ScTokenArray( const ScTokenArray& ) = default;
65 virtual ~ScTokenArray() override;
67 bool EqualTokens( const ScTokenArray* pArr2 ) const;
69 virtual void Clear() override;
70 std::unique_ptr<ScTokenArray> Clone() const; /// True copy!
72 void GenHash();
73 size_t GetHash() const { return mnHashValue;}
75 ScFormulaVectorState GetVectorState() const { return meVectorState;}
76 void ResetVectorState();
77 bool IsFormulaVectorDisabled() const;
79 /**
80 * If the array contains at least one relative row reference or named
81 * expression, it's variant. Otherwise invariant.
83 bool IsInvariant() const;
85 /// Exactly and only one range (valid or deleted)
86 bool IsReference( ScRange& rRange, const ScAddress& rPos ) const;
87 /// Exactly and only one valid range (no #REF!s)
88 bool IsValidReference( ScRange& rRange, const ScAddress& rPos ) const;
90 /** Determines the extent of direct adjacent
91 references. Only use with real functions, e.g.
92 GetOuterFuncOpCode() == ocSum ! */
93 bool GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend,
94 const ScAddress& rPos, ScDirection );
96 formula::FormulaToken* AddRawToken( const ScRawToken& );
97 virtual bool AddFormulaToken(
98 const css::sheet::FormulaToken& rToken,
99 svl::SharedStringPool& rSPool,
100 formula::ExternalReferenceHelper* _pRef) override;
101 virtual void CheckToken( const formula::FormulaToken& r ) override;
102 virtual formula::FormulaToken* AddOpCode( OpCode eCode ) override;
103 /** ScSingleRefToken with ocPush. */
104 formula::FormulaToken* AddSingleReference( const ScSingleRefData& rRef );
105 /** ScSingleRefOpToken with ocMatRef. */
106 formula::FormulaToken* AddMatrixSingleReference( const ScSingleRefData& rRef );
107 formula::FormulaToken* AddDoubleReference( const ScComplexRefData& rRef );
108 void AddRangeName( sal_uInt16 n, sal_Int16 nSheet );
109 formula::FormulaToken* AddDBRange( sal_uInt16 n );
110 formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const svl::SharedString& rName );
111 void AddExternalSingleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScSingleRefData& rRef );
112 formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScComplexRefData& rRef );
113 formula::FormulaToken* AddMatrix( const ScMatrixRef& p );
114 /** ScSingleRefOpToken with ocColRowName. */
115 formula::FormulaToken* AddColRowName( const ScSingleRefData& rRef );
116 virtual formula::FormulaToken* MergeArray( ) override;
118 /** Merge very last SingleRef+ocRange+SingleRef combination into DoubleRef
119 and adjust pCode array, or do nothing if conditions not met. */
120 void MergeRangeReference( const ScAddress & rPos );
122 /// Assign XML string placeholder to the array
123 void AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp );
125 /** Assignment with incrementing references of FormulaToken entries
126 (not copied!) */
127 ScTokenArray& operator=( const ScTokenArray& );
130 * Make all absolute references external references pointing to the old document
132 * @param pOldDoc old document
133 * @param pNewDoc new document
134 * @param rPos position of the cell to determine if the reference is in the copied area
135 * @param bRangeName set for range names, range names have special handling for absolute sheet ref + relative col/row ref
137 void ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName = false );
140 * Make all absolute references pointing to the copied range if the range is copied too
141 * @param bCheckCopyArea should references pointing into the copy area be adjusted independently from being absolute, should be true only for copy&paste between documents
143 void AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bCheckCopyArea );
145 /** When copying a sheet-local named expression, move sheet references that
146 point to the originating sheet to point to the new sheet instead.
148 void AdjustSheetLocalNameReferences( SCTAB nOldTab, SCTAB nNewTab );
150 /** Returns true if the sheet nTab is referenced in code. Relative sheet
151 references are evaluated using nPosTab.
153 bool ReferencesSheet( SCTAB nTab, SCTAB nPosTab ) const;
156 * Adjust all references in response to shifting of cells during cell
157 * insertion and deletion.
159 * @param rCxt context that stores details of shifted region.
160 * @param rOldPos old cell position prior to shifting.
162 sc::RefUpdateResult AdjustReferenceOnShift( const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos );
164 sc::RefUpdateResult AdjustReferenceOnMove(
165 const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos, const ScAddress& rNewPos );
168 * Move reference positions in response to column reordering. A range
169 * reference gets moved only when the whole range fits in a single column.
171 * @param rPos position of this formula cell
172 * @param nTab sheet where columns are reordered.
173 * @param nRow1 top row of reordered range.
174 * @param nRow2 bottom row of reordered range.
175 * @param rColMap old-to-new column mapping.
177 void MoveReferenceColReorder(
178 const ScAddress& rPos, SCTAB nTab, SCROW nRow1, SCROW nRow2,
179 const sc::ColRowReorderMapType& rColMap );
181 void MoveReferenceRowReorder(
182 const ScAddress& rPos, SCTAB nTab, SCCOL nCol1, SCCOL nCol2,
183 const sc::ColRowReorderMapType& rRowMap );
186 * Adjust all references in named expression. In named expression, we only
187 * update absolute positions, and leave relative positions intact.
189 * @param rCxt context that stores details of shifted region
191 * @return update result.
193 sc::RefUpdateResult AdjustReferenceInName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
195 sc::RefUpdateResult AdjustReferenceInMovedName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
198 * Adjust all references on sheet deletion.
200 * @param nDelPos position of sheet being deleted.
201 * @param nSheets number of sheets to delete.
202 * @param rOldPos position of formula cell prior to the deletion.
204 * @return true if at least one reference has changed its sheet reference.
206 sc::RefUpdateResult AdjustReferenceOnDeletedTab( const sc::RefUpdateDeleteTabContext& rCxt, const ScAddress& rOldPos );
208 sc::RefUpdateResult AdjustReferenceOnInsertedTab( const sc::RefUpdateInsertTabContext& rCxt, const ScAddress& rOldPos );
210 sc::RefUpdateResult AdjustReferenceOnMovedTab( const sc::RefUpdateMoveTabContext& rCxt, const ScAddress& rOldPos );
213 * Adjust all internal references on base position change.
215 void AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const ScAddress& rNewPos );
218 * Adjust all internal references on base position change if they point to
219 * a sheet other than the one of rOldPos.
221 void AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rOldPos, const ScAddress& rNewPos );
224 * Adjust internal range references on base position change to justify /
225 * put in order the relative references.
227 void AdjustReferenceOnCopy( const ScAddress& rNewPos );
230 * Clear sheet deleted flag from internal reference tokens if the sheet
231 * index falls within specified range. Note that when a reference is on a
232 * sheet that's been deleted, its referenced sheet index retains the
233 * original index of the deleted sheet.
235 * @param rPos position of formula cell
236 * @param nStartTab index of first sheet, inclusive.
237 * @param nEndTab index of last sheet, inclusive.
239 void ClearTabDeleted( const ScAddress& rPos, SCTAB nStartTab, SCTAB nEndTab );
241 void CheckRelativeReferenceBounds(
242 const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
244 void CheckRelativeReferenceBounds(
245 const ScAddress& rPos, SCROW nGroupLen, const ScRange& rRange, std::vector<SCROW>& rBounds ) const;
247 void CheckExpandReferenceBounds(
248 const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
251 * Create a string representation of formula token array without modifying
252 * the internal state of the token array.
254 OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
256 void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow );
257 bool NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const;
259 sal_Int32 GetWeight() const;
261 bool IsEnabledForOpenCL() const { return mbOpenCLEnabled; }
262 bool IsEnabledForThreading() const { return mbThreadingEnabled; }
264 #if DEBUG_FORMULA_COMPILER
265 void Dump() const;
266 #endif
269 #endif // INCLUDED_SC_INC_TOKENARRAY_HXX
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */