1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <documentstreamaccess.hxx>
11 #include <document.hxx>
14 #include <mtvelements.hxx>
16 #include <svl/sharedstringpool.hxx>
20 struct DocumentStreamAccessImpl
23 ColumnBlockPositionSet maBlockPosSet
;
25 explicit DocumentStreamAccessImpl( ScDocument
& 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());
44 ColumnBlockPosition
* pBlockPos
=
45 mpImpl
->maBlockPosSet
.getBlockPosition(rPos
.Tab(), rPos
.Col());
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());
65 ColumnBlockPosition
* pBlockPos
=
66 mpImpl
->maBlockPosSet
.getBlockPosition(rPos
.Tab(), rPos
.Col());
71 svl::SharedString aSS
= mpImpl
->mrDoc
.GetSharedStringPool().intern(rStr
);
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());
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
);
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());
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
);
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: */