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"
24 ScClipParam::ScClipParam() :
25 meDirection(Unspecified
),
31 ScClipParam::ScClipParam(const ScRange
& rRange
, bool bCutMode
) :
32 meDirection(Unspecified
),
36 maRanges
.Append(rRange
);
39 bool ScClipParam::isMultiRange() const
41 return maRanges
.size() > 1;
44 SCCOL
ScClipParam::getPasteColSize()
51 case ScClipParam::Column
:
54 for ( size_t i
= 0, nListSize
= maRanges
.size(); i
< nListSize
; ++i
)
56 ScRange
* p
= maRanges
[ i
];
57 nColSize
+= p
->aEnd
.Col() - p
->aStart
.Col() + 1;
61 case ScClipParam::Row
:
63 // We assume that all ranges have identical column size.
64 const ScRange
& rRange
= *maRanges
.front();
65 return rRange
.aEnd
.Col() - rRange
.aStart
.Col() + 1;
67 case ScClipParam::Unspecified
:
74 SCROW
ScClipParam::getPasteRowSize()
81 case ScClipParam::Column
:
83 // We assume that all ranges have identical row size.
84 const ScRange
& rRange
= *maRanges
.front();
85 return rRange
.aEnd
.Row() - rRange
.aStart
.Row() + 1;
87 case ScClipParam::Row
:
90 for ( size_t i
= 0, nListSize
= maRanges
.size(); i
< nListSize
; ++i
)
92 ScRange
* p
= maRanges
[ i
];
93 nRowSize
+= p
->aEnd
.Row() - p
->aStart
.Row() + 1;
97 case ScClipParam::Unspecified
:
104 ScRange
ScClipParam::getWholeRange() const
106 return maRanges
.Combine();
109 void ScClipParam::transpose()
114 meDirection
= ScClipParam::Row
;
117 meDirection
= ScClipParam::Column
;
124 ScRangeList aNewRanges
;
125 if (!maRanges
.empty())
127 ScRange
* p
= maRanges
.front();
128 SCCOL nColOrigin
= p
->aStart
.Col();
129 SCROW nRowOrigin
= p
->aStart
.Row();
131 for ( size_t i
= 0, n
= maRanges
.size(); i
< n
; ++i
)
134 SCCOL nColDelta
= p
->aStart
.Col() - nColOrigin
;
135 SCROW nRowDelta
= p
->aStart
.Row() - nRowOrigin
;
137 SCCOL nCol2
= static_cast<SCCOL
>(p
->aEnd
.Row() - p
->aStart
.Row());
139 SCROW nRow2
= static_cast<SCROW
>(p
->aEnd
.Col() - p
->aStart
.Col());
140 nCol1
+= static_cast<SCCOL
>(nRowDelta
);
141 nCol2
+= static_cast<SCCOL
>(nRowDelta
);
142 nRow1
+= static_cast<SCROW
>(nColDelta
);
143 nRow2
+= static_cast<SCROW
>(nColDelta
);
144 aNewRanges
.push_back( new ScRange(nCol1
, nRow1
, p
->aStart
.Tab(), nCol2
, nRow2
, p
->aStart
.Tab() ) );
147 maRanges
= aNewRanges
;
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */