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 ScRange
& rRange
, bool bCutMode
) :
47 meDirection(Unspecified
),
50 maRanges
.Append(rRange
);
53 ScClipParam::ScClipParam(const ScClipParam
& r
) :
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())
72 case ScClipParam::Column
:
75 for (ScRangePtr p
= maRanges
.First(); p
; p
= maRanges
.Next())
76 nColSize
+= p
->aEnd
.Col() - p
->aStart
.Col() + 1;
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
:
92 SCROW
ScClipParam::getPasteRowSize()
94 if (!maRanges
.Count())
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
:
108 for (ScRangePtr p
= maRanges
.First(); p
; p
= maRanges
.Next())
109 nRowSize
+= p
->aEnd
.Row() - p
->aStart
.Row() + 1;
112 case ScClipParam::Unspecified
:
119 ScRange
ScClipParam::getWholeRange() const
123 ScRangeList aRanges
= maRanges
;
124 for (ScRange
* p
= aRanges
.First(); p
; p
= aRanges
.Next())
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());
148 void ScClipParam::transpose()
153 meDirection
= ScClipParam::Row
;
156 meDirection
= ScClipParam::Column
;
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
;
174 SCCOL nCol2
= static_cast<SCCOL
>(p
->aEnd
.Row() - p
->aStart
.Row());
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() :
195 ScClipRangeNameData::~ScClipRangeNameData()
199 void ScClipRangeNameData::insert(sal_uInt16 nOldIndex
, sal_uInt16 nNewIndex
)
202 ScRangeData::IndexMap::value_type(nOldIndex
, nNewIndex
));