update dev300-m57
[ooovba.git] / sc / source / core / data / clipparam.cxx
blob564b04d858fd11001a86e26a3974e7ce4801ebbe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: document.cxx,v $
10 * $Revision: 1.90.36.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // INCLUDE ---------------------------------------------------------------
36 #include "clipparam.hxx"
38 using ::std::vector;
40 ScClipParam::ScClipParam() :
41 meDirection(Unspecified),
42 mbCutMode(false)
46 ScClipParam::ScClipParam(const ScClipParam& r) :
47 maRanges(r.maRanges),
48 meDirection(r.meDirection),
49 mbCutMode(r.mbCutMode)
53 bool ScClipParam::isMultiRange() const
55 return maRanges.Count() > 1;
58 SCCOL ScClipParam::getPasteColSize()
60 if (!maRanges.Count())
61 return 0;
63 switch (meDirection)
65 case ScClipParam::Column:
67 SCCOL nColSize = 0;
68 for (ScRangePtr p = maRanges.First(); p; p = maRanges.Next())
69 nColSize += p->aEnd.Col() - p->aStart.Col() + 1;
70 return nColSize;
72 break;
73 case ScClipParam::Row:
75 // We assume that all ranges have identical column size.
76 const ScRange& rRange = *maRanges.First();
77 return rRange.aEnd.Col() - rRange.aStart.Col() + 1;
79 break;
80 case ScClipParam::Unspecified:
81 default:
84 return 0;
87 SCROW ScClipParam::getPasteRowSize()
89 if (!maRanges.Count())
90 return 0;
92 switch (meDirection)
94 case ScClipParam::Column:
96 // We assume that all ranges have identical row size.
97 const ScRange& rRange = *maRanges.First();
98 return rRange.aEnd.Row() - rRange.aStart.Row() + 1;
100 break;
101 case ScClipParam::Row:
103 SCROW nRowSize = 0;
104 for (ScRangePtr p = maRanges.First(); p; p = maRanges.Next())
105 nRowSize += p->aEnd.Row() - p->aStart.Row() + 1;
106 return nRowSize;
108 break;
109 case ScClipParam::Unspecified:
110 default:
113 return 0;
116 ScRange ScClipParam::getWholeRange() const
118 ScRange aWhole;
119 bool bFirst = true;
120 ScRangeList aRanges = maRanges;
121 for (ScRange* p = aRanges.First(); p; p = aRanges.Next())
123 if (bFirst)
125 aWhole = *p;
126 bFirst = false;
127 continue;
130 if (aWhole.aStart.Col() > p->aStart.Col())
131 aWhole.aStart.SetCol(p->aStart.Col());
133 if (aWhole.aStart.Row() > p->aStart.Row())
134 aWhole.aStart.SetRow(p->aStart.Row());
136 if (aWhole.aEnd.Col() < p->aEnd.Col())
137 aWhole.aEnd.SetCol(p->aEnd.Col());
139 if (aWhole.aEnd.Row() < p->aEnd.Row())
140 aWhole.aEnd.SetRow(p->aEnd.Row());
142 return aWhole;
145 void ScClipParam::transpose()
147 switch (meDirection)
149 case Column:
150 meDirection = ScClipParam::Row;
151 break;
152 case Row:
153 meDirection = ScClipParam::Column;
154 break;
155 case Unspecified:
156 default:
160 ScRangeList aNewRanges;
161 if (maRanges.Count())
163 ScRange* p = maRanges.First();
164 SCCOL nColOrigin = p->aStart.Col();
165 SCROW nRowOrigin = p->aStart.Row();
166 for (; p; p = maRanges.Next())
168 SCCOL nColDelta = p->aStart.Col() - nColOrigin;
169 SCROW nRowDelta = p->aStart.Row() - nRowOrigin;
170 SCCOL nCol1 = 0;
171 SCCOL nCol2 = static_cast<SCCOL>(p->aEnd.Row() - p->aStart.Row());
172 SCROW nRow1 = 0;
173 SCROW nRow2 = static_cast<SCROW>(p->aEnd.Col() - p->aStart.Col());
174 nCol1 += static_cast<SCCOL>(nRowDelta);
175 nCol2 += static_cast<SCCOL>(nRowDelta);
176 nRow1 += static_cast<SCROW>(nColDelta);
177 nRow2 += static_cast<SCROW>(nColDelta);
178 ScRange aNew(nCol1, nRow1, p->aStart.Tab(), nCol2, nRow2, p->aStart.Tab());
179 aNewRanges.Append(aNew);
182 maRanges = aNewRanges;
185 // ============================================================================
187 ScClipRangeNameData::ScClipRangeNameData() :
188 mbReplace(false)
192 ScClipRangeNameData::~ScClipRangeNameData()
196 void ScClipRangeNameData::insert(sal_uInt16 nOldIndex, sal_uInt16 nNewIndex)
198 maRangeMap.insert(
199 ScRangeData::IndexMap::value_type(nOldIndex, nNewIndex));