update dev300-m58
[ooovba.git] / sc / source / core / data / clipparam.cxx
blobb2ec555a0d5c80f6fb00c2d240e14d6b0563df87
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 ScRange& rRange, bool bCutMode) :
47 meDirection(Unspecified),
48 mbCutMode(bCutMode)
50 maRanges.Append(rRange);
53 ScClipParam::ScClipParam(const ScClipParam& r) :
54 maRanges(r.maRanges),
55 meDirection(r.meDirection),
56 mbCutMode(r.mbCutMode)
60 bool ScClipParam::isMultiRange() const
62 return maRanges.Count() > 1;
65 SCCOL ScClipParam::getPasteColSize()
67 if (!maRanges.Count())
68 return 0;
70 switch (meDirection)
72 case ScClipParam::Column:
74 SCCOL nColSize = 0;
75 for (ScRangePtr p = maRanges.First(); p; p = maRanges.Next())
76 nColSize += p->aEnd.Col() - p->aStart.Col() + 1;
77 return nColSize;
79 case ScClipParam::Row:
81 // We assume that all ranges have identical column size.
82 const ScRange& rRange = *maRanges.First();
83 return rRange.aEnd.Col() - rRange.aStart.Col() + 1;
85 case ScClipParam::Unspecified:
86 default:
89 return 0;
92 SCROW ScClipParam::getPasteRowSize()
94 if (!maRanges.Count())
95 return 0;
97 switch (meDirection)
99 case ScClipParam::Column:
101 // We assume that all ranges have identical row size.
102 const ScRange& rRange = *maRanges.First();
103 return rRange.aEnd.Row() - rRange.aStart.Row() + 1;
105 case ScClipParam::Row:
107 SCROW nRowSize = 0;
108 for (ScRangePtr p = maRanges.First(); p; p = maRanges.Next())
109 nRowSize += p->aEnd.Row() - p->aStart.Row() + 1;
110 return nRowSize;
112 case ScClipParam::Unspecified:
113 default:
116 return 0;
119 ScRange ScClipParam::getWholeRange() const
121 ScRange aWhole;
122 bool bFirst = true;
123 ScRangeList aRanges = maRanges;
124 for (ScRange* p = aRanges.First(); p; p = aRanges.Next())
126 if (bFirst)
128 aWhole = *p;
129 bFirst = false;
130 continue;
133 if (aWhole.aStart.Col() > p->aStart.Col())
134 aWhole.aStart.SetCol(p->aStart.Col());
136 if (aWhole.aStart.Row() > p->aStart.Row())
137 aWhole.aStart.SetRow(p->aStart.Row());
139 if (aWhole.aEnd.Col() < p->aEnd.Col())
140 aWhole.aEnd.SetCol(p->aEnd.Col());
142 if (aWhole.aEnd.Row() < p->aEnd.Row())
143 aWhole.aEnd.SetRow(p->aEnd.Row());
145 return aWhole;
148 void ScClipParam::transpose()
150 switch (meDirection)
152 case Column:
153 meDirection = ScClipParam::Row;
154 break;
155 case Row:
156 meDirection = ScClipParam::Column;
157 break;
158 case Unspecified:
159 default:
163 ScRangeList aNewRanges;
164 if (maRanges.Count())
166 ScRange* p = maRanges.First();
167 SCCOL nColOrigin = p->aStart.Col();
168 SCROW nRowOrigin = p->aStart.Row();
169 for (; p; p = maRanges.Next())
171 SCCOL nColDelta = p->aStart.Col() - nColOrigin;
172 SCROW nRowDelta = p->aStart.Row() - nRowOrigin;
173 SCCOL nCol1 = 0;
174 SCCOL nCol2 = static_cast<SCCOL>(p->aEnd.Row() - p->aStart.Row());
175 SCROW nRow1 = 0;
176 SCROW nRow2 = static_cast<SCROW>(p->aEnd.Col() - p->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 ScRange aNew(nCol1, nRow1, p->aStart.Tab(), nCol2, nRow2, p->aStart.Tab());
182 aNewRanges.Append(aNew);
185 maRanges = aNewRanges;
188 // ============================================================================
190 ScClipRangeNameData::ScClipRangeNameData() :
191 mbReplace(false)
195 ScClipRangeNameData::~ScClipRangeNameData()
199 void ScClipRangeNameData::insert(sal_uInt16 nOldIndex, sal_uInt16 nNewIndex)
201 maRangeMap.insert(
202 ScRangeData::IndexMap::value_type(nOldIndex, nNewIndex));