Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / sc / source / core / data / refupdatecontext.cxx
blob0ce3f175e48f9a89cea853736eb8a7ae8810166e
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 #include <refupdatecontext.hxx>
11 #include <algorithm>
12 #include <clipparam.hxx>
13 #include <mtvelements.hxx>
15 namespace sc {
17 void UpdatedRangeNames::setUpdatedName(SCTAB nTab, sal_uInt16 nIndex)
19 // Map anything <-1 to global names. Unless we really want to come up with
20 // some classification there...
21 if (nTab < -1)
22 nTab = -1;
24 UpdatedNamesType::iterator it = maUpdatedNames.find(nTab);
25 if (it == maUpdatedNames.end())
27 // Insert a new container for this sheet index.
28 NameIndicesType aIndices;
29 std::pair<UpdatedNamesType::iterator,bool> r =
30 maUpdatedNames.emplace( nTab, aIndices);
32 if (!r.second)
33 // Insertion failed for whatever reason.
34 return;
36 it = r.first;
39 NameIndicesType& rIndices = it->second;
40 rIndices.insert(nIndex);
43 bool UpdatedRangeNames::isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const
45 UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
46 if (it == maUpdatedNames.end())
47 return false;
49 const NameIndicesType& rIndices = it->second;
50 return rIndices.count(nIndex) > 0;
53 UpdatedRangeNames::NameIndicesType UpdatedRangeNames::getUpdatedNames(SCTAB nTab) const
55 UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
56 if (it == maUpdatedNames.end())
57 return NameIndicesType();
58 return it->second;
61 bool UpdatedRangeNames::isEmpty(SCTAB nTab) const
63 UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
64 return it == maUpdatedNames.end();
67 RefUpdateContext::RefUpdateContext(ScDocument& rDoc, ScDocument* pClipdoc)
68 : mrDoc(rDoc)
69 , meMode(URM_INSDEL)
70 , mbTransposed(pClipdoc != nullptr && pClipdoc->GetClipParam().isTransposed())
71 , mnColDelta(0)
72 , mnRowDelta(0)
73 , mnTabDelta(0)
74 , mpBlockPos(nullptr)
76 assert((pClipdoc == nullptr || pClipdoc->IsClipboard()) && "only nullptr or clipdoc allowed");
79 bool RefUpdateContext::isInserted() const
81 return (meMode == URM_INSDEL) && (mnColDelta > 0 || mnRowDelta > 0 || mnTabDelta > 0);
84 bool RefUpdateContext::isDeleted() const
86 return (meMode == URM_INSDEL) && (mnColDelta < 0 || mnRowDelta < 0 || mnTabDelta < 0);
89 void RefUpdateContext::setBlockPositionReference( ColumnBlockPositionSet* blockPos )
91 mpBlockPos = blockPos;
94 ColumnBlockPosition* RefUpdateContext::getBlockPosition(SCTAB nTab, SCCOL nCol)
96 return mpBlockPos ? mpBlockPos->getBlockPosition(nTab, nCol) : nullptr;
99 RefUpdateResult::RefUpdateResult()
100 : mbValueChanged(false), mbReferenceModified(false), mbNameModified(false), mnTab(-1) {}
102 RefUpdateInsertTabContext::RefUpdateInsertTabContext(ScDocument& rDoc, SCTAB nInsertPos, SCTAB nSheets) :
103 mrDoc(rDoc), mnInsertPos(nInsertPos), mnSheets(nSheets) {}
105 RefUpdateDeleteTabContext::RefUpdateDeleteTabContext(ScDocument& rDoc, SCTAB nDeletePos, SCTAB nSheets) :
106 mrDoc(rDoc), mnDeletePos(nDeletePos), mnSheets(nSheets) {}
108 RefUpdateMoveTabContext::RefUpdateMoveTabContext(ScDocument& rDoc, SCTAB nOldPos, SCTAB nNewPos) :
109 mrDoc(rDoc), mnOldPos(nOldPos), mnNewPos(nNewPos) {}
111 SCTAB RefUpdateMoveTabContext::getNewTab(SCTAB nOldTab) const
113 // Sheets below the lower bound or above the upper bound will not change.
114 SCTAB nLowerBound = std::min(mnOldPos, mnNewPos);
115 SCTAB nUpperBound = std::max(mnOldPos, mnNewPos);
117 if (nOldTab < nLowerBound || nUpperBound < nOldTab)
118 // Outside the boundary. Nothing to adjust.
119 return nOldTab;
121 if (nOldTab == mnOldPos)
122 return mnNewPos;
124 // It's somewhere in between.
125 if (mnOldPos < mnNewPos)
127 // Moving a sheet to the right. The rest of the sheets shifts to the left.
128 return nOldTab - 1;
131 // Moving a sheet to the left. The rest of the sheets shifts to the right.
132 return nOldTab + 1;
135 SetFormulaDirtyContext::SetFormulaDirtyContext() :
136 mnTabDeletedStart(-1), mnTabDeletedEnd(-1), mbClearTabDeletedFlag(false) {}
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */