update ooo310-m15
[ooovba.git] / sc / inc / dociter.hxx
blobcf42c08b0b76f8577b03d1003972e045a789e8f2
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>
36 #include "global.hxx"
37 #include "scdllapi.h"
39 class ScDocument;
40 class ScBaseCell;
41 class ScPatternAttr;
42 class ScAttrArray;
43 class ScAttrIterator;
44 class ScRange;
46 class ScDocumentIterator // alle nichtleeren Zellen durchgehen
48 private:
49 ScDocument* pDoc;
50 SCTAB nStartTab;
51 SCTAB nEndTab;
53 const ScPatternAttr* pDefPattern;
55 SCCOL nCol;
56 SCROW nRow;
57 SCTAB nTab;
58 ScBaseCell* pCell;
59 const ScPatternAttr* pPattern;
62 SCSIZE nColPos;
63 SCSIZE nAttrPos;
65 BOOL GetThis();
66 BOOL GetThisCol();
68 public:
69 ScDocumentIterator( ScDocument* pDocument, SCTAB nStartTable, SCTAB nEndTable );
70 ~ScDocumentIterator();
72 BOOL GetFirst();
73 BOOL GetNext();
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
82 private:
83 double fNextValue;
84 ScDocument* pDoc;
85 const ScAttrArray* pAttrArray;
86 ULONG nNumFormat; // fuer CalcAsShown
87 ULONG nNumFmtIndex;
88 SCCOL nStartCol;
89 SCROW nStartRow;
90 SCTAB nStartTab;
91 SCCOL nEndCol;
92 SCROW nEndRow;
93 SCTAB nEndTab;
94 SCCOL nCol;
95 SCROW nRow;
96 SCTAB nTab;
97 SCSIZE nColRow;
98 SCROW nNextRow;
99 SCROW nAttrEndRow;
100 short nNumFmtType;
101 BOOL bNumValid;
102 BOOL bSubTotal;
103 BOOL bNextValid;
104 BOOL bCalcAsShown;
105 BOOL bTextAsZero;
107 BOOL GetThis(double& rValue, USHORT& rErr);
108 public:
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
132 private:
133 ScQueryParam aParam;
134 ScDocument* pDoc;
135 const ScAttrArray* pAttrArray;
136 ULONG nNumFormat; // fuer CalcAsShown
137 ULONG nNumFmtIndex;
138 SCCOL nCol;
139 SCROW nRow;
140 SCSIZE nColRow;
141 SCROW nAttrEndRow;
142 SCTAB nTab;
143 short nNumFmtType;
144 BOOL bCalcAsShown;
146 BOOL GetThis(double& rValue, USHORT& rErr);
147 public:
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
161 ScDocument* pDoc;
162 SCCOL nStartCol;
163 SCROW nStartRow;
164 SCTAB nStartTab;
165 SCCOL nEndCol;
166 SCROW nEndRow;
167 SCTAB nEndTab;
168 SCCOL nCol;
169 SCROW nRow;
170 SCTAB nTab;
171 SCSIZE nColRow;
172 BOOL bSubTotal;
174 ScBaseCell* GetThis();
175 public:
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
191 { // durchgehen
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
208 private:
209 ScQueryParam aParam;
210 ScDocument* pDoc;
211 const ScAttrArray* pAttrArray;
212 ULONG nNumFormat;
213 SCTAB nTab;
214 SCCOL nCol;
215 SCROW nRow;
216 SCSIZE nColRow;
217 SCROW nAttrEndRow;
218 BYTE nStopOnMismatch;
219 BYTE nTestEqualCondition;
220 BOOL bAdvanceQuery;
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();
236 public:
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()
258 returns TRUE then.
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
262 executed. */
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
290 invalid.
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
310 number format!
312 BOOL FindEqualOrSortedLastInRange( SCCOL& nFoundCol,
313 SCROW& nFoundRow, BOOL bSearchForEqualAfterMismatch = FALSE,
314 BOOL bIgnoreMismatchOnLeadingStrings = TRUE );
317 class ScDocAttrIterator // alle Attribut-Bereiche
319 private:
320 ScDocument* pDoc;
321 SCTAB nTab;
322 SCCOL nEndCol;
323 SCROW nStartRow;
324 SCROW nEndRow;
325 SCCOL nCol;
326 ScAttrIterator* pColIter;
328 public:
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
338 private:
339 ScDocument* pDoc;
340 SCTAB nTab;
341 SCCOL nEndCol;
342 SCROW nStartRow;
343 SCROW nEndRow;
344 SCCOL nIterStartCol;
345 SCCOL nIterEndCol;
346 ScAttrIterator* pColIter;
348 public:
349 ScAttrRectIterator(ScDocument* pDocument, SCTAB nTable,
350 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
351 ~ScAttrRectIterator();
353 void DataChanged();
354 const ScPatternAttr* GetNext( SCCOL& rCol1, SCCOL& rCol2, SCROW& rRow1, SCROW& rRow2 );
357 class ScHorizontalCellIterator // alle nichtleeren Zellen in einem Bereich
358 { // zeilenweise durchgehen
359 private:
360 ScDocument* pDoc;
361 SCTAB nTab;
362 SCCOL nStartCol;
363 SCCOL nEndCol;
364 SCROW nEndRow;
365 SCROW* pNextRows;
366 SCSIZE* pNextIndices;
367 SCCOL nCol;
368 SCROW nRow;
369 BOOL bMore;
371 public:
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 );
379 private:
380 void Advance();
385 // gibt alle Bereiche mit nicht-Default-Formatierung zurueck (horizontal)
388 class ScHorizontalAttrIterator
390 private:
391 ScDocument* pDoc;
392 SCTAB nTab;
393 SCCOL nStartCol;
394 SCROW nStartRow;
395 SCCOL nEndCol;
396 SCROW nEndRow;
398 SCROW* pNextEnd;
399 SCSIZE* pIndices;
400 const ScPatternAttr** ppPatterns;
401 SCCOL nCol;
402 SCROW nRow;
403 BOOL bRowEmpty;
405 public:
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
419 private:
420 ScHorizontalCellIterator aCellIter;
421 ScHorizontalAttrIterator aAttrIter;
423 SCCOL nNextCol;
424 SCROW nNextRow;
426 SCCOL nCellCol;
427 SCROW nCellRow;
428 const ScBaseCell* pCell;
429 SCCOL nAttrCol1;
430 SCCOL nAttrCol2;
431 SCROW nAttrRow;
432 const ScPatternAttr* pPattern;
434 SCCOL nFoundStartCol; // Ergebnisse nach GetNext
435 SCCOL nFoundEndCol;
436 SCROW nFoundRow;
437 const ScPatternAttr* pFoundPattern;
438 const ScBaseCell* pFoundCell;
440 public:
441 ScUsedAreaIterator( ScDocument* pDocument, SCTAB nTable,
442 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
443 ~ScUsedAreaIterator();
445 BOOL GetNext();
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; }
454 #endif