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/.
11 #include <clipcontext.hxx>
12 #include <document.hxx>
13 #include <clipparam.hxx>
14 #include <bcaslot.hxx>
15 #include <segmenttree.hxx>
16 #include <sharedformula.hxx>
17 #include <cellvalues.hxx>
19 bool ScTable::IsMerged( SCCOL nCol
, SCROW nRow
) const
24 return aCol
[nCol
].IsMerged(nRow
);
27 void ScTable::DeleteBeforeCopyFromClip(
28 sc::CopyFromClipContext
& rCxt
, const ScTable
& rClipTab
, sc::ColumnSpanSet
& rBroadcastSpans
)
30 sc::CopyFromClipContext::Range aRange
= rCxt
.getDestRange();
31 if (!ValidCol(aRange
.mnCol1
) || !ValidCol(aRange
.mnCol2
))
34 // Pass some stuff to the columns via context.
35 rCxt
.setTableProtected(IsProtected());
36 rCxt
.setCondFormatList(mpCondFormatList
.get());
38 ScRange aClipRange
= rCxt
.getClipDoc()->GetClipParam().getWholeRange();
39 SCCOL nClipCol
= aClipRange
.aStart
.Col();
41 for (SCCOL nCol
= aRange
.mnCol1
; nCol
<= aRange
.mnCol2
; ++nCol
, ++nClipCol
)
43 if (nClipCol
> aClipRange
.aEnd
.Col())
44 nClipCol
= aClipRange
.aStart
.Col(); // loop through columns.
46 const ScColumn
& rClipCol
= rClipTab
.aCol
[nClipCol
];
47 aCol
[nCol
].DeleteBeforeCopyFromClip(rCxt
, rClipCol
, rBroadcastSpans
);
51 SetStreamValid(false);
54 void ScTable::CopyOneCellFromClip(
55 sc::CopyFromClipContext
& rCxt
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
)
57 ScRange aSrcRange
= rCxt
.getClipDoc()->GetClipParam().getWholeRange();
58 SCCOL nSrcColSize
= aSrcRange
.aEnd
.Col() - aSrcRange
.aStart
.Col() + 1;
60 for (SCCOL nCol
= nCol1
; nCol
<= nCol2
; ++nCol
)
62 SCCOL nColOffset
= nCol
- nCol1
;
63 nColOffset
= nColOffset
% nSrcColSize
;
64 assert(nColOffset
>= 0);
65 aCol
[nCol
].CopyOneCellFromClip(rCxt
, nRow1
, nRow2
, nColOffset
);
69 void ScTable::SetValues( SCCOL nCol
, SCROW nRow
, const std::vector
<double>& rVals
)
74 aCol
[nCol
].SetValues(nRow
, rVals
);
77 void ScTable::TransferCellValuesTo( SCCOL nCol
, SCROW nRow
, size_t nLen
, sc::CellValues
& rDest
)
82 aCol
[nCol
].TransferCellValuesTo(nRow
, nLen
, rDest
);
85 void ScTable::CopyCellValuesFrom( SCCOL nCol
, SCROW nRow
, const sc::CellValues
& rSrc
)
90 aCol
[nCol
].CopyCellValuesFrom(nRow
, rSrc
);
93 void ScTable::ConvertFormulaToValue(
94 sc::EndListeningContext
& rCxt
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
,
95 sc::TableValues
* pUndo
)
97 if (!ValidCol(nCol1
) || !ValidCol(nCol2
) || nCol1
> nCol2
)
100 for (SCCOL nCol
= nCol1
; nCol
<= nCol2
; ++nCol
)
101 aCol
[nCol
].ConvertFormulaToValue(rCxt
, nRow1
, nRow2
, pUndo
);
104 void ScTable::SwapNonEmpty(
105 sc::TableValues
& rValues
, sc::StartListeningContext
& rStartCxt
, sc::EndListeningContext
& rEndCxt
)
107 const ScRange
& rRange
= rValues
.getRange();
108 assert(rRange
.IsValid());
109 for (SCCOL nCol
= rRange
.aStart
.Col(); nCol
<= rRange
.aEnd
.Col(); ++nCol
)
110 aCol
[nCol
].SwapNonEmpty(rValues
, rStartCxt
, rEndCxt
);
113 void ScTable::PreprocessRangeNameUpdate(
114 sc::EndListeningContext
& rEndListenCxt
, sc::CompileFormulaContext
& rCompileCxt
)
116 for (SCCOL i
= 0; i
<= MAXCOL
; ++i
)
117 aCol
[i
].PreprocessRangeNameUpdate(rEndListenCxt
, rCompileCxt
);
120 void ScTable::PreprocessDBDataUpdate(
121 sc::EndListeningContext
& rEndListenCxt
, sc::CompileFormulaContext
& rCompileCxt
)
123 for (SCCOL i
= 0; i
<= MAXCOL
; ++i
)
124 aCol
[i
].PreprocessDBDataUpdate(rEndListenCxt
, rCompileCxt
);
127 void ScTable::CompileHybridFormula(
128 sc::StartListeningContext
& rStartListenCxt
, sc::CompileFormulaContext
& rCompileCxt
)
130 for (SCCOL i
= 0; i
<= MAXCOL
; ++i
)
131 aCol
[i
].CompileHybridFormula(rStartListenCxt
, rCompileCxt
);
134 void ScTable::UpdateScriptTypes( SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
)
136 if (!ValidCol(nCol1
) || !ValidCol(nCol2
) || nCol1
> nCol2
)
139 for (SCCOL nCol
= nCol1
; nCol
<= nCol2
; ++nCol
)
140 aCol
[nCol
].UpdateScriptTypes(nRow1
, nRow2
);
143 bool ScTable::HasUniformRowHeight( SCROW nRow1
, SCROW nRow2
) const
145 if (!ValidRow(nRow1
) || !ValidRow(nRow2
) || nRow1
> nRow2
)
148 ScFlatUInt16RowSegments::RangeData aData
;
149 if (!mpRowHeights
->getRangeData(nRow1
, aData
))
153 return nRow2
<= aData
.mnRow2
;
156 void ScTable::SplitFormulaGroups( SCCOL nCol
, std::vector
<SCROW
>& rRows
)
161 sc::SharedFormulaUtil::splitFormulaCellGroups(aCol
[nCol
].maCells
, rRows
);
164 void ScTable::UnshareFormulaCells( SCCOL nCol
, std::vector
<SCROW
>& rRows
)
169 sc::SharedFormulaUtil::unshareFormulaCells(aCol
[nCol
].maCells
, rRows
);
172 void ScTable::RegroupFormulaCells( SCCOL nCol
)
177 aCol
[nCol
].RegroupFormulaCells();
180 void ScTable::CollectListeners(
181 std::vector
<SvtListener
*>& rListeners
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
)
183 if (nCol2
< nCol1
|| !ValidCol(nCol1
) || !ValidCol(nCol2
))
186 for (SCCOL nCol
= nCol1
; nCol
<= nCol2
; ++nCol
)
187 aCol
[nCol
].CollectListeners(rListeners
, nRow1
, nRow2
);
190 bool ScTable::HasFormulaCell( SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
) const
192 if (nCol2
< nCol1
|| !ValidCol(nCol1
) || !ValidCol(nCol2
))
195 for (SCCOL nCol
= nCol1
; nCol
<= nCol2
; ++nCol
)
196 if (aCol
[nCol
].HasFormulaCell(nRow1
, nRow2
))
202 void ScTable::EndListeningIntersectedGroup(
203 sc::EndListeningContext
& rCxt
, SCCOL nCol
, SCROW nRow
, std::vector
<ScAddress
>* pGroupPos
)
208 aCol
[nCol
].EndListeningIntersectedGroup(rCxt
, nRow
, pGroupPos
);
211 void ScTable::EndListeningIntersectedGroups(
212 sc::EndListeningContext
& rCxt
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
,
213 std::vector
<ScAddress
>* pGroupPos
)
215 if (nCol2
< nCol1
|| !ValidCol(nCol1
) || !ValidCol(nCol2
))
218 for (SCCOL nCol
= nCol1
; nCol
<= nCol2
; ++nCol
)
219 aCol
[nCol
].EndListeningIntersectedGroups(rCxt
, nRow1
, nRow2
, pGroupPos
);
222 void ScTable::EndListeningGroup( sc::EndListeningContext
& rCxt
, SCCOL nCol
, SCROW nRow
)
227 aCol
[nCol
].EndListeningGroup(rCxt
, nRow
);
230 void ScTable::SetNeedsListeningGroup( SCCOL nCol
, SCROW nRow
)
235 aCol
[nCol
].SetNeedsListeningGroup(nRow
);
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */