xref: /aoo41x/main/sc/inc/dbcolect.hxx (revision 57b4fa3c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_DBCOLECT_HXX
25 #define SC_DBCOLECT_HXX
26 
27 #include "scdllapi.h"
28 #include "collect.hxx"
29 #include "global.hxx"		// MAXQUERY
30 #include "sortparam.hxx"	// MAXSORT
31 #include "refreshtimer.hxx"
32 #include "address.hxx"
33 #include "scdllapi.h"
34 
35 //------------------------------------------------------------------------
36 
37 class ScDocument;
38 
39 //------------------------------------------------------------------------
40 
41 class ScDBData : public ScDataObject, public ScRefreshTimer
42 {
43 friend class ScDBCollection;
44 private:
45 	// DBParam
46 	String			aName;
47 	SCTAB			nTable;
48 	SCCOL      	    nStartCol;
49 	SCROW			nStartRow;
50 	SCCOL			nEndCol;
51 	SCROW			nEndRow;
52 	sal_Bool			bByRow;
53 	sal_Bool			bHasHeader;
54 	sal_Bool			bDoSize;
55 	sal_Bool			bKeepFmt;
56 	sal_Bool			bStripData;
57 	// SortParam
58 	sal_Bool			bSortCaseSens;
59 	sal_Bool			bIncludePattern;
60 	sal_Bool			bSortInplace;
61 	sal_Bool			bSortUserDef;
62 	sal_uInt16			nSortUserIndex;
63 	SCTAB			nSortDestTab;
64 	SCCOL			nSortDestCol;
65 	SCROW			nSortDestRow;
66 	sal_Bool			bDoSort[MAXSORT];
67 	SCCOLROW		nSortField[MAXSORT];
68 	sal_Bool			bAscending[MAXSORT];
69 	::com::sun::star::lang::Locale aSortLocale;
70 	String			aSortAlgorithm;
71 	// QueryParam
72 	sal_Bool			bQueryInplace;
73 	sal_Bool			bQueryCaseSens;
74 	sal_Bool			bQueryRegExp;
75 	sal_Bool			bQueryDuplicate;
76 	SCTAB			nQueryDestTab;
77 	SCCOL			nQueryDestCol;
78 	SCROW			nQueryDestRow;
79 	sal_Bool			bDoQuery[MAXQUERY];
80 	SCCOLROW		nQueryField[MAXQUERY];
81 	ScQueryOp		eQueryOp[MAXQUERY];
82 	sal_Bool			bQueryByString[MAXQUERY];
83     bool            bQueryByDate[MAXQUERY];
84 	String*			pQueryStr[MAXQUERY];
85 	double			nQueryVal[MAXQUERY];
86 	ScQueryConnect  eQueryConnect[MAXQUERY];
87 	sal_Bool			bIsAdvanced;		// sal_True if created by advanced filter
88 	ScRange			aAdvSource;			// source range
89 	// SubTotalParam
90 	sal_Bool			bSubRemoveOnly;
91 	sal_Bool			bSubReplace;
92 	sal_Bool			bSubPagebreak;
93 	sal_Bool			bSubCaseSens;
94 	sal_Bool			bSubDoSort;
95 	sal_Bool			bSubAscending;
96 	sal_Bool			bSubIncludePattern;
97 	sal_Bool			bSubUserDef;
98 	sal_uInt16			nSubUserIndex;
99 	sal_Bool			bDoSubTotal[MAXSUBTOTAL];
100 	SCCOL			nSubField[MAXSUBTOTAL];
101 	SCCOL			nSubTotals[MAXSUBTOTAL];
102 	SCCOL*			pSubTotals[MAXSUBTOTAL];
103 	ScSubTotalFunc*	pFunctions[MAXSUBTOTAL];
104 	// Datenbank-Import
105 	sal_Bool			bDBImport;
106 	String			aDBName;
107 	String			aDBStatement;
108 	sal_Bool			bDBNative;
109 	sal_Bool			bDBSelection;		// nicht im Param: Wenn Selektion, Update sperren
110 	sal_Bool			bDBSql;				// aDBStatement ist SQL und kein Name
111 	sal_uInt8			nDBType;			// enum DBObject (bisher nur dbTable, dbQuery)
112 
113 	sal_uInt16			nIndex; 			// eindeutiger Index fuer Formeln
114 	sal_Bool			bAutoFilter;		// AutoFilter? (nicht gespeichert)
115 	sal_Bool			bModified;			// wird bei UpdateReference gesetzt/geloescht
116 
117     using ScRefreshTimer::operator==;
118 
119 public:
120 			SC_DLLPUBLIC ScDBData(const String& rName,
121 					 SCTAB nTab,
122 					 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
123 					 sal_Bool bByR = sal_True, sal_Bool bHasH = sal_True);
124 			ScDBData(const ScDBData& rData);
125 			~ScDBData();
126 
127 	virtual	ScDataObject*	Clone() const;
128 
129 			ScDBData&	operator= (const ScDBData& rData);
130 
131 			sal_Bool		operator== (const ScDBData& rData) const;
132 
133 			const String& GetName() const				{ return aName; }
134 			void		GetName(String& rName) const	{ rName = aName; }
135 			void		SetName(const String& rName)	{ aName = rName; }
136 			void		GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2) const;
137 			SC_DLLPUBLIC void		GetArea(ScRange& rRange) const;
138 			void		SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
139             //If the name of DBData is started with "unnamed", it will be recognized as build in DBData
140             sal_Bool        IsBuildin();
141 			void		MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
142 			sal_Bool		IsByRow() const 				{ return bByRow; }
143 			void		SetByRow(sal_Bool bByR) 			{ bByRow = bByR; }
144 			sal_Bool		HasHeader() const 				{ return bHasHeader; }
145 			void		SetHeader(sal_Bool bHasH) 			{ bHasHeader = bHasH; }
146             void        SetIndex(sal_uInt16 nInd)           { nIndex = nInd; }
147 			sal_uInt16		GetIndex() const				{ return nIndex; }
148 			sal_Bool		IsDoSize() const				{ return bDoSize; }
149 			void		SetDoSize(sal_Bool bSet)			{ bDoSize = bSet; }
150 			sal_Bool		IsKeepFmt() const				{ return bKeepFmt; }
151 			void		SetKeepFmt(sal_Bool bSet)			{ bKeepFmt = bSet; }
152 			sal_Bool		IsStripData() const				{ return bStripData; }
153 			void		SetStripData(sal_Bool bSet)			{ bStripData = bSet; }
154 
155 //UNUSED2008-05  sal_Bool		IsBeyond(SCROW nMaxRow) const;
156 
157 			String		GetSourceString() const;
158 			String		GetOperations() const;
159 
160 			void		GetSortParam(ScSortParam& rSortParam) const;
161 			void		SetSortParam(const ScSortParam& rSortParam);
162 
163 			SC_DLLPUBLIC void		GetQueryParam(ScQueryParam& rQueryParam) const;
164 			SC_DLLPUBLIC void		SetQueryParam(const ScQueryParam& rQueryParam);
165 			SC_DLLPUBLIC sal_Bool		GetAdvancedQuerySource(ScRange& rSource) const;
166 			SC_DLLPUBLIC void		SetAdvancedQuerySource(const ScRange* pSource);
167 
168 			void		GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const;
169 			void		SetSubTotalParam(const ScSubTotalParam& rSubTotalParam);
170 
171 			void		GetImportParam(ScImportParam& rImportParam) const;
172 			void		SetImportParam(const ScImportParam& rImportParam);
173 
174 			sal_Bool		IsDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const;
175 			sal_Bool		IsDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
176 
177 			sal_Bool		HasImportParam() const	 { return bDBImport; }
178 			sal_Bool		HasQueryParam() const	 { return bDoQuery[0]; }
179 			sal_Bool		HasSortParam() const	 { return bDoSort[0]; }
180 			sal_Bool		HasSubTotalParam() const { return bDoSubTotal[0]; }
181 
182 			sal_Bool		HasImportSelection() const		{ return bDBSelection; }
183 			void		SetImportSelection(sal_Bool bSet)	{ bDBSelection = bSet; }
184 
185 			sal_Bool		HasAutoFilter() const 		{ return bAutoFilter; }
186 			void		SetAutoFilter(sal_Bool bSet)	{ bAutoFilter = bSet; }
187 
188 			sal_Bool		IsModified() const			{ return bModified; }
189 			void		SetModified(sal_Bool bMod)		{ bModified = bMod; }
190 };
191 
192 
193 //------------------------------------------------------------------------
194 class SC_DLLPUBLIC ScDBCollection : public ScSortedCollection
195 {
196 
197 private:
198 	Link		aRefreshHandler;
199 	ScDocument* pDoc;
200 	sal_uInt16 nEntryIndex;			// Zaehler fuer die eindeutigen Indizes
201 
202 public:
203 	ScDBCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False, ScDocument* pDocument = NULL) :
204 					ScSortedCollection	( nLim, nDel, bDup ),
205 					pDoc				( pDocument ),
206 					nEntryIndex			( SC_START_INDEX_DB_COLL )	// oberhalb der Namen
207 					{}
208 	ScDBCollection(const ScDBCollection& rScDBCollection) :
209 					ScSortedCollection	( rScDBCollection ),
210 					pDoc 				( rScDBCollection.pDoc ),
211 					nEntryIndex			( rScDBCollection.nEntryIndex)
212 					{}
213 
214 	virtual	ScDataObject*	Clone() const { return new ScDBCollection(*this); }
215 			ScDBData*	operator[]( const sal_uInt16 nIndex) const {return (ScDBData*)At(nIndex);}
216 	virtual	short		Compare(ScDataObject* pKey1, ScDataObject* pKey2) const;
217 	virtual	sal_Bool		IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const;
218 			ScDBData*	GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const;
219 			ScDBData*	GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
220 			ScDBData*       GetFilterDBAtTable(SCTAB nTab) const;
221             ScDBData*	GetDBAtTable(SCTAB nTab, ScGetDBMode eMode) const;
222 
223 	sal_Bool	SearchName( const String& rName, sal_uInt16& rIndex ) const;
224 
225     void    DeleteOnTab( SCTAB nTab );
226 	void	UpdateReference(UpdateRefMode eUpdateRefMode,
227 								SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
228 								SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
229 								SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
230 	void	UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
231 
232 	ScDBData* FindIndex(sal_uInt16 nIndex);
233 	sal_uInt16 	GetEntryIndex()					{ return nEntryIndex; }
234 	void 	SetEntryIndex(sal_uInt16 nInd)		{ nEntryIndex = nInd; }
235 	virtual sal_Bool Insert(ScDataObject* pScDataObject);
236 
237 	void			SetRefreshHandler( const Link& rLink )
238 						{ aRefreshHandler = rLink; }
239 	const Link&		GetRefreshHandler() const	{ return aRefreshHandler; }
240     String      GetNewDefaultDBName();
241     /*sal_Bool        IsFiltered(SCTAB nTab, SCROW nRow);*/
242 };
243 
244 #endif
245