fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / documentstreamaccess.cxx
blob1eacfc978be1ac59e41e5e68826ed7bd5e5be7f4
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 "documentstreamaccess.hxx"
11 #include "document.hxx"
12 #include "table.hxx"
13 #include "column.hxx"
14 #include "mtvelements.hxx"
16 #include <svl/sharedstringpool.hxx>
18 namespace sc {
20 struct DocumentStreamAccessImpl
22 ScDocument& mrDoc;
23 ColumnBlockPositionSet maBlockPosSet;
25 DocumentStreamAccessImpl( ScDocument& rDoc ) :
26 mrDoc(rDoc),
27 maBlockPosSet(rDoc)
31 DocumentStreamAccess::DocumentStreamAccess( ScDocument& rDoc ) :
32 mpImpl(new DocumentStreamAccessImpl(rDoc)) {}
34 DocumentStreamAccess::~DocumentStreamAccess()
38 void DocumentStreamAccess::setNumericCell( const ScAddress& rPos, double fVal )
40 ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab());
41 if (!pTab)
42 return;
44 ColumnBlockPosition* pBlockPos =
45 mpImpl->maBlockPosSet.getBlockPosition(rPos.Tab(), rPos.Col());
47 if (!pBlockPos)
48 return;
50 // Set the numeric value.
51 CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
52 pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), fVal);
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());
59 void DocumentStreamAccess::setStringCell( const ScAddress& rPos, const OUString& rStr )
61 ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab());
62 if (!pTab)
63 return;
65 ColumnBlockPosition* pBlockPos =
66 mpImpl->maBlockPosSet.getBlockPosition(rPos.Tab(), rPos.Col());
68 if (!pBlockPos)
69 return;
71 svl::SharedString aSS = mpImpl->mrDoc.GetSharedStringPool().intern(rStr);
72 if (!aSS.getData())
73 return;
75 // Set the string.
76 CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
77 pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), aSS);
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());
84 void DocumentStreamAccess::reset()
86 mpImpl->maBlockPosSet.clear();
89 void DocumentStreamAccess::shiftRangeUp( const ScRange& rRange )
91 ScTable* pTab = mpImpl->mrDoc.FetchTable(rRange.aStart.Tab());
92 if (!pTab)
93 return;
95 SCROW nTopRow = rRange.aStart.Row();
96 SCROW nLastRow = rRange.aEnd.Row();
98 for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
100 ColumnBlockPosition* pBlockPos =
101 mpImpl->maBlockPosSet.getBlockPosition(rRange.aStart.Tab(), nCol);
103 if (!pBlockPos)
104 return;
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);
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);
117 void DocumentStreamAccess::shiftRangeDown( const ScRange& rRange )
119 ScTable* pTab = mpImpl->mrDoc.FetchTable(rRange.aStart.Tab());
120 if (!pTab)
121 return;
123 SCROW nTopRow = rRange.aStart.Row();
124 SCROW nLastRow = rRange.aEnd.Row();
126 for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
128 ColumnBlockPosition* pBlockPos =
129 mpImpl->maBlockPosSet.getBlockPosition(rRange.aStart.Tab(), nCol);
131 if (!pBlockPos)
132 return;
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.
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);
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */