merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / tool / queryparam.cxx
blob059353431e29e877d73c464b2686961512480689
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: interpr4.cxx,v $
10 * $Revision: 1.57.92.5 $
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 "queryparam.hxx"
38 using ::std::vector;
40 // ============================================================================
42 ScQueryParamBase::ScQueryParamBase()
44 Resize( MAXQUERY );
45 for (USHORT i=0; i<MAXQUERY; i++)
46 maEntries[i].Clear();
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)
56 ScQueryParamBase::~ScQueryParamBase()
60 SCSIZE ScQueryParamBase::GetEntryCount() const
62 return maEntries.size();
65 ScQueryEntry& ScQueryParamBase::GetEntry(SCSIZE n) const
67 return maEntries[n];
70 void ScQueryParamBase::Resize(SCSIZE nNew)
72 if ( nNew < MAXQUERY )
73 nNew = MAXQUERY; // nie weniger als MAXQUERY
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];
80 maEntries.swap(aNewEntries);
83 void ScQueryParamBase::DeleteQuery( SCSIZE nPos )
85 if (nPos >= maEntries.size())
86 return;
88 size_t n = maEntries.size();
89 vector<ScQueryEntry> aNewEntries;
90 aNewEntries.reserve(n-1);
91 for (size_t i = 0; i < n; ++i)
92 if (i != nPos)
93 aNewEntries.push_back(maEntries[i]);
95 maEntries.swap(aNewEntries);
98 void ScQueryParamBase::FillInExcelSyntax(String& aCellStr, SCSIZE nIndex)
100 if (aCellStr.Len() > 0)
102 if ( nIndex >= maEntries.size() )
103 Resize( nIndex+1 );
105 ScQueryEntry& rEntry = GetEntry(nIndex);
107 rEntry.bDoQuery = TRUE;
108 // Operatoren herausfiltern
109 if (aCellStr.GetChar(0) == '<')
111 if (aCellStr.GetChar(1) == '>')
113 *rEntry.pStr = aCellStr.Copy(2);
114 rEntry.eOp = SC_NOT_EQUAL;
116 else if (aCellStr.GetChar(1) == '=')
118 *rEntry.pStr = aCellStr.Copy(2);
119 rEntry.eOp = SC_LESS_EQUAL;
121 else
123 *rEntry.pStr = aCellStr.Copy(1);
124 rEntry.eOp = SC_LESS;
127 else if (aCellStr.GetChar(0) == '>')
129 if (aCellStr.GetChar(1) == '=')
131 *rEntry.pStr = aCellStr.Copy(2);
132 rEntry.eOp = SC_GREATER_EQUAL;
134 else
136 *rEntry.pStr = aCellStr.Copy(1);
137 rEntry.eOp = SC_GREATER;
140 else
142 if (aCellStr.GetChar(0) == '=')
143 *rEntry.pStr = aCellStr.Copy(1);
144 else
145 *rEntry.pStr = aCellStr;
146 rEntry.eOp = SC_EQUAL;
151 // ============================================================================
153 ScQueryParamTable::ScQueryParamTable()
157 ScQueryParamTable::ScQueryParamTable(const ScQueryParamTable& r) :
158 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nTab(r.nTab)
162 ScQueryParamTable::~ScQueryParamTable()
166 // ============================================================================
168 ScQueryParam::ScQueryParam() :
169 ScQueryParamBase(),
170 ScQueryParamTable()
172 Clear();
175 //------------------------------------------------------------------------
177 ScQueryParam::ScQueryParam( const ScQueryParam& r ) :
178 ScQueryParamBase(r),
179 ScQueryParamTable(r),
180 bDestPers(r.bDestPers), nDestTab(r.nDestTab), nDestCol(r.nDestCol), nDestRow(r.nDestRow),
181 nDynamicEndRow(r.nDynamicEndRow), bUseDynamicRange(r.bUseDynamicRange)
185 ScQueryParam::ScQueryParam( const ScDBQueryParamInternal& r ) :
186 ScQueryParamBase(r),
187 ScQueryParamTable(r),
188 bDestPers(true),
189 nDestTab(0),
190 nDestCol(0),
191 nDestRow(0),
192 nDynamicEndRow(0),
193 bUseDynamicRange(false)
198 //------------------------------------------------------------------------
200 ScQueryParam::~ScQueryParam()
204 //------------------------------------------------------------------------
206 void ScQueryParam::Clear()
208 nCol1=nCol2 = 0;
209 nRow1=nRow2 = 0;
210 nTab = SCTAB_MAX;
211 bHasHeader = bCaseSens = bRegExp = bMixedComparison = FALSE;
212 bInplace = bByRow = bDuplicate = TRUE;
214 Resize( MAXQUERY );
215 for (USHORT i=0; i<MAXQUERY; i++)
216 maEntries[i].Clear();
218 ClearDestParams();
221 void ScQueryParam::ClearDestParams()
223 bDestPers = true;
224 nDestTab = 0;
225 nDestCol = 0;
226 nDestRow = 0;
227 nDynamicEndRow = 0;
228 bUseDynamicRange = false;
231 //------------------------------------------------------------------------
233 ScQueryParam& ScQueryParam::operator=( const ScQueryParam& r )
235 nCol1 = r.nCol1;
236 nRow1 = r.nRow1;
237 nCol2 = r.nCol2;
238 nRow2 = r.nRow2;
239 nTab = r.nTab;
240 nDestTab = r.nDestTab;
241 nDestCol = r.nDestCol;
242 nDestRow = r.nDestRow;
243 bHasHeader = r.bHasHeader;
244 bInplace = r.bInplace;
245 bCaseSens = r.bCaseSens;
246 bRegExp = r.bRegExp;
247 bMixedComparison = r.bMixedComparison;
248 bDuplicate = r.bDuplicate;
249 bByRow = r.bByRow;
250 bDestPers = r.bDestPers;
251 nDynamicEndRow = r.nDynamicEndRow;
252 bUseDynamicRange = r.bUseDynamicRange;
254 maEntries = r.maEntries;
256 return *this;
259 //------------------------------------------------------------------------
261 BOOL ScQueryParam::operator==( const ScQueryParam& rOther ) const
263 BOOL bEqual = FALSE;
265 // Anzahl der Queries gleich?
266 SCSIZE nUsed = 0;
267 SCSIZE nOtherUsed = 0;
268 SCSIZE nEntryCount = GetEntryCount();
269 SCSIZE nOtherEntryCount = rOther.GetEntryCount();
271 while ( nUsed<nEntryCount && maEntries[nUsed].bDoQuery ) ++nUsed;
272 while ( nOtherUsed<nOtherEntryCount && rOther.maEntries[nOtherUsed].bDoQuery )
273 ++nOtherUsed;
275 if ( (nUsed == nOtherUsed)
276 && (nCol1 == rOther.nCol1)
277 && (nRow1 == rOther.nRow1)
278 && (nCol2 == rOther.nCol2)
279 && (nRow2 == rOther.nRow2)
280 && (nTab == rOther.nTab)
281 && (bHasHeader == rOther.bHasHeader)
282 && (bByRow == rOther.bByRow)
283 && (bInplace == rOther.bInplace)
284 && (bCaseSens == rOther.bCaseSens)
285 && (bRegExp == rOther.bRegExp)
286 && (bMixedComparison == rOther.bMixedComparison)
287 && (bDuplicate == rOther.bDuplicate)
288 && (bDestPers == rOther.bDestPers)
289 && (nDestTab == rOther.nDestTab)
290 && (nDestCol == rOther.nDestCol)
291 && (nDestRow == rOther.nDestRow)
292 && (nDynamicEndRow == rOther.nDynamicEndRow)
293 && (bUseDynamicRange == rOther.bUseDynamicRange) )
295 bEqual = TRUE;
296 for ( SCSIZE i=0; i<nUsed && bEqual; i++ )
297 bEqual = maEntries[i] == rOther.maEntries[i];
299 return bEqual;
302 //------------------------------------------------------------------------
304 void ScQueryParam::MoveToDest()
306 if (!bInplace)
308 SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
309 SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);
310 SCsTAB nDifZ = ((SCsTAB) nDestTab) - ((SCsTAB) nTab);
312 nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
313 nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
314 nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
315 nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
316 nTab = sal::static_int_cast<SCTAB>( nTab + nDifZ );
317 nDynamicEndRow = sal::static_int_cast<SCROW>( nDynamicEndRow + nDifY );
318 size_t n = maEntries.size();
319 for (size_t i=0; i<n; i++)
320 maEntries[i].nField += nDifX;
322 bInplace = TRUE;
324 else
326 DBG_ERROR("MoveToDest, bInplace == TRUE");
330 // ============================================================================
332 ScDBQueryParamBase::ScDBQueryParamBase(DataType eType) :
333 ScQueryParamBase(),
334 mnField(-1),
335 mbSkipString(true),
336 meType(eType)
340 ScDBQueryParamBase::~ScDBQueryParamBase()
344 ScDBQueryParamBase::DataType ScDBQueryParamBase::GetType() const
346 return meType;
349 // ============================================================================
351 ScDBQueryParamInternal::ScDBQueryParamInternal() :
352 ScDBQueryParamBase(ScDBQueryParamBase::INTERNAL),
353 ScQueryParamTable()
357 ScDBQueryParamInternal::~ScDBQueryParamInternal()
361 // ============================================================================
363 ScDBQueryParamMatrix::ScDBQueryParamMatrix() :
364 ScDBQueryParamBase(ScDBQueryParamBase::MATRIX)
368 ScDBQueryParamMatrix::~ScDBQueryParamMatrix()