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>
46 class ScDocumentIterator
// alle nichtleeren Zellen durchgehen
53 const ScPatternAttr
* pDefPattern
;
59 const ScPatternAttr
* pPattern
;
69 ScDocumentIterator( ScDocument
* pDocument
, SCTAB nStartTable
, SCTAB nEndTable
);
70 ~ScDocumentIterator();
75 ScBaseCell
* GetCell();
76 const ScPatternAttr
* GetPattern();
77 void GetPos( SCCOL
& rCol
, SCROW
& rRow
, SCTAB
& rTab
);
80 class ScValueIterator
// alle Zahlenwerte in einem Bereich durchgehen
85 const ScAttrArray
* pAttrArray
;
86 ULONG nNumFormat
; // fuer CalcAsShown
107 BOOL
GetThis(double& rValue
, USHORT
& rErr
);
109 //UNUSED2008-05 ScValueIterator(ScDocument* pDocument,
110 //UNUSED2008-05 SCCOL nSCol, SCROW nSRow, SCTAB nSTab,
111 //UNUSED2008-05 SCCOL nECol, SCROW nERow, SCTAB nETab,
112 //UNUSED2008-05 BOOL bSTotal = FALSE, BOOL bTextAsZero = FALSE);
114 ScValueIterator(ScDocument
* pDocument
,
115 const ScRange
& rRange
, BOOL bSTotal
= FALSE
,
116 BOOL bTextAsZero
= FALSE
);
117 void GetCurNumFmtInfo( short& nType
, ULONG
& nIndex
);
118 /// Does NOT reset rValue if no value found!
119 BOOL
GetFirst(double& rValue
, USHORT
& rErr
);
120 /// Does NOT reset rValue if no value found!
121 BOOL
GetNext(double& rValue
, USHORT
& rErr
)
123 return bNextValid
? ( bNextValid
= FALSE
, rValue
= fNextValue
,
124 rErr
= 0, nRow
= nNextRow
,
125 ++nColRow
, bNumValid
= FALSE
, TRUE
)
126 : ( ++nRow
, GetThis(rValue
, rErr
) );
130 class ScQueryValueIterator
// alle Zahlenwerte in einem Bereich durchgehen
135 const ScAttrArray
* pAttrArray
;
136 ULONG nNumFormat
; // fuer CalcAsShown
146 BOOL
GetThis(double& rValue
, USHORT
& rErr
);
148 ScQueryValueIterator(ScDocument
* pDocument
, SCTAB nTable
,
149 const ScQueryParam
& aParam
);
150 /// Does NOT reset rValue if no value found!
151 BOOL
GetFirst(double& rValue
, USHORT
& rErr
);
152 /// Does NOT reset rValue if no value found!
153 BOOL
GetNext(double& rValue
, USHORT
& rErr
);
154 void GetCurNumFmtInfo( short& nType
, ULONG
& nIndex
)
155 { nType
= nNumFmtType
; nIndex
= nNumFmtIndex
; }
158 class ScCellIterator
// alle Zellen in einem Bereich durchgehen
159 { // bei SubTotal aber keine ausgeblendeten und
160 private: // SubTotalZeilen
174 ScBaseCell
* GetThis();
176 ScCellIterator(ScDocument
* pDocument
,
177 SCCOL nSCol
, SCROW nSRow
, SCTAB nSTab
,
178 SCCOL nECol
, SCROW nERow
, SCTAB nETab
,
179 BOOL bSTotal
= FALSE
);
180 ScCellIterator(ScDocument
* pDocument
,
181 const ScRange
& rRange
, BOOL bSTotal
= FALSE
);
182 ScBaseCell
* GetFirst();
183 ScBaseCell
* GetNext();
184 SCCOL
GetCol() const { return nCol
; }
185 SCROW
GetRow() const { return nRow
; }
186 SCTAB
GetTab() const { return nTab
; }
187 ScAddress
GetPos() const { return ScAddress( nCol
, nRow
, nTab
); }
190 class ScQueryCellIterator
// alle nichtleeren Zellen in einem Bereich
192 enum StopOnMismatchBits
194 nStopOnMismatchDisabled
= 0x00,
195 nStopOnMismatchEnabled
= 0x01,
196 nStopOnMismatchOccured
= 0x02,
197 nStopOnMismatchExecuted
= nStopOnMismatchEnabled
| nStopOnMismatchOccured
200 enum TestEqualConditionBits
202 nTestEqualConditionDisabled
= 0x00,
203 nTestEqualConditionEnabled
= 0x01,
204 nTestEqualConditionMatched
= 0x02,
205 nTestEqualConditionFulfilled
= nTestEqualConditionEnabled
| nTestEqualConditionMatched
211 const ScAttrArray
* pAttrArray
;
218 BYTE nStopOnMismatch
;
219 BYTE nTestEqualCondition
;
221 BOOL bIgnoreMismatchOnLeadingStrings
;
223 ScBaseCell
* GetThis();
225 /* Only works if no regular expression is involved, only
226 searches for rows in one column, and only the first
227 query entry is considered with simple conditions
228 SC_LESS_EQUAL (sorted ascending) or SC_GREATER_EQUAL
229 (sorted descending). Check these things before
230 invocation! Delivers a starting point, continue with
231 GetThis() and GetNext() afterwards. Introduced for
232 FindEqualOrSortedLastInRange()
234 ScBaseCell
* BinarySearch();
237 ScQueryCellIterator(ScDocument
* pDocument
, SCTAB nTable
,
238 const ScQueryParam
& aParam
, BOOL bMod
= TRUE
);
239 // fuer bMod = FALSE muss der QueryParam
240 // weiter aufgefuellt sein (bIsString)
241 ScBaseCell
* GetFirst();
242 ScBaseCell
* GetNext();
243 SCCOL
GetCol() { return nCol
; }
244 SCROW
GetRow() { return nRow
; }
245 ULONG
GetNumberFormat();
247 // setzt alle Entry.nField einen weiter, wenn Spalte
248 // wechselt, fuer ScInterpreter ScHLookup()
249 void SetAdvanceQueryParamEntryField( BOOL bVal
)
250 { bAdvanceQuery
= bVal
; }
251 void AdvanceQueryParamEntryField();
253 /** If set, iterator stops on first non-matching cell
254 content. May be used in SC_LESS_EQUAL queries where a
255 cell range is assumed to be sorted; stops on first
256 value being greater than the queried value and
257 GetFirst()/GetNext() return NULL. StoppedOnMismatch()
259 However, the iterator's conditions are not set to end
260 all queries, GetCol() and GetRow() return values for
261 the non-matching cell, further GetNext() calls may be
263 void SetStopOnMismatch( BOOL bVal
)
265 nStopOnMismatch
= sal::static_int_cast
<BYTE
>(bVal
? nStopOnMismatchEnabled
:
266 nStopOnMismatchDisabled
);
268 BOOL
StoppedOnMismatch() const
269 { return nStopOnMismatch
== nStopOnMismatchExecuted
; }
271 /** If set, an additional test for SC_EQUAL condition is
272 executed in ScTable::ValidQuery() if SC_LESS_EQUAL or
273 SC_GREATER_EQUAL conditions are to be tested. May be
274 used where a cell range is assumed to be sorted to stop
275 if an equal match is found. */
276 void SetTestEqualCondition( BOOL bVal
)
278 nTestEqualCondition
= sal::static_int_cast
<BYTE
>(bVal
?
279 nTestEqualConditionEnabled
:
280 nTestEqualConditionDisabled
);
282 BOOL
IsEqualConditionFulfilled() const
283 { return nTestEqualCondition
== nTestEqualConditionFulfilled
; }
285 /** In a range assumed to be sorted find either the last of
286 a sequence of equal entries or the last being less than
287 (or greater than) the queried value. Used by the
288 interpreter for [HV]?LOOKUP() and MATCH(). Column and
289 row position of the found entry are returned, otherwise
292 @param bSearchForEqualAfterMismatch
293 Continue searching for an equal entry even if the
294 last entry matching the range was found, in case
295 the data is not sorted. Is always done if regular
296 expressions are involved.
298 @param bIgnoreMismatchOnLeadingStrings
299 Normally strings are sorted behind numerical
300 values. If this parameter is TRUE, the search does
301 not stop when encountering a string and does not
302 assume that no values follow anymore.
303 If querying for a string a mismatch on the first
304 entry, e.g. column header, is ignored.
306 @ATTENTION! StopOnMismatch, TestEqualCondition and
307 the internal IgnoreMismatchOnLeadingStrings and query
308 params are in an undefined state upon return! The
309 iterator is not usable anymore except for obtaining the
312 BOOL
FindEqualOrSortedLastInRange( SCCOL
& nFoundCol
,
313 SCROW
& nFoundRow
, BOOL bSearchForEqualAfterMismatch
= FALSE
,
314 BOOL bIgnoreMismatchOnLeadingStrings
= TRUE
);
317 class ScDocAttrIterator
// alle Attribut-Bereiche
326 ScAttrIterator
* pColIter
;
329 ScDocAttrIterator(ScDocument
* pDocument
, SCTAB nTable
,
330 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
331 ~ScDocAttrIterator();
333 const ScPatternAttr
* GetNext( SCCOL
& rCol
, SCROW
& rRow1
, SCROW
& rRow2
);
336 class ScAttrRectIterator
// alle Attribut-Bereiche, auch Bereiche ueber mehrere Spalten
346 ScAttrIterator
* pColIter
;
349 ScAttrRectIterator(ScDocument
* pDocument
, SCTAB nTable
,
350 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
351 ~ScAttrRectIterator();
354 const ScPatternAttr
* GetNext( SCCOL
& rCol1
, SCCOL
& rCol2
, SCROW
& rRow1
, SCROW
& rRow2
);
357 class ScHorizontalCellIterator
// alle nichtleeren Zellen in einem Bereich
358 { // zeilenweise durchgehen
366 SCSIZE
* pNextIndices
;
372 ScHorizontalCellIterator(ScDocument
* pDocument
, SCTAB nTable
,
373 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
374 ~ScHorizontalCellIterator();
376 ScBaseCell
* GetNext( SCCOL
& rCol
, SCROW
& rRow
);
377 BOOL
ReturnNext( SCCOL
& rCol
, SCROW
& rRow
);
385 // gibt alle Bereiche mit nicht-Default-Formatierung zurueck (horizontal)
388 class ScHorizontalAttrIterator
400 const ScPatternAttr
** ppPatterns
;
406 ScHorizontalAttrIterator( ScDocument
* pDocument
, SCTAB nTable
,
407 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
408 ~ScHorizontalAttrIterator();
410 const ScPatternAttr
* GetNext( SCCOL
& rCol1
, SCCOL
& rCol2
, SCROW
& rRow
);
414 // gibt nichtleere Zellen und Bereiche mit Formatierung zurueck (horizontal)
417 class SC_DLLPUBLIC ScUsedAreaIterator
420 ScHorizontalCellIterator aCellIter
;
421 ScHorizontalAttrIterator aAttrIter
;
428 const ScBaseCell
* pCell
;
432 const ScPatternAttr
* pPattern
;
434 SCCOL nFoundStartCol
; // Ergebnisse nach GetNext
437 const ScPatternAttr
* pFoundPattern
;
438 const ScBaseCell
* pFoundCell
;
441 ScUsedAreaIterator( ScDocument
* pDocument
, SCTAB nTable
,
442 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
443 ~ScUsedAreaIterator();
447 SCCOL
GetStartCol() const { return nFoundStartCol
; }
448 SCCOL
GetEndCol() const { return nFoundEndCol
; }
449 SCROW
GetRow() const { return nFoundRow
; }
450 const ScPatternAttr
* GetPattern() const { return pFoundPattern
; }
451 const ScBaseCell
* GetCell() const { return pFoundCell
; }