Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / refupdatecontext.hxx
blob7789dfdc3a9e0d99fa210e347c3ac504a1b4971b
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/.
8 */
10 #pragma once
12 #include "global.hxx"
13 #include "address.hxx"
14 #include "columnset.hxx"
16 #include <unordered_map>
17 #include <unordered_set>
19 class ScDocument;
21 namespace sc
23 struct ColumnBlockPosition;
24 class ColumnBlockPositionSet;
26 /**
27 * Keep track of all named expressions that have been updated during
28 * reference update.
30 * Can also be used to collect any set of named expressions / ranges.
32 class UpdatedRangeNames
34 public:
35 typedef std::unordered_set<sal_uInt16> NameIndicesType;
37 void setUpdatedName(SCTAB nTab, sal_uInt16 nIndex);
38 bool isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const;
39 NameIndicesType getUpdatedNames(SCTAB nTab) const;
40 bool isEmpty(SCTAB nTab) const;
42 private:
43 typedef std::unordered_map<SCTAB, NameIndicesType> UpdatedNamesType;
45 UpdatedNamesType maUpdatedNames;
48 /**
49 * Context for reference update during shifting, moving or copying of cell
50 * ranges.
52 struct RefUpdateContext
54 ScDocument& mrDoc;
56 /**
57 * update mode - insert/delete, copy, or move. The reorder mode (which
58 * corresponds with the reordering of sheets) is not used with this
59 * context.
61 UpdateRefMode meMode;
63 /**
64 * Range of cells that are about to be moved for insert/delete/move modes.
65 * For copy mode, it's the destination range of cells that are about to be
66 * pasted. When moving a range of cells, it's the destination range, not
67 * the source range.
69 ScRange maRange;
71 /** Are the data transposed? */
72 bool mbTransposed;
74 /** Amount and direction of movement in the column direction. */
75 SCCOL mnColDelta;
76 /** Amount and direction of movement in the row direction. */
77 SCROW mnRowDelta;
78 /** Amount and direction of movement in the sheet direction. */
79 SCTAB mnTabDelta;
81 UpdatedRangeNames maUpdatedNames;
82 ColumnSet maRegroupCols;
84 ColumnBlockPositionSet* mpBlockPos; // not owning
86 RefUpdateContext(ScDocument& rDoc, ScDocument* pClipdoc = nullptr);
88 bool isInserted() const;
89 bool isDeleted() const;
91 void setBlockPositionReference(ColumnBlockPositionSet* blockPos);
92 ColumnBlockPosition* getBlockPosition(SCTAB nTab, SCCOL nCol);
95 struct RefUpdateResult
97 /**
98 * When this flag is true, the result of the formula needs to be
99 * re-calculated either because it contains a reference that's been
100 * deleted, or the size of a range reference has changed.
102 bool mbValueChanged;
105 * This flag indicates whether any reference in the token array has been
106 * modified.
108 bool mbReferenceModified;
111 * When this flag is true, it indicates that the token array contains a
112 * range name that's been updated.
114 bool mbNameModified;
116 SCTAB mnTab;
118 RefUpdateResult();
121 struct SC_DLLPUBLIC RefUpdateInsertTabContext
123 ScDocument& mrDoc;
124 SCTAB mnInsertPos;
125 SCTAB mnSheets;
126 UpdatedRangeNames maUpdatedNames;
128 RefUpdateInsertTabContext(ScDocument& rDoc, SCTAB nInsertPos, SCTAB nSheets);
131 struct SC_DLLPUBLIC RefUpdateDeleteTabContext
133 ScDocument& mrDoc;
134 SCTAB mnDeletePos;
135 SCTAB mnSheets;
136 UpdatedRangeNames maUpdatedNames;
138 RefUpdateDeleteTabContext(ScDocument& rDoc, SCTAB nInsertPos, SCTAB nSheets);
141 struct RefUpdateMoveTabContext
143 ScDocument& mrDoc;
144 SCTAB mnOldPos;
145 SCTAB mnNewPos;
146 UpdatedRangeNames maUpdatedNames;
148 RefUpdateMoveTabContext(ScDocument& rDoc, SCTAB nOldPos, SCTAB nNewPos);
150 SCTAB getNewTab(SCTAB nOldTab) const;
153 struct SetFormulaDirtyContext
155 SCTAB mnTabDeletedStart;
156 SCTAB mnTabDeletedEnd;
159 * When true, go through all reference tokens and clears "sheet deleted"
160 * flag if its corresponding index falls within specified sheet range.
162 bool mbClearTabDeletedFlag;
164 SetFormulaDirtyContext();
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */