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 $
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
35 #include <tools/solar.h>
49 class ScValueIterator
// alle Zahlenwerte in einem Bereich durchgehen
54 const ScAttrArray
* pAttrArray
;
55 ULONG nNumFormat
; // fuer CalcAsShown
76 BOOL
GetThis(double& rValue
, USHORT
& rErr
);
78 ScValueIterator(ScDocument
* pDocument
,
79 const ScRange
& rRange
, BOOL bSTotal
= FALSE
,
80 BOOL bTextAsZero
= FALSE
);
81 void GetCurNumFmtInfo( short& nType
, ULONG
& nIndex
);
82 BOOL
GetFirst(double& rValue
, USHORT
& rErr
);
83 BOOL
GetNext(double& rValue
, USHORT
& rErr
)
85 return bNextValid
? ( bNextValid
= FALSE
, rValue
= fNextValue
,
86 rErr
= 0, nRow
= nNextRow
,
87 ++nColRow
, bNumValid
= FALSE
, TRUE
)
88 : ( ++nRow
, GetThis(rValue
, rErr
) );
92 class ScQueryValueIterator
// alle Zahlenwerte in einem Bereich durchgehen
97 ScAttrArray
* pAttrArray
;
98 ULONG nNumFormat
; // fuer CalcAsShown
108 BOOL
GetThis(double& rValue
, USHORT
& rErr
);
110 ScQueryValueIterator(ScDocument
* pDocument
, USHORT nTable
,
111 const ScQueryParam
& aParam
);
112 BOOL
GetFirst(double& rValue
, USHORT
& rErr
);
113 BOOL
GetNext(double& rValue
, USHORT
& rErr
);
114 void GetCurNumFmtInfo( short& nType
, ULONG
& nIndex
)
115 { nType
= nNumFmtType
; nIndex
= nNumFmtIndex
; }
118 class ScCellIterator
// alle Zellen in einem Bereich durchgehen
119 { // bei SubTotal aber keine ausgeblendeten und
120 private: // SubTotalZeilen
134 ScBaseCell
* GetThis();
136 ScCellIterator(ScDocument
* pDocument
,
137 USHORT nSCol
, USHORT nSRow
, USHORT nSTab
,
138 USHORT nECol
, USHORT nERow
, USHORT nETab
,
139 BOOL bSTotal
= FALSE
);
140 ScCellIterator(ScDocument
* pDocument
,
141 const ScRange
& rRange
, BOOL bSTotal
= FALSE
);
142 ScBaseCell
* GetFirst();
143 ScBaseCell
* GetNext();
144 USHORT
GetCol() { return nCol
; }
145 USHORT
GetRow() { return nRow
; }
146 USHORT
GetTab() { return nTab
; }
149 class ScQueryCellIterator
// alle nichtleeren Zellen in einem Bereich
151 enum StopOnMismatchBits
153 nStopOnMismatchDisabled
= 0x00,
154 nStopOnMismatchEnabled
= 0x01,
155 nStopOnMismatchOccured
= 0x02,
156 nStopOnMismatchExecuted
= nStopOnMismatchEnabled
| nStopOnMismatchOccured
159 enum TestEqualConditionBits
161 nTestEqualConditionDisabled
= 0x00,
162 nTestEqualConditionEnabled
= 0x01,
163 nTestEqualConditionMatched
= 0x02,
164 nTestEqualConditionFulfilled
= nTestEqualConditionEnabled
| nTestEqualConditionMatched
170 ScAttrArray
* pAttrArray
;
177 BYTE nStopOnMismatch
;
178 BYTE nTestEqualCondition
;
181 ScBaseCell
* GetThis();
183 ScQueryCellIterator(ScDocument
* pDocument
, USHORT nTable
,
184 const ScQueryParam
& aParam
, BOOL bMod
= TRUE
);
185 // fuer bMod = FALSE muss der QueryParam
186 // weiter aufgefuellt sein (bIsString)
187 ScBaseCell
* GetFirst();
188 ScBaseCell
* GetNext();
189 USHORT
GetCol() { return nCol
; }
190 USHORT
GetRow() { return nRow
; }
191 ULONG
GetNumberFormat();
193 // setzt alle Entry.nField einen weiter, wenn Spalte
194 // wechselt, fuer ScInterpreter ScHLookup()
195 void SetAdvanceQueryParamEntryField( BOOL bVal
)
196 { bAdvanceQuery
= bVal
; }
197 void AdvanceQueryParamEntryField();
199 /** If set, iterator stops on first non-matching cell
200 content. May be used in SC_LESS_EQUAL queries where a
201 cell range is assumed to be sorted; stops on first
202 value being greater than the queried value and
203 GetFirst()/GetNext() return NULL. StoppedOnMismatch()
205 However, the iterator's conditions are not set to end
206 all queries, GetCol() and GetRow() return values for
207 the non-matching cell, further GetNext() calls may be
209 void SetStopOnMismatch( BOOL bVal
)
211 nStopOnMismatch
= (bVal
? nStopOnMismatchEnabled
:
212 nStopOnMismatchDisabled
);
214 BOOL
StoppedOnMismatch() const
215 { return nStopOnMismatch
== nStopOnMismatchExecuted
; }
217 /** If set, an additional test for SC_EQUAL condition is
218 executed in ScTable::ValidQuery() if SC_LESS_EQUAL or
219 SC_GREATER_EQUAL conditions are to be tested. May be
220 used where a cell range is assumed to be sorted to stop
221 if an equal match is found. */
222 void SetTestEqualCondition( BOOL bVal
)
224 nTestEqualCondition
= (bVal
?
225 nTestEqualConditionEnabled
:
226 nTestEqualConditionDisabled
);
228 BOOL
IsEqualConditionFulfilled() const
229 { return nTestEqualCondition
== nTestEqualConditionFulfilled
; }
231 /** In a range assumed to be sorted find either the first
232 equal entry or the last being less than (or greater
233 than) the queried value. Continues searching for an
234 equal entry even if the last entry matching the range
235 is found, in case the data is not sorted. Used by the
236 interpreter for LOOKUP() and similar. Column and row
237 position of the found entry are returned, otherwise
239 @ATTENTION! StopOnMismatch, TestEqualCondition and
240 the internal query params are in an undefined state
242 BOOL
FindEqualOrSortedLastInRange( USHORT
& nFoundCol
, USHORT
& nFoundRow
);
245 class ScDocAttrIterator
// alle Attribut-Bereiche
254 ScAttrIterator
* pColIter
;
257 ScDocAttrIterator(ScDocument
* pDocument
, USHORT nTable
,
258 USHORT nCol1
, USHORT nRow1
, USHORT nCol2
, USHORT nRow2
);
259 ~ScDocAttrIterator();
261 const ScPatternAttr
* GetNext( USHORT
& rCol
, USHORT
& rRow1
, USHORT
& rRow2
);
264 class ScAttrRectIterator
// alle Attribut-Bereiche, auch Bereiche ueber mehrere Spalten
272 USHORT nIterStartCol
;
274 ScAttrIterator
* pColIter
;
277 ScAttrRectIterator(ScDocument
* pDocument
, USHORT nTable
,
278 USHORT nCol1
, USHORT nRow1
, USHORT nCol2
, USHORT nRow2
);
279 ~ScAttrRectIterator();
282 const ScPatternAttr
* GetNext( USHORT
& rCol1
, USHORT
& rCol2
, USHORT
& rRow1
, USHORT
& rRow2
);
285 class ScHorizontalCellIterator
// alle nichtleeren Zellen in einem Bereich
286 { // zeilenweise durchgehen
294 USHORT
* pNextIndices
;
300 ScHorizontalCellIterator(ScDocument
* pDocument
, USHORT nTable
,
301 USHORT nCol1
, USHORT nRow1
, USHORT nCol2
, USHORT nRow2
);
302 ~ScHorizontalCellIterator();
304 ScBaseCell
* GetNext( USHORT
& rCol
, USHORT
& rRow
);
305 BOOL
ReturnNext( USHORT
& rCol
, USHORT
& rRow
);
313 // gibt alle Bereiche mit nicht-Default-Formatierung zurueck (horizontal)
318 // gibt nichtleere Zellen und Bereiche mit Formatierung zurueck (horizontal)
322 } //namespace binfilter