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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <clipparam.hxx>
23 ScClipParam::ScClipParam() :
24 meDirection(Unspecified
),
30 ScClipParam::ScClipParam(const ScRange
& rRange
, bool bCutMode
) :
31 meDirection(Unspecified
),
35 maRanges
.push_back(rRange
);
38 bool ScClipParam::isMultiRange() const
40 return maRanges
.size() > 1;
43 SCCOL
ScClipParam::getPasteColSize()
50 case ScClipParam::Column
:
53 for ( size_t i
= 0, nListSize
= maRanges
.size(); i
< nListSize
; ++i
)
55 const ScRange
& rRange
= maRanges
[ i
];
56 nColSize
+= rRange
.aEnd
.Col() - rRange
.aStart
.Col() + 1;
60 case ScClipParam::Row
:
62 // We assume that all ranges have identical column size.
63 const ScRange
& rRange
= maRanges
.front();
64 return rRange
.aEnd
.Col() - rRange
.aStart
.Col() + 1;
66 case ScClipParam::Unspecified
:
73 SCROW
ScClipParam::getPasteRowSize(const ScDocument
& rSrcDoc
, bool bIncludeFiltered
)
80 case ScClipParam::Column
:
82 // We assume that all ranges have identical row size.
83 const ScRange
& rRange
= maRanges
.front();
84 return bIncludeFiltered
85 ? rRange
.aEnd
.Row() - rRange
.aStart
.Row() + 1
86 : rSrcDoc
.CountNonFilteredRows(rRange
.aStart
.Row(), rRange
.aEnd
.Row(),
89 case ScClipParam::Row
:
92 for ( size_t i
= 0, nListSize
= maRanges
.size(); i
< nListSize
; ++i
)
94 const ScRange
& rRange
= maRanges
[ i
];
95 nRowSize
+= bIncludeFiltered
? rRange
.aEnd
.Row() - rRange
.aStart
.Row() + 1
96 : rSrcDoc
.CountNonFilteredRows(rRange
.aStart
.Row(),
102 case ScClipParam::Unspecified
:
109 ScRange
ScClipParam::getWholeRange() const
111 return maRanges
.Combine();
114 void ScClipParam::transpose(const ScDocument
& rSrcDoc
, bool bIncludeFiltered
,
115 bool bIsMultiRangeRowFilteredTranspose
)
122 meDirection
= ScClipParam::Row
;
125 meDirection
= ScClipParam::Column
;
132 ScRangeList aNewRanges
;
133 if (!maRanges
.empty())
135 const ScRange
& rRange1
= maRanges
.front();
136 SCCOL nColOrigin
= rRange1
.aStart
.Col();
137 SCROW nRowOrigin
= rRange1
.aStart
.Row();
139 for ( size_t i
= 0, n
= maRanges
.size(); i
< n
; ++i
)
141 const ScRange
& rRange
= maRanges
[ i
];
142 SCCOL nColDelta
= rRange
.aStart
.Col() - nColOrigin
;
143 SCROW nRowDelta
= rRange
.aStart
.Row() - nRowOrigin
;
144 SCROW nNonFilteredRows
= rSrcDoc
.CountNonFilteredRows(
145 rRange
.aStart
.Row(), rRange
.aEnd
.Row(), rRange
.aStart
.Tab());
146 if (!bIsMultiRangeRowFilteredTranspose
)
149 SCCOL nCol2
= bIncludeFiltered
150 ? static_cast<SCCOL
>(rRange
.aEnd
.Row() - rRange
.aStart
.Row())
151 : nNonFilteredRows
- 1;
153 SCROW nRow2
= static_cast<SCROW
>(rRange
.aEnd
.Col() - rRange
.aStart
.Col());
154 nCol1
+= static_cast<SCCOL
>(nRowDelta
);
155 nCol2
+= static_cast<SCCOL
>(nRowDelta
);
156 nRow1
+= static_cast<SCROW
>(nColDelta
);
157 nRow2
+= static_cast<SCROW
>(nColDelta
);
158 aNewRanges
.push_back(ScRange(nColOrigin
+ nCol1
, nRowOrigin
+ nRow1
,
159 rRange
.aStart
.Tab(), nColOrigin
+ nCol2
,
160 nRowOrigin
+ nRow2
, rRange
.aStart
.Tab()));
163 nRowCount
+= nNonFilteredRows
;
166 // Transpose of filtered multi range row selection is a special case since filtering
167 // and selection are in the same dimension (i.e. row), see ScDocument::TransposeClip()
168 if (bIsMultiRangeRowFilteredTranspose
)
170 assert(!bIncludeFiltered
&& "bIsMultiRangeRowFilteredTranspose can only be true if bIncludeFiltered is false");
171 SCCOL nColDelta
= rRange1
.aStart
.Col() - nColOrigin
;
172 SCROW nRowDelta
= rRange1
.aStart
.Row() - nRowOrigin
;
174 SCCOL nCol2
= nRowCount
- 1;
176 SCROW nRow2
= static_cast<SCROW
>(rRange1
.aEnd
.Col() - rRange1
.aStart
.Col());
177 nCol1
+= static_cast<SCCOL
>(nRowDelta
);
178 nCol2
+= static_cast<SCCOL
>(nRowDelta
);
179 nRow1
+= static_cast<SCROW
>(nColDelta
);
180 nRow2
+= static_cast<SCROW
>(nColDelta
);
181 aNewRanges
.push_back(ScRange(nColOrigin
+ nCol1
, nRowOrigin
+ nRow1
,
182 rRange1
.aStart
.Tab(), nColOrigin
+ nCol2
,
183 nRowOrigin
+ nRow2
, rRange1
.aStart
.Tab()));
186 maRanges
= std::move(aNewRanges
);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */