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 DocumentStreamAccessImpl( ScDocument
& rDoc
) :
31 DocumentStreamAccess::DocumentStreamAccess( ScDocument
& rDoc
) :
32 mpImpl(new DocumentStreamAccessImpl(rDoc
)) {}
34 void DocumentStreamAccess::setNumericCell( const ScAddress
& rPos
, double fVal
)
36 ScTable
* pTab
= mpImpl
->mrDoc
.FetchTable(rPos
.Tab());
40 ColumnBlockPosition
* pBlockPos
=
41 mpImpl
->maBlockPosSet
.getBlockPosition(rPos
.Tab(), rPos
.Col());
46 // Set the numeric value.
47 CellStoreType
& rCells
= pTab
->aCol
[rPos
.Col()].maCells
;
48 pBlockPos
->miCellPos
= rCells
.set(pBlockPos
->miCellPos
, rPos
.Row(), fVal
);
50 // Be sure to set the corresponding text attribute to the default value.
51 CellTextAttrStoreType
& rAttrs
= pTab
->aCol
[rPos
.Col()].maCellTextAttrs
;
52 pBlockPos
->miCellTextAttrPos
= rAttrs
.set(pBlockPos
->miCellTextAttrPos
, rPos
.Row(), CellTextAttr());
55 void DocumentStreamAccess::setStringCell( const ScAddress
& rPos
, const OUString
& rStr
)
57 ScTable
* pTab
= mpImpl
->mrDoc
.FetchTable(rPos
.Tab());
61 ColumnBlockPosition
* pBlockPos
=
62 mpImpl
->maBlockPosSet
.getBlockPosition(rPos
.Tab(), rPos
.Col());
67 svl::SharedString aSS
= mpImpl
->mrDoc
.GetSharedStringPool().intern(rStr
);
72 CellStoreType
& rCells
= pTab
->aCol
[rPos
.Col()].maCells
;
73 pBlockPos
->miCellPos
= rCells
.set(pBlockPos
->miCellPos
, rPos
.Row(), aSS
);
75 // Be sure to set the corresponding text attribute to the default value.
76 CellTextAttrStoreType
& rAttrs
= pTab
->aCol
[rPos
.Col()].maCellTextAttrs
;
77 pBlockPos
->miCellTextAttrPos
= rAttrs
.set(pBlockPos
->miCellTextAttrPos
, rPos
.Row(), CellTextAttr());
80 void DocumentStreamAccess::reset()
82 mpImpl
->maBlockPosSet
.clear();
85 void DocumentStreamAccess::shiftRangeUp( const ScRange
& rRange
)
87 ScTable
* pTab
= mpImpl
->mrDoc
.FetchTable(rRange
.aStart
.Tab());
91 SCROW nTopRow
= rRange
.aStart
.Row();
92 SCROW nLastRow
= rRange
.aEnd
.Row();
94 for (SCCOL nCol
= rRange
.aStart
.Col(); nCol
<= rRange
.aEnd
.Col(); ++nCol
)
96 ColumnBlockPosition
* pBlockPos
=
97 mpImpl
->maBlockPosSet
.getBlockPosition(rRange
.aStart
.Tab(), nCol
);
102 CellStoreType
& rCells
= pTab
->aCol
[nCol
].maCells
;
103 rCells
.erase(nTopRow
, nTopRow
); // Erase the top, and shift the rest up.
104 pBlockPos
->miCellPos
= rCells
.insert_empty(nLastRow
, 1);
106 // Do the same for the text attribute storage.
107 CellTextAttrStoreType
& rAttrs
= pTab
->aCol
[nCol
].maCellTextAttrs
;
108 rAttrs
.erase(nTopRow
, nTopRow
);
109 pBlockPos
->miCellTextAttrPos
= rAttrs
.insert_empty(nLastRow
, 1);
113 void DocumentStreamAccess::shiftRangeDown( const ScRange
& rRange
)
115 ScTable
* pTab
= mpImpl
->mrDoc
.FetchTable(rRange
.aStart
.Tab());
119 SCROW nTopRow
= rRange
.aStart
.Row();
120 SCROW nLastRow
= rRange
.aEnd
.Row();
122 for (SCCOL nCol
= rRange
.aStart
.Col(); nCol
<= rRange
.aEnd
.Col(); ++nCol
)
124 ColumnBlockPosition
* pBlockPos
=
125 mpImpl
->maBlockPosSet
.getBlockPosition(rRange
.aStart
.Tab(), nCol
);
130 CellStoreType
& rCells
= pTab
->aCol
[nCol
].maCells
;
131 rCells
.erase(nLastRow
, nLastRow
); // Erase the bottom.
132 pBlockPos
->miCellPos
= rCells
.insert_empty(nTopRow
, 1); // insert at the top and shift everything down.
134 // Do the same for the text attribute storage.
135 CellTextAttrStoreType
& rAttrs
= pTab
->aCol
[nCol
].maCellTextAttrs
;
136 rAttrs
.erase(nLastRow
, nLastRow
);
137 pBlockPos
->miCellTextAttrPos
= rAttrs
.insert_empty(nTopRow
, 1);
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */