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 <clipparam.hxx>
13#include <mtvelements.hxx>
14
15namespace sc {
16
17void UpdatedRangeNames::setUpdatedName(SCTAB nTab, sal_uInt16 nIndex)
18{
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;
23
24 UpdatedNamesType::iterator it = maUpdatedNames.find(nTab);
25 if (it == maUpdatedNames.end())
26 {
27 // Insert a new container for this sheet index.
28 NameIndicesType aIndices;
29 std::pair<UpdatedNamesType::iterator,bool> r =
30 maUpdatedNames.emplace( nTab, aIndices);
31
32 if (!r.second)
33 // Insertion failed for whatever reason.
34 return;
35
36 it = r.first;
37 }
38
39 NameIndicesType& rIndices = it->second;
40 rIndices.insert(nIndex);
41}
42
43bool UpdatedRangeNames::isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const
44{
45 UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
46 if (it == maUpdatedNames.end())
47 return false;
48
49 const NameIndicesType& rIndices = it->second;
50 return rIndices.count(nIndex) > 0;
51}
52
54{
55 UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
56 if (it == maUpdatedNames.end())
57 return NameIndicesType();
58 return it->second;
59}
60
62{
63 UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
64 return it == maUpdatedNames.end();
65}
66
68 : mrDoc(rDoc)
70 , mbTransposed(pClipdoc != nullptr && pClipdoc->GetClipParam().isTransposed())
71 , mnColDelta(0)
72 , mnRowDelta(0)
73 , mnTabDelta(0)
74 , mpBlockPos(nullptr)
75{
76 assert((pClipdoc == nullptr || pClipdoc->IsClipboard()) && "only nullptr or clipdoc allowed");
77}
78
80{
81 return (meMode == URM_INSDEL) && (mnColDelta > 0 || mnRowDelta > 0 || mnTabDelta > 0);
82}
83
85{
86 return (meMode == URM_INSDEL) && (mnColDelta < 0 || mnRowDelta < 0 || mnTabDelta < 0);
87}
88
90{
91 mpBlockPos = blockPos;
92}
93
95{
96 return mpBlockPos ? mpBlockPos->getBlockPosition(nTab, nCol) : nullptr;
97}
98
99RefUpdateResult::RefUpdateResult() : mbValueChanged(false), mbReferenceModified(false), mbNameModified(false) {}
100
102 mrDoc(rDoc), mnInsertPos(nInsertPos), mnSheets(nSheets) {}
103
105 mrDoc(rDoc), mnDeletePos(nDeletePos), mnSheets(nSheets) {}
106
108 mrDoc(rDoc), mnOldPos(nOldPos), mnNewPos(nNewPos) {}
109
111{
112 // Sheets below the lower bound or above the upper bound will not change.
113 SCTAB nLowerBound = std::min(mnOldPos, mnNewPos);
114 SCTAB nUpperBound = std::max(mnOldPos, mnNewPos);
115
116 if (nOldTab < nLowerBound || nUpperBound < nOldTab)
117 // Outside the boundary. Nothing to adjust.
118 return nOldTab;
119
120 if (nOldTab == mnOldPos)
121 return mnNewPos;
122
123 // It's somewhere in between.
124 if (mnOldPos < mnNewPos)
125 {
126 // Moving a sheet to the right. The rest of the sheets shifts to the left.
127 return nOldTab - 1;
128 }
129
130 // Moving a sheet to the left. The rest of the sheets shifts to the right.
131 return nOldTab + 1;
132}
133
135 mnTabDeletedStart(-1), mnTabDeletedEnd(-1), mbClearTabDeletedFlag(false) {}
136
137}
138
139/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsClipboard() const
Definition: document.hxx:1592
ColumnBlockPosition * getBlockPosition(SCTAB nTab, SCCOL nCol)
Definition: mtvelements.cxx:71
UpdatedNamesType maUpdatedNames
std::unordered_set< sal_uInt16 > NameIndicesType
NameIndicesType getUpdatedNames(SCTAB nTab) const
bool isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const
void setUpdatedName(SCTAB nTab, sal_uInt16 nIndex)
bool isEmpty(SCTAB nTab) const
ColorMode meMode
@ URM_INSDEL
Definition: global.hxx:301
sal_Int32 nIndex
CAUTION! The following defines must be in the same namespace as the respective type.
Store position data for column array storage.
ColumnBlockPosition * getBlockPosition(SCTAB nTab, SCCOL nCol)
SCROW mnRowDelta
Amount and direction of movement in the row direction.
UpdateRefMode meMode
update mode - insert/delete, copy, or move.
RefUpdateContext(ScDocument &rDoc, ScDocument *pClipdoc=nullptr)
void setBlockPositionReference(ColumnBlockPositionSet *blockPos)
SCCOL mnColDelta
Amount and direction of movement in the column direction.
SCTAB mnTabDelta
Amount and direction of movement in the sheet direction.
ColumnBlockPositionSet * mpBlockPos
RefUpdateDeleteTabContext(ScDocument &rDoc, SCTAB nInsertPos, SCTAB nSheets)
RefUpdateInsertTabContext(ScDocument &rDoc, SCTAB nInsertPos, SCTAB nSheets)
RefUpdateMoveTabContext(ScDocument &rDoc, SCTAB nOldPos, SCTAB nNewPos)
SCTAB getNewTab(SCTAB nOldTab) const
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21