xref: /aoo41x/main/sc/inc/dbcolect.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, 2011 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_DBCOLECT_HXX
29*cdf0e10cSrcweir #define SC_DBCOLECT_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "scdllapi.h"
32*cdf0e10cSrcweir #include "collect.hxx"
33*cdf0e10cSrcweir #include "global.hxx"		// MAXQUERY
34*cdf0e10cSrcweir #include "sortparam.hxx"	// MAXSORT
35*cdf0e10cSrcweir #include "refreshtimer.hxx"
36*cdf0e10cSrcweir #include "address.hxx"
37*cdf0e10cSrcweir #include "scdllapi.h"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //------------------------------------------------------------------------
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir class ScDocument;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //------------------------------------------------------------------------
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir class ScDBData : public ScDataObject, public ScRefreshTimer
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir friend class ScDBCollection;
48*cdf0e10cSrcweir private:
49*cdf0e10cSrcweir 	// DBParam
50*cdf0e10cSrcweir 	String			aName;
51*cdf0e10cSrcweir 	SCTAB			nTable;
52*cdf0e10cSrcweir 	SCCOL      	    nStartCol;
53*cdf0e10cSrcweir 	SCROW			nStartRow;
54*cdf0e10cSrcweir 	SCCOL			nEndCol;
55*cdf0e10cSrcweir 	SCROW			nEndRow;
56*cdf0e10cSrcweir 	sal_Bool			bByRow;
57*cdf0e10cSrcweir 	sal_Bool			bHasHeader;
58*cdf0e10cSrcweir 	sal_Bool			bDoSize;
59*cdf0e10cSrcweir 	sal_Bool			bKeepFmt;
60*cdf0e10cSrcweir 	sal_Bool			bStripData;
61*cdf0e10cSrcweir 	// SortParam
62*cdf0e10cSrcweir 	sal_Bool			bSortCaseSens;
63*cdf0e10cSrcweir 	sal_Bool			bIncludePattern;
64*cdf0e10cSrcweir 	sal_Bool			bSortInplace;
65*cdf0e10cSrcweir 	sal_Bool			bSortUserDef;
66*cdf0e10cSrcweir 	sal_uInt16			nSortUserIndex;
67*cdf0e10cSrcweir 	SCTAB			nSortDestTab;
68*cdf0e10cSrcweir 	SCCOL			nSortDestCol;
69*cdf0e10cSrcweir 	SCROW			nSortDestRow;
70*cdf0e10cSrcweir 	sal_Bool			bDoSort[MAXSORT];
71*cdf0e10cSrcweir 	SCCOLROW		nSortField[MAXSORT];
72*cdf0e10cSrcweir 	sal_Bool			bAscending[MAXSORT];
73*cdf0e10cSrcweir 	::com::sun::star::lang::Locale aSortLocale;
74*cdf0e10cSrcweir 	String			aSortAlgorithm;
75*cdf0e10cSrcweir 	// QueryParam
76*cdf0e10cSrcweir 	sal_Bool			bQueryInplace;
77*cdf0e10cSrcweir 	sal_Bool			bQueryCaseSens;
78*cdf0e10cSrcweir 	sal_Bool			bQueryRegExp;
79*cdf0e10cSrcweir 	sal_Bool			bQueryDuplicate;
80*cdf0e10cSrcweir 	SCTAB			nQueryDestTab;
81*cdf0e10cSrcweir 	SCCOL			nQueryDestCol;
82*cdf0e10cSrcweir 	SCROW			nQueryDestRow;
83*cdf0e10cSrcweir 	sal_Bool			bDoQuery[MAXQUERY];
84*cdf0e10cSrcweir 	SCCOLROW		nQueryField[MAXQUERY];
85*cdf0e10cSrcweir 	ScQueryOp		eQueryOp[MAXQUERY];
86*cdf0e10cSrcweir 	sal_Bool			bQueryByString[MAXQUERY];
87*cdf0e10cSrcweir     bool            bQueryByDate[MAXQUERY];
88*cdf0e10cSrcweir 	String*			pQueryStr[MAXQUERY];
89*cdf0e10cSrcweir 	double			nQueryVal[MAXQUERY];
90*cdf0e10cSrcweir 	ScQueryConnect  eQueryConnect[MAXQUERY];
91*cdf0e10cSrcweir 	sal_Bool			bIsAdvanced;		// sal_True if created by advanced filter
92*cdf0e10cSrcweir 	ScRange			aAdvSource;			// source range
93*cdf0e10cSrcweir 	// SubTotalParam
94*cdf0e10cSrcweir 	sal_Bool			bSubRemoveOnly;
95*cdf0e10cSrcweir 	sal_Bool			bSubReplace;
96*cdf0e10cSrcweir 	sal_Bool			bSubPagebreak;
97*cdf0e10cSrcweir 	sal_Bool			bSubCaseSens;
98*cdf0e10cSrcweir 	sal_Bool			bSubDoSort;
99*cdf0e10cSrcweir 	sal_Bool			bSubAscending;
100*cdf0e10cSrcweir 	sal_Bool			bSubIncludePattern;
101*cdf0e10cSrcweir 	sal_Bool			bSubUserDef;
102*cdf0e10cSrcweir 	sal_uInt16			nSubUserIndex;
103*cdf0e10cSrcweir 	sal_Bool			bDoSubTotal[MAXSUBTOTAL];
104*cdf0e10cSrcweir 	SCCOL			nSubField[MAXSUBTOTAL];
105*cdf0e10cSrcweir 	SCCOL			nSubTotals[MAXSUBTOTAL];
106*cdf0e10cSrcweir 	SCCOL*			pSubTotals[MAXSUBTOTAL];
107*cdf0e10cSrcweir 	ScSubTotalFunc*	pFunctions[MAXSUBTOTAL];
108*cdf0e10cSrcweir 	// Datenbank-Import
109*cdf0e10cSrcweir 	sal_Bool			bDBImport;
110*cdf0e10cSrcweir 	String			aDBName;
111*cdf0e10cSrcweir 	String			aDBStatement;
112*cdf0e10cSrcweir 	sal_Bool			bDBNative;
113*cdf0e10cSrcweir 	sal_Bool			bDBSelection;		// nicht im Param: Wenn Selektion, Update sperren
114*cdf0e10cSrcweir 	sal_Bool			bDBSql;				// aDBStatement ist SQL und kein Name
115*cdf0e10cSrcweir 	sal_uInt8			nDBType;			// enum DBObject (bisher nur dbTable, dbQuery)
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	sal_uInt16			nIndex; 			// eindeutiger Index fuer Formeln
118*cdf0e10cSrcweir 	sal_Bool			bAutoFilter;		// AutoFilter? (nicht gespeichert)
119*cdf0e10cSrcweir 	sal_Bool			bModified;			// wird bei UpdateReference gesetzt/geloescht
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     using ScRefreshTimer::operator==;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir public:
124*cdf0e10cSrcweir 			SC_DLLPUBLIC ScDBData(const String& rName,
125*cdf0e10cSrcweir 					 SCTAB nTab,
126*cdf0e10cSrcweir 					 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
127*cdf0e10cSrcweir 					 sal_Bool bByR = sal_True, sal_Bool bHasH = sal_True);
128*cdf0e10cSrcweir 			ScDBData(const ScDBData& rData);
129*cdf0e10cSrcweir 			~ScDBData();
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	virtual	ScDataObject*	Clone() const;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 			ScDBData&	operator= (const ScDBData& rData);
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 			sal_Bool		operator== (const ScDBData& rData) const;
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 			const String& GetName() const				{ return aName; }
138*cdf0e10cSrcweir 			void		GetName(String& rName) const	{ rName = aName; }
139*cdf0e10cSrcweir 			void		SetName(const String& rName)	{ aName = rName; }
140*cdf0e10cSrcweir 			void		GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2) const;
141*cdf0e10cSrcweir 			SC_DLLPUBLIC void		GetArea(ScRange& rRange) const;
142*cdf0e10cSrcweir 			void		SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
143*cdf0e10cSrcweir 			void		MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
144*cdf0e10cSrcweir 			sal_Bool		IsByRow() const 				{ return bByRow; }
145*cdf0e10cSrcweir 			void		SetByRow(sal_Bool bByR) 			{ bByRow = bByR; }
146*cdf0e10cSrcweir 			sal_Bool		HasHeader() const 				{ return bHasHeader; }
147*cdf0e10cSrcweir 			void		SetHeader(sal_Bool bHasH) 			{ bHasHeader = bHasH; }
148*cdf0e10cSrcweir             void        SetIndex(sal_uInt16 nInd)           { nIndex = nInd; }
149*cdf0e10cSrcweir 			sal_uInt16		GetIndex() const				{ return nIndex; }
150*cdf0e10cSrcweir 			sal_Bool		IsDoSize() const				{ return bDoSize; }
151*cdf0e10cSrcweir 			void		SetDoSize(sal_Bool bSet)			{ bDoSize = bSet; }
152*cdf0e10cSrcweir 			sal_Bool		IsKeepFmt() const				{ return bKeepFmt; }
153*cdf0e10cSrcweir 			void		SetKeepFmt(sal_Bool bSet)			{ bKeepFmt = bSet; }
154*cdf0e10cSrcweir 			sal_Bool		IsStripData() const				{ return bStripData; }
155*cdf0e10cSrcweir 			void		SetStripData(sal_Bool bSet)			{ bStripData = bSet; }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir //UNUSED2008-05  sal_Bool		IsBeyond(SCROW nMaxRow) const;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 			String		GetSourceString() const;
160*cdf0e10cSrcweir 			String		GetOperations() const;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 			void		GetSortParam(ScSortParam& rSortParam) const;
163*cdf0e10cSrcweir 			void		SetSortParam(const ScSortParam& rSortParam);
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 			SC_DLLPUBLIC void		GetQueryParam(ScQueryParam& rQueryParam) const;
166*cdf0e10cSrcweir 			SC_DLLPUBLIC void		SetQueryParam(const ScQueryParam& rQueryParam);
167*cdf0e10cSrcweir 			SC_DLLPUBLIC sal_Bool		GetAdvancedQuerySource(ScRange& rSource) const;
168*cdf0e10cSrcweir 			SC_DLLPUBLIC void		SetAdvancedQuerySource(const ScRange* pSource);
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 			void		GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const;
171*cdf0e10cSrcweir 			void		SetSubTotalParam(const ScSubTotalParam& rSubTotalParam);
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 			void		GetImportParam(ScImportParam& rImportParam) const;
174*cdf0e10cSrcweir 			void		SetImportParam(const ScImportParam& rImportParam);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 			sal_Bool		IsDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const;
177*cdf0e10cSrcweir 			sal_Bool		IsDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 			sal_Bool		HasImportParam() const	 { return bDBImport; }
180*cdf0e10cSrcweir 			sal_Bool		HasQueryParam() const	 { return bDoQuery[0]; }
181*cdf0e10cSrcweir 			sal_Bool		HasSortParam() const	 { return bDoSort[0]; }
182*cdf0e10cSrcweir 			sal_Bool		HasSubTotalParam() const { return bDoSubTotal[0]; }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 			sal_Bool		HasImportSelection() const		{ return bDBSelection; }
185*cdf0e10cSrcweir 			void		SetImportSelection(sal_Bool bSet)	{ bDBSelection = bSet; }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 			sal_Bool		HasAutoFilter() const 		{ return bAutoFilter; }
188*cdf0e10cSrcweir 			void		SetAutoFilter(sal_Bool bSet)	{ bAutoFilter = bSet; }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 			sal_Bool		IsModified() const			{ return bModified; }
191*cdf0e10cSrcweir 			void		SetModified(sal_Bool bMod)		{ bModified = bMod; }
192*cdf0e10cSrcweir };
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir //------------------------------------------------------------------------
196*cdf0e10cSrcweir class SC_DLLPUBLIC ScDBCollection : public ScSortedCollection
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir private:
200*cdf0e10cSrcweir 	Link		aRefreshHandler;
201*cdf0e10cSrcweir 	ScDocument* pDoc;
202*cdf0e10cSrcweir 	sal_uInt16 nEntryIndex;			// Zaehler fuer die eindeutigen Indizes
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir public:
205*cdf0e10cSrcweir 	ScDBCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False, ScDocument* pDocument = NULL) :
206*cdf0e10cSrcweir 					ScSortedCollection	( nLim, nDel, bDup ),
207*cdf0e10cSrcweir 					pDoc				( pDocument ),
208*cdf0e10cSrcweir 					nEntryIndex			( SC_START_INDEX_DB_COLL )	// oberhalb der Namen
209*cdf0e10cSrcweir 					{}
210*cdf0e10cSrcweir 	ScDBCollection(const ScDBCollection& rScDBCollection) :
211*cdf0e10cSrcweir 					ScSortedCollection	( rScDBCollection ),
212*cdf0e10cSrcweir 					pDoc 				( rScDBCollection.pDoc ),
213*cdf0e10cSrcweir 					nEntryIndex			( rScDBCollection.nEntryIndex)
214*cdf0e10cSrcweir 					{}
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	virtual	ScDataObject*	Clone() const { return new ScDBCollection(*this); }
217*cdf0e10cSrcweir 			ScDBData*	operator[]( const sal_uInt16 nIndex) const {return (ScDBData*)At(nIndex);}
218*cdf0e10cSrcweir 	virtual	short		Compare(ScDataObject* pKey1, ScDataObject* pKey2) const;
219*cdf0e10cSrcweir 	virtual	sal_Bool		IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const;
220*cdf0e10cSrcweir 			ScDBData*	GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const;
221*cdf0e10cSrcweir 			ScDBData*	GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
222*cdf0e10cSrcweir 			ScDBData*       GetFilterDBAtTable(SCTAB nTab) const;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	sal_Bool	SearchName( const String& rName, sal_uInt16& rIndex ) const;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir     void    DeleteOnTab( SCTAB nTab );
227*cdf0e10cSrcweir 	void	UpdateReference(UpdateRefMode eUpdateRefMode,
228*cdf0e10cSrcweir 								SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
229*cdf0e10cSrcweir 								SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
230*cdf0e10cSrcweir 								SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
231*cdf0e10cSrcweir 	void	UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	ScDBData* FindIndex(sal_uInt16 nIndex);
234*cdf0e10cSrcweir 	sal_uInt16 	GetEntryIndex()					{ return nEntryIndex; }
235*cdf0e10cSrcweir 	void 	SetEntryIndex(sal_uInt16 nInd)		{ nEntryIndex = nInd; }
236*cdf0e10cSrcweir 	virtual sal_Bool Insert(ScDataObject* pScDataObject);
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 	void			SetRefreshHandler( const Link& rLink )
239*cdf0e10cSrcweir 						{ aRefreshHandler = rLink; }
240*cdf0e10cSrcweir 	const Link&		GetRefreshHandler() const	{ return aRefreshHandler; }
241*cdf0e10cSrcweir };
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir #endif
244