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"
40 ScClipParam::ScClipParam() :
41 meDirection(Unspecified
),
46 ScClipParam::ScClipParam(const ScClipParam
& r
) :
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())
65 case ScClipParam::Column
:
68 for (ScRangePtr p
= maRanges
.First(); p
; p
= maRanges
.Next())
69 nColSize
+= p
->aEnd
.Col() - p
->aStart
.Col() + 1;
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;
80 case ScClipParam::Unspecified
:
87 SCROW
ScClipParam::getPasteRowSize()
89 if (!maRanges
.Count())
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;
101 case ScClipParam::Row
:
104 for (ScRangePtr p
= maRanges
.First(); p
; p
= maRanges
.Next())
105 nRowSize
+= p
->aEnd
.Row() - p
->aStart
.Row() + 1;
109 case ScClipParam::Unspecified
:
116 ScRange
ScClipParam::getWholeRange() const
120 ScRangeList aRanges
= maRanges
;
121 for (ScRange
* p
= aRanges
.First(); p
; p
= aRanges
.Next())
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());
145 void ScClipParam::transpose()
150 meDirection
= ScClipParam::Row
;
153 meDirection
= ScClipParam::Column
;
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
;
171 SCCOL nCol2
= static_cast<SCCOL
>(p
->aEnd
.Row() - p
->aStart
.Row());
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() :
192 ScClipRangeNameData::~ScClipRangeNameData()
196 void ScClipRangeNameData::insert(sal_uInt16 nOldIndex
, sal_uInt16 nNewIndex
)
199 ScRangeData::IndexMap::value_type(nOldIndex
, nNewIndex
));