Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / tokenarray.hxx
blobb8aec07b2354e125100893ffba5f3b39616d6823
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 SC_TOKENARRAY_HXX
21 #define SC_TOKENARRAY_HXX
23 #include "formula/token.hxx"
24 #include <tools/solar.h>
25 #include "scdllapi.h"
26 #include "types.hxx"
27 #include "calcmacros.hxx"
28 #include "address.hxx"
29 #include "global.hxx"
30 #include <formula/tokenarray.hxx>
32 namespace sc {
34 struct RefUpdateContext;
35 struct RefUpdateInsertTabContext;
36 struct RefUpdateDeleteTabContext;
37 struct RefUpdateMoveTabContext;
38 struct RefUpdateResult;
39 struct TokenStringContext;
43 struct ScRawToken;
44 struct ScSingleRefData;
45 struct ScComplexRefData;
47 class 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;
56 public:
57 ScTokenArray();
58 /// Assignment with references to ScToken entries (not copied!)
59 ScTokenArray( const ScTokenArray& );
60 virtual ~ScTokenArray();
61 ScTokenArray* Clone() const; /// True copy!
63 void GenHash();
64 size_t GetHash() const;
66 ScFormulaVectorState GetVectorState() const;
68 /**
69 * If the array contains at least one relative row reference or named
70 * expression, it's variant. Otherwise invariant.
72 bool IsInvariant() const;
74 /// Exactly and only one range (valid or deleted)
75 bool IsReference( ScRange& rRange, const ScAddress& rPos ) const;
76 /// Exactly and only one valid range (no #REF!s)
77 bool IsValidReference( ScRange& rRange, const ScAddress& rPos ) const;
80 /** Determines the extent of direct adjacent
81 references. Only use with real functions, e.g.
82 GetOuterFuncOpCode() == ocSum ! */
83 bool GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend,
84 const ScAddress& rPos, ScDirection );
86 formula::FormulaToken* AddRawToken( const ScRawToken& );
87 virtual bool AddFormulaToken(const com::sun::star::sheet::FormulaToken& _aToken,formula::ExternalReferenceHelper* _pRef);
88 virtual void CheckToken( const formula::FormulaToken& r );
89 virtual formula::FormulaToken* AddOpCode( OpCode eCode );
90 /** ScSingleRefToken with ocPush. */
91 formula::FormulaToken* AddSingleReference( const ScSingleRefData& rRef );
92 /** ScSingleRefOpToken with ocMatRef. */
93 formula::FormulaToken* AddMatrixSingleReference( const ScSingleRefData& rRef );
94 formula::FormulaToken* AddDoubleReference( const ScComplexRefData& rRef );
95 formula::FormulaToken* AddRangeName( sal_uInt16 n, bool bGlobal );
96 formula::FormulaToken* AddDBRange( sal_uInt16 n );
97 formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const OUString& rName );
98 formula::FormulaToken* AddExternalSingleReference( sal_uInt16 nFileId, const OUString& rTabName, const ScSingleRefData& rRef );
99 formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const OUString& rTabName, const ScComplexRefData& rRef );
100 formula::FormulaToken* AddMatrix( const ScMatrixRef& p );
101 /** ScSingleRefOpToken with ocColRowName. */
102 formula::FormulaToken* AddColRowName( const ScSingleRefData& rRef );
103 virtual formula::FormulaToken* MergeArray( );
105 /** Merge very last SingleRef+ocRange+SingleRef combination into DoubleRef
106 and adjust pCode array, or do nothing if conditions not met.
107 Unconditionally returns last token from the resulting pCode array, or
108 NULL if there is no pCode (which actually would be caller's fault). */
109 formula::FormulaToken* MergeRangeReference( const ScAddress & rPos );
111 /// Assignment with references to ScToken entries (not copied!)
112 ScTokenArray& operator=( const ScTokenArray& );
114 /// Make 3D references point to old referenced position even if relative
115 void ReadjustRelative3DReferences(
116 const ScAddress& rOldPos,
117 const ScAddress& rNewPos );
120 * Make all absolute references external references pointing to the old document
122 * @param pOldDoc old document
123 * @param pNewDoc new document
124 * @param rPos position of the cell to determine if the reference is in the copied area
125 * @param bRangeName set for range names, range names have special handling for absolute sheet ref + relative col/row ref
127 void ReadjustAbsolute3DReferences( const ScDocument* pOldDoc, const ScDocument* pNewDoc, const ScAddress& rPos, bool bRangeName = false );
130 * Make all absolute references pointing to the copied range if the range is copied too
131 * @param bCheckCopyArea should references pointing into the copy area be adjusted independently from being absolute, should be true only for copy&paste between documents
133 void AdjustAbsoluteRefs( const ScDocument* pOldDoc, const ScAddress& rOldPos, const ScAddress& rNewPos, bool bRangeName = false, bool bCheckCopyArea = false );
136 * Adjust all references in response to shifting of cells during cell
137 * insertion and deletion.
139 * @param rCxt context that stores details of shifted region.
140 * @param rOldPos old cell position prior to shifting.
142 sc::RefUpdateResult AdjustReferenceOnShift( const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos );
144 sc::RefUpdateResult AdjustReferenceOnMove(
145 const sc::RefUpdateContext& rCxt, const ScAddress& rOldPos, const ScAddress& rNewPos );
148 * Adjust all references in named expression. In named expression, we only
149 * update absolute positions, and leave relative positions intact.
151 * @param rCxt context that stores details of shifted region
153 * @return update result.
155 sc::RefUpdateResult AdjustReferenceInName( const sc::RefUpdateContext& rCxt, const ScAddress& rPos );
158 * Adjust all references on sheet deletion.
160 * @param nDelPos position of sheet being deleted.
161 * @param nSheets number of sheets to delete.
162 * @param rOldPos position of formula cell prior to the deletion.
164 * @return true if at least one reference has changed its sheet reference.
166 sc::RefUpdateResult AdjustReferenceOnDeletedTab( sc::RefUpdateDeleteTabContext& rCxt, const ScAddress& rOldPos );
168 sc::RefUpdateResult AdjustReferenceOnInsertedTab( sc::RefUpdateInsertTabContext& rCxt, const ScAddress& rOldPos );
170 sc::RefUpdateResult AdjustReferenceOnMovedTab( sc::RefUpdateMoveTabContext& rCxt, const ScAddress& rOldPos );
172 void CheckRelativeReferenceBounds(
173 const sc::RefUpdateContext& rCxt, const ScAddress& rPos, SCROW nGroupLen, std::vector<SCROW>& rBounds ) const;
176 * Create a string representation of formula token array without modifying
177 * the internal state of the token array.
179 OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
181 #if DEBUG_FORMULA_COMPILER
182 void Dump() const;
183 #endif
186 #endif // SC_TOKENARRAY_HXX
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */