Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / data / clipparam.cxx
blob3935141976af990818688801dc70f6e0aceb380c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 using ::std::vector;
24 ScClipParam::ScClipParam() :
25 meDirection(Unspecified),
26 mbCutMode(false),
27 mnSourceDocID(0)
31 ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) :
32 meDirection(Unspecified),
33 mbCutMode(bCutMode),
34 mnSourceDocID(0)
36 maRanges.Append(rRange);
39 ScClipParam::ScClipParam(const ScClipParam& r) :
40 maRanges(r.maRanges),
41 meDirection(r.meDirection),
42 mbCutMode(r.mbCutMode),
43 mnSourceDocID(r.mnSourceDocID),
44 maProtectedChartRangesVector(r.maProtectedChartRangesVector)
48 bool ScClipParam::isMultiRange() const
50 return maRanges.size() > 1;
53 SCCOL ScClipParam::getPasteColSize()
55 if (maRanges.empty())
56 return 0;
58 switch (meDirection)
60 case ScClipParam::Column:
62 SCCOL nColSize = 0;
63 for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
65 ScRange* p = maRanges[ i ];
66 nColSize += p->aEnd.Col() - p->aStart.Col() + 1;
68 return nColSize;
70 case ScClipParam::Row:
72 // We assume that all ranges have identical column size.
73 const ScRange& rRange = *maRanges.front();
74 return rRange.aEnd.Col() - rRange.aStart.Col() + 1;
76 case ScClipParam::Unspecified:
77 default:
80 return 0;
83 SCROW ScClipParam::getPasteRowSize()
85 if (maRanges.empty())
86 return 0;
88 switch (meDirection)
90 case ScClipParam::Column:
92 // We assume that all ranges have identical row size.
93 const ScRange& rRange = *maRanges.front();
94 return rRange.aEnd.Row() - rRange.aStart.Row() + 1;
96 case ScClipParam::Row:
98 SCROW nRowSize = 0;
99 for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
101 ScRange* p = maRanges[ i ];
102 nRowSize += p->aEnd.Row() - p->aStart.Row() + 1;
104 return nRowSize;
106 case ScClipParam::Unspecified:
107 default:
110 return 0;
113 ScRange ScClipParam::getWholeRange() const
115 return maRanges.Combine();
118 void ScClipParam::transpose()
120 switch (meDirection)
122 case Column:
123 meDirection = ScClipParam::Row;
124 break;
125 case Row:
126 meDirection = ScClipParam::Column;
127 break;
128 case Unspecified:
129 default:
133 ScRangeList aNewRanges;
134 if (!maRanges.empty())
136 ScRange* p = maRanges.front();
137 SCCOL nColOrigin = p->aStart.Col();
138 SCROW nRowOrigin = p->aStart.Row();
140 for ( size_t i = 0, n = maRanges.size(); i < n; ++i )
142 p = maRanges[ i ];
143 SCCOL nColDelta = p->aStart.Col() - nColOrigin;
144 SCROW nRowDelta = p->aStart.Row() - nRowOrigin;
145 SCCOL nCol1 = 0;
146 SCCOL nCol2 = static_cast<SCCOL>(p->aEnd.Row() - p->aStart.Row());
147 SCROW nRow1 = 0;
148 SCROW nRow2 = static_cast<SCROW>(p->aEnd.Col() - p->aStart.Col());
149 nCol1 += static_cast<SCCOL>(nRowDelta);
150 nCol2 += static_cast<SCCOL>(nRowDelta);
151 nRow1 += static_cast<SCROW>(nColDelta);
152 nRow2 += static_cast<SCROW>(nColDelta);
153 aNewRanges.push_back( new ScRange(nCol1, nRow1, p->aStart.Tab(), nCol2, nRow2, p->aStart.Tab() ) );
156 maRanges = aNewRanges;
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */