1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sc.hxx" 26 27 // INCLUDE --------------------------------------------------------------- 28 29 #include "clipparam.hxx" 30 31 using ::std::vector; 32 33 ScClipParam::ScClipParam() : 34 meDirection(Unspecified), 35 mbCutMode(false), 36 mnSourceDocID(0) 37 { 38 } 39 40 ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) : 41 meDirection(Unspecified), 42 mbCutMode(bCutMode), 43 mnSourceDocID(0) 44 { 45 maRanges.Append(rRange); 46 } 47 48 ScClipParam::ScClipParam(const ScClipParam& r) : 49 maRanges(r.maRanges), 50 meDirection(r.meDirection), 51 mbCutMode(r.mbCutMode), 52 mnSourceDocID(r.mnSourceDocID), 53 maProtectedChartRangesVector(r.maProtectedChartRangesVector) 54 { 55 } 56 57 bool ScClipParam::isMultiRange() const 58 { 59 return maRanges.Count() > 1; 60 } 61 62 SCCOL ScClipParam::getPasteColSize() 63 { 64 if (!maRanges.Count()) 65 return 0; 66 67 switch (meDirection) 68 { 69 case ScClipParam::Column: 70 { 71 SCCOL nColSize = 0; 72 for (ScRangePtr p = maRanges.First(); p; p = maRanges.Next()) 73 nColSize += p->aEnd.Col() - p->aStart.Col() + 1; 74 return nColSize; 75 } 76 case ScClipParam::Row: 77 { 78 // We assume that all ranges have identical column size. 79 const ScRange& rRange = *maRanges.First(); 80 return rRange.aEnd.Col() - rRange.aStart.Col() + 1; 81 } 82 case ScClipParam::Unspecified: 83 default: 84 ; 85 } 86 return 0; 87 } 88 89 SCROW ScClipParam::getPasteRowSize() 90 { 91 if (!maRanges.Count()) 92 return 0; 93 94 switch (meDirection) 95 { 96 case ScClipParam::Column: 97 { 98 // We assume that all ranges have identical row size. 99 const ScRange& rRange = *maRanges.First(); 100 return rRange.aEnd.Row() - rRange.aStart.Row() + 1; 101 } 102 case ScClipParam::Row: 103 { 104 SCROW nRowSize = 0; 105 for (ScRangePtr p = maRanges.First(); p; p = maRanges.Next()) 106 nRowSize += p->aEnd.Row() - p->aStart.Row() + 1; 107 return nRowSize; 108 } 109 case ScClipParam::Unspecified: 110 default: 111 ; 112 } 113 return 0; 114 } 115 116 ScRange ScClipParam::getWholeRange() const 117 { 118 ScRange aWhole; 119 bool bFirst = true; 120 ScRangeList aRanges = maRanges; 121 for (ScRange* p = aRanges.First(); p; p = aRanges.Next()) 122 { 123 if (bFirst) 124 { 125 aWhole = *p; 126 bFirst = false; 127 continue; 128 } 129 130 if (aWhole.aStart.Col() > p->aStart.Col()) 131 aWhole.aStart.SetCol(p->aStart.Col()); 132 133 if (aWhole.aStart.Row() > p->aStart.Row()) 134 aWhole.aStart.SetRow(p->aStart.Row()); 135 136 if (aWhole.aEnd.Col() < p->aEnd.Col()) 137 aWhole.aEnd.SetCol(p->aEnd.Col()); 138 139 if (aWhole.aEnd.Row() < p->aEnd.Row()) 140 aWhole.aEnd.SetRow(p->aEnd.Row()); 141 } 142 return aWhole; 143 } 144 145 void ScClipParam::transpose() 146 { 147 switch (meDirection) 148 { 149 case Column: 150 meDirection = ScClipParam::Row; 151 break; 152 case Row: 153 meDirection = ScClipParam::Column; 154 break; 155 case Unspecified: 156 default: 157 ; 158 } 159 160 ScRangeList aNewRanges; 161 if (maRanges.Count()) 162 { 163 ScRange* p = maRanges.First(); 164 SCCOL nColOrigin = p->aStart.Col(); 165 SCROW nRowOrigin = p->aStart.Row(); 166 for (; p; p = maRanges.Next()) 167 { 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); 180 } 181 } 182 maRanges = aNewRanges; 183 } 184 185 // ============================================================================ 186 187 ScClipRangeNameData::ScClipRangeNameData() : 188 mbReplace(false) 189 { 190 } 191 192 ScClipRangeNameData::~ScClipRangeNameData() 193 { 194 } 195 196 void ScClipRangeNameData::insert(sal_uInt16 nOldIndex, sal_uInt16 nNewIndex) 197 { 198 maRangeMap.insert( 199 ScRangeData::IndexMap::value_type(nOldIndex, nNewIndex)); 200 } 201