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: dociter.hxx,v $
10 * $Revision: 1.9.128.1 $
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 #ifndef SC_DOCITER_HXX
32 #define SC_DOCITER_HXX
34 #include "address.hxx"
35 #include <tools/solar.h>
38 #include "queryparam.hxx"
49 class ScDocumentIterator
// alle nichtleeren Zellen durchgehen
56 const ScPatternAttr
* pDefPattern
;
62 const ScPatternAttr
* pPattern
;
72 ScDocumentIterator( ScDocument
* pDocument
, SCTAB nStartTable
, SCTAB nEndTable
);
73 ~ScDocumentIterator();
78 ScBaseCell
* GetCell();
79 const ScPatternAttr
* GetPattern();
80 void GetPos( SCCOL
& rCol
, SCROW
& rRow
, SCTAB
& rTab
);
83 class ScValueIterator
// alle Zahlenwerte in einem Bereich durchgehen
88 const ScAttrArray
* pAttrArray
;
89 ULONG nNumFormat
; // fuer CalcAsShown
110 BOOL
GetThis(double& rValue
, USHORT
& rErr
);
112 //UNUSED2008-05 ScValueIterator(ScDocument* pDocument,
113 //UNUSED2008-05 SCCOL nSCol, SCROW nSRow, SCTAB nSTab,
114 //UNUSED2008-05 SCCOL nECol, SCROW nERow, SCTAB nETab,
115 //UNUSED2008-05 BOOL bSTotal = FALSE, BOOL bTextAsZero = FALSE);
117 ScValueIterator(ScDocument
* pDocument
,
118 const ScRange
& rRange
, BOOL bSTotal
= FALSE
,
119 BOOL bTextAsZero
= FALSE
);
120 void GetCurNumFmtInfo( short& nType
, ULONG
& nIndex
);
121 /// Does NOT reset rValue if no value found!
122 BOOL
GetFirst(double& rValue
, USHORT
& rErr
);
123 /// Does NOT reset rValue if no value found!
124 BOOL
GetNext(double& rValue
, USHORT
& rErr
)
126 return bNextValid
? ( bNextValid
= FALSE
, rValue
= fNextValue
,
127 rErr
= 0, nRow
= nNextRow
,
128 ++nColRow
, bNumValid
= FALSE
, TRUE
)
129 : ( ++nRow
, GetThis(rValue
, rErr
) );
133 // ============================================================================
135 class ScDBQueryDataIterator
140 ::rtl::OUString maString
;
152 DataAccess(const ScDBQueryDataIterator
* pParent
);
153 virtual ~DataAccess() = 0;
154 virtual bool getCurrent(Value
& rValue
) = 0;
155 virtual bool getFirst(Value
& rValue
) = 0;
156 virtual bool getNext(Value
& rValue
) = 0;
158 const ScDBQueryDataIterator
* mpParent
;
161 class DataAccessInternal
: public DataAccess
164 DataAccessInternal(const ScDBQueryDataIterator
* pParent
, ScDBQueryParamInternal
* pParam
, ScDocument
* pDoc
);
165 virtual ~DataAccessInternal();
166 virtual bool getCurrent(Value
& rValue
);
167 virtual bool getFirst(Value
& rValue
);
168 virtual bool getNext(Value
& rValue
);
171 ScDBQueryParamInternal
* mpParam
;
173 const ScAttrArray
* pAttrArray
;
174 ULONG nNumFormat
; // for CalcAsShown
185 class DataAccessMatrix
: public DataAccess
188 DataAccessMatrix(const ScDBQueryDataIterator
* pParent
, ScDBQueryParamMatrix
* pParam
);
189 virtual ~DataAccessMatrix();
190 virtual bool getCurrent(Value
& rValue
);
191 virtual bool getFirst(Value
& rValue
);
192 virtual bool getNext(Value
& rValue
);
195 bool isValidQuery(SCROW mnRow
, const ScMatrix
& rMat
) const;
197 ScDBQueryParamMatrix
* mpParam
;
203 ::std::auto_ptr
<ScDBQueryParamBase
> mpParam
;
204 ::std::auto_ptr
<DataAccess
> mpData
;
206 bool GetThis(Value
& rValue
);
209 ScDBQueryDataIterator(ScDocument
* pDocument
, ScDBQueryParamBase
* pParam
);
210 /// Does NOT reset rValue if no value found!
211 bool GetFirst(Value
& rValue
);
212 /// Does NOT reset rValue if no value found!
213 bool GetNext(Value
& rValue
);
216 // ============================================================================
218 class ScCellIterator
// alle Zellen in einem Bereich durchgehen
219 { // bei SubTotal aber keine ausgeblendeten und
220 private: // SubTotalZeilen
234 ScBaseCell
* GetThis();
236 ScCellIterator(ScDocument
* pDocument
,
237 SCCOL nSCol
, SCROW nSRow
, SCTAB nSTab
,
238 SCCOL nECol
, SCROW nERow
, SCTAB nETab
,
239 BOOL bSTotal
= FALSE
);
240 ScCellIterator(ScDocument
* pDocument
,
241 const ScRange
& rRange
, BOOL bSTotal
= FALSE
);
242 ScBaseCell
* GetFirst();
243 ScBaseCell
* GetNext();
244 SCCOL
GetCol() const { return nCol
; }
245 SCROW
GetRow() const { return nRow
; }
246 SCTAB
GetTab() const { return nTab
; }
247 ScAddress
GetPos() const { return ScAddress( nCol
, nRow
, nTab
); }
250 class ScQueryCellIterator
// alle nichtleeren Zellen in einem Bereich
252 enum StopOnMismatchBits
254 nStopOnMismatchDisabled
= 0x00,
255 nStopOnMismatchEnabled
= 0x01,
256 nStopOnMismatchOccured
= 0x02,
257 nStopOnMismatchExecuted
= nStopOnMismatchEnabled
| nStopOnMismatchOccured
260 enum TestEqualConditionBits
262 nTestEqualConditionDisabled
= 0x00,
263 nTestEqualConditionEnabled
= 0x01,
264 nTestEqualConditionMatched
= 0x02,
265 nTestEqualConditionFulfilled
= nTestEqualConditionEnabled
| nTestEqualConditionMatched
271 const ScAttrArray
* pAttrArray
;
278 BYTE nStopOnMismatch
;
279 BYTE nTestEqualCondition
;
281 BOOL bIgnoreMismatchOnLeadingStrings
;
283 ScBaseCell
* GetThis();
285 /* Only works if no regular expression is involved, only
286 searches for rows in one column, and only the first
287 query entry is considered with simple conditions
288 SC_LESS_EQUAL (sorted ascending) or SC_GREATER_EQUAL
289 (sorted descending). Check these things before
290 invocation! Delivers a starting point, continue with
291 GetThis() and GetNext() afterwards. Introduced for
292 FindEqualOrSortedLastInRange()
294 ScBaseCell
* BinarySearch();
297 ScQueryCellIterator(ScDocument
* pDocument
, SCTAB nTable
,
298 const ScQueryParam
& aParam
, BOOL bMod
= TRUE
);
299 // fuer bMod = FALSE muss der QueryParam
300 // weiter aufgefuellt sein (bIsString)
301 ScBaseCell
* GetFirst();
302 ScBaseCell
* GetNext();
303 SCCOL
GetCol() { return nCol
; }
304 SCROW
GetRow() { return nRow
; }
305 ULONG
GetNumberFormat();
307 // setzt alle Entry.nField einen weiter, wenn Spalte
308 // wechselt, fuer ScInterpreter ScHLookup()
309 void SetAdvanceQueryParamEntryField( BOOL bVal
)
310 { bAdvanceQuery
= bVal
; }
311 void AdvanceQueryParamEntryField();
313 /** If set, iterator stops on first non-matching cell
314 content. May be used in SC_LESS_EQUAL queries where a
315 cell range is assumed to be sorted; stops on first
316 value being greater than the queried value and
317 GetFirst()/GetNext() return NULL. StoppedOnMismatch()
319 However, the iterator's conditions are not set to end
320 all queries, GetCol() and GetRow() return values for
321 the non-matching cell, further GetNext() calls may be
323 void SetStopOnMismatch( BOOL bVal
)
325 nStopOnMismatch
= sal::static_int_cast
<BYTE
>(bVal
? nStopOnMismatchEnabled
:
326 nStopOnMismatchDisabled
);
328 BOOL
StoppedOnMismatch() const
329 { return nStopOnMismatch
== nStopOnMismatchExecuted
; }
331 /** If set, an additional test for SC_EQUAL condition is
332 executed in ScTable::ValidQuery() if SC_LESS_EQUAL or
333 SC_GREATER_EQUAL conditions are to be tested. May be
334 used where a cell range is assumed to be sorted to stop
335 if an equal match is found. */
336 void SetTestEqualCondition( BOOL bVal
)
338 nTestEqualCondition
= sal::static_int_cast
<BYTE
>(bVal
?
339 nTestEqualConditionEnabled
:
340 nTestEqualConditionDisabled
);
342 BOOL
IsEqualConditionFulfilled() const
343 { return nTestEqualCondition
== nTestEqualConditionFulfilled
; }
345 /** In a range assumed to be sorted find either the last of
346 a sequence of equal entries or the last being less than
347 (or greater than) the queried value. Used by the
348 interpreter for [HV]?LOOKUP() and MATCH(). Column and
349 row position of the found entry are returned, otherwise
352 @param bSearchForEqualAfterMismatch
353 Continue searching for an equal entry even if the
354 last entry matching the range was found, in case
355 the data is not sorted. Is always done if regular
356 expressions are involved.
358 @param bIgnoreMismatchOnLeadingStrings
359 Normally strings are sorted behind numerical
360 values. If this parameter is TRUE, the search does
361 not stop when encountering a string and does not
362 assume that no values follow anymore.
363 If querying for a string a mismatch on the first
364 entry, e.g. column header, is ignored.
366 @ATTENTION! StopOnMismatch, TestEqualCondition and
367 the internal IgnoreMismatchOnLeadingStrings and query
368 params are in an undefined state upon return! The
369 iterator is not usable anymore except for obtaining the
372 BOOL
FindEqualOrSortedLastInRange( SCCOL
& nFoundCol
,
373 SCROW
& nFoundRow
, BOOL bSearchForEqualAfterMismatch
= FALSE
,
374 BOOL bIgnoreMismatchOnLeadingStrings
= TRUE
);
377 class ScDocAttrIterator
// alle Attribut-Bereiche
386 ScAttrIterator
* pColIter
;
389 ScDocAttrIterator(ScDocument
* pDocument
, SCTAB nTable
,
390 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
391 ~ScDocAttrIterator();
393 const ScPatternAttr
* GetNext( SCCOL
& rCol
, SCROW
& rRow1
, SCROW
& rRow2
);
396 class ScAttrRectIterator
// alle Attribut-Bereiche, auch Bereiche ueber mehrere Spalten
406 ScAttrIterator
* pColIter
;
409 ScAttrRectIterator(ScDocument
* pDocument
, SCTAB nTable
,
410 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
411 ~ScAttrRectIterator();
414 const ScPatternAttr
* GetNext( SCCOL
& rCol1
, SCCOL
& rCol2
, SCROW
& rRow1
, SCROW
& rRow2
);
417 class ScHorizontalCellIterator
// alle nichtleeren Zellen in einem Bereich
418 { // zeilenweise durchgehen
426 SCSIZE
* pNextIndices
;
432 ScHorizontalCellIterator(ScDocument
* pDocument
, SCTAB nTable
,
433 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
434 ~ScHorizontalCellIterator();
436 ScBaseCell
* GetNext( SCCOL
& rCol
, SCROW
& rRow
);
437 BOOL
ReturnNext( SCCOL
& rCol
, SCROW
& rRow
);
445 // gibt alle Bereiche mit nicht-Default-Formatierung zurueck (horizontal)
448 class ScHorizontalAttrIterator
460 const ScPatternAttr
** ppPatterns
;
466 ScHorizontalAttrIterator( ScDocument
* pDocument
, SCTAB nTable
,
467 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
468 ~ScHorizontalAttrIterator();
470 const ScPatternAttr
* GetNext( SCCOL
& rCol1
, SCCOL
& rCol2
, SCROW
& rRow
);
474 // gibt nichtleere Zellen und Bereiche mit Formatierung zurueck (horizontal)
477 class SC_DLLPUBLIC ScUsedAreaIterator
480 ScHorizontalCellIterator aCellIter
;
481 ScHorizontalAttrIterator aAttrIter
;
488 const ScBaseCell
* pCell
;
492 const ScPatternAttr
* pPattern
;
494 SCCOL nFoundStartCol
; // Ergebnisse nach GetNext
497 const ScPatternAttr
* pFoundPattern
;
498 const ScBaseCell
* pFoundCell
;
501 ScUsedAreaIterator( ScDocument
* pDocument
, SCTAB nTable
,
502 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
503 ~ScUsedAreaIterator();
507 SCCOL
GetStartCol() const { return nFoundStartCol
; }
508 SCCOL
GetEndCol() const { return nFoundEndCol
; }
509 SCROW
GetRow() const { return nFoundRow
; }
510 const ScPatternAttr
* GetPattern() const { return pFoundPattern
; }
511 const ScBaseCell
* GetCell() const { return pFoundCell
; }