1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2008 by Sun Microsystems, Inc. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * $RCSfile: interpr4.cxx,v $ 10 * $Revision: 1.57.92.5 $ 11 * 12 * This file is part of OpenOffice.org. 13 * 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. 17 * 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). 23 * 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. 28 * 29 ************************************************************************/ 30 31 // MARKER(update_precomp.py): autogen include statement, do not remove 32 #include "precompiled_sc.hxx" 33 34 // INCLUDE --------------------------------------------------------------- 35 36 #include "queryparam.hxx" 37 38 using ::std::vector; 39 40 // ============================================================================ 41 42 ScQueryParamBase::ScQueryParamBase() 43 { 44 Resize( MAXQUERY ); 45 for (sal_uInt16 i=0; i<MAXQUERY; i++) 46 maEntries[i].Clear(); 47 } 48 49 ScQueryParamBase::ScQueryParamBase(const ScQueryParamBase& r) : 50 bHasHeader(r.bHasHeader), bByRow(r.bByRow), bInplace(r.bInplace), bCaseSens(r.bCaseSens), 51 bRegExp(r.bRegExp), bDuplicate(r.bDuplicate), bMixedComparison(r.bMixedComparison), 52 maEntries(r.maEntries) 53 { 54 } 55 56 ScQueryParamBase::~ScQueryParamBase() 57 { 58 } 59 60 SCSIZE ScQueryParamBase::GetEntryCount() const 61 { 62 return maEntries.size(); 63 } 64 65 ScQueryEntry& ScQueryParamBase::GetEntry(SCSIZE n) const 66 { 67 return maEntries[n]; 68 } 69 70 void ScQueryParamBase::Resize(SCSIZE nNew) 71 { 72 if ( nNew < MAXQUERY ) 73 nNew = MAXQUERY; // nie weniger als MAXQUERY 74 75 vector<ScQueryEntry> aNewEntries(nNew); 76 SCSIZE nCopy = ::std::min(maEntries.size(), nNew); 77 for (SCSIZE i=0; i<nCopy; i++) 78 aNewEntries[i] = maEntries[i]; 79 80 maEntries.swap(aNewEntries); 81 } 82 83 void ScQueryParamBase::DeleteQuery( SCSIZE nPos ) 84 { 85 if (nPos >= maEntries.size()) 86 return; 87 88 size_t n = maEntries.size(); 89 vector<ScQueryEntry> aNewEntries; 90 aNewEntries.reserve(n); 91 for (size_t i = 0; i < n; ++i) 92 if (i != nPos) 93 aNewEntries.push_back(maEntries[i]); 94 95 // Don't forget to append an empty entry to make up for the removed one. 96 // The size of the entries is not supposed to change. 97 aNewEntries.push_back(ScQueryEntry()); 98 99 maEntries.swap(aNewEntries); 100 } 101 102 void ScQueryParamBase::FillInExcelSyntax(String& aCellStr, SCSIZE nIndex) 103 { 104 if (aCellStr.Len() > 0) 105 { 106 if ( nIndex >= maEntries.size() ) 107 Resize( nIndex+1 ); 108 109 ScQueryEntry& rEntry = GetEntry(nIndex); 110 111 rEntry.bDoQuery = sal_True; 112 // Operatoren herausfiltern 113 if (aCellStr.GetChar(0) == '<') 114 { 115 if (aCellStr.GetChar(1) == '>') 116 { 117 *rEntry.pStr = aCellStr.Copy(2); 118 rEntry.eOp = SC_NOT_EQUAL; 119 } 120 else if (aCellStr.GetChar(1) == '=') 121 { 122 *rEntry.pStr = aCellStr.Copy(2); 123 rEntry.eOp = SC_LESS_EQUAL; 124 } 125 else 126 { 127 *rEntry.pStr = aCellStr.Copy(1); 128 rEntry.eOp = SC_LESS; 129 } 130 } 131 else if (aCellStr.GetChar(0) == '>') 132 { 133 if (aCellStr.GetChar(1) == '=') 134 { 135 *rEntry.pStr = aCellStr.Copy(2); 136 rEntry.eOp = SC_GREATER_EQUAL; 137 } 138 else 139 { 140 *rEntry.pStr = aCellStr.Copy(1); 141 rEntry.eOp = SC_GREATER; 142 } 143 } 144 else 145 { 146 if (aCellStr.GetChar(0) == '=') 147 *rEntry.pStr = aCellStr.Copy(1); 148 else 149 *rEntry.pStr = aCellStr; 150 rEntry.eOp = SC_EQUAL; 151 } 152 } 153 } 154 155 // ============================================================================ 156 157 ScQueryParamTable::ScQueryParamTable() 158 { 159 } 160 161 ScQueryParamTable::ScQueryParamTable(const ScQueryParamTable& r) : 162 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nTab(r.nTab) 163 { 164 } 165 166 ScQueryParamTable::~ScQueryParamTable() 167 { 168 } 169 170 // ============================================================================ 171 172 ScQueryParam::ScQueryParam() : 173 ScQueryParamBase(), 174 ScQueryParamTable(), 175 bDestPers(true), 176 nDestTab(0), 177 nDestCol(0), 178 nDestRow(0) 179 { 180 Clear(); 181 } 182 183 //------------------------------------------------------------------------ 184 185 ScQueryParam::ScQueryParam( const ScQueryParam& r ) : 186 ScQueryParamBase(r), 187 ScQueryParamTable(r), 188 bDestPers(r.bDestPers), nDestTab(r.nDestTab), nDestCol(r.nDestCol), nDestRow(r.nDestRow) 189 { 190 } 191 192 ScQueryParam::ScQueryParam( const ScDBQueryParamInternal& r ) : 193 ScQueryParamBase(r), 194 ScQueryParamTable(r), 195 bDestPers(true), 196 nDestTab(0), 197 nDestCol(0), 198 nDestRow(0) 199 { 200 } 201 202 203 //------------------------------------------------------------------------ 204 205 ScQueryParam::~ScQueryParam() 206 { 207 } 208 209 //------------------------------------------------------------------------ 210 211 void ScQueryParam::Clear() 212 { 213 nCol1=nCol2 = 0; 214 nRow1=nRow2 = 0; 215 nTab = SCTAB_MAX; 216 bHasHeader = bCaseSens = bRegExp = bMixedComparison = sal_False; 217 bInplace = bByRow = bDuplicate = sal_True; 218 219 Resize( MAXQUERY ); 220 for (sal_uInt16 i=0; i<MAXQUERY; i++) 221 maEntries[i].Clear(); 222 223 ClearDestParams(); 224 } 225 226 void ScQueryParam::ClearDestParams() 227 { 228 bDestPers = true; 229 nDestTab = 0; 230 nDestCol = 0; 231 nDestRow = 0; 232 } 233 234 //------------------------------------------------------------------------ 235 236 ScQueryParam& ScQueryParam::operator=( const ScQueryParam& r ) 237 { 238 nCol1 = r.nCol1; 239 nRow1 = r.nRow1; 240 nCol2 = r.nCol2; 241 nRow2 = r.nRow2; 242 nTab = r.nTab; 243 nDestTab = r.nDestTab; 244 nDestCol = r.nDestCol; 245 nDestRow = r.nDestRow; 246 bHasHeader = r.bHasHeader; 247 bInplace = r.bInplace; 248 bCaseSens = r.bCaseSens; 249 bRegExp = r.bRegExp; 250 bMixedComparison = r.bMixedComparison; 251 bDuplicate = r.bDuplicate; 252 bByRow = r.bByRow; 253 bDestPers = r.bDestPers; 254 255 maEntries = r.maEntries; 256 257 return *this; 258 } 259 260 //------------------------------------------------------------------------ 261 262 sal_Bool ScQueryParam::operator==( const ScQueryParam& rOther ) const 263 { 264 sal_Bool bEqual = sal_False; 265 266 // Anzahl der Queries gleich? 267 SCSIZE nUsed = 0; 268 SCSIZE nOtherUsed = 0; 269 SCSIZE nEntryCount = GetEntryCount(); 270 SCSIZE nOtherEntryCount = rOther.GetEntryCount(); 271 272 while ( nUsed<nEntryCount && maEntries[nUsed].bDoQuery ) ++nUsed; 273 while ( nOtherUsed<nOtherEntryCount && rOther.maEntries[nOtherUsed].bDoQuery ) 274 ++nOtherUsed; 275 276 if ( (nUsed == nOtherUsed) 277 && (nCol1 == rOther.nCol1) 278 && (nRow1 == rOther.nRow1) 279 && (nCol2 == rOther.nCol2) 280 && (nRow2 == rOther.nRow2) 281 && (nTab == rOther.nTab) 282 && (bHasHeader == rOther.bHasHeader) 283 && (bByRow == rOther.bByRow) 284 && (bInplace == rOther.bInplace) 285 && (bCaseSens == rOther.bCaseSens) 286 && (bRegExp == rOther.bRegExp) 287 && (bMixedComparison == rOther.bMixedComparison) 288 && (bDuplicate == rOther.bDuplicate) 289 && (bDestPers == rOther.bDestPers) 290 && (nDestTab == rOther.nDestTab) 291 && (nDestCol == rOther.nDestCol) 292 && (nDestRow == rOther.nDestRow) ) 293 { 294 bEqual = sal_True; 295 for ( SCSIZE i=0; i<nUsed && bEqual; i++ ) 296 bEqual = maEntries[i] == rOther.maEntries[i]; 297 } 298 return bEqual; 299 } 300 301 //------------------------------------------------------------------------ 302 303 void ScQueryParam::MoveToDest() 304 { 305 if (!bInplace) 306 { 307 SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1); 308 SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1); 309 SCsTAB nDifZ = ((SCsTAB) nDestTab) - ((SCsTAB) nTab); 310 311 nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX ); 312 nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY ); 313 nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX ); 314 nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY ); 315 nTab = sal::static_int_cast<SCTAB>( nTab + nDifZ ); 316 size_t n = maEntries.size(); 317 for (size_t i=0; i<n; i++) 318 maEntries[i].nField += nDifX; 319 320 bInplace = sal_True; 321 } 322 else 323 { 324 DBG_ERROR("MoveToDest, bInplace == TRUE"); 325 } 326 } 327 328 // ============================================================================ 329 330 ScDBQueryParamBase::ScDBQueryParamBase(DataType eType) : 331 ScQueryParamBase(), 332 mnField(-1), 333 mbSkipString(true), 334 meType(eType) 335 { 336 } 337 338 ScDBQueryParamBase::~ScDBQueryParamBase() 339 { 340 } 341 342 ScDBQueryParamBase::DataType ScDBQueryParamBase::GetType() const 343 { 344 return meType; 345 } 346 347 // ============================================================================ 348 349 ScDBQueryParamInternal::ScDBQueryParamInternal() : 350 ScDBQueryParamBase(ScDBQueryParamBase::INTERNAL), 351 ScQueryParamTable() 352 { 353 } 354 355 ScDBQueryParamInternal::~ScDBQueryParamInternal() 356 { 357 } 358 359 // ============================================================================ 360 361 ScDBQueryParamMatrix::ScDBQueryParamMatrix() : 362 ScDBQueryParamBase(ScDBQueryParamBase::MATRIX) 363 { 364 } 365 366 ScDBQueryParamMatrix::~ScDBQueryParamMatrix() 367 { 368 } 369 370