LibreOffice Module sc (master)  1
refupdatecontext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #include <refupdatecontext.hxx>
11 #include <algorithm>
12 #include <mtvelements.hxx>
13 
14 namespace sc {
15 
16 void UpdatedRangeNames::setUpdatedName(SCTAB nTab, sal_uInt16 nIndex)
17 {
18  // Map anything <-1 to global names. Unless we really want to come up with
19  // some classification there...
20  if (nTab < -1)
21  nTab = -1;
22 
23  UpdatedNamesType::iterator it = maUpdatedNames.find(nTab);
24  if (it == maUpdatedNames.end())
25  {
26  // Insert a new container for this sheet index.
27  NameIndicesType aIndices;
28  std::pair<UpdatedNamesType::iterator,bool> r =
29  maUpdatedNames.emplace( nTab, aIndices);
30 
31  if (!r.second)
32  // Insertion failed for whatever reason.
33  return;
34 
35  it = r.first;
36  }
37 
38  NameIndicesType& rIndices = it->second;
39  rIndices.insert(nIndex);
40 }
41 
42 bool UpdatedRangeNames::isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const
43 {
44  UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
45  if (it == maUpdatedNames.end())
46  return false;
47 
48  const NameIndicesType& rIndices = it->second;
49  return rIndices.count(nIndex) > 0;
50 }
51 
53 {
54  UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
55  if (it == maUpdatedNames.end())
56  return NameIndicesType();
57  return it->second;
58 }
59 
61 {
62  UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
63  return it == maUpdatedNames.end();
64 }
65 
66 
68  mrDoc(rDoc), meMode(URM_INSDEL), mnColDelta(0), mnRowDelta(0), mnTabDelta(0), mpBlockPos( nullptr ) {}
69 
71 {
72  return (meMode == URM_INSDEL) && (mnColDelta > 0 || mnRowDelta > 0 || mnTabDelta > 0);
73 }
74 
76 {
77  return (meMode == URM_INSDEL) && (mnColDelta < 0 || mnRowDelta < 0 || mnTabDelta < 0);
78 }
79 
81 {
82  mpBlockPos = blockPos;
83 }
84 
86 {
87  return mpBlockPos ? mpBlockPos->getBlockPosition(nTab, nCol) : nullptr;
88 }
89 
90 RefUpdateResult::RefUpdateResult() : mbValueChanged(false), mbReferenceModified(false), mbNameModified(false) {}
91 
93  mrDoc(rDoc), mnInsertPos(nInsertPos), mnSheets(nSheets) {}
94 
96  mrDoc(rDoc), mnDeletePos(nDeletePos), mnSheets(nSheets) {}
97 
99  mrDoc(rDoc), mnOldPos(nOldPos), mnNewPos(nNewPos) {}
100 
102 {
103  // Sheets below the lower bound or above the upper bound will not change.
104  SCTAB nLowerBound = std::min(mnOldPos, mnNewPos);
105  SCTAB nUpperBound = std::max(mnOldPos, mnNewPos);
106 
107  if (nOldTab < nLowerBound || nUpperBound < nOldTab)
108  // Outside the boundary. Nothing to adjust.
109  return nOldTab;
110 
111  if (nOldTab == mnOldPos)
112  return mnNewPos;
113 
114  // It's somewhere in between.
115  if (mnOldPos < mnNewPos)
116  {
117  // Moving a sheet to the right. The rest of the sheets shifts to the left.
118  return nOldTab - 1;
119  }
120 
121  // Moving a sheet to the left. The rest of the sheets shifts to the right.
122  return nOldTab + 1;
123 }
124 
126  mnTabDeletedStart(-1), mnTabDeletedEnd(-1), mbClearTabDeletedFlag(false) {}
127 
128 }
129 
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
RefUpdateInsertTabContext(ScDocument &rDoc, SCTAB nInsertPos, SCTAB nSheets)
SCROW mnRowDelta
Amount and direction of movement in the row direction.
void setBlockPositionReference(ColumnBlockPositionSet *blockPos)
UpdatedNamesType maUpdatedNames
SCTAB getNewTab(SCTAB nOldTab) const
Store position data for column array storage.
RefUpdateContext(ScDocument &rDoc)
std::unordered_set< sal_uInt16 > NameIndicesType
void setUpdatedName(SCTAB nTab, sal_uInt16 nIndex)
bool isEmpty(SCTAB nTab) const
ColumnBlockPosition * getBlockPosition(SCTAB nTab, SCCOL nCol)
Definition: mtvelements.cxx:56
bool isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const
ColumnBlockPositionSet * mpBlockPos
ColorMode meMode
RefUpdateDeleteTabContext(ScDocument &rDoc, SCTAB nInsertPos, SCTAB nSheets)
ColumnBlockPosition * getBlockPosition(SCTAB nTab, SCCOL nCol)
UpdateRefMode meMode
update mode - insert/delete, copy, or move.
sal_Int16 SCCOL
Definition: types.hxx:22
NameIndicesType getUpdatedNames(SCTAB nTab) const
SCTAB mnTabDelta
Amount and direction of movement in the sheet direction.
RefUpdateMoveTabContext(ScDocument &rDoc, SCTAB nOldPos, SCTAB nNewPos)
SCCOL mnColDelta
Amount and direction of movement in the column direction.
sal_Int16 SCTAB
Definition: types.hxx:23