Update ooo320-m1
[ooovba.git] / sc / inc / dociter.hxx
blob350c6110bb262bbcb743c9a1e0d644a4e7c4f2b6
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"
38 #include "queryparam.hxx"
40 #include <memory>
42 class ScDocument;
43 class ScBaseCell;
44 class ScPatternAttr;
45 class ScAttrArray;
46 class ScAttrIterator;
47 class ScRange;
49 class ScDocumentIterator // alle nichtleeren Zellen durchgehen
51 private:
52 ScDocument* pDoc;
53 SCTAB nStartTab;
54 SCTAB nEndTab;
56 const ScPatternAttr* pDefPattern;
58 SCCOL nCol;
59 SCROW nRow;
60 SCTAB nTab;
61 ScBaseCell* pCell;
62 const ScPatternAttr* pPattern;
65 SCSIZE nColPos;
66 SCSIZE nAttrPos;
68 BOOL GetThis();
69 BOOL GetThisCol();
71 public:
72 ScDocumentIterator( ScDocument* pDocument, SCTAB nStartTable, SCTAB nEndTable );
73 ~ScDocumentIterator();
75 BOOL GetFirst();
76 BOOL GetNext();
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
85 private:
86 double fNextValue;
87 ScDocument* pDoc;
88 const ScAttrArray* pAttrArray;
89 ULONG nNumFormat; // fuer CalcAsShown
90 ULONG nNumFmtIndex;
91 SCCOL nStartCol;
92 SCROW nStartRow;
93 SCTAB nStartTab;
94 SCCOL nEndCol;
95 SCROW nEndRow;
96 SCTAB nEndTab;
97 SCCOL nCol;
98 SCROW nRow;
99 SCTAB nTab;
100 SCSIZE nColRow;
101 SCROW nNextRow;
102 SCROW nAttrEndRow;
103 short nNumFmtType;
104 BOOL bNumValid;
105 BOOL bSubTotal;
106 BOOL bNextValid;
107 BOOL bCalcAsShown;
108 BOOL bTextAsZero;
110 BOOL GetThis(double& rValue, USHORT& rErr);
111 public:
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
137 public:
138 struct Value
140 ::rtl::OUString maString;
141 double mfValue;
142 sal_uInt16 mnError;
143 bool mbIsNumber;
145 Value();
148 private:
149 class DataAccess
151 public:
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;
157 protected:
158 const ScDBQueryDataIterator* mpParent;
161 class DataAccessInternal : public DataAccess
163 public:
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);
170 private:
171 ScDBQueryParamInternal* mpParam;
172 ScDocument* mpDoc;
173 const ScAttrArray* pAttrArray;
174 ULONG nNumFormat; // for CalcAsShown
175 ULONG nNumFmtIndex;
176 SCCOL nCol;
177 SCROW nRow;
178 SCSIZE nColRow;
179 SCROW nAttrEndRow;
180 SCTAB nTab;
181 short nNumFmtType;
182 bool bCalcAsShown;
185 class DataAccessMatrix : public DataAccess
187 public:
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);
194 private:
195 bool isValidQuery(SCROW mnRow, const ScMatrix& rMat) const;
197 ScDBQueryParamMatrix* mpParam;
198 SCROW mnCurRow;
199 SCROW mnRows;
200 SCCOL mnCols;
203 ::std::auto_ptr<ScDBQueryParamBase> mpParam;
204 ::std::auto_ptr<DataAccess> mpData;
206 bool GetThis(Value& rValue);
208 public:
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
221 ScDocument* pDoc;
222 SCCOL nStartCol;
223 SCROW nStartRow;
224 SCTAB nStartTab;
225 SCCOL nEndCol;
226 SCROW nEndRow;
227 SCTAB nEndTab;
228 SCCOL nCol;
229 SCROW nRow;
230 SCTAB nTab;
231 SCSIZE nColRow;
232 BOOL bSubTotal;
234 ScBaseCell* GetThis();
235 public:
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
251 { // durchgehen
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
268 private:
269 ScQueryParam aParam;
270 ScDocument* pDoc;
271 const ScAttrArray* pAttrArray;
272 ULONG nNumFormat;
273 SCTAB nTab;
274 SCCOL nCol;
275 SCROW nRow;
276 SCSIZE nColRow;
277 SCROW nAttrEndRow;
278 BYTE nStopOnMismatch;
279 BYTE nTestEqualCondition;
280 BOOL bAdvanceQuery;
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();
296 public:
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()
318 returns TRUE then.
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
322 executed. */
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
350 invalid.
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
370 number format!
372 BOOL FindEqualOrSortedLastInRange( SCCOL& nFoundCol,
373 SCROW& nFoundRow, BOOL bSearchForEqualAfterMismatch = FALSE,
374 BOOL bIgnoreMismatchOnLeadingStrings = TRUE );
377 class ScDocAttrIterator // alle Attribut-Bereiche
379 private:
380 ScDocument* pDoc;
381 SCTAB nTab;
382 SCCOL nEndCol;
383 SCROW nStartRow;
384 SCROW nEndRow;
385 SCCOL nCol;
386 ScAttrIterator* pColIter;
388 public:
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
398 private:
399 ScDocument* pDoc;
400 SCTAB nTab;
401 SCCOL nEndCol;
402 SCROW nStartRow;
403 SCROW nEndRow;
404 SCCOL nIterStartCol;
405 SCCOL nIterEndCol;
406 ScAttrIterator* pColIter;
408 public:
409 ScAttrRectIterator(ScDocument* pDocument, SCTAB nTable,
410 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
411 ~ScAttrRectIterator();
413 void DataChanged();
414 const ScPatternAttr* GetNext( SCCOL& rCol1, SCCOL& rCol2, SCROW& rRow1, SCROW& rRow2 );
417 class ScHorizontalCellIterator // alle nichtleeren Zellen in einem Bereich
418 { // zeilenweise durchgehen
419 private:
420 ScDocument* pDoc;
421 SCTAB nTab;
422 SCCOL nStartCol;
423 SCCOL nEndCol;
424 SCROW nEndRow;
425 SCROW* pNextRows;
426 SCSIZE* pNextIndices;
427 SCCOL nCol;
428 SCROW nRow;
429 BOOL bMore;
431 public:
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 );
439 private:
440 void Advance();
445 // gibt alle Bereiche mit nicht-Default-Formatierung zurueck (horizontal)
448 class ScHorizontalAttrIterator
450 private:
451 ScDocument* pDoc;
452 SCTAB nTab;
453 SCCOL nStartCol;
454 SCROW nStartRow;
455 SCCOL nEndCol;
456 SCROW nEndRow;
458 SCROW* pNextEnd;
459 SCSIZE* pIndices;
460 const ScPatternAttr** ppPatterns;
461 SCCOL nCol;
462 SCROW nRow;
463 BOOL bRowEmpty;
465 public:
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
479 private:
480 ScHorizontalCellIterator aCellIter;
481 ScHorizontalAttrIterator aAttrIter;
483 SCCOL nNextCol;
484 SCROW nNextRow;
486 SCCOL nCellCol;
487 SCROW nCellRow;
488 const ScBaseCell* pCell;
489 SCCOL nAttrCol1;
490 SCCOL nAttrCol2;
491 SCROW nAttrRow;
492 const ScPatternAttr* pPattern;
494 SCCOL nFoundStartCol; // Ergebnisse nach GetNext
495 SCCOL nFoundEndCol;
496 SCROW nFoundRow;
497 const ScPatternAttr* pFoundPattern;
498 const ScBaseCell* pFoundCell;
500 public:
501 ScUsedAreaIterator( ScDocument* pDocument, SCTAB nTable,
502 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
503 ~ScUsedAreaIterator();
505 BOOL GetNext();
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; }
514 #endif