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