diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sc/source/core/data/documentstreamaccess.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sc/source/core/data/documentstreamaccess.cxx')
-rw-r--r-- | sc/source/core/data/documentstreamaccess.cxx | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/sc/source/core/data/documentstreamaccess.cxx b/sc/source/core/data/documentstreamaccess.cxx new file mode 100644 index 000000000..6b3581058 --- /dev/null +++ b/sc/source/core/data/documentstreamaccess.cxx @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <documentstreamaccess.hxx> +#include <document.hxx> +#include <table.hxx> +#include <column.hxx> +#include <mtvelements.hxx> + +#include <svl/sharedstringpool.hxx> + +namespace sc { + +struct DocumentStreamAccessImpl +{ + ScDocument& mrDoc; + ColumnBlockPositionSet maBlockPosSet; + + explicit DocumentStreamAccessImpl( ScDocument& rDoc ) : + mrDoc(rDoc), + maBlockPosSet(rDoc) + {} +}; + +DocumentStreamAccess::DocumentStreamAccess( ScDocument& rDoc ) : + mpImpl(new DocumentStreamAccessImpl(rDoc)) {} + +DocumentStreamAccess::~DocumentStreamAccess() +{ +} + +void DocumentStreamAccess::setNumericCell( const ScAddress& rPos, double fVal ) +{ + ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab()); + if (!pTab) + return; + + ColumnBlockPosition* pBlockPos = + mpImpl->maBlockPosSet.getBlockPosition(rPos.Tab(), rPos.Col()); + + if (!pBlockPos) + return; + + // Set the numeric value. + CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells; + pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), fVal); + + // Be sure to set the corresponding text attribute to the default value. + CellTextAttrStoreType& rAttrs = pTab->aCol[rPos.Col()].maCellTextAttrs; + pBlockPos->miCellTextAttrPos = rAttrs.set(pBlockPos->miCellTextAttrPos, rPos.Row(), CellTextAttr()); +} + +void DocumentStreamAccess::setStringCell( const ScAddress& rPos, const OUString& rStr ) +{ + ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab()); + if (!pTab) + return; + + ColumnBlockPosition* pBlockPos = + mpImpl->maBlockPosSet.getBlockPosition(rPos.Tab(), rPos.Col()); + + if (!pBlockPos) + return; + + svl::SharedString aSS = mpImpl->mrDoc.GetSharedStringPool().intern(rStr); + if (!aSS.getData()) + return; + + // Set the string. + CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells; + pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), aSS); + + // Be sure to set the corresponding text attribute to the default value. + CellTextAttrStoreType& rAttrs = pTab->aCol[rPos.Col()].maCellTextAttrs; + pBlockPos->miCellTextAttrPos = rAttrs.set(pBlockPos->miCellTextAttrPos, rPos.Row(), CellTextAttr()); +} + +void DocumentStreamAccess::reset() +{ + mpImpl->maBlockPosSet.clear(); +} + +void DocumentStreamAccess::shiftRangeUp( const ScRange& rRange ) +{ + ScTable* pTab = mpImpl->mrDoc.FetchTable(rRange.aStart.Tab()); + if (!pTab) + return; + + SCROW nTopRow = rRange.aStart.Row(); + SCROW nLastRow = rRange.aEnd.Row(); + + for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol) + { + ColumnBlockPosition* pBlockPos = + mpImpl->maBlockPosSet.getBlockPosition(rRange.aStart.Tab(), nCol); + + if (!pBlockPos) + return; + + CellStoreType& rCells = pTab->aCol[nCol].maCells; + rCells.erase(nTopRow, nTopRow); // Erase the top, and shift the rest up. + pBlockPos->miCellPos = rCells.insert_empty(nLastRow, 1); + + // Do the same for the text attribute storage. + CellTextAttrStoreType& rAttrs = pTab->aCol[nCol].maCellTextAttrs; + rAttrs.erase(nTopRow, nTopRow); + pBlockPos->miCellTextAttrPos = rAttrs.insert_empty(nLastRow, 1); + } +} + +void DocumentStreamAccess::shiftRangeDown( const ScRange& rRange ) +{ + ScTable* pTab = mpImpl->mrDoc.FetchTable(rRange.aStart.Tab()); + if (!pTab) + return; + + SCROW nTopRow = rRange.aStart.Row(); + SCROW nLastRow = rRange.aEnd.Row(); + + for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol) + { + ColumnBlockPosition* pBlockPos = + mpImpl->maBlockPosSet.getBlockPosition(rRange.aStart.Tab(), nCol); + + if (!pBlockPos) + return; + + CellStoreType& rCells = pTab->aCol[nCol].maCells; + rCells.erase(nLastRow, nLastRow); // Erase the bottom. + pBlockPos->miCellPos = rCells.insert_empty(nTopRow, 1); // insert at the top and shift everything down. + + // Do the same for the text attribute storage. + CellTextAttrStoreType& rAttrs = pTab->aCol[nCol].maCellTextAttrs; + rAttrs.erase(nLastRow, nLastRow); + pBlockPos->miCellTextAttrPos = rAttrs.insert_empty(nTopRow, 1); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |