LibreOffice Module sc (master) 1
documentstreamaccess.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
11#include <document.hxx>
12#include <table.hxx>
13#include <column.hxx>
14#include <mtvelements.hxx>
15
17
18namespace sc {
19
21{
24
26 mrDoc(rDoc),
27 maBlockPosSet(rDoc)
28 {}
29};
30
32 mpImpl(new DocumentStreamAccessImpl(rDoc)) {}
33
35{
36}
37
38void DocumentStreamAccess::setNumericCell( const ScAddress& rPos, double fVal )
39{
40 ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab());
41 if (!pTab)
42 return;
43
44 ColumnBlockPosition* pBlockPos =
45 mpImpl->maBlockPosSet.getBlockPosition(rPos.Tab(), rPos.Col());
46
47 if (!pBlockPos)
48 return;
49
50 // Set the numeric value.
51 CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
52 pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), fVal);
53
54 // Be sure to set the corresponding text attribute to the default value.
55 CellTextAttrStoreType& rAttrs = pTab->aCol[rPos.Col()].maCellTextAttrs;
56 pBlockPos->miCellTextAttrPos = rAttrs.set(pBlockPos->miCellTextAttrPos, rPos.Row(), CellTextAttr());
57}
58
59void DocumentStreamAccess::setStringCell( const ScAddress& rPos, const OUString& rStr )
60{
61 ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab());
62 if (!pTab)
63 return;
64
65 ColumnBlockPosition* pBlockPos =
66 mpImpl->maBlockPosSet.getBlockPosition(rPos.Tab(), rPos.Col());
67
68 if (!pBlockPos)
69 return;
70
71 svl::SharedString aSS = mpImpl->mrDoc.GetSharedStringPool().intern(rStr);
72 if (!aSS.getData())
73 return;
74
75 // Set the string.
76 CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
77 pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), aSS);
78
79 // Be sure to set the corresponding text attribute to the default value.
80 CellTextAttrStoreType& rAttrs = pTab->aCol[rPos.Col()].maCellTextAttrs;
81 pBlockPos->miCellTextAttrPos = rAttrs.set(pBlockPos->miCellTextAttrPos, rPos.Row(), CellTextAttr());
82}
83
85{
86 mpImpl->maBlockPosSet.clear();
87}
88
90{
91 ScTable* pTab = mpImpl->mrDoc.FetchTable(rRange.aStart.Tab());
92 if (!pTab)
93 return;
94
95 SCROW nTopRow = rRange.aStart.Row();
96 SCROW nLastRow = rRange.aEnd.Row();
97
98 for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
99 {
100 ColumnBlockPosition* pBlockPos =
101 mpImpl->maBlockPosSet.getBlockPosition(rRange.aStart.Tab(), nCol);
102
103 if (!pBlockPos)
104 return;
105
106 CellStoreType& rCells = pTab->aCol[nCol].maCells;
107 rCells.erase(nTopRow, nTopRow); // Erase the top, and shift the rest up.
108 pBlockPos->miCellPos = rCells.insert_empty(nLastRow, 1);
109
110 // Do the same for the text attribute storage.
111 CellTextAttrStoreType& rAttrs = pTab->aCol[nCol].maCellTextAttrs;
112 rAttrs.erase(nTopRow, nTopRow);
113 pBlockPos->miCellTextAttrPos = rAttrs.insert_empty(nLastRow, 1);
114 }
115}
116
118{
119 ScTable* pTab = mpImpl->mrDoc.FetchTable(rRange.aStart.Tab());
120 if (!pTab)
121 return;
122
123 SCROW nTopRow = rRange.aStart.Row();
124 SCROW nLastRow = rRange.aEnd.Row();
125
126 for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
127 {
128 ColumnBlockPosition* pBlockPos =
129 mpImpl->maBlockPosSet.getBlockPosition(rRange.aStart.Tab(), nCol);
130
131 if (!pBlockPos)
132 return;
133
134 CellStoreType& rCells = pTab->aCol[nCol].maCells;
135 rCells.erase(nLastRow, nLastRow); // Erase the bottom.
136 pBlockPos->miCellPos = rCells.insert_empty(nTopRow, 1); // insert at the top and shift everything down.
137
138 // Do the same for the text attribute storage.
139 CellTextAttrStoreType& rAttrs = pTab->aCol[nCol].maCellTextAttrs;
140 rAttrs.erase(nLastRow, nLastRow);
141 pBlockPos->miCellTextAttrPos = rAttrs.insert_empty(nTopRow, 1);
142 }
143}
144
145}
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
ScColContainer aCol
Definition: table.hxx:162
void reset()
Clear its internal state, and more importantly all the block position hints currently held.
void shiftRangeUp(const ScRange &rRange)
Pop the top row inside specified range, shift all the other rows up by one, then set the bottom row e...
void setStringCell(const ScAddress &rPos, const OUString &rStr)
DocumentStreamAccess(ScDocument &rDoc)
void setNumericCell(const ScAddress &rPos, double fVal)
std::unique_ptr< DocumentStreamAccessImpl > mpImpl
void shiftRangeDown(const ScRange &rRange)
Top the bottom row inside specified range, shift all the other rows above downward by one by insertin...
rtl_uString * getData()
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
mdds::mtv::soa::multi_type_vector< CellStoreTraits > CellStoreType
Cell container.
mdds::mtv::soa::multi_type_vector< CellTextAttrTraits > CellTextAttrStoreType
Cell text attribute container.
Store position data for column array storage.
CellTextAttrStoreType::iterator miCellTextAttrPos
CellStoreType::iterator miCellPos
ColumnBlockPositionSet maBlockPosSet
DocumentStreamAccessImpl(ScDocument &rDoc)
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17