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: 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"
40 // ============================================================================
42 ScQueryParamBase::ScQueryParamBase()
45 for (USHORT i
=0; i
<MAXQUERY
; i
++)
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
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())
88 size_t n
= maEntries
.size();
89 vector
<ScQueryEntry
> aNewEntries
;
90 aNewEntries
.reserve(n
-1);
91 for (size_t i
= 0; i
< n
; ++i
)
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() )
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
;
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
;
136 *rEntry
.pStr
= aCellStr
.Copy(1);
137 rEntry
.eOp
= SC_GREATER
;
142 if (aCellStr
.GetChar(0) == '=')
143 *rEntry
.pStr
= aCellStr
.Copy(1);
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() :
175 //------------------------------------------------------------------------
177 ScQueryParam::ScQueryParam( const ScQueryParam
& 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
) :
187 ScQueryParamTable(r
),
193 bUseDynamicRange(false)
198 //------------------------------------------------------------------------
200 ScQueryParam::~ScQueryParam()
204 //------------------------------------------------------------------------
206 void ScQueryParam::Clear()
211 bHasHeader
= bCaseSens
= bRegExp
= bMixedComparison
= FALSE
;
212 bInplace
= bByRow
= bDuplicate
= TRUE
;
215 for (USHORT i
=0; i
<MAXQUERY
; i
++)
216 maEntries
[i
].Clear();
221 void ScQueryParam::ClearDestParams()
228 bUseDynamicRange
= false;
231 //------------------------------------------------------------------------
233 ScQueryParam
& ScQueryParam::operator=( const ScQueryParam
& r
)
240 nDestTab
= r
.nDestTab
;
241 nDestCol
= r
.nDestCol
;
242 nDestRow
= r
.nDestRow
;
243 bHasHeader
= r
.bHasHeader
;
244 bInplace
= r
.bInplace
;
245 bCaseSens
= r
.bCaseSens
;
247 bMixedComparison
= r
.bMixedComparison
;
248 bDuplicate
= r
.bDuplicate
;
250 bDestPers
= r
.bDestPers
;
251 nDynamicEndRow
= r
.nDynamicEndRow
;
252 bUseDynamicRange
= r
.bUseDynamicRange
;
254 maEntries
= r
.maEntries
;
259 //------------------------------------------------------------------------
261 BOOL
ScQueryParam::operator==( const ScQueryParam
& rOther
) const
265 // Anzahl der Queries gleich?
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
)
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
) )
296 for ( SCSIZE i
=0; i
<nUsed
&& bEqual
; i
++ )
297 bEqual
= maEntries
[i
] == rOther
.maEntries
[i
];
302 //------------------------------------------------------------------------
304 void ScQueryParam::MoveToDest()
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
;
326 DBG_ERROR("MoveToDest, bInplace == TRUE");
330 // ============================================================================
332 ScDBQueryParamBase::ScDBQueryParamBase(DataType eType
) :
340 ScDBQueryParamBase::~ScDBQueryParamBase()
344 ScDBQueryParamBase::DataType
ScDBQueryParamBase::GetType() const
349 // ============================================================================
351 ScDBQueryParamInternal::ScDBQueryParamInternal() :
352 ScDBQueryParamBase(ScDBQueryParamBase::INTERNAL
),
357 ScDBQueryParamInternal::~ScDBQueryParamInternal()
361 // ============================================================================
363 ScDBQueryParamMatrix::ScDBQueryParamMatrix() :
364 ScDBQueryParamBase(ScDBQueryParamBase::MATRIX
)
368 ScDBQueryParamMatrix::~ScDBQueryParamMatrix()