xref: /aoo41x/main/sc/inc/dociter.hxx (revision 38d50f7b)
1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38d50f7bSAndrew Rist  * distributed with this work for additional information
6*38d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*38d50f7bSAndrew Rist  *
11*38d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*38d50f7bSAndrew Rist  *
13*38d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist  * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*38d50f7bSAndrew Rist  * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist  * under the License.
19*38d50f7bSAndrew Rist  *
20*38d50f7bSAndrew Rist  *************************************************************/
21*38d50f7bSAndrew Rist 
22*38d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_DOCITER_HXX
25cdf0e10cSrcweir #define SC_DOCITER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "address.hxx"
28cdf0e10cSrcweir #include <tools/solar.h>
29cdf0e10cSrcweir #include "global.hxx"
30cdf0e10cSrcweir #include "scdllapi.h"
31cdf0e10cSrcweir #include "queryparam.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <memory>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <set>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class ScDocument;
38cdf0e10cSrcweir class ScBaseCell;
39cdf0e10cSrcweir class ScPatternAttr;
40cdf0e10cSrcweir class ScAttrArray;
41cdf0e10cSrcweir class ScAttrIterator;
42cdf0e10cSrcweir class ScRange;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir class ScDocumentIterator				// alle nichtleeren Zellen durchgehen
45cdf0e10cSrcweir {
46cdf0e10cSrcweir private:
47cdf0e10cSrcweir 	ScDocument*				pDoc;
48cdf0e10cSrcweir 	SCTAB					nStartTab;
49cdf0e10cSrcweir 	SCTAB					nEndTab;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	const ScPatternAttr*	pDefPattern;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	SCCOL					nCol;
54cdf0e10cSrcweir 	SCROW					nRow;
55cdf0e10cSrcweir 	SCTAB					nTab;
56cdf0e10cSrcweir 	ScBaseCell*				pCell;
57cdf0e10cSrcweir 	const ScPatternAttr*	pPattern;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	SCSIZE					nColPos;
61cdf0e10cSrcweir 	SCSIZE					nAttrPos;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	sal_Bool					GetThis();
64cdf0e10cSrcweir 	sal_Bool					GetThisCol();
65cdf0e10cSrcweir 
66cdf0e10cSrcweir public:
67cdf0e10cSrcweir 			ScDocumentIterator( ScDocument* pDocument, SCTAB nStartTable, SCTAB nEndTable );
68cdf0e10cSrcweir 			~ScDocumentIterator();
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	sal_Bool					GetFirst();
71cdf0e10cSrcweir 	sal_Bool					GetNext();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	ScBaseCell*				GetCell();
74cdf0e10cSrcweir 	const ScPatternAttr*	GetPattern();
75cdf0e10cSrcweir 	void					GetPos( SCCOL& rCol, SCROW& rRow, SCTAB& rTab );
76cdf0e10cSrcweir };
77cdf0e10cSrcweir 
78cdf0e10cSrcweir class ScValueIterator            // alle Zahlenwerte in einem Bereich durchgehen
79cdf0e10cSrcweir {
80cdf0e10cSrcweir private:
81cdf0e10cSrcweir 	double			fNextValue;
82cdf0e10cSrcweir 	ScDocument*		pDoc;
83cdf0e10cSrcweir 	const ScAttrArray*	pAttrArray;
84cdf0e10cSrcweir 	sal_uLong			nNumFormat;		// fuer CalcAsShown
85cdf0e10cSrcweir 	sal_uLong			nNumFmtIndex;
86cdf0e10cSrcweir 	SCCOL			nStartCol;
87cdf0e10cSrcweir 	SCROW			nStartRow;
88cdf0e10cSrcweir 	SCTAB			nStartTab;
89cdf0e10cSrcweir 	SCCOL			nEndCol;
90cdf0e10cSrcweir 	SCROW			nEndRow;
91cdf0e10cSrcweir 	SCTAB			nEndTab;
92cdf0e10cSrcweir 	SCCOL 			nCol;
93cdf0e10cSrcweir 	SCROW			nRow;
94cdf0e10cSrcweir 	SCTAB			nTab;
95cdf0e10cSrcweir 	SCSIZE			nColRow;
96cdf0e10cSrcweir 	SCROW			nNextRow;
97cdf0e10cSrcweir 	SCROW			nAttrEndRow;
98cdf0e10cSrcweir 	short			nNumFmtType;
99cdf0e10cSrcweir 	sal_Bool			bNumValid;
100cdf0e10cSrcweir 	sal_Bool			bSubTotal;
101cdf0e10cSrcweir 	sal_Bool			bNextValid;
102cdf0e10cSrcweir 	sal_Bool			bCalcAsShown;
103cdf0e10cSrcweir 	sal_Bool			bTextAsZero;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	sal_Bool			GetThis(double& rValue, sal_uInt16& rErr);
106cdf0e10cSrcweir public:
107cdf0e10cSrcweir //UNUSED2008-05  ScValueIterator(ScDocument* pDocument,
108cdf0e10cSrcweir //UNUSED2008-05                  SCCOL nSCol, SCROW nSRow, SCTAB nSTab,
109cdf0e10cSrcweir //UNUSED2008-05                  SCCOL nECol, SCROW nERow, SCTAB nETab,
110cdf0e10cSrcweir //UNUSED2008-05                  sal_Bool bSTotal = sal_False, sal_Bool bTextAsZero = sal_False);
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 					ScValueIterator(ScDocument* pDocument,
113cdf0e10cSrcweir 									const ScRange& rRange, sal_Bool bSTotal = sal_False,
114cdf0e10cSrcweir 									sal_Bool bTextAsZero = sal_False );
115cdf0e10cSrcweir 	void			GetCurNumFmtInfo( short& nType, sal_uLong& nIndex );
116cdf0e10cSrcweir     /// Does NOT reset rValue if no value found!
117cdf0e10cSrcweir 	sal_Bool			GetFirst(double& rValue, sal_uInt16& rErr);
118cdf0e10cSrcweir     /// Does NOT reset rValue if no value found!
GetNext(double & rValue,sal_uInt16 & rErr)119cdf0e10cSrcweir 	sal_Bool			GetNext(double& rValue, sal_uInt16& rErr)
120cdf0e10cSrcweir 					{
121cdf0e10cSrcweir 						return bNextValid ? ( bNextValid = sal_False, rValue = fNextValue,
122cdf0e10cSrcweir 												rErr = 0, nRow = nNextRow,
123cdf0e10cSrcweir 												++nColRow, bNumValid = sal_False, sal_True )
124cdf0e10cSrcweir 										  : ( ++nRow, GetThis(rValue, rErr) );
125cdf0e10cSrcweir 					}
126cdf0e10cSrcweir };
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // ============================================================================
129cdf0e10cSrcweir 
130cdf0e10cSrcweir class ScDBQueryDataIterator
131cdf0e10cSrcweir {
132cdf0e10cSrcweir public:
133cdf0e10cSrcweir     struct Value
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         ::rtl::OUString maString;
136cdf0e10cSrcweir         double          mfValue;
137cdf0e10cSrcweir         sal_uInt16      mnError;
138cdf0e10cSrcweir         bool            mbIsNumber;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         Value();
141cdf0e10cSrcweir     };
142cdf0e10cSrcweir 
143cdf0e10cSrcweir private:
144cdf0e10cSrcweir     static SCROW        GetRowByColEntryIndex(ScDocument& rDoc, SCTAB nTab, SCCOL nCol, SCSIZE nColRow);
145cdf0e10cSrcweir     static ScBaseCell*  GetCellByColEntryIndex(ScDocument& rDoc, SCTAB nTab, SCCOL nCol, SCSIZE nColRow);
146cdf0e10cSrcweir     static ScAttrArray* GetAttrArrayByCol(ScDocument& rDoc, SCTAB nTab, SCCOL nCol);
147cdf0e10cSrcweir     static bool         IsQueryValid(ScDocument& rDoc, const ScQueryParam& rParam, SCTAB nTab, SCROW nRow, ScBaseCell* pCell);
148cdf0e10cSrcweir     static SCSIZE       SearchColEntryIndex(ScDocument& rDoc, SCTAB nTab, SCROW nRow, SCCOL nCol);
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     class DataAccess
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir     public:
153cdf0e10cSrcweir         DataAccess(const ScDBQueryDataIterator* pParent);
154cdf0e10cSrcweir         virtual ~DataAccess() = 0;
155cdf0e10cSrcweir         virtual bool getCurrent(Value& rValue) = 0;
156cdf0e10cSrcweir         virtual bool getFirst(Value& rValue) = 0;
157cdf0e10cSrcweir         virtual bool getNext(Value& rValue) = 0;
158cdf0e10cSrcweir     protected:
159cdf0e10cSrcweir         const ScDBQueryDataIterator* mpParent;
160cdf0e10cSrcweir     };
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     class DataAccessInternal : public DataAccess
163cdf0e10cSrcweir     {
164cdf0e10cSrcweir     public:
165cdf0e10cSrcweir         DataAccessInternal(const ScDBQueryDataIterator* pParent, ScDBQueryParamInternal* pParam, ScDocument* pDoc);
166cdf0e10cSrcweir         virtual ~DataAccessInternal();
167cdf0e10cSrcweir         virtual bool getCurrent(Value& rValue);
168cdf0e10cSrcweir         virtual bool getFirst(Value& rValue);
169cdf0e10cSrcweir         virtual bool getNext(Value& rValue);
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     private:
172cdf0e10cSrcweir         ScDBQueryParamInternal* mpParam;
173cdf0e10cSrcweir         ScDocument*         mpDoc;
174cdf0e10cSrcweir         const ScAttrArray*  pAttrArray;
175cdf0e10cSrcweir         sal_uLong               nNumFormat;     // for CalcAsShown
176cdf0e10cSrcweir         sal_uLong               nNumFmtIndex;
177cdf0e10cSrcweir         SCCOL               nCol;
178cdf0e10cSrcweir         SCROW               nRow;
179cdf0e10cSrcweir         SCSIZE              nColRow;
180cdf0e10cSrcweir         SCROW               nAttrEndRow;
181cdf0e10cSrcweir         SCTAB               nTab;
182cdf0e10cSrcweir         short               nNumFmtType;
183cdf0e10cSrcweir         bool                bCalcAsShown;
184cdf0e10cSrcweir     };
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     class DataAccessMatrix : public DataAccess
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir     public:
189cdf0e10cSrcweir         DataAccessMatrix(const ScDBQueryDataIterator* pParent, ScDBQueryParamMatrix* pParam);
190cdf0e10cSrcweir         virtual ~DataAccessMatrix();
191cdf0e10cSrcweir         virtual bool getCurrent(Value& rValue);
192cdf0e10cSrcweir         virtual bool getFirst(Value& rValue);
193cdf0e10cSrcweir         virtual bool getNext(Value& rValue);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     private:
196cdf0e10cSrcweir         bool isValidQuery(SCROW mnRow, const ScMatrix& rMat) const;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         ScDBQueryParamMatrix* mpParam;
199cdf0e10cSrcweir         SCROW mnCurRow;
200cdf0e10cSrcweir         SCROW mnRows;
201cdf0e10cSrcweir         SCCOL mnCols;
202cdf0e10cSrcweir     };
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     ::std::auto_ptr<ScDBQueryParamBase> mpParam;
205cdf0e10cSrcweir     ::std::auto_ptr<DataAccess>         mpData;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir public:
208cdf0e10cSrcweir                     ScDBQueryDataIterator(ScDocument* pDocument, ScDBQueryParamBase* pParam);
209cdf0e10cSrcweir     /// Does NOT reset rValue if no value found!
210cdf0e10cSrcweir     bool            GetFirst(Value& rValue);
211cdf0e10cSrcweir     /// Does NOT reset rValue if no value found!
212cdf0e10cSrcweir     bool            GetNext(Value& rValue);
213cdf0e10cSrcweir };
214cdf0e10cSrcweir 
215cdf0e10cSrcweir // ============================================================================
216cdf0e10cSrcweir 
217cdf0e10cSrcweir class ScCellIterator            // alle Zellen in einem Bereich durchgehen
218cdf0e10cSrcweir {								// bei SubTotal aber keine ausgeblendeten und
219cdf0e10cSrcweir private:						// SubTotalZeilen
220cdf0e10cSrcweir 	ScDocument*		pDoc;
221cdf0e10cSrcweir 	SCCOL			nStartCol;
222cdf0e10cSrcweir 	SCROW			nStartRow;
223cdf0e10cSrcweir 	SCTAB			nStartTab;
224cdf0e10cSrcweir 	SCCOL			nEndCol;
225cdf0e10cSrcweir 	SCROW			nEndRow;
226cdf0e10cSrcweir 	SCTAB			nEndTab;
227cdf0e10cSrcweir 	SCCOL 			nCol;
228cdf0e10cSrcweir 	SCROW			nRow;
229cdf0e10cSrcweir 	SCTAB			nTab;
230cdf0e10cSrcweir 	SCSIZE			nColRow;
231cdf0e10cSrcweir 	sal_Bool			bSubTotal;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	ScBaseCell*		GetThis();
234cdf0e10cSrcweir public:
235cdf0e10cSrcweir 					ScCellIterator(ScDocument* pDocument,
236cdf0e10cSrcweir 								   SCCOL nSCol, SCROW nSRow, SCTAB nSTab,
237cdf0e10cSrcweir 								   SCCOL nECol, SCROW nERow, SCTAB nETab,
238cdf0e10cSrcweir 								   sal_Bool bSTotal = sal_False);
239cdf0e10cSrcweir 					ScCellIterator(ScDocument* pDocument,
240cdf0e10cSrcweir 								   const ScRange& rRange, sal_Bool bSTotal = sal_False);
241cdf0e10cSrcweir 	ScBaseCell*		GetFirst();
242cdf0e10cSrcweir 	ScBaseCell*		GetNext();
GetCol() const243cdf0e10cSrcweir     SCCOL           GetCol() const { return nCol; }
GetRow() const244cdf0e10cSrcweir     SCROW           GetRow() const { return nRow; }
GetTab() const245cdf0e10cSrcweir     SCTAB           GetTab() const { return nTab; }
GetPos() const246cdf0e10cSrcweir     ScAddress       GetPos() const { return ScAddress( nCol, nRow, nTab ); }
247cdf0e10cSrcweir };
248cdf0e10cSrcweir 
249cdf0e10cSrcweir class ScQueryCellIterator           // alle nichtleeren Zellen in einem Bereich
250cdf0e10cSrcweir {									// durchgehen
251cdf0e10cSrcweir     enum StopOnMismatchBits
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         nStopOnMismatchDisabled = 0x00,
254cdf0e10cSrcweir         nStopOnMismatchEnabled  = 0x01,
255cdf0e10cSrcweir         nStopOnMismatchOccured  = 0x02,
256cdf0e10cSrcweir         nStopOnMismatchExecuted = nStopOnMismatchEnabled | nStopOnMismatchOccured
257cdf0e10cSrcweir     };
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     enum TestEqualConditionBits
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         nTestEqualConditionDisabled = 0x00,
262cdf0e10cSrcweir         nTestEqualConditionEnabled  = 0x01,
263cdf0e10cSrcweir         nTestEqualConditionMatched  = 0x02,
264cdf0e10cSrcweir         nTestEqualConditionFulfilled = nTestEqualConditionEnabled | nTestEqualConditionMatched
265cdf0e10cSrcweir     };
266cdf0e10cSrcweir 
267cdf0e10cSrcweir private:
268cdf0e10cSrcweir 	ScQueryParam	aParam;
269cdf0e10cSrcweir 	ScDocument*		pDoc;
270cdf0e10cSrcweir 	const ScAttrArray*	pAttrArray;
271cdf0e10cSrcweir 	sal_uLong			nNumFormat;
272cdf0e10cSrcweir 	SCTAB			nTab;
273cdf0e10cSrcweir 	SCCOL 			nCol;
274cdf0e10cSrcweir 	SCROW			nRow;
275cdf0e10cSrcweir 	SCSIZE			nColRow;
276cdf0e10cSrcweir 	SCROW			nAttrEndRow;
277cdf0e10cSrcweir     sal_uInt8            nStopOnMismatch;
278cdf0e10cSrcweir     sal_uInt8            nTestEqualCondition;
279cdf0e10cSrcweir 	sal_Bool			bAdvanceQuery;
280cdf0e10cSrcweir     sal_Bool            bIgnoreMismatchOnLeadingStrings;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 	ScBaseCell*		GetThis();
283cdf0e10cSrcweir 
284cdf0e10cSrcweir                     /* Only works if no regular expression is involved, only
285cdf0e10cSrcweir                        searches for rows in one column, and only the first
286cdf0e10cSrcweir                        query entry is considered with simple conditions
287cdf0e10cSrcweir                        SC_LESS_EQUAL (sorted ascending) or SC_GREATER_EQUAL
288cdf0e10cSrcweir                        (sorted descending). Check these things before
289cdf0e10cSrcweir                        invocation! Delivers a starting point, continue with
290cdf0e10cSrcweir                        GetThis() and GetNext() afterwards. Introduced for
291cdf0e10cSrcweir                        FindEqualOrSortedLastInRange()
292cdf0e10cSrcweir                      */
293cdf0e10cSrcweir     ScBaseCell*     BinarySearch();
294cdf0e10cSrcweir 
295cdf0e10cSrcweir public:
296cdf0e10cSrcweir 					ScQueryCellIterator(ScDocument* pDocument, SCTAB nTable,
297cdf0e10cSrcweir 										const ScQueryParam& aParam, sal_Bool bMod = sal_True);
298cdf0e10cSrcweir 										// fuer bMod = sal_False muss der QueryParam
299cdf0e10cSrcweir 										// weiter aufgefuellt sein (bIsString)
300cdf0e10cSrcweir 	ScBaseCell*		GetFirst();
301cdf0e10cSrcweir 	ScBaseCell*		GetNext();
GetCol()302cdf0e10cSrcweir 	SCCOL           GetCol() { return nCol; }
GetRow()303cdf0e10cSrcweir 	SCROW           GetRow() { return nRow; }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 					// setzt alle Entry.nField einen weiter, wenn Spalte
306cdf0e10cSrcweir 					// wechselt, fuer ScInterpreter ScHLookup()
SetAdvanceQueryParamEntryField(sal_Bool bVal)307cdf0e10cSrcweir 	void			SetAdvanceQueryParamEntryField( sal_Bool bVal )
308cdf0e10cSrcweir 						{ bAdvanceQuery = bVal; }
309cdf0e10cSrcweir 	void			AdvanceQueryParamEntryField();
310cdf0e10cSrcweir 
311cdf0e10cSrcweir                     /** If set, iterator stops on first non-matching cell
312cdf0e10cSrcweir                         content. May be used in SC_LESS_EQUAL queries where a
313cdf0e10cSrcweir                         cell range is assumed to be sorted; stops on first
314cdf0e10cSrcweir                         value being greater than the queried value and
315cdf0e10cSrcweir                         GetFirst()/GetNext() return NULL. StoppedOnMismatch()
316cdf0e10cSrcweir                         returns sal_True then.
317cdf0e10cSrcweir                         However, the iterator's conditions are not set to end
318cdf0e10cSrcweir                         all queries, GetCol() and GetRow() return values for
319cdf0e10cSrcweir                         the non-matching cell, further GetNext() calls may be
320cdf0e10cSrcweir                         executed. */
SetStopOnMismatch(sal_Bool bVal)321cdf0e10cSrcweir     void            SetStopOnMismatch( sal_Bool bVal )
322cdf0e10cSrcweir                         {
323cdf0e10cSrcweir                             nStopOnMismatch = sal::static_int_cast<sal_uInt8>(bVal ? nStopOnMismatchEnabled :
324cdf0e10cSrcweir                                 nStopOnMismatchDisabled);
325cdf0e10cSrcweir                         }
StoppedOnMismatch() const326cdf0e10cSrcweir     sal_Bool            StoppedOnMismatch() const
327cdf0e10cSrcweir                         { return nStopOnMismatch == nStopOnMismatchExecuted; }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir                     /** If set, an additional test for SC_EQUAL condition is
330cdf0e10cSrcweir                         executed in ScTable::ValidQuery() if SC_LESS_EQUAL or
331cdf0e10cSrcweir                         SC_GREATER_EQUAL conditions are to be tested. May be
332cdf0e10cSrcweir                         used where a cell range is assumed to be sorted to stop
333cdf0e10cSrcweir                         if an equal match is found. */
SetTestEqualCondition(sal_Bool bVal)334cdf0e10cSrcweir     void            SetTestEqualCondition( sal_Bool bVal )
335cdf0e10cSrcweir                         {
336cdf0e10cSrcweir                             nTestEqualCondition = sal::static_int_cast<sal_uInt8>(bVal ?
337cdf0e10cSrcweir                                 nTestEqualConditionEnabled :
338cdf0e10cSrcweir                                 nTestEqualConditionDisabled);
339cdf0e10cSrcweir                         }
IsEqualConditionFulfilled() const340cdf0e10cSrcweir     sal_Bool            IsEqualConditionFulfilled() const
341cdf0e10cSrcweir                         { return nTestEqualCondition == nTestEqualConditionFulfilled; }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir                     /** In a range assumed to be sorted find either the last of
344cdf0e10cSrcweir                         a sequence of equal entries or the last being less than
345cdf0e10cSrcweir                         (or greater than) the queried value. Used by the
346cdf0e10cSrcweir                         interpreter for [HV]?LOOKUP() and MATCH(). Column and
347cdf0e10cSrcweir                         row position of the found entry are returned, otherwise
348cdf0e10cSrcweir                         invalid.
349cdf0e10cSrcweir 
350cdf0e10cSrcweir                         @param bSearchForEqualAfterMismatch
351cdf0e10cSrcweir                             Continue searching for an equal entry even if the
352cdf0e10cSrcweir                             last entry matching the range was found, in case
353cdf0e10cSrcweir                             the data is not sorted. Is always done if regular
354cdf0e10cSrcweir                             expressions are involved.
355cdf0e10cSrcweir 
356cdf0e10cSrcweir                         @param bIgnoreMismatchOnLeadingStrings
357cdf0e10cSrcweir                             Normally strings are sorted behind numerical
358cdf0e10cSrcweir                             values. If this parameter is sal_True, the search does
359cdf0e10cSrcweir                             not stop when encountering a string and does not
360cdf0e10cSrcweir                             assume that no values follow anymore.
361cdf0e10cSrcweir                             If querying for a string a mismatch on the first
362cdf0e10cSrcweir                             entry, e.g. column header, is ignored.
363cdf0e10cSrcweir 
364cdf0e10cSrcweir                         @ATTENTION! StopOnMismatch, TestEqualCondition and
365cdf0e10cSrcweir                         the internal IgnoreMismatchOnLeadingStrings and query
366cdf0e10cSrcweir                         params are in an undefined state upon return! The
367cdf0e10cSrcweir                         iterator is not usable anymore except for obtaining the
368cdf0e10cSrcweir                         number format!
369cdf0e10cSrcweir                       */
370cdf0e10cSrcweir     sal_Bool            FindEqualOrSortedLastInRange( SCCOL& nFoundCol,
371cdf0e10cSrcweir                         SCROW& nFoundRow, sal_Bool bSearchForEqualAfterMismatch = sal_False,
372cdf0e10cSrcweir                         sal_Bool bIgnoreMismatchOnLeadingStrings = sal_True );
373cdf0e10cSrcweir };
374cdf0e10cSrcweir 
375cdf0e10cSrcweir class ScDocAttrIterator				// alle Attribut-Bereiche
376cdf0e10cSrcweir {
377cdf0e10cSrcweir private:
378cdf0e10cSrcweir 	ScDocument*		pDoc;
379cdf0e10cSrcweir 	SCTAB			nTab;
380cdf0e10cSrcweir 	SCCOL			nEndCol;
381cdf0e10cSrcweir 	SCROW			nStartRow;
382cdf0e10cSrcweir 	SCROW			nEndRow;
383cdf0e10cSrcweir 	SCCOL			nCol;
384cdf0e10cSrcweir 	ScAttrIterator*	pColIter;
385cdf0e10cSrcweir 
386cdf0e10cSrcweir public:
387cdf0e10cSrcweir 					ScDocAttrIterator(ScDocument* pDocument, SCTAB nTable,
388cdf0e10cSrcweir 									SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
389cdf0e10cSrcweir 					~ScDocAttrIterator();
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	const ScPatternAttr*	GetNext( SCCOL& rCol, SCROW& rRow1, SCROW& rRow2 );
392cdf0e10cSrcweir };
393cdf0e10cSrcweir 
394cdf0e10cSrcweir class ScAttrRectIterator			// alle Attribut-Bereiche, auch Bereiche ueber mehrere Spalten
395cdf0e10cSrcweir {
396cdf0e10cSrcweir private:
397cdf0e10cSrcweir 	ScDocument*		pDoc;
398cdf0e10cSrcweir 	SCTAB			nTab;
399cdf0e10cSrcweir 	SCCOL			nEndCol;
400cdf0e10cSrcweir 	SCROW			nStartRow;
401cdf0e10cSrcweir 	SCROW			nEndRow;
402cdf0e10cSrcweir 	SCCOL			nIterStartCol;
403cdf0e10cSrcweir 	SCCOL			nIterEndCol;
404cdf0e10cSrcweir 	ScAttrIterator*	pColIter;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir public:
407cdf0e10cSrcweir 					ScAttrRectIterator(ScDocument* pDocument, SCTAB nTable,
408cdf0e10cSrcweir 									SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
409cdf0e10cSrcweir 					~ScAttrRectIterator();
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 	void 					DataChanged();
412cdf0e10cSrcweir 	const ScPatternAttr*	GetNext( SCCOL& rCol1, SCCOL& rCol2, SCROW& rRow1, SCROW& rRow2 );
413cdf0e10cSrcweir };
414cdf0e10cSrcweir 
415cdf0e10cSrcweir class ScHorizontalCellIterator		// alle nichtleeren Zellen in einem Bereich
416cdf0e10cSrcweir {									// zeilenweise durchgehen
417cdf0e10cSrcweir private:
418cdf0e10cSrcweir 	ScDocument*		pDoc;
419cdf0e10cSrcweir 	SCTAB			nTab;
420cdf0e10cSrcweir 	SCCOL			nStartCol;
421cdf0e10cSrcweir 	SCCOL			nEndCol;
422cdf0e10cSrcweir 	SCROW			nStartRow;
423cdf0e10cSrcweir 	SCROW			nEndRow;
424cdf0e10cSrcweir 	SCROW*			pNextRows;
425cdf0e10cSrcweir 	SCSIZE*			pNextIndices;
426cdf0e10cSrcweir 	SCCOL			nCol;
427cdf0e10cSrcweir 	SCROW			nRow;
428cdf0e10cSrcweir 	sal_Bool			bMore;
429cdf0e10cSrcweir 
430cdf0e10cSrcweir public:
431cdf0e10cSrcweir 					ScHorizontalCellIterator(ScDocument* pDocument, SCTAB nTable,
432cdf0e10cSrcweir 									SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
433cdf0e10cSrcweir 					~ScHorizontalCellIterator();
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 	ScBaseCell*		GetNext( SCCOL& rCol, SCROW& rRow );
436cdf0e10cSrcweir 	sal_Bool			ReturnNext( SCCOL& rCol, SCROW& rRow );
437cdf0e10cSrcweir     /// Set a(nother) sheet and (re)init.
438cdf0e10cSrcweir     void            SetTab( SCTAB nTab );
439cdf0e10cSrcweir 
440cdf0e10cSrcweir private:
441cdf0e10cSrcweir 	void			Advance();
442cdf0e10cSrcweir };
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 
445cdf0e10cSrcweir /** Row-wise value iterator. */
446cdf0e10cSrcweir class ScHorizontalValueIterator
447cdf0e10cSrcweir {
448cdf0e10cSrcweir private:
449cdf0e10cSrcweir     ScDocument               *pDoc;
450cdf0e10cSrcweir     const ScAttrArray        *pAttrArray;
451cdf0e10cSrcweir     ScHorizontalCellIterator *pCellIter;
452cdf0e10cSrcweir     sal_uLong                 nNumFormat;     // for CalcAsShown
453cdf0e10cSrcweir     sal_uLong                 nNumFmtIndex;
454cdf0e10cSrcweir     SCTAB                     nEndTab;
455cdf0e10cSrcweir     SCCOL                     nCurCol;
456cdf0e10cSrcweir     SCROW                     nCurRow;
457cdf0e10cSrcweir     SCTAB                     nCurTab;
458cdf0e10cSrcweir     SCROW                     nAttrEndRow;
459cdf0e10cSrcweir     short                     nNumFmtType;
460cdf0e10cSrcweir     bool                      bNumValid;
461cdf0e10cSrcweir     bool                      bSubTotal;
462cdf0e10cSrcweir     bool                      bCalcAsShown;
463cdf0e10cSrcweir     bool                      bTextAsZero;
464cdf0e10cSrcweir 
465cdf0e10cSrcweir public:
466cdf0e10cSrcweir 
467cdf0e10cSrcweir                     ScHorizontalValueIterator( ScDocument* pDocument,
468cdf0e10cSrcweir                                                const ScRange& rRange,
469cdf0e10cSrcweir                                                bool bSTotal = false,
470cdf0e10cSrcweir                                                bool bTextAsZero = false );
471cdf0e10cSrcweir                     ~ScHorizontalValueIterator();
472cdf0e10cSrcweir     void            GetCurNumFmtInfo( short& nType, sal_uLong& nIndex );
473cdf0e10cSrcweir     /// Does NOT reset rValue if no value found!
474cdf0e10cSrcweir     bool            GetNext( double& rValue, sal_uInt16& rErr );
475cdf0e10cSrcweir };
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 
478cdf0e10cSrcweir //
479cdf0e10cSrcweir //	gibt alle Bereiche mit nicht-Default-Formatierung zurueck (horizontal)
480cdf0e10cSrcweir //
481cdf0e10cSrcweir 
482cdf0e10cSrcweir class ScHorizontalAttrIterator
483cdf0e10cSrcweir {
484cdf0e10cSrcweir private:
485cdf0e10cSrcweir 	ScDocument* 			pDoc;
486cdf0e10cSrcweir 	SCTAB					nTab;
487cdf0e10cSrcweir 	SCCOL					nStartCol;
488cdf0e10cSrcweir 	SCROW					nStartRow;
489cdf0e10cSrcweir 	SCCOL					nEndCol;
490cdf0e10cSrcweir 	SCROW					nEndRow;
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	SCROW*					pNextEnd;
493cdf0e10cSrcweir 	SCSIZE*					pIndices;
494cdf0e10cSrcweir 	const ScPatternAttr**	ppPatterns;
495cdf0e10cSrcweir 	SCCOL					nCol;
496cdf0e10cSrcweir 	SCROW					nRow;
497cdf0e10cSrcweir 	sal_Bool					bRowEmpty;
498cdf0e10cSrcweir 
499cdf0e10cSrcweir public:
500cdf0e10cSrcweir 			ScHorizontalAttrIterator( ScDocument* pDocument, SCTAB nTable,
501cdf0e10cSrcweir 									SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
502cdf0e10cSrcweir 			~ScHorizontalAttrIterator();
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	const ScPatternAttr*	GetNext( SCCOL& rCol1, SCCOL& rCol2, SCROW& rRow );
505cdf0e10cSrcweir };
506cdf0e10cSrcweir 
507cdf0e10cSrcweir //
508cdf0e10cSrcweir //	gibt nichtleere Zellen und Bereiche mit Formatierung zurueck (horizontal)
509cdf0e10cSrcweir //
510cdf0e10cSrcweir 
511cdf0e10cSrcweir class SC_DLLPUBLIC ScUsedAreaIterator
512cdf0e10cSrcweir {
513cdf0e10cSrcweir private:
514cdf0e10cSrcweir 	ScHorizontalCellIterator	aCellIter;
515cdf0e10cSrcweir 	ScHorizontalAttrIterator	aAttrIter;
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 	SCCOL					nNextCol;
518cdf0e10cSrcweir 	SCROW					nNextRow;
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 	SCCOL					nCellCol;
521cdf0e10cSrcweir 	SCROW					nCellRow;
522cdf0e10cSrcweir 	const ScBaseCell*		pCell;
523cdf0e10cSrcweir 	SCCOL					nAttrCol1;
524cdf0e10cSrcweir 	SCCOL					nAttrCol2;
525cdf0e10cSrcweir 	SCROW					nAttrRow;
526cdf0e10cSrcweir 	const ScPatternAttr*	pPattern;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	SCCOL					nFoundStartCol;			// Ergebnisse nach GetNext
529cdf0e10cSrcweir 	SCCOL					nFoundEndCol;
530cdf0e10cSrcweir 	SCROW					nFoundRow;
531cdf0e10cSrcweir 	const ScPatternAttr*	pFoundPattern;
532cdf0e10cSrcweir 	const ScBaseCell*		pFoundCell;
533cdf0e10cSrcweir 
534cdf0e10cSrcweir public:
535cdf0e10cSrcweir 			ScUsedAreaIterator( ScDocument* pDocument, SCTAB nTable,
536cdf0e10cSrcweir 								SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
537cdf0e10cSrcweir 			~ScUsedAreaIterator();
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 	sal_Bool	GetNext();
540cdf0e10cSrcweir 
GetStartCol() const541cdf0e10cSrcweir 	SCCOL					GetStartCol() const		{ return nFoundStartCol; }
GetEndCol() const542cdf0e10cSrcweir 	SCCOL					GetEndCol() const		{ return nFoundEndCol; }
GetRow() const543cdf0e10cSrcweir 	SCROW					GetRow() const			{ return nFoundRow; }
GetPattern() const544cdf0e10cSrcweir 	const ScPatternAttr*	GetPattern() const		{ return pFoundPattern; }
GetCell() const545cdf0e10cSrcweir 	const ScBaseCell*		GetCell() const			{ return pFoundCell; }
546cdf0e10cSrcweir };
547cdf0e10cSrcweir 
548cdf0e10cSrcweir // ============================================================================
549cdf0e10cSrcweir 
550cdf0e10cSrcweir class ScRowBreakIterator
551cdf0e10cSrcweir {
552cdf0e10cSrcweir public:
553cdf0e10cSrcweir     static SCROW NOT_FOUND;
554cdf0e10cSrcweir 
555cdf0e10cSrcweir     explicit ScRowBreakIterator(::std::set<SCROW>& rBreaks);
556cdf0e10cSrcweir     SCROW first();
557cdf0e10cSrcweir     SCROW next();
558cdf0e10cSrcweir 
559cdf0e10cSrcweir private:
560cdf0e10cSrcweir     ::std::set<SCROW>& mrBreaks;
561cdf0e10cSrcweir     ::std::set<SCROW>::const_iterator maItr;
562cdf0e10cSrcweir     ::std::set<SCROW>::const_iterator maEnd;
563cdf0e10cSrcweir };
564cdf0e10cSrcweir 
565cdf0e10cSrcweir #endif
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 
568